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