< prev index next >

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

Print this page
rev 3244 : Initial import


   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.code;
  27 
  28 import java.util.HashMap;
  29 import java.util.HashSet;
  30 import java.util.Map;
  31 import java.util.Set;
  32 
  33 import javax.lang.model.element.ElementVisitor;
  34 import javax.tools.JavaFileObject;
  35 
  36 
  37 import com.sun.tools.javac.code.Scope.WriteableScope;
  38 import com.sun.tools.javac.code.Symbol.ClassSymbol;
  39 import com.sun.tools.javac.code.Symbol.Completer;
  40 import com.sun.tools.javac.code.Symbol.CompletionFailure;
  41 import com.sun.tools.javac.code.Symbol.MethodSymbol;
  42 import com.sun.tools.javac.code.Symbol.OperatorSymbol;
  43 import com.sun.tools.javac.code.Symbol.PackageSymbol;
  44 import com.sun.tools.javac.code.Symbol.TypeSymbol;
  45 import com.sun.tools.javac.code.Symbol.VarSymbol;
  46 import com.sun.tools.javac.code.Type.BottomType;
  47 import com.sun.tools.javac.code.Type.ClassType;
  48 import com.sun.tools.javac.code.Type.ErrorType;
  49 import com.sun.tools.javac.code.Type.JCPrimitiveType;
  50 import com.sun.tools.javac.code.Type.JCVoidType;
  51 import com.sun.tools.javac.code.Type.MethodType;
  52 import com.sun.tools.javac.code.Type.UnknownType;
  53 import com.sun.tools.javac.jvm.ByteCodes;
  54 import com.sun.tools.javac.jvm.Target;
  55 import com.sun.tools.javac.util.Assert;
  56 import com.sun.tools.javac.util.Context;
  57 import com.sun.tools.javac.util.Convert;
  58 import com.sun.tools.javac.util.DefinedBy;
  59 import com.sun.tools.javac.util.DefinedBy.Api;
  60 import com.sun.tools.javac.util.JavacMessages;
  61 import com.sun.tools.javac.util.List;
  62 import com.sun.tools.javac.util.Log;
  63 import com.sun.tools.javac.util.Name;
  64 import com.sun.tools.javac.util.Names;
  65 
  66 import static com.sun.tools.javac.code.Flags.*;
  67 import static com.sun.tools.javac.code.Kinds.Kind.*;
  68 import static com.sun.tools.javac.jvm.ByteCodes.*;
  69 import static com.sun.tools.javac.code.TypeTag.*;
  70 
  71 /** A class that defines all predefined constants and operators
  72  *  as well as special classes such as java.lang.Object, which need
  73  *  to be known to the compiler. All symbols are held in instance
  74  *  fields. This makes it possible to work in multiple concurrent
  75  *  projects, which might use different class files for library classes.
  76  *
  77  *  <p><b>This is NOT part of any supported API.
  78  *  If you write code that depends on this, you do so at your own risk.
  79  *  This code and its internal interfaces are subject to change or
  80  *  deletion without notice.</b>
  81  */
  82 public class Symtab {
  83     /** The context key for the symbol table. */
  84     protected static final Context.Key<Symtab> symtabKey = new Context.Key<>();
  85 
  86     /** Get the symbol table instance. */
  87     public static Symtab instance(Context context) {
  88         Symtab instance = context.get(symtabKey);


 131     /** A value for the errType, with a originalType of noType */
 132     public final Type errType;
 133 
 134     /** A value for the unknown type. */
 135     public final Type unknownType;
 136 
 137     /** The builtin type of all arrays. */
 138     public final ClassSymbol arrayClass;
 139     public final MethodSymbol arrayCloneMethod;
 140 
 141     /** VGJ: The (singleton) type of all bound types. */
 142     public final ClassSymbol boundClass;
 143 
 144     /** The builtin type of all methods. */
 145     public final ClassSymbol methodClass;
 146 
 147     /** Predefined types.
 148      */
 149     public final Type objectType;
 150     public final Type objectsType;

 151     public final Type classType;
 152     public final Type classLoaderType;
 153     public final Type stringType;
 154     public final Type stringBufferType;
 155     public final Type stringBuilderType;
 156     public final Type cloneableType;
 157     public final Type serializableType;
 158     public final Type serializedLambdaType;
 159     public final Type methodHandleType;
 160     public final Type methodHandleLookupType;
 161     public final Type methodTypeType;
 162     public final Type nativeHeaderType;
 163     public final Type throwableType;
 164     public final Type errorType;
 165     public final Type interruptedExceptionType;
 166     public final Type illegalArgumentExceptionType;
 167     public final Type exceptionType;
 168     public final Type runtimeExceptionType;
 169     public final Type classNotFoundExceptionType;
 170     public final Type noClassDefFoundErrorType;


 176     public final Type listType;
 177     public final Type collectionsType;
 178     public final Type comparableType;
 179     public final Type comparatorType;
 180     public final Type arraysType;
 181     public final Type iterableType;
 182     public final Type iteratorType;
 183     public final Type annotationTargetType;
 184     public final Type overrideType;
 185     public final Type retentionType;
 186     public final Type deprecatedType;
 187     public final Type suppressWarningsType;
 188     public final Type supplierType;
 189     public final Type inheritedType;
 190     public final Type profileType;
 191     public final Type proprietaryType;
 192     public final Type systemType;
 193     public final Type autoCloseableType;
 194     public final Type trustMeType;
 195     public final Type lambdaMetafactory;

 196     public final Type repeatableType;
 197     public final Type documentedType;
 198     public final Type elementTypeType;
 199     public final Type functionalInterfaceType;
 200 
 201     /** The symbol representing the length field of an array.
 202      */
 203     public final VarSymbol lengthVar;
 204 
 205     /** The symbol representing the final finalize method on enums */
 206     public final MethodSymbol enumFinalFinalize;
 207 
 208     /** The symbol representing the close method on TWR AutoCloseable type */
 209     public final MethodSymbol autoCloseableClose;
 210 
 211     /** The predefined type that belongs to a tag.
 212      */
 213     public final Type[] typeOfTag = new Type[TypeTag.getTypeTagCount()];
 214 
 215     /** The name of the class that belongs to a basix type tag.


 399         // Enter symbols for basic types.
 400         scope.enter(byteType.tsym);
 401         scope.enter(shortType.tsym);
 402         scope.enter(charType.tsym);
 403         scope.enter(intType.tsym);
 404         scope.enter(longType.tsym);
 405         scope.enter(floatType.tsym);
 406         scope.enter(doubleType.tsym);
 407         scope.enter(booleanType.tsym);
 408         scope.enter(errType.tsym);
 409 
 410         // Enter symbol for the errSymbol
 411         scope.enter(errSymbol);
 412 
 413         classes.put(predefClass.fullname, predefClass);
 414 
 415         // Enter predefined classes.
 416         objectType = enterClass("java.lang.Object");
 417         objectsType = enterClass("java.util.Objects");
 418         classType = enterClass("java.lang.Class");

 419         stringType = enterClass("java.lang.String");
 420         stringBufferType = enterClass("java.lang.StringBuffer");
 421         stringBuilderType = enterClass("java.lang.StringBuilder");
 422         cloneableType = enterClass("java.lang.Cloneable");
 423         throwableType = enterClass("java.lang.Throwable");
 424         serializableType = enterClass("java.io.Serializable");
 425         serializedLambdaType = enterClass("java.lang.invoke.SerializedLambda");
 426         methodHandleType = enterClass("java.lang.invoke.MethodHandle");
 427         methodHandleLookupType = enterClass("java.lang.invoke.MethodHandles$Lookup");
 428         methodTypeType = enterClass("java.lang.invoke.MethodType");
 429         errorType = enterClass("java.lang.Error");
 430         illegalArgumentExceptionType = enterClass("java.lang.IllegalArgumentException");
 431         interruptedExceptionType = enterClass("java.lang.InterruptedException");
 432         exceptionType = enterClass("java.lang.Exception");
 433         runtimeExceptionType = enterClass("java.lang.RuntimeException");
 434         classNotFoundExceptionType = enterClass("java.lang.ClassNotFoundException");
 435         noClassDefFoundErrorType = enterClass("java.lang.NoClassDefFoundError");
 436         noSuchFieldErrorType = enterClass("java.lang.NoSuchFieldError");
 437         assertionErrorType = enterClass("java.lang.AssertionError");
 438         cloneNotSupportedExceptionType = enterClass("java.lang.CloneNotSupportedException");


 455         annotationTargetType = enterClass("java.lang.annotation.Target");
 456         overrideType = enterClass("java.lang.Override");
 457         retentionType = enterClass("java.lang.annotation.Retention");
 458         deprecatedType = enterClass("java.lang.Deprecated");
 459         suppressWarningsType = enterClass("java.lang.SuppressWarnings");
 460         supplierType = enterClass("java.util.function.Supplier");
 461         inheritedType = enterClass("java.lang.annotation.Inherited");
 462         repeatableType = enterClass("java.lang.annotation.Repeatable");
 463         documentedType = enterClass("java.lang.annotation.Documented");
 464         elementTypeType = enterClass("java.lang.annotation.ElementType");
 465         systemType = enterClass("java.lang.System");
 466         autoCloseableType = enterClass("java.lang.AutoCloseable");
 467         autoCloseableClose = new MethodSymbol(PUBLIC,
 468                              names.close,
 469                              new MethodType(List.<Type>nil(), voidType,
 470                                             List.of(exceptionType), methodClass),
 471                              autoCloseableType.tsym);
 472         trustMeType = enterClass("java.lang.SafeVarargs");
 473         nativeHeaderType = enterClass("java.lang.annotation.Native");
 474         lambdaMetafactory = enterClass("java.lang.invoke.LambdaMetafactory");

 475         functionalInterfaceType = enterClass("java.lang.FunctionalInterface");
 476 
 477         synthesizeEmptyInterfaceIfMissing(autoCloseableType);
 478         synthesizeEmptyInterfaceIfMissing(cloneableType);
 479         synthesizeEmptyInterfaceIfMissing(serializableType);
 480         synthesizeEmptyInterfaceIfMissing(lambdaMetafactory);
 481         synthesizeEmptyInterfaceIfMissing(serializedLambdaType);

 482         synthesizeBoxTypeIfMissing(doubleType);
 483         synthesizeBoxTypeIfMissing(floatType);
 484         synthesizeBoxTypeIfMissing(voidType);
 485 
 486         // Enter a synthetic class that is used to mark internal
 487         // proprietary classes in ct.sym.  This class does not have a
 488         // class file.
 489         proprietaryType = enterSyntheticAnnotation("sun.Proprietary+Annotation");
 490 
 491         // Enter a synthetic class that is used to provide profile info for
 492         // classes in ct.sym.  This class does not have a class file.
 493         profileType = enterSyntheticAnnotation("jdk.Profile+Annotation");
 494         MethodSymbol m = new MethodSymbol(PUBLIC | ABSTRACT, names.value, intType, profileType.tsym);
 495         profileType.tsym.members().enter(m);
 496 
 497         // Enter a class for arrays.
 498         // The class implements java.lang.Cloneable and java.io.Serializable.
 499         // It has a final length field and a clone method.
 500         ClassType arrayClassType = (ClassType)arrayClass.type;
 501         arrayClassType.supertype_field = objectType;




   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.code;
  27 
  28 import java.util.HashMap;

  29 import java.util.Map;

  30 
  31 import javax.lang.model.element.ElementVisitor;
  32 import javax.tools.JavaFileObject;
  33 
  34 
  35 import com.sun.tools.javac.code.Scope.WriteableScope;
  36 import com.sun.tools.javac.code.Symbol.ClassSymbol;
  37 import com.sun.tools.javac.code.Symbol.Completer;
  38 import com.sun.tools.javac.code.Symbol.CompletionFailure;
  39 import com.sun.tools.javac.code.Symbol.MethodSymbol;

  40 import com.sun.tools.javac.code.Symbol.PackageSymbol;
  41 import com.sun.tools.javac.code.Symbol.TypeSymbol;
  42 import com.sun.tools.javac.code.Symbol.VarSymbol;
  43 import com.sun.tools.javac.code.Type.BottomType;
  44 import com.sun.tools.javac.code.Type.ClassType;
  45 import com.sun.tools.javac.code.Type.ErrorType;
  46 import com.sun.tools.javac.code.Type.JCPrimitiveType;
  47 import com.sun.tools.javac.code.Type.JCVoidType;
  48 import com.sun.tools.javac.code.Type.MethodType;
  49 import com.sun.tools.javac.code.Type.UnknownType;

  50 import com.sun.tools.javac.jvm.Target;
  51 import com.sun.tools.javac.util.Assert;
  52 import com.sun.tools.javac.util.Context;
  53 import com.sun.tools.javac.util.Convert;
  54 import com.sun.tools.javac.util.DefinedBy;
  55 import com.sun.tools.javac.util.DefinedBy.Api;
  56 import com.sun.tools.javac.util.JavacMessages;
  57 import com.sun.tools.javac.util.List;
  58 import com.sun.tools.javac.util.Log;
  59 import com.sun.tools.javac.util.Name;
  60 import com.sun.tools.javac.util.Names;
  61 
  62 import static com.sun.tools.javac.code.Flags.*;
  63 import static com.sun.tools.javac.code.Kinds.Kind.*;

  64 import static com.sun.tools.javac.code.TypeTag.*;
  65 
  66 /** A class that defines all predefined constants and operators
  67  *  as well as special classes such as java.lang.Object, which need
  68  *  to be known to the compiler. All symbols are held in instance
  69  *  fields. This makes it possible to work in multiple concurrent
  70  *  projects, which might use different class files for library classes.
  71  *
  72  *  <p><b>This is NOT part of any supported API.
  73  *  If you write code that depends on this, you do so at your own risk.
  74  *  This code and its internal interfaces are subject to change or
  75  *  deletion without notice.</b>
  76  */
  77 public class Symtab {
  78     /** The context key for the symbol table. */
  79     protected static final Context.Key<Symtab> symtabKey = new Context.Key<>();
  80 
  81     /** Get the symbol table instance. */
  82     public static Symtab instance(Context context) {
  83         Symtab instance = context.get(symtabKey);


 126     /** A value for the errType, with a originalType of noType */
 127     public final Type errType;
 128 
 129     /** A value for the unknown type. */
 130     public final Type unknownType;
 131 
 132     /** The builtin type of all arrays. */
 133     public final ClassSymbol arrayClass;
 134     public final MethodSymbol arrayCloneMethod;
 135 
 136     /** VGJ: The (singleton) type of all bound types. */
 137     public final ClassSymbol boundClass;
 138 
 139     /** The builtin type of all methods. */
 140     public final ClassSymbol methodClass;
 141 
 142     /** Predefined types.
 143      */
 144     public final Type objectType;
 145     public final Type objectsType;
 146     public final Type voidClassType;
 147     public final Type classType;
 148     public final Type classLoaderType;
 149     public final Type stringType;
 150     public final Type stringBufferType;
 151     public final Type stringBuilderType;
 152     public final Type cloneableType;
 153     public final Type serializableType;
 154     public final Type serializedLambdaType;
 155     public final Type methodHandleType;
 156     public final Type methodHandleLookupType;
 157     public final Type methodTypeType;
 158     public final Type nativeHeaderType;
 159     public final Type throwableType;
 160     public final Type errorType;
 161     public final Type interruptedExceptionType;
 162     public final Type illegalArgumentExceptionType;
 163     public final Type exceptionType;
 164     public final Type runtimeExceptionType;
 165     public final Type classNotFoundExceptionType;
 166     public final Type noClassDefFoundErrorType;


 172     public final Type listType;
 173     public final Type collectionsType;
 174     public final Type comparableType;
 175     public final Type comparatorType;
 176     public final Type arraysType;
 177     public final Type iterableType;
 178     public final Type iteratorType;
 179     public final Type annotationTargetType;
 180     public final Type overrideType;
 181     public final Type retentionType;
 182     public final Type deprecatedType;
 183     public final Type suppressWarningsType;
 184     public final Type supplierType;
 185     public final Type inheritedType;
 186     public final Type profileType;
 187     public final Type proprietaryType;
 188     public final Type systemType;
 189     public final Type autoCloseableType;
 190     public final Type trustMeType;
 191     public final Type lambdaMetafactory;
 192     public final Type stringConcatFactory;
 193     public final Type repeatableType;
 194     public final Type documentedType;
 195     public final Type elementTypeType;
 196     public final Type functionalInterfaceType;
 197 
 198     /** The symbol representing the length field of an array.
 199      */
 200     public final VarSymbol lengthVar;
 201 
 202     /** The symbol representing the final finalize method on enums */
 203     public final MethodSymbol enumFinalFinalize;
 204 
 205     /** The symbol representing the close method on TWR AutoCloseable type */
 206     public final MethodSymbol autoCloseableClose;
 207 
 208     /** The predefined type that belongs to a tag.
 209      */
 210     public final Type[] typeOfTag = new Type[TypeTag.getTypeTagCount()];
 211 
 212     /** The name of the class that belongs to a basix type tag.


 396         // Enter symbols for basic types.
 397         scope.enter(byteType.tsym);
 398         scope.enter(shortType.tsym);
 399         scope.enter(charType.tsym);
 400         scope.enter(intType.tsym);
 401         scope.enter(longType.tsym);
 402         scope.enter(floatType.tsym);
 403         scope.enter(doubleType.tsym);
 404         scope.enter(booleanType.tsym);
 405         scope.enter(errType.tsym);
 406 
 407         // Enter symbol for the errSymbol
 408         scope.enter(errSymbol);
 409 
 410         classes.put(predefClass.fullname, predefClass);
 411 
 412         // Enter predefined classes.
 413         objectType = enterClass("java.lang.Object");
 414         objectsType = enterClass("java.util.Objects");
 415         classType = enterClass("java.lang.Class");
 416         voidClassType = enterClass("java.lang.Void");
 417         stringType = enterClass("java.lang.String");
 418         stringBufferType = enterClass("java.lang.StringBuffer");
 419         stringBuilderType = enterClass("java.lang.StringBuilder");
 420         cloneableType = enterClass("java.lang.Cloneable");
 421         throwableType = enterClass("java.lang.Throwable");
 422         serializableType = enterClass("java.io.Serializable");
 423         serializedLambdaType = enterClass("java.lang.invoke.SerializedLambda");
 424         methodHandleType = enterClass("java.lang.invoke.MethodHandle");
 425         methodHandleLookupType = enterClass("java.lang.invoke.MethodHandles$Lookup");
 426         methodTypeType = enterClass("java.lang.invoke.MethodType");
 427         errorType = enterClass("java.lang.Error");
 428         illegalArgumentExceptionType = enterClass("java.lang.IllegalArgumentException");
 429         interruptedExceptionType = enterClass("java.lang.InterruptedException");
 430         exceptionType = enterClass("java.lang.Exception");
 431         runtimeExceptionType = enterClass("java.lang.RuntimeException");
 432         classNotFoundExceptionType = enterClass("java.lang.ClassNotFoundException");
 433         noClassDefFoundErrorType = enterClass("java.lang.NoClassDefFoundError");
 434         noSuchFieldErrorType = enterClass("java.lang.NoSuchFieldError");
 435         assertionErrorType = enterClass("java.lang.AssertionError");
 436         cloneNotSupportedExceptionType = enterClass("java.lang.CloneNotSupportedException");


 453         annotationTargetType = enterClass("java.lang.annotation.Target");
 454         overrideType = enterClass("java.lang.Override");
 455         retentionType = enterClass("java.lang.annotation.Retention");
 456         deprecatedType = enterClass("java.lang.Deprecated");
 457         suppressWarningsType = enterClass("java.lang.SuppressWarnings");
 458         supplierType = enterClass("java.util.function.Supplier");
 459         inheritedType = enterClass("java.lang.annotation.Inherited");
 460         repeatableType = enterClass("java.lang.annotation.Repeatable");
 461         documentedType = enterClass("java.lang.annotation.Documented");
 462         elementTypeType = enterClass("java.lang.annotation.ElementType");
 463         systemType = enterClass("java.lang.System");
 464         autoCloseableType = enterClass("java.lang.AutoCloseable");
 465         autoCloseableClose = new MethodSymbol(PUBLIC,
 466                              names.close,
 467                              new MethodType(List.<Type>nil(), voidType,
 468                                             List.of(exceptionType), methodClass),
 469                              autoCloseableType.tsym);
 470         trustMeType = enterClass("java.lang.SafeVarargs");
 471         nativeHeaderType = enterClass("java.lang.annotation.Native");
 472         lambdaMetafactory = enterClass("java.lang.invoke.LambdaMetafactory");
 473         stringConcatFactory = enterClass("java.lang.invoke.StringConcatFactory");
 474         functionalInterfaceType = enterClass("java.lang.FunctionalInterface");
 475 
 476         synthesizeEmptyInterfaceIfMissing(autoCloseableType);
 477         synthesizeEmptyInterfaceIfMissing(cloneableType);
 478         synthesizeEmptyInterfaceIfMissing(serializableType);
 479         synthesizeEmptyInterfaceIfMissing(lambdaMetafactory);
 480         synthesizeEmptyInterfaceIfMissing(serializedLambdaType);
 481         synthesizeEmptyInterfaceIfMissing(stringConcatFactory);
 482         synthesizeBoxTypeIfMissing(doubleType);
 483         synthesizeBoxTypeIfMissing(floatType);
 484         synthesizeBoxTypeIfMissing(voidType);
 485 
 486         // Enter a synthetic class that is used to mark internal
 487         // proprietary classes in ct.sym.  This class does not have a
 488         // class file.
 489         proprietaryType = enterSyntheticAnnotation("sun.Proprietary+Annotation");
 490 
 491         // Enter a synthetic class that is used to provide profile info for
 492         // classes in ct.sym.  This class does not have a class file.
 493         profileType = enterSyntheticAnnotation("jdk.Profile+Annotation");
 494         MethodSymbol m = new MethodSymbol(PUBLIC | ABSTRACT, names.value, intType, profileType.tsym);
 495         profileType.tsym.members().enter(m);
 496 
 497         // Enter a class for arrays.
 498         // The class implements java.lang.Cloneable and java.io.Serializable.
 499         // It has a final length field and a clone method.
 500         ClassType arrayClassType = (ClassType)arrayClass.type;
 501         arrayClassType.supertype_field = objectType;


< prev index next >