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