| 1 | package com.sun.fortress.compiler.phases; |
|---|
| 2 | |
|---|
| 3 | import com.sun.fortress.compiler.AnalyzeResult; |
|---|
| 4 | import com.sun.fortress.compiler.Desugarer; |
|---|
| 5 | import com.sun.fortress.compiler.GlobalEnvironment; |
|---|
| 6 | import com.sun.fortress.exceptions.MultipleStaticError; |
|---|
| 7 | import com.sun.fortress.exceptions.StaticError; |
|---|
| 8 | import com.sun.fortress.useful.Debug; |
|---|
| 9 | |
|---|
| 10 | import edu.rice.cs.plt.collect.CollectUtil; |
|---|
| 11 | import edu.rice.cs.plt.iter.IterUtil; |
|---|
| 12 | |
|---|
| 13 | public class DesugarPhase extends Phase { |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | public DesugarPhase(Phase parentPhase) { |
|---|
| 17 | super(parentPhase); |
|---|
| 18 | } |
|---|
| 19 | |
|---|
| 20 | @Override |
|---|
| 21 | public AnalyzeResult execute( ) throws StaticError { |
|---|
| 22 | Debug.debug( Debug.Type.FORTRESS, 1, "Start phase Desugar" ); |
|---|
| 23 | AnalyzeResult previous = parentPhase.getResult(); |
|---|
| 24 | |
|---|
| 25 | GlobalEnvironment apiEnv = new GlobalEnvironment.FromMap(CollectUtil.union(repository.apis(), |
|---|
| 26 | previous.apis())); |
|---|
| 27 | |
|---|
| 28 | Desugarer.ApiResult apiDSR = Desugarer.desugarApis(previous.apis(), apiEnv); |
|---|
| 29 | |
|---|
| 30 | if ( ! apiDSR.isSuccessful() ){ |
|---|
| 31 | throw new MultipleStaticError(apiDSR.errors()); |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | Desugarer.ComponentResult componentDSR = Desugarer.desugarComponents(previous.components(), apiEnv); |
|---|
| 35 | |
|---|
| 36 | if ( ! componentDSR.isSuccessful() ){ |
|---|
| 37 | throw new MultipleStaticError(componentDSR.errors()); |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | return new AnalyzeResult(apiDSR.apis(), componentDSR.components(), |
|---|
| 41 | IterUtil.<StaticError>empty(), previous.typeEnvAtNode()); |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | } |
|---|