Skip to content

Latest commit

 

History

History
168 lines (125 loc) · 4.02 KB

File metadata and controls

168 lines (125 loc) · 4.02 KB

Definitions and Uses

Uses

A use is a qualified identifier that refers to a definition according to the scoping rules for names.

A use is a qualifying use if it qualifies another use. For example, in the following code

  • The expression M.a contains the expression M, which is a qualifying use of the module M. It qualifies the use M.a.

  • The expression M.a is not a qualifying use.

module M {

  constant a = 0

  constant b = M.a

}

If a use u is not a qualifying use, then we say it is a non-qualifying use.

Use-Def Graph

The set of definitions and non-qualifying uses in an FPP model induces a directed graph called the use-def graph. In this graph,

  1. The nodes are the definitions.

  2. There is an edge from each definition d to the definitions \$d_1, ..., d_n\$ corresponding to the non-qualifying uses \$u_1, ..., u_n\$ appearing in d.

For example, in the following code, the use-def graph has two nodes a and b and one edge b \$rarr\$ a.

constant a = 0
constant b = a

In a legal FPP model, the use-def graph must be acyclic. For example, this model is illegal:

constant a = b
constant b = a

This model is also illegal:

constant a = a

This model is legal:

module M {

  constant a = 0

  constant b = M.a

}

The use M appears inside the definition of M. However, it is a qualifying use.

Order of Definitions and Uses

So long as the use-def graph is acyclic, there is no constraint either on the ordering of definitions and uses within a translation unit, or on the distribution of definitions and uses among translation units. For example, if the definition constant c = 0 appears anywhere in any translation unit of a model M, then the use of c as a constant value of type Integer is legal anywhere in any translation unit of M. In particular, this model is legal:

constant b = a
constant a = 0

The model consisting of two translation units

constant b = a

and

constant a = 0

is also legal, and the order in which the units are presented to the translator does not matter.

Implied Uses

At certain points in the analysis, the analyzer may treat an element of the model as if it contained uses of one or more framework definitions. These uses are called implied uses. For example, a topology definition has implied uses when a dictionary is being generated.

Whenever an implied use is called out in this specification, the definition being used must be available at the point of the implied use. If the definition is unavailable because it is hidden by another definition in an inner scope, then an error occurs. For example, this model is illegal, because the definition M.FwSizeStoreType hides the framework definition FwSizeStoreType at the point of the implied use in the type string size 100:

module M {

   type FwSizeStoreType = U16

   type T = string size 100

}

An error also occurs if the rules for resolving dot expressions cause an implied constant use to be resolved to a member of a struct value instead of a constant definition. For example, suppose this definition exists in the model:

constant A = { B = 0 }

Then there is an error at any point where there is an implied use of the constant A.B. Here A.B does represent a constant value, but it does not represent a constant definition, and so it is not a legal candidate for an implied constant use. This situation can occur because the dot syntax in FPP is overloaded to mean both qualification and member selection.