author | jlahoda |
Wed, 09 Jul 2014 16:32:05 +0200 | |
changeset 25443 | 9187d77f2c64 |
parent 24604 | 7f68545b5128 |
child 25445 | 603f0c93d5c9 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
2 |
* Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 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 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.code; |
|
27 |
||
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
28 |
import java.util.HashMap; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
29 |
import java.util.HashSet; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
30 |
import java.util.Map; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
31 |
import java.util.Set; |
10 | 32 |
|
14258 | 33 |
import javax.lang.model.element.ElementVisitor; |
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
34 |
import javax.tools.JavaFileObject; |
14258 | 35 |
|
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
36 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24604
diff
changeset
|
37 |
import com.sun.tools.javac.code.Scope.WriteableScope; |
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
38 |
import com.sun.tools.javac.code.Symbol.ClassSymbol; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
39 |
import com.sun.tools.javac.code.Symbol.Completer; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
40 |
import com.sun.tools.javac.code.Symbol.CompletionFailure; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
41 |
import com.sun.tools.javac.code.Symbol.MethodSymbol; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
42 |
import com.sun.tools.javac.code.Symbol.OperatorSymbol; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
43 |
import com.sun.tools.javac.code.Symbol.PackageSymbol; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
44 |
import com.sun.tools.javac.code.Symbol.TypeSymbol; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
45 |
import com.sun.tools.javac.code.Symbol.VarSymbol; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
46 |
import com.sun.tools.javac.code.Type.BottomType; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
47 |
import com.sun.tools.javac.code.Type.ClassType; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
48 |
import com.sun.tools.javac.code.Type.ErrorType; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
49 |
import com.sun.tools.javac.code.Type.JCPrimitiveType; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
50 |
import com.sun.tools.javac.code.Type.JCVoidType; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
51 |
import com.sun.tools.javac.code.Type.MethodType; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
52 |
import com.sun.tools.javac.code.Type.UnknownType; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
53 |
import com.sun.tools.javac.jvm.ByteCodes; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
54 |
import com.sun.tools.javac.jvm.Target; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
55 |
import com.sun.tools.javac.util.Assert; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
56 |
import com.sun.tools.javac.util.Context; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
57 |
import com.sun.tools.javac.util.Convert; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
58 |
import com.sun.tools.javac.util.JavacMessages; |
14258 | 59 |
import com.sun.tools.javac.util.List; |
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
60 |
import com.sun.tools.javac.util.Log; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
61 |
import com.sun.tools.javac.util.Name; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
62 |
import com.sun.tools.javac.util.Names; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
63 |
|
14258 | 64 |
import static com.sun.tools.javac.code.Flags.*; |
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
65 |
import static com.sun.tools.javac.code.Kinds.PCK; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
66 |
import static com.sun.tools.javac.code.Kinds.TYP; |
10 | 67 |
import static com.sun.tools.javac.jvm.ByteCodes.*; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
68 |
import static com.sun.tools.javac.code.TypeTag.*; |
10 | 69 |
|
70 |
/** A class that defines all predefined constants and operators |
|
71 |
* as well as special classes such as java.lang.Object, which need |
|
72 |
* to be known to the compiler. All symbols are held in instance |
|
73 |
* fields. This makes it possible to work in multiple concurrent |
|
74 |
* projects, which might use different class files for library classes. |
|
75 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
76 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
77 |
* If you write code that depends on this, you do so at your own risk. |
10 | 78 |
* This code and its internal interfaces are subject to change or |
79 |
* deletion without notice.</b> |
|
80 |
*/ |
|
81 |
public class Symtab { |
|
82 |
/** The context key for the symbol table. */ |
|
22163 | 83 |
protected static final Context.Key<Symtab> symtabKey = new Context.Key<>(); |
10 | 84 |
|
85 |
/** Get the symbol table instance. */ |
|
86 |
public static Symtab instance(Context context) { |
|
87 |
Symtab instance = context.get(symtabKey); |
|
88 |
if (instance == null) |
|
89 |
instance = new Symtab(context); |
|
90 |
return instance; |
|
91 |
} |
|
92 |
||
93 |
/** Builtin types. |
|
94 |
*/ |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18414
diff
changeset
|
95 |
public final JCPrimitiveType byteType = new JCPrimitiveType(BYTE, null); |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18414
diff
changeset
|
96 |
public final JCPrimitiveType charType = new JCPrimitiveType(CHAR, null); |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18414
diff
changeset
|
97 |
public final JCPrimitiveType shortType = new JCPrimitiveType(SHORT, null); |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18414
diff
changeset
|
98 |
public final JCPrimitiveType intType = new JCPrimitiveType(INT, null); |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18414
diff
changeset
|
99 |
public final JCPrimitiveType longType = new JCPrimitiveType(LONG, null); |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18414
diff
changeset
|
100 |
public final JCPrimitiveType floatType = new JCPrimitiveType(FLOAT, null); |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18414
diff
changeset
|
101 |
public final JCPrimitiveType doubleType = new JCPrimitiveType(DOUBLE, null); |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18414
diff
changeset
|
102 |
public final JCPrimitiveType booleanType = new JCPrimitiveType(BOOLEAN, null); |
10 | 103 |
public final Type botType = new BottomType(); |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18414
diff
changeset
|
104 |
public final JCVoidType voidType = new JCVoidType(); |
10 | 105 |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
106 |
private final Names names; |
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
107 |
private final Completer initialCompleter; |
1037
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
108 |
private final Target target; |
10 | 109 |
|
110 |
/** A symbol for the root package. |
|
111 |
*/ |
|
112 |
public final PackageSymbol rootPackage; |
|
113 |
||
114 |
/** A symbol for the unnamed package. |
|
115 |
*/ |
|
116 |
public final PackageSymbol unnamedPackage; |
|
117 |
||
118 |
/** A symbol that stands for a missing symbol. |
|
119 |
*/ |
|
120 |
public final TypeSymbol noSymbol; |
|
121 |
||
122 |
/** The error symbol. |
|
123 |
*/ |
|
124 |
public final ClassSymbol errSymbol; |
|
125 |
||
6594
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6148
diff
changeset
|
126 |
/** The unknown symbol. |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6148
diff
changeset
|
127 |
*/ |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6148
diff
changeset
|
128 |
public final ClassSymbol unknownSymbol; |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6148
diff
changeset
|
129 |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1037
diff
changeset
|
130 |
/** A value for the errType, with a originalType of noType */ |
10 | 131 |
public final Type errType; |
132 |
||
133 |
/** A value for the unknown type. */ |
|
134 |
public final Type unknownType; |
|
135 |
||
136 |
/** The builtin type of all arrays. */ |
|
137 |
public final ClassSymbol arrayClass; |
|
138 |
public final MethodSymbol arrayCloneMethod; |
|
139 |
||
140 |
/** VGJ: The (singleton) type of all bound types. */ |
|
141 |
public final ClassSymbol boundClass; |
|
142 |
||
143 |
/** The builtin type of all methods. */ |
|
144 |
public final ClassSymbol methodClass; |
|
145 |
||
146 |
/** Predefined types. |
|
147 |
*/ |
|
148 |
public final Type objectType; |
|
149 |
public final Type classType; |
|
150 |
public final Type classLoaderType; |
|
151 |
public final Type stringType; |
|
152 |
public final Type stringBufferType; |
|
153 |
public final Type stringBuilderType; |
|
154 |
public final Type cloneableType; |
|
155 |
public final Type serializableType; |
|
16300 | 156 |
public final Type serializedLambdaType; |
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
1471
diff
changeset
|
157 |
public final Type methodHandleType; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
158 |
public final Type methodHandleLookupType; |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13844
diff
changeset
|
159 |
public final Type methodTypeType; |
12213
516b112d6c68
7150368: javac should include basic ability to generate native headers
jjg
parents:
9082
diff
changeset
|
160 |
public final Type nativeHeaderType; |
10 | 161 |
public final Type throwableType; |
162 |
public final Type errorType; |
|
9076
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
8621
diff
changeset
|
163 |
public final Type interruptedExceptionType; |
10 | 164 |
public final Type illegalArgumentExceptionType; |
165 |
public final Type exceptionType; |
|
166 |
public final Type runtimeExceptionType; |
|
167 |
public final Type classNotFoundExceptionType; |
|
168 |
public final Type noClassDefFoundErrorType; |
|
169 |
public final Type noSuchFieldErrorType; |
|
170 |
public final Type assertionErrorType; |
|
171 |
public final Type cloneNotSupportedExceptionType; |
|
172 |
public final Type annotationType; |
|
173 |
public final TypeSymbol enumSym; |
|
174 |
public final Type listType; |
|
175 |
public final Type collectionsType; |
|
176 |
public final Type comparableType; |
|
16333 | 177 |
public final Type comparatorType; |
10 | 178 |
public final Type arraysType; |
179 |
public final Type iterableType; |
|
180 |
public final Type iteratorType; |
|
181 |
public final Type annotationTargetType; |
|
182 |
public final Type overrideType; |
|
183 |
public final Type retentionType; |
|
184 |
public final Type deprecatedType; |
|
185 |
public final Type suppressWarningsType; |
|
186 |
public final Type inheritedType; |
|
15724 | 187 |
public final Type profileType; |
10 | 188 |
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
|
189 |
public final Type systemType; |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
190 |
public final Type autoCloseableType; |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
6709
diff
changeset
|
191 |
public final Type trustMeType; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
192 |
public final Type lambdaMetafactory; |
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14539
diff
changeset
|
193 |
public final Type repeatableType; |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
12335
diff
changeset
|
194 |
public final Type documentedType; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
12335
diff
changeset
|
195 |
public final Type elementTypeType; |
15361
01f1828683e6
8005299: Add FunctionalInterface checking to javac
mcimadamore
parents:
15356
diff
changeset
|
196 |
public final Type functionalInterfaceType; |
10 | 197 |
|
198 |
/** The symbol representing the length field of an array. |
|
199 |
*/ |
|
200 |
public final VarSymbol lengthVar; |
|
201 |
||
202 |
/** The null check operator. */ |
|
203 |
public final OperatorSymbol nullcheck; |
|
204 |
||
205 |
/** The symbol representing the final finalize method on enums */ |
|
206 |
public final MethodSymbol enumFinalFinalize; |
|
207 |
||
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
208 |
/** The symbol representing the close method on TWR AutoCloseable type */ |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
209 |
public final MethodSymbol autoCloseableClose; |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
210 |
|
10 | 211 |
/** The predefined type that belongs to a tag. |
212 |
*/ |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
213 |
public final Type[] typeOfTag = new Type[TypeTag.getTypeTagCount()]; |
10 | 214 |
|
215 |
/** The name of the class that belongs to a basix type tag. |
|
216 |
*/ |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
217 |
public final Name[] boxedName = new Name[TypeTag.getTypeTagCount()]; |
10 | 218 |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14046
diff
changeset
|
219 |
/** A set containing all operator names. |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14046
diff
changeset
|
220 |
*/ |
22163 | 221 |
public final Set<Name> operatorNames = new HashSet<>(); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14046
diff
changeset
|
222 |
|
10 | 223 |
/** A hashtable containing the encountered top-level and member classes, |
224 |
* indexed by flat names. The table does not contain local classes. |
|
225 |
* It should be updated from the outside to reflect classes defined |
|
226 |
* by compiled source files. |
|
227 |
*/ |
|
22163 | 228 |
public final Map<Name, ClassSymbol> classes = new HashMap<>(); |
10 | 229 |
|
230 |
/** A hashtable containing the encountered packages. |
|
231 |
* the table should be updated from outside to reflect packages defined |
|
232 |
* by compiled source files. |
|
233 |
*/ |
|
22163 | 234 |
public final Map<Name, PackageSymbol> packages = new HashMap<>(); |
10 | 235 |
|
236 |
public void initType(Type type, ClassSymbol c) { |
|
237 |
type.tsym = c; |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18414
diff
changeset
|
238 |
typeOfTag[type.getTag().ordinal()] = type; |
10 | 239 |
} |
240 |
||
241 |
public void initType(Type type, String name) { |
|
242 |
initType( |
|
243 |
type, |
|
244 |
new ClassSymbol( |
|
245 |
PUBLIC, names.fromString(name), type, rootPackage)); |
|
246 |
} |
|
247 |
||
248 |
public void initType(Type type, String name, String bname) { |
|
249 |
initType(type, name); |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18414
diff
changeset
|
250 |
boxedName[type.getTag().ordinal()] = names.fromString("java.lang." + bname); |
10 | 251 |
} |
252 |
||
253 |
/** The class symbol that owns all predefined symbols. |
|
254 |
*/ |
|
255 |
public final ClassSymbol predefClass; |
|
256 |
||
257 |
/** Enter a constant into symbol table. |
|
258 |
* @param name The constant's name. |
|
259 |
* @param type The constant's type. |
|
260 |
*/ |
|
261 |
private VarSymbol enterConstant(String name, Type type) { |
|
262 |
VarSymbol c = new VarSymbol( |
|
263 |
PUBLIC | STATIC | FINAL, |
|
264 |
names.fromString(name), |
|
265 |
type, |
|
266 |
predefClass); |
|
267 |
c.setData(type.constValue()); |
|
268 |
predefClass.members().enter(c); |
|
269 |
return c; |
|
270 |
} |
|
271 |
||
272 |
/** Enter a binary operation into symbol table. |
|
273 |
* @param name The name of the operator. |
|
274 |
* @param left The type of the left operand. |
|
275 |
* @param right The type of the left operand. |
|
276 |
* @param res The operation's result type. |
|
277 |
* @param opcode The operation's bytecode instruction. |
|
278 |
*/ |
|
279 |
private void enterBinop(String name, |
|
280 |
Type left, Type right, Type res, |
|
281 |
int opcode) { |
|
282 |
predefClass.members().enter( |
|
283 |
new OperatorSymbol( |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14046
diff
changeset
|
284 |
makeOperatorName(name), |
10 | 285 |
new MethodType(List.of(left, right), res, |
286 |
List.<Type>nil(), methodClass), |
|
287 |
opcode, |
|
288 |
predefClass)); |
|
289 |
} |
|
290 |
||
291 |
/** Enter a binary operation, as above but with two opcodes, |
|
13844 | 292 |
* which get encoded as |
293 |
* {@code (opcode1 << ByteCodeTags.preShift) + opcode2 }. |
|
10 | 294 |
* @param opcode1 First opcode. |
295 |
* @param opcode2 Second opcode. |
|
296 |
*/ |
|
297 |
private void enterBinop(String name, |
|
298 |
Type left, Type right, Type res, |
|
299 |
int opcode1, int opcode2) { |
|
300 |
enterBinop( |
|
301 |
name, left, right, res, (opcode1 << ByteCodes.preShift) | opcode2); |
|
302 |
} |
|
303 |
||
304 |
/** Enter a unary operation into symbol table. |
|
305 |
* @param name The name of the operator. |
|
306 |
* @param arg The type of the operand. |
|
307 |
* @param res The operation's result type. |
|
308 |
* @param opcode The operation's bytecode instruction. |
|
309 |
*/ |
|
310 |
private OperatorSymbol enterUnop(String name, |
|
311 |
Type arg, |
|
312 |
Type res, |
|
313 |
int opcode) { |
|
314 |
OperatorSymbol sym = |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14046
diff
changeset
|
315 |
new OperatorSymbol(makeOperatorName(name), |
10 | 316 |
new MethodType(List.of(arg), |
317 |
res, |
|
318 |
List.<Type>nil(), |
|
319 |
methodClass), |
|
320 |
opcode, |
|
321 |
predefClass); |
|
322 |
predefClass.members().enter(sym); |
|
323 |
return sym; |
|
324 |
} |
|
325 |
||
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14046
diff
changeset
|
326 |
/** |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14046
diff
changeset
|
327 |
* Create a new operator name from corresponding String representation |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14046
diff
changeset
|
328 |
* and add the name to the set of known operator names. |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14046
diff
changeset
|
329 |
*/ |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14046
diff
changeset
|
330 |
private Name makeOperatorName(String name) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14046
diff
changeset
|
331 |
Name opName = names.fromString(name); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14046
diff
changeset
|
332 |
operatorNames.add(opName); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14046
diff
changeset
|
333 |
return opName; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14046
diff
changeset
|
334 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14046
diff
changeset
|
335 |
|
10 | 336 |
/** Enter a class into symbol table. |
14259 | 337 |
* @param s The name of the class. |
10 | 338 |
*/ |
339 |
private Type enterClass(String s) { |
|
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
340 |
return enterClass(names.fromString(s)).type; |
10 | 341 |
} |
342 |
||
1037
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
343 |
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
|
344 |
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
|
345 |
if (completer != null) { |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
346 |
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
|
347 |
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
|
348 |
try { |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
349 |
completer.complete(sym); |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
350 |
} catch (CompletionFailure e) { |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
351 |
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
|
352 |
((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
|
353 |
} |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
354 |
} |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
355 |
}; |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
356 |
} |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
357 |
} |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
358 |
|
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
359 |
public void synthesizeBoxTypeIfMissing(final Type type) { |
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
360 |
ClassSymbol sym = enterClass(boxedName[type.getTag().ordinal()]); |
1037
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
361 |
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
|
362 |
if (completer != null) { |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
363 |
sym.completer = new Completer() { |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
364 |
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
|
365 |
try { |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
366 |
completer.complete(sym); |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
367 |
} catch (CompletionFailure e) { |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
368 |
sym.flags_field |= PUBLIC; |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
369 |
((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
|
370 |
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
|
371 |
MethodSymbol boxMethod = |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
372 |
new MethodSymbol(PUBLIC | STATIC, |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
373 |
n, |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
374 |
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
|
375 |
List.<Type>nil(), methodClass), |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
376 |
sym); |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
377 |
sym.members().enter(boxMethod); |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
378 |
MethodSymbol unboxMethod = |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
379 |
new MethodSymbol(PUBLIC, |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
380 |
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
|
381 |
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
|
382 |
List.<Type>nil(), methodClass), |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
383 |
sym); |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
384 |
sym.members().enter(unboxMethod); |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
385 |
} |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
386 |
} |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
387 |
}; |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
388 |
} |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
389 |
|
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
390 |
} |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
391 |
|
15724 | 392 |
// Enter a synthetic class that is used to mark classes in ct.sym. |
393 |
// This class does not have a class file. |
|
394 |
private Type enterSyntheticAnnotation(String name) { |
|
395 |
ClassType type = (ClassType)enterClass(name); |
|
396 |
ClassSymbol sym = (ClassSymbol)type.tsym; |
|
397 |
sym.completer = null; |
|
398 |
sym.flags_field = PUBLIC|ACYCLIC|ANNOTATION|INTERFACE; |
|
399 |
sym.erasure_field = type; |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24604
diff
changeset
|
400 |
sym.members_field = WriteableScope.create(sym); |
15724 | 401 |
type.typarams_field = List.nil(); |
402 |
type.allparams_field = List.nil(); |
|
403 |
type.supertype_field = annotationType; |
|
404 |
type.interfaces_field = List.nil(); |
|
405 |
return type; |
|
406 |
} |
|
407 |
||
10 | 408 |
/** Constructor; enters all predefined identifiers and operators |
409 |
* into symbol table. |
|
410 |
*/ |
|
411 |
protected Symtab(Context context) throws CompletionFailure { |
|
412 |
context.put(symtabKey, this); |
|
413 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
414 |
names = Names.instance(context); |
1037
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
415 |
target = Target.instance(context); |
10 | 416 |
|
417 |
// Create the unknown type |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18414
diff
changeset
|
418 |
unknownType = new UnknownType(); |
10 | 419 |
|
420 |
// create the basic builtin symbols |
|
421 |
rootPackage = new PackageSymbol(names.empty, null); |
|
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
422 |
packages.put(names.empty, rootPackage); |
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1264
diff
changeset
|
423 |
final JavacMessages messages = JavacMessages.instance(context); |
10 | 424 |
unnamedPackage = new PackageSymbol(names.empty, rootPackage) { |
425 |
public String toString() { |
|
426 |
return messages.getLocalizedString("compiler.misc.unnamed.package"); |
|
427 |
} |
|
428 |
}; |
|
16967
79d444669f3f
7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents:
16333
diff
changeset
|
429 |
noSymbol = new TypeSymbol(Kinds.NIL, 0, names.empty, Type.noType, rootPackage) { |
8621
ce0bce60cffc
7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents:
8242
diff
changeset
|
430 |
public <R, P> R accept(ElementVisitor<R, P> v, P p) { |
ce0bce60cffc
7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents:
8242
diff
changeset
|
431 |
return v.visitUnknown(this, p); |
ce0bce60cffc
7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents:
8242
diff
changeset
|
432 |
} |
ce0bce60cffc
7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents:
8242
diff
changeset
|
433 |
}; |
10 | 434 |
|
435 |
// create the error symbols |
|
436 |
errSymbol = new ClassSymbol(PUBLIC|STATIC|ACYCLIC, names.any, null, rootPackage); |
|
8621
ce0bce60cffc
7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents:
8242
diff
changeset
|
437 |
errType = new ErrorType(errSymbol, Type.noType); |
ce0bce60cffc
7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents:
8242
diff
changeset
|
438 |
|
6594
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6148
diff
changeset
|
439 |
unknownSymbol = new ClassSymbol(PUBLIC|STATIC|ACYCLIC, names.fromString("<any?>"), null, rootPackage); |
8621
ce0bce60cffc
7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents:
8242
diff
changeset
|
440 |
unknownSymbol.members_field = new Scope.ErrorScope(unknownSymbol); |
ce0bce60cffc
7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents:
8242
diff
changeset
|
441 |
unknownSymbol.type = unknownType; |
10 | 442 |
|
443 |
// initialize builtin types |
|
444 |
initType(byteType, "byte", "Byte"); |
|
445 |
initType(shortType, "short", "Short"); |
|
446 |
initType(charType, "char", "Character"); |
|
447 |
initType(intType, "int", "Integer"); |
|
448 |
initType(longType, "long", "Long"); |
|
449 |
initType(floatType, "float", "Float"); |
|
450 |
initType(doubleType, "double", "Double"); |
|
451 |
initType(booleanType, "boolean", "Boolean"); |
|
452 |
initType(voidType, "void", "Void"); |
|
453 |
initType(botType, "<nulltype>"); |
|
454 |
initType(errType, errSymbol); |
|
6594
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6148
diff
changeset
|
455 |
initType(unknownType, unknownSymbol); |
10 | 456 |
|
457 |
// the builtin class of all arrays |
|
458 |
arrayClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Array, noSymbol); |
|
459 |
||
460 |
// VGJ |
|
461 |
boundClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Bound, noSymbol); |
|
8621
ce0bce60cffc
7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents:
8242
diff
changeset
|
462 |
boundClass.members_field = new Scope.ErrorScope(boundClass); |
10 | 463 |
|
464 |
// the builtin class of all methods |
|
465 |
methodClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Method, noSymbol); |
|
8621
ce0bce60cffc
7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents:
8242
diff
changeset
|
466 |
methodClass.members_field = new Scope.ErrorScope(boundClass); |
10 | 467 |
|
468 |
// Create class to hold all predefined constants and operations. |
|
469 |
predefClass = new ClassSymbol(PUBLIC|ACYCLIC, names.empty, rootPackage); |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24604
diff
changeset
|
470 |
WriteableScope scope = WriteableScope.create(predefClass); |
10 | 471 |
predefClass.members_field = scope; |
472 |
||
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
22442
diff
changeset
|
473 |
// Get the initial completer for Symbols from the ClassFinder |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
22442
diff
changeset
|
474 |
initialCompleter = ClassFinder.instance(context).getCompleter(); |
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
475 |
rootPackage.completer = initialCompleter; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
476 |
unnamedPackage.completer = initialCompleter; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
477 |
|
10 | 478 |
// Enter symbols for basic types. |
479 |
scope.enter(byteType.tsym); |
|
480 |
scope.enter(shortType.tsym); |
|
481 |
scope.enter(charType.tsym); |
|
482 |
scope.enter(intType.tsym); |
|
483 |
scope.enter(longType.tsym); |
|
484 |
scope.enter(floatType.tsym); |
|
485 |
scope.enter(doubleType.tsym); |
|
486 |
scope.enter(booleanType.tsym); |
|
487 |
scope.enter(errType.tsym); |
|
488 |
||
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1037
diff
changeset
|
489 |
// Enter symbol for the errSymbol |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1037
diff
changeset
|
490 |
scope.enter(errSymbol); |
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1037
diff
changeset
|
491 |
|
10 | 492 |
classes.put(predefClass.fullname, predefClass); |
493 |
||
494 |
// Enter predefined classes. |
|
495 |
objectType = enterClass("java.lang.Object"); |
|
496 |
classType = enterClass("java.lang.Class"); |
|
497 |
stringType = enterClass("java.lang.String"); |
|
498 |
stringBufferType = enterClass("java.lang.StringBuffer"); |
|
499 |
stringBuilderType = enterClass("java.lang.StringBuilder"); |
|
500 |
cloneableType = enterClass("java.lang.Cloneable"); |
|
501 |
throwableType = enterClass("java.lang.Throwable"); |
|
502 |
serializableType = enterClass("java.io.Serializable"); |
|
16300 | 503 |
serializedLambdaType = enterClass("java.lang.invoke.SerializedLambda"); |
8241
4161b56e0d20
7017414: before the move of JSR 292 to package java.lang.invoke, javac must recognize the new package
mcimadamore
parents:
8036
diff
changeset
|
504 |
methodHandleType = enterClass("java.lang.invoke.MethodHandle"); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
505 |
methodHandleLookupType = enterClass("java.lang.invoke.MethodHandles$Lookup"); |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13844
diff
changeset
|
506 |
methodTypeType = enterClass("java.lang.invoke.MethodType"); |
10 | 507 |
errorType = enterClass("java.lang.Error"); |
508 |
illegalArgumentExceptionType = enterClass("java.lang.IllegalArgumentException"); |
|
9076
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
8621
diff
changeset
|
509 |
interruptedExceptionType = enterClass("java.lang.InterruptedException"); |
10 | 510 |
exceptionType = enterClass("java.lang.Exception"); |
511 |
runtimeExceptionType = enterClass("java.lang.RuntimeException"); |
|
512 |
classNotFoundExceptionType = enterClass("java.lang.ClassNotFoundException"); |
|
513 |
noClassDefFoundErrorType = enterClass("java.lang.NoClassDefFoundError"); |
|
514 |
noSuchFieldErrorType = enterClass("java.lang.NoSuchFieldError"); |
|
515 |
assertionErrorType = enterClass("java.lang.AssertionError"); |
|
516 |
cloneNotSupportedExceptionType = enterClass("java.lang.CloneNotSupportedException"); |
|
517 |
annotationType = enterClass("java.lang.annotation.Annotation"); |
|
518 |
classLoaderType = enterClass("java.lang.ClassLoader"); |
|
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
519 |
enumSym = enterClass(names.java_lang_Enum); |
10 | 520 |
enumFinalFinalize = |
521 |
new MethodSymbol(PROTECTED|FINAL|HYPOTHETICAL, |
|
522 |
names.finalize, |
|
523 |
new MethodType(List.<Type>nil(), voidType, |
|
524 |
List.<Type>nil(), methodClass), |
|
525 |
enumSym); |
|
526 |
listType = enterClass("java.util.List"); |
|
527 |
collectionsType = enterClass("java.util.Collections"); |
|
528 |
comparableType = enterClass("java.lang.Comparable"); |
|
16333 | 529 |
comparatorType = enterClass("java.util.Comparator"); |
10 | 530 |
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
|
531 |
iterableType = target.hasIterable() |
10 | 532 |
? enterClass("java.lang.Iterable") |
533 |
: enterClass("java.util.Collection"); |
|
534 |
iteratorType = enterClass("java.util.Iterator"); |
|
535 |
annotationTargetType = enterClass("java.lang.annotation.Target"); |
|
536 |
overrideType = enterClass("java.lang.Override"); |
|
537 |
retentionType = enterClass("java.lang.annotation.Retention"); |
|
538 |
deprecatedType = enterClass("java.lang.Deprecated"); |
|
539 |
suppressWarningsType = enterClass("java.lang.SuppressWarnings"); |
|
540 |
inheritedType = enterClass("java.lang.annotation.Inherited"); |
|
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14539
diff
changeset
|
541 |
repeatableType = enterClass("java.lang.annotation.Repeatable"); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
12335
diff
changeset
|
542 |
documentedType = enterClass("java.lang.annotation.Documented"); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
12335
diff
changeset
|
543 |
elementTypeType = enterClass("java.lang.annotation.ElementType"); |
1037
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
544 |
systemType = enterClass("java.lang.System"); |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
545 |
autoCloseableType = enterClass("java.lang.AutoCloseable"); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
546 |
autoCloseableClose = new MethodSymbol(PUBLIC, |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
547 |
names.close, |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
548 |
new MethodType(List.<Type>nil(), voidType, |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
549 |
List.of(exceptionType), methodClass), |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
550 |
autoCloseableType.tsym); |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
6709
diff
changeset
|
551 |
trustMeType = enterClass("java.lang.SafeVarargs"); |
14539
507556c4e622
8003412: javac needs to understand java.lang.annotation.Native
jjg
parents:
14365
diff
changeset
|
552 |
nativeHeaderType = enterClass("java.lang.annotation.Native"); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
553 |
lambdaMetafactory = enterClass("java.lang.invoke.LambdaMetafactory"); |
15361
01f1828683e6
8005299: Add FunctionalInterface checking to javac
mcimadamore
parents:
15356
diff
changeset
|
554 |
functionalInterfaceType = enterClass("java.lang.FunctionalInterface"); |
1037
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
555 |
|
9076
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
8621
diff
changeset
|
556 |
synthesizeEmptyInterfaceIfMissing(autoCloseableType); |
1037
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
557 |
synthesizeEmptyInterfaceIfMissing(cloneableType); |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
558 |
synthesizeEmptyInterfaceIfMissing(serializableType); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
559 |
synthesizeEmptyInterfaceIfMissing(lambdaMetafactory); |
16300 | 560 |
synthesizeEmptyInterfaceIfMissing(serializedLambdaType); |
1037
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
561 |
synthesizeBoxTypeIfMissing(doubleType); |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
562 |
synthesizeBoxTypeIfMissing(floatType); |
3555
a6fd77fe81df
6390045: Unexpected error "cannot access java.lang.Void" with '-target cldc1.0' with -source >=1.5
mcimadamore
parents:
2723
diff
changeset
|
563 |
synthesizeBoxTypeIfMissing(voidType); |
10 | 564 |
|
5848
c5a4ce47e780
6960407: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5847
diff
changeset
|
565 |
// Enter a synthetic class that is used to mark internal |
10 | 566 |
// proprietary classes in ct.sym. This class does not have a |
567 |
// class file. |
|
15724 | 568 |
proprietaryType = enterSyntheticAnnotation("sun.Proprietary+Annotation"); |
569 |
||
570 |
// Enter a synthetic class that is used to provide profile info for |
|
571 |
// classes in ct.sym. This class does not have a class file. |
|
572 |
profileType = enterSyntheticAnnotation("jdk.Profile+Annotation"); |
|
573 |
MethodSymbol m = new MethodSymbol(PUBLIC | ABSTRACT, names.value, intType, profileType.tsym); |
|
574 |
profileType.tsym.members().enter(m); |
|
10 | 575 |
|
576 |
// Enter a class for arrays. |
|
577 |
// The class implements java.lang.Cloneable and java.io.Serializable. |
|
578 |
// It has a final length field and a clone method. |
|
579 |
ClassType arrayClassType = (ClassType)arrayClass.type; |
|
580 |
arrayClassType.supertype_field = objectType; |
|
581 |
arrayClassType.interfaces_field = List.of(cloneableType, serializableType); |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24604
diff
changeset
|
582 |
arrayClass.members_field = WriteableScope.create(arrayClass); |
10 | 583 |
lengthVar = new VarSymbol( |
584 |
PUBLIC | FINAL, |
|
585 |
names.length, |
|
586 |
intType, |
|
587 |
arrayClass); |
|
588 |
arrayClass.members().enter(lengthVar); |
|
589 |
arrayCloneMethod = new MethodSymbol( |
|
590 |
PUBLIC, |
|
591 |
names.clone, |
|
592 |
new MethodType(List.<Type>nil(), objectType, |
|
593 |
List.<Type>nil(), methodClass), |
|
594 |
arrayClass); |
|
595 |
arrayClass.members().enter(arrayCloneMethod); |
|
596 |
||
597 |
// Enter operators. |
|
18414
ee1e93e83d2b
8016610: javac, add new internal symbols to make operator resolution faster
vromero
parents:
17546
diff
changeset
|
598 |
/* Internally we use +++, --- for unary +, - to reduce +, - operators |
ee1e93e83d2b
8016610: javac, add new internal symbols to make operator resolution faster
vromero
parents:
17546
diff
changeset
|
599 |
* overloading |
ee1e93e83d2b
8016610: javac, add new internal symbols to make operator resolution faster
vromero
parents:
17546
diff
changeset
|
600 |
*/ |
ee1e93e83d2b
8016610: javac, add new internal symbols to make operator resolution faster
vromero
parents:
17546
diff
changeset
|
601 |
enterUnop("+++", doubleType, doubleType, nop); |
ee1e93e83d2b
8016610: javac, add new internal symbols to make operator resolution faster
vromero
parents:
17546
diff
changeset
|
602 |
enterUnop("+++", floatType, floatType, nop); |
ee1e93e83d2b
8016610: javac, add new internal symbols to make operator resolution faster
vromero
parents:
17546
diff
changeset
|
603 |
enterUnop("+++", longType, longType, nop); |
ee1e93e83d2b
8016610: javac, add new internal symbols to make operator resolution faster
vromero
parents:
17546
diff
changeset
|
604 |
enterUnop("+++", intType, intType, nop); |
10 | 605 |
|
18414
ee1e93e83d2b
8016610: javac, add new internal symbols to make operator resolution faster
vromero
parents:
17546
diff
changeset
|
606 |
enterUnop("---", doubleType, doubleType, dneg); |
ee1e93e83d2b
8016610: javac, add new internal symbols to make operator resolution faster
vromero
parents:
17546
diff
changeset
|
607 |
enterUnop("---", floatType, floatType, fneg); |
ee1e93e83d2b
8016610: javac, add new internal symbols to make operator resolution faster
vromero
parents:
17546
diff
changeset
|
608 |
enterUnop("---", longType, longType, lneg); |
ee1e93e83d2b
8016610: javac, add new internal symbols to make operator resolution faster
vromero
parents:
17546
diff
changeset
|
609 |
enterUnop("---", intType, intType, ineg); |
10 | 610 |
|
611 |
enterUnop("~", longType, longType, lxor); |
|
612 |
enterUnop("~", intType, intType, ixor); |
|
613 |
||
614 |
enterUnop("++", doubleType, doubleType, dadd); |
|
615 |
enterUnop("++", floatType, floatType, fadd); |
|
616 |
enterUnop("++", longType, longType, ladd); |
|
617 |
enterUnop("++", intType, intType, iadd); |
|
618 |
enterUnop("++", charType, charType, iadd); |
|
619 |
enterUnop("++", shortType, shortType, iadd); |
|
620 |
enterUnop("++", byteType, byteType, iadd); |
|
621 |
||
622 |
enterUnop("--", doubleType, doubleType, dsub); |
|
623 |
enterUnop("--", floatType, floatType, fsub); |
|
624 |
enterUnop("--", longType, longType, lsub); |
|
625 |
enterUnop("--", intType, intType, isub); |
|
626 |
enterUnop("--", charType, charType, isub); |
|
627 |
enterUnop("--", shortType, shortType, isub); |
|
628 |
enterUnop("--", byteType, byteType, isub); |
|
629 |
||
630 |
enterUnop("!", booleanType, booleanType, bool_not); |
|
631 |
nullcheck = enterUnop("<*nullchk*>", objectType, objectType, nullchk); |
|
632 |
||
633 |
// string concatenation |
|
634 |
enterBinop("+", stringType, objectType, stringType, string_add); |
|
635 |
enterBinop("+", objectType, stringType, stringType, string_add); |
|
636 |
enterBinop("+", stringType, stringType, stringType, string_add); |
|
637 |
enterBinop("+", stringType, intType, stringType, string_add); |
|
638 |
enterBinop("+", stringType, longType, stringType, string_add); |
|
639 |
enterBinop("+", stringType, floatType, stringType, string_add); |
|
640 |
enterBinop("+", stringType, doubleType, stringType, string_add); |
|
641 |
enterBinop("+", stringType, booleanType, stringType, string_add); |
|
642 |
enterBinop("+", stringType, botType, stringType, string_add); |
|
643 |
enterBinop("+", intType, stringType, stringType, string_add); |
|
644 |
enterBinop("+", longType, stringType, stringType, string_add); |
|
645 |
enterBinop("+", floatType, stringType, stringType, string_add); |
|
646 |
enterBinop("+", doubleType, stringType, stringType, string_add); |
|
647 |
enterBinop("+", booleanType, stringType, stringType, string_add); |
|
648 |
enterBinop("+", botType, stringType, stringType, string_add); |
|
649 |
||
650 |
// these errors would otherwise be matched as string concatenation |
|
651 |
enterBinop("+", botType, botType, botType, error); |
|
652 |
enterBinop("+", botType, intType, botType, error); |
|
653 |
enterBinop("+", botType, longType, botType, error); |
|
654 |
enterBinop("+", botType, floatType, botType, error); |
|
655 |
enterBinop("+", botType, doubleType, botType, error); |
|
656 |
enterBinop("+", botType, booleanType, botType, error); |
|
657 |
enterBinop("+", botType, objectType, botType, error); |
|
658 |
enterBinop("+", intType, botType, botType, error); |
|
659 |
enterBinop("+", longType, botType, botType, error); |
|
660 |
enterBinop("+", floatType, botType, botType, error); |
|
661 |
enterBinop("+", doubleType, botType, botType, error); |
|
662 |
enterBinop("+", booleanType, botType, botType, error); |
|
663 |
enterBinop("+", objectType, botType, botType, error); |
|
664 |
||
665 |
enterBinop("+", doubleType, doubleType, doubleType, dadd); |
|
666 |
enterBinop("+", floatType, floatType, floatType, fadd); |
|
667 |
enterBinop("+", longType, longType, longType, ladd); |
|
668 |
enterBinop("+", intType, intType, intType, iadd); |
|
669 |
||
670 |
enterBinop("-", doubleType, doubleType, doubleType, dsub); |
|
671 |
enterBinop("-", floatType, floatType, floatType, fsub); |
|
672 |
enterBinop("-", longType, longType, longType, lsub); |
|
673 |
enterBinop("-", intType, intType, intType, isub); |
|
674 |
||
675 |
enterBinop("*", doubleType, doubleType, doubleType, dmul); |
|
676 |
enterBinop("*", floatType, floatType, floatType, fmul); |
|
677 |
enterBinop("*", longType, longType, longType, lmul); |
|
678 |
enterBinop("*", intType, intType, intType, imul); |
|
679 |
||
680 |
enterBinop("/", doubleType, doubleType, doubleType, ddiv); |
|
681 |
enterBinop("/", floatType, floatType, floatType, fdiv); |
|
682 |
enterBinop("/", longType, longType, longType, ldiv); |
|
683 |
enterBinop("/", intType, intType, intType, idiv); |
|
684 |
||
685 |
enterBinop("%", doubleType, doubleType, doubleType, dmod); |
|
686 |
enterBinop("%", floatType, floatType, floatType, fmod); |
|
687 |
enterBinop("%", longType, longType, longType, lmod); |
|
688 |
enterBinop("%", intType, intType, intType, imod); |
|
689 |
||
690 |
enterBinop("&", booleanType, booleanType, booleanType, iand); |
|
691 |
enterBinop("&", longType, longType, longType, land); |
|
692 |
enterBinop("&", intType, intType, intType, iand); |
|
693 |
||
694 |
enterBinop("|", booleanType, booleanType, booleanType, ior); |
|
695 |
enterBinop("|", longType, longType, longType, lor); |
|
696 |
enterBinop("|", intType, intType, intType, ior); |
|
697 |
||
698 |
enterBinop("^", booleanType, booleanType, booleanType, ixor); |
|
699 |
enterBinop("^", longType, longType, longType, lxor); |
|
700 |
enterBinop("^", intType, intType, intType, ixor); |
|
701 |
||
702 |
enterBinop("<<", longType, longType, longType, lshll); |
|
703 |
enterBinop("<<", intType, longType, intType, ishll); |
|
704 |
enterBinop("<<", longType, intType, longType, lshl); |
|
705 |
enterBinop("<<", intType, intType, intType, ishl); |
|
706 |
||
707 |
enterBinop(">>", longType, longType, longType, lshrl); |
|
708 |
enterBinop(">>", intType, longType, intType, ishrl); |
|
709 |
enterBinop(">>", longType, intType, longType, lshr); |
|
710 |
enterBinop(">>", intType, intType, intType, ishr); |
|
711 |
||
712 |
enterBinop(">>>", longType, longType, longType, lushrl); |
|
713 |
enterBinop(">>>", intType, longType, intType, iushrl); |
|
714 |
enterBinop(">>>", longType, intType, longType, lushr); |
|
715 |
enterBinop(">>>", intType, intType, intType, iushr); |
|
716 |
||
717 |
enterBinop("<", doubleType, doubleType, booleanType, dcmpg, iflt); |
|
718 |
enterBinop("<", floatType, floatType, booleanType, fcmpg, iflt); |
|
719 |
enterBinop("<", longType, longType, booleanType, lcmp, iflt); |
|
720 |
enterBinop("<", intType, intType, booleanType, if_icmplt); |
|
721 |
||
722 |
enterBinop(">", doubleType, doubleType, booleanType, dcmpl, ifgt); |
|
723 |
enterBinop(">", floatType, floatType, booleanType, fcmpl, ifgt); |
|
724 |
enterBinop(">", longType, longType, booleanType, lcmp, ifgt); |
|
725 |
enterBinop(">", intType, intType, booleanType, if_icmpgt); |
|
726 |
||
727 |
enterBinop("<=", doubleType, doubleType, booleanType, dcmpg, ifle); |
|
728 |
enterBinop("<=", floatType, floatType, booleanType, fcmpg, ifle); |
|
729 |
enterBinop("<=", longType, longType, booleanType, lcmp, ifle); |
|
730 |
enterBinop("<=", intType, intType, booleanType, if_icmple); |
|
731 |
||
732 |
enterBinop(">=", doubleType, doubleType, booleanType, dcmpl, ifge); |
|
733 |
enterBinop(">=", floatType, floatType, booleanType, fcmpl, ifge); |
|
734 |
enterBinop(">=", longType, longType, booleanType, lcmp, ifge); |
|
735 |
enterBinop(">=", intType, intType, booleanType, if_icmpge); |
|
736 |
||
737 |
enterBinop("==", objectType, objectType, booleanType, if_acmpeq); |
|
738 |
enterBinop("==", booleanType, booleanType, booleanType, if_icmpeq); |
|
739 |
enterBinop("==", doubleType, doubleType, booleanType, dcmpl, ifeq); |
|
740 |
enterBinop("==", floatType, floatType, booleanType, fcmpl, ifeq); |
|
741 |
enterBinop("==", longType, longType, booleanType, lcmp, ifeq); |
|
742 |
enterBinop("==", intType, intType, booleanType, if_icmpeq); |
|
743 |
||
744 |
enterBinop("!=", objectType, objectType, booleanType, if_acmpne); |
|
745 |
enterBinop("!=", booleanType, booleanType, booleanType, if_icmpne); |
|
746 |
enterBinop("!=", doubleType, doubleType, booleanType, dcmpl, ifne); |
|
747 |
enterBinop("!=", floatType, floatType, booleanType, fcmpl, ifne); |
|
748 |
enterBinop("!=", longType, longType, booleanType, lcmp, ifne); |
|
749 |
enterBinop("!=", intType, intType, booleanType, if_icmpne); |
|
750 |
||
751 |
enterBinop("&&", booleanType, booleanType, booleanType, bool_and); |
|
752 |
enterBinop("||", booleanType, booleanType, booleanType, bool_or); |
|
753 |
} |
|
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
754 |
|
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
755 |
/** Define a new class given its name and owner. |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
756 |
*/ |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
757 |
public ClassSymbol defineClass(Name name, Symbol owner) { |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
758 |
ClassSymbol c = new ClassSymbol(0, name, owner); |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
759 |
if (owner.kind == PCK) |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
760 |
Assert.checkNull(classes.get(c.flatname), c); |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
761 |
c.completer = initialCompleter; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
762 |
return c; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
763 |
} |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
764 |
|
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
765 |
/** Create a new toplevel or member class symbol with given name |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
766 |
* and owner and enter in `classes' unless already there. |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
767 |
*/ |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
768 |
public ClassSymbol enterClass(Name name, TypeSymbol owner) { |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
769 |
Name flatname = TypeSymbol.formFlatName(name, owner); |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
770 |
ClassSymbol c = classes.get(flatname); |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
771 |
if (c == null) { |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
772 |
c = defineClass(name, owner); |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
773 |
classes.put(flatname, c); |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
774 |
} else if ((c.name != name || c.owner != owner) && owner.kind == TYP && c.owner.kind == PCK) { |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
775 |
// reassign fields of classes that might have been loaded with |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
776 |
// their flat names. |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
777 |
c.owner.members().remove(c); |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
778 |
c.name = name; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
779 |
c.owner = owner; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
780 |
c.fullname = ClassSymbol.formFullName(name, owner); |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
781 |
} |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
782 |
return c; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
783 |
} |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
784 |
|
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
785 |
/** |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
786 |
* Creates a new toplevel class symbol with given flat name and |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
787 |
* given class (or source) file. |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
788 |
* |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
789 |
* @param flatName a fully qualified binary class name |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
790 |
* @param classFile the class file or compilation unit defining |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
791 |
* the class (may be {@code null}) |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
792 |
* @return a newly created class symbol |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
793 |
* @throws AssertionError if the class symbol already exists |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
794 |
*/ |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
795 |
public ClassSymbol enterClass(Name flatName, JavaFileObject classFile) { |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
796 |
ClassSymbol cs = classes.get(flatName); |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
797 |
if (cs != null) { |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
798 |
String msg = Log.format("%s: completer = %s; class file = %s; source file = %s", |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
799 |
cs.fullname, |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
800 |
cs.completer, |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
801 |
cs.classfile, |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
802 |
cs.sourcefile); |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
803 |
throw new AssertionError(msg); |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
804 |
} |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
805 |
Name packageName = Convert.packagePart(flatName); |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
806 |
PackageSymbol owner = packageName.isEmpty() |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
807 |
? unnamedPackage |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
808 |
: enterPackage(packageName); |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
809 |
cs = defineClass(Convert.shortName(flatName), owner); |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
810 |
cs.classfile = classFile; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
811 |
classes.put(flatName, cs); |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
812 |
return cs; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
813 |
} |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
814 |
|
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
815 |
/** Create a new member or toplevel class symbol with given flat name |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
816 |
* and enter in `classes' unless already there. |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
817 |
*/ |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
818 |
public ClassSymbol enterClass(Name flatname) { |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
819 |
ClassSymbol c = classes.get(flatname); |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
820 |
if (c == null) |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
821 |
return enterClass(flatname, (JavaFileObject)null); |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
822 |
else |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
823 |
return c; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
824 |
} |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
825 |
|
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
826 |
/** Check to see if a package exists, given its fully qualified name. |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
827 |
*/ |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
828 |
public boolean packageExists(Name fullname) { |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
829 |
return enterPackage(fullname).exists(); |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
830 |
} |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
831 |
|
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
832 |
/** Make a package, given its fully qualified name. |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
833 |
*/ |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
834 |
public PackageSymbol enterPackage(Name fullname) { |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
835 |
PackageSymbol p = packages.get(fullname); |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
836 |
if (p == null) { |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
837 |
Assert.check(!fullname.isEmpty(), "rootPackage missing!"); |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
838 |
p = new PackageSymbol( |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
839 |
Convert.shortName(fullname), |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
840 |
enterPackage(Convert.packagePart(fullname))); |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
841 |
p.completer = initialCompleter; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
842 |
packages.put(fullname, p); |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
843 |
} |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
844 |
return p; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
845 |
} |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
846 |
|
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
847 |
/** Make a package, given its unqualified name and enclosing package. |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
848 |
*/ |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
849 |
public PackageSymbol enterPackage(Name name, PackageSymbol owner) { |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
850 |
return enterPackage(TypeSymbol.formFullName(name, owner)); |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
851 |
} |
10 | 852 |
} |