author | mcimadamore |
Fri, 09 Jan 2015 15:51:20 +0000 | |
changeset 28339 | fa0685d84b74 |
parent 28337 | 0b46fb7be75a |
child 28800 | 35f9042d53b3 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
23127
5aba53c2b9b2
8034048: javac crash with method references plus lambda plus var args
jjg
parents:
22168
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.comp; |
|
27 |
||
28 |
import java.util.*; |
|
29 |
||
30 |
import com.sun.tools.javac.code.*; |
|
31 |
import com.sun.tools.javac.code.Symbol.*; |
|
32 |
import com.sun.tools.javac.tree.*; |
|
33 |
import com.sun.tools.javac.tree.JCTree.*; |
|
34 |
import com.sun.tools.javac.util.*; |
|
35 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
|
36 |
import com.sun.tools.javac.util.List; |
|
37 |
||
38 |
import static com.sun.tools.javac.code.Flags.*; |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
27124
diff
changeset
|
39 |
import static com.sun.tools.javac.code.Kinds.Kind.*; |
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25306
diff
changeset
|
40 |
import static com.sun.tools.javac.code.Scope.LookupKind.NON_RECURSIVE; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
41 |
import static com.sun.tools.javac.code.TypeTag.CLASS; |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
42 |
import static com.sun.tools.javac.code.TypeTag.TYPEVAR; |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
43 |
import static com.sun.tools.javac.code.TypeTag.VOID; |
16968 | 44 |
import static com.sun.tools.javac.comp.CompileStates.CompileState; |
10 | 45 |
|
46 |
/** This pass translates Generic Java to conventional Java. |
|
47 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
48 |
* <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
|
49 |
* If you write code that depends on this, you do so at your own risk. |
10 | 50 |
* This code and its internal interfaces are subject to change or |
51 |
* deletion without notice.</b> |
|
52 |
*/ |
|
53 |
public class TransTypes extends TreeTranslator { |
|
54 |
/** The context key for the TransTypes phase. */ |
|
22163 | 55 |
protected static final Context.Key<TransTypes> transTypesKey = new Context.Key<>(); |
10 | 56 |
|
57 |
/** Get the instance for this context. */ |
|
58 |
public static TransTypes instance(Context context) { |
|
59 |
TransTypes instance = context.get(transTypesKey); |
|
60 |
if (instance == null) |
|
61 |
instance = new TransTypes(context); |
|
62 |
return instance; |
|
63 |
} |
|
64 |
||
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
735
diff
changeset
|
65 |
private Names names; |
10 | 66 |
private Log log; |
67 |
private Symtab syms; |
|
68 |
private TreeMaker make; |
|
69 |
private Enter enter; |
|
70 |
private Types types; |
|
71 |
private final Resolve resolve; |
|
27124
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
72 |
private final CompileStates compileStates; |
10 | 73 |
|
27124
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
74 |
/** Switch: is complex graph inference supported? */ |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
75 |
private final boolean allowGraphInference; |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
76 |
|
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
77 |
/** Switch: are default methods supported? */ |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
78 |
private final boolean allowInterfaceBridges; |
16968 | 79 |
|
10 | 80 |
protected TransTypes(Context context) { |
81 |
context.put(transTypesKey, this); |
|
16968 | 82 |
compileStates = CompileStates.instance(context); |
1260
a772ba9ba43d
6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents:
735
diff
changeset
|
83 |
names = Names.instance(context); |
10 | 84 |
log = Log.instance(context); |
85 |
syms = Symtab.instance(context); |
|
86 |
enter = Enter.instance(context); |
|
22163 | 87 |
overridden = new HashMap<>(); |
10 | 88 |
types = Types.instance(context); |
89 |
make = TreeMaker.instance(context); |
|
90 |
resolve = Resolve.instance(context); |
|
27124
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
91 |
Source source = Source.instance(context); |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
92 |
allowInterfaceBridges = source.allowDefaultMethods(); |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
93 |
allowGraphInference = source.allowGraphInference(); |
10 | 94 |
} |
95 |
||
96 |
/** A hashtable mapping bridge methods to the methods they override after |
|
97 |
* type erasure. |
|
98 |
*/ |
|
99 |
Map<MethodSymbol,MethodSymbol> overridden; |
|
100 |
||
101 |
/** Construct an attributed tree for a cast of expression to target type, |
|
102 |
* unless it already has precisely that type. |
|
103 |
* @param tree The expression tree. |
|
104 |
* @param target The target type. |
|
105 |
*/ |
|
106 |
JCExpression cast(JCExpression tree, Type target) { |
|
107 |
int oldpos = make.pos; |
|
108 |
make.at(tree.pos); |
|
109 |
if (!types.isSameType(tree.type, target)) { |
|
110 |
if (!resolve.isAccessible(env, target.tsym)) |
|
12082
32bdf6ef6388
7151070: NullPointerException in Resolve.isAccessible
mcimadamore
parents:
8032
diff
changeset
|
111 |
resolve.logAccessErrorInternal(env, tree, target); |
10 | 112 |
tree = make.TypeCast(make.Type(target), tree).setType(target); |
113 |
} |
|
114 |
make.pos = oldpos; |
|
115 |
return tree; |
|
116 |
} |
|
117 |
||
118 |
/** Construct an attributed tree to coerce an expression to some erased |
|
119 |
* target type, unless the expression is already assignable to that type. |
|
120 |
* If target type is a constant type, use its base type instead. |
|
121 |
* @param tree The expression tree. |
|
122 |
* @param target The target type. |
|
123 |
*/ |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
124 |
public JCExpression coerce(Env<AttrContext> env, JCExpression tree, Type target) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
125 |
Env<AttrContext> prevEnv = this.env; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
126 |
try { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
127 |
this.env = env; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
128 |
return coerce(tree, target); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
129 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
130 |
finally { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
131 |
this.env = prevEnv; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
132 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
133 |
} |
10 | 134 |
JCExpression coerce(JCExpression tree, Type target) { |
135 |
Type btarget = target.baseType(); |
|
136 |
if (tree.type.isPrimitive() == target.isPrimitive()) { |
|
14547 | 137 |
return types.isAssignable(tree.type, btarget, types.noWarnings) |
10 | 138 |
? tree |
139 |
: cast(tree, btarget); |
|
140 |
} |
|
141 |
return tree; |
|
142 |
} |
|
143 |
||
144 |
/** Given an erased reference type, assume this type as the tree's type. |
|
145 |
* Then, coerce to some given target type unless target type is null. |
|
146 |
* This operation is used in situations like the following: |
|
147 |
* |
|
14259 | 148 |
* <pre>{@code |
10 | 149 |
* class Cell<A> { A value; } |
150 |
* ... |
|
151 |
* Cell<Integer> cell; |
|
152 |
* Integer x = cell.value; |
|
14259 | 153 |
* }</pre> |
10 | 154 |
* |
155 |
* Since the erasure of Cell.value is Object, but the type |
|
156 |
* of cell.value in the assignment is Integer, we need to |
|
157 |
* adjust the original type of cell.value to Object, and insert |
|
158 |
* a cast to Integer. That is, the last assignment becomes: |
|
159 |
* |
|
14259 | 160 |
* <pre>{@code |
10 | 161 |
* Integer x = (Integer)cell.value; |
14259 | 162 |
* }</pre> |
10 | 163 |
* |
164 |
* @param tree The expression tree whose type might need adjustment. |
|
165 |
* @param erasedType The expression's type after erasure. |
|
166 |
* @param target The target type, which is usually the erasure of the |
|
167 |
* expression's original type. |
|
168 |
*/ |
|
169 |
JCExpression retype(JCExpression tree, Type erasedType, Type target) { |
|
170 |
// System.err.println("retype " + tree + " to " + erasedType);//DEBUG |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
171 |
if (!erasedType.isPrimitive()) { |
17810
db9f3e9cd760
7053059: VerifyError with double Assignment using a Generic Member of a Superclass
vromero
parents:
16974
diff
changeset
|
172 |
if (target != null && target.isPrimitive()) { |
10 | 173 |
target = erasure(tree.type); |
17810
db9f3e9cd760
7053059: VerifyError with double Assignment using a Generic Member of a Superclass
vromero
parents:
16974
diff
changeset
|
174 |
} |
10 | 175 |
tree.type = erasedType; |
17810
db9f3e9cd760
7053059: VerifyError with double Assignment using a Generic Member of a Superclass
vromero
parents:
16974
diff
changeset
|
176 |
if (target != null) { |
db9f3e9cd760
7053059: VerifyError with double Assignment using a Generic Member of a Superclass
vromero
parents:
16974
diff
changeset
|
177 |
return coerce(tree, target); |
db9f3e9cd760
7053059: VerifyError with double Assignment using a Generic Member of a Superclass
vromero
parents:
16974
diff
changeset
|
178 |
} |
10 | 179 |
} |
180 |
return tree; |
|
181 |
} |
|
182 |
||
183 |
/** Translate method argument list, casting each argument |
|
184 |
* to its corresponding type in a list of target types. |
|
185 |
* @param _args The method argument list. |
|
186 |
* @param parameters The list of target types. |
|
187 |
* @param varargsElement The erasure of the varargs element type, |
|
188 |
* or null if translating a non-varargs invocation |
|
189 |
*/ |
|
190 |
<T extends JCTree> List<T> translateArgs(List<T> _args, |
|
191 |
List<Type> parameters, |
|
192 |
Type varargsElement) { |
|
193 |
if (parameters.isEmpty()) return _args; |
|
194 |
List<T> args = _args; |
|
195 |
while (parameters.tail.nonEmpty()) { |
|
196 |
args.head = translate(args.head, parameters.head); |
|
197 |
args = args.tail; |
|
198 |
parameters = parameters.tail; |
|
199 |
} |
|
200 |
Type parameter = parameters.head; |
|
8032 | 201 |
Assert.check(varargsElement != null || args.length() == 1); |
10 | 202 |
if (varargsElement != null) { |
203 |
while (args.nonEmpty()) { |
|
204 |
args.head = translate(args.head, varargsElement); |
|
205 |
args = args.tail; |
|
206 |
} |
|
207 |
} else { |
|
208 |
args.head = translate(args.head, parameter); |
|
209 |
} |
|
210 |
return _args; |
|
211 |
} |
|
212 |
||
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
213 |
public <T extends JCTree> List<T> translateArgs(List<T> _args, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
214 |
List<Type> parameters, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
215 |
Type varargsElement, |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
216 |
Env<AttrContext> localEnv) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
217 |
Env<AttrContext> prevEnv = env; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
218 |
try { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
219 |
env = localEnv; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
220 |
return translateArgs(_args, parameters, varargsElement); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
221 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
222 |
finally { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
223 |
env = prevEnv; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
224 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
225 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
226 |
|
10 | 227 |
/** Add a bridge definition and enter corresponding method symbol in |
228 |
* local scope of origin. |
|
229 |
* |
|
230 |
* @param pos The source code position to be used for the definition. |
|
231 |
* @param meth The method for which a bridge needs to be added |
|
232 |
* @param impl That method's implementation (possibly the method itself) |
|
233 |
* @param origin The class to which the bridge will be added |
|
234 |
* @param hypothetical |
|
235 |
* True if the bridge method is not strictly necessary in the |
|
236 |
* binary, but is represented in the symbol table to detect |
|
237 |
* erasure clashes. |
|
238 |
* @param bridges The list buffer to which the bridge will be added |
|
239 |
*/ |
|
240 |
void addBridge(DiagnosticPosition pos, |
|
241 |
MethodSymbol meth, |
|
242 |
MethodSymbol impl, |
|
243 |
ClassSymbol origin, |
|
244 |
boolean hypothetical, |
|
245 |
ListBuffer<JCTree> bridges) { |
|
246 |
make.at(pos); |
|
247 |
Type origType = types.memberType(origin.type, meth); |
|
248 |
Type origErasure = erasure(origType); |
|
249 |
||
250 |
// Create a bridge method symbol and a bridge definition without a body. |
|
251 |
Type bridgeType = meth.erasure(types); |
|
24793
bb58a9f1ae10
8044487: Fix for 8042785 causes regression tests to fail with java.lang.VerifyError
vromero
parents:
24792
diff
changeset
|
252 |
long flags = impl.flags() & AccessFlags | SYNTHETIC | BRIDGE | |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
253 |
(origin.isInterface() ? DEFAULT : 0); |
10 | 254 |
if (hypothetical) flags |= HYPOTHETICAL; |
255 |
MethodSymbol bridge = new MethodSymbol(flags, |
|
256 |
meth.name, |
|
257 |
bridgeType, |
|
258 |
origin); |
|
18000
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
259 |
/* once JDK-6996415 is solved it should be checked if this approach can |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
260 |
* be applied to method addOverrideBridgesIfNeeded |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
261 |
*/ |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
262 |
bridge.params = createBridgeParams(impl, bridge, bridgeType); |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
18000
diff
changeset
|
263 |
bridge.setAttributes(impl); |
18000
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
264 |
|
10 | 265 |
if (!hypothetical) { |
266 |
JCMethodDecl md = make.MethodDef(bridge, null); |
|
267 |
||
268 |
// The bridge calls this.impl(..), if we have an implementation |
|
269 |
// in the current class, super.impl(...) otherwise. |
|
270 |
JCExpression receiver = (impl.owner == origin) |
|
271 |
? make.This(origin.erasure(types)) |
|
272 |
: make.Super(types.supertype(origin.type).tsym.erasure(types), origin); |
|
273 |
||
274 |
// The type returned from the original method. |
|
275 |
Type calltype = erasure(impl.type.getReturnType()); |
|
276 |
||
277 |
// Construct a call of this.impl(params), or super.impl(params), |
|
278 |
// casting params and possibly results as needed. |
|
279 |
JCExpression call = |
|
280 |
make.Apply( |
|
281 |
null, |
|
282 |
make.Select(receiver, impl).setType(calltype), |
|
283 |
translateArgs(make.Idents(md.params), origErasure.getParameterTypes(), null)) |
|
284 |
.setType(calltype); |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
285 |
JCStatement stat = (origErasure.getReturnType().hasTag(VOID)) |
10 | 286 |
? make.Exec(call) |
287 |
: make.Return(coerce(call, bridgeType.getReturnType())); |
|
288 |
md.body = make.Block(0, List.of(stat)); |
|
289 |
||
290 |
// Add bridge to `bridges' buffer |
|
291 |
bridges.append(md); |
|
292 |
} |
|
293 |
||
294 |
// Add bridge to scope of enclosing class and `overridden' table. |
|
295 |
origin.members().enter(bridge); |
|
296 |
overridden.put(bridge, meth); |
|
297 |
} |
|
298 |
||
18000
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
299 |
private List<VarSymbol> createBridgeParams(MethodSymbol impl, MethodSymbol bridge, |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
300 |
Type bridgeType) { |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
301 |
List<VarSymbol> bridgeParams = null; |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
302 |
if (impl.params != null) { |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
303 |
bridgeParams = List.nil(); |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
304 |
List<VarSymbol> implParams = impl.params; |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
305 |
Type.MethodType mType = (Type.MethodType)bridgeType; |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
306 |
List<Type> argTypes = mType.argtypes; |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
307 |
while (implParams.nonEmpty() && argTypes.nonEmpty()) { |
19941
8b91e8eb2d20
7047734: javac, the LVT is not generated correctly in several scenarios
vromero
parents:
19939
diff
changeset
|
308 |
VarSymbol param = new VarSymbol(implParams.head.flags() | SYNTHETIC | PARAMETER, |
18000
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
309 |
implParams.head.name, argTypes.head, bridge); |
18010
604faee85350
8004643: Reduce javac space overhead introduced with compiler support for repeating annotations
jjg
parents:
18000
diff
changeset
|
310 |
param.setAttributes(implParams.head); |
18000
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
311 |
bridgeParams = bridgeParams.append(param); |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
312 |
implParams = implParams.tail; |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
313 |
argTypes = argTypes.tail; |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
314 |
} |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
315 |
} |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
316 |
return bridgeParams; |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
317 |
} |
5d29ce00a7a2
6695379: Copy method annotations and parameter annotations to synthetic bridge methods
vromero
parents:
17810
diff
changeset
|
318 |
|
10 | 319 |
/** Add bridge if given symbol is a non-private, non-static member |
320 |
* of the given class, which is either defined in the class or non-final |
|
321 |
* inherited, and one of the two following conditions holds: |
|
322 |
* 1. The method's type changes in the given class, as compared to the |
|
323 |
* class where the symbol was defined, (in this case |
|
324 |
* we have extended a parameterized class with non-trivial parameters). |
|
325 |
* 2. The method has an implementation with a different erased return type. |
|
326 |
* (in this case we have used co-variant returns). |
|
327 |
* If a bridge already exists in some other class, no new bridge is added. |
|
328 |
* Instead, it is checked that the bridge symbol overrides the method symbol. |
|
329 |
* (Spec ???). |
|
330 |
* todo: what about bridges for privates??? |
|
331 |
* |
|
332 |
* @param pos The source code position to be used for the definition. |
|
333 |
* @param sym The symbol for which a bridge might have to be added. |
|
334 |
* @param origin The class in which the bridge would go. |
|
335 |
* @param bridges The list buffer to which the bridge would be added. |
|
336 |
*/ |
|
337 |
void addBridgeIfNeeded(DiagnosticPosition pos, |
|
338 |
Symbol sym, |
|
339 |
ClassSymbol origin, |
|
340 |
ListBuffer<JCTree> bridges) { |
|
341 |
if (sym.kind == MTH && |
|
342 |
sym.name != names.init && |
|
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6148
diff
changeset
|
343 |
(sym.flags() & (PRIVATE | STATIC)) == 0 && |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6148
diff
changeset
|
344 |
(sym.flags() & (SYNTHETIC | OVERRIDE_BRIDGE)) != SYNTHETIC && |
10 | 345 |
sym.isMemberOf(origin, types)) |
346 |
{ |
|
347 |
MethodSymbol meth = (MethodSymbol)sym; |
|
348 |
MethodSymbol bridge = meth.binaryImplementation(origin, types); |
|
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6148
diff
changeset
|
349 |
MethodSymbol impl = meth.implementation(origin, types, true, overrideBridgeFilter); |
10 | 350 |
if (bridge == null || |
351 |
bridge == meth || |
|
352 |
(impl != null && !bridge.owner.isSubClass(impl.owner, types))) { |
|
353 |
// No bridge was added yet. |
|
354 |
if (impl != null && isBridgeNeeded(meth, impl, origin.type)) { |
|
355 |
addBridge(pos, meth, impl, origin, bridge==impl, bridges); |
|
356 |
} else if (impl == meth |
|
357 |
&& impl.owner != origin |
|
358 |
&& (impl.flags() & FINAL) == 0 |
|
359 |
&& (meth.flags() & (ABSTRACT|PUBLIC)) == PUBLIC |
|
360 |
&& (origin.flags() & PUBLIC) > (impl.owner.flags() & PUBLIC)) { |
|
361 |
// this is to work around a horrible but permanent |
|
362 |
// reflection design error. |
|
363 |
addBridge(pos, meth, impl, origin, false, bridges); |
|
364 |
} |
|
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6148
diff
changeset
|
365 |
} else if ((bridge.flags() & (SYNTHETIC | OVERRIDE_BRIDGE)) == SYNTHETIC) { |
10 | 366 |
MethodSymbol other = overridden.get(bridge); |
367 |
if (other != null && other != meth) { |
|
368 |
if (impl == null || !impl.overrides(other, origin, types, true)) { |
|
369 |
// Bridge for other symbol pair was added |
|
370 |
log.error(pos, "name.clash.same.erasure.no.override", |
|
371 |
other, other.location(origin.type, types), |
|
372 |
meth, meth.location(origin.type, types)); |
|
373 |
} |
|
374 |
} |
|
375 |
} else if (!bridge.overrides(meth, origin, types, true)) { |
|
376 |
// Accidental binary override without source override. |
|
377 |
if (bridge.owner == origin || |
|
378 |
types.asSuper(bridge.owner.type, meth.owner) == null) |
|
379 |
// Don't diagnose the problem if it would already |
|
380 |
// have been reported in the superclass |
|
381 |
log.error(pos, "name.clash.same.erasure.no.override", |
|
382 |
bridge, bridge.location(origin.type, types), |
|
383 |
meth, meth.location(origin.type, types)); |
|
384 |
} |
|
385 |
} |
|
386 |
} |
|
387 |
// where |
|
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
388 |
private Filter<Symbol> overrideBridgeFilter = new Filter<Symbol>() { |
6591
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6148
diff
changeset
|
389 |
public boolean accepts(Symbol s) { |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6148
diff
changeset
|
390 |
return (s.flags() & (SYNTHETIC | OVERRIDE_BRIDGE)) != SYNTHETIC; |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6148
diff
changeset
|
391 |
} |
a953c8c6b85e
6337171: javac should create bridge methods when type variable bounds restricted
mcimadamore
parents:
6148
diff
changeset
|
392 |
}; |
18730
95354d510139
8016281: The SAM method should be passed to the metafactory as a MethodType not a MethodHandle
mcimadamore
parents:
18412
diff
changeset
|
393 |
|
10 | 394 |
/** |
395 |
* @param method The symbol for which a bridge might have to be added |
|
396 |
* @param impl The implementation of method |
|
397 |
* @param dest The type in which the bridge would go |
|
398 |
*/ |
|
399 |
private boolean isBridgeNeeded(MethodSymbol method, |
|
400 |
MethodSymbol impl, |
|
401 |
Type dest) { |
|
402 |
if (impl != method) { |
|
403 |
// If either method or impl have different erasures as |
|
404 |
// members of dest, a bridge is needed. |
|
405 |
Type method_erasure = method.erasure(types); |
|
406 |
if (!isSameMemberWhenErased(dest, method, method_erasure)) |
|
407 |
return true; |
|
408 |
Type impl_erasure = impl.erasure(types); |
|
409 |
if (!isSameMemberWhenErased(dest, impl, impl_erasure)) |
|
410 |
return true; |
|
411 |
||
412 |
// If the erasure of the return type is different, a |
|
413 |
// bridge is needed. |
|
414 |
return !types.isSameType(impl_erasure.getReturnType(), |
|
415 |
method_erasure.getReturnType()); |
|
416 |
} else { |
|
417 |
// method and impl are the same... |
|
418 |
if ((method.flags() & ABSTRACT) != 0) { |
|
419 |
// ...and abstract so a bridge is not needed. |
|
420 |
// Concrete subclasses will bridge as needed. |
|
421 |
return false; |
|
422 |
} |
|
423 |
||
424 |
// The erasure of the return type is always the same |
|
425 |
// for the same symbol. Reducing the three tests in |
|
426 |
// the other branch to just one: |
|
427 |
return !isSameMemberWhenErased(dest, method, method.erasure(types)); |
|
428 |
} |
|
429 |
} |
|
430 |
/** |
|
431 |
* Lookup the method as a member of the type. Compare the |
|
432 |
* erasures. |
|
433 |
* @param type the class where to look for the method |
|
434 |
* @param method the method to look for in class |
|
435 |
* @param erasure the erasure of method |
|
436 |
*/ |
|
437 |
private boolean isSameMemberWhenErased(Type type, |
|
438 |
MethodSymbol method, |
|
439 |
Type erasure) { |
|
440 |
return types.isSameType(erasure(types.memberType(type, method)), |
|
441 |
erasure); |
|
442 |
} |
|
443 |
||
444 |
void addBridges(DiagnosticPosition pos, |
|
445 |
TypeSymbol i, |
|
446 |
ClassSymbol origin, |
|
447 |
ListBuffer<JCTree> bridges) { |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25306
diff
changeset
|
448 |
for (Symbol sym : i.members().getSymbols(NON_RECURSIVE)) |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25306
diff
changeset
|
449 |
addBridgeIfNeeded(pos, sym, origin, bridges); |
10 | 450 |
for (List<Type> l = types.interfaces(i.type); l.nonEmpty(); l = l.tail) |
451 |
addBridges(pos, l.head.tsym, origin, bridges); |
|
452 |
} |
|
453 |
||
454 |
/** Add all necessary bridges to some class appending them to list buffer. |
|
455 |
* @param pos The source code position to be used for the bridges. |
|
456 |
* @param origin The class in which the bridges go. |
|
457 |
* @param bridges The list buffer to which the bridges are added. |
|
458 |
*/ |
|
459 |
void addBridges(DiagnosticPosition pos, ClassSymbol origin, ListBuffer<JCTree> bridges) { |
|
460 |
Type st = types.supertype(origin.type); |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
461 |
while (st.hasTag(CLASS)) { |
10 | 462 |
// if (isSpecialization(st)) |
463 |
addBridges(pos, st.tsym, origin, bridges); |
|
464 |
st = types.supertype(st); |
|
465 |
} |
|
466 |
for (List<Type> l = types.interfaces(origin.type); l.nonEmpty(); l = l.tail) |
|
467 |
// if (isSpecialization(l.head)) |
|
468 |
addBridges(pos, l.head.tsym, origin, bridges); |
|
469 |
} |
|
470 |
||
471 |
/* ************************************************************************ |
|
472 |
* Visitor methods |
|
473 |
*************************************************************************/ |
|
474 |
||
475 |
/** Visitor argument: proto-type. |
|
476 |
*/ |
|
477 |
private Type pt; |
|
478 |
||
479 |
/** Visitor method: perform a type translation on tree. |
|
480 |
*/ |
|
481 |
public <T extends JCTree> T translate(T tree, Type pt) { |
|
482 |
Type prevPt = this.pt; |
|
483 |
try { |
|
484 |
this.pt = pt; |
|
485 |
return translate(tree); |
|
486 |
} finally { |
|
487 |
this.pt = prevPt; |
|
488 |
} |
|
489 |
} |
|
490 |
||
491 |
/** Visitor method: perform a type translation on list of trees. |
|
492 |
*/ |
|
493 |
public <T extends JCTree> List<T> translate(List<T> trees, Type pt) { |
|
494 |
Type prevPt = this.pt; |
|
495 |
List<T> res; |
|
496 |
try { |
|
497 |
this.pt = pt; |
|
498 |
res = translate(trees); |
|
499 |
} finally { |
|
500 |
this.pt = prevPt; |
|
501 |
} |
|
502 |
return res; |
|
503 |
} |
|
504 |
||
505 |
public void visitClassDef(JCClassDecl tree) { |
|
506 |
translateClass(tree.sym); |
|
507 |
result = tree; |
|
508 |
} |
|
509 |
||
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
510 |
JCTree currentMethod = null; |
10 | 511 |
public void visitMethodDef(JCMethodDecl tree) { |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
512 |
JCTree previousMethod = currentMethod; |
10 | 513 |
try { |
514 |
currentMethod = tree; |
|
515 |
tree.restype = translate(tree.restype, null); |
|
516 |
tree.typarams = List.nil(); |
|
517 |
tree.params = translateVarDefs(tree.params); |
|
15385 | 518 |
tree.recvparam = translate(tree.recvparam, null); |
10 | 519 |
tree.thrown = translate(tree.thrown, null); |
520 |
tree.body = translate(tree.body, tree.sym.erasure(types).getReturnType()); |
|
521 |
tree.type = erasure(tree.type); |
|
522 |
result = tree; |
|
523 |
} finally { |
|
524 |
currentMethod = previousMethod; |
|
525 |
} |
|
526 |
||
527 |
// Check that we do not introduce a name clash by erasing types. |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25306
diff
changeset
|
528 |
for (Symbol sym : tree.sym.owner.members().getSymbolsByName(tree.name)) { |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25306
diff
changeset
|
529 |
if (sym != tree.sym && |
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25306
diff
changeset
|
530 |
types.isSameType(erasure(sym.type), tree.type)) { |
10 | 531 |
log.error(tree.pos(), |
532 |
"name.clash.same.erasure", tree.sym, |
|
25443
9187d77f2c64
8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents:
25306
diff
changeset
|
533 |
sym); |
10 | 534 |
return; |
535 |
} |
|
536 |
} |
|
537 |
} |
|
538 |
||
539 |
public void visitVarDef(JCVariableDecl tree) { |
|
540 |
tree.vartype = translate(tree.vartype, null); |
|
541 |
tree.init = translate(tree.init, tree.sym.erasure(types)); |
|
542 |
tree.type = erasure(tree.type); |
|
543 |
result = tree; |
|
544 |
} |
|
545 |
||
546 |
public void visitDoLoop(JCDoWhileLoop tree) { |
|
547 |
tree.body = translate(tree.body); |
|
548 |
tree.cond = translate(tree.cond, syms.booleanType); |
|
549 |
result = tree; |
|
550 |
} |
|
551 |
||
552 |
public void visitWhileLoop(JCWhileLoop tree) { |
|
553 |
tree.cond = translate(tree.cond, syms.booleanType); |
|
554 |
tree.body = translate(tree.body); |
|
555 |
result = tree; |
|
556 |
} |
|
557 |
||
558 |
public void visitForLoop(JCForLoop tree) { |
|
559 |
tree.init = translate(tree.init, null); |
|
560 |
if (tree.cond != null) |
|
561 |
tree.cond = translate(tree.cond, syms.booleanType); |
|
562 |
tree.step = translate(tree.step, null); |
|
563 |
tree.body = translate(tree.body); |
|
564 |
result = tree; |
|
565 |
} |
|
566 |
||
567 |
public void visitForeachLoop(JCEnhancedForLoop tree) { |
|
568 |
tree.var = translate(tree.var, null); |
|
569 |
Type iterableType = tree.expr.type; |
|
570 |
tree.expr = translate(tree.expr, erasure(tree.expr.type)); |
|
571 |
if (types.elemtype(tree.expr.type) == null) |
|
572 |
tree.expr.type = iterableType; // preserve type for Lower |
|
573 |
tree.body = translate(tree.body); |
|
574 |
result = tree; |
|
575 |
} |
|
576 |
||
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
577 |
public void visitLambda(JCLambda tree) { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
578 |
JCTree prevMethod = currentMethod; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
579 |
try { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
580 |
currentMethod = null; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
581 |
tree.params = translate(tree.params); |
22168
a48fe7ec473d
8030626: java.lang.VerifyError: Bad return type when lambda's body is in parentheses
rfield
parents:
22163
diff
changeset
|
582 |
tree.body = translate(tree.body, tree.body.type==null? null : erasure(tree.body.type)); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
583 |
tree.type = erasure(tree.type); |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
584 |
result = tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
585 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
586 |
finally { |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
587 |
currentMethod = prevMethod; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
588 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
589 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
590 |
|
10 | 591 |
public void visitSwitch(JCSwitch tree) { |
592 |
Type selsuper = types.supertype(tree.selector.type); |
|
593 |
boolean enumSwitch = selsuper != null && |
|
594 |
selsuper.tsym == syms.enumSym; |
|
595 |
Type target = enumSwitch ? erasure(tree.selector.type) : syms.intType; |
|
596 |
tree.selector = translate(tree.selector, target); |
|
597 |
tree.cases = translateCases(tree.cases); |
|
598 |
result = tree; |
|
599 |
} |
|
600 |
||
601 |
public void visitCase(JCCase tree) { |
|
602 |
tree.pat = translate(tree.pat, null); |
|
603 |
tree.stats = translate(tree.stats); |
|
604 |
result = tree; |
|
605 |
} |
|
606 |
||
607 |
public void visitSynchronized(JCSynchronized tree) { |
|
608 |
tree.lock = translate(tree.lock, erasure(tree.lock.type)); |
|
609 |
tree.body = translate(tree.body); |
|
610 |
result = tree; |
|
611 |
} |
|
612 |
||
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
613 |
public void visitTry(JCTry tree) { |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
614 |
tree.resources = translate(tree.resources, syms.autoCloseableType); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
615 |
tree.body = translate(tree.body); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
616 |
tree.catchers = translateCatchers(tree.catchers); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
617 |
tree.finalizer = translate(tree.finalizer); |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
618 |
result = tree; |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
619 |
} |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5847
diff
changeset
|
620 |
|
10 | 621 |
public void visitConditional(JCConditional tree) { |
622 |
tree.cond = translate(tree.cond, syms.booleanType); |
|
623 |
tree.truepart = translate(tree.truepart, erasure(tree.type)); |
|
624 |
tree.falsepart = translate(tree.falsepart, erasure(tree.type)); |
|
625 |
tree.type = erasure(tree.type); |
|
1356
9f40f16e543b
6500343: compiler generates bad code when translating conditional expressions
mcimadamore
parents:
1260
diff
changeset
|
626 |
result = retype(tree, tree.type, pt); |
10 | 627 |
} |
628 |
||
629 |
public void visitIf(JCIf tree) { |
|
630 |
tree.cond = translate(tree.cond, syms.booleanType); |
|
631 |
tree.thenpart = translate(tree.thenpart); |
|
632 |
tree.elsepart = translate(tree.elsepart); |
|
633 |
result = tree; |
|
634 |
} |
|
635 |
||
636 |
public void visitExec(JCExpressionStatement tree) { |
|
637 |
tree.expr = translate(tree.expr, null); |
|
638 |
result = tree; |
|
639 |
} |
|
640 |
||
641 |
public void visitReturn(JCReturn tree) { |
|
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
642 |
tree.expr = translate(tree.expr, currentMethod != null ? types.erasure(currentMethod.type).getReturnType() : null); |
10 | 643 |
result = tree; |
644 |
} |
|
645 |
||
646 |
public void visitThrow(JCThrow tree) { |
|
647 |
tree.expr = translate(tree.expr, erasure(tree.expr.type)); |
|
648 |
result = tree; |
|
649 |
} |
|
650 |
||
651 |
public void visitAssert(JCAssert tree) { |
|
652 |
tree.cond = translate(tree.cond, syms.booleanType); |
|
653 |
if (tree.detail != null) |
|
654 |
tree.detail = translate(tree.detail, erasure(tree.detail.type)); |
|
655 |
result = tree; |
|
656 |
} |
|
657 |
||
658 |
public void visitApply(JCMethodInvocation tree) { |
|
659 |
tree.meth = translate(tree.meth, null); |
|
660 |
Symbol meth = TreeInfo.symbol(tree.meth); |
|
661 |
Type mt = meth.erasure(types); |
|
27124
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
662 |
boolean useInstantiatedPtArgs = |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
663 |
allowGraphInference && !types.isSignaturePolymorphic((MethodSymbol)meth.baseSymbol()); |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
664 |
List<Type> argtypes = useInstantiatedPtArgs ? |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
665 |
tree.meth.type.getParameterTypes() : |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
666 |
mt.getParameterTypes(); |
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
667 |
if (meth.name == names.init && meth.owner == syms.enumSym) |
10 | 668 |
argtypes = argtypes.tail.tail; |
669 |
if (tree.varargsElement != null) |
|
670 |
tree.varargsElement = types.erasure(tree.varargsElement); |
|
671 |
else |
|
19133
aa085efaaa2e
8013179: assertion failure in javac when compiling with -source 1.6 -target 1.6
vromero
parents:
18730
diff
changeset
|
672 |
if (tree.args.length() != argtypes.length()) { |
aa085efaaa2e
8013179: assertion failure in javac when compiling with -source 1.6 -target 1.6
vromero
parents:
18730
diff
changeset
|
673 |
log.error(tree.pos(), |
aa085efaaa2e
8013179: assertion failure in javac when compiling with -source 1.6 -target 1.6
vromero
parents:
18730
diff
changeset
|
674 |
"method.invoked.with.incorrect.number.arguments", |
aa085efaaa2e
8013179: assertion failure in javac when compiling with -source 1.6 -target 1.6
vromero
parents:
18730
diff
changeset
|
675 |
tree.args.length(), argtypes.length()); |
aa085efaaa2e
8013179: assertion failure in javac when compiling with -source 1.6 -target 1.6
vromero
parents:
18730
diff
changeset
|
676 |
} |
10 | 677 |
tree.args = translateArgs(tree.args, argtypes, tree.varargsElement); |
678 |
||
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
679 |
tree.type = types.erasure(tree.type); |
10 | 680 |
// Insert casts of method invocation results as needed. |
681 |
result = retype(tree, mt.getReturnType(), pt); |
|
682 |
} |
|
683 |
||
684 |
public void visitNewClass(JCNewClass tree) { |
|
685 |
if (tree.encl != null) |
|
686 |
tree.encl = translate(tree.encl, erasure(tree.encl.type)); |
|
27124
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
687 |
|
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
688 |
Type erasedConstructorType = tree.constructorType != null ? |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
689 |
erasure(tree.constructorType) : |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
690 |
null; |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
691 |
|
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
692 |
List<Type> argtypes = erasedConstructorType != null && allowGraphInference ? |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
693 |
erasedConstructorType.getParameterTypes() : |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
694 |
tree.constructor.erasure(types).getParameterTypes(); |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
695 |
|
10 | 696 |
tree.clazz = translate(tree.clazz, null); |
697 |
if (tree.varargsElement != null) |
|
698 |
tree.varargsElement = types.erasure(tree.varargsElement); |
|
699 |
tree.args = translateArgs( |
|
27124
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
700 |
tree.args, argtypes, tree.varargsElement); |
10 | 701 |
tree.def = translate(tree.def, null); |
27124
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
702 |
if (erasedConstructorType != null) |
5b69a74c224e
8058199: Code generation problem with javac skipping a checkcast instruction
mcimadamore
parents:
25874
diff
changeset
|
703 |
tree.constructorType = erasedConstructorType; |
10 | 704 |
tree.type = erasure(tree.type); |
705 |
result = tree; |
|
706 |
} |
|
707 |
||
708 |
public void visitNewArray(JCNewArray tree) { |
|
709 |
tree.elemtype = translate(tree.elemtype, null); |
|
710 |
translate(tree.dims, syms.intType); |
|
5008
3a90203fa91e
6930032: fix findbugs errors in com.sun.tools.javac.comp
jjg
parents:
4865
diff
changeset
|
711 |
if (tree.type != null) { |
3a90203fa91e
6930032: fix findbugs errors in com.sun.tools.javac.comp
jjg
parents:
4865
diff
changeset
|
712 |
tree.elems = translate(tree.elems, erasure(types.elemtype(tree.type))); |
3a90203fa91e
6930032: fix findbugs errors in com.sun.tools.javac.comp
jjg
parents:
4865
diff
changeset
|
713 |
tree.type = erasure(tree.type); |
3a90203fa91e
6930032: fix findbugs errors in com.sun.tools.javac.comp
jjg
parents:
4865
diff
changeset
|
714 |
} else { |
3a90203fa91e
6930032: fix findbugs errors in com.sun.tools.javac.comp
jjg
parents:
4865
diff
changeset
|
715 |
tree.elems = translate(tree.elems, null); |
3a90203fa91e
6930032: fix findbugs errors in com.sun.tools.javac.comp
jjg
parents:
4865
diff
changeset
|
716 |
} |
10 | 717 |
|
718 |
result = tree; |
|
719 |
} |
|
720 |
||
721 |
public void visitParens(JCParens tree) { |
|
722 |
tree.expr = translate(tree.expr, pt); |
|
723 |
tree.type = erasure(tree.type); |
|
724 |
result = tree; |
|
725 |
} |
|
726 |
||
727 |
public void visitAssign(JCAssign tree) { |
|
728 |
tree.lhs = translate(tree.lhs, null); |
|
729 |
tree.rhs = translate(tree.rhs, erasure(tree.lhs.type)); |
|
17810
db9f3e9cd760
7053059: VerifyError with double Assignment using a Generic Member of a Superclass
vromero
parents:
16974
diff
changeset
|
730 |
tree.type = erasure(tree.lhs.type); |
db9f3e9cd760
7053059: VerifyError with double Assignment using a Generic Member of a Superclass
vromero
parents:
16974
diff
changeset
|
731 |
result = retype(tree, tree.type, pt); |
10 | 732 |
} |
733 |
||
734 |
public void visitAssignop(JCAssignOp tree) { |
|
3558
56be54d60f36
6869075: regression: javac crashes when compiling compound string assignment with generics
mcimadamore
parents:
3542
diff
changeset
|
735 |
tree.lhs = translate(tree.lhs, null); |
1468
19d266637353
6751514: Unary post-increment with type variables crash javac during lowering
mcimadamore
parents:
1356
diff
changeset
|
736 |
tree.rhs = translate(tree.rhs, tree.operator.type.getParameterTypes().tail.head); |
10 | 737 |
tree.type = erasure(tree.type); |
738 |
result = tree; |
|
739 |
} |
|
740 |
||
741 |
public void visitUnary(JCUnary tree) { |
|
28337
0b46fb7be75a
8043741: VerifyError due to missing checkcast
mcimadamore
parents:
27224
diff
changeset
|
742 |
tree.arg = translate(tree.arg, (tree.getTag() == Tag.NULLCHK) |
0b46fb7be75a
8043741: VerifyError due to missing checkcast
mcimadamore
parents:
27224
diff
changeset
|
743 |
? tree.type |
0b46fb7be75a
8043741: VerifyError due to missing checkcast
mcimadamore
parents:
27224
diff
changeset
|
744 |
: tree.operator.type.getParameterTypes().head); |
10 | 745 |
result = tree; |
746 |
} |
|
747 |
||
748 |
public void visitBinary(JCBinary tree) { |
|
749 |
tree.lhs = translate(tree.lhs, tree.operator.type.getParameterTypes().head); |
|
750 |
tree.rhs = translate(tree.rhs, tree.operator.type.getParameterTypes().tail.head); |
|
751 |
result = tree; |
|
752 |
} |
|
753 |
||
754 |
public void visitTypeCast(JCTypeCast tree) { |
|
755 |
tree.clazz = translate(tree.clazz, null); |
|
16974
0c9f2cc31ae7
8011392: Missing checkcast when casting to intersection type
mcimadamore
parents:
16968
diff
changeset
|
756 |
Type originalTarget = tree.type; |
10 | 757 |
tree.type = erasure(tree.type); |
28339
fa0685d84b74
8067914: Redundant type cast nodes in AST (follow up from JDK-8043741)
mcimadamore
parents:
28337
diff
changeset
|
758 |
JCExpression newExpression = translate(tree.expr, erasure(tree.expr.type)); |
fa0685d84b74
8067914: Redundant type cast nodes in AST (follow up from JDK-8043741)
mcimadamore
parents:
28337
diff
changeset
|
759 |
if (newExpression != tree.expr) { |
fa0685d84b74
8067914: Redundant type cast nodes in AST (follow up from JDK-8043741)
mcimadamore
parents:
28337
diff
changeset
|
760 |
JCTypeCast typeCast = newExpression.hasTag(Tag.TYPECAST) |
fa0685d84b74
8067914: Redundant type cast nodes in AST (follow up from JDK-8043741)
mcimadamore
parents:
28337
diff
changeset
|
761 |
? (JCTypeCast) newExpression |
fa0685d84b74
8067914: Redundant type cast nodes in AST (follow up from JDK-8043741)
mcimadamore
parents:
28337
diff
changeset
|
762 |
: null; |
fa0685d84b74
8067914: Redundant type cast nodes in AST (follow up from JDK-8043741)
mcimadamore
parents:
28337
diff
changeset
|
763 |
tree.expr = typeCast != null && types.isSameType(typeCast.type, originalTarget, true) |
fa0685d84b74
8067914: Redundant type cast nodes in AST (follow up from JDK-8043741)
mcimadamore
parents:
28337
diff
changeset
|
764 |
? typeCast.expr |
fa0685d84b74
8067914: Redundant type cast nodes in AST (follow up from JDK-8043741)
mcimadamore
parents:
28337
diff
changeset
|
765 |
: newExpression; |
fa0685d84b74
8067914: Redundant type cast nodes in AST (follow up from JDK-8043741)
mcimadamore
parents:
28337
diff
changeset
|
766 |
} |
16974
0c9f2cc31ae7
8011392: Missing checkcast when casting to intersection type
mcimadamore
parents:
16968
diff
changeset
|
767 |
if (originalTarget.isCompound()) { |
0c9f2cc31ae7
8011392: Missing checkcast when casting to intersection type
mcimadamore
parents:
16968
diff
changeset
|
768 |
Type.IntersectionClassType ict = (Type.IntersectionClassType)originalTarget; |
0c9f2cc31ae7
8011392: Missing checkcast when casting to intersection type
mcimadamore
parents:
16968
diff
changeset
|
769 |
for (Type c : ict.getExplicitComponents()) { |
0c9f2cc31ae7
8011392: Missing checkcast when casting to intersection type
mcimadamore
parents:
16968
diff
changeset
|
770 |
Type ec = erasure(c); |
0c9f2cc31ae7
8011392: Missing checkcast when casting to intersection type
mcimadamore
parents:
16968
diff
changeset
|
771 |
if (!types.isSameType(ec, tree.type)) { |
0c9f2cc31ae7
8011392: Missing checkcast when casting to intersection type
mcimadamore
parents:
16968
diff
changeset
|
772 |
tree.expr = coerce(tree.expr, ec); |
0c9f2cc31ae7
8011392: Missing checkcast when casting to intersection type
mcimadamore
parents:
16968
diff
changeset
|
773 |
} |
0c9f2cc31ae7
8011392: Missing checkcast when casting to intersection type
mcimadamore
parents:
16968
diff
changeset
|
774 |
} |
0c9f2cc31ae7
8011392: Missing checkcast when casting to intersection type
mcimadamore
parents:
16968
diff
changeset
|
775 |
} |
10 | 776 |
result = tree; |
777 |
} |
|
778 |
||
779 |
public void visitTypeTest(JCInstanceOf tree) { |
|
780 |
tree.expr = translate(tree.expr, null); |
|
781 |
tree.clazz = translate(tree.clazz, null); |
|
782 |
result = tree; |
|
783 |
} |
|
784 |
||
785 |
public void visitIndexed(JCArrayAccess tree) { |
|
786 |
tree.indexed = translate(tree.indexed, erasure(tree.indexed.type)); |
|
787 |
tree.index = translate(tree.index, syms.intType); |
|
788 |
||
789 |
// Insert casts of indexed expressions as needed. |
|
790 |
result = retype(tree, types.elemtype(tree.indexed.type), pt); |
|
791 |
} |
|
792 |
||
793 |
// There ought to be nothing to rewrite here; |
|
794 |
// we don't generate code. |
|
795 |
public void visitAnnotation(JCAnnotation tree) { |
|
796 |
result = tree; |
|
797 |
} |
|
798 |
||
799 |
public void visitIdent(JCIdent tree) { |
|
800 |
Type et = tree.sym.erasure(types); |
|
801 |
||
802 |
// Map type variables to their bounds. |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
803 |
if (tree.sym.kind == TYP && tree.sym.type.hasTag(TYPEVAR)) { |
10 | 804 |
result = make.at(tree.pos).Type(et); |
805 |
} else |
|
806 |
// Map constants expressions to themselves. |
|
807 |
if (tree.type.constValue() != null) { |
|
808 |
result = tree; |
|
809 |
} |
|
810 |
// Insert casts of variable uses as needed. |
|
811 |
else if (tree.sym.kind == VAR) { |
|
812 |
result = retype(tree, et, pt); |
|
813 |
} |
|
814 |
else { |
|
815 |
tree.type = erasure(tree.type); |
|
816 |
result = tree; |
|
817 |
} |
|
818 |
} |
|
819 |
||
820 |
public void visitSelect(JCFieldAccess tree) { |
|
821 |
Type t = tree.selected.type; |
|
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14259
diff
changeset
|
822 |
while (t.hasTag(TYPEVAR)) |
507
bdd92cc35ac4
6531075: Missing synthetic casts when accessing fields/methods of intersection types including type variables
mcimadamore
parents:
10
diff
changeset
|
823 |
t = t.getUpperBound(); |
bdd92cc35ac4
6531075: Missing synthetic casts when accessing fields/methods of intersection types including type variables
mcimadamore
parents:
10
diff
changeset
|
824 |
if (t.isCompound()) { |
10 | 825 |
if ((tree.sym.flags() & IPROXY) != 0) { |
826 |
tree.sym = ((MethodSymbol)tree.sym). |
|
827 |
implemented((TypeSymbol)tree.sym.owner, types); |
|
828 |
} |
|
7617
6d4424dd7256
6956758: NPE in com.sun.tools.javac.code.Symbol - isSubClass
mcimadamore
parents:
7080
diff
changeset
|
829 |
tree.selected = coerce( |
507
bdd92cc35ac4
6531075: Missing synthetic casts when accessing fields/methods of intersection types including type variables
mcimadamore
parents:
10
diff
changeset
|
830 |
translate(tree.selected, erasure(tree.selected.type)), |
10 | 831 |
erasure(tree.sym.owner.type)); |
832 |
} else |
|
833 |
tree.selected = translate(tree.selected, erasure(t)); |
|
834 |
||
835 |
// Map constants expressions to themselves. |
|
836 |
if (tree.type.constValue() != null) { |
|
837 |
result = tree; |
|
838 |
} |
|
839 |
// Insert casts of variable uses as needed. |
|
840 |
else if (tree.sym.kind == VAR) { |
|
841 |
result = retype(tree, tree.sym.erasure(types), pt); |
|
842 |
} |
|
843 |
else { |
|
844 |
tree.type = erasure(tree.type); |
|
845 |
result = tree; |
|
846 |
} |
|
847 |
} |
|
848 |
||
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
849 |
public void visitReference(JCMemberReference tree) { |
19939
ab90fbc7b74e
8023558: Javac creates invalid bootstrap methods for complex lambda/methodref case
vromero
parents:
19133
diff
changeset
|
850 |
tree.expr = translate(tree.expr, erasure(tree.expr.type)); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
851 |
tree.type = erasure(tree.type); |
23127
5aba53c2b9b2
8034048: javac crash with method references plus lambda plus var args
jjg
parents:
22168
diff
changeset
|
852 |
if (tree.varargsElement != null) |
5aba53c2b9b2
8034048: javac crash with method references plus lambda plus var args
jjg
parents:
22168
diff
changeset
|
853 |
tree.varargsElement = erasure(tree.varargsElement); |
14365
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
854 |
result = tree; |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
855 |
} |
20f388573215
8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents:
14359
diff
changeset
|
856 |
|
10 | 857 |
public void visitTypeArray(JCArrayTypeTree tree) { |
858 |
tree.elemtype = translate(tree.elemtype, null); |
|
859 |
tree.type = erasure(tree.type); |
|
860 |
result = tree; |
|
861 |
} |
|
862 |
||
863 |
/** Visitor method for parameterized types. |
|
864 |
*/ |
|
865 |
public void visitTypeApply(JCTypeApply tree) { |
|
3149 | 866 |
JCTree clazz = translate(tree.clazz, null); |
867 |
result = clazz; |
|
10 | 868 |
} |
869 |
||
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14547
diff
changeset
|
870 |
public void visitTypeIntersection(JCTypeIntersection tree) { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14547
diff
changeset
|
871 |
tree.bounds = translate(tree.bounds, null); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14547
diff
changeset
|
872 |
tree.type = erasure(tree.type); |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14547
diff
changeset
|
873 |
result = tree; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14547
diff
changeset
|
874 |
} |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14547
diff
changeset
|
875 |
|
10 | 876 |
/************************************************************************** |
877 |
* utility methods |
|
878 |
*************************************************************************/ |
|
879 |
||
880 |
private Type erasure(Type t) { |
|
881 |
return types.erasure(t); |
|
882 |
} |
|
883 |
||
884 |
/************************************************************************** |
|
885 |
* main method |
|
886 |
*************************************************************************/ |
|
887 |
||
888 |
private Env<AttrContext> env; |
|
889 |
||
16968 | 890 |
private static final String statePreviousToFlowAssertMsg = |
891 |
"The current compile state [%s] of class %s is previous to FLOW"; |
|
892 |
||
10 | 893 |
void translateClass(ClassSymbol c) { |
894 |
Type st = types.supertype(c.type); |
|
895 |
// process superclass before derived |
|
16968 | 896 |
if (st.hasTag(CLASS)) { |
10 | 897 |
translateClass((ClassSymbol)st.tsym); |
16968 | 898 |
} |
10 | 899 |
|
25007 | 900 |
Env<AttrContext> myEnv = enter.getEnv(c); |
901 |
if (myEnv == null || (c.flags_field & TYPE_TRANSLATED) != 0) { |
|
10 | 902 |
return; |
16968 | 903 |
} |
25007 | 904 |
c.flags_field |= TYPE_TRANSLATED; |
16968 | 905 |
|
906 |
/* The two assertions below are set for early detection of any attempt |
|
907 |
* to translate a class that: |
|
908 |
* |
|
909 |
* 1) has no compile state being it the most outer class. |
|
910 |
* We accept this condition for inner classes. |
|
911 |
* |
|
912 |
* 2) has a compile state which is previous to Flow state. |
|
913 |
*/ |
|
914 |
boolean envHasCompState = compileStates.get(myEnv) != null; |
|
915 |
if (!envHasCompState && c.outermostClass() == c) { |
|
916 |
Assert.error("No info for outermost class: " + myEnv.enclClass.sym); |
|
917 |
} |
|
918 |
||
919 |
if (envHasCompState && |
|
920 |
CompileState.FLOW.isAfter(compileStates.get(myEnv))) { |
|
921 |
Assert.error(String.format(statePreviousToFlowAssertMsg, |
|
922 |
compileStates.get(myEnv), myEnv.enclClass.sym)); |
|
923 |
} |
|
924 |
||
10 | 925 |
Env<AttrContext> oldEnv = env; |
926 |
try { |
|
927 |
env = myEnv; |
|
928 |
// class has not been translated yet |
|
929 |
||
930 |
TreeMaker savedMake = make; |
|
931 |
Type savedPt = pt; |
|
932 |
make = make.forToplevel(env.toplevel); |
|
933 |
pt = null; |
|
934 |
try { |
|
935 |
JCClassDecl tree = (JCClassDecl) env.tree; |
|
936 |
tree.typarams = List.nil(); |
|
937 |
super.visitClassDef(tree); |
|
938 |
make.at(tree.pos); |
|
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
939 |
ListBuffer<JCTree> bridges = new ListBuffer<>(); |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
940 |
if (allowInterfaceBridges || (tree.sym.flags() & INTERFACE) == 0) { |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
941 |
addBridges(tree.pos(), c, bridges); |
10 | 942 |
} |
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25443
diff
changeset
|
943 |
tree.defs = bridges.toList().prependList(tree.defs); |
10 | 944 |
tree.type = erasure(tree.type); |
945 |
} finally { |
|
946 |
make = savedMake; |
|
947 |
pt = savedPt; |
|
948 |
} |
|
949 |
} finally { |
|
950 |
env = oldEnv; |
|
951 |
} |
|
952 |
} |
|
953 |
||
954 |
/** Translate a toplevel class definition. |
|
955 |
* @param cdef The definition to be translated. |
|
956 |
*/ |
|
957 |
public JCTree translateTopLevelClass(JCTree cdef, TreeMaker make) { |
|
958 |
// note that this method does NOT support recursion. |
|
959 |
this.make = make; |
|
960 |
pt = null; |
|
961 |
return translate(cdef, null); |
|
962 |
} |
|
963 |
} |