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

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.tools.javac.code;
aoqi@0 27
aoqi@0 28 import java.util.*;
aoqi@0 29
aoqi@0 30 import javax.lang.model.element.ElementVisitor;
aoqi@0 31
aoqi@0 32 import com.sun.tools.javac.code.Symbol.*;
aoqi@0 33 import com.sun.tools.javac.code.Type.*;
aoqi@0 34 import com.sun.tools.javac.jvm.*;
aoqi@0 35 import com.sun.tools.javac.util.*;
aoqi@0 36 import com.sun.tools.javac.util.List;
aoqi@0 37 import static com.sun.tools.javac.code.Flags.*;
aoqi@0 38 import static com.sun.tools.javac.jvm.ByteCodes.*;
aoqi@0 39 import static com.sun.tools.javac.code.TypeTag.*;
aoqi@0 40
aoqi@0 41 /** A class that defines all predefined constants and operators
aoqi@0 42 * as well as special classes such as java.lang.Object, which need
aoqi@0 43 * to be known to the compiler. All symbols are held in instance
aoqi@0 44 * fields. This makes it possible to work in multiple concurrent
aoqi@0 45 * projects, which might use different class files for library classes.
aoqi@0 46 *
aoqi@0 47 * <p><b>This is NOT part of any supported API.
aoqi@0 48 * If you write code that depends on this, you do so at your own risk.
aoqi@0 49 * This code and its internal interfaces are subject to change or
aoqi@0 50 * deletion without notice.</b>
aoqi@0 51 */
aoqi@0 52 public class Symtab {
aoqi@0 53 /** The context key for the symbol table. */
aoqi@0 54 protected static final Context.Key<Symtab> symtabKey =
aoqi@0 55 new Context.Key<Symtab>();
aoqi@0 56
aoqi@0 57 /** Get the symbol table instance. */
aoqi@0 58 public static Symtab instance(Context context) {
aoqi@0 59 Symtab instance = context.get(symtabKey);
aoqi@0 60 if (instance == null)
aoqi@0 61 instance = new Symtab(context);
aoqi@0 62 return instance;
aoqi@0 63 }
aoqi@0 64
aoqi@0 65 /** Builtin types.
aoqi@0 66 */
aoqi@0 67 public final JCPrimitiveType byteType = new JCPrimitiveType(BYTE, null);
aoqi@0 68 public final JCPrimitiveType charType = new JCPrimitiveType(CHAR, null);
aoqi@0 69 public final JCPrimitiveType shortType = new JCPrimitiveType(SHORT, null);
aoqi@0 70 public final JCPrimitiveType intType = new JCPrimitiveType(INT, null);
aoqi@0 71 public final JCPrimitiveType longType = new JCPrimitiveType(LONG, null);
aoqi@0 72 public final JCPrimitiveType floatType = new JCPrimitiveType(FLOAT, null);
aoqi@0 73 public final JCPrimitiveType doubleType = new JCPrimitiveType(DOUBLE, null);
aoqi@0 74 public final JCPrimitiveType booleanType = new JCPrimitiveType(BOOLEAN, null);
aoqi@0 75 public final Type botType = new BottomType();
aoqi@0 76 public final JCVoidType voidType = new JCVoidType();
aoqi@0 77
aoqi@0 78 private final Names names;
aoqi@0 79 private final ClassReader reader;
aoqi@0 80 private final Target target;
aoqi@0 81
aoqi@0 82 /** A symbol for the root package.
aoqi@0 83 */
aoqi@0 84 public final PackageSymbol rootPackage;
aoqi@0 85
aoqi@0 86 /** A symbol for the unnamed package.
aoqi@0 87 */
aoqi@0 88 public final PackageSymbol unnamedPackage;
aoqi@0 89
aoqi@0 90 /** A symbol that stands for a missing symbol.
aoqi@0 91 */
aoqi@0 92 public final TypeSymbol noSymbol;
aoqi@0 93
aoqi@0 94 /** The error symbol.
aoqi@0 95 */
aoqi@0 96 public final ClassSymbol errSymbol;
aoqi@0 97
aoqi@0 98 /** The unknown symbol.
aoqi@0 99 */
aoqi@0 100 public final ClassSymbol unknownSymbol;
aoqi@0 101
aoqi@0 102 /** A value for the errType, with a originalType of noType */
aoqi@0 103 public final Type errType;
aoqi@0 104
aoqi@0 105 /** A value for the unknown type. */
aoqi@0 106 public final Type unknownType;
aoqi@0 107
aoqi@0 108 /** The builtin type of all arrays. */
aoqi@0 109 public final ClassSymbol arrayClass;
aoqi@0 110 public final MethodSymbol arrayCloneMethod;
aoqi@0 111
aoqi@0 112 /** VGJ: The (singleton) type of all bound types. */
aoqi@0 113 public final ClassSymbol boundClass;
aoqi@0 114
aoqi@0 115 /** The builtin type of all methods. */
aoqi@0 116 public final ClassSymbol methodClass;
aoqi@0 117
aoqi@0 118 /** Predefined types.
aoqi@0 119 */
aoqi@0 120 public final Type objectType;
aoqi@0 121 public final Type classType;
aoqi@0 122 public final Type classLoaderType;
aoqi@0 123 public final Type stringType;
aoqi@0 124 public final Type stringBufferType;
aoqi@0 125 public final Type stringBuilderType;
aoqi@0 126 public final Type cloneableType;
aoqi@0 127 public final Type serializableType;
aoqi@0 128 public final Type serializedLambdaType;
aoqi@0 129 public final Type methodHandleType;
aoqi@0 130 public final Type methodHandleLookupType;
aoqi@0 131 public final Type methodTypeType;
aoqi@0 132 public final Type nativeHeaderType;
aoqi@0 133 public final Type throwableType;
aoqi@0 134 public final Type errorType;
aoqi@0 135 public final Type interruptedExceptionType;
aoqi@0 136 public final Type illegalArgumentExceptionType;
aoqi@0 137 public final Type exceptionType;
aoqi@0 138 public final Type runtimeExceptionType;
aoqi@0 139 public final Type classNotFoundExceptionType;
aoqi@0 140 public final Type noClassDefFoundErrorType;
aoqi@0 141 public final Type noSuchFieldErrorType;
aoqi@0 142 public final Type assertionErrorType;
aoqi@0 143 public final Type cloneNotSupportedExceptionType;
aoqi@0 144 public final Type annotationType;
aoqi@0 145 public final TypeSymbol enumSym;
aoqi@0 146 public final Type listType;
aoqi@0 147 public final Type collectionsType;
aoqi@0 148 public final Type comparableType;
aoqi@0 149 public final Type comparatorType;
aoqi@0 150 public final Type arraysType;
aoqi@0 151 public final Type iterableType;
aoqi@0 152 public final Type iteratorType;
aoqi@0 153 public final Type annotationTargetType;
aoqi@0 154 public final Type overrideType;
aoqi@0 155 public final Type retentionType;
aoqi@0 156 public final Type deprecatedType;
aoqi@0 157 public final Type suppressWarningsType;
aoqi@0 158 public final Type inheritedType;
aoqi@0 159 public final Type profileType;
aoqi@0 160 public final Type proprietaryType;
aoqi@0 161 public final Type systemType;
aoqi@0 162 public final Type autoCloseableType;
aoqi@0 163 public final Type trustMeType;
aoqi@0 164 public final Type lambdaMetafactory;
aoqi@0 165 public final Type repeatableType;
aoqi@0 166 public final Type documentedType;
aoqi@0 167 public final Type elementTypeType;
aoqi@0 168 public final Type functionalInterfaceType;
aoqi@0 169
aoqi@0 170 /** The symbol representing the length field of an array.
aoqi@0 171 */
aoqi@0 172 public final VarSymbol lengthVar;
aoqi@0 173
aoqi@0 174 /** The null check operator. */
aoqi@0 175 public final OperatorSymbol nullcheck;
aoqi@0 176
aoqi@0 177 /** The symbol representing the final finalize method on enums */
aoqi@0 178 public final MethodSymbol enumFinalFinalize;
aoqi@0 179
aoqi@0 180 /** The symbol representing the close method on TWR AutoCloseable type */
aoqi@0 181 public final MethodSymbol autoCloseableClose;
aoqi@0 182
aoqi@0 183 /** The predefined type that belongs to a tag.
aoqi@0 184 */
aoqi@0 185 public final Type[] typeOfTag = new Type[TypeTag.getTypeTagCount()];
aoqi@0 186
aoqi@0 187 /** The name of the class that belongs to a basix type tag.
aoqi@0 188 */
aoqi@0 189 public final Name[] boxedName = new Name[TypeTag.getTypeTagCount()];
aoqi@0 190
aoqi@0 191 /** A set containing all operator names.
aoqi@0 192 */
aoqi@0 193 public final Set<Name> operatorNames = new HashSet<Name>();
aoqi@0 194
aoqi@0 195 /** A hashtable containing the encountered top-level and member classes,
aoqi@0 196 * indexed by flat names. The table does not contain local classes.
aoqi@0 197 * It should be updated from the outside to reflect classes defined
aoqi@0 198 * by compiled source files.
aoqi@0 199 */
aoqi@0 200 public final Map<Name, ClassSymbol> classes = new HashMap<Name, ClassSymbol>();
aoqi@0 201
aoqi@0 202 /** A hashtable containing the encountered packages.
aoqi@0 203 * the table should be updated from outside to reflect packages defined
aoqi@0 204 * by compiled source files.
aoqi@0 205 */
aoqi@0 206 public final Map<Name, PackageSymbol> packages = new HashMap<Name, PackageSymbol>();
aoqi@0 207
aoqi@0 208 public void initType(Type type, ClassSymbol c) {
aoqi@0 209 type.tsym = c;
aoqi@0 210 typeOfTag[type.getTag().ordinal()] = type;
aoqi@0 211 }
aoqi@0 212
aoqi@0 213 public void initType(Type type, String name) {
aoqi@0 214 initType(
aoqi@0 215 type,
aoqi@0 216 new ClassSymbol(
aoqi@0 217 PUBLIC, names.fromString(name), type, rootPackage));
aoqi@0 218 }
aoqi@0 219
aoqi@0 220 public void initType(Type type, String name, String bname) {
aoqi@0 221 initType(type, name);
aoqi@0 222 boxedName[type.getTag().ordinal()] = names.fromString("java.lang." + bname);
aoqi@0 223 }
aoqi@0 224
aoqi@0 225 /** The class symbol that owns all predefined symbols.
aoqi@0 226 */
aoqi@0 227 public final ClassSymbol predefClass;
aoqi@0 228
aoqi@0 229 /** Enter a constant into symbol table.
aoqi@0 230 * @param name The constant's name.
aoqi@0 231 * @param type The constant's type.
aoqi@0 232 */
aoqi@0 233 private VarSymbol enterConstant(String name, Type type) {
aoqi@0 234 VarSymbol c = new VarSymbol(
aoqi@0 235 PUBLIC | STATIC | FINAL,
aoqi@0 236 names.fromString(name),
aoqi@0 237 type,
aoqi@0 238 predefClass);
aoqi@0 239 c.setData(type.constValue());
aoqi@0 240 predefClass.members().enter(c);
aoqi@0 241 return c;
aoqi@0 242 }
aoqi@0 243
aoqi@0 244 /** Enter a binary operation into symbol table.
aoqi@0 245 * @param name The name of the operator.
aoqi@0 246 * @param left The type of the left operand.
aoqi@0 247 * @param right The type of the left operand.
aoqi@0 248 * @param res The operation's result type.
aoqi@0 249 * @param opcode The operation's bytecode instruction.
aoqi@0 250 */
aoqi@0 251 private void enterBinop(String name,
aoqi@0 252 Type left, Type right, Type res,
aoqi@0 253 int opcode) {
aoqi@0 254 predefClass.members().enter(
aoqi@0 255 new OperatorSymbol(
aoqi@0 256 makeOperatorName(name),
aoqi@0 257 new MethodType(List.of(left, right), res,
aoqi@0 258 List.<Type>nil(), methodClass),
aoqi@0 259 opcode,
aoqi@0 260 predefClass));
aoqi@0 261 }
aoqi@0 262
aoqi@0 263 /** Enter a binary operation, as above but with two opcodes,
aoqi@0 264 * which get encoded as
aoqi@0 265 * {@code (opcode1 << ByteCodeTags.preShift) + opcode2 }.
aoqi@0 266 * @param opcode1 First opcode.
aoqi@0 267 * @param opcode2 Second opcode.
aoqi@0 268 */
aoqi@0 269 private void enterBinop(String name,
aoqi@0 270 Type left, Type right, Type res,
aoqi@0 271 int opcode1, int opcode2) {
aoqi@0 272 enterBinop(
aoqi@0 273 name, left, right, res, (opcode1 << ByteCodes.preShift) | opcode2);
aoqi@0 274 }
aoqi@0 275
aoqi@0 276 /** Enter a unary operation into symbol table.
aoqi@0 277 * @param name The name of the operator.
aoqi@0 278 * @param arg The type of the operand.
aoqi@0 279 * @param res The operation's result type.
aoqi@0 280 * @param opcode The operation's bytecode instruction.
aoqi@0 281 */
aoqi@0 282 private OperatorSymbol enterUnop(String name,
aoqi@0 283 Type arg,
aoqi@0 284 Type res,
aoqi@0 285 int opcode) {
aoqi@0 286 OperatorSymbol sym =
aoqi@0 287 new OperatorSymbol(makeOperatorName(name),
aoqi@0 288 new MethodType(List.of(arg),
aoqi@0 289 res,
aoqi@0 290 List.<Type>nil(),
aoqi@0 291 methodClass),
aoqi@0 292 opcode,
aoqi@0 293 predefClass);
aoqi@0 294 predefClass.members().enter(sym);
aoqi@0 295 return sym;
aoqi@0 296 }
aoqi@0 297
aoqi@0 298 /**
aoqi@0 299 * Create a new operator name from corresponding String representation
aoqi@0 300 * and add the name to the set of known operator names.
aoqi@0 301 */
aoqi@0 302 private Name makeOperatorName(String name) {
aoqi@0 303 Name opName = names.fromString(name);
aoqi@0 304 operatorNames.add(opName);
aoqi@0 305 return opName;
aoqi@0 306 }
aoqi@0 307
aoqi@0 308 /** Enter a class into symbol table.
aoqi@0 309 * @param s The name of the class.
aoqi@0 310 */
aoqi@0 311 private Type enterClass(String s) {
aoqi@0 312 return reader.enterClass(names.fromString(s)).type;
aoqi@0 313 }
aoqi@0 314
aoqi@0 315 public void synthesizeEmptyInterfaceIfMissing(final Type type) {
aoqi@0 316 final Completer completer = type.tsym.completer;
aoqi@0 317 if (completer != null) {
aoqi@0 318 type.tsym.completer = new Completer() {
aoqi@0 319 public void complete(Symbol sym) throws CompletionFailure {
aoqi@0 320 try {
aoqi@0 321 completer.complete(sym);
aoqi@0 322 } catch (CompletionFailure e) {
aoqi@0 323 sym.flags_field |= (PUBLIC | INTERFACE);
aoqi@0 324 ((ClassType) sym.type).supertype_field = objectType;
aoqi@0 325 }
aoqi@0 326 }
aoqi@0 327 };
aoqi@0 328 }
aoqi@0 329 }
aoqi@0 330
aoqi@0 331 public void synthesizeBoxTypeIfMissing(final Type type) {
aoqi@0 332 ClassSymbol sym = reader.enterClass(boxedName[type.getTag().ordinal()]);
aoqi@0 333 final Completer completer = sym.completer;
aoqi@0 334 if (completer != null) {
aoqi@0 335 sym.completer = new Completer() {
aoqi@0 336 public void complete(Symbol sym) throws CompletionFailure {
aoqi@0 337 try {
aoqi@0 338 completer.complete(sym);
aoqi@0 339 } catch (CompletionFailure e) {
aoqi@0 340 sym.flags_field |= PUBLIC;
aoqi@0 341 ((ClassType) sym.type).supertype_field = objectType;
aoqi@0 342 Name n = target.boxWithConstructors() ? names.init : names.valueOf;
aoqi@0 343 MethodSymbol boxMethod =
aoqi@0 344 new MethodSymbol(PUBLIC | STATIC,
aoqi@0 345 n,
aoqi@0 346 new MethodType(List.of(type), sym.type,
aoqi@0 347 List.<Type>nil(), methodClass),
aoqi@0 348 sym);
aoqi@0 349 sym.members().enter(boxMethod);
aoqi@0 350 MethodSymbol unboxMethod =
aoqi@0 351 new MethodSymbol(PUBLIC,
aoqi@0 352 type.tsym.name.append(names.Value), // x.intValue()
aoqi@0 353 new MethodType(List.<Type>nil(), type,
aoqi@0 354 List.<Type>nil(), methodClass),
aoqi@0 355 sym);
aoqi@0 356 sym.members().enter(unboxMethod);
aoqi@0 357 }
aoqi@0 358 }
aoqi@0 359 };
aoqi@0 360 }
aoqi@0 361
aoqi@0 362 }
aoqi@0 363
aoqi@0 364 // Enter a synthetic class that is used to mark classes in ct.sym.
aoqi@0 365 // This class does not have a class file.
aoqi@0 366 private Type enterSyntheticAnnotation(String name) {
aoqi@0 367 ClassType type = (ClassType)enterClass(name);
aoqi@0 368 ClassSymbol sym = (ClassSymbol)type.tsym;
aoqi@0 369 sym.completer = null;
aoqi@0 370 sym.flags_field = PUBLIC|ACYCLIC|ANNOTATION|INTERFACE;
aoqi@0 371 sym.erasure_field = type;
aoqi@0 372 sym.members_field = new Scope(sym);
aoqi@0 373 type.typarams_field = List.nil();
aoqi@0 374 type.allparams_field = List.nil();
aoqi@0 375 type.supertype_field = annotationType;
aoqi@0 376 type.interfaces_field = List.nil();
aoqi@0 377 return type;
aoqi@0 378 }
aoqi@0 379
aoqi@0 380 /** Constructor; enters all predefined identifiers and operators
aoqi@0 381 * into symbol table.
aoqi@0 382 */
aoqi@0 383 protected Symtab(Context context) throws CompletionFailure {
aoqi@0 384 context.put(symtabKey, this);
aoqi@0 385
aoqi@0 386 names = Names.instance(context);
aoqi@0 387 target = Target.instance(context);
aoqi@0 388
aoqi@0 389 // Create the unknown type
aoqi@0 390 unknownType = new UnknownType();
aoqi@0 391
aoqi@0 392 // create the basic builtin symbols
aoqi@0 393 rootPackage = new PackageSymbol(names.empty, null);
aoqi@0 394 final JavacMessages messages = JavacMessages.instance(context);
aoqi@0 395 unnamedPackage = new PackageSymbol(names.empty, rootPackage) {
aoqi@0 396 public String toString() {
aoqi@0 397 return messages.getLocalizedString("compiler.misc.unnamed.package");
aoqi@0 398 }
aoqi@0 399 };
aoqi@0 400 noSymbol = new TypeSymbol(Kinds.NIL, 0, names.empty, Type.noType, rootPackage) {
aoqi@0 401 public <R, P> R accept(ElementVisitor<R, P> v, P p) {
aoqi@0 402 return v.visitUnknown(this, p);
aoqi@0 403 }
aoqi@0 404 };
aoqi@0 405
aoqi@0 406 // create the error symbols
aoqi@0 407 errSymbol = new ClassSymbol(PUBLIC|STATIC|ACYCLIC, names.any, null, rootPackage);
aoqi@0 408 errType = new ErrorType(errSymbol, Type.noType);
aoqi@0 409
aoqi@0 410 unknownSymbol = new ClassSymbol(PUBLIC|STATIC|ACYCLIC, names.fromString("<any?>"), null, rootPackage);
aoqi@0 411 unknownSymbol.members_field = new Scope.ErrorScope(unknownSymbol);
aoqi@0 412 unknownSymbol.type = unknownType;
aoqi@0 413
aoqi@0 414 // initialize builtin types
aoqi@0 415 initType(byteType, "byte", "Byte");
aoqi@0 416 initType(shortType, "short", "Short");
aoqi@0 417 initType(charType, "char", "Character");
aoqi@0 418 initType(intType, "int", "Integer");
aoqi@0 419 initType(longType, "long", "Long");
aoqi@0 420 initType(floatType, "float", "Float");
aoqi@0 421 initType(doubleType, "double", "Double");
aoqi@0 422 initType(booleanType, "boolean", "Boolean");
aoqi@0 423 initType(voidType, "void", "Void");
aoqi@0 424 initType(botType, "<nulltype>");
aoqi@0 425 initType(errType, errSymbol);
aoqi@0 426 initType(unknownType, unknownSymbol);
aoqi@0 427
aoqi@0 428 // the builtin class of all arrays
aoqi@0 429 arrayClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Array, noSymbol);
aoqi@0 430
aoqi@0 431 // VGJ
aoqi@0 432 boundClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Bound, noSymbol);
aoqi@0 433 boundClass.members_field = new Scope.ErrorScope(boundClass);
aoqi@0 434
aoqi@0 435 // the builtin class of all methods
aoqi@0 436 methodClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Method, noSymbol);
aoqi@0 437 methodClass.members_field = new Scope.ErrorScope(boundClass);
aoqi@0 438
aoqi@0 439 // Create class to hold all predefined constants and operations.
aoqi@0 440 predefClass = new ClassSymbol(PUBLIC|ACYCLIC, names.empty, rootPackage);
aoqi@0 441 Scope scope = new Scope(predefClass);
aoqi@0 442 predefClass.members_field = scope;
aoqi@0 443
aoqi@0 444 // Enter symbols for basic types.
aoqi@0 445 scope.enter(byteType.tsym);
aoqi@0 446 scope.enter(shortType.tsym);
aoqi@0 447 scope.enter(charType.tsym);
aoqi@0 448 scope.enter(intType.tsym);
aoqi@0 449 scope.enter(longType.tsym);
aoqi@0 450 scope.enter(floatType.tsym);
aoqi@0 451 scope.enter(doubleType.tsym);
aoqi@0 452 scope.enter(booleanType.tsym);
aoqi@0 453 scope.enter(errType.tsym);
aoqi@0 454
aoqi@0 455 // Enter symbol for the errSymbol
aoqi@0 456 scope.enter(errSymbol);
aoqi@0 457
aoqi@0 458 classes.put(predefClass.fullname, predefClass);
aoqi@0 459
aoqi@0 460 reader = ClassReader.instance(context);
aoqi@0 461 reader.init(this);
aoqi@0 462
aoqi@0 463 // Enter predefined classes.
aoqi@0 464 objectType = enterClass("java.lang.Object");
aoqi@0 465 classType = enterClass("java.lang.Class");
aoqi@0 466 stringType = enterClass("java.lang.String");
aoqi@0 467 stringBufferType = enterClass("java.lang.StringBuffer");
aoqi@0 468 stringBuilderType = enterClass("java.lang.StringBuilder");
aoqi@0 469 cloneableType = enterClass("java.lang.Cloneable");
aoqi@0 470 throwableType = enterClass("java.lang.Throwable");
aoqi@0 471 serializableType = enterClass("java.io.Serializable");
aoqi@0 472 serializedLambdaType = enterClass("java.lang.invoke.SerializedLambda");
aoqi@0 473 methodHandleType = enterClass("java.lang.invoke.MethodHandle");
aoqi@0 474 methodHandleLookupType = enterClass("java.lang.invoke.MethodHandles$Lookup");
aoqi@0 475 methodTypeType = enterClass("java.lang.invoke.MethodType");
aoqi@0 476 errorType = enterClass("java.lang.Error");
aoqi@0 477 illegalArgumentExceptionType = enterClass("java.lang.IllegalArgumentException");
aoqi@0 478 interruptedExceptionType = enterClass("java.lang.InterruptedException");
aoqi@0 479 exceptionType = enterClass("java.lang.Exception");
aoqi@0 480 runtimeExceptionType = enterClass("java.lang.RuntimeException");
aoqi@0 481 classNotFoundExceptionType = enterClass("java.lang.ClassNotFoundException");
aoqi@0 482 noClassDefFoundErrorType = enterClass("java.lang.NoClassDefFoundError");
aoqi@0 483 noSuchFieldErrorType = enterClass("java.lang.NoSuchFieldError");
aoqi@0 484 assertionErrorType = enterClass("java.lang.AssertionError");
aoqi@0 485 cloneNotSupportedExceptionType = enterClass("java.lang.CloneNotSupportedException");
aoqi@0 486 annotationType = enterClass("java.lang.annotation.Annotation");
aoqi@0 487 classLoaderType = enterClass("java.lang.ClassLoader");
aoqi@0 488 enumSym = reader.enterClass(names.java_lang_Enum);
aoqi@0 489 enumFinalFinalize =
aoqi@0 490 new MethodSymbol(PROTECTED|FINAL|HYPOTHETICAL,
aoqi@0 491 names.finalize,
aoqi@0 492 new MethodType(List.<Type>nil(), voidType,
aoqi@0 493 List.<Type>nil(), methodClass),
aoqi@0 494 enumSym);
aoqi@0 495 listType = enterClass("java.util.List");
aoqi@0 496 collectionsType = enterClass("java.util.Collections");
aoqi@0 497 comparableType = enterClass("java.lang.Comparable");
aoqi@0 498 comparatorType = enterClass("java.util.Comparator");
aoqi@0 499 arraysType = enterClass("java.util.Arrays");
aoqi@0 500 iterableType = target.hasIterable()
aoqi@0 501 ? enterClass("java.lang.Iterable")
aoqi@0 502 : enterClass("java.util.Collection");
aoqi@0 503 iteratorType = enterClass("java.util.Iterator");
aoqi@0 504 annotationTargetType = enterClass("java.lang.annotation.Target");
aoqi@0 505 overrideType = enterClass("java.lang.Override");
aoqi@0 506 retentionType = enterClass("java.lang.annotation.Retention");
aoqi@0 507 deprecatedType = enterClass("java.lang.Deprecated");
aoqi@0 508 suppressWarningsType = enterClass("java.lang.SuppressWarnings");
aoqi@0 509 inheritedType = enterClass("java.lang.annotation.Inherited");
aoqi@0 510 repeatableType = enterClass("java.lang.annotation.Repeatable");
aoqi@0 511 documentedType = enterClass("java.lang.annotation.Documented");
aoqi@0 512 elementTypeType = enterClass("java.lang.annotation.ElementType");
aoqi@0 513 systemType = enterClass("java.lang.System");
aoqi@0 514 autoCloseableType = enterClass("java.lang.AutoCloseable");
aoqi@0 515 autoCloseableClose = new MethodSymbol(PUBLIC,
aoqi@0 516 names.close,
aoqi@0 517 new MethodType(List.<Type>nil(), voidType,
aoqi@0 518 List.of(exceptionType), methodClass),
aoqi@0 519 autoCloseableType.tsym);
aoqi@0 520 trustMeType = enterClass("java.lang.SafeVarargs");
aoqi@0 521 nativeHeaderType = enterClass("java.lang.annotation.Native");
aoqi@0 522 lambdaMetafactory = enterClass("java.lang.invoke.LambdaMetafactory");
aoqi@0 523 functionalInterfaceType = enterClass("java.lang.FunctionalInterface");
aoqi@0 524
aoqi@0 525 synthesizeEmptyInterfaceIfMissing(autoCloseableType);
aoqi@0 526 synthesizeEmptyInterfaceIfMissing(cloneableType);
aoqi@0 527 synthesizeEmptyInterfaceIfMissing(serializableType);
aoqi@0 528 synthesizeEmptyInterfaceIfMissing(lambdaMetafactory);
aoqi@0 529 synthesizeEmptyInterfaceIfMissing(serializedLambdaType);
aoqi@0 530 synthesizeBoxTypeIfMissing(doubleType);
aoqi@0 531 synthesizeBoxTypeIfMissing(floatType);
aoqi@0 532 synthesizeBoxTypeIfMissing(voidType);
aoqi@0 533
aoqi@0 534 // Enter a synthetic class that is used to mark internal
aoqi@0 535 // proprietary classes in ct.sym. This class does not have a
aoqi@0 536 // class file.
aoqi@0 537 proprietaryType = enterSyntheticAnnotation("sun.Proprietary+Annotation");
aoqi@0 538
aoqi@0 539 // Enter a synthetic class that is used to provide profile info for
aoqi@0 540 // classes in ct.sym. This class does not have a class file.
aoqi@0 541 profileType = enterSyntheticAnnotation("jdk.Profile+Annotation");
aoqi@0 542 MethodSymbol m = new MethodSymbol(PUBLIC | ABSTRACT, names.value, intType, profileType.tsym);
aoqi@0 543 profileType.tsym.members().enter(m);
aoqi@0 544
aoqi@0 545 // Enter a class for arrays.
aoqi@0 546 // The class implements java.lang.Cloneable and java.io.Serializable.
aoqi@0 547 // It has a final length field and a clone method.
aoqi@0 548 ClassType arrayClassType = (ClassType)arrayClass.type;
aoqi@0 549 arrayClassType.supertype_field = objectType;
aoqi@0 550 arrayClassType.interfaces_field = List.of(cloneableType, serializableType);
aoqi@0 551 arrayClass.members_field = new Scope(arrayClass);
aoqi@0 552 lengthVar = new VarSymbol(
aoqi@0 553 PUBLIC | FINAL,
aoqi@0 554 names.length,
aoqi@0 555 intType,
aoqi@0 556 arrayClass);
aoqi@0 557 arrayClass.members().enter(lengthVar);
aoqi@0 558 arrayCloneMethod = new MethodSymbol(
aoqi@0 559 PUBLIC,
aoqi@0 560 names.clone,
aoqi@0 561 new MethodType(List.<Type>nil(), objectType,
aoqi@0 562 List.<Type>nil(), methodClass),
aoqi@0 563 arrayClass);
aoqi@0 564 arrayClass.members().enter(arrayCloneMethod);
aoqi@0 565
aoqi@0 566 // Enter operators.
aoqi@0 567 /* Internally we use +++, --- for unary +, - to reduce +, - operators
aoqi@0 568 * overloading
aoqi@0 569 */
aoqi@0 570 enterUnop("+++", doubleType, doubleType, nop);
aoqi@0 571 enterUnop("+++", floatType, floatType, nop);
aoqi@0 572 enterUnop("+++", longType, longType, nop);
aoqi@0 573 enterUnop("+++", intType, intType, nop);
aoqi@0 574
aoqi@0 575 enterUnop("---", doubleType, doubleType, dneg);
aoqi@0 576 enterUnop("---", floatType, floatType, fneg);
aoqi@0 577 enterUnop("---", longType, longType, lneg);
aoqi@0 578 enterUnop("---", intType, intType, ineg);
aoqi@0 579
aoqi@0 580 enterUnop("~", longType, longType, lxor);
aoqi@0 581 enterUnop("~", intType, intType, ixor);
aoqi@0 582
aoqi@0 583 enterUnop("++", doubleType, doubleType, dadd);
aoqi@0 584 enterUnop("++", floatType, floatType, fadd);
aoqi@0 585 enterUnop("++", longType, longType, ladd);
aoqi@0 586 enterUnop("++", intType, intType, iadd);
aoqi@0 587 enterUnop("++", charType, charType, iadd);
aoqi@0 588 enterUnop("++", shortType, shortType, iadd);
aoqi@0 589 enterUnop("++", byteType, byteType, iadd);
aoqi@0 590
aoqi@0 591 enterUnop("--", doubleType, doubleType, dsub);
aoqi@0 592 enterUnop("--", floatType, floatType, fsub);
aoqi@0 593 enterUnop("--", longType, longType, lsub);
aoqi@0 594 enterUnop("--", intType, intType, isub);
aoqi@0 595 enterUnop("--", charType, charType, isub);
aoqi@0 596 enterUnop("--", shortType, shortType, isub);
aoqi@0 597 enterUnop("--", byteType, byteType, isub);
aoqi@0 598
aoqi@0 599 enterUnop("!", booleanType, booleanType, bool_not);
aoqi@0 600 nullcheck = enterUnop("<*nullchk*>", objectType, objectType, nullchk);
aoqi@0 601
aoqi@0 602 // string concatenation
aoqi@0 603 enterBinop("+", stringType, objectType, stringType, string_add);
aoqi@0 604 enterBinop("+", objectType, stringType, stringType, string_add);
aoqi@0 605 enterBinop("+", stringType, stringType, stringType, string_add);
aoqi@0 606 enterBinop("+", stringType, intType, stringType, string_add);
aoqi@0 607 enterBinop("+", stringType, longType, stringType, string_add);
aoqi@0 608 enterBinop("+", stringType, floatType, stringType, string_add);
aoqi@0 609 enterBinop("+", stringType, doubleType, stringType, string_add);
aoqi@0 610 enterBinop("+", stringType, booleanType, stringType, string_add);
aoqi@0 611 enterBinop("+", stringType, botType, stringType, string_add);
aoqi@0 612 enterBinop("+", intType, stringType, stringType, string_add);
aoqi@0 613 enterBinop("+", longType, stringType, stringType, string_add);
aoqi@0 614 enterBinop("+", floatType, stringType, stringType, string_add);
aoqi@0 615 enterBinop("+", doubleType, stringType, stringType, string_add);
aoqi@0 616 enterBinop("+", booleanType, stringType, stringType, string_add);
aoqi@0 617 enterBinop("+", botType, stringType, stringType, string_add);
aoqi@0 618
aoqi@0 619 // these errors would otherwise be matched as string concatenation
aoqi@0 620 enterBinop("+", botType, botType, botType, error);
aoqi@0 621 enterBinop("+", botType, intType, botType, error);
aoqi@0 622 enterBinop("+", botType, longType, botType, error);
aoqi@0 623 enterBinop("+", botType, floatType, botType, error);
aoqi@0 624 enterBinop("+", botType, doubleType, botType, error);
aoqi@0 625 enterBinop("+", botType, booleanType, botType, error);
aoqi@0 626 enterBinop("+", botType, objectType, botType, error);
aoqi@0 627 enterBinop("+", intType, botType, botType, error);
aoqi@0 628 enterBinop("+", longType, botType, botType, error);
aoqi@0 629 enterBinop("+", floatType, botType, botType, error);
aoqi@0 630 enterBinop("+", doubleType, botType, botType, error);
aoqi@0 631 enterBinop("+", booleanType, botType, botType, error);
aoqi@0 632 enterBinop("+", objectType, botType, botType, error);
aoqi@0 633
aoqi@0 634 enterBinop("+", doubleType, doubleType, doubleType, dadd);
aoqi@0 635 enterBinop("+", floatType, floatType, floatType, fadd);
aoqi@0 636 enterBinop("+", longType, longType, longType, ladd);
aoqi@0 637 enterBinop("+", intType, intType, intType, iadd);
aoqi@0 638
aoqi@0 639 enterBinop("-", doubleType, doubleType, doubleType, dsub);
aoqi@0 640 enterBinop("-", floatType, floatType, floatType, fsub);
aoqi@0 641 enterBinop("-", longType, longType, longType, lsub);
aoqi@0 642 enterBinop("-", intType, intType, intType, isub);
aoqi@0 643
aoqi@0 644 enterBinop("*", doubleType, doubleType, doubleType, dmul);
aoqi@0 645 enterBinop("*", floatType, floatType, floatType, fmul);
aoqi@0 646 enterBinop("*", longType, longType, longType, lmul);
aoqi@0 647 enterBinop("*", intType, intType, intType, imul);
aoqi@0 648
aoqi@0 649 enterBinop("/", doubleType, doubleType, doubleType, ddiv);
aoqi@0 650 enterBinop("/", floatType, floatType, floatType, fdiv);
aoqi@0 651 enterBinop("/", longType, longType, longType, ldiv);
aoqi@0 652 enterBinop("/", intType, intType, intType, idiv);
aoqi@0 653
aoqi@0 654 enterBinop("%", doubleType, doubleType, doubleType, dmod);
aoqi@0 655 enterBinop("%", floatType, floatType, floatType, fmod);
aoqi@0 656 enterBinop("%", longType, longType, longType, lmod);
aoqi@0 657 enterBinop("%", intType, intType, intType, imod);
aoqi@0 658
aoqi@0 659 enterBinop("&", booleanType, booleanType, booleanType, iand);
aoqi@0 660 enterBinop("&", longType, longType, longType, land);
aoqi@0 661 enterBinop("&", intType, intType, intType, iand);
aoqi@0 662
aoqi@0 663 enterBinop("|", booleanType, booleanType, booleanType, ior);
aoqi@0 664 enterBinop("|", longType, longType, longType, lor);
aoqi@0 665 enterBinop("|", intType, intType, intType, ior);
aoqi@0 666
aoqi@0 667 enterBinop("^", booleanType, booleanType, booleanType, ixor);
aoqi@0 668 enterBinop("^", longType, longType, longType, lxor);
aoqi@0 669 enterBinop("^", intType, intType, intType, ixor);
aoqi@0 670
aoqi@0 671 enterBinop("<<", longType, longType, longType, lshll);
aoqi@0 672 enterBinop("<<", intType, longType, intType, ishll);
aoqi@0 673 enterBinop("<<", longType, intType, longType, lshl);
aoqi@0 674 enterBinop("<<", intType, intType, intType, ishl);
aoqi@0 675
aoqi@0 676 enterBinop(">>", longType, longType, longType, lshrl);
aoqi@0 677 enterBinop(">>", intType, longType, intType, ishrl);
aoqi@0 678 enterBinop(">>", longType, intType, longType, lshr);
aoqi@0 679 enterBinop(">>", intType, intType, intType, ishr);
aoqi@0 680
aoqi@0 681 enterBinop(">>>", longType, longType, longType, lushrl);
aoqi@0 682 enterBinop(">>>", intType, longType, intType, iushrl);
aoqi@0 683 enterBinop(">>>", longType, intType, longType, lushr);
aoqi@0 684 enterBinop(">>>", intType, intType, intType, iushr);
aoqi@0 685
aoqi@0 686 enterBinop("<", doubleType, doubleType, booleanType, dcmpg, iflt);
aoqi@0 687 enterBinop("<", floatType, floatType, booleanType, fcmpg, iflt);
aoqi@0 688 enterBinop("<", longType, longType, booleanType, lcmp, iflt);
aoqi@0 689 enterBinop("<", intType, intType, booleanType, if_icmplt);
aoqi@0 690
aoqi@0 691 enterBinop(">", doubleType, doubleType, booleanType, dcmpl, ifgt);
aoqi@0 692 enterBinop(">", floatType, floatType, booleanType, fcmpl, ifgt);
aoqi@0 693 enterBinop(">", longType, longType, booleanType, lcmp, ifgt);
aoqi@0 694 enterBinop(">", intType, intType, booleanType, if_icmpgt);
aoqi@0 695
aoqi@0 696 enterBinop("<=", doubleType, doubleType, booleanType, dcmpg, ifle);
aoqi@0 697 enterBinop("<=", floatType, floatType, booleanType, fcmpg, ifle);
aoqi@0 698 enterBinop("<=", longType, longType, booleanType, lcmp, ifle);
aoqi@0 699 enterBinop("<=", intType, intType, booleanType, if_icmple);
aoqi@0 700
aoqi@0 701 enterBinop(">=", doubleType, doubleType, booleanType, dcmpl, ifge);
aoqi@0 702 enterBinop(">=", floatType, floatType, booleanType, fcmpl, ifge);
aoqi@0 703 enterBinop(">=", longType, longType, booleanType, lcmp, ifge);
aoqi@0 704 enterBinop(">=", intType, intType, booleanType, if_icmpge);
aoqi@0 705
aoqi@0 706 enterBinop("==", objectType, objectType, booleanType, if_acmpeq);
aoqi@0 707 enterBinop("==", booleanType, booleanType, booleanType, if_icmpeq);
aoqi@0 708 enterBinop("==", doubleType, doubleType, booleanType, dcmpl, ifeq);
aoqi@0 709 enterBinop("==", floatType, floatType, booleanType, fcmpl, ifeq);
aoqi@0 710 enterBinop("==", longType, longType, booleanType, lcmp, ifeq);
aoqi@0 711 enterBinop("==", intType, intType, booleanType, if_icmpeq);
aoqi@0 712
aoqi@0 713 enterBinop("!=", objectType, objectType, booleanType, if_acmpne);
aoqi@0 714 enterBinop("!=", booleanType, booleanType, booleanType, if_icmpne);
aoqi@0 715 enterBinop("!=", doubleType, doubleType, booleanType, dcmpl, ifne);
aoqi@0 716 enterBinop("!=", floatType, floatType, booleanType, fcmpl, ifne);
aoqi@0 717 enterBinop("!=", longType, longType, booleanType, lcmp, ifne);
aoqi@0 718 enterBinop("!=", intType, intType, booleanType, if_icmpne);
aoqi@0 719
aoqi@0 720 enterBinop("&&", booleanType, booleanType, booleanType, bool_and);
aoqi@0 721 enterBinop("||", booleanType, booleanType, booleanType, bool_or);
aoqi@0 722 }
aoqi@0 723 }

mercurial