-
Notifications
You must be signed in to change notification settings - Fork 34
Check Use Def Cycles
This algorithm traverses the a source model and checks that there are no cycles in the use-def graph.
-
A list tul of translation units.
-
An analysis data structure a representing the results of analysis so far. The use-def map must already be computed. The visited symbol set, use-def path set, and use-def path list must be empty.
Each method accepts an analysis data structure a as input and yields either a new analysis data structure a' or an error as output.
-
Translation units: For each translation unit tu, visit each definition appearing in tu.
-
Definitions: For each definition d that may be involved in a cycle:
-
Let s be the unique symbol representing d.
-
Check whether s appears in the use-def symbol set of a. If it does, then the use-def matching list of a represents a cycle. Throw a semantic error. Use the use-def matching list to construct the cycle for the error message.
-
Otherwise if s is not in the visited symbol set of a, then
-
Let a' be the analysis data structure that results from adding s to the use-def symbol set set of a.
-
Visit each use appearing in d with input a'.
-
Let a'' be the analysis data structure that results from adding s to the visited symbol set of a.
-
Yield a'' as the result.
-
-
Otherwise we have already visited s; yield a as the result.
-
-
Uses: For each AST node n that represents a use:
-
Look in the use-def map of n to get the symbol s corresponding to n. Throw an internal error if it is not there.
-
Use n and s to construct a use-def matching m.
-
Let a' be the analysis data structure that results from adding m to the use-def matching list of a.
-
Visit the definition corresponding to s with input a'.
-
Return a or an error.
-