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