| 1 | package com.sun.fortress.compiler.phases; |
|---|
| 2 | |
|---|
| 3 | import com.sun.fortress.compiler.AnalyzeResult; |
|---|
| 4 | import com.sun.fortress.compiler.GlobalEnvironment; |
|---|
| 5 | import com.sun.fortress.compiler.IndexBuilder; |
|---|
| 6 | import com.sun.fortress.exceptions.MultipleStaticError; |
|---|
| 7 | import com.sun.fortress.exceptions.StaticError; |
|---|
| 8 | import com.sun.fortress.syntax_abstractions.phases.GrammarRewriter; |
|---|
| 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 GrammarPhase extends Phase { |
|---|
| 15 | |
|---|
| 16 | public GrammarPhase(Phase parentPhase) { |
|---|
| 17 | super(parentPhase); |
|---|
| 18 | } |
|---|
| 19 | |
|---|
| 20 | @Override |
|---|
| 21 | public AnalyzeResult execute() throws StaticError { |
|---|
| 22 | Debug.debug( Debug.Type.FORTRESS, 1, "Start phase GrammarPhase" ); |
|---|
| 23 | AnalyzeResult previous = parentPhase.getResult(); |
|---|
| 24 | |
|---|
| 25 | GlobalEnvironment apiEnv = |
|---|
| 26 | new GlobalEnvironment.FromMap(CollectUtil.union(repository.apis(), |
|---|
| 27 | previous.apis())); |
|---|
| 28 | |
|---|
| 29 | GrammarRewriter.ApiResult apiID = GrammarRewriter.rewriteApis(previous.apis(), apiEnv); |
|---|
| 30 | if (!apiID.isSuccessful()) { |
|---|
| 31 | throw new MultipleStaticError(apiID.errors()); |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | IndexBuilder.ApiResult apiDone = IndexBuilder.buildApis(apiID.apis(), lastModified); |
|---|
| 35 | if (!apiDone.isSuccessful()) { |
|---|
| 36 | throw new MultipleStaticError(apiDone.errors()); |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | return new AnalyzeResult(apiDone.apis(), previous.components(), |
|---|
| 40 | IterUtil.<StaticError>empty(), previous.typeEnvAtNode()); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | } |
|---|