Skip to content

Enter Symbols

Rob Bocchino edited this page Jun 4, 2024 · 8 revisions

This algorithm traverses a source model and enters symbols into their scopes.

Input

  1. A list tul of translation units.

  2. An analysis data structure a representing the results of analysis so far.

Output

  1. An updated analysis data structure a with symbols entered.

Procedure

  1. Translation unit lists: Visit each translation unit tu in tul in order.

  2. Translation units: Visit a translation unit tu by visiting its members tum.

  3. Translation unit members: Visit a translation unit member tum as follows:

    1. Module definitions: If tum is a module definition d with name n, then

      1. Look up the symbol sym with unqualified name n in the innermost nested scope of a in the value name group.

      2. If sym exists and is a module symbol, then let s be the scope corresponding to sym in the symbol-scope map of a.

      3. Otherwise if sym exists then report an error.

      4. Otherwise

        1. Let s be a fresh scope.

        2. Construct a module symbol sym.

        3. Add the mapping from n to sym in the innermost nested scope of a in every name group.

        4. Add sym to the parent symbol map of a.

      5. Add n to the scope name list of a.

      6. Push s onto the nested scope of a.

      7. Visit each translation unit member of d, yielding a new analysis data structure a.

        1. Let s' be the innermost nested scope of a.

        2. Add the mapping from sym to s' in the symbol-scope map of a.

      8. Pop s' off the nested scope of a.

      9. Remove n from the scope name list of a.

    2. Constant definitions: If tum is a constant definition d with name n, then

      1. Construct the unique symbol s of the correct kind for d.

      2. Add the mapping from n to s in the innermost nested scope of a in the value name group.

      3. Add s to the parent symbol map of a.

    3. Type definitions: If tum is an abstract type, array, or struct definition d with name n, then

      1. Construct the unique symbol s of the correct kind for d.

      2. Add the mapping from n to s in the innermost nested scope of a in the type name group.

      3. Add s to the parent symbol map of a.

    4. Enum definitions: If tum is an enum definition d with name n, then

      1. Construct the unique enum definition symbol sym for d.

      2. Add the mapping from n to sym in the innermost nested scope of a in the type and the value name groups.

      3. Add sym to the parent symbol map of a.

      4. Create a fresh scope s.

      5. Push s onto the nested scope of a.

      6. Add n to the scope name list of a.

      7. Visit each enumerated constant definition of d, yielding a new analysis data structure a.

      8. Remove n from the scope name list of a.

      9. Let s' be the innermost nested scope of a.

      10. Add the mapping from sym to s' in the symbol-scope map of a.

      11. Pop s' off the nested scope of a.

    5. Port definitions: If tum is a port definition d with name n, then

      1. Construct the unique symbol s of the correct kind for d.

      2. Add the mapping from n to s in the innermost nested scope of a in the port name group.

      3. Add s to the parent symbol map of a.

    6. Component definitions: If tum is a component definition d with name n, then

      1. Construct the unique component definition symbol sym for d.

      2. Add the mapping from n to sym in the innermost nested scope of a in the component, type, and value name groups.

      3. Add sym to the parent symbol map of a.

      4. Create a fresh scope s.

      5. Push s onto the nested scope of a.

      6. Add n to the scope name list of a.

      7. Visit each component member of d, yielding a new analysis data structure a.

      8. Remove n from the scope name list of a.

      9. Let s' be the innermost nested scope of a.

      10. Add the mapping from sym to s' in the symbol-scope map of a.

      11. Pop s' off the nested scope of a.

    7. Component instance definitions: If tum is a component instance definition d with name n, then

      1. Construct the unique symbol s of the correct kind for d.

      2. Add the mapping from n to s in the innermost nested scope of a in the component instance name group.

      3. Add s to the parent symbol map of a.

    8. Topology definitions: If tum is a topology definition d with name n, then

      1. Construct the unique symbol s of the correct kind for d.

      2. Add the mapping from n to s in the innermost nested scope of a in the topology name group.

      3. Add s to the parent symbol map of a.

  4. Enumerated constant definitions: Visit an enumerated constant definition d with name n as follows:

    1. Construct the unique enumerated constant definition symbol s for d.

    2. Add the mapping from n to s in the innermost nested scope of a in the value name group.

      1. Add s to the parent symbol map of a.

  5. Component members: Visit a component member cm as follows:

    1. If cm corresponds to a translation unit member tum, then visit cm in the same way as tum.

    2. Otherwise do nothing.