author | jjg |
Fri, 01 Aug 2008 15:23:18 -0700 | |
changeset 1037 | c6b315a34dc6 |
parent 10 | 06bc494ca11e |
child 1257 | 873b053bf757 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
2 |
* Copyright 1999-2006 Sun Microsystems, Inc. All Rights Reserved. |
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
package com.sun.tools.javac.code; |
|
27 |
||
28 |
import java.util.*; |
|
29 |
||
30 |
import com.sun.tools.javac.util.*; |
|
31 |
import com.sun.tools.javac.util.List; |
|
32 |
import com.sun.tools.javac.code.Symbol.*; |
|
33 |
import com.sun.tools.javac.code.Type.*; |
|
34 |
import com.sun.tools.javac.jvm.*; |
|
35 |
||
36 |
import static com.sun.tools.javac.jvm.ByteCodes.*; |
|
37 |
import static com.sun.tools.javac.code.Flags.*; |
|
38 |
||
39 |
/** A class that defines all predefined constants and operators |
|
40 |
* as well as special classes such as java.lang.Object, which need |
|
41 |
* to be known to the compiler. All symbols are held in instance |
|
42 |
* fields. This makes it possible to work in multiple concurrent |
|
43 |
* projects, which might use different class files for library classes. |
|
44 |
* |
|
45 |
* <p><b>This is NOT part of any API supported by Sun Microsystems. If |
|
46 |
* you write code that depends on this, you do so at your own risk. |
|
47 |
* This code and its internal interfaces are subject to change or |
|
48 |
* deletion without notice.</b> |
|
49 |
*/ |
|
50 |
public class Symtab { |
|
51 |
/** The context key for the symbol table. */ |
|
52 |
protected static final Context.Key<Symtab> symtabKey = |
|
53 |
new Context.Key<Symtab>(); |
|
54 |
||
55 |
/** Get the symbol table instance. */ |
|
56 |
public static Symtab instance(Context context) { |
|
57 |
Symtab instance = context.get(symtabKey); |
|
58 |
if (instance == null) |
|
59 |
instance = new Symtab(context); |
|
60 |
return instance; |
|
61 |
} |
|
62 |
||
63 |
/** Builtin types. |
|
64 |
*/ |
|
65 |
public final Type byteType = new Type(TypeTags.BYTE, null); |
|
66 |
public final Type charType = new Type(TypeTags.CHAR, null); |
|
67 |
public final Type shortType = new Type(TypeTags.SHORT, null); |
|
68 |
public final Type intType = new Type(TypeTags.INT, null); |
|
69 |
public final Type longType = new Type(TypeTags.LONG, null); |
|
70 |
public final Type floatType = new Type(TypeTags.FLOAT, null); |
|
71 |
public final Type doubleType = new Type(TypeTags.DOUBLE, null); |
|
72 |
public final Type booleanType = new Type(TypeTags.BOOLEAN, null); |
|
73 |
public final Type botType = new BottomType(); |
|
74 |
public final JCNoType voidType = new JCNoType(TypeTags.VOID); |
|
75 |
||
76 |
private final Name.Table names; |
|
77 |
private final ClassReader reader; |
|
1037
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
78 |
private final Target target; |
10 | 79 |
|
80 |
/** A symbol for the root package. |
|
81 |
*/ |
|
82 |
public final PackageSymbol rootPackage; |
|
83 |
||
84 |
/** A symbol for the unnamed package. |
|
85 |
*/ |
|
86 |
public final PackageSymbol unnamedPackage; |
|
87 |
||
88 |
/** A symbol that stands for a missing symbol. |
|
89 |
*/ |
|
90 |
public final TypeSymbol noSymbol; |
|
91 |
||
92 |
/** The error symbol. |
|
93 |
*/ |
|
94 |
public final ClassSymbol errSymbol; |
|
95 |
||
96 |
/** An instance of the error type. |
|
97 |
*/ |
|
98 |
public final Type errType; |
|
99 |
||
100 |
/** A value for the unknown type. */ |
|
101 |
public final Type unknownType; |
|
102 |
||
103 |
/** The builtin type of all arrays. */ |
|
104 |
public final ClassSymbol arrayClass; |
|
105 |
public final MethodSymbol arrayCloneMethod; |
|
106 |
||
107 |
/** VGJ: The (singleton) type of all bound types. */ |
|
108 |
public final ClassSymbol boundClass; |
|
109 |
||
110 |
/** The builtin type of all methods. */ |
|
111 |
public final ClassSymbol methodClass; |
|
112 |
||
113 |
/** Predefined types. |
|
114 |
*/ |
|
115 |
public final Type objectType; |
|
116 |
public final Type classType; |
|
117 |
public final Type classLoaderType; |
|
118 |
public final Type stringType; |
|
119 |
public final Type stringBufferType; |
|
120 |
public final Type stringBuilderType; |
|
121 |
public final Type cloneableType; |
|
122 |
public final Type serializableType; |
|
123 |
public final Type throwableType; |
|
124 |
public final Type errorType; |
|
125 |
public final Type illegalArgumentExceptionType; |
|
126 |
public final Type exceptionType; |
|
127 |
public final Type runtimeExceptionType; |
|
128 |
public final Type classNotFoundExceptionType; |
|
129 |
public final Type noClassDefFoundErrorType; |
|
130 |
public final Type noSuchFieldErrorType; |
|
131 |
public final Type assertionErrorType; |
|
132 |
public final Type cloneNotSupportedExceptionType; |
|
133 |
public final Type annotationType; |
|
134 |
public final TypeSymbol enumSym; |
|
135 |
public final Type listType; |
|
136 |
public final Type collectionsType; |
|
137 |
public final Type comparableType; |
|
138 |
public final Type arraysType; |
|
139 |
public final Type iterableType; |
|
140 |
public final Type iteratorType; |
|
141 |
public final Type annotationTargetType; |
|
142 |
public final Type overrideType; |
|
143 |
public final Type retentionType; |
|
144 |
public final Type deprecatedType; |
|
145 |
public final Type suppressWarningsType; |
|
146 |
public final Type inheritedType; |
|
147 |
public final Type proprietaryType; |
|
1037
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
148 |
public final Type systemType; |
10 | 149 |
|
150 |
/** The symbol representing the length field of an array. |
|
151 |
*/ |
|
152 |
public final VarSymbol lengthVar; |
|
153 |
||
154 |
/** The null check operator. */ |
|
155 |
public final OperatorSymbol nullcheck; |
|
156 |
||
157 |
/** The symbol representing the final finalize method on enums */ |
|
158 |
public final MethodSymbol enumFinalFinalize; |
|
159 |
||
160 |
/** The predefined type that belongs to a tag. |
|
161 |
*/ |
|
162 |
public final Type[] typeOfTag = new Type[TypeTags.TypeTagCount]; |
|
163 |
||
164 |
/** The name of the class that belongs to a basix type tag. |
|
165 |
*/ |
|
166 |
public final Name[] boxedName = new Name[TypeTags.TypeTagCount]; |
|
167 |
||
168 |
/** A hashtable containing the encountered top-level and member classes, |
|
169 |
* indexed by flat names. The table does not contain local classes. |
|
170 |
* It should be updated from the outside to reflect classes defined |
|
171 |
* by compiled source files. |
|
172 |
*/ |
|
173 |
public final Map<Name, ClassSymbol> classes = new HashMap<Name, ClassSymbol>(); |
|
174 |
||
175 |
/** A hashtable containing the encountered packages. |
|
176 |
* the table should be updated from outside to reflect packages defined |
|
177 |
* by compiled source files. |
|
178 |
*/ |
|
179 |
public final Map<Name, PackageSymbol> packages = new HashMap<Name, PackageSymbol>(); |
|
180 |
||
181 |
public void initType(Type type, ClassSymbol c) { |
|
182 |
type.tsym = c; |
|
183 |
typeOfTag[type.tag] = type; |
|
184 |
} |
|
185 |
||
186 |
public void initType(Type type, String name) { |
|
187 |
initType( |
|
188 |
type, |
|
189 |
new ClassSymbol( |
|
190 |
PUBLIC, names.fromString(name), type, rootPackage)); |
|
191 |
} |
|
192 |
||
193 |
public void initType(Type type, String name, String bname) { |
|
194 |
initType(type, name); |
|
195 |
boxedName[type.tag] = names.fromString("java.lang." + bname); |
|
196 |
} |
|
197 |
||
198 |
/** The class symbol that owns all predefined symbols. |
|
199 |
*/ |
|
200 |
public final ClassSymbol predefClass; |
|
201 |
||
202 |
/** Enter a constant into symbol table. |
|
203 |
* @param name The constant's name. |
|
204 |
* @param type The constant's type. |
|
205 |
*/ |
|
206 |
private VarSymbol enterConstant(String name, Type type) { |
|
207 |
VarSymbol c = new VarSymbol( |
|
208 |
PUBLIC | STATIC | FINAL, |
|
209 |
names.fromString(name), |
|
210 |
type, |
|
211 |
predefClass); |
|
212 |
c.setData(type.constValue()); |
|
213 |
predefClass.members().enter(c); |
|
214 |
return c; |
|
215 |
} |
|
216 |
||
217 |
/** Enter a binary operation into symbol table. |
|
218 |
* @param name The name of the operator. |
|
219 |
* @param left The type of the left operand. |
|
220 |
* @param right The type of the left operand. |
|
221 |
* @param res The operation's result type. |
|
222 |
* @param opcode The operation's bytecode instruction. |
|
223 |
*/ |
|
224 |
private void enterBinop(String name, |
|
225 |
Type left, Type right, Type res, |
|
226 |
int opcode) { |
|
227 |
predefClass.members().enter( |
|
228 |
new OperatorSymbol( |
|
229 |
names.fromString(name), |
|
230 |
new MethodType(List.of(left, right), res, |
|
231 |
List.<Type>nil(), methodClass), |
|
232 |
opcode, |
|
233 |
predefClass)); |
|
234 |
} |
|
235 |
||
236 |
/** Enter a binary operation, as above but with two opcodes, |
|
237 |
* which get encoded as (opcode1 << ByteCodeTags.preShift) + opcode2. |
|
238 |
* @param opcode1 First opcode. |
|
239 |
* @param opcode2 Second opcode. |
|
240 |
*/ |
|
241 |
private void enterBinop(String name, |
|
242 |
Type left, Type right, Type res, |
|
243 |
int opcode1, int opcode2) { |
|
244 |
enterBinop( |
|
245 |
name, left, right, res, (opcode1 << ByteCodes.preShift) | opcode2); |
|
246 |
} |
|
247 |
||
248 |
/** Enter a unary operation into symbol table. |
|
249 |
* @param name The name of the operator. |
|
250 |
* @param arg The type of the operand. |
|
251 |
* @param res The operation's result type. |
|
252 |
* @param opcode The operation's bytecode instruction. |
|
253 |
*/ |
|
254 |
private OperatorSymbol enterUnop(String name, |
|
255 |
Type arg, |
|
256 |
Type res, |
|
257 |
int opcode) { |
|
258 |
OperatorSymbol sym = |
|
259 |
new OperatorSymbol(names.fromString(name), |
|
260 |
new MethodType(List.of(arg), |
|
261 |
res, |
|
262 |
List.<Type>nil(), |
|
263 |
methodClass), |
|
264 |
opcode, |
|
265 |
predefClass); |
|
266 |
predefClass.members().enter(sym); |
|
267 |
return sym; |
|
268 |
} |
|
269 |
||
270 |
/** Enter a class into symbol table. |
|
271 |
* @param The name of the class. |
|
272 |
*/ |
|
273 |
private Type enterClass(String s) { |
|
274 |
return reader.enterClass(names.fromString(s)).type; |
|
275 |
} |
|
276 |
||
1037
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
277 |
public void synthesizeEmptyInterfaceIfMissing(final Type type) { |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
278 |
final Completer completer = type.tsym.completer; |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
279 |
if (completer != null) { |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
280 |
type.tsym.completer = new Completer() { |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
281 |
public void complete(Symbol sym) throws CompletionFailure { |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
282 |
try { |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
283 |
completer.complete(sym); |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
284 |
} catch (CompletionFailure e) { |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
285 |
sym.flags_field |= (PUBLIC | INTERFACE); |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
286 |
((ClassType) sym.type).supertype_field = objectType; |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
287 |
} |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
288 |
} |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
289 |
}; |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
290 |
} |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
291 |
} |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
292 |
|
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
293 |
public void synthesizeBoxTypeIfMissing(final Type type) { |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
294 |
ClassSymbol sym = reader.enterClass(boxedName[type.tag]); |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
295 |
final Completer completer = sym.completer; |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
296 |
if (completer != null) { |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
297 |
sym.completer = new Completer() { |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
298 |
public void complete(Symbol sym) throws CompletionFailure { |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
299 |
try { |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
300 |
completer.complete(sym); |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
301 |
} catch (CompletionFailure e) { |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
302 |
sym.flags_field |= PUBLIC; |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
303 |
((ClassType) sym.type).supertype_field = objectType; |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
304 |
Name n = target.boxWithConstructors() ? names.init : names.valueOf; |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
305 |
MethodSymbol boxMethod = |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
306 |
new MethodSymbol(PUBLIC | STATIC, |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
307 |
n, |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
308 |
new MethodType(List.of(type), sym.type, |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
309 |
List.<Type>nil(), methodClass), |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
310 |
sym); |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
311 |
sym.members().enter(boxMethod); |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
312 |
MethodSymbol unboxMethod = |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
313 |
new MethodSymbol(PUBLIC, |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
314 |
type.tsym.name.append(names.Value), // x.intValue() |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
315 |
new MethodType(List.<Type>nil(), type, |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
316 |
List.<Type>nil(), methodClass), |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
317 |
sym); |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
318 |
sym.members().enter(unboxMethod); |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
319 |
} |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
320 |
} |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
321 |
}; |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
322 |
} |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
323 |
|
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
324 |
} |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
325 |
|
10 | 326 |
/** Constructor; enters all predefined identifiers and operators |
327 |
* into symbol table. |
|
328 |
*/ |
|
329 |
protected Symtab(Context context) throws CompletionFailure { |
|
330 |
context.put(symtabKey, this); |
|
331 |
||
332 |
names = Name.Table.instance(context); |
|
1037
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
333 |
target = Target.instance(context); |
10 | 334 |
|
335 |
// Create the unknown type |
|
336 |
unknownType = new Type(TypeTags.UNKNOWN, null); |
|
337 |
||
338 |
// create the basic builtin symbols |
|
339 |
rootPackage = new PackageSymbol(names.empty, null); |
|
340 |
final Messages messages = Messages.instance(context); |
|
341 |
unnamedPackage = new PackageSymbol(names.empty, rootPackage) { |
|
342 |
public String toString() { |
|
343 |
return messages.getLocalizedString("compiler.misc.unnamed.package"); |
|
344 |
} |
|
345 |
}; |
|
346 |
noSymbol = new TypeSymbol(0, names.empty, Type.noType, rootPackage); |
|
347 |
noSymbol.kind = Kinds.NIL; |
|
348 |
||
349 |
// create the error symbols |
|
350 |
errSymbol = new ClassSymbol(PUBLIC|STATIC|ACYCLIC, names.any, null, rootPackage); |
|
351 |
errType = new ErrorType(errSymbol); |
|
352 |
||
353 |
// initialize builtin types |
|
354 |
initType(byteType, "byte", "Byte"); |
|
355 |
initType(shortType, "short", "Short"); |
|
356 |
initType(charType, "char", "Character"); |
|
357 |
initType(intType, "int", "Integer"); |
|
358 |
initType(longType, "long", "Long"); |
|
359 |
initType(floatType, "float", "Float"); |
|
360 |
initType(doubleType, "double", "Double"); |
|
361 |
initType(booleanType, "boolean", "Boolean"); |
|
362 |
initType(voidType, "void", "Void"); |
|
363 |
initType(botType, "<nulltype>"); |
|
364 |
initType(errType, errSymbol); |
|
365 |
initType(unknownType, "<any?>"); |
|
366 |
||
367 |
// the builtin class of all arrays |
|
368 |
arrayClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Array, noSymbol); |
|
369 |
||
370 |
// VGJ |
|
371 |
boundClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Bound, noSymbol); |
|
372 |
||
373 |
// the builtin class of all methods |
|
374 |
methodClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Method, noSymbol); |
|
375 |
||
376 |
// Create class to hold all predefined constants and operations. |
|
377 |
predefClass = new ClassSymbol(PUBLIC|ACYCLIC, names.empty, rootPackage); |
|
378 |
Scope scope = new Scope(predefClass); |
|
379 |
predefClass.members_field = scope; |
|
380 |
||
381 |
// Enter symbols for basic types. |
|
382 |
scope.enter(byteType.tsym); |
|
383 |
scope.enter(shortType.tsym); |
|
384 |
scope.enter(charType.tsym); |
|
385 |
scope.enter(intType.tsym); |
|
386 |
scope.enter(longType.tsym); |
|
387 |
scope.enter(floatType.tsym); |
|
388 |
scope.enter(doubleType.tsym); |
|
389 |
scope.enter(booleanType.tsym); |
|
390 |
scope.enter(errType.tsym); |
|
391 |
||
392 |
classes.put(predefClass.fullname, predefClass); |
|
393 |
||
394 |
reader = ClassReader.instance(context); |
|
395 |
reader.init(this); |
|
396 |
||
397 |
// Enter predefined classes. |
|
398 |
objectType = enterClass("java.lang.Object"); |
|
399 |
classType = enterClass("java.lang.Class"); |
|
400 |
stringType = enterClass("java.lang.String"); |
|
401 |
stringBufferType = enterClass("java.lang.StringBuffer"); |
|
402 |
stringBuilderType = enterClass("java.lang.StringBuilder"); |
|
403 |
cloneableType = enterClass("java.lang.Cloneable"); |
|
404 |
throwableType = enterClass("java.lang.Throwable"); |
|
405 |
serializableType = enterClass("java.io.Serializable"); |
|
406 |
errorType = enterClass("java.lang.Error"); |
|
407 |
illegalArgumentExceptionType = enterClass("java.lang.IllegalArgumentException"); |
|
408 |
exceptionType = enterClass("java.lang.Exception"); |
|
409 |
runtimeExceptionType = enterClass("java.lang.RuntimeException"); |
|
410 |
classNotFoundExceptionType = enterClass("java.lang.ClassNotFoundException"); |
|
411 |
noClassDefFoundErrorType = enterClass("java.lang.NoClassDefFoundError"); |
|
412 |
noSuchFieldErrorType = enterClass("java.lang.NoSuchFieldError"); |
|
413 |
assertionErrorType = enterClass("java.lang.AssertionError"); |
|
414 |
cloneNotSupportedExceptionType = enterClass("java.lang.CloneNotSupportedException"); |
|
415 |
annotationType = enterClass("java.lang.annotation.Annotation"); |
|
416 |
classLoaderType = enterClass("java.lang.ClassLoader"); |
|
417 |
enumSym = reader.enterClass(names.java_lang_Enum); |
|
418 |
enumFinalFinalize = |
|
419 |
new MethodSymbol(PROTECTED|FINAL|HYPOTHETICAL, |
|
420 |
names.finalize, |
|
421 |
new MethodType(List.<Type>nil(), voidType, |
|
422 |
List.<Type>nil(), methodClass), |
|
423 |
enumSym); |
|
424 |
listType = enterClass("java.util.List"); |
|
425 |
collectionsType = enterClass("java.util.Collections"); |
|
426 |
comparableType = enterClass("java.lang.Comparable"); |
|
427 |
arraysType = enterClass("java.util.Arrays"); |
|
1037
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
428 |
iterableType = target.hasIterable() |
10 | 429 |
? enterClass("java.lang.Iterable") |
430 |
: enterClass("java.util.Collection"); |
|
431 |
iteratorType = enterClass("java.util.Iterator"); |
|
432 |
annotationTargetType = enterClass("java.lang.annotation.Target"); |
|
433 |
overrideType = enterClass("java.lang.Override"); |
|
434 |
retentionType = enterClass("java.lang.annotation.Retention"); |
|
435 |
deprecatedType = enterClass("java.lang.Deprecated"); |
|
436 |
suppressWarningsType = enterClass("java.lang.SuppressWarnings"); |
|
437 |
inheritedType = enterClass("java.lang.annotation.Inherited"); |
|
1037
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
438 |
systemType = enterClass("java.lang.System"); |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
439 |
|
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
440 |
synthesizeEmptyInterfaceIfMissing(cloneableType); |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
441 |
synthesizeEmptyInterfaceIfMissing(serializableType); |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
442 |
synthesizeBoxTypeIfMissing(doubleType); |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
443 |
synthesizeBoxTypeIfMissing(floatType); |
10 | 444 |
|
445 |
// Enter a synthetic class that is used to mark Sun |
|
446 |
// proprietary classes in ct.sym. This class does not have a |
|
447 |
// class file. |
|
448 |
ClassType proprietaryType = (ClassType)enterClass("sun.Proprietary+Annotation"); |
|
449 |
this.proprietaryType = proprietaryType; |
|
450 |
ClassSymbol proprietarySymbol = (ClassSymbol)proprietaryType.tsym; |
|
451 |
proprietarySymbol.completer = null; |
|
452 |
proprietarySymbol.flags_field = PUBLIC|ACYCLIC|ANNOTATION|INTERFACE; |
|
453 |
proprietarySymbol.erasure_field = proprietaryType; |
|
454 |
proprietarySymbol.members_field = new Scope(proprietarySymbol); |
|
455 |
proprietaryType.typarams_field = List.nil(); |
|
456 |
proprietaryType.allparams_field = List.nil(); |
|
457 |
proprietaryType.supertype_field = annotationType; |
|
458 |
proprietaryType.interfaces_field = List.nil(); |
|
459 |
||
460 |
// Enter a class for arrays. |
|
461 |
// The class implements java.lang.Cloneable and java.io.Serializable. |
|
462 |
// It has a final length field and a clone method. |
|
463 |
ClassType arrayClassType = (ClassType)arrayClass.type; |
|
464 |
arrayClassType.supertype_field = objectType; |
|
465 |
arrayClassType.interfaces_field = List.of(cloneableType, serializableType); |
|
466 |
arrayClass.members_field = new Scope(arrayClass); |
|
467 |
lengthVar = new VarSymbol( |
|
468 |
PUBLIC | FINAL, |
|
469 |
names.length, |
|
470 |
intType, |
|
471 |
arrayClass); |
|
472 |
arrayClass.members().enter(lengthVar); |
|
473 |
arrayCloneMethod = new MethodSymbol( |
|
474 |
PUBLIC, |
|
475 |
names.clone, |
|
476 |
new MethodType(List.<Type>nil(), objectType, |
|
477 |
List.<Type>nil(), methodClass), |
|
478 |
arrayClass); |
|
479 |
arrayClass.members().enter(arrayCloneMethod); |
|
480 |
||
481 |
// Enter operators. |
|
482 |
enterUnop("+", doubleType, doubleType, nop); |
|
483 |
enterUnop("+", floatType, floatType, nop); |
|
484 |
enterUnop("+", longType, longType, nop); |
|
485 |
enterUnop("+", intType, intType, nop); |
|
486 |
||
487 |
enterUnop("-", doubleType, doubleType, dneg); |
|
488 |
enterUnop("-", floatType, floatType, fneg); |
|
489 |
enterUnop("-", longType, longType, lneg); |
|
490 |
enterUnop("-", intType, intType, ineg); |
|
491 |
||
492 |
enterUnop("~", longType, longType, lxor); |
|
493 |
enterUnop("~", intType, intType, ixor); |
|
494 |
||
495 |
enterUnop("++", doubleType, doubleType, dadd); |
|
496 |
enterUnop("++", floatType, floatType, fadd); |
|
497 |
enterUnop("++", longType, longType, ladd); |
|
498 |
enterUnop("++", intType, intType, iadd); |
|
499 |
enterUnop("++", charType, charType, iadd); |
|
500 |
enterUnop("++", shortType, shortType, iadd); |
|
501 |
enterUnop("++", byteType, byteType, iadd); |
|
502 |
||
503 |
enterUnop("--", doubleType, doubleType, dsub); |
|
504 |
enterUnop("--", floatType, floatType, fsub); |
|
505 |
enterUnop("--", longType, longType, lsub); |
|
506 |
enterUnop("--", intType, intType, isub); |
|
507 |
enterUnop("--", charType, charType, isub); |
|
508 |
enterUnop("--", shortType, shortType, isub); |
|
509 |
enterUnop("--", byteType, byteType, isub); |
|
510 |
||
511 |
enterUnop("!", booleanType, booleanType, bool_not); |
|
512 |
nullcheck = enterUnop("<*nullchk*>", objectType, objectType, nullchk); |
|
513 |
||
514 |
// string concatenation |
|
515 |
enterBinop("+", stringType, objectType, stringType, string_add); |
|
516 |
enterBinop("+", objectType, stringType, stringType, string_add); |
|
517 |
enterBinop("+", stringType, stringType, stringType, string_add); |
|
518 |
enterBinop("+", stringType, intType, stringType, string_add); |
|
519 |
enterBinop("+", stringType, longType, stringType, string_add); |
|
520 |
enterBinop("+", stringType, floatType, stringType, string_add); |
|
521 |
enterBinop("+", stringType, doubleType, stringType, string_add); |
|
522 |
enterBinop("+", stringType, booleanType, stringType, string_add); |
|
523 |
enterBinop("+", stringType, botType, stringType, string_add); |
|
524 |
enterBinop("+", intType, stringType, stringType, string_add); |
|
525 |
enterBinop("+", longType, stringType, stringType, string_add); |
|
526 |
enterBinop("+", floatType, stringType, stringType, string_add); |
|
527 |
enterBinop("+", doubleType, stringType, stringType, string_add); |
|
528 |
enterBinop("+", booleanType, stringType, stringType, string_add); |
|
529 |
enterBinop("+", botType, stringType, stringType, string_add); |
|
530 |
||
531 |
// these errors would otherwise be matched as string concatenation |
|
532 |
enterBinop("+", botType, botType, botType, error); |
|
533 |
enterBinop("+", botType, intType, botType, error); |
|
534 |
enterBinop("+", botType, longType, botType, error); |
|
535 |
enterBinop("+", botType, floatType, botType, error); |
|
536 |
enterBinop("+", botType, doubleType, botType, error); |
|
537 |
enterBinop("+", botType, booleanType, botType, error); |
|
538 |
enterBinop("+", botType, objectType, botType, error); |
|
539 |
enterBinop("+", intType, botType, botType, error); |
|
540 |
enterBinop("+", longType, botType, botType, error); |
|
541 |
enterBinop("+", floatType, botType, botType, error); |
|
542 |
enterBinop("+", doubleType, botType, botType, error); |
|
543 |
enterBinop("+", booleanType, botType, botType, error); |
|
544 |
enterBinop("+", objectType, botType, botType, error); |
|
545 |
||
546 |
enterBinop("+", doubleType, doubleType, doubleType, dadd); |
|
547 |
enterBinop("+", floatType, floatType, floatType, fadd); |
|
548 |
enterBinop("+", longType, longType, longType, ladd); |
|
549 |
enterBinop("+", intType, intType, intType, iadd); |
|
550 |
||
551 |
enterBinop("-", doubleType, doubleType, doubleType, dsub); |
|
552 |
enterBinop("-", floatType, floatType, floatType, fsub); |
|
553 |
enterBinop("-", longType, longType, longType, lsub); |
|
554 |
enterBinop("-", intType, intType, intType, isub); |
|
555 |
||
556 |
enterBinop("*", doubleType, doubleType, doubleType, dmul); |
|
557 |
enterBinop("*", floatType, floatType, floatType, fmul); |
|
558 |
enterBinop("*", longType, longType, longType, lmul); |
|
559 |
enterBinop("*", intType, intType, intType, imul); |
|
560 |
||
561 |
enterBinop("/", doubleType, doubleType, doubleType, ddiv); |
|
562 |
enterBinop("/", floatType, floatType, floatType, fdiv); |
|
563 |
enterBinop("/", longType, longType, longType, ldiv); |
|
564 |
enterBinop("/", intType, intType, intType, idiv); |
|
565 |
||
566 |
enterBinop("%", doubleType, doubleType, doubleType, dmod); |
|
567 |
enterBinop("%", floatType, floatType, floatType, fmod); |
|
568 |
enterBinop("%", longType, longType, longType, lmod); |
|
569 |
enterBinop("%", intType, intType, intType, imod); |
|
570 |
||
571 |
enterBinop("&", booleanType, booleanType, booleanType, iand); |
|
572 |
enterBinop("&", longType, longType, longType, land); |
|
573 |
enterBinop("&", intType, intType, intType, iand); |
|
574 |
||
575 |
enterBinop("|", booleanType, booleanType, booleanType, ior); |
|
576 |
enterBinop("|", longType, longType, longType, lor); |
|
577 |
enterBinop("|", intType, intType, intType, ior); |
|
578 |
||
579 |
enterBinop("^", booleanType, booleanType, booleanType, ixor); |
|
580 |
enterBinop("^", longType, longType, longType, lxor); |
|
581 |
enterBinop("^", intType, intType, intType, ixor); |
|
582 |
||
583 |
enterBinop("<<", longType, longType, longType, lshll); |
|
584 |
enterBinop("<<", intType, longType, intType, ishll); |
|
585 |
enterBinop("<<", longType, intType, longType, lshl); |
|
586 |
enterBinop("<<", intType, intType, intType, ishl); |
|
587 |
||
588 |
enterBinop(">>", longType, longType, longType, lshrl); |
|
589 |
enterBinop(">>", intType, longType, intType, ishrl); |
|
590 |
enterBinop(">>", longType, intType, longType, lshr); |
|
591 |
enterBinop(">>", intType, intType, intType, ishr); |
|
592 |
||
593 |
enterBinop(">>>", longType, longType, longType, lushrl); |
|
594 |
enterBinop(">>>", intType, longType, intType, iushrl); |
|
595 |
enterBinop(">>>", longType, intType, longType, lushr); |
|
596 |
enterBinop(">>>", intType, intType, intType, iushr); |
|
597 |
||
598 |
enterBinop("<", doubleType, doubleType, booleanType, dcmpg, iflt); |
|
599 |
enterBinop("<", floatType, floatType, booleanType, fcmpg, iflt); |
|
600 |
enterBinop("<", longType, longType, booleanType, lcmp, iflt); |
|
601 |
enterBinop("<", intType, intType, booleanType, if_icmplt); |
|
602 |
||
603 |
enterBinop(">", doubleType, doubleType, booleanType, dcmpl, ifgt); |
|
604 |
enterBinop(">", floatType, floatType, booleanType, fcmpl, ifgt); |
|
605 |
enterBinop(">", longType, longType, booleanType, lcmp, ifgt); |
|
606 |
enterBinop(">", intType, intType, booleanType, if_icmpgt); |
|
607 |
||
608 |
enterBinop("<=", doubleType, doubleType, booleanType, dcmpg, ifle); |
|
609 |
enterBinop("<=", floatType, floatType, booleanType, fcmpg, ifle); |
|
610 |
enterBinop("<=", longType, longType, booleanType, lcmp, ifle); |
|
611 |
enterBinop("<=", intType, intType, booleanType, if_icmple); |
|
612 |
||
613 |
enterBinop(">=", doubleType, doubleType, booleanType, dcmpl, ifge); |
|
614 |
enterBinop(">=", floatType, floatType, booleanType, fcmpl, ifge); |
|
615 |
enterBinop(">=", longType, longType, booleanType, lcmp, ifge); |
|
616 |
enterBinop(">=", intType, intType, booleanType, if_icmpge); |
|
617 |
||
618 |
enterBinop("==", objectType, objectType, booleanType, if_acmpeq); |
|
619 |
enterBinop("==", booleanType, booleanType, booleanType, if_icmpeq); |
|
620 |
enterBinop("==", doubleType, doubleType, booleanType, dcmpl, ifeq); |
|
621 |
enterBinop("==", floatType, floatType, booleanType, fcmpl, ifeq); |
|
622 |
enterBinop("==", longType, longType, booleanType, lcmp, ifeq); |
|
623 |
enterBinop("==", intType, intType, booleanType, if_icmpeq); |
|
624 |
||
625 |
enterBinop("!=", objectType, objectType, booleanType, if_acmpne); |
|
626 |
enterBinop("!=", booleanType, booleanType, booleanType, if_icmpne); |
|
627 |
enterBinop("!=", doubleType, doubleType, booleanType, dcmpl, ifne); |
|
628 |
enterBinop("!=", floatType, floatType, booleanType, fcmpl, ifne); |
|
629 |
enterBinop("!=", longType, longType, booleanType, lcmp, ifne); |
|
630 |
enterBinop("!=", intType, intType, booleanType, if_icmpne); |
|
631 |
||
632 |
enterBinop("&&", booleanType, booleanType, booleanType, bool_and); |
|
633 |
enterBinop("||", booleanType, booleanType, booleanType, bool_or); |
|
634 |
} |
|
635 |
} |