| 1 | package com.sun.fortress.compiler.phases; |
|---|
| 2 | |
|---|
| 3 | import com.sun.fortress.compiler.AnalyzeResult; |
|---|
| 4 | import com.sun.fortress.compiler.Disambiguator; |
|---|
| 5 | import com.sun.fortress.compiler.GlobalEnvironment; |
|---|
| 6 | import com.sun.fortress.compiler.IndexBuilder; |
|---|
| 7 | import com.sun.fortress.exceptions.MultipleStaticError; |
|---|
| 8 | import com.sun.fortress.exceptions.StaticError; |
|---|
| 9 | import com.sun.fortress.useful.Debug; |
|---|
| 10 | |
|---|
| 11 | import edu.rice.cs.plt.collect.CollectUtil; |
|---|
| 12 | import edu.rice.cs.plt.iter.IterUtil; |
|---|
| 13 | |
|---|
| 14 | public 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 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | GlobalEnvironment rawApiEnv = |
|---|
| 30 | new GlobalEnvironment.FromMap(CollectUtil.union(repository.apis(), |
|---|
| 31 | previous.apis())); |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 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 | |
|---|
| 43 | IndexBuilder.ApiResult apiIR = |
|---|
| 44 | IndexBuilder.buildApis(apiDR.apis(), lastModified); |
|---|
| 45 | if (!apiIR.isSuccessful()) { |
|---|
| 46 | throw new MultipleStaticError(apiIR.errors()); |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 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 | |
|---|
| 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 | } |
|---|