If a domain D is defined in a file d and extended in a file e then the above code will not yet have added the fact that e depends on d.
Without the help of a proper Aldor parser, the task of finding the right dependencies if extensions are involved is impossible. Assume there are two files x and y with the following content.
--file x
#include "aldor" define Cat1: Category == with {foo1: ()->()} extend Integer: Cat1 == add {import from String; ...} |
--file y
#include "aldor" define Cat2: Category == with {foo2: ()->()} extend String: Cat2 == add {import from Integer; ... foo1() ...} |
Clearly, the file x should be compiled before y. However, the code we are presenting below does not necessarily get the dependency right, because it only looks for constructor names. So the information that the name foo1 is used in y is not taken into account. Note that it would be even hard to find out for a simple Perl program whether the appearance of foo1 really refers to an implementation of Cat1 in Integer or an implementation in yet another domain that comes from another file.
A simpler problematic case is
--file x
#include "aldor" extend Integer: with {foo: ()->()} == add {import from Dom; ...} |
--file y
#include "aldor" Dom: Cat == add {import from Integer; ...} |
where y would have to be compiled before x. This case, however, is resolved correctly already by the code above, since the identifier Dom appears explicitly as a use in x.
We try to place the extension of domains as early as possible into the compilation chain.
If a domain A is extended in a file x and A is used in a file y, then y depends on x if and only if x does not depend on y for some other reasons. For example, y could have defined a domain B which is used in x.
In order to find whether or not x already depends on y we simply saturate the dependencies that have been computed so far and then we check whether $DEP{x}{y} is zero.
The treatment of extensions is problematic.
For a domain, like MachineInteger, for example, that is not defined in the same library, it is not necessary to put it into a separate file. However, also in this case there can be only one extension.
How do we resolve dependencies? Assume there are 3 domains A, B, and C defined in the files a, b, and c respectively. Both in b and c the domain A is mentioned, so we easily find that c and b depend on a. Now there is a file a′ that extends A and uses B but not C for this extension. So a′ depends on a and b. In such a case, we add a dependency, namely c depends on a′. It basically means that we place extensions in the dependency hierarchy as early as possible.