-
Notifications
You must be signed in to change notification settings - Fork 31
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: Otherwise 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: Otherwise 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: Otherwise 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.
-
-
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 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, and port 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 from e' to sym' in the use-def map of a. If no such mapping exists, then throw an internal error.
-
Look up the mapping from sym' to s in the symbol-scope map of a. If no such mapping exists, then throw a semantic 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.