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