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

Revision 2404, 2.0 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 java.util.Map;
4
5import com.sun.fortress.compiler.AnalyzeResult;
6import com.sun.fortress.compiler.GlobalEnvironment;
7import com.sun.fortress.compiler.IndexBuilder;
8import com.sun.fortress.compiler.StaticChecker;
9import com.sun.fortress.compiler.typechecker.TypeEnv;
10import com.sun.fortress.exceptions.MultipleStaticError;
11import com.sun.fortress.exceptions.StaticError;
12import com.sun.fortress.nodes.Node;
13import com.sun.fortress.nodes_util.Span;
14import com.sun.fortress.useful.Debug;
15
16import edu.rice.cs.plt.collect.CollectUtil;
17import edu.rice.cs.plt.iter.IterUtil;
18import edu.rice.cs.plt.tuple.Option;
19import edu.rice.cs.plt.tuple.Pair;
20
21public class TypeCheckPhase extends Phase {
22       
23    public TypeCheckPhase(Phase parentPhase) {
24                super(parentPhase);
25        }
26
27        @Override
28    public AnalyzeResult execute( ) throws StaticError {
29        Debug.debug( Debug.Type.FORTRESS, 1, "Start phase TypeCheck" );
30                AnalyzeResult previous = parentPhase.getResult();       
31
32        IndexBuilder.ApiResult apiIndex = IndexBuilder.buildApis(previous.apiIterator(), lastModified);
33        IndexBuilder.ComponentResult componentIndex = IndexBuilder.buildComponents(previous.componentIterator(), lastModified);
34        GlobalEnvironment apiEnv = new GlobalEnvironment.FromMap(CollectUtil.union(repository.apis(),
35                                                     apiIndex.apis()));
36
37        StaticChecker.ApiResult apiSR = StaticChecker.checkApis( apiIndex.apis(), apiEnv );
38
39        if ( !apiSR.isSuccessful() ){
40                throw new MultipleStaticError(apiSR.errors());
41        }
42
43        StaticChecker.ComponentResult componentSR =
44                StaticChecker.checkComponents( componentIndex.components(), env);
45
46        if ( !componentSR.isSuccessful() ){
47                throw new MultipleStaticError(componentSR.errors());
48        }
49
50        return new AnalyzeResult(apiSR.apis(), componentSR.components(),
51                        IterUtil.<StaticError> empty(),
52                        Option.<Map<Pair<Node,Span>, TypeEnv>>some(componentSR.typeEnvAtNode()));
53    }
54
55}
Note: See TracBrowser for help on using the browser.