langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symtab.java
changeset 29051 7244db2ab176
parent 27224 228abfa87080
child 29294 376a915b4ff0
equal deleted inserted replaced
29050:76df9080086c 29051:7244db2ab176
   198 
   198 
   199     /** The symbol representing the length field of an array.
   199     /** The symbol representing the length field of an array.
   200      */
   200      */
   201     public final VarSymbol lengthVar;
   201     public final VarSymbol lengthVar;
   202 
   202 
   203     /** The null check operator. */
       
   204     public final OperatorSymbol nullcheck;
       
   205 
       
   206     /** The symbol representing the final finalize method on enums */
   203     /** The symbol representing the final finalize method on enums */
   207     public final MethodSymbol enumFinalFinalize;
   204     public final MethodSymbol enumFinalFinalize;
   208 
   205 
   209     /** The symbol representing the close method on TWR AutoCloseable type */
   206     /** The symbol representing the close method on TWR AutoCloseable type */
   210     public final MethodSymbol autoCloseableClose;
   207     public final MethodSymbol autoCloseableClose;
   214     public final Type[] typeOfTag = new Type[TypeTag.getTypeTagCount()];
   211     public final Type[] typeOfTag = new Type[TypeTag.getTypeTagCount()];
   215 
   212 
   216     /** The name of the class that belongs to a basix type tag.
   213     /** The name of the class that belongs to a basix type tag.
   217      */
   214      */
   218     public final Name[] boxedName = new Name[TypeTag.getTypeTagCount()];
   215     public final Name[] boxedName = new Name[TypeTag.getTypeTagCount()];
   219 
       
   220     /** A set containing all operator names.
       
   221      */
       
   222     public final Set<Name> operatorNames = new HashSet<>();
       
   223 
   216 
   224     /** A hashtable containing the encountered top-level and member classes,
   217     /** A hashtable containing the encountered top-level and member classes,
   225      *  indexed by flat names. The table does not contain local classes.
   218      *  indexed by flat names. The table does not contain local classes.
   226      *  It should be updated from the outside to reflect classes defined
   219      *  It should be updated from the outside to reflect classes defined
   227      *  by compiled source files.
   220      *  by compiled source files.
   252     }
   245     }
   253 
   246 
   254     /** The class symbol that owns all predefined symbols.
   247     /** The class symbol that owns all predefined symbols.
   255      */
   248      */
   256     public final ClassSymbol predefClass;
   249     public final ClassSymbol predefClass;
   257 
       
   258     /** Enter a constant into symbol table.
       
   259      *  @param name   The constant's name.
       
   260      *  @param type   The constant's type.
       
   261      */
       
   262     private VarSymbol enterConstant(String name, Type type) {
       
   263         VarSymbol c = new VarSymbol(
       
   264             PUBLIC | STATIC | FINAL,
       
   265             names.fromString(name),
       
   266             type,
       
   267             predefClass);
       
   268         c.setData(type.constValue());
       
   269         predefClass.members().enter(c);
       
   270         return c;
       
   271     }
       
   272 
       
   273     /** Enter a binary operation into symbol table.
       
   274      *  @param name     The name of the operator.
       
   275      *  @param left     The type of the left operand.
       
   276      *  @param right    The type of the left operand.
       
   277      *  @param res      The operation's result type.
       
   278      *  @param opcode   The operation's bytecode instruction.
       
   279      */
       
   280     private void enterBinop(String name,
       
   281                             Type left, Type right, Type res,
       
   282                             int opcode) {
       
   283         predefClass.members().enter(
       
   284             new OperatorSymbol(
       
   285                 makeOperatorName(name),
       
   286                 new MethodType(List.of(left, right), res,
       
   287                                List.<Type>nil(), methodClass),
       
   288                 opcode,
       
   289                 predefClass));
       
   290     }
       
   291 
       
   292     /** Enter a binary operation, as above but with two opcodes,
       
   293      *  which get encoded as
       
   294      *  {@code (opcode1 << ByteCodeTags.preShift) + opcode2 }.
       
   295      *  @param opcode1     First opcode.
       
   296      *  @param opcode2     Second opcode.
       
   297      */
       
   298     private void enterBinop(String name,
       
   299                             Type left, Type right, Type res,
       
   300                             int opcode1, int opcode2) {
       
   301         enterBinop(
       
   302             name, left, right, res, (opcode1 << ByteCodes.preShift) | opcode2);
       
   303     }
       
   304 
       
   305     /** Enter a unary operation into symbol table.
       
   306      *  @param name     The name of the operator.
       
   307      *  @param arg      The type of the operand.
       
   308      *  @param res      The operation's result type.
       
   309      *  @param opcode   The operation's bytecode instruction.
       
   310      */
       
   311     private OperatorSymbol enterUnop(String name,
       
   312                                      Type arg,
       
   313                                      Type res,
       
   314                                      int opcode) {
       
   315         OperatorSymbol sym =
       
   316             new OperatorSymbol(makeOperatorName(name),
       
   317                                new MethodType(List.of(arg),
       
   318                                               res,
       
   319                                               List.<Type>nil(),
       
   320                                               methodClass),
       
   321                                opcode,
       
   322                                predefClass);
       
   323         predefClass.members().enter(sym);
       
   324         return sym;
       
   325     }
       
   326 
       
   327     /**
       
   328      * Create a new operator name from corresponding String representation
       
   329      * and add the name to the set of known operator names.
       
   330      */
       
   331     private Name makeOperatorName(String name) {
       
   332         Name opName = names.fromString(name);
       
   333         operatorNames.add(opName);
       
   334         return opName;
       
   335     }
       
   336 
   250 
   337     /** Enter a class into symbol table.
   251     /** Enter a class into symbol table.
   338      *  @param s The name of the class.
   252      *  @param s The name of the class.
   339      */
   253      */
   340     private Type enterClass(String s) {
   254     private Type enterClass(String s) {
   589             names.clone,
   503             names.clone,
   590             new MethodType(List.<Type>nil(), objectType,
   504             new MethodType(List.<Type>nil(), objectType,
   591                            List.<Type>nil(), methodClass),
   505                            List.<Type>nil(), methodClass),
   592             arrayClass);
   506             arrayClass);
   593         arrayClass.members().enter(arrayCloneMethod);
   507         arrayClass.members().enter(arrayCloneMethod);
   594 
       
   595         // Enter operators.
       
   596         /*  Internally we use +++, --- for unary +, - to reduce +, - operators
       
   597          *  overloading
       
   598          */
       
   599         enterUnop("+++", doubleType, doubleType, nop);
       
   600         enterUnop("+++", floatType, floatType, nop);
       
   601         enterUnop("+++", longType, longType, nop);
       
   602         enterUnop("+++", intType, intType, nop);
       
   603 
       
   604         enterUnop("---", doubleType, doubleType, dneg);
       
   605         enterUnop("---", floatType, floatType, fneg);
       
   606         enterUnop("---", longType, longType, lneg);
       
   607         enterUnop("---", intType, intType, ineg);
       
   608 
       
   609         enterUnop("~", longType, longType, lxor);
       
   610         enterUnop("~", intType, intType, ixor);
       
   611 
       
   612         enterUnop("++", doubleType, doubleType, dadd);
       
   613         enterUnop("++", floatType, floatType, fadd);
       
   614         enterUnop("++", longType, longType, ladd);
       
   615         enterUnop("++", intType, intType, iadd);
       
   616         enterUnop("++", charType, charType, iadd);
       
   617         enterUnop("++", shortType, shortType, iadd);
       
   618         enterUnop("++", byteType, byteType, iadd);
       
   619 
       
   620         enterUnop("--", doubleType, doubleType, dsub);
       
   621         enterUnop("--", floatType, floatType, fsub);
       
   622         enterUnop("--", longType, longType, lsub);
       
   623         enterUnop("--", intType, intType, isub);
       
   624         enterUnop("--", charType, charType, isub);
       
   625         enterUnop("--", shortType, shortType, isub);
       
   626         enterUnop("--", byteType, byteType, isub);
       
   627 
       
   628         enterUnop("!", booleanType, booleanType, bool_not);
       
   629         nullcheck = enterUnop("<*nullchk*>", objectType, objectType, nullchk);
       
   630 
       
   631         // string concatenation
       
   632         enterBinop("+", stringType, objectType, stringType, string_add);
       
   633         enterBinop("+", objectType, stringType, stringType, string_add);
       
   634         enterBinop("+", stringType, stringType, stringType, string_add);
       
   635         enterBinop("+", stringType, intType, stringType, string_add);
       
   636         enterBinop("+", stringType, longType, stringType, string_add);
       
   637         enterBinop("+", stringType, floatType, stringType, string_add);
       
   638         enterBinop("+", stringType, doubleType, stringType, string_add);
       
   639         enterBinop("+", stringType, booleanType, stringType, string_add);
       
   640         enterBinop("+", stringType, botType, stringType, string_add);
       
   641         enterBinop("+", intType, stringType, stringType, string_add);
       
   642         enterBinop("+", longType, stringType, stringType, string_add);
       
   643         enterBinop("+", floatType, stringType, stringType, string_add);
       
   644         enterBinop("+", doubleType, stringType, stringType, string_add);
       
   645         enterBinop("+", booleanType, stringType, stringType, string_add);
       
   646         enterBinop("+", botType, stringType, stringType, string_add);
       
   647 
       
   648         // these errors would otherwise be matched as string concatenation
       
   649         enterBinop("+", botType, botType, botType, error);
       
   650         enterBinop("+", botType, intType, botType, error);
       
   651         enterBinop("+", botType, longType, botType, error);
       
   652         enterBinop("+", botType, floatType, botType, error);
       
   653         enterBinop("+", botType, doubleType, botType, error);
       
   654         enterBinop("+", botType, booleanType, botType, error);
       
   655         enterBinop("+", botType, objectType, botType, error);
       
   656         enterBinop("+", intType, botType, botType, error);
       
   657         enterBinop("+", longType, botType, botType, error);
       
   658         enterBinop("+", floatType, botType, botType, error);
       
   659         enterBinop("+", doubleType, botType, botType, error);
       
   660         enterBinop("+", booleanType, botType, botType, error);
       
   661         enterBinop("+", objectType, botType, botType, error);
       
   662 
       
   663         enterBinop("+", doubleType, doubleType, doubleType, dadd);
       
   664         enterBinop("+", floatType, floatType, floatType, fadd);
       
   665         enterBinop("+", longType, longType, longType, ladd);
       
   666         enterBinop("+", intType, intType, intType, iadd);
       
   667 
       
   668         enterBinop("-", doubleType, doubleType, doubleType, dsub);
       
   669         enterBinop("-", floatType, floatType, floatType, fsub);
       
   670         enterBinop("-", longType, longType, longType, lsub);
       
   671         enterBinop("-", intType, intType, intType, isub);
       
   672 
       
   673         enterBinop("*", doubleType, doubleType, doubleType, dmul);
       
   674         enterBinop("*", floatType, floatType, floatType, fmul);
       
   675         enterBinop("*", longType, longType, longType, lmul);
       
   676         enterBinop("*", intType, intType, intType, imul);
       
   677 
       
   678         enterBinop("/", doubleType, doubleType, doubleType, ddiv);
       
   679         enterBinop("/", floatType, floatType, floatType, fdiv);
       
   680         enterBinop("/", longType, longType, longType, ldiv);
       
   681         enterBinop("/", intType, intType, intType, idiv);
       
   682 
       
   683         enterBinop("%", doubleType, doubleType, doubleType, dmod);
       
   684         enterBinop("%", floatType, floatType, floatType, fmod);
       
   685         enterBinop("%", longType, longType, longType, lmod);
       
   686         enterBinop("%", intType, intType, intType, imod);
       
   687 
       
   688         enterBinop("&", booleanType, booleanType, booleanType, iand);
       
   689         enterBinop("&", longType, longType, longType, land);
       
   690         enterBinop("&", intType, intType, intType, iand);
       
   691 
       
   692         enterBinop("|", booleanType, booleanType, booleanType, ior);
       
   693         enterBinop("|", longType, longType, longType, lor);
       
   694         enterBinop("|", intType, intType, intType, ior);
       
   695 
       
   696         enterBinop("^", booleanType, booleanType, booleanType, ixor);
       
   697         enterBinop("^", longType, longType, longType, lxor);
       
   698         enterBinop("^", intType, intType, intType, ixor);
       
   699 
       
   700         enterBinop("<<", longType, longType, longType, lshll);
       
   701         enterBinop("<<", intType, longType, intType, ishll);
       
   702         enterBinop("<<", longType, intType, longType, lshl);
       
   703         enterBinop("<<", intType, intType, intType, ishl);
       
   704 
       
   705         enterBinop(">>", longType, longType, longType, lshrl);
       
   706         enterBinop(">>", intType, longType, intType, ishrl);
       
   707         enterBinop(">>", longType, intType, longType, lshr);
       
   708         enterBinop(">>", intType, intType, intType, ishr);
       
   709 
       
   710         enterBinop(">>>", longType, longType, longType, lushrl);
       
   711         enterBinop(">>>", intType, longType, intType, iushrl);
       
   712         enterBinop(">>>", longType, intType, longType, lushr);
       
   713         enterBinop(">>>", intType, intType, intType, iushr);
       
   714 
       
   715         enterBinop("<", doubleType, doubleType, booleanType, dcmpg, iflt);
       
   716         enterBinop("<", floatType, floatType, booleanType, fcmpg, iflt);
       
   717         enterBinop("<", longType, longType, booleanType, lcmp, iflt);
       
   718         enterBinop("<", intType, intType, booleanType, if_icmplt);
       
   719 
       
   720         enterBinop(">", doubleType, doubleType, booleanType, dcmpl, ifgt);
       
   721         enterBinop(">", floatType, floatType, booleanType, fcmpl, ifgt);
       
   722         enterBinop(">", longType, longType, booleanType, lcmp, ifgt);
       
   723         enterBinop(">", intType, intType, booleanType, if_icmpgt);
       
   724 
       
   725         enterBinop("<=", doubleType, doubleType, booleanType, dcmpg, ifle);
       
   726         enterBinop("<=", floatType, floatType, booleanType, fcmpg, ifle);
       
   727         enterBinop("<=", longType, longType, booleanType, lcmp, ifle);
       
   728         enterBinop("<=", intType, intType, booleanType, if_icmple);
       
   729 
       
   730         enterBinop(">=", doubleType, doubleType, booleanType, dcmpl, ifge);
       
   731         enterBinop(">=", floatType, floatType, booleanType, fcmpl, ifge);
       
   732         enterBinop(">=", longType, longType, booleanType, lcmp, ifge);
       
   733         enterBinop(">=", intType, intType, booleanType, if_icmpge);
       
   734 
       
   735         enterBinop("==", objectType, objectType, booleanType, if_acmpeq);
       
   736         enterBinop("==", booleanType, booleanType, booleanType, if_icmpeq);
       
   737         enterBinop("==", doubleType, doubleType, booleanType, dcmpl, ifeq);
       
   738         enterBinop("==", floatType, floatType, booleanType, fcmpl, ifeq);
       
   739         enterBinop("==", longType, longType, booleanType, lcmp, ifeq);
       
   740         enterBinop("==", intType, intType, booleanType, if_icmpeq);
       
   741 
       
   742         enterBinop("!=", objectType, objectType, booleanType, if_acmpne);
       
   743         enterBinop("!=", booleanType, booleanType, booleanType, if_icmpne);
       
   744         enterBinop("!=", doubleType, doubleType, booleanType, dcmpl, ifne);
       
   745         enterBinop("!=", floatType, floatType, booleanType, fcmpl, ifne);
       
   746         enterBinop("!=", longType, longType, booleanType, lcmp, ifne);
       
   747         enterBinop("!=", intType, intType, booleanType, if_icmpne);
       
   748 
       
   749         enterBinop("&&", booleanType, booleanType, booleanType, bool_and);
       
   750         enterBinop("||", booleanType, booleanType, booleanType, bool_or);
       
   751     }
   508     }
   752 
   509 
   753     /** Define a new class given its name and owner.
   510     /** Define a new class given its name and owner.
   754      */
   511      */
   755     public ClassSymbol defineClass(Name name, Symbol owner) {
   512     public ClassSymbol defineClass(Name name, Symbol owner) {