35 import com.sun.tools.javac.jvm.*; |
35 import com.sun.tools.javac.jvm.*; |
36 import com.sun.tools.javac.util.*; |
36 import com.sun.tools.javac.util.*; |
37 import com.sun.tools.javac.util.List; |
37 import com.sun.tools.javac.util.List; |
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.jvm.ByteCodes.*; |
39 import static com.sun.tools.javac.jvm.ByteCodes.*; |
|
40 import static com.sun.tools.javac.code.TypeTag.*; |
40 |
41 |
41 /** A class that defines all predefined constants and operators |
42 /** A class that defines all predefined constants and operators |
42 * as well as special classes such as java.lang.Object, which need |
43 * as well as special classes such as java.lang.Object, which need |
43 * to be known to the compiler. All symbols are held in instance |
44 * to be known to the compiler. All symbols are held in instance |
44 * fields. This makes it possible to work in multiple concurrent |
45 * fields. This makes it possible to work in multiple concurrent |
62 return instance; |
63 return instance; |
63 } |
64 } |
64 |
65 |
65 /** Builtin types. |
66 /** Builtin types. |
66 */ |
67 */ |
67 public final Type byteType = new Type(TypeTags.BYTE, null); |
68 public final Type byteType = new Type(BYTE, null); |
68 public final Type charType = new Type(TypeTags.CHAR, null); |
69 public final Type charType = new Type(CHAR, null); |
69 public final Type shortType = new Type(TypeTags.SHORT, null); |
70 public final Type shortType = new Type(SHORT, null); |
70 public final Type intType = new Type(TypeTags.INT, null); |
71 public final Type intType = new Type(INT, null); |
71 public final Type longType = new Type(TypeTags.LONG, null); |
72 public final Type longType = new Type(LONG, null); |
72 public final Type floatType = new Type(TypeTags.FLOAT, null); |
73 public final Type floatType = new Type(FLOAT, null); |
73 public final Type doubleType = new Type(TypeTags.DOUBLE, null); |
74 public final Type doubleType = new Type(DOUBLE, null); |
74 public final Type booleanType = new Type(TypeTags.BOOLEAN, null); |
75 public final Type booleanType = new Type(BOOLEAN, null); |
75 public final Type botType = new BottomType(); |
76 public final Type botType = new BottomType(); |
76 public final JCNoType voidType = new JCNoType(TypeTags.VOID); |
77 public final JCNoType voidType = new JCNoType(VOID); |
77 |
78 |
78 private final Names names; |
79 private final Names names; |
79 private final ClassReader reader; |
80 private final ClassReader reader; |
80 private final Target target; |
81 private final Target target; |
81 |
82 |
175 /** The symbol representing the close method on TWR AutoCloseable type */ |
176 /** The symbol representing the close method on TWR AutoCloseable type */ |
176 public final MethodSymbol autoCloseableClose; |
177 public final MethodSymbol autoCloseableClose; |
177 |
178 |
178 /** The predefined type that belongs to a tag. |
179 /** The predefined type that belongs to a tag. |
179 */ |
180 */ |
180 public final Type[] typeOfTag = new Type[TypeTags.TypeTagCount]; |
181 public final Type[] typeOfTag = new Type[TypeTag.getTypeTagCount()]; |
181 |
182 |
182 /** The name of the class that belongs to a basix type tag. |
183 /** The name of the class that belongs to a basix type tag. |
183 */ |
184 */ |
184 public final Name[] boxedName = new Name[TypeTags.TypeTagCount]; |
185 public final Name[] boxedName = new Name[TypeTag.getTypeTagCount()]; |
185 |
186 |
186 /** A set containing all operator names. |
187 /** A set containing all operator names. |
187 */ |
188 */ |
188 public final Set<Name> operatorNames = new HashSet<Name>(); |
189 public final Set<Name> operatorNames = new HashSet<Name>(); |
189 |
190 |
200 */ |
201 */ |
201 public final Map<Name, PackageSymbol> packages = new HashMap<Name, PackageSymbol>(); |
202 public final Map<Name, PackageSymbol> packages = new HashMap<Name, PackageSymbol>(); |
202 |
203 |
203 public void initType(Type type, ClassSymbol c) { |
204 public void initType(Type type, ClassSymbol c) { |
204 type.tsym = c; |
205 type.tsym = c; |
205 typeOfTag[type.tag] = type; |
206 typeOfTag[type.tag.ordinal()] = type; |
206 } |
207 } |
207 |
208 |
208 public void initType(Type type, String name) { |
209 public void initType(Type type, String name) { |
209 initType( |
210 initType( |
210 type, |
211 type, |
212 PUBLIC, names.fromString(name), type, rootPackage)); |
213 PUBLIC, names.fromString(name), type, rootPackage)); |
213 } |
214 } |
214 |
215 |
215 public void initType(Type type, String name, String bname) { |
216 public void initType(Type type, String name, String bname) { |
216 initType(type, name); |
217 initType(type, name); |
217 boxedName[type.tag] = names.fromString("java.lang." + bname); |
218 boxedName[type.tag.ordinal()] = names.fromString("java.lang." + bname); |
218 } |
219 } |
219 |
220 |
220 /** The class symbol that owns all predefined symbols. |
221 /** The class symbol that owns all predefined symbols. |
221 */ |
222 */ |
222 public final ClassSymbol predefClass; |
223 public final ClassSymbol predefClass; |
322 }; |
323 }; |
323 } |
324 } |
324 } |
325 } |
325 |
326 |
326 public void synthesizeBoxTypeIfMissing(final Type type) { |
327 public void synthesizeBoxTypeIfMissing(final Type type) { |
327 ClassSymbol sym = reader.enterClass(boxedName[type.tag]); |
328 ClassSymbol sym = reader.enterClass(boxedName[type.tag.ordinal()]); |
328 final Completer completer = sym.completer; |
329 final Completer completer = sym.completer; |
329 if (completer != null) { |
330 if (completer != null) { |
330 sym.completer = new Completer() { |
331 sym.completer = new Completer() { |
331 public void complete(Symbol sym) throws CompletionFailure { |
332 public void complete(Symbol sym) throws CompletionFailure { |
332 try { |
333 try { |
364 |
365 |
365 names = Names.instance(context); |
366 names = Names.instance(context); |
366 target = Target.instance(context); |
367 target = Target.instance(context); |
367 |
368 |
368 // Create the unknown type |
369 // Create the unknown type |
369 unknownType = new Type(TypeTags.UNKNOWN, null) { |
370 unknownType = new Type(UNKNOWN, null) { |
370 @Override |
371 @Override |
371 public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
372 public <R, P> R accept(TypeVisitor<R, P> v, P p) { |
372 return v.visitUnknown(this, p); |
373 return v.visitUnknown(this, p); |
373 } |
374 } |
374 }; |
375 }; |