-
Notifications
You must be signed in to change notification settings - Fork 53
Check Uses
This algorithm traverses a source model and checks that each use refers to definition. It also constructs the use-def map.
-
A list tul of translation units.
-
An analysis data structure a representing the results of analysis so far.
-
Translation unit lists: Visit each translation unit tu in tul in order.
-
Translation units: Visit a translation unit tu by visiting its members tum.
-
Translation unit members: Visit a translation unit member tum as follows:
-
Module definitions: If tum is a module definition d with name n, then
-
Look up the module symbol sym associated with the unqualified name n as described in Expressions below.
-
Look up the mapping from sym to s in the symbol-scope map of a. If no such mapping exists, then throw an internal error.
-
Push s onto the nested scope of a.
-
Visit each translation unit member of d.
-
Pop s off the nested scope of a.
-
-
Enum definitions: If tum is an enum definition d with name n, then
-
Visit the type of d if it is present.
-
Construct the unique enum symbol sym corresponding to d.
-
Look up the mapping from sym to s in the symbol-scope map of a. If no such mapping exists, then throw an internal error.
-
Push s onto the nested scope of a.
-
Visit each enumerated constant definition of d.
-
Pop s off the nested scope of a.
-
-
Component definitions: If tum is a component definition d with name n, then
-
Construct the unique component symbol sym corresponding to d.
-
Look up the mapping from sym to s in the symbol-scope map of a. If no such mapping exists, then throw an internal error.
-
Push s onto the nested scope of a.
-
Visit each member of d.
-
Pop s off the nested scope of a.
-
-
Interface definitions: If tum is a component instance definition, then visit all the expressions, and port uses uses appearing in tum.
-
Component instance definitions: If tum is a component instance definition, then visit all the type names, expressions, and component uses appearing in tum.
-
Topology definitions: If tum is a topology definition, then
-
Visit all the implied uses of tum.
-
Visit all the type names, expressions, and component instance uses appearing in tum.
-
-
Other definitions: If tum is an abstract type, array, constant, or port definition, then visit all the type names and expressions appearing in tum.
-
-
Enumerated constant definitions: Visit an enumerated constant definition d as follows:
-
If d contains an expression e, then visit e.
-
-
Component members: Visit a component member cm as follows:
-
If cm corresponds to a translation member tum, then visit cm in the same manner as tum.
-
Otherwise visit all the expressions, types, port uses, implied uses, and state machine uses appearing in cm.
-
-
Expressions: Visit an expression e as follows:
-
Unqualified names: If e is an unqualified name n, then
-
Look up the mapping from n to sym in the innermost nested scope of a in the value name group. If no such mapping exists, then throw a semantic error.
-
Record the mapping from e to sym in the use-def map of a.
-
-
Dot expressions: Otherwise if e is a dot expression e'.n, then
-
Visit e'.
-
Look up the mapping of e' to sym' in the use-def map
-
If sym' does not exist or sym' exists and is a constant symbol, this dot expression selects a member of the constant and therefore does not introduce an additional use. Exit this visitor.
-
Otherwise if sym' exists, get the mapping from sym' to s in the symbol-scope map of a. If no such mapping exists, then throw an internal error.
-
Look up the mapping from n to sym in s. If no such mapping exists, then throw a semantic error.
-
Record the mapping from e to sym in the use-def map of a.
-
-
-
Other expressions: Otherwise visit each expression and type appearing in e.
-
-
Type names: Visit a type name tn as follows:
-
Unqualified names: Use the same algorithm as for unqualified name expressions, but use the type name group instead of the value name group.
-
Qualified names: Use the same algorithm as for dot expressions, but use the type name group instead of the value name group.
-
Other types: Nothing to do.
-
-
Port uses: A port use pu is a qualified or unqualified name. Visit pu in the same way as a qualified or unqualified type name, but use the port name group instead of the type name group.
-
Component instance uses: A component instance use ciu is a qualified or unqualified name. Visit ciu in the same way as for a port use, but use the component instance name group instead of the port name group.
-
Implied uses: An implied use iu is a qualified or unqualified name provided by the implied use map. Visit iu like a constant expression, a type use, or a port use.