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