aoqi@0: /* aoqi@0: * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.tools.javac.code; aoqi@0: aoqi@0: import java.util.*; aoqi@0: aoqi@0: import javax.lang.model.element.ElementVisitor; aoqi@0: aoqi@0: import com.sun.tools.javac.code.Symbol.*; aoqi@0: import com.sun.tools.javac.code.Type.*; aoqi@0: import com.sun.tools.javac.jvm.*; aoqi@0: import com.sun.tools.javac.util.*; aoqi@0: import com.sun.tools.javac.util.List; aoqi@0: import static com.sun.tools.javac.code.Flags.*; aoqi@0: import static com.sun.tools.javac.jvm.ByteCodes.*; aoqi@0: import static com.sun.tools.javac.code.TypeTag.*; aoqi@0: aoqi@0: /** A class that defines all predefined constants and operators aoqi@0: * as well as special classes such as java.lang.Object, which need aoqi@0: * to be known to the compiler. All symbols are held in instance aoqi@0: * fields. This makes it possible to work in multiple concurrent aoqi@0: * projects, which might use different class files for library classes. aoqi@0: * aoqi@0: *

This is NOT part of any supported API. aoqi@0: * If you write code that depends on this, you do so at your own risk. aoqi@0: * This code and its internal interfaces are subject to change or aoqi@0: * deletion without notice. aoqi@0: */ aoqi@0: public class Symtab { aoqi@0: /** The context key for the symbol table. */ aoqi@0: protected static final Context.Key symtabKey = aoqi@0: new Context.Key(); aoqi@0: aoqi@0: /** Get the symbol table instance. */ aoqi@0: public static Symtab instance(Context context) { aoqi@0: Symtab instance = context.get(symtabKey); aoqi@0: if (instance == null) aoqi@0: instance = new Symtab(context); aoqi@0: return instance; aoqi@0: } aoqi@0: aoqi@0: /** Builtin types. aoqi@0: */ aoqi@0: public final JCPrimitiveType byteType = new JCPrimitiveType(BYTE, null); aoqi@0: public final JCPrimitiveType charType = new JCPrimitiveType(CHAR, null); aoqi@0: public final JCPrimitiveType shortType = new JCPrimitiveType(SHORT, null); aoqi@0: public final JCPrimitiveType intType = new JCPrimitiveType(INT, null); aoqi@0: public final JCPrimitiveType longType = new JCPrimitiveType(LONG, null); aoqi@0: public final JCPrimitiveType floatType = new JCPrimitiveType(FLOAT, null); aoqi@0: public final JCPrimitiveType doubleType = new JCPrimitiveType(DOUBLE, null); aoqi@0: public final JCPrimitiveType booleanType = new JCPrimitiveType(BOOLEAN, null); aoqi@0: public final Type botType = new BottomType(); aoqi@0: public final JCVoidType voidType = new JCVoidType(); aoqi@0: aoqi@0: private final Names names; aoqi@0: private final ClassReader reader; aoqi@0: private final Target target; aoqi@0: aoqi@0: /** A symbol for the root package. aoqi@0: */ aoqi@0: public final PackageSymbol rootPackage; aoqi@0: aoqi@0: /** A symbol for the unnamed package. aoqi@0: */ aoqi@0: public final PackageSymbol unnamedPackage; aoqi@0: aoqi@0: /** A symbol that stands for a missing symbol. aoqi@0: */ aoqi@0: public final TypeSymbol noSymbol; aoqi@0: aoqi@0: /** The error symbol. aoqi@0: */ aoqi@0: public final ClassSymbol errSymbol; aoqi@0: aoqi@0: /** The unknown symbol. aoqi@0: */ aoqi@0: public final ClassSymbol unknownSymbol; aoqi@0: aoqi@0: /** A value for the errType, with a originalType of noType */ aoqi@0: public final Type errType; aoqi@0: aoqi@0: /** A value for the unknown type. */ aoqi@0: public final Type unknownType; aoqi@0: aoqi@0: /** The builtin type of all arrays. */ aoqi@0: public final ClassSymbol arrayClass; aoqi@0: public final MethodSymbol arrayCloneMethod; aoqi@0: aoqi@0: /** VGJ: The (singleton) type of all bound types. */ aoqi@0: public final ClassSymbol boundClass; aoqi@0: aoqi@0: /** The builtin type of all methods. */ aoqi@0: public final ClassSymbol methodClass; aoqi@0: aoqi@0: /** Predefined types. aoqi@0: */ aoqi@0: public final Type objectType; aoqi@0: public final Type classType; aoqi@0: public final Type classLoaderType; aoqi@0: public final Type stringType; aoqi@0: public final Type stringBufferType; aoqi@0: public final Type stringBuilderType; aoqi@0: public final Type cloneableType; aoqi@0: public final Type serializableType; aoqi@0: public final Type serializedLambdaType; aoqi@0: public final Type methodHandleType; aoqi@0: public final Type methodHandleLookupType; aoqi@0: public final Type methodTypeType; aoqi@0: public final Type nativeHeaderType; aoqi@0: public final Type throwableType; aoqi@0: public final Type errorType; aoqi@0: public final Type interruptedExceptionType; aoqi@0: public final Type illegalArgumentExceptionType; aoqi@0: public final Type exceptionType; aoqi@0: public final Type runtimeExceptionType; aoqi@0: public final Type classNotFoundExceptionType; aoqi@0: public final Type noClassDefFoundErrorType; aoqi@0: public final Type noSuchFieldErrorType; aoqi@0: public final Type assertionErrorType; aoqi@0: public final Type cloneNotSupportedExceptionType; aoqi@0: public final Type annotationType; aoqi@0: public final TypeSymbol enumSym; aoqi@0: public final Type listType; aoqi@0: public final Type collectionsType; aoqi@0: public final Type comparableType; aoqi@0: public final Type comparatorType; aoqi@0: public final Type arraysType; aoqi@0: public final Type iterableType; aoqi@0: public final Type iteratorType; aoqi@0: public final Type annotationTargetType; aoqi@0: public final Type overrideType; aoqi@0: public final Type retentionType; aoqi@0: public final Type deprecatedType; aoqi@0: public final Type suppressWarningsType; aoqi@0: public final Type inheritedType; aoqi@0: public final Type profileType; aoqi@0: public final Type proprietaryType; aoqi@0: public final Type systemType; aoqi@0: public final Type autoCloseableType; aoqi@0: public final Type trustMeType; aoqi@0: public final Type lambdaMetafactory; aoqi@0: public final Type repeatableType; aoqi@0: public final Type documentedType; aoqi@0: public final Type elementTypeType; aoqi@0: public final Type functionalInterfaceType; aoqi@0: aoqi@0: /** The symbol representing the length field of an array. aoqi@0: */ aoqi@0: public final VarSymbol lengthVar; aoqi@0: aoqi@0: /** The null check operator. */ aoqi@0: public final OperatorSymbol nullcheck; aoqi@0: aoqi@0: /** The symbol representing the final finalize method on enums */ aoqi@0: public final MethodSymbol enumFinalFinalize; aoqi@0: aoqi@0: /** The symbol representing the close method on TWR AutoCloseable type */ aoqi@0: public final MethodSymbol autoCloseableClose; aoqi@0: aoqi@0: /** The predefined type that belongs to a tag. aoqi@0: */ aoqi@0: public final Type[] typeOfTag = new Type[TypeTag.getTypeTagCount()]; aoqi@0: aoqi@0: /** The name of the class that belongs to a basix type tag. aoqi@0: */ aoqi@0: public final Name[] boxedName = new Name[TypeTag.getTypeTagCount()]; aoqi@0: aoqi@0: /** A set containing all operator names. aoqi@0: */ aoqi@0: public final Set operatorNames = new HashSet(); aoqi@0: aoqi@0: /** A hashtable containing the encountered top-level and member classes, aoqi@0: * indexed by flat names. The table does not contain local classes. aoqi@0: * It should be updated from the outside to reflect classes defined aoqi@0: * by compiled source files. aoqi@0: */ aoqi@0: public final Map classes = new HashMap(); aoqi@0: aoqi@0: /** A hashtable containing the encountered packages. aoqi@0: * the table should be updated from outside to reflect packages defined aoqi@0: * by compiled source files. aoqi@0: */ aoqi@0: public final Map packages = new HashMap(); aoqi@0: aoqi@0: public void initType(Type type, ClassSymbol c) { aoqi@0: type.tsym = c; aoqi@0: typeOfTag[type.getTag().ordinal()] = type; aoqi@0: } aoqi@0: aoqi@0: public void initType(Type type, String name) { aoqi@0: initType( aoqi@0: type, aoqi@0: new ClassSymbol( aoqi@0: PUBLIC, names.fromString(name), type, rootPackage)); aoqi@0: } aoqi@0: aoqi@0: public void initType(Type type, String name, String bname) { aoqi@0: initType(type, name); aoqi@0: boxedName[type.getTag().ordinal()] = names.fromString("java.lang." + bname); aoqi@0: } aoqi@0: aoqi@0: /** The class symbol that owns all predefined symbols. aoqi@0: */ aoqi@0: public final ClassSymbol predefClass; aoqi@0: aoqi@0: /** Enter a constant into symbol table. aoqi@0: * @param name The constant's name. aoqi@0: * @param type The constant's type. aoqi@0: */ aoqi@0: private VarSymbol enterConstant(String name, Type type) { aoqi@0: VarSymbol c = new VarSymbol( aoqi@0: PUBLIC | STATIC | FINAL, aoqi@0: names.fromString(name), aoqi@0: type, aoqi@0: predefClass); aoqi@0: c.setData(type.constValue()); aoqi@0: predefClass.members().enter(c); aoqi@0: return c; aoqi@0: } aoqi@0: aoqi@0: /** Enter a binary operation into symbol table. aoqi@0: * @param name The name of the operator. aoqi@0: * @param left The type of the left operand. aoqi@0: * @param right The type of the left operand. aoqi@0: * @param res The operation's result type. aoqi@0: * @param opcode The operation's bytecode instruction. aoqi@0: */ aoqi@0: private void enterBinop(String name, aoqi@0: Type left, Type right, Type res, aoqi@0: int opcode) { aoqi@0: predefClass.members().enter( aoqi@0: new OperatorSymbol( aoqi@0: makeOperatorName(name), aoqi@0: new MethodType(List.of(left, right), res, aoqi@0: List.nil(), methodClass), aoqi@0: opcode, aoqi@0: predefClass)); aoqi@0: } aoqi@0: aoqi@0: /** Enter a binary operation, as above but with two opcodes, aoqi@0: * which get encoded as aoqi@0: * {@code (opcode1 << ByteCodeTags.preShift) + opcode2 }. aoqi@0: * @param opcode1 First opcode. aoqi@0: * @param opcode2 Second opcode. aoqi@0: */ aoqi@0: private void enterBinop(String name, aoqi@0: Type left, Type right, Type res, aoqi@0: int opcode1, int opcode2) { aoqi@0: enterBinop( aoqi@0: name, left, right, res, (opcode1 << ByteCodes.preShift) | opcode2); aoqi@0: } aoqi@0: aoqi@0: /** Enter a unary operation into symbol table. aoqi@0: * @param name The name of the operator. aoqi@0: * @param arg The type of the operand. aoqi@0: * @param res The operation's result type. aoqi@0: * @param opcode The operation's bytecode instruction. aoqi@0: */ aoqi@0: private OperatorSymbol enterUnop(String name, aoqi@0: Type arg, aoqi@0: Type res, aoqi@0: int opcode) { aoqi@0: OperatorSymbol sym = aoqi@0: new OperatorSymbol(makeOperatorName(name), aoqi@0: new MethodType(List.of(arg), aoqi@0: res, aoqi@0: List.nil(), aoqi@0: methodClass), aoqi@0: opcode, aoqi@0: predefClass); aoqi@0: predefClass.members().enter(sym); aoqi@0: return sym; aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Create a new operator name from corresponding String representation aoqi@0: * and add the name to the set of known operator names. aoqi@0: */ aoqi@0: private Name makeOperatorName(String name) { aoqi@0: Name opName = names.fromString(name); aoqi@0: operatorNames.add(opName); aoqi@0: return opName; aoqi@0: } aoqi@0: aoqi@0: /** Enter a class into symbol table. aoqi@0: * @param s The name of the class. aoqi@0: */ aoqi@0: private Type enterClass(String s) { aoqi@0: return reader.enterClass(names.fromString(s)).type; aoqi@0: } aoqi@0: aoqi@0: public void synthesizeEmptyInterfaceIfMissing(final Type type) { aoqi@0: final Completer completer = type.tsym.completer; aoqi@0: if (completer != null) { aoqi@0: type.tsym.completer = new Completer() { aoqi@0: public void complete(Symbol sym) throws CompletionFailure { aoqi@0: try { aoqi@0: completer.complete(sym); aoqi@0: } catch (CompletionFailure e) { aoqi@0: sym.flags_field |= (PUBLIC | INTERFACE); aoqi@0: ((ClassType) sym.type).supertype_field = objectType; aoqi@0: } aoqi@0: } aoqi@0: }; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public void synthesizeBoxTypeIfMissing(final Type type) { aoqi@0: ClassSymbol sym = reader.enterClass(boxedName[type.getTag().ordinal()]); aoqi@0: final Completer completer = sym.completer; aoqi@0: if (completer != null) { aoqi@0: sym.completer = new Completer() { aoqi@0: public void complete(Symbol sym) throws CompletionFailure { aoqi@0: try { aoqi@0: completer.complete(sym); aoqi@0: } catch (CompletionFailure e) { aoqi@0: sym.flags_field |= PUBLIC; aoqi@0: ((ClassType) sym.type).supertype_field = objectType; aoqi@0: Name n = target.boxWithConstructors() ? names.init : names.valueOf; aoqi@0: MethodSymbol boxMethod = aoqi@0: new MethodSymbol(PUBLIC | STATIC, aoqi@0: n, aoqi@0: new MethodType(List.of(type), sym.type, aoqi@0: List.nil(), methodClass), aoqi@0: sym); aoqi@0: sym.members().enter(boxMethod); aoqi@0: MethodSymbol unboxMethod = aoqi@0: new MethodSymbol(PUBLIC, aoqi@0: type.tsym.name.append(names.Value), // x.intValue() aoqi@0: new MethodType(List.nil(), type, aoqi@0: List.nil(), methodClass), aoqi@0: sym); aoqi@0: sym.members().enter(unboxMethod); aoqi@0: } aoqi@0: } aoqi@0: }; aoqi@0: } aoqi@0: aoqi@0: } aoqi@0: aoqi@0: // Enter a synthetic class that is used to mark classes in ct.sym. aoqi@0: // This class does not have a class file. aoqi@0: private Type enterSyntheticAnnotation(String name) { aoqi@0: ClassType type = (ClassType)enterClass(name); aoqi@0: ClassSymbol sym = (ClassSymbol)type.tsym; aoqi@0: sym.completer = null; aoqi@0: sym.flags_field = PUBLIC|ACYCLIC|ANNOTATION|INTERFACE; aoqi@0: sym.erasure_field = type; aoqi@0: sym.members_field = new Scope(sym); aoqi@0: type.typarams_field = List.nil(); aoqi@0: type.allparams_field = List.nil(); aoqi@0: type.supertype_field = annotationType; aoqi@0: type.interfaces_field = List.nil(); aoqi@0: return type; aoqi@0: } aoqi@0: aoqi@0: /** Constructor; enters all predefined identifiers and operators aoqi@0: * into symbol table. aoqi@0: */ aoqi@0: protected Symtab(Context context) throws CompletionFailure { aoqi@0: context.put(symtabKey, this); aoqi@0: aoqi@0: names = Names.instance(context); aoqi@0: target = Target.instance(context); aoqi@0: aoqi@0: // Create the unknown type aoqi@0: unknownType = new UnknownType(); aoqi@0: aoqi@0: // create the basic builtin symbols aoqi@0: rootPackage = new PackageSymbol(names.empty, null); aoqi@0: final JavacMessages messages = JavacMessages.instance(context); aoqi@0: unnamedPackage = new PackageSymbol(names.empty, rootPackage) { aoqi@0: public String toString() { aoqi@0: return messages.getLocalizedString("compiler.misc.unnamed.package"); aoqi@0: } aoqi@0: }; aoqi@0: noSymbol = new TypeSymbol(Kinds.NIL, 0, names.empty, Type.noType, rootPackage) { aoqi@0: public R accept(ElementVisitor v, P p) { aoqi@0: return v.visitUnknown(this, p); aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: // create the error symbols aoqi@0: errSymbol = new ClassSymbol(PUBLIC|STATIC|ACYCLIC, names.any, null, rootPackage); aoqi@0: errType = new ErrorType(errSymbol, Type.noType); aoqi@0: aoqi@0: unknownSymbol = new ClassSymbol(PUBLIC|STATIC|ACYCLIC, names.fromString(""), null, rootPackage); aoqi@0: unknownSymbol.members_field = new Scope.ErrorScope(unknownSymbol); aoqi@0: unknownSymbol.type = unknownType; aoqi@0: aoqi@0: // initialize builtin types aoqi@0: initType(byteType, "byte", "Byte"); aoqi@0: initType(shortType, "short", "Short"); aoqi@0: initType(charType, "char", "Character"); aoqi@0: initType(intType, "int", "Integer"); aoqi@0: initType(longType, "long", "Long"); aoqi@0: initType(floatType, "float", "Float"); aoqi@0: initType(doubleType, "double", "Double"); aoqi@0: initType(booleanType, "boolean", "Boolean"); aoqi@0: initType(voidType, "void", "Void"); aoqi@0: initType(botType, ""); aoqi@0: initType(errType, errSymbol); aoqi@0: initType(unknownType, unknownSymbol); aoqi@0: aoqi@0: // the builtin class of all arrays aoqi@0: arrayClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Array, noSymbol); aoqi@0: aoqi@0: // VGJ aoqi@0: boundClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Bound, noSymbol); aoqi@0: boundClass.members_field = new Scope.ErrorScope(boundClass); aoqi@0: aoqi@0: // the builtin class of all methods aoqi@0: methodClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Method, noSymbol); aoqi@0: methodClass.members_field = new Scope.ErrorScope(boundClass); aoqi@0: aoqi@0: // Create class to hold all predefined constants and operations. aoqi@0: predefClass = new ClassSymbol(PUBLIC|ACYCLIC, names.empty, rootPackage); aoqi@0: Scope scope = new Scope(predefClass); aoqi@0: predefClass.members_field = scope; aoqi@0: aoqi@0: // Enter symbols for basic types. aoqi@0: scope.enter(byteType.tsym); aoqi@0: scope.enter(shortType.tsym); aoqi@0: scope.enter(charType.tsym); aoqi@0: scope.enter(intType.tsym); aoqi@0: scope.enter(longType.tsym); aoqi@0: scope.enter(floatType.tsym); aoqi@0: scope.enter(doubleType.tsym); aoqi@0: scope.enter(booleanType.tsym); aoqi@0: scope.enter(errType.tsym); aoqi@0: aoqi@0: // Enter symbol for the errSymbol aoqi@0: scope.enter(errSymbol); aoqi@0: aoqi@0: classes.put(predefClass.fullname, predefClass); aoqi@0: aoqi@0: reader = ClassReader.instance(context); aoqi@0: reader.init(this); aoqi@0: aoqi@0: // Enter predefined classes. aoqi@0: objectType = enterClass("java.lang.Object"); aoqi@0: classType = enterClass("java.lang.Class"); aoqi@0: stringType = enterClass("java.lang.String"); aoqi@0: stringBufferType = enterClass("java.lang.StringBuffer"); aoqi@0: stringBuilderType = enterClass("java.lang.StringBuilder"); aoqi@0: cloneableType = enterClass("java.lang.Cloneable"); aoqi@0: throwableType = enterClass("java.lang.Throwable"); aoqi@0: serializableType = enterClass("java.io.Serializable"); aoqi@0: serializedLambdaType = enterClass("java.lang.invoke.SerializedLambda"); aoqi@0: methodHandleType = enterClass("java.lang.invoke.MethodHandle"); aoqi@0: methodHandleLookupType = enterClass("java.lang.invoke.MethodHandles$Lookup"); aoqi@0: methodTypeType = enterClass("java.lang.invoke.MethodType"); aoqi@0: errorType = enterClass("java.lang.Error"); aoqi@0: illegalArgumentExceptionType = enterClass("java.lang.IllegalArgumentException"); aoqi@0: interruptedExceptionType = enterClass("java.lang.InterruptedException"); aoqi@0: exceptionType = enterClass("java.lang.Exception"); aoqi@0: runtimeExceptionType = enterClass("java.lang.RuntimeException"); aoqi@0: classNotFoundExceptionType = enterClass("java.lang.ClassNotFoundException"); aoqi@0: noClassDefFoundErrorType = enterClass("java.lang.NoClassDefFoundError"); aoqi@0: noSuchFieldErrorType = enterClass("java.lang.NoSuchFieldError"); aoqi@0: assertionErrorType = enterClass("java.lang.AssertionError"); aoqi@0: cloneNotSupportedExceptionType = enterClass("java.lang.CloneNotSupportedException"); aoqi@0: annotationType = enterClass("java.lang.annotation.Annotation"); aoqi@0: classLoaderType = enterClass("java.lang.ClassLoader"); aoqi@0: enumSym = reader.enterClass(names.java_lang_Enum); aoqi@0: enumFinalFinalize = aoqi@0: new MethodSymbol(PROTECTED|FINAL|HYPOTHETICAL, aoqi@0: names.finalize, aoqi@0: new MethodType(List.nil(), voidType, aoqi@0: List.nil(), methodClass), aoqi@0: enumSym); aoqi@0: listType = enterClass("java.util.List"); aoqi@0: collectionsType = enterClass("java.util.Collections"); aoqi@0: comparableType = enterClass("java.lang.Comparable"); aoqi@0: comparatorType = enterClass("java.util.Comparator"); aoqi@0: arraysType = enterClass("java.util.Arrays"); aoqi@0: iterableType = target.hasIterable() aoqi@0: ? enterClass("java.lang.Iterable") aoqi@0: : enterClass("java.util.Collection"); aoqi@0: iteratorType = enterClass("java.util.Iterator"); aoqi@0: annotationTargetType = enterClass("java.lang.annotation.Target"); aoqi@0: overrideType = enterClass("java.lang.Override"); aoqi@0: retentionType = enterClass("java.lang.annotation.Retention"); aoqi@0: deprecatedType = enterClass("java.lang.Deprecated"); aoqi@0: suppressWarningsType = enterClass("java.lang.SuppressWarnings"); aoqi@0: inheritedType = enterClass("java.lang.annotation.Inherited"); aoqi@0: repeatableType = enterClass("java.lang.annotation.Repeatable"); aoqi@0: documentedType = enterClass("java.lang.annotation.Documented"); aoqi@0: elementTypeType = enterClass("java.lang.annotation.ElementType"); aoqi@0: systemType = enterClass("java.lang.System"); aoqi@0: autoCloseableType = enterClass("java.lang.AutoCloseable"); aoqi@0: autoCloseableClose = new MethodSymbol(PUBLIC, aoqi@0: names.close, aoqi@0: new MethodType(List.nil(), voidType, aoqi@0: List.of(exceptionType), methodClass), aoqi@0: autoCloseableType.tsym); aoqi@0: trustMeType = enterClass("java.lang.SafeVarargs"); aoqi@0: nativeHeaderType = enterClass("java.lang.annotation.Native"); aoqi@0: lambdaMetafactory = enterClass("java.lang.invoke.LambdaMetafactory"); aoqi@0: functionalInterfaceType = enterClass("java.lang.FunctionalInterface"); aoqi@0: aoqi@0: synthesizeEmptyInterfaceIfMissing(autoCloseableType); aoqi@0: synthesizeEmptyInterfaceIfMissing(cloneableType); aoqi@0: synthesizeEmptyInterfaceIfMissing(serializableType); aoqi@0: synthesizeEmptyInterfaceIfMissing(lambdaMetafactory); aoqi@0: synthesizeEmptyInterfaceIfMissing(serializedLambdaType); aoqi@0: synthesizeBoxTypeIfMissing(doubleType); aoqi@0: synthesizeBoxTypeIfMissing(floatType); aoqi@0: synthesizeBoxTypeIfMissing(voidType); aoqi@0: aoqi@0: // Enter a synthetic class that is used to mark internal aoqi@0: // proprietary classes in ct.sym. This class does not have a aoqi@0: // class file. aoqi@0: proprietaryType = enterSyntheticAnnotation("sun.Proprietary+Annotation"); aoqi@0: aoqi@0: // Enter a synthetic class that is used to provide profile info for aoqi@0: // classes in ct.sym. This class does not have a class file. aoqi@0: profileType = enterSyntheticAnnotation("jdk.Profile+Annotation"); aoqi@0: MethodSymbol m = new MethodSymbol(PUBLIC | ABSTRACT, names.value, intType, profileType.tsym); aoqi@0: profileType.tsym.members().enter(m); aoqi@0: aoqi@0: // Enter a class for arrays. aoqi@0: // The class implements java.lang.Cloneable and java.io.Serializable. aoqi@0: // It has a final length field and a clone method. aoqi@0: ClassType arrayClassType = (ClassType)arrayClass.type; aoqi@0: arrayClassType.supertype_field = objectType; aoqi@0: arrayClassType.interfaces_field = List.of(cloneableType, serializableType); aoqi@0: arrayClass.members_field = new Scope(arrayClass); aoqi@0: lengthVar = new VarSymbol( aoqi@0: PUBLIC | FINAL, aoqi@0: names.length, aoqi@0: intType, aoqi@0: arrayClass); aoqi@0: arrayClass.members().enter(lengthVar); aoqi@0: arrayCloneMethod = new MethodSymbol( aoqi@0: PUBLIC, aoqi@0: names.clone, aoqi@0: new MethodType(List.nil(), objectType, aoqi@0: List.nil(), methodClass), aoqi@0: arrayClass); aoqi@0: arrayClass.members().enter(arrayCloneMethod); aoqi@0: aoqi@0: // Enter operators. aoqi@0: /* Internally we use +++, --- for unary +, - to reduce +, - operators aoqi@0: * overloading aoqi@0: */ aoqi@0: enterUnop("+++", doubleType, doubleType, nop); aoqi@0: enterUnop("+++", floatType, floatType, nop); aoqi@0: enterUnop("+++", longType, longType, nop); aoqi@0: enterUnop("+++", intType, intType, nop); aoqi@0: aoqi@0: enterUnop("---", doubleType, doubleType, dneg); aoqi@0: enterUnop("---", floatType, floatType, fneg); aoqi@0: enterUnop("---", longType, longType, lneg); aoqi@0: enterUnop("---", intType, intType, ineg); aoqi@0: aoqi@0: enterUnop("~", longType, longType, lxor); aoqi@0: enterUnop("~", intType, intType, ixor); aoqi@0: aoqi@0: enterUnop("++", doubleType, doubleType, dadd); aoqi@0: enterUnop("++", floatType, floatType, fadd); aoqi@0: enterUnop("++", longType, longType, ladd); aoqi@0: enterUnop("++", intType, intType, iadd); aoqi@0: enterUnop("++", charType, charType, iadd); aoqi@0: enterUnop("++", shortType, shortType, iadd); aoqi@0: enterUnop("++", byteType, byteType, iadd); aoqi@0: aoqi@0: enterUnop("--", doubleType, doubleType, dsub); aoqi@0: enterUnop("--", floatType, floatType, fsub); aoqi@0: enterUnop("--", longType, longType, lsub); aoqi@0: enterUnop("--", intType, intType, isub); aoqi@0: enterUnop("--", charType, charType, isub); aoqi@0: enterUnop("--", shortType, shortType, isub); aoqi@0: enterUnop("--", byteType, byteType, isub); aoqi@0: aoqi@0: enterUnop("!", booleanType, booleanType, bool_not); aoqi@0: nullcheck = enterUnop("<*nullchk*>", objectType, objectType, nullchk); aoqi@0: aoqi@0: // string concatenation aoqi@0: enterBinop("+", stringType, objectType, stringType, string_add); aoqi@0: enterBinop("+", objectType, stringType, stringType, string_add); aoqi@0: enterBinop("+", stringType, stringType, stringType, string_add); aoqi@0: enterBinop("+", stringType, intType, stringType, string_add); aoqi@0: enterBinop("+", stringType, longType, stringType, string_add); aoqi@0: enterBinop("+", stringType, floatType, stringType, string_add); aoqi@0: enterBinop("+", stringType, doubleType, stringType, string_add); aoqi@0: enterBinop("+", stringType, booleanType, stringType, string_add); aoqi@0: enterBinop("+", stringType, botType, stringType, string_add); aoqi@0: enterBinop("+", intType, stringType, stringType, string_add); aoqi@0: enterBinop("+", longType, stringType, stringType, string_add); aoqi@0: enterBinop("+", floatType, stringType, stringType, string_add); aoqi@0: enterBinop("+", doubleType, stringType, stringType, string_add); aoqi@0: enterBinop("+", booleanType, stringType, stringType, string_add); aoqi@0: enterBinop("+", botType, stringType, stringType, string_add); aoqi@0: aoqi@0: // these errors would otherwise be matched as string concatenation aoqi@0: enterBinop("+", botType, botType, botType, error); aoqi@0: enterBinop("+", botType, intType, botType, error); aoqi@0: enterBinop("+", botType, longType, botType, error); aoqi@0: enterBinop("+", botType, floatType, botType, error); aoqi@0: enterBinop("+", botType, doubleType, botType, error); aoqi@0: enterBinop("+", botType, booleanType, botType, error); aoqi@0: enterBinop("+", botType, objectType, botType, error); aoqi@0: enterBinop("+", intType, botType, botType, error); aoqi@0: enterBinop("+", longType, botType, botType, error); aoqi@0: enterBinop("+", floatType, botType, botType, error); aoqi@0: enterBinop("+", doubleType, botType, botType, error); aoqi@0: enterBinop("+", booleanType, botType, botType, error); aoqi@0: enterBinop("+", objectType, botType, botType, error); aoqi@0: aoqi@0: enterBinop("+", doubleType, doubleType, doubleType, dadd); aoqi@0: enterBinop("+", floatType, floatType, floatType, fadd); aoqi@0: enterBinop("+", longType, longType, longType, ladd); aoqi@0: enterBinop("+", intType, intType, intType, iadd); aoqi@0: aoqi@0: enterBinop("-", doubleType, doubleType, doubleType, dsub); aoqi@0: enterBinop("-", floatType, floatType, floatType, fsub); aoqi@0: enterBinop("-", longType, longType, longType, lsub); aoqi@0: enterBinop("-", intType, intType, intType, isub); aoqi@0: aoqi@0: enterBinop("*", doubleType, doubleType, doubleType, dmul); aoqi@0: enterBinop("*", floatType, floatType, floatType, fmul); aoqi@0: enterBinop("*", longType, longType, longType, lmul); aoqi@0: enterBinop("*", intType, intType, intType, imul); aoqi@0: aoqi@0: enterBinop("/", doubleType, doubleType, doubleType, ddiv); aoqi@0: enterBinop("/", floatType, floatType, floatType, fdiv); aoqi@0: enterBinop("/", longType, longType, longType, ldiv); aoqi@0: enterBinop("/", intType, intType, intType, idiv); aoqi@0: aoqi@0: enterBinop("%", doubleType, doubleType, doubleType, dmod); aoqi@0: enterBinop("%", floatType, floatType, floatType, fmod); aoqi@0: enterBinop("%", longType, longType, longType, lmod); aoqi@0: enterBinop("%", intType, intType, intType, imod); aoqi@0: aoqi@0: enterBinop("&", booleanType, booleanType, booleanType, iand); aoqi@0: enterBinop("&", longType, longType, longType, land); aoqi@0: enterBinop("&", intType, intType, intType, iand); aoqi@0: aoqi@0: enterBinop("|", booleanType, booleanType, booleanType, ior); aoqi@0: enterBinop("|", longType, longType, longType, lor); aoqi@0: enterBinop("|", intType, intType, intType, ior); aoqi@0: aoqi@0: enterBinop("^", booleanType, booleanType, booleanType, ixor); aoqi@0: enterBinop("^", longType, longType, longType, lxor); aoqi@0: enterBinop("^", intType, intType, intType, ixor); aoqi@0: aoqi@0: enterBinop("<<", longType, longType, longType, lshll); aoqi@0: enterBinop("<<", intType, longType, intType, ishll); aoqi@0: enterBinop("<<", longType, intType, longType, lshl); aoqi@0: enterBinop("<<", intType, intType, intType, ishl); aoqi@0: aoqi@0: enterBinop(">>", longType, longType, longType, lshrl); aoqi@0: enterBinop(">>", intType, longType, intType, ishrl); aoqi@0: enterBinop(">>", longType, intType, longType, lshr); aoqi@0: enterBinop(">>", intType, intType, intType, ishr); aoqi@0: aoqi@0: enterBinop(">>>", longType, longType, longType, lushrl); aoqi@0: enterBinop(">>>", intType, longType, intType, iushrl); aoqi@0: enterBinop(">>>", longType, intType, longType, lushr); aoqi@0: enterBinop(">>>", intType, intType, intType, iushr); aoqi@0: aoqi@0: enterBinop("<", doubleType, doubleType, booleanType, dcmpg, iflt); aoqi@0: enterBinop("<", floatType, floatType, booleanType, fcmpg, iflt); aoqi@0: enterBinop("<", longType, longType, booleanType, lcmp, iflt); aoqi@0: enterBinop("<", intType, intType, booleanType, if_icmplt); aoqi@0: aoqi@0: enterBinop(">", doubleType, doubleType, booleanType, dcmpl, ifgt); aoqi@0: enterBinop(">", floatType, floatType, booleanType, fcmpl, ifgt); aoqi@0: enterBinop(">", longType, longType, booleanType, lcmp, ifgt); aoqi@0: enterBinop(">", intType, intType, booleanType, if_icmpgt); aoqi@0: aoqi@0: enterBinop("<=", doubleType, doubleType, booleanType, dcmpg, ifle); aoqi@0: enterBinop("<=", floatType, floatType, booleanType, fcmpg, ifle); aoqi@0: enterBinop("<=", longType, longType, booleanType, lcmp, ifle); aoqi@0: enterBinop("<=", intType, intType, booleanType, if_icmple); aoqi@0: aoqi@0: enterBinop(">=", doubleType, doubleType, booleanType, dcmpl, ifge); aoqi@0: enterBinop(">=", floatType, floatType, booleanType, fcmpl, ifge); aoqi@0: enterBinop(">=", longType, longType, booleanType, lcmp, ifge); aoqi@0: enterBinop(">=", intType, intType, booleanType, if_icmpge); aoqi@0: aoqi@0: enterBinop("==", objectType, objectType, booleanType, if_acmpeq); aoqi@0: enterBinop("==", booleanType, booleanType, booleanType, if_icmpeq); aoqi@0: enterBinop("==", doubleType, doubleType, booleanType, dcmpl, ifeq); aoqi@0: enterBinop("==", floatType, floatType, booleanType, fcmpl, ifeq); aoqi@0: enterBinop("==", longType, longType, booleanType, lcmp, ifeq); aoqi@0: enterBinop("==", intType, intType, booleanType, if_icmpeq); aoqi@0: aoqi@0: enterBinop("!=", objectType, objectType, booleanType, if_acmpne); aoqi@0: enterBinop("!=", booleanType, booleanType, booleanType, if_icmpne); aoqi@0: enterBinop("!=", doubleType, doubleType, booleanType, dcmpl, ifne); aoqi@0: enterBinop("!=", floatType, floatType, booleanType, fcmpl, ifne); aoqi@0: enterBinop("!=", longType, longType, booleanType, lcmp, ifne); aoqi@0: enterBinop("!=", intType, intType, booleanType, if_icmpne); aoqi@0: aoqi@0: enterBinop("&&", booleanType, booleanType, booleanType, bool_and); aoqi@0: enterBinop("||", booleanType, booleanType, booleanType, bool_or); aoqi@0: } aoqi@0: }