root/trunk/ProjectFortress/src/com/sun/fortress/compiler/phases/DisambiguatePhase.java @ 2404

Revision 2404, 2.6 KB (checked in by mspiegel, 16 months ago)

[static analysis] Another refactoring of Shell.java. Static phases are now declared in package com.sun.fortress.compiler.phases.

Line 
1package com.sun.fortress.compiler.phases;
2
3import com.sun.fortress.compiler.AnalyzeResult;
4import com.sun.fortress.compiler.Disambiguator;
5import com.sun.fortress.compiler.GlobalEnvironment;
6import com.sun.fortress.compiler.IndexBuilder;
7import com.sun.fortress.exceptions.MultipleStaticError;
8import com.sun.fortress.exceptions.StaticError;
9import com.sun.fortress.useful.Debug;
10
11import edu.rice.cs.plt.collect.CollectUtil;
12import edu.rice.cs.plt.iter.IterUtil;
13
14public class DisambiguatePhase extends Phase {         
15
16        public DisambiguatePhase(Phase parentPhase) {
17                super(parentPhase);
18        }               
19       
20    @Override
21    public AnalyzeResult execute( ) throws StaticError {
22        Debug.debug( Debug.Type.FORTRESS, 1, "Start phase Disambiguate" );
23                AnalyzeResult previous = parentPhase.getResult();               
24
25                // Build a new GlobalEnvironment consisting of all APIs in a global
26                // repository combined with all APIs that have been processed in the previous
27                // step.  For now, we are implementing pure static linking, so there is
28                // no global repository.
29                GlobalEnvironment rawApiEnv =
30                        new GlobalEnvironment.FromMap(CollectUtil.union(repository.apis(),
31                                        previous.apis()));
32
33                // Rewrite all API ASTs so they include only fully qualified names, relying
34                // on the rawApiEnv constructed in the previous step. Note that, after this
35                // step, the rawApiEnv is stale and needs to be rebuilt with the new API ASTs.
36                Disambiguator.ApiResult apiDR =
37                        Disambiguator.disambiguateApis(previous.apiIterator(), rawApiEnv, repository.apis());
38                if (!apiDR.isSuccessful()) {
39                        throw new MultipleStaticError(apiDR.errors());
40                }
41
42                // Rebuild ApiIndices.
43                IndexBuilder.ApiResult apiIR =
44                        IndexBuilder.buildApis(apiDR.apis(), lastModified);
45                if (!apiIR.isSuccessful()) {
46                        throw new MultipleStaticError(apiIR.errors());
47                }
48
49                // Rebuild GlobalEnvironment.
50                GlobalEnvironment apiEnv =
51                        new GlobalEnvironment.FromMap(CollectUtil.union(repository.apis(),
52                                        apiIR.apis()));
53
54                Disambiguator.ComponentResult componentDR =
55                        Disambiguator.disambiguateComponents(previous.componentIterator(), apiEnv,
56                                        previous.components());
57                if (!componentDR.isSuccessful()) {
58                        throw new MultipleStaticError(componentDR.errors());
59                }
60
61                // Rebuild ComponentIndices.
62                IndexBuilder.ComponentResult componentsDone =
63                        IndexBuilder.buildComponents(componentDR.components(), lastModified);
64                if (!componentsDone.isSuccessful()) {
65                        throw new MultipleStaticError(componentsDone.errors());
66                }
67
68                return new AnalyzeResult(apiIR.apis(), componentsDone.components(),
69                                IterUtil.<StaticError>empty(), previous.typeEnvAtNode());
70       
71    }
72
73}
Note: See TracBrowser for help on using the browser.