author | zmajo |
Thu, 24 Mar 2016 16:21:21 +0100 | |
changeset 36996 | 2c3a5307865f |
parent 36995 | e19153419efd |
parent 36526 | 3b41f1c69604 |
child 37744 | bf4fd5e022c5 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
36526 | 2 |
* Copyright (c) 1999, 2016, 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 |
||
36526 | 28 |
import java.util.Collection; |
29 |
import java.util.Collections; |
|
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
30 |
import java.util.HashMap; |
36526 | 31 |
import java.util.LinkedHashMap; |
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
32 |
import java.util.Map; |
10 | 33 |
|
14258 | 34 |
import javax.lang.model.element.ElementVisitor; |
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
35 |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24604
diff
changeset
|
36 |
import com.sun.tools.javac.code.Scope.WriteableScope; |
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
37 |
import com.sun.tools.javac.code.Symbol.ClassSymbol; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
38 |
import com.sun.tools.javac.code.Symbol.Completer; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
39 |
import com.sun.tools.javac.code.Symbol.CompletionFailure; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
40 |
import com.sun.tools.javac.code.Symbol.MethodSymbol; |
36526 | 41 |
import com.sun.tools.javac.code.Symbol.ModuleSymbol; |
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
42 |
import com.sun.tools.javac.code.Symbol.PackageSymbol; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
43 |
import com.sun.tools.javac.code.Symbol.TypeSymbol; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
44 |
import com.sun.tools.javac.code.Symbol.VarSymbol; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
45 |
import com.sun.tools.javac.code.Type.BottomType; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
46 |
import com.sun.tools.javac.code.Type.ClassType; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
47 |
import com.sun.tools.javac.code.Type.ErrorType; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
48 |
import com.sun.tools.javac.code.Type.JCPrimitiveType; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
49 |
import com.sun.tools.javac.code.Type.JCVoidType; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
50 |
import com.sun.tools.javac.code.Type.MethodType; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
51 |
import com.sun.tools.javac.code.Type.UnknownType; |
36526 | 52 |
import com.sun.tools.javac.comp.Modules; |
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
53 |
import com.sun.tools.javac.util.Assert; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
54 |
import com.sun.tools.javac.util.Context; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
55 |
import com.sun.tools.javac.util.Convert; |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
56 |
import com.sun.tools.javac.util.DefinedBy; |
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
57 |
import com.sun.tools.javac.util.DefinedBy.Api; |
36526 | 58 |
import com.sun.tools.javac.util.Iterators; |
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
59 |
import com.sun.tools.javac.util.JavacMessages; |
14258 | 60 |
import com.sun.tools.javac.util.List; |
22442
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; |
36526 | 63 |
import com.sun.tools.javac.util.Options; |
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
64 |
|
14258 | 65 |
import static com.sun.tools.javac.code.Flags.*; |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26266
diff
changeset
|
66 |
import static com.sun.tools.javac.code.Kinds.Kind.*; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
67 |
import static com.sun.tools.javac.code.TypeTag.*; |
10 | 68 |
|
69 |
/** A class that defines all predefined constants and operators |
|
70 |
* as well as special classes such as java.lang.Object, which need |
|
71 |
* to be known to the compiler. All symbols are held in instance |
|
72 |
* fields. This makes it possible to work in multiple concurrent |
|
73 |
* projects, which might use different class files for library classes. |
|
74 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
75 |
* <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
|
76 |
* If you write code that depends on this, you do so at your own risk. |
10 | 77 |
* This code and its internal interfaces are subject to change or |
78 |
* deletion without notice.</b> |
|
79 |
*/ |
|
80 |
public class Symtab { |
|
81 |
/** The context key for the symbol table. */ |
|
22163 | 82 |
protected static final Context.Key<Symtab> symtabKey = new Context.Key<>(); |
10 | 83 |
|
84 |
/** Get the symbol table instance. */ |
|
85 |
public static Symtab instance(Context context) { |
|
86 |
Symtab instance = context.get(symtabKey); |
|
87 |
if (instance == null) |
|
88 |
instance = new Symtab(context); |
|
89 |
return instance; |
|
90 |
} |
|
91 |
||
92 |
/** Builtin types. |
|
93 |
*/ |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18414
diff
changeset
|
94 |
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
|
95 |
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
|
96 |
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
|
97 |
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
|
98 |
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
|
99 |
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
|
100 |
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
|
101 |
public final JCPrimitiveType booleanType = new JCPrimitiveType(BOOLEAN, null); |
10 | 102 |
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
|
103 |
public final JCVoidType voidType = new JCVoidType(); |
10 | 104 |
|
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
105 |
private final Names names; |
36526 | 106 |
private final JavacMessages messages; |
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
107 |
private final Completer initialCompleter; |
36526 | 108 |
private final Completer moduleCompleter; |
109 |
||
110 |
/** A symbol for the unnamed module. |
|
111 |
*/ |
|
112 |
public final ModuleSymbol unnamedModule; |
|
113 |
||
114 |
/** The error module. |
|
115 |
*/ |
|
116 |
public final ModuleSymbol errModule; |
|
117 |
||
118 |
/** A symbol for no module, for use with -source 8 or less |
|
119 |
*/ |
|
120 |
public final ModuleSymbol noModule; |
|
10 | 121 |
|
122 |
/** A symbol for the root package. |
|
123 |
*/ |
|
124 |
public final PackageSymbol rootPackage; |
|
125 |
||
126 |
/** A symbol that stands for a missing symbol. |
|
127 |
*/ |
|
128 |
public final TypeSymbol noSymbol; |
|
129 |
||
130 |
/** The error symbol. |
|
131 |
*/ |
|
132 |
public final ClassSymbol errSymbol; |
|
133 |
||
6594
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6148
diff
changeset
|
134 |
/** The unknown symbol. |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6148
diff
changeset
|
135 |
*/ |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6148
diff
changeset
|
136 |
public final ClassSymbol unknownSymbol; |
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6148
diff
changeset
|
137 |
|
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
|
138 |
/** A value for the errType, with a originalType of noType */ |
10 | 139 |
public final Type errType; |
140 |
||
141 |
/** A value for the unknown type. */ |
|
142 |
public final Type unknownType; |
|
143 |
||
144 |
/** The builtin type of all arrays. */ |
|
145 |
public final ClassSymbol arrayClass; |
|
146 |
public final MethodSymbol arrayCloneMethod; |
|
147 |
||
148 |
/** VGJ: The (singleton) type of all bound types. */ |
|
149 |
public final ClassSymbol boundClass; |
|
150 |
||
151 |
/** The builtin type of all methods. */ |
|
152 |
public final ClassSymbol methodClass; |
|
153 |
||
36526 | 154 |
/** A symbol for the java.base module. |
155 |
*/ |
|
156 |
public final ModuleSymbol java_base; |
|
157 |
||
10 | 158 |
/** Predefined types. |
159 |
*/ |
|
160 |
public final Type objectType; |
|
29295
5a367770a074
8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
29294
diff
changeset
|
161 |
public final Type objectsType; |
10 | 162 |
public final Type classType; |
163 |
public final Type classLoaderType; |
|
164 |
public final Type stringType; |
|
165 |
public final Type stringBufferType; |
|
166 |
public final Type stringBuilderType; |
|
167 |
public final Type cloneableType; |
|
168 |
public final Type serializableType; |
|
16300 | 169 |
public final Type serializedLambdaType; |
36995 | 170 |
public final Type varHandleType; |
2723
b659ca23d5f5
6829189: Java programming with JSR 292 needs language support
jrose
parents:
1471
diff
changeset
|
171 |
public final Type methodHandleType; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
172 |
public final Type methodHandleLookupType; |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13844
diff
changeset
|
173 |
public final Type methodTypeType; |
12213
516b112d6c68
7150368: javac should include basic ability to generate native headers
jjg
parents:
9082
diff
changeset
|
174 |
public final Type nativeHeaderType; |
10 | 175 |
public final Type throwableType; |
176 |
public final Type errorType; |
|
9076
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
8621
diff
changeset
|
177 |
public final Type interruptedExceptionType; |
10 | 178 |
public final Type illegalArgumentExceptionType; |
179 |
public final Type exceptionType; |
|
180 |
public final Type runtimeExceptionType; |
|
181 |
public final Type classNotFoundExceptionType; |
|
182 |
public final Type noClassDefFoundErrorType; |
|
183 |
public final Type noSuchFieldErrorType; |
|
184 |
public final Type assertionErrorType; |
|
185 |
public final Type cloneNotSupportedExceptionType; |
|
186 |
public final Type annotationType; |
|
187 |
public final TypeSymbol enumSym; |
|
188 |
public final Type listType; |
|
189 |
public final Type collectionsType; |
|
190 |
public final Type comparableType; |
|
16333 | 191 |
public final Type comparatorType; |
10 | 192 |
public final Type arraysType; |
193 |
public final Type iterableType; |
|
194 |
public final Type iteratorType; |
|
195 |
public final Type annotationTargetType; |
|
196 |
public final Type overrideType; |
|
197 |
public final Type retentionType; |
|
198 |
public final Type deprecatedType; |
|
199 |
public final Type suppressWarningsType; |
|
29294
376a915b4ff0
8073645: Add lambda-based lazy eval versions of Assert.check methods
mcimadamore
parents:
29051
diff
changeset
|
200 |
public final Type supplierType; |
10 | 201 |
public final Type inheritedType; |
15724 | 202 |
public final Type profileType; |
10 | 203 |
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
|
204 |
public final Type systemType; |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
205 |
public final Type autoCloseableType; |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
6709
diff
changeset
|
206 |
public final Type trustMeType; |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
207 |
public final Type lambdaMetafactory; |
35424 | 208 |
public final Type stringConcatFactory; |
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14539
diff
changeset
|
209 |
public final Type repeatableType; |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
12335
diff
changeset
|
210 |
public final Type documentedType; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
12335
diff
changeset
|
211 |
public final Type elementTypeType; |
15361
01f1828683e6
8005299: Add FunctionalInterface checking to javac
mcimadamore
parents:
15356
diff
changeset
|
212 |
public final Type functionalInterfaceType; |
10 | 213 |
|
214 |
/** The symbol representing the length field of an array. |
|
215 |
*/ |
|
216 |
public final VarSymbol lengthVar; |
|
217 |
||
218 |
/** The symbol representing the final finalize method on enums */ |
|
219 |
public final MethodSymbol enumFinalFinalize; |
|
220 |
||
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
221 |
/** 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
|
222 |
public final MethodSymbol autoCloseableClose; |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
223 |
|
10 | 224 |
/** The predefined type that belongs to a tag. |
225 |
*/ |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
226 |
public final Type[] typeOfTag = new Type[TypeTag.getTypeTagCount()]; |
10 | 227 |
|
36526 | 228 |
/** The name of the class that belongs to a basic type tag. |
10 | 229 |
*/ |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
230 |
public final Name[] boxedName = new Name[TypeTag.getTypeTagCount()]; |
10 | 231 |
|
232 |
/** A hashtable containing the encountered top-level and member classes, |
|
233 |
* indexed by flat names. The table does not contain local classes. |
|
234 |
* It should be updated from the outside to reflect classes defined |
|
235 |
* by compiled source files. |
|
236 |
*/ |
|
36526 | 237 |
private final Map<Name, Map<ModuleSymbol,ClassSymbol>> classes = new HashMap<>(); |
10 | 238 |
|
239 |
/** A hashtable containing the encountered packages. |
|
240 |
* the table should be updated from outside to reflect packages defined |
|
241 |
* by compiled source files. |
|
242 |
*/ |
|
36526 | 243 |
private final Map<Name, Map<ModuleSymbol,PackageSymbol>> packages = new HashMap<>(); |
244 |
||
245 |
/** A hashtable giving the encountered modules. |
|
246 |
*/ |
|
247 |
private final Map<Name, ModuleSymbol> modules = new LinkedHashMap<>(); |
|
10 | 248 |
|
249 |
public void initType(Type type, ClassSymbol c) { |
|
250 |
type.tsym = c; |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18414
diff
changeset
|
251 |
typeOfTag[type.getTag().ordinal()] = type; |
10 | 252 |
} |
253 |
||
254 |
public void initType(Type type, String name) { |
|
255 |
initType( |
|
256 |
type, |
|
257 |
new ClassSymbol( |
|
258 |
PUBLIC, names.fromString(name), type, rootPackage)); |
|
259 |
} |
|
260 |
||
261 |
public void initType(Type type, String name, String bname) { |
|
262 |
initType(type, name); |
|
36526 | 263 |
boxedName[type.getTag().ordinal()] = names.fromString("java.lang." + bname); |
10 | 264 |
} |
265 |
||
266 |
/** The class symbol that owns all predefined symbols. |
|
267 |
*/ |
|
268 |
public final ClassSymbol predefClass; |
|
269 |
||
270 |
/** Enter a class into symbol table. |
|
14259 | 271 |
* @param s The name of the class. |
10 | 272 |
*/ |
273 |
private Type enterClass(String s) { |
|
36526 | 274 |
return enterClass(java_base, names.fromString(s)).type; |
10 | 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; |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
279 |
type.tsym.completer = new Completer() { |
36526 | 280 |
@Override |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
281 |
public void complete(Symbol sym) throws CompletionFailure { |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
282 |
try { |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
283 |
completer.complete(sym); |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
284 |
} catch (CompletionFailure e) { |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
285 |
sym.flags_field |= (PUBLIC | INTERFACE); |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
286 |
((ClassType) sym.type).supertype_field = objectType; |
1037
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
287 |
} |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
288 |
} |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
289 |
|
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
290 |
@Override |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
291 |
public boolean isTerminal() { |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
292 |
return completer.isTerminal(); |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
293 |
} |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
294 |
}; |
1037
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
295 |
} |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
296 |
|
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
297 |
public void synthesizeBoxTypeIfMissing(final Type type) { |
36526 | 298 |
ClassSymbol sym = enterClass(java_base, 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
|
299 |
final Completer completer = sym.completer; |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
300 |
sym.completer = new Completer() { |
36526 | 301 |
@Override |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
302 |
public void complete(Symbol sym) throws CompletionFailure { |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
303 |
try { |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
304 |
completer.complete(sym); |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
305 |
} catch (CompletionFailure e) { |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
306 |
sym.flags_field |= PUBLIC; |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
307 |
((ClassType) sym.type).supertype_field = objectType; |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
308 |
MethodSymbol boxMethod = |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
309 |
new MethodSymbol(PUBLIC | STATIC, names.valueOf, |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
310 |
new MethodType(List.of(type), sym.type, |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
311 |
List.<Type>nil(), methodClass), |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
312 |
sym); |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
313 |
sym.members().enter(boxMethod); |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
314 |
MethodSymbol unboxMethod = |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
315 |
new MethodSymbol(PUBLIC, |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
316 |
type.tsym.name.append(names.Value), // x.intValue() |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
317 |
new MethodType(List.<Type>nil(), type, |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
318 |
List.<Type>nil(), methodClass), |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
319 |
sym); |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
320 |
sym.members().enter(unboxMethod); |
1037
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
321 |
} |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
322 |
} |
1037
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
323 |
|
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
324 |
@Override |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
325 |
public boolean isTerminal() { |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
326 |
return completer.isTerminal(); |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
327 |
} |
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
328 |
}; |
1037
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
329 |
} |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
330 |
|
15724 | 331 |
// Enter a synthetic class that is used to mark classes in ct.sym. |
332 |
// This class does not have a class file. |
|
333 |
private Type enterSyntheticAnnotation(String name) { |
|
36526 | 334 |
// for now, leave the module null, to prevent problems from synthesizing the |
335 |
// existence of a class in any specific module, including noModule |
|
336 |
ClassType type = (ClassType)enterClass(java_base, names.fromString(name)).type; |
|
15724 | 337 |
ClassSymbol sym = (ClassSymbol)type.tsym; |
30066
d74c06a92bd8
8078600: Infinite loop when compiling annotations with -XDcompletionDeps
alundblad
parents:
29295
diff
changeset
|
338 |
sym.completer = Completer.NULL_COMPLETER; |
15724 | 339 |
sym.flags_field = PUBLIC|ACYCLIC|ANNOTATION|INTERFACE; |
340 |
sym.erasure_field = type; |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24604
diff
changeset
|
341 |
sym.members_field = WriteableScope.create(sym); |
15724 | 342 |
type.typarams_field = List.nil(); |
343 |
type.allparams_field = List.nil(); |
|
344 |
type.supertype_field = annotationType; |
|
345 |
type.interfaces_field = List.nil(); |
|
346 |
return type; |
|
347 |
} |
|
348 |
||
10 | 349 |
/** Constructor; enters all predefined identifiers and operators |
350 |
* into symbol table. |
|
351 |
*/ |
|
352 |
protected Symtab(Context context) throws CompletionFailure { |
|
353 |
context.put(symtabKey, this); |
|
354 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
1257
diff
changeset
|
355 |
names = Names.instance(context); |
10 | 356 |
|
357 |
// Create the unknown type |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18414
diff
changeset
|
358 |
unknownType = new UnknownType(); |
10 | 359 |
|
36526 | 360 |
messages = JavacMessages.instance(context); |
361 |
||
10 | 362 |
rootPackage = new PackageSymbol(names.empty, null); |
36526 | 363 |
|
364 |
// create the basic builtin symbols |
|
365 |
unnamedModule = new ModuleSymbol(names.empty, null) { |
|
366 |
@Override |
|
10 | 367 |
public String toString() { |
36526 | 368 |
return messages.getLocalizedString("compiler.misc.unnamed.module"); |
10 | 369 |
} |
370 |
}; |
|
36526 | 371 |
addRootPackageFor(unnamedModule); |
372 |
||
373 |
errModule = new ModuleSymbol(names.empty, null) { }; |
|
374 |
addRootPackageFor(errModule); |
|
375 |
||
376 |
noModule = new ModuleSymbol(names.empty, null) { |
|
377 |
@Override public boolean isNoModule() { |
|
378 |
return true; |
|
379 |
} |
|
380 |
}; |
|
381 |
addRootPackageFor(noModule); |
|
382 |
||
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26266
diff
changeset
|
383 |
noSymbol = new TypeSymbol(NIL, 0, names.empty, Type.noType, rootPackage) { |
36526 | 384 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
8621
ce0bce60cffc
7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents:
8242
diff
changeset
|
385 |
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
|
386 |
return v.visitUnknown(this, p); |
ce0bce60cffc
7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents:
8242
diff
changeset
|
387 |
} |
ce0bce60cffc
7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents:
8242
diff
changeset
|
388 |
}; |
10 | 389 |
|
390 |
// create the error symbols |
|
391 |
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
|
392 |
errType = new ErrorType(errSymbol, Type.noType); |
ce0bce60cffc
7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents:
8242
diff
changeset
|
393 |
|
6594
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6148
diff
changeset
|
394 |
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
|
395 |
unknownSymbol.members_field = new Scope.ErrorScope(unknownSymbol); |
ce0bce60cffc
7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents:
8242
diff
changeset
|
396 |
unknownSymbol.type = unknownType; |
10 | 397 |
|
398 |
// initialize builtin types |
|
399 |
initType(byteType, "byte", "Byte"); |
|
400 |
initType(shortType, "short", "Short"); |
|
401 |
initType(charType, "char", "Character"); |
|
402 |
initType(intType, "int", "Integer"); |
|
403 |
initType(longType, "long", "Long"); |
|
404 |
initType(floatType, "float", "Float"); |
|
405 |
initType(doubleType, "double", "Double"); |
|
406 |
initType(booleanType, "boolean", "Boolean"); |
|
407 |
initType(voidType, "void", "Void"); |
|
408 |
initType(botType, "<nulltype>"); |
|
409 |
initType(errType, errSymbol); |
|
6594
d43f068fba19
6970584: Flow.java should be more error-friendly
mcimadamore
parents:
6148
diff
changeset
|
410 |
initType(unknownType, unknownSymbol); |
10 | 411 |
|
412 |
// the builtin class of all arrays |
|
413 |
arrayClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Array, noSymbol); |
|
414 |
||
415 |
// VGJ |
|
416 |
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
|
417 |
boundClass.members_field = new Scope.ErrorScope(boundClass); |
10 | 418 |
|
419 |
// the builtin class of all methods |
|
420 |
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
|
421 |
methodClass.members_field = new Scope.ErrorScope(boundClass); |
10 | 422 |
|
423 |
// Create class to hold all predefined constants and operations. |
|
424 |
predefClass = new ClassSymbol(PUBLIC|ACYCLIC, names.empty, rootPackage); |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24604
diff
changeset
|
425 |
WriteableScope scope = WriteableScope.create(predefClass); |
10 | 426 |
predefClass.members_field = scope; |
427 |
||
24604
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
22442
diff
changeset
|
428 |
// Get the initial completer for Symbols from the ClassFinder |
7f68545b5128
8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents:
22442
diff
changeset
|
429 |
initialCompleter = ClassFinder.instance(context).getCompleter(); |
36526 | 430 |
rootPackage.members_field = WriteableScope.create(rootPackage); |
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
431 |
|
10 | 432 |
// Enter symbols for basic types. |
433 |
scope.enter(byteType.tsym); |
|
434 |
scope.enter(shortType.tsym); |
|
435 |
scope.enter(charType.tsym); |
|
436 |
scope.enter(intType.tsym); |
|
437 |
scope.enter(longType.tsym); |
|
438 |
scope.enter(floatType.tsym); |
|
439 |
scope.enter(doubleType.tsym); |
|
440 |
scope.enter(booleanType.tsym); |
|
441 |
scope.enter(errType.tsym); |
|
442 |
||
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
|
443 |
// 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
|
444 |
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
|
445 |
|
36526 | 446 |
Source source = Source.instance(context); |
447 |
Options options = Options.instance(context); |
|
448 |
boolean noModules = options.isSet("noModules"); |
|
449 |
if (source.allowModules() && !noModules) { |
|
450 |
java_base = enterModule(names.java_base); |
|
451 |
//avoid completing java.base during the Symtab initialization |
|
452 |
java_base.completer = Completer.NULL_COMPLETER; |
|
453 |
java_base.visiblePackages = Collections.emptyMap(); |
|
454 |
} else { |
|
455 |
java_base = noModule; |
|
456 |
} |
|
10 | 457 |
|
36526 | 458 |
// Get the initial completer for ModuleSymbols from Modules |
459 |
moduleCompleter = Modules.instance(context).getCompleter(); |
|
460 |
||
461 |
// Enter predefined classes. All are assumed to be in the java.base module. |
|
10 | 462 |
objectType = enterClass("java.lang.Object"); |
29295
5a367770a074
8073432: Object.getClass() throws stackless NPE, due to C2 intrinsic
mcimadamore
parents:
29294
diff
changeset
|
463 |
objectsType = enterClass("java.util.Objects"); |
10 | 464 |
classType = enterClass("java.lang.Class"); |
465 |
stringType = enterClass("java.lang.String"); |
|
466 |
stringBufferType = enterClass("java.lang.StringBuffer"); |
|
467 |
stringBuilderType = enterClass("java.lang.StringBuilder"); |
|
468 |
cloneableType = enterClass("java.lang.Cloneable"); |
|
469 |
throwableType = enterClass("java.lang.Throwable"); |
|
470 |
serializableType = enterClass("java.io.Serializable"); |
|
16300 | 471 |
serializedLambdaType = enterClass("java.lang.invoke.SerializedLambda"); |
36995 | 472 |
varHandleType = enterClass("java.lang.invoke.VarHandle"); |
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
|
473 |
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
|
474 |
methodHandleLookupType = enterClass("java.lang.invoke.MethodHandles$Lookup"); |
14046
8ef5d5b19998
7194586: Add back-end support for invokedynamic
mcimadamore
parents:
13844
diff
changeset
|
475 |
methodTypeType = enterClass("java.lang.invoke.MethodType"); |
10 | 476 |
errorType = enterClass("java.lang.Error"); |
477 |
illegalArgumentExceptionType = enterClass("java.lang.IllegalArgumentException"); |
|
9076
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
8621
diff
changeset
|
478 |
interruptedExceptionType = enterClass("java.lang.InterruptedException"); |
10 | 479 |
exceptionType = enterClass("java.lang.Exception"); |
480 |
runtimeExceptionType = enterClass("java.lang.RuntimeException"); |
|
481 |
classNotFoundExceptionType = enterClass("java.lang.ClassNotFoundException"); |
|
482 |
noClassDefFoundErrorType = enterClass("java.lang.NoClassDefFoundError"); |
|
483 |
noSuchFieldErrorType = enterClass("java.lang.NoSuchFieldError"); |
|
484 |
assertionErrorType = enterClass("java.lang.AssertionError"); |
|
485 |
cloneNotSupportedExceptionType = enterClass("java.lang.CloneNotSupportedException"); |
|
486 |
annotationType = enterClass("java.lang.annotation.Annotation"); |
|
487 |
classLoaderType = enterClass("java.lang.ClassLoader"); |
|
36526 | 488 |
enumSym = enterClass(java_base, names.java_lang_Enum); |
10 | 489 |
enumFinalFinalize = |
490 |
new MethodSymbol(PROTECTED|FINAL|HYPOTHETICAL, |
|
491 |
names.finalize, |
|
492 |
new MethodType(List.<Type>nil(), voidType, |
|
493 |
List.<Type>nil(), methodClass), |
|
494 |
enumSym); |
|
495 |
listType = enterClass("java.util.List"); |
|
496 |
collectionsType = enterClass("java.util.Collections"); |
|
497 |
comparableType = enterClass("java.lang.Comparable"); |
|
16333 | 498 |
comparatorType = enterClass("java.util.Comparator"); |
10 | 499 |
arraysType = enterClass("java.util.Arrays"); |
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
500 |
iterableType = enterClass("java.lang.Iterable"); |
10 | 501 |
iteratorType = enterClass("java.util.Iterator"); |
502 |
annotationTargetType = enterClass("java.lang.annotation.Target"); |
|
503 |
overrideType = enterClass("java.lang.Override"); |
|
504 |
retentionType = enterClass("java.lang.annotation.Retention"); |
|
505 |
deprecatedType = enterClass("java.lang.Deprecated"); |
|
506 |
suppressWarningsType = enterClass("java.lang.SuppressWarnings"); |
|
29294
376a915b4ff0
8073645: Add lambda-based lazy eval versions of Assert.check methods
mcimadamore
parents:
29051
diff
changeset
|
507 |
supplierType = enterClass("java.util.function.Supplier"); |
10 | 508 |
inheritedType = enterClass("java.lang.annotation.Inherited"); |
15356
cf312dc54c60
8006119: update javac to follow latest spec for repeatable annotations
jjg
parents:
14539
diff
changeset
|
509 |
repeatableType = enterClass("java.lang.annotation.Repeatable"); |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
12335
diff
changeset
|
510 |
documentedType = enterClass("java.lang.annotation.Documented"); |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
12335
diff
changeset
|
511 |
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
|
512 |
systemType = enterClass("java.lang.System"); |
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
513 |
autoCloseableType = enterClass("java.lang.AutoCloseable"); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
514 |
autoCloseableClose = new MethodSymbol(PUBLIC, |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
515 |
names.close, |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
516 |
new MethodType(List.<Type>nil(), voidType, |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
517 |
List.of(exceptionType), methodClass), |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
518 |
autoCloseableType.tsym); |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
6709
diff
changeset
|
519 |
trustMeType = enterClass("java.lang.SafeVarargs"); |
14539
507556c4e622
8003412: javac needs to understand java.lang.annotation.Native
jjg
parents:
14365
diff
changeset
|
520 |
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
|
521 |
lambdaMetafactory = enterClass("java.lang.invoke.LambdaMetafactory"); |
35424 | 522 |
stringConcatFactory = enterClass("java.lang.invoke.StringConcatFactory"); |
15361
01f1828683e6
8005299: Add FunctionalInterface checking to javac
mcimadamore
parents:
15356
diff
changeset
|
523 |
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
|
524 |
|
9076
45c73da050e9
7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents:
8621
diff
changeset
|
525 |
synthesizeEmptyInterfaceIfMissing(autoCloseableType); |
1037
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
526 |
synthesizeEmptyInterfaceIfMissing(cloneableType); |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
527 |
synthesizeEmptyInterfaceIfMissing(serializableType); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
528 |
synthesizeEmptyInterfaceIfMissing(lambdaMetafactory); |
16300 | 529 |
synthesizeEmptyInterfaceIfMissing(serializedLambdaType); |
35424 | 530 |
synthesizeEmptyInterfaceIfMissing(stringConcatFactory); |
1037
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
531 |
synthesizeBoxTypeIfMissing(doubleType); |
c6b315a34dc6
6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents:
10
diff
changeset
|
532 |
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
|
533 |
synthesizeBoxTypeIfMissing(voidType); |
10 | 534 |
|
5848
c5a4ce47e780
6960407: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5847
diff
changeset
|
535 |
// Enter a synthetic class that is used to mark internal |
10 | 536 |
// proprietary classes in ct.sym. This class does not have a |
537 |
// class file. |
|
15724 | 538 |
proprietaryType = enterSyntheticAnnotation("sun.Proprietary+Annotation"); |
539 |
||
540 |
// Enter a synthetic class that is used to provide profile info for |
|
541 |
// classes in ct.sym. This class does not have a class file. |
|
542 |
profileType = enterSyntheticAnnotation("jdk.Profile+Annotation"); |
|
543 |
MethodSymbol m = new MethodSymbol(PUBLIC | ABSTRACT, names.value, intType, profileType.tsym); |
|
544 |
profileType.tsym.members().enter(m); |
|
10 | 545 |
|
546 |
// Enter a class for arrays. |
|
547 |
// The class implements java.lang.Cloneable and java.io.Serializable. |
|
548 |
// It has a final length field and a clone method. |
|
549 |
ClassType arrayClassType = (ClassType)arrayClass.type; |
|
550 |
arrayClassType.supertype_field = objectType; |
|
551 |
arrayClassType.interfaces_field = List.of(cloneableType, serializableType); |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
24604
diff
changeset
|
552 |
arrayClass.members_field = WriteableScope.create(arrayClass); |
10 | 553 |
lengthVar = new VarSymbol( |
554 |
PUBLIC | FINAL, |
|
555 |
names.length, |
|
556 |
intType, |
|
557 |
arrayClass); |
|
558 |
arrayClass.members().enter(lengthVar); |
|
559 |
arrayCloneMethod = new MethodSymbol( |
|
560 |
PUBLIC, |
|
561 |
names.clone, |
|
562 |
new MethodType(List.<Type>nil(), objectType, |
|
563 |
List.<Type>nil(), methodClass), |
|
564 |
arrayClass); |
|
565 |
arrayClass.members().enter(arrayCloneMethod); |
|
36526 | 566 |
|
567 |
if (java_base != noModule) |
|
568 |
java_base.completer = sym -> moduleCompleter.complete(sym); //bootstrap issues |
|
569 |
||
10 | 570 |
} |
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
571 |
|
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
572 |
/** Define a new class given its name and owner. |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
573 |
*/ |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
574 |
public ClassSymbol defineClass(Name name, Symbol owner) { |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
575 |
ClassSymbol c = new ClassSymbol(0, name, owner); |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
576 |
c.completer = initialCompleter; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
577 |
return c; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
578 |
} |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
579 |
|
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
580 |
/** 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
|
581 |
* and owner and enter in `classes' unless already there. |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
582 |
*/ |
36526 | 583 |
public ClassSymbol enterClass(ModuleSymbol msym, Name name, TypeSymbol owner) { |
584 |
Assert.checkNonNull(msym); |
|
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
585 |
Name flatname = TypeSymbol.formFlatName(name, owner); |
36526 | 586 |
ClassSymbol c = getClass(msym, flatname); |
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
587 |
if (c == null) { |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
588 |
c = defineClass(name, owner); |
36526 | 589 |
doEnterClass(msym, c); |
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
590 |
} 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
|
591 |
// reassign fields of classes that might have been loaded with |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
592 |
// their flat names. |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
593 |
c.owner.members().remove(c); |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
594 |
c.name = name; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
595 |
c.owner = owner; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
596 |
c.fullname = ClassSymbol.formFullName(name, owner); |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
597 |
} |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
598 |
return c; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
599 |
} |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
600 |
|
36526 | 601 |
public ClassSymbol getClass(ModuleSymbol msym, Name flatName) { |
602 |
Assert.checkNonNull(msym, () -> flatName.toString()); |
|
603 |
return classes.getOrDefault(flatName, Collections.emptyMap()).get(msym); |
|
604 |
} |
|
605 |
||
606 |
public PackageSymbol lookupPackage(ModuleSymbol msym, Name flatName) { |
|
607 |
Assert.checkNonNull(msym); |
|
608 |
||
609 |
if (flatName.isEmpty()) { |
|
610 |
//unnamed packages only from the current module - visiblePackages contains *root* package, not unnamed package! |
|
611 |
return msym.unnamedPackage; |
|
612 |
} |
|
613 |
||
614 |
if (msym == noModule) { |
|
615 |
return enterPackage(msym, flatName); |
|
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
616 |
} |
36526 | 617 |
|
618 |
msym.complete(); |
|
619 |
||
620 |
PackageSymbol pack; |
|
621 |
||
622 |
pack = msym.visiblePackages.get(flatName); |
|
623 |
||
624 |
if (pack != null) |
|
625 |
return pack; |
|
626 |
||
627 |
pack = getPackage(msym, flatName); |
|
628 |
||
629 |
if (pack != null && pack.exists()) |
|
630 |
return pack; |
|
631 |
||
632 |
boolean dependsOnUnnamed = msym.requires != null && |
|
633 |
msym.requires.stream() |
|
634 |
.map(rd -> rd.module) |
|
635 |
.anyMatch(mod -> mod == unnamedModule); |
|
636 |
||
637 |
if (dependsOnUnnamed) { |
|
638 |
//msyms depends on the unnamed module, for which we generally don't know |
|
639 |
//the list of packages it "exports" ahead of time. So try to lookup the package in the |
|
640 |
//current module, and in the unnamed module and see if it exists in one of them |
|
641 |
PackageSymbol unnamedPack = getPackage(unnamedModule, flatName); |
|
642 |
||
643 |
if (unnamedPack != null && unnamedPack.exists()) { |
|
644 |
msym.visiblePackages.put(unnamedPack.fullname, unnamedPack); |
|
645 |
return unnamedPack; |
|
646 |
} |
|
647 |
||
648 |
pack = enterPackage(msym, flatName); |
|
649 |
pack.complete(); |
|
650 |
if (pack.exists()) |
|
651 |
return pack; |
|
652 |
||
653 |
unnamedPack = enterPackage(unnamedModule, flatName); |
|
654 |
unnamedPack.complete(); |
|
655 |
if (unnamedPack.exists()) { |
|
656 |
msym.visiblePackages.put(unnamedPack.fullname, unnamedPack); |
|
657 |
return unnamedPack; |
|
658 |
} |
|
659 |
||
660 |
return pack; |
|
661 |
} |
|
662 |
||
663 |
return enterPackage(msym, flatName); |
|
664 |
} |
|
665 |
||
666 |
private static final Map<ModuleSymbol, ClassSymbol> EMPTY = new HashMap<>(); |
|
667 |
||
668 |
public void removeClass(ModuleSymbol msym, Name flatName) { |
|
669 |
classes.getOrDefault(flatName, EMPTY).remove(msym); |
|
670 |
} |
|
671 |
||
672 |
public Iterable<ClassSymbol> getAllClasses() { |
|
673 |
return () -> Iterators.createCompoundIterator(classes.values(), v -> v.values().iterator()); |
|
674 |
} |
|
675 |
||
676 |
private void doEnterClass(ModuleSymbol msym, ClassSymbol cs) { |
|
677 |
classes.computeIfAbsent(cs.flatname, n -> new HashMap<>()).put(msym, cs); |
|
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
678 |
} |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
679 |
|
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
680 |
/** 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
|
681 |
* and enter in `classes' unless already there. |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
682 |
*/ |
36526 | 683 |
public ClassSymbol enterClass(ModuleSymbol msym, Name flatname) { |
684 |
Assert.checkNonNull(msym); |
|
685 |
PackageSymbol ps = lookupPackage(msym, Convert.packagePart(flatname)); |
|
686 |
Assert.checkNonNull(ps); |
|
687 |
Assert.checkNonNull(ps.modle); |
|
688 |
ClassSymbol c = getClass(ps.modle, flatname); |
|
689 |
if (c == null) { |
|
690 |
c = defineClass(Convert.shortName(flatname), ps); |
|
691 |
doEnterClass(ps.modle, c); |
|
692 |
return c; |
|
693 |
} else |
|
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
694 |
return c; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
695 |
} |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
696 |
|
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
697 |
/** 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
|
698 |
*/ |
36526 | 699 |
public boolean packageExists(ModuleSymbol msym, Name fullname) { |
700 |
Assert.checkNonNull(msym); |
|
701 |
return enterPackage(msym, fullname).exists(); |
|
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
702 |
} |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
703 |
|
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
704 |
/** Make a package, given its fully qualified name. |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
705 |
*/ |
36526 | 706 |
public PackageSymbol enterPackage(ModuleSymbol currModule, Name fullname) { |
707 |
Assert.checkNonNull(currModule); |
|
708 |
PackageSymbol p = getPackage(currModule, fullname); |
|
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
709 |
if (p == null) { |
36526 | 710 |
Assert.check(!fullname.isEmpty(), () -> "rootPackage missing!; currModule: " + currModule); |
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
711 |
p = new PackageSymbol( |
36526 | 712 |
Convert.shortName(fullname), |
713 |
enterPackage(currModule, Convert.packagePart(fullname))); |
|
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
714 |
p.completer = initialCompleter; |
36526 | 715 |
p.modle = currModule; |
716 |
doEnterPackage(currModule, p); |
|
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
717 |
} |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
718 |
return p; |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
719 |
} |
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
720 |
|
36526 | 721 |
private void doEnterPackage(ModuleSymbol msym, PackageSymbol pack) { |
722 |
packages.computeIfAbsent(pack.fullname, n -> new HashMap<>()).put(msym, pack); |
|
723 |
msym.enclosedPackages = msym.enclosedPackages.prepend(pack); |
|
724 |
} |
|
725 |
||
726 |
private void addRootPackageFor(ModuleSymbol module) { |
|
727 |
doEnterPackage(module, rootPackage); |
|
728 |
PackageSymbol unnamedPackage = new PackageSymbol(names.empty, rootPackage) { |
|
729 |
@Override |
|
730 |
public String toString() { |
|
731 |
return messages.getLocalizedString("compiler.misc.unnamed.package"); |
|
732 |
} |
|
733 |
}; |
|
734 |
unnamedPackage.modle = module; |
|
735 |
unnamedPackage.completer = sym -> initialCompleter.complete(sym); |
|
736 |
module.unnamedPackage = unnamedPackage; |
|
737 |
} |
|
738 |
||
739 |
public PackageSymbol getPackage(ModuleSymbol module, Name fullname) { |
|
740 |
return packages.getOrDefault(fullname, Collections.emptyMap()).get(module); |
|
741 |
} |
|
742 |
||
743 |
public ModuleSymbol enterModule(Name name) { |
|
744 |
ModuleSymbol msym = modules.get(name); |
|
745 |
if (msym == null) { |
|
746 |
msym = ModuleSymbol.create(name, names.module_info); |
|
747 |
addRootPackageFor(msym); |
|
748 |
msym.completer = sym -> moduleCompleter.complete(sym); //bootstrap issues |
|
749 |
modules.put(name, msym); |
|
750 |
} |
|
751 |
return msym; |
|
752 |
} |
|
753 |
||
754 |
public void enterModule(ModuleSymbol msym, Name name) { |
|
755 |
Assert.checkNull(modules.get(name)); |
|
756 |
Assert.checkNull(msym.name); |
|
757 |
msym.name = name; |
|
758 |
addRootPackageFor(msym); |
|
759 |
ClassSymbol info = msym.module_info; |
|
760 |
info.fullname = msym.name.append('.', names.module_info); |
|
761 |
info.flatname = info.fullname; |
|
762 |
modules.put(name, msym); |
|
763 |
} |
|
764 |
||
765 |
public ModuleSymbol getModule(Name name) { |
|
766 |
return modules.get(name); |
|
767 |
} |
|
768 |
||
769 |
//temporary: |
|
770 |
public ModuleSymbol inferModule(Name packageName) { |
|
771 |
if (packageName.isEmpty()) |
|
772 |
return java_base == noModule ? noModule : unnamedModule;//! |
|
773 |
||
774 |
ModuleSymbol msym = null; |
|
775 |
Map<ModuleSymbol,PackageSymbol> map = packages.get(packageName); |
|
776 |
if (map == null) |
|
777 |
return null; |
|
778 |
for (Map.Entry<ModuleSymbol,PackageSymbol> e: map.entrySet()) { |
|
779 |
if (!e.getValue().members().isEmpty()) { |
|
780 |
if (msym == null) { |
|
781 |
msym = e.getKey(); |
|
782 |
} else { |
|
783 |
return null; |
|
784 |
} |
|
785 |
} |
|
786 |
} |
|
787 |
return msym; |
|
788 |
} |
|
789 |
||
790 |
public List<ModuleSymbol> listPackageModules(Name packageName) { |
|
791 |
if (packageName.isEmpty()) |
|
792 |
return List.nil(); |
|
793 |
||
794 |
List<ModuleSymbol> result = List.nil(); |
|
795 |
Map<ModuleSymbol,PackageSymbol> map = packages.get(packageName); |
|
796 |
if (map != null) { |
|
797 |
for (Map.Entry<ModuleSymbol, PackageSymbol> e: map.entrySet()) { |
|
798 |
if (!e.getValue().members().isEmpty()) { |
|
799 |
result = result.prepend(e.getKey()); |
|
800 |
} |
|
801 |
} |
|
802 |
} |
|
803 |
return result; |
|
804 |
} |
|
805 |
||
806 |
public Collection<ModuleSymbol> getAllModules() { |
|
807 |
return modules.values(); |
|
22442
8fd30fc4e3a3
8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents:
22163
diff
changeset
|
808 |
} |
10 | 809 |
} |