src/share/classes/com/sun/tools/javac/code/Symtab.java

changeset 0
959103a6100f
child 2525
2eb010b6cb22
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symtab.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,723 @@
     1.4 +/*
     1.5 + * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.tools.javac.code;
    1.30 +
    1.31 +import java.util.*;
    1.32 +
    1.33 +import javax.lang.model.element.ElementVisitor;
    1.34 +
    1.35 +import com.sun.tools.javac.code.Symbol.*;
    1.36 +import com.sun.tools.javac.code.Type.*;
    1.37 +import com.sun.tools.javac.jvm.*;
    1.38 +import com.sun.tools.javac.util.*;
    1.39 +import com.sun.tools.javac.util.List;
    1.40 +import static com.sun.tools.javac.code.Flags.*;
    1.41 +import static com.sun.tools.javac.jvm.ByteCodes.*;
    1.42 +import static com.sun.tools.javac.code.TypeTag.*;
    1.43 +
    1.44 +/** A class that defines all predefined constants and operators
    1.45 + *  as well as special classes such as java.lang.Object, which need
    1.46 + *  to be known to the compiler. All symbols are held in instance
    1.47 + *  fields. This makes it possible to work in multiple concurrent
    1.48 + *  projects, which might use different class files for library classes.
    1.49 + *
    1.50 + *  <p><b>This is NOT part of any supported API.
    1.51 + *  If you write code that depends on this, you do so at your own risk.
    1.52 + *  This code and its internal interfaces are subject to change or
    1.53 + *  deletion without notice.</b>
    1.54 + */
    1.55 +public class Symtab {
    1.56 +    /** The context key for the symbol table. */
    1.57 +    protected static final Context.Key<Symtab> symtabKey =
    1.58 +        new Context.Key<Symtab>();
    1.59 +
    1.60 +    /** Get the symbol table instance. */
    1.61 +    public static Symtab instance(Context context) {
    1.62 +        Symtab instance = context.get(symtabKey);
    1.63 +        if (instance == null)
    1.64 +            instance = new Symtab(context);
    1.65 +        return instance;
    1.66 +    }
    1.67 +
    1.68 +    /** Builtin types.
    1.69 +     */
    1.70 +    public final JCPrimitiveType byteType = new JCPrimitiveType(BYTE, null);
    1.71 +    public final JCPrimitiveType charType = new JCPrimitiveType(CHAR, null);
    1.72 +    public final JCPrimitiveType shortType = new JCPrimitiveType(SHORT, null);
    1.73 +    public final JCPrimitiveType intType = new JCPrimitiveType(INT, null);
    1.74 +    public final JCPrimitiveType longType = new JCPrimitiveType(LONG, null);
    1.75 +    public final JCPrimitiveType floatType = new JCPrimitiveType(FLOAT, null);
    1.76 +    public final JCPrimitiveType doubleType = new JCPrimitiveType(DOUBLE, null);
    1.77 +    public final JCPrimitiveType booleanType = new JCPrimitiveType(BOOLEAN, null);
    1.78 +    public final Type botType = new BottomType();
    1.79 +    public final JCVoidType voidType = new JCVoidType();
    1.80 +
    1.81 +    private final Names names;
    1.82 +    private final ClassReader reader;
    1.83 +    private final Target target;
    1.84 +
    1.85 +    /** A symbol for the root package.
    1.86 +     */
    1.87 +    public final PackageSymbol rootPackage;
    1.88 +
    1.89 +    /** A symbol for the unnamed package.
    1.90 +     */
    1.91 +    public final PackageSymbol unnamedPackage;
    1.92 +
    1.93 +    /** A symbol that stands for a missing symbol.
    1.94 +     */
    1.95 +    public final TypeSymbol noSymbol;
    1.96 +
    1.97 +    /** The error symbol.
    1.98 +     */
    1.99 +    public final ClassSymbol errSymbol;
   1.100 +
   1.101 +    /** The unknown symbol.
   1.102 +     */
   1.103 +    public final ClassSymbol unknownSymbol;
   1.104 +
   1.105 +    /** A value for the errType, with a originalType of noType */
   1.106 +    public final Type errType;
   1.107 +
   1.108 +    /** A value for the unknown type. */
   1.109 +    public final Type unknownType;
   1.110 +
   1.111 +    /** The builtin type of all arrays. */
   1.112 +    public final ClassSymbol arrayClass;
   1.113 +    public final MethodSymbol arrayCloneMethod;
   1.114 +
   1.115 +    /** VGJ: The (singleton) type of all bound types. */
   1.116 +    public final ClassSymbol boundClass;
   1.117 +
   1.118 +    /** The builtin type of all methods. */
   1.119 +    public final ClassSymbol methodClass;
   1.120 +
   1.121 +    /** Predefined types.
   1.122 +     */
   1.123 +    public final Type objectType;
   1.124 +    public final Type classType;
   1.125 +    public final Type classLoaderType;
   1.126 +    public final Type stringType;
   1.127 +    public final Type stringBufferType;
   1.128 +    public final Type stringBuilderType;
   1.129 +    public final Type cloneableType;
   1.130 +    public final Type serializableType;
   1.131 +    public final Type serializedLambdaType;
   1.132 +    public final Type methodHandleType;
   1.133 +    public final Type methodHandleLookupType;
   1.134 +    public final Type methodTypeType;
   1.135 +    public final Type nativeHeaderType;
   1.136 +    public final Type throwableType;
   1.137 +    public final Type errorType;
   1.138 +    public final Type interruptedExceptionType;
   1.139 +    public final Type illegalArgumentExceptionType;
   1.140 +    public final Type exceptionType;
   1.141 +    public final Type runtimeExceptionType;
   1.142 +    public final Type classNotFoundExceptionType;
   1.143 +    public final Type noClassDefFoundErrorType;
   1.144 +    public final Type noSuchFieldErrorType;
   1.145 +    public final Type assertionErrorType;
   1.146 +    public final Type cloneNotSupportedExceptionType;
   1.147 +    public final Type annotationType;
   1.148 +    public final TypeSymbol enumSym;
   1.149 +    public final Type listType;
   1.150 +    public final Type collectionsType;
   1.151 +    public final Type comparableType;
   1.152 +    public final Type comparatorType;
   1.153 +    public final Type arraysType;
   1.154 +    public final Type iterableType;
   1.155 +    public final Type iteratorType;
   1.156 +    public final Type annotationTargetType;
   1.157 +    public final Type overrideType;
   1.158 +    public final Type retentionType;
   1.159 +    public final Type deprecatedType;
   1.160 +    public final Type suppressWarningsType;
   1.161 +    public final Type inheritedType;
   1.162 +    public final Type profileType;
   1.163 +    public final Type proprietaryType;
   1.164 +    public final Type systemType;
   1.165 +    public final Type autoCloseableType;
   1.166 +    public final Type trustMeType;
   1.167 +    public final Type lambdaMetafactory;
   1.168 +    public final Type repeatableType;
   1.169 +    public final Type documentedType;
   1.170 +    public final Type elementTypeType;
   1.171 +    public final Type functionalInterfaceType;
   1.172 +
   1.173 +    /** The symbol representing the length field of an array.
   1.174 +     */
   1.175 +    public final VarSymbol lengthVar;
   1.176 +
   1.177 +    /** The null check operator. */
   1.178 +    public final OperatorSymbol nullcheck;
   1.179 +
   1.180 +    /** The symbol representing the final finalize method on enums */
   1.181 +    public final MethodSymbol enumFinalFinalize;
   1.182 +
   1.183 +    /** The symbol representing the close method on TWR AutoCloseable type */
   1.184 +    public final MethodSymbol autoCloseableClose;
   1.185 +
   1.186 +    /** The predefined type that belongs to a tag.
   1.187 +     */
   1.188 +    public final Type[] typeOfTag = new Type[TypeTag.getTypeTagCount()];
   1.189 +
   1.190 +    /** The name of the class that belongs to a basix type tag.
   1.191 +     */
   1.192 +    public final Name[] boxedName = new Name[TypeTag.getTypeTagCount()];
   1.193 +
   1.194 +    /** A set containing all operator names.
   1.195 +     */
   1.196 +    public final Set<Name> operatorNames = new HashSet<Name>();
   1.197 +
   1.198 +    /** A hashtable containing the encountered top-level and member classes,
   1.199 +     *  indexed by flat names. The table does not contain local classes.
   1.200 +     *  It should be updated from the outside to reflect classes defined
   1.201 +     *  by compiled source files.
   1.202 +     */
   1.203 +    public final Map<Name, ClassSymbol> classes = new HashMap<Name, ClassSymbol>();
   1.204 +
   1.205 +    /** A hashtable containing the encountered packages.
   1.206 +     *  the table should be updated from outside to reflect packages defined
   1.207 +     *  by compiled source files.
   1.208 +     */
   1.209 +    public final Map<Name, PackageSymbol> packages = new HashMap<Name, PackageSymbol>();
   1.210 +
   1.211 +    public void initType(Type type, ClassSymbol c) {
   1.212 +        type.tsym = c;
   1.213 +        typeOfTag[type.getTag().ordinal()] = type;
   1.214 +    }
   1.215 +
   1.216 +    public void initType(Type type, String name) {
   1.217 +        initType(
   1.218 +            type,
   1.219 +            new ClassSymbol(
   1.220 +                PUBLIC, names.fromString(name), type, rootPackage));
   1.221 +    }
   1.222 +
   1.223 +    public void initType(Type type, String name, String bname) {
   1.224 +        initType(type, name);
   1.225 +            boxedName[type.getTag().ordinal()] = names.fromString("java.lang." + bname);
   1.226 +    }
   1.227 +
   1.228 +    /** The class symbol that owns all predefined symbols.
   1.229 +     */
   1.230 +    public final ClassSymbol predefClass;
   1.231 +
   1.232 +    /** Enter a constant into symbol table.
   1.233 +     *  @param name   The constant's name.
   1.234 +     *  @param type   The constant's type.
   1.235 +     */
   1.236 +    private VarSymbol enterConstant(String name, Type type) {
   1.237 +        VarSymbol c = new VarSymbol(
   1.238 +            PUBLIC | STATIC | FINAL,
   1.239 +            names.fromString(name),
   1.240 +            type,
   1.241 +            predefClass);
   1.242 +        c.setData(type.constValue());
   1.243 +        predefClass.members().enter(c);
   1.244 +        return c;
   1.245 +    }
   1.246 +
   1.247 +    /** Enter a binary operation into symbol table.
   1.248 +     *  @param name     The name of the operator.
   1.249 +     *  @param left     The type of the left operand.
   1.250 +     *  @param right    The type of the left operand.
   1.251 +     *  @param res      The operation's result type.
   1.252 +     *  @param opcode   The operation's bytecode instruction.
   1.253 +     */
   1.254 +    private void enterBinop(String name,
   1.255 +                            Type left, Type right, Type res,
   1.256 +                            int opcode) {
   1.257 +        predefClass.members().enter(
   1.258 +            new OperatorSymbol(
   1.259 +                makeOperatorName(name),
   1.260 +                new MethodType(List.of(left, right), res,
   1.261 +                               List.<Type>nil(), methodClass),
   1.262 +                opcode,
   1.263 +                predefClass));
   1.264 +    }
   1.265 +
   1.266 +    /** Enter a binary operation, as above but with two opcodes,
   1.267 +     *  which get encoded as
   1.268 +     *  {@code (opcode1 << ByteCodeTags.preShift) + opcode2 }.
   1.269 +     *  @param opcode1     First opcode.
   1.270 +     *  @param opcode2     Second opcode.
   1.271 +     */
   1.272 +    private void enterBinop(String name,
   1.273 +                            Type left, Type right, Type res,
   1.274 +                            int opcode1, int opcode2) {
   1.275 +        enterBinop(
   1.276 +            name, left, right, res, (opcode1 << ByteCodes.preShift) | opcode2);
   1.277 +    }
   1.278 +
   1.279 +    /** Enter a unary operation into symbol table.
   1.280 +     *  @param name     The name of the operator.
   1.281 +     *  @param arg      The type of the operand.
   1.282 +     *  @param res      The operation's result type.
   1.283 +     *  @param opcode   The operation's bytecode instruction.
   1.284 +     */
   1.285 +    private OperatorSymbol enterUnop(String name,
   1.286 +                                     Type arg,
   1.287 +                                     Type res,
   1.288 +                                     int opcode) {
   1.289 +        OperatorSymbol sym =
   1.290 +            new OperatorSymbol(makeOperatorName(name),
   1.291 +                               new MethodType(List.of(arg),
   1.292 +                                              res,
   1.293 +                                              List.<Type>nil(),
   1.294 +                                              methodClass),
   1.295 +                               opcode,
   1.296 +                               predefClass);
   1.297 +        predefClass.members().enter(sym);
   1.298 +        return sym;
   1.299 +    }
   1.300 +
   1.301 +    /**
   1.302 +     * Create a new operator name from corresponding String representation
   1.303 +     * and add the name to the set of known operator names.
   1.304 +     */
   1.305 +    private Name makeOperatorName(String name) {
   1.306 +        Name opName = names.fromString(name);
   1.307 +        operatorNames.add(opName);
   1.308 +        return opName;
   1.309 +    }
   1.310 +
   1.311 +    /** Enter a class into symbol table.
   1.312 +     *  @param s The name of the class.
   1.313 +     */
   1.314 +    private Type enterClass(String s) {
   1.315 +        return reader.enterClass(names.fromString(s)).type;
   1.316 +    }
   1.317 +
   1.318 +    public void synthesizeEmptyInterfaceIfMissing(final Type type) {
   1.319 +        final Completer completer = type.tsym.completer;
   1.320 +        if (completer != null) {
   1.321 +            type.tsym.completer = new Completer() {
   1.322 +                public void complete(Symbol sym) throws CompletionFailure {
   1.323 +                    try {
   1.324 +                        completer.complete(sym);
   1.325 +                    } catch (CompletionFailure e) {
   1.326 +                        sym.flags_field |= (PUBLIC | INTERFACE);
   1.327 +                        ((ClassType) sym.type).supertype_field = objectType;
   1.328 +                    }
   1.329 +                }
   1.330 +            };
   1.331 +        }
   1.332 +    }
   1.333 +
   1.334 +    public void synthesizeBoxTypeIfMissing(final Type type) {
   1.335 +        ClassSymbol sym = reader.enterClass(boxedName[type.getTag().ordinal()]);
   1.336 +        final Completer completer = sym.completer;
   1.337 +        if (completer != null) {
   1.338 +            sym.completer = new Completer() {
   1.339 +                public void complete(Symbol sym) throws CompletionFailure {
   1.340 +                    try {
   1.341 +                        completer.complete(sym);
   1.342 +                    } catch (CompletionFailure e) {
   1.343 +                        sym.flags_field |= PUBLIC;
   1.344 +                        ((ClassType) sym.type).supertype_field = objectType;
   1.345 +                        Name n = target.boxWithConstructors() ? names.init : names.valueOf;
   1.346 +                        MethodSymbol boxMethod =
   1.347 +                            new MethodSymbol(PUBLIC | STATIC,
   1.348 +                                n,
   1.349 +                                new MethodType(List.of(type), sym.type,
   1.350 +                                    List.<Type>nil(), methodClass),
   1.351 +                                sym);
   1.352 +                        sym.members().enter(boxMethod);
   1.353 +                        MethodSymbol unboxMethod =
   1.354 +                            new MethodSymbol(PUBLIC,
   1.355 +                                type.tsym.name.append(names.Value), // x.intValue()
   1.356 +                                new MethodType(List.<Type>nil(), type,
   1.357 +                                    List.<Type>nil(), methodClass),
   1.358 +                                sym);
   1.359 +                        sym.members().enter(unboxMethod);
   1.360 +                    }
   1.361 +                }
   1.362 +            };
   1.363 +        }
   1.364 +
   1.365 +    }
   1.366 +
   1.367 +    // Enter a synthetic class that is used to mark classes in ct.sym.
   1.368 +    // This class does not have a class file.
   1.369 +    private Type enterSyntheticAnnotation(String name) {
   1.370 +        ClassType type = (ClassType)enterClass(name);
   1.371 +        ClassSymbol sym = (ClassSymbol)type.tsym;
   1.372 +        sym.completer = null;
   1.373 +        sym.flags_field = PUBLIC|ACYCLIC|ANNOTATION|INTERFACE;
   1.374 +        sym.erasure_field = type;
   1.375 +        sym.members_field = new Scope(sym);
   1.376 +        type.typarams_field = List.nil();
   1.377 +        type.allparams_field = List.nil();
   1.378 +        type.supertype_field = annotationType;
   1.379 +        type.interfaces_field = List.nil();
   1.380 +        return type;
   1.381 +    }
   1.382 +
   1.383 +    /** Constructor; enters all predefined identifiers and operators
   1.384 +     *  into symbol table.
   1.385 +     */
   1.386 +    protected Symtab(Context context) throws CompletionFailure {
   1.387 +        context.put(symtabKey, this);
   1.388 +
   1.389 +        names = Names.instance(context);
   1.390 +        target = Target.instance(context);
   1.391 +
   1.392 +        // Create the unknown type
   1.393 +        unknownType = new UnknownType();
   1.394 +
   1.395 +        // create the basic builtin symbols
   1.396 +        rootPackage = new PackageSymbol(names.empty, null);
   1.397 +        final JavacMessages messages = JavacMessages.instance(context);
   1.398 +        unnamedPackage = new PackageSymbol(names.empty, rootPackage) {
   1.399 +                public String toString() {
   1.400 +                    return messages.getLocalizedString("compiler.misc.unnamed.package");
   1.401 +                }
   1.402 +            };
   1.403 +        noSymbol = new TypeSymbol(Kinds.NIL, 0, names.empty, Type.noType, rootPackage) {
   1.404 +            public <R, P> R accept(ElementVisitor<R, P> v, P p) {
   1.405 +                return v.visitUnknown(this, p);
   1.406 +            }
   1.407 +        };
   1.408 +
   1.409 +        // create the error symbols
   1.410 +        errSymbol = new ClassSymbol(PUBLIC|STATIC|ACYCLIC, names.any, null, rootPackage);
   1.411 +        errType = new ErrorType(errSymbol, Type.noType);
   1.412 +
   1.413 +        unknownSymbol = new ClassSymbol(PUBLIC|STATIC|ACYCLIC, names.fromString("<any?>"), null, rootPackage);
   1.414 +        unknownSymbol.members_field = new Scope.ErrorScope(unknownSymbol);
   1.415 +        unknownSymbol.type = unknownType;
   1.416 +
   1.417 +        // initialize builtin types
   1.418 +        initType(byteType, "byte", "Byte");
   1.419 +        initType(shortType, "short", "Short");
   1.420 +        initType(charType, "char", "Character");
   1.421 +        initType(intType, "int", "Integer");
   1.422 +        initType(longType, "long", "Long");
   1.423 +        initType(floatType, "float", "Float");
   1.424 +        initType(doubleType, "double", "Double");
   1.425 +        initType(booleanType, "boolean", "Boolean");
   1.426 +        initType(voidType, "void", "Void");
   1.427 +        initType(botType, "<nulltype>");
   1.428 +        initType(errType, errSymbol);
   1.429 +        initType(unknownType, unknownSymbol);
   1.430 +
   1.431 +        // the builtin class of all arrays
   1.432 +        arrayClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Array, noSymbol);
   1.433 +
   1.434 +        // VGJ
   1.435 +        boundClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Bound, noSymbol);
   1.436 +        boundClass.members_field = new Scope.ErrorScope(boundClass);
   1.437 +
   1.438 +        // the builtin class of all methods
   1.439 +        methodClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Method, noSymbol);
   1.440 +        methodClass.members_field = new Scope.ErrorScope(boundClass);
   1.441 +
   1.442 +        // Create class to hold all predefined constants and operations.
   1.443 +        predefClass = new ClassSymbol(PUBLIC|ACYCLIC, names.empty, rootPackage);
   1.444 +        Scope scope = new Scope(predefClass);
   1.445 +        predefClass.members_field = scope;
   1.446 +
   1.447 +        // Enter symbols for basic types.
   1.448 +        scope.enter(byteType.tsym);
   1.449 +        scope.enter(shortType.tsym);
   1.450 +        scope.enter(charType.tsym);
   1.451 +        scope.enter(intType.tsym);
   1.452 +        scope.enter(longType.tsym);
   1.453 +        scope.enter(floatType.tsym);
   1.454 +        scope.enter(doubleType.tsym);
   1.455 +        scope.enter(booleanType.tsym);
   1.456 +        scope.enter(errType.tsym);
   1.457 +
   1.458 +        // Enter symbol for the errSymbol
   1.459 +        scope.enter(errSymbol);
   1.460 +
   1.461 +        classes.put(predefClass.fullname, predefClass);
   1.462 +
   1.463 +        reader = ClassReader.instance(context);
   1.464 +        reader.init(this);
   1.465 +
   1.466 +        // Enter predefined classes.
   1.467 +        objectType = enterClass("java.lang.Object");
   1.468 +        classType = enterClass("java.lang.Class");
   1.469 +        stringType = enterClass("java.lang.String");
   1.470 +        stringBufferType = enterClass("java.lang.StringBuffer");
   1.471 +        stringBuilderType = enterClass("java.lang.StringBuilder");
   1.472 +        cloneableType = enterClass("java.lang.Cloneable");
   1.473 +        throwableType = enterClass("java.lang.Throwable");
   1.474 +        serializableType = enterClass("java.io.Serializable");
   1.475 +        serializedLambdaType = enterClass("java.lang.invoke.SerializedLambda");
   1.476 +        methodHandleType = enterClass("java.lang.invoke.MethodHandle");
   1.477 +        methodHandleLookupType = enterClass("java.lang.invoke.MethodHandles$Lookup");
   1.478 +        methodTypeType = enterClass("java.lang.invoke.MethodType");
   1.479 +        errorType = enterClass("java.lang.Error");
   1.480 +        illegalArgumentExceptionType = enterClass("java.lang.IllegalArgumentException");
   1.481 +        interruptedExceptionType = enterClass("java.lang.InterruptedException");
   1.482 +        exceptionType = enterClass("java.lang.Exception");
   1.483 +        runtimeExceptionType = enterClass("java.lang.RuntimeException");
   1.484 +        classNotFoundExceptionType = enterClass("java.lang.ClassNotFoundException");
   1.485 +        noClassDefFoundErrorType = enterClass("java.lang.NoClassDefFoundError");
   1.486 +        noSuchFieldErrorType = enterClass("java.lang.NoSuchFieldError");
   1.487 +        assertionErrorType = enterClass("java.lang.AssertionError");
   1.488 +        cloneNotSupportedExceptionType = enterClass("java.lang.CloneNotSupportedException");
   1.489 +        annotationType = enterClass("java.lang.annotation.Annotation");
   1.490 +        classLoaderType = enterClass("java.lang.ClassLoader");
   1.491 +        enumSym = reader.enterClass(names.java_lang_Enum);
   1.492 +        enumFinalFinalize =
   1.493 +            new MethodSymbol(PROTECTED|FINAL|HYPOTHETICAL,
   1.494 +                             names.finalize,
   1.495 +                             new MethodType(List.<Type>nil(), voidType,
   1.496 +                                            List.<Type>nil(), methodClass),
   1.497 +                             enumSym);
   1.498 +        listType = enterClass("java.util.List");
   1.499 +        collectionsType = enterClass("java.util.Collections");
   1.500 +        comparableType = enterClass("java.lang.Comparable");
   1.501 +        comparatorType = enterClass("java.util.Comparator");
   1.502 +        arraysType = enterClass("java.util.Arrays");
   1.503 +        iterableType = target.hasIterable()
   1.504 +            ? enterClass("java.lang.Iterable")
   1.505 +            : enterClass("java.util.Collection");
   1.506 +        iteratorType = enterClass("java.util.Iterator");
   1.507 +        annotationTargetType = enterClass("java.lang.annotation.Target");
   1.508 +        overrideType = enterClass("java.lang.Override");
   1.509 +        retentionType = enterClass("java.lang.annotation.Retention");
   1.510 +        deprecatedType = enterClass("java.lang.Deprecated");
   1.511 +        suppressWarningsType = enterClass("java.lang.SuppressWarnings");
   1.512 +        inheritedType = enterClass("java.lang.annotation.Inherited");
   1.513 +        repeatableType = enterClass("java.lang.annotation.Repeatable");
   1.514 +        documentedType = enterClass("java.lang.annotation.Documented");
   1.515 +        elementTypeType = enterClass("java.lang.annotation.ElementType");
   1.516 +        systemType = enterClass("java.lang.System");
   1.517 +        autoCloseableType = enterClass("java.lang.AutoCloseable");
   1.518 +        autoCloseableClose = new MethodSymbol(PUBLIC,
   1.519 +                             names.close,
   1.520 +                             new MethodType(List.<Type>nil(), voidType,
   1.521 +                                            List.of(exceptionType), methodClass),
   1.522 +                             autoCloseableType.tsym);
   1.523 +        trustMeType = enterClass("java.lang.SafeVarargs");
   1.524 +        nativeHeaderType = enterClass("java.lang.annotation.Native");
   1.525 +        lambdaMetafactory = enterClass("java.lang.invoke.LambdaMetafactory");
   1.526 +        functionalInterfaceType = enterClass("java.lang.FunctionalInterface");
   1.527 +
   1.528 +        synthesizeEmptyInterfaceIfMissing(autoCloseableType);
   1.529 +        synthesizeEmptyInterfaceIfMissing(cloneableType);
   1.530 +        synthesizeEmptyInterfaceIfMissing(serializableType);
   1.531 +        synthesizeEmptyInterfaceIfMissing(lambdaMetafactory);
   1.532 +        synthesizeEmptyInterfaceIfMissing(serializedLambdaType);
   1.533 +        synthesizeBoxTypeIfMissing(doubleType);
   1.534 +        synthesizeBoxTypeIfMissing(floatType);
   1.535 +        synthesizeBoxTypeIfMissing(voidType);
   1.536 +
   1.537 +        // Enter a synthetic class that is used to mark internal
   1.538 +        // proprietary classes in ct.sym.  This class does not have a
   1.539 +        // class file.
   1.540 +        proprietaryType = enterSyntheticAnnotation("sun.Proprietary+Annotation");
   1.541 +
   1.542 +        // Enter a synthetic class that is used to provide profile info for
   1.543 +        // classes in ct.sym.  This class does not have a class file.
   1.544 +        profileType = enterSyntheticAnnotation("jdk.Profile+Annotation");
   1.545 +        MethodSymbol m = new MethodSymbol(PUBLIC | ABSTRACT, names.value, intType, profileType.tsym);
   1.546 +        profileType.tsym.members().enter(m);
   1.547 +
   1.548 +        // Enter a class for arrays.
   1.549 +        // The class implements java.lang.Cloneable and java.io.Serializable.
   1.550 +        // It has a final length field and a clone method.
   1.551 +        ClassType arrayClassType = (ClassType)arrayClass.type;
   1.552 +        arrayClassType.supertype_field = objectType;
   1.553 +        arrayClassType.interfaces_field = List.of(cloneableType, serializableType);
   1.554 +        arrayClass.members_field = new Scope(arrayClass);
   1.555 +        lengthVar = new VarSymbol(
   1.556 +            PUBLIC | FINAL,
   1.557 +            names.length,
   1.558 +            intType,
   1.559 +            arrayClass);
   1.560 +        arrayClass.members().enter(lengthVar);
   1.561 +        arrayCloneMethod = new MethodSymbol(
   1.562 +            PUBLIC,
   1.563 +            names.clone,
   1.564 +            new MethodType(List.<Type>nil(), objectType,
   1.565 +                           List.<Type>nil(), methodClass),
   1.566 +            arrayClass);
   1.567 +        arrayClass.members().enter(arrayCloneMethod);
   1.568 +
   1.569 +        // Enter operators.
   1.570 +        /*  Internally we use +++, --- for unary +, - to reduce +, - operators
   1.571 +         *  overloading
   1.572 +         */
   1.573 +        enterUnop("+++", doubleType, doubleType, nop);
   1.574 +        enterUnop("+++", floatType, floatType, nop);
   1.575 +        enterUnop("+++", longType, longType, nop);
   1.576 +        enterUnop("+++", intType, intType, nop);
   1.577 +
   1.578 +        enterUnop("---", doubleType, doubleType, dneg);
   1.579 +        enterUnop("---", floatType, floatType, fneg);
   1.580 +        enterUnop("---", longType, longType, lneg);
   1.581 +        enterUnop("---", intType, intType, ineg);
   1.582 +
   1.583 +        enterUnop("~", longType, longType, lxor);
   1.584 +        enterUnop("~", intType, intType, ixor);
   1.585 +
   1.586 +        enterUnop("++", doubleType, doubleType, dadd);
   1.587 +        enterUnop("++", floatType, floatType, fadd);
   1.588 +        enterUnop("++", longType, longType, ladd);
   1.589 +        enterUnop("++", intType, intType, iadd);
   1.590 +        enterUnop("++", charType, charType, iadd);
   1.591 +        enterUnop("++", shortType, shortType, iadd);
   1.592 +        enterUnop("++", byteType, byteType, iadd);
   1.593 +
   1.594 +        enterUnop("--", doubleType, doubleType, dsub);
   1.595 +        enterUnop("--", floatType, floatType, fsub);
   1.596 +        enterUnop("--", longType, longType, lsub);
   1.597 +        enterUnop("--", intType, intType, isub);
   1.598 +        enterUnop("--", charType, charType, isub);
   1.599 +        enterUnop("--", shortType, shortType, isub);
   1.600 +        enterUnop("--", byteType, byteType, isub);
   1.601 +
   1.602 +        enterUnop("!", booleanType, booleanType, bool_not);
   1.603 +        nullcheck = enterUnop("<*nullchk*>", objectType, objectType, nullchk);
   1.604 +
   1.605 +        // string concatenation
   1.606 +        enterBinop("+", stringType, objectType, stringType, string_add);
   1.607 +        enterBinop("+", objectType, stringType, stringType, string_add);
   1.608 +        enterBinop("+", stringType, stringType, stringType, string_add);
   1.609 +        enterBinop("+", stringType, intType, stringType, string_add);
   1.610 +        enterBinop("+", stringType, longType, stringType, string_add);
   1.611 +        enterBinop("+", stringType, floatType, stringType, string_add);
   1.612 +        enterBinop("+", stringType, doubleType, stringType, string_add);
   1.613 +        enterBinop("+", stringType, booleanType, stringType, string_add);
   1.614 +        enterBinop("+", stringType, botType, stringType, string_add);
   1.615 +        enterBinop("+", intType, stringType, stringType, string_add);
   1.616 +        enterBinop("+", longType, stringType, stringType, string_add);
   1.617 +        enterBinop("+", floatType, stringType, stringType, string_add);
   1.618 +        enterBinop("+", doubleType, stringType, stringType, string_add);
   1.619 +        enterBinop("+", booleanType, stringType, stringType, string_add);
   1.620 +        enterBinop("+", botType, stringType, stringType, string_add);
   1.621 +
   1.622 +        // these errors would otherwise be matched as string concatenation
   1.623 +        enterBinop("+", botType, botType, botType, error);
   1.624 +        enterBinop("+", botType, intType, botType, error);
   1.625 +        enterBinop("+", botType, longType, botType, error);
   1.626 +        enterBinop("+", botType, floatType, botType, error);
   1.627 +        enterBinop("+", botType, doubleType, botType, error);
   1.628 +        enterBinop("+", botType, booleanType, botType, error);
   1.629 +        enterBinop("+", botType, objectType, botType, error);
   1.630 +        enterBinop("+", intType, botType, botType, error);
   1.631 +        enterBinop("+", longType, botType, botType, error);
   1.632 +        enterBinop("+", floatType, botType, botType, error);
   1.633 +        enterBinop("+", doubleType, botType, botType, error);
   1.634 +        enterBinop("+", booleanType, botType, botType, error);
   1.635 +        enterBinop("+", objectType, botType, botType, error);
   1.636 +
   1.637 +        enterBinop("+", doubleType, doubleType, doubleType, dadd);
   1.638 +        enterBinop("+", floatType, floatType, floatType, fadd);
   1.639 +        enterBinop("+", longType, longType, longType, ladd);
   1.640 +        enterBinop("+", intType, intType, intType, iadd);
   1.641 +
   1.642 +        enterBinop("-", doubleType, doubleType, doubleType, dsub);
   1.643 +        enterBinop("-", floatType, floatType, floatType, fsub);
   1.644 +        enterBinop("-", longType, longType, longType, lsub);
   1.645 +        enterBinop("-", intType, intType, intType, isub);
   1.646 +
   1.647 +        enterBinop("*", doubleType, doubleType, doubleType, dmul);
   1.648 +        enterBinop("*", floatType, floatType, floatType, fmul);
   1.649 +        enterBinop("*", longType, longType, longType, lmul);
   1.650 +        enterBinop("*", intType, intType, intType, imul);
   1.651 +
   1.652 +        enterBinop("/", doubleType, doubleType, doubleType, ddiv);
   1.653 +        enterBinop("/", floatType, floatType, floatType, fdiv);
   1.654 +        enterBinop("/", longType, longType, longType, ldiv);
   1.655 +        enterBinop("/", intType, intType, intType, idiv);
   1.656 +
   1.657 +        enterBinop("%", doubleType, doubleType, doubleType, dmod);
   1.658 +        enterBinop("%", floatType, floatType, floatType, fmod);
   1.659 +        enterBinop("%", longType, longType, longType, lmod);
   1.660 +        enterBinop("%", intType, intType, intType, imod);
   1.661 +
   1.662 +        enterBinop("&", booleanType, booleanType, booleanType, iand);
   1.663 +        enterBinop("&", longType, longType, longType, land);
   1.664 +        enterBinop("&", intType, intType, intType, iand);
   1.665 +
   1.666 +        enterBinop("|", booleanType, booleanType, booleanType, ior);
   1.667 +        enterBinop("|", longType, longType, longType, lor);
   1.668 +        enterBinop("|", intType, intType, intType, ior);
   1.669 +
   1.670 +        enterBinop("^", booleanType, booleanType, booleanType, ixor);
   1.671 +        enterBinop("^", longType, longType, longType, lxor);
   1.672 +        enterBinop("^", intType, intType, intType, ixor);
   1.673 +
   1.674 +        enterBinop("<<", longType, longType, longType, lshll);
   1.675 +        enterBinop("<<", intType, longType, intType, ishll);
   1.676 +        enterBinop("<<", longType, intType, longType, lshl);
   1.677 +        enterBinop("<<", intType, intType, intType, ishl);
   1.678 +
   1.679 +        enterBinop(">>", longType, longType, longType, lshrl);
   1.680 +        enterBinop(">>", intType, longType, intType, ishrl);
   1.681 +        enterBinop(">>", longType, intType, longType, lshr);
   1.682 +        enterBinop(">>", intType, intType, intType, ishr);
   1.683 +
   1.684 +        enterBinop(">>>", longType, longType, longType, lushrl);
   1.685 +        enterBinop(">>>", intType, longType, intType, iushrl);
   1.686 +        enterBinop(">>>", longType, intType, longType, lushr);
   1.687 +        enterBinop(">>>", intType, intType, intType, iushr);
   1.688 +
   1.689 +        enterBinop("<", doubleType, doubleType, booleanType, dcmpg, iflt);
   1.690 +        enterBinop("<", floatType, floatType, booleanType, fcmpg, iflt);
   1.691 +        enterBinop("<", longType, longType, booleanType, lcmp, iflt);
   1.692 +        enterBinop("<", intType, intType, booleanType, if_icmplt);
   1.693 +
   1.694 +        enterBinop(">", doubleType, doubleType, booleanType, dcmpl, ifgt);
   1.695 +        enterBinop(">", floatType, floatType, booleanType, fcmpl, ifgt);
   1.696 +        enterBinop(">", longType, longType, booleanType, lcmp, ifgt);
   1.697 +        enterBinop(">", intType, intType, booleanType, if_icmpgt);
   1.698 +
   1.699 +        enterBinop("<=", doubleType, doubleType, booleanType, dcmpg, ifle);
   1.700 +        enterBinop("<=", floatType, floatType, booleanType, fcmpg, ifle);
   1.701 +        enterBinop("<=", longType, longType, booleanType, lcmp, ifle);
   1.702 +        enterBinop("<=", intType, intType, booleanType, if_icmple);
   1.703 +
   1.704 +        enterBinop(">=", doubleType, doubleType, booleanType, dcmpl, ifge);
   1.705 +        enterBinop(">=", floatType, floatType, booleanType, fcmpl, ifge);
   1.706 +        enterBinop(">=", longType, longType, booleanType, lcmp, ifge);
   1.707 +        enterBinop(">=", intType, intType, booleanType, if_icmpge);
   1.708 +
   1.709 +        enterBinop("==", objectType, objectType, booleanType, if_acmpeq);
   1.710 +        enterBinop("==", booleanType, booleanType, booleanType, if_icmpeq);
   1.711 +        enterBinop("==", doubleType, doubleType, booleanType, dcmpl, ifeq);
   1.712 +        enterBinop("==", floatType, floatType, booleanType, fcmpl, ifeq);
   1.713 +        enterBinop("==", longType, longType, booleanType, lcmp, ifeq);
   1.714 +        enterBinop("==", intType, intType, booleanType, if_icmpeq);
   1.715 +
   1.716 +        enterBinop("!=", objectType, objectType, booleanType, if_acmpne);
   1.717 +        enterBinop("!=", booleanType, booleanType, booleanType, if_icmpne);
   1.718 +        enterBinop("!=", doubleType, doubleType, booleanType, dcmpl, ifne);
   1.719 +        enterBinop("!=", floatType, floatType, booleanType, fcmpl, ifne);
   1.720 +        enterBinop("!=", longType, longType, booleanType, lcmp, ifne);
   1.721 +        enterBinop("!=", intType, intType, booleanType, if_icmpne);
   1.722 +
   1.723 +        enterBinop("&&", booleanType, booleanType, booleanType, bool_and);
   1.724 +        enterBinop("||", booleanType, booleanType, booleanType, bool_or);
   1.725 +    }
   1.726 +}

mercurial