| 1 | package com.sun.fortress.compiler.phases; |
|---|
| 2 | |
|---|
| 3 | import com.sun.fortress.compiler.GlobalEnvironment; |
|---|
| 4 | import com.sun.fortress.exceptions.InterpreterBug; |
|---|
| 5 | import com.sun.fortress.exceptions.StaticError; |
|---|
| 6 | import com.sun.fortress.nodes.Api; |
|---|
| 7 | import com.sun.fortress.nodes.Component; |
|---|
| 8 | import com.sun.fortress.repository.FortressRepository; |
|---|
| 9 | |
|---|
| 10 | public enum PhaseOrder { |
|---|
| 11 | EMPTY("Empty Phase"), |
|---|
| 12 | DISAMBIGUATE("Disambiguation"), |
|---|
| 13 | GRAMMAR("Grammar Rewriting"), |
|---|
| 14 | TYPECHECK("Typechecking"), |
|---|
| 15 | DESUGAR("Desugaring"), |
|---|
| 16 | CODEGEN("Code generation"); |
|---|
| 17 | |
|---|
| 18 | private String phaseName; |
|---|
| 19 | |
|---|
| 20 | PhaseOrder(String phaseName) { |
|---|
| 21 | this.phaseName = phaseName; |
|---|
| 22 | } |
|---|
| 23 | |
|---|
| 24 | public Phase makePhase(FortressRepository repository, GlobalEnvironment env, |
|---|
| 25 | Iterable<Api> apis, Iterable<Component> components, long lastModified) throws StaticError { |
|---|
| 26 | Phase empty = new EmptyPhase(repository,env,apis,components,lastModified); |
|---|
| 27 | switch(this) { |
|---|
| 28 | case EMPTY: return empty; |
|---|
| 29 | default: return makePhaseHelper(empty); |
|---|
| 30 | } |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | private Phase makePhaseHelper(Phase emptyPhase) { |
|---|
| 34 | switch(this) { |
|---|
| 35 | case EMPTY: return emptyPhase; |
|---|
| 36 | case DISAMBIGUATE: return new DisambiguatePhase(EMPTY.makePhaseHelper(emptyPhase)); |
|---|
| 37 | case GRAMMAR: return new GrammarPhase(DISAMBIGUATE.makePhaseHelper(emptyPhase)); |
|---|
| 38 | case TYPECHECK: return new TypeCheckPhase(GRAMMAR.makePhaseHelper(emptyPhase)); |
|---|
| 39 | case DESUGAR: return new DesugarPhase(TYPECHECK.makePhaseHelper(emptyPhase)); |
|---|
| 40 | case CODEGEN: return new CodeGenerationPhase(DESUGAR.makePhaseHelper(emptyPhase)); |
|---|
| 41 | default: return InterpreterBug.bug("Unknown static analysis phase: " + phaseName); |
|---|
| 42 | } |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | @Override |
|---|
| 46 | public String toString() { |
|---|
| 47 | return phaseName; |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | } |
|---|