| 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 com.sun.fortress.compiler.GlobalEnvironment; |
|---|
| 21 | import com.sun.fortress.exceptions.InterpreterBug; |
|---|
| 22 | import com.sun.fortress.exceptions.StaticError; |
|---|
| 23 | import com.sun.fortress.nodes.Api; |
|---|
| 24 | import com.sun.fortress.nodes.Component; |
|---|
| 25 | import com.sun.fortress.repository.FortressRepository; |
|---|
| 26 | |
|---|
| 27 | public enum PhaseOrder { |
|---|
| 28 | EMPTY("Empty Phase"), |
|---|
| 29 | DISAMBIGUATE("Disambiguation"), |
|---|
| 30 | GRAMMAR("Grammar Rewriting"), |
|---|
| 31 | TYPECHECK("Typechecking"), |
|---|
| 32 | DESUGAR("Desugaring"), |
|---|
| 33 | CODEGEN("Code generation"); |
|---|
| 34 | |
|---|
| 35 | private String phaseName; |
|---|
| 36 | |
|---|
| 37 | PhaseOrder(String phaseName) { |
|---|
| 38 | this.phaseName = phaseName; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | public Phase makePhase(FortressRepository repository, GlobalEnvironment env, |
|---|
| 42 | Iterable<Api> apis, Iterable<Component> components, long lastModified) throws StaticError { |
|---|
| 43 | Phase empty = new EmptyPhase(repository,env,apis,components,lastModified); |
|---|
| 44 | switch(this) { |
|---|
| 45 | case EMPTY: return empty; |
|---|
| 46 | default: return makePhaseHelper(empty); |
|---|
| 47 | } |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | private Phase makePhaseHelper(Phase emptyPhase) { |
|---|
| 51 | switch(this) { |
|---|
| 52 | case EMPTY: return emptyPhase; |
|---|
| 53 | case DISAMBIGUATE: return new DisambiguatePhase(EMPTY.makePhaseHelper(emptyPhase)); |
|---|
| 54 | case GRAMMAR: return new GrammarPhase(DISAMBIGUATE.makePhaseHelper(emptyPhase)); |
|---|
| 55 | case TYPECHECK: return new TypeCheckPhase(GRAMMAR.makePhaseHelper(emptyPhase)); |
|---|
| 56 | case DESUGAR: return new DesugarPhase(TYPECHECK.makePhaseHelper(emptyPhase)); |
|---|
| 57 | case CODEGEN: return new CodeGenerationPhase(DESUGAR.makePhaseHelper(emptyPhase)); |
|---|
| 58 | default: return InterpreterBug.bug("Unknown static analysis phase: " + phaseName); |
|---|
| 59 | } |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | @Override |
|---|
| 63 | public String toString() { |
|---|
| 64 | return phaseName; |
|---|
| 65 | } |
|---|
| 66 | |
|---|
| 67 | } |
|---|