-
Notifications
You must be signed in to change notification settings - Fork 31
Check Expression Types
This algorithm traverses the source model and computes the types of constant symbols and expressions, except that array size expressions and default value expressions in type definitions are still unevaluated. As the algorithm computes types, it checks for typing errors.
-
A list tul of translation units.
-
An analysis data structure a representing the results of analysis so far. Check Type Uses must have already been run.
-
The analysis a with an updated type map, if the check passes; otherwise an error.
-
Visit each translation unit in tul with input a, yielding either a new analysis a' or an error.
Each method accepts an analysis data structure a as input and yields either a new analysis data structure a' or an error as output.
For each constant definition d:
-
If d is not in the type map of a, then
-
Visit each expression appearing in d, threading the analysis through the visits. Let a' be the resulting analysis.
-
Check that d obeys all of its typing rules. Throw an error if not.
-
Use information in the type map of a' to compute the type of d.
-
Let a'' be the analysis data structure that results from adding the type of d to a'.
-
Yield a'' as the result.
-
-
Otherwise we have already visited d; yield a as the result.
For each string type name that has a size expression, check that the size expression is a numeric type.
For each AST node n that represents an expression:
-
Compute the type T of n:
-
If the type of n is directly available (for example, the type of an integer literal expression is Integer), then use that as T.
-
Otherwise if n represents a use, then
-
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.
-
Visit the definition corresponding to s.
-
Look in the type map of a to get the type T of s. Throw an internal error if it is not there.
-
Use T as the type of n.
-
-
Otherwise
-
Visit the child expressions of n.
-
Look in the type map to get the types of the children.
-
Check that n obeys all of its typing rules. Throw an error if not.
-
Compute the type T of n.
-
-
-
Update the type map with the mapping of n to T.