| 1 | package com.sun.fortress.compiler.phases; |
|---|
| 2 | |
|---|
| 3 | import java.util.Map; |
|---|
| 4 | |
|---|
| 5 | import com.sun.fortress.compiler.AnalyzeResult; |
|---|
| 6 | import com.sun.fortress.compiler.GlobalEnvironment; |
|---|
| 7 | import com.sun.fortress.compiler.IndexBuilder; |
|---|
| 8 | import com.sun.fortress.compiler.StaticChecker; |
|---|
| 9 | import com.sun.fortress.compiler.typechecker.TypeEnv; |
|---|
| 10 | import com.sun.fortress.exceptions.MultipleStaticError; |
|---|
| 11 | import com.sun.fortress.exceptions.StaticError; |
|---|
| 12 | import com.sun.fortress.nodes.Node; |
|---|
| 13 | import com.sun.fortress.nodes_util.Span; |
|---|
| 14 | import com.sun.fortress.useful.Debug; |
|---|
| 15 | |
|---|
| 16 | import edu.rice.cs.plt.collect.CollectUtil; |
|---|
| 17 | import edu.rice.cs.plt.iter.IterUtil; |
|---|
| 18 | import edu.rice.cs.plt.tuple.Option; |
|---|
| 19 | import edu.rice.cs.plt.tuple.Pair; |
|---|
| 20 | |
|---|
| 21 | public 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 | } |
|---|