Skip to content

Computing Dependencies

Rob Bocchino edited this page Nov 19, 2025 · 15 revisions

This algorithm computes dependencies for a list of translation units.

Input

  1. An analysis data structure a. The input file set of a must record the set of files presented for analysis.

  2. A list tul of FPP translation units.

Output

Procedure

Run the dependency algorithm on tul.

Dependency Algorithm

To run the dependency algorithm on a translation unit list tul, do the following:

  1. Resolve include specifiers: Recursively resolve include specifiers in tul. Add the path of each included file to the included file set in a. If the level of a is zero, then add the path of each included file to the direct dependency file set in a.

  2. Build the location specifier map: Traverse each translation unit tu in tul, updating the scope name list as modules are entered and exited. For each location specifier s encountered, do the following:

    1. Let k be the symbol kind specified in s. For example, in the specifier locate constant c at "c.fpp", the symbol kind is constant.

    2. Compute the qualified name q associated with s. For example, if the location specifier locate constant c at "c.fpp" appears inside module M, then q is M.c.

    3. Check the location specifier map for a mapping from (k, q) to some location specifier s'.

    4. If there is no such mapping, then add the mapping from (k, q) to s.

    5. Otherwise

      1. Compute the absolute path p associated with s. For example, if the location specifier locate constant c at "c.fpp" appears in the file /home/foo/bar/baz.fpp, then p is /home/foo/bar/c.fpp.

      2. Compute the absolute path p' associated with s'.

      3. If p does not equal p', then throw an error.

      4. Check that s and s' are either both dictionary specifiers or both not dictionary specifiers. If not, then throw an error.

  3. Construct the implied use map: Run the algorithm for constructing the implied use map.

  4. Add dependencies: Traverse each translation unit tu in tul, updating the scope name list as modules are entered and exited.

    1. For each use of a symbol u encountered in tu, including all the implied uses, do the following:

      1. Resolve u to a list l of possible qualified names. For example, if u is c.d and it appears inside module B which appears inside module A, then l is A.B.c.d, A.c.d, c.d. Construct l with the innermost name first. For example, A.B.c.d appears before A.c.d.

      2. For each qualified name q in l, in order starting with the head of l, check the location specifier map of a for a location specifier s corresponding to q.

      3. If s exists, then add the dependencies for s.

    2. For each topology definition T encountered in tu, if this is the first topology seen in dependency checking, then

      1. For each location specifier s in the location specifier map, if s specifies dictionary, then add the dependencies for s.

      2. Mark in a that we have seen a topology.

    3. For each location specifier s encountered in tu, if we have seen a topology and s specifies dictionary, then add the dependencies for s.

  5. Eliminate included files as dependencies: For each file f in the included file set, if f appears in the dependency file set, then delete it from the set. The dependency is already recorded in the file that includes f.

Adding Dependencies for a Location Specifier

To add a dependency for a location specifier s, do the following:

  1. Compute the absolute path p associated with s.

  2. If p is in the input file set of a or is already in the dependency file set of a, then do nothing.

  3. Otherwise

    1. If the level of a is zero, then add p to the direct dependency file set of a.

    2. Add p to the dependency file set of a.

    3. If the file f at p exists, then

      1. Parse f, generating a translation unit tu.

      2. Run the dependency algorithm on the list [ tu ] with the value of a computed so far, but with an empty scope name list. Restore the current level and scope name list and let the result be the new a.

    4. Otherwise add p to the missing dependency file set of a.

Clone this wiki locally