38 import static com.sun.tools.javac.code.Flags.*; |
38 import static com.sun.tools.javac.code.Flags.*; |
39 import static com.sun.tools.javac.code.Kinds.*; |
39 import static com.sun.tools.javac.code.Kinds.*; |
40 import static com.sun.tools.javac.code.TypeTag.CLASS; |
40 import static com.sun.tools.javac.code.TypeTag.CLASS; |
41 import static com.sun.tools.javac.code.TypeTag.TYPEVAR; |
41 import static com.sun.tools.javac.code.TypeTag.TYPEVAR; |
42 import static com.sun.tools.javac.code.TypeTag.VOID; |
42 import static com.sun.tools.javac.code.TypeTag.VOID; |
|
43 import static com.sun.tools.javac.comp.CompileStates.CompileState; |
43 |
44 |
44 /** This pass translates Generic Java to conventional Java. |
45 /** This pass translates Generic Java to conventional Java. |
45 * |
46 * |
46 * <p><b>This is NOT part of any supported API. |
47 * <p><b>This is NOT part of any supported API. |
47 * If you write code that depends on this, you do so at your own risk. |
48 * If you write code that depends on this, you do so at your own risk. |
75 * For pre-Tiger source there is no need for bridge methods, so it |
76 * For pre-Tiger source there is no need for bridge methods, so it |
76 * can be skipped to get better performance for -source 1.4 etc. |
77 * can be skipped to get better performance for -source 1.4 etc. |
77 */ |
78 */ |
78 private final boolean addBridges; |
79 private final boolean addBridges; |
79 |
80 |
|
81 private final CompileStates compileStates; |
|
82 |
80 protected TransTypes(Context context) { |
83 protected TransTypes(Context context) { |
81 context.put(transTypesKey, this); |
84 context.put(transTypesKey, this); |
|
85 compileStates = CompileStates.instance(context); |
82 names = Names.instance(context); |
86 names = Names.instance(context); |
83 log = Log.instance(context); |
87 log = Log.instance(context); |
84 syms = Symtab.instance(context); |
88 syms = Symtab.instance(context); |
85 enter = Enter.instance(context); |
89 enter = Enter.instance(context); |
86 overridden = new HashMap<MethodSymbol,MethodSymbol>(); |
90 overridden = new HashMap<MethodSymbol,MethodSymbol>(); |
902 * main method |
906 * main method |
903 *************************************************************************/ |
907 *************************************************************************/ |
904 |
908 |
905 private Env<AttrContext> env; |
909 private Env<AttrContext> env; |
906 |
910 |
|
911 private static final String statePreviousToFlowAssertMsg = |
|
912 "The current compile state [%s] of class %s is previous to FLOW"; |
|
913 |
907 void translateClass(ClassSymbol c) { |
914 void translateClass(ClassSymbol c) { |
908 Type st = types.supertype(c.type); |
915 Type st = types.supertype(c.type); |
909 |
|
910 // process superclass before derived |
916 // process superclass before derived |
911 if (st.hasTag(CLASS)) |
917 if (st.hasTag(CLASS)) { |
912 translateClass((ClassSymbol)st.tsym); |
918 translateClass((ClassSymbol)st.tsym); |
|
919 } |
913 |
920 |
914 Env<AttrContext> myEnv = enter.typeEnvs.remove(c); |
921 Env<AttrContext> myEnv = enter.typeEnvs.remove(c); |
915 if (myEnv == null) |
922 if (myEnv == null) { |
916 return; |
923 return; |
|
924 } |
|
925 |
|
926 /* The two assertions below are set for early detection of any attempt |
|
927 * to translate a class that: |
|
928 * |
|
929 * 1) has no compile state being it the most outer class. |
|
930 * We accept this condition for inner classes. |
|
931 * |
|
932 * 2) has a compile state which is previous to Flow state. |
|
933 */ |
|
934 boolean envHasCompState = compileStates.get(myEnv) != null; |
|
935 if (!envHasCompState && c.outermostClass() == c) { |
|
936 Assert.error("No info for outermost class: " + myEnv.enclClass.sym); |
|
937 } |
|
938 |
|
939 if (envHasCompState && |
|
940 CompileState.FLOW.isAfter(compileStates.get(myEnv))) { |
|
941 Assert.error(String.format(statePreviousToFlowAssertMsg, |
|
942 compileStates.get(myEnv), myEnv.enclClass.sym)); |
|
943 } |
|
944 |
917 Env<AttrContext> oldEnv = env; |
945 Env<AttrContext> oldEnv = env; |
918 try { |
946 try { |
919 env = myEnv; |
947 env = myEnv; |
920 // class has not been translated yet |
948 // class has not been translated yet |
921 |
949 |