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

Revision 2406, 3.4 KB (checked in by mspiegel, 16 months ago)

Added copyright notices.

Line 
1/*******************************************************************************
2  Copyright 2008 Sun Microsystems, Inc.,
3  4150 Network Circle, Santa Clara, California 95054, U.S.A.
4  All rights reserved.
5
6  U.S. Government Rights - Commercial software.
7  Government users are subject to the Sun Microsystems, Inc. standard
8  license agreement and applicable provisions of the FAR and its supplements.
9
10  Use is subject to license terms.
11
12  This distribution may include materials developed by third parties.
13
14  Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered
15  trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
16  ******************************************************************************/
17
18package com.sun.fortress.compiler.phases;
19
20import com.sun.fortress.compiler.AnalyzeResult;
21import com.sun.fortress.compiler.Disambiguator;
22import com.sun.fortress.compiler.GlobalEnvironment;
23import com.sun.fortress.compiler.IndexBuilder;
24import com.sun.fortress.exceptions.MultipleStaticError;
25import com.sun.fortress.exceptions.StaticError;
26import com.sun.fortress.useful.Debug;
27
28import edu.rice.cs.plt.collect.CollectUtil;
29import edu.rice.cs.plt.iter.IterUtil;
30
31public class DisambiguatePhase extends Phase {         
32
33        public DisambiguatePhase(Phase parentPhase) {
34                super(parentPhase);
35        }               
36       
37    @Override
38    public AnalyzeResult execute( ) throws StaticError {
39        Debug.debug( Debug.Type.FORTRESS, 1, "Start phase Disambiguate" );
40                AnalyzeResult previous = parentPhase.getResult();               
41
42                // Build a new GlobalEnvironment consisting of all APIs in a global
43                // repository combined with all APIs that have been processed in the previous
44                // step.  For now, we are implementing pure static linking, so there is
45                // no global repository.
46                GlobalEnvironment rawApiEnv =
47                        new GlobalEnvironment.FromMap(CollectUtil.union(repository.apis(),
48                                        previous.apis()));
49
50                // Rewrite all API ASTs so they include only fully qualified names, relying
51                // on the rawApiEnv constructed in the previous step. Note that, after this
52                // step, the rawApiEnv is stale and needs to be rebuilt with the new API ASTs.
53                Disambiguator.ApiResult apiDR =
54                        Disambiguator.disambiguateApis(previous.apiIterator(), rawApiEnv, repository.apis());
55                if (!apiDR.isSuccessful()) {
56                        throw new MultipleStaticError(apiDR.errors());
57                }
58
59                // Rebuild ApiIndices.
60                IndexBuilder.ApiResult apiIR =
61                        IndexBuilder.buildApis(apiDR.apis(), lastModified);
62                if (!apiIR.isSuccessful()) {
63                        throw new MultipleStaticError(apiIR.errors());
64                }
65
66                // Rebuild GlobalEnvironment.
67                GlobalEnvironment apiEnv =
68                        new GlobalEnvironment.FromMap(CollectUtil.union(repository.apis(),
69                                        apiIR.apis()));
70
71                Disambiguator.ComponentResult componentDR =
72                        Disambiguator.disambiguateComponents(previous.componentIterator(), apiEnv,
73                                        previous.components());
74                if (!componentDR.isSuccessful()) {
75                        throw new MultipleStaticError(componentDR.errors());
76                }
77
78                // Rebuild ComponentIndices.
79                IndexBuilder.ComponentResult componentsDone =
80                        IndexBuilder.buildComponents(componentDR.components(), lastModified);
81                if (!componentsDone.isSuccessful()) {
82                        throw new MultipleStaticError(componentsDone.errors());
83                }
84
85                return new AnalyzeResult(apiIR.apis(), componentsDone.components(),
86                                IterUtil.<StaticError>empty(), previous.typeEnvAtNode());
87       
88    }
89
90}
Note: See TracBrowser for help on using the browser.