langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symtab.java
author mcimadamore
Mon, 16 Feb 2015 12:24:25 +0000
changeset 29051 7244db2ab176
parent 27224 228abfa87080
child 29294 376a915b4ff0
permissions -rw-r--r--
8071241: Investigate alternate strategy for type-checking operators Summary: Separat operator lookup logic from overload resolution. Reviewed-by: jjg, jlahoda, sadayapalam
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
     2
 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3555
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3555
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3555
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3555
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 3555
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.code;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    28
import java.util.HashMap;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    29
import java.util.HashSet;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    30
import java.util.Map;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    31
import java.util.Set;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 14057
diff changeset
    33
import javax.lang.model.element.ElementVisitor;
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    34
import javax.tools.JavaFileObject;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 14057
diff changeset
    35
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    36
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24604
diff changeset
    37
import com.sun.tools.javac.code.Scope.WriteableScope;
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    38
import com.sun.tools.javac.code.Symbol.ClassSymbol;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    39
import com.sun.tools.javac.code.Symbol.Completer;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    40
import com.sun.tools.javac.code.Symbol.CompletionFailure;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    41
import com.sun.tools.javac.code.Symbol.MethodSymbol;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    42
import com.sun.tools.javac.code.Symbol.OperatorSymbol;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    43
import com.sun.tools.javac.code.Symbol.PackageSymbol;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    44
import com.sun.tools.javac.code.Symbol.TypeSymbol;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    45
import com.sun.tools.javac.code.Symbol.VarSymbol;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    46
import com.sun.tools.javac.code.Type.BottomType;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    47
import com.sun.tools.javac.code.Type.ClassType;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    48
import com.sun.tools.javac.code.Type.ErrorType;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    49
import com.sun.tools.javac.code.Type.JCPrimitiveType;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    50
import com.sun.tools.javac.code.Type.JCVoidType;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    51
import com.sun.tools.javac.code.Type.MethodType;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    52
import com.sun.tools.javac.code.Type.UnknownType;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    53
import com.sun.tools.javac.jvm.ByteCodes;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    54
import com.sun.tools.javac.jvm.Target;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    55
import com.sun.tools.javac.util.Assert;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    56
import com.sun.tools.javac.util.Context;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    57
import com.sun.tools.javac.util.Convert;
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
    58
import com.sun.tools.javac.util.DefinedBy;
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
    59
import com.sun.tools.javac.util.DefinedBy.Api;
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    60
import com.sun.tools.javac.util.JavacMessages;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 14057
diff changeset
    61
import com.sun.tools.javac.util.List;
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    62
import com.sun.tools.javac.util.Log;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    63
import com.sun.tools.javac.util.Name;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    64
import com.sun.tools.javac.util.Names;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
    65
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 14057
diff changeset
    66
import static com.sun.tools.javac.code.Flags.*;
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26266
diff changeset
    67
import static com.sun.tools.javac.code.Kinds.Kind.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
import static com.sun.tools.javac.jvm.ByteCodes.*;
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
    69
import static com.sun.tools.javac.code.TypeTag.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
/** A class that defines all predefined constants and operators
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
 *  as well as special classes such as java.lang.Object, which need
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
 *  to be known to the compiler. All symbols are held in instance
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
 *  fields. This makes it possible to work in multiple concurrent
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
 *  projects, which might use different class files for library classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    77
 *  <p><b>This is NOT part of any supported API.
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    78
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
public class Symtab {
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    /** The context key for the symbol table. */
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 18646
diff changeset
    84
    protected static final Context.Key<Symtab> symtabKey = new Context.Key<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    /** Get the symbol table instance. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
    public static Symtab instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
        Symtab instance = context.get(symtabKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
            instance = new Symtab(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
    /** Builtin types.
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
     */
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18414
diff changeset
    96
    public final JCPrimitiveType byteType = new JCPrimitiveType(BYTE, null);
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18414
diff changeset
    97
    public final JCPrimitiveType charType = new JCPrimitiveType(CHAR, null);
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18414
diff changeset
    98
    public final JCPrimitiveType shortType = new JCPrimitiveType(SHORT, null);
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18414
diff changeset
    99
    public final JCPrimitiveType intType = new JCPrimitiveType(INT, null);
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18414
diff changeset
   100
    public final JCPrimitiveType longType = new JCPrimitiveType(LONG, null);
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18414
diff changeset
   101
    public final JCPrimitiveType floatType = new JCPrimitiveType(FLOAT, null);
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18414
diff changeset
   102
    public final JCPrimitiveType doubleType = new JCPrimitiveType(DOUBLE, null);
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18414
diff changeset
   103
    public final JCPrimitiveType booleanType = new JCPrimitiveType(BOOLEAN, null);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
    public final Type botType = new BottomType();
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18414
diff changeset
   105
    public final JCVoidType voidType = new JCVoidType();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
   107
    private final Names names;
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   108
    private final Completer initialCompleter;
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   109
    private final Target target;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    /** A symbol for the root package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
    public final PackageSymbol rootPackage;
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    /** A symbol for the unnamed package.
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
    public final PackageSymbol unnamedPackage;
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
    /** A symbol that stands for a missing symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
    public final TypeSymbol noSymbol;
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    /** The error symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    public final ClassSymbol errSymbol;
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
6594
d43f068fba19 6970584: Flow.java should be more error-friendly
mcimadamore
parents: 6148
diff changeset
   127
    /** The unknown symbol.
d43f068fba19 6970584: Flow.java should be more error-friendly
mcimadamore
parents: 6148
diff changeset
   128
     */
d43f068fba19 6970584: Flow.java should be more error-friendly
mcimadamore
parents: 6148
diff changeset
   129
    public final ClassSymbol unknownSymbol;
d43f068fba19 6970584: Flow.java should be more error-friendly
mcimadamore
parents: 6148
diff changeset
   130
1257
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1037
diff changeset
   131
    /** A value for the errType, with a originalType of noType */
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
    public final Type errType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
    /** A value for the unknown type. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
    public final Type unknownType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
    /** The builtin type of all arrays. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
    public final ClassSymbol arrayClass;
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
    public final MethodSymbol arrayCloneMethod;
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
    /** VGJ: The (singleton) type of all bound types. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
    public final ClassSymbol boundClass;
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
    /** The builtin type of all methods. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    public final ClassSymbol methodClass;
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    /** Predefined types.
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    public final Type objectType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
    public final Type classType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
    public final Type classLoaderType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
    public final Type stringType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
    public final Type stringBufferType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
    public final Type stringBuilderType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
    public final Type cloneableType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
    public final Type serializableType;
16300
7cf27559c8df 8004969: Generate $deserializeLambda$ method
rfield
parents: 15361
diff changeset
   157
    public final Type serializedLambdaType;
2723
b659ca23d5f5 6829189: Java programming with JSR 292 needs language support
jrose
parents: 1471
diff changeset
   158
    public final Type methodHandleType;
14365
20f388573215 8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents: 14359
diff changeset
   159
    public final Type methodHandleLookupType;
14046
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13844
diff changeset
   160
    public final Type methodTypeType;
12213
516b112d6c68 7150368: javac should include basic ability to generate native headers
jjg
parents: 9082
diff changeset
   161
    public final Type nativeHeaderType;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
    public final Type throwableType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
    public final Type errorType;
9076
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents: 8621
diff changeset
   164
    public final Type interruptedExceptionType;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
    public final Type illegalArgumentExceptionType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    public final Type exceptionType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
    public final Type runtimeExceptionType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
    public final Type classNotFoundExceptionType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
    public final Type noClassDefFoundErrorType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
    public final Type noSuchFieldErrorType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
    public final Type assertionErrorType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
    public final Type cloneNotSupportedExceptionType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
    public final Type annotationType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
    public final TypeSymbol enumSym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
    public final Type listType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
    public final Type collectionsType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
    public final Type comparableType;
16333
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16316
diff changeset
   178
    public final Type comparatorType;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
    public final Type arraysType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
    public final Type iterableType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
    public final Type iteratorType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
    public final Type annotationTargetType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
    public final Type overrideType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
    public final Type retentionType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
    public final Type deprecatedType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
    public final Type suppressWarningsType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
    public final Type inheritedType;
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   188
    public final Type profileType;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
    public final Type proprietaryType;
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   190
    public final Type systemType;
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5857
diff changeset
   191
    public final Type autoCloseableType;
7643
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 6709
diff changeset
   192
    public final Type trustMeType;
14365
20f388573215 8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents: 14359
diff changeset
   193
    public final Type lambdaMetafactory;
15356
cf312dc54c60 8006119: update javac to follow latest spec for repeatable annotations
jjg
parents: 14539
diff changeset
   194
    public final Type repeatableType;
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12335
diff changeset
   195
    public final Type documentedType;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12335
diff changeset
   196
    public final Type elementTypeType;
15361
01f1828683e6 8005299: Add FunctionalInterface checking to javac
mcimadamore
parents: 15356
diff changeset
   197
    public final Type functionalInterfaceType;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
    /** The symbol representing the length field of an array.
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
    public final VarSymbol lengthVar;
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
    /** The symbol representing the final finalize method on enums */
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
    public final MethodSymbol enumFinalFinalize;
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5857
diff changeset
   206
    /** The symbol representing the close method on TWR AutoCloseable type */
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5857
diff changeset
   207
    public final MethodSymbol autoCloseableClose;
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5857
diff changeset
   208
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
    /** The predefined type that belongs to a tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
     */
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
   211
    public final Type[] typeOfTag = new Type[TypeTag.getTypeTagCount()];
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
    /** The name of the class that belongs to a basix type tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
     */
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14259
diff changeset
   215
    public final Name[] boxedName = new Name[TypeTag.getTypeTagCount()];
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
    /** A hashtable containing the encountered top-level and member classes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
     *  indexed by flat names. The table does not contain local classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
     *  It should be updated from the outside to reflect classes defined
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
     *  by compiled source files.
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
     */
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 18646
diff changeset
   222
    public final Map<Name, ClassSymbol> classes = new HashMap<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
    /** A hashtable containing the encountered packages.
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
     *  the table should be updated from outside to reflect packages defined
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
     *  by compiled source files.
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
     */
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 18646
diff changeset
   228
    public final Map<Name, PackageSymbol> packages = new HashMap<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
    public void initType(Type type, ClassSymbol c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
        type.tsym = c;
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18414
diff changeset
   232
        typeOfTag[type.getTag().ordinal()] = type;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
    public void initType(Type type, String name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
        initType(
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
            type,
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
            new ClassSymbol(
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
                PUBLIC, names.fromString(name), type, rootPackage));
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
    public void initType(Type type, String name, String bname) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
        initType(type, name);
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18414
diff changeset
   244
            boxedName[type.getTag().ordinal()] = names.fromString("java.lang." + bname);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
    /** The class symbol that owns all predefined symbols.
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
    public final ClassSymbol predefClass;
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
    /** Enter a class into symbol table.
14259
fb94a1df0d53 8000208: fix langtools javadoc comment issues
jjg
parents: 14258
diff changeset
   252
     *  @param s The name of the class.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
    private Type enterClass(String s) {
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   255
        return enterClass(names.fromString(s)).type;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   258
    public void synthesizeEmptyInterfaceIfMissing(final Type type) {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   259
        final Completer completer = type.tsym.completer;
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   260
        if (completer != null) {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   261
            type.tsym.completer = new Completer() {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   262
                public void complete(Symbol sym) throws CompletionFailure {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   263
                    try {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   264
                        completer.complete(sym);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   265
                    } catch (CompletionFailure e) {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   266
                        sym.flags_field |= (PUBLIC | INTERFACE);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   267
                        ((ClassType) sym.type).supertype_field = objectType;
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   268
                    }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   269
                }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   270
            };
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   271
        }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   272
    }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   273
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   274
    public void synthesizeBoxTypeIfMissing(final Type type) {
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   275
        ClassSymbol sym = enterClass(boxedName[type.getTag().ordinal()]);
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   276
        final Completer completer = sym.completer;
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   277
        if (completer != null) {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   278
            sym.completer = new Completer() {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   279
                public void complete(Symbol sym) throws CompletionFailure {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   280
                    try {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   281
                        completer.complete(sym);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   282
                    } catch (CompletionFailure e) {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   283
                        sym.flags_field |= PUBLIC;
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   284
                        ((ClassType) sym.type).supertype_field = objectType;
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   285
                        MethodSymbol boxMethod =
25445
603f0c93d5c9 8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents: 25443
diff changeset
   286
                            new MethodSymbol(PUBLIC | STATIC, names.valueOf,
603f0c93d5c9 8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents: 25443
diff changeset
   287
                                             new MethodType(List.of(type), sym.type,
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   288
                                    List.<Type>nil(), methodClass),
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   289
                                sym);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   290
                        sym.members().enter(boxMethod);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   291
                        MethodSymbol unboxMethod =
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   292
                            new MethodSymbol(PUBLIC,
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   293
                                type.tsym.name.append(names.Value), // x.intValue()
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   294
                                new MethodType(List.<Type>nil(), type,
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   295
                                    List.<Type>nil(), methodClass),
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   296
                                sym);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   297
                        sym.members().enter(unboxMethod);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   298
                    }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   299
                }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   300
            };
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   301
        }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   302
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   303
    }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   304
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   305
    // Enter a synthetic class that is used to mark classes in ct.sym.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   306
    // This class does not have a class file.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   307
    private Type enterSyntheticAnnotation(String name) {
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   308
        ClassType type = (ClassType)enterClass(name);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   309
        ClassSymbol sym = (ClassSymbol)type.tsym;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   310
        sym.completer = null;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   311
        sym.flags_field = PUBLIC|ACYCLIC|ANNOTATION|INTERFACE;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   312
        sym.erasure_field = type;
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24604
diff changeset
   313
        sym.members_field = WriteableScope.create(sym);
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   314
        type.typarams_field = List.nil();
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   315
        type.allparams_field = List.nil();
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   316
        type.supertype_field = annotationType;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   317
        type.interfaces_field = List.nil();
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   318
        return type;
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   319
    }
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   320
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   321
    /** Constructor; enters all predefined identifiers and operators
06bc494ca11e Initial load
duke
parents:
diff changeset
   322
     *  into symbol table.
06bc494ca11e Initial load
duke
parents:
diff changeset
   323
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   324
    protected Symtab(Context context) throws CompletionFailure {
06bc494ca11e Initial load
duke
parents:
diff changeset
   325
        context.put(symtabKey, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
1260
a772ba9ba43d 6574134: Allow for alternative implementation of Name Table with garbage collection of name bytes
jjg
parents: 1257
diff changeset
   327
        names = Names.instance(context);
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   328
        target = Target.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
        // Create the unknown type
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18414
diff changeset
   331
        unknownType = new UnknownType();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
06bc494ca11e Initial load
duke
parents:
diff changeset
   333
        // create the basic builtin symbols
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
        rootPackage = new PackageSymbol(names.empty, null);
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   335
        packages.put(names.empty, rootPackage);
1471
57506cdfb7b4 6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents: 1264
diff changeset
   336
        final JavacMessages messages = JavacMessages.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
        unnamedPackage = new PackageSymbol(names.empty, rootPackage) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
                public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
                    return messages.getLocalizedString("compiler.misc.unnamed.package");
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
            };
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26266
diff changeset
   342
        noSymbol = new TypeSymbol(NIL, 0, names.empty, Type.noType, rootPackage) {
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   343
            @DefinedBy(Api.LANGUAGE_MODEL)
8621
ce0bce60cffc 7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents: 8242
diff changeset
   344
            public <R, P> R accept(ElementVisitor<R, P> v, P p) {
ce0bce60cffc 7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents: 8242
diff changeset
   345
                return v.visitUnknown(this, p);
ce0bce60cffc 7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents: 8242
diff changeset
   346
            }
ce0bce60cffc 7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents: 8242
diff changeset
   347
        };
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   348
06bc494ca11e Initial load
duke
parents:
diff changeset
   349
        // create the error symbols
06bc494ca11e Initial load
duke
parents:
diff changeset
   350
        errSymbol = new ClassSymbol(PUBLIC|STATIC|ACYCLIC, names.any, null, rootPackage);
8621
ce0bce60cffc 7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents: 8242
diff changeset
   351
        errType = new ErrorType(errSymbol, Type.noType);
ce0bce60cffc 7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents: 8242
diff changeset
   352
6594
d43f068fba19 6970584: Flow.java should be more error-friendly
mcimadamore
parents: 6148
diff changeset
   353
        unknownSymbol = new ClassSymbol(PUBLIC|STATIC|ACYCLIC, names.fromString("<any?>"), null, rootPackage);
8621
ce0bce60cffc 7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents: 8242
diff changeset
   354
        unknownSymbol.members_field = new Scope.ErrorScope(unknownSymbol);
ce0bce60cffc 7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents: 8242
diff changeset
   355
        unknownSymbol.type = unknownType;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
        // initialize builtin types
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
        initType(byteType, "byte", "Byte");
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
        initType(shortType, "short", "Short");
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
        initType(charType, "char", "Character");
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
        initType(intType, "int", "Integer");
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
        initType(longType, "long", "Long");
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
        initType(floatType, "float", "Float");
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
        initType(doubleType, "double", "Double");
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
        initType(booleanType, "boolean", "Boolean");
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
        initType(voidType, "void", "Void");
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
        initType(botType, "<nulltype>");
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
        initType(errType, errSymbol);
6594
d43f068fba19 6970584: Flow.java should be more error-friendly
mcimadamore
parents: 6148
diff changeset
   369
        initType(unknownType, unknownSymbol);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
        // the builtin class of all arrays
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
        arrayClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Array, noSymbol);
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
        // VGJ
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
        boundClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Bound, noSymbol);
8621
ce0bce60cffc 7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents: 8242
diff changeset
   376
        boundClass.members_field = new Scope.ErrorScope(boundClass);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
        // the builtin class of all methods
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
        methodClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Method, noSymbol);
8621
ce0bce60cffc 7021183: 269: assertion failure getting enclosing element of an undefined name
jjg
parents: 8242
diff changeset
   380
        methodClass.members_field = new Scope.ErrorScope(boundClass);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
        // Create class to hold all predefined constants and operations.
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
        predefClass = new ClassSymbol(PUBLIC|ACYCLIC, names.empty, rootPackage);
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24604
diff changeset
   384
        WriteableScope scope = WriteableScope.create(predefClass);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
        predefClass.members_field = scope;
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
24604
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 22442
diff changeset
   387
        // Get the initial completer for Symbols from the ClassFinder
7f68545b5128 8041422: Split javac ClassReader into ClassReader+ClassFinder
jjg
parents: 22442
diff changeset
   388
        initialCompleter = ClassFinder.instance(context).getCompleter();
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   389
        rootPackage.completer = initialCompleter;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   390
        unnamedPackage.completer = initialCompleter;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   391
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
        // Enter symbols for basic types.
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
        scope.enter(byteType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
        scope.enter(shortType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
        scope.enter(charType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
        scope.enter(intType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
        scope.enter(longType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
        scope.enter(floatType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
        scope.enter(doubleType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
        scope.enter(booleanType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
        scope.enter(errType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
1257
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1037
diff changeset
   403
        // Enter symbol for the errSymbol
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1037
diff changeset
   404
        scope.enter(errSymbol);
873b053bf757 6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents: 1037
diff changeset
   405
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
        classes.put(predefClass.fullname, predefClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
        // Enter predefined classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
        objectType = enterClass("java.lang.Object");
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
        classType = enterClass("java.lang.Class");
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
        stringType = enterClass("java.lang.String");
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
        stringBufferType = enterClass("java.lang.StringBuffer");
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
        stringBuilderType = enterClass("java.lang.StringBuilder");
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
        cloneableType = enterClass("java.lang.Cloneable");
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
        throwableType = enterClass("java.lang.Throwable");
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
        serializableType = enterClass("java.io.Serializable");
16300
7cf27559c8df 8004969: Generate $deserializeLambda$ method
rfield
parents: 15361
diff changeset
   417
        serializedLambdaType = enterClass("java.lang.invoke.SerializedLambda");
8241
4161b56e0d20 7017414: before the move of JSR 292 to package java.lang.invoke, javac must recognize the new package
mcimadamore
parents: 8036
diff changeset
   418
        methodHandleType = enterClass("java.lang.invoke.MethodHandle");
14365
20f388573215 8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents: 14359
diff changeset
   419
        methodHandleLookupType = enterClass("java.lang.invoke.MethodHandles$Lookup");
14046
8ef5d5b19998 7194586: Add back-end support for invokedynamic
mcimadamore
parents: 13844
diff changeset
   420
        methodTypeType = enterClass("java.lang.invoke.MethodType");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
        errorType = enterClass("java.lang.Error");
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
        illegalArgumentExceptionType = enterClass("java.lang.IllegalArgumentException");
9076
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents: 8621
diff changeset
   423
        interruptedExceptionType = enterClass("java.lang.InterruptedException");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
        exceptionType = enterClass("java.lang.Exception");
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
        runtimeExceptionType = enterClass("java.lang.RuntimeException");
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
        classNotFoundExceptionType = enterClass("java.lang.ClassNotFoundException");
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
        noClassDefFoundErrorType = enterClass("java.lang.NoClassDefFoundError");
06bc494ca11e Initial load
duke
parents:
diff changeset
   428
        noSuchFieldErrorType = enterClass("java.lang.NoSuchFieldError");
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
        assertionErrorType = enterClass("java.lang.AssertionError");
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
        cloneNotSupportedExceptionType = enterClass("java.lang.CloneNotSupportedException");
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
        annotationType = enterClass("java.lang.annotation.Annotation");
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
        classLoaderType = enterClass("java.lang.ClassLoader");
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   433
        enumSym = enterClass(names.java_lang_Enum);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
        enumFinalFinalize =
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
            new MethodSymbol(PROTECTED|FINAL|HYPOTHETICAL,
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
                             names.finalize,
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
                             new MethodType(List.<Type>nil(), voidType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   438
                                            List.<Type>nil(), methodClass),
06bc494ca11e Initial load
duke
parents:
diff changeset
   439
                             enumSym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   440
        listType = enterClass("java.util.List");
06bc494ca11e Initial load
duke
parents:
diff changeset
   441
        collectionsType = enterClass("java.util.Collections");
06bc494ca11e Initial load
duke
parents:
diff changeset
   442
        comparableType = enterClass("java.lang.Comparable");
16333
a6e1ded87200 8009138: javac, equals-hashCode warning tuning
vromero
parents: 16316
diff changeset
   443
        comparatorType = enterClass("java.util.Comparator");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
        arraysType = enterClass("java.util.Arrays");
25445
603f0c93d5c9 8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents: 25443
diff changeset
   445
        iterableType = enterClass("java.lang.Iterable");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
        iteratorType = enterClass("java.util.Iterator");
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
        annotationTargetType = enterClass("java.lang.annotation.Target");
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
        overrideType = enterClass("java.lang.Override");
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
        retentionType = enterClass("java.lang.annotation.Retention");
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
        deprecatedType = enterClass("java.lang.Deprecated");
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
        suppressWarningsType = enterClass("java.lang.SuppressWarnings");
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
        inheritedType = enterClass("java.lang.annotation.Inherited");
15356
cf312dc54c60 8006119: update javac to follow latest spec for repeatable annotations
jjg
parents: 14539
diff changeset
   453
        repeatableType = enterClass("java.lang.annotation.Repeatable");
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12335
diff changeset
   454
        documentedType = enterClass("java.lang.annotation.Documented");
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 12335
diff changeset
   455
        elementTypeType = enterClass("java.lang.annotation.ElementType");
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   456
        systemType = enterClass("java.lang.System");
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5857
diff changeset
   457
        autoCloseableType = enterClass("java.lang.AutoCloseable");
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5857
diff changeset
   458
        autoCloseableClose = new MethodSymbol(PUBLIC,
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5857
diff changeset
   459
                             names.close,
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5857
diff changeset
   460
                             new MethodType(List.<Type>nil(), voidType,
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5857
diff changeset
   461
                                            List.of(exceptionType), methodClass),
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5857
diff changeset
   462
                             autoCloseableType.tsym);
7643
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 6709
diff changeset
   463
        trustMeType = enterClass("java.lang.SafeVarargs");
14539
507556c4e622 8003412: javac needs to understand java.lang.annotation.Native
jjg
parents: 14365
diff changeset
   464
        nativeHeaderType = enterClass("java.lang.annotation.Native");
14365
20f388573215 8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents: 14359
diff changeset
   465
        lambdaMetafactory = enterClass("java.lang.invoke.LambdaMetafactory");
15361
01f1828683e6 8005299: Add FunctionalInterface checking to javac
mcimadamore
parents: 15356
diff changeset
   466
        functionalInterfaceType = enterClass("java.lang.FunctionalInterface");
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   467
9076
45c73da050e9 7027157: Project Coin: javac warnings for AutoCloseable.close throwing InterruptedException
mcimadamore
parents: 8621
diff changeset
   468
        synthesizeEmptyInterfaceIfMissing(autoCloseableType);
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   469
        synthesizeEmptyInterfaceIfMissing(cloneableType);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   470
        synthesizeEmptyInterfaceIfMissing(serializableType);
14365
20f388573215 8000694: Add generation of lambda implementation code: invokedynamic call, lambda method, adaptor methods
rfield
parents: 14359
diff changeset
   471
        synthesizeEmptyInterfaceIfMissing(lambdaMetafactory);
16300
7cf27559c8df 8004969: Generate $deserializeLambda$ method
rfield
parents: 15361
diff changeset
   472
        synthesizeEmptyInterfaceIfMissing(serializedLambdaType);
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   473
        synthesizeBoxTypeIfMissing(doubleType);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   474
        synthesizeBoxTypeIfMissing(floatType);
3555
a6fd77fe81df 6390045: Unexpected error "cannot access java.lang.Void" with '-target cldc1.0' with -source >=1.5
mcimadamore
parents: 2723
diff changeset
   475
        synthesizeBoxTypeIfMissing(voidType);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
5848
c5a4ce47e780 6960407: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5847
diff changeset
   477
        // Enter a synthetic class that is used to mark internal
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
        // proprietary classes in ct.sym.  This class does not have a
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
        // class file.
15724
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   480
        proprietaryType = enterSyntheticAnnotation("sun.Proprietary+Annotation");
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   481
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   482
        // Enter a synthetic class that is used to provide profile info for
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   483
        // classes in ct.sym.  This class does not have a class file.
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   484
        profileType = enterSyntheticAnnotation("jdk.Profile+Annotation");
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   485
        MethodSymbol m = new MethodSymbol(PUBLIC | ABSTRACT, names.value, intType, profileType.tsym);
3063fb01c8a1 8004182: Add support for profiles in javac
jjg
parents: 14539
diff changeset
   486
        profileType.tsym.members().enter(m);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
        // Enter a class for arrays.
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
        // The class implements java.lang.Cloneable and java.io.Serializable.
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
        // It has a final length field and a clone method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
        ClassType arrayClassType = (ClassType)arrayClass.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
        arrayClassType.supertype_field = objectType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
        arrayClassType.interfaces_field = List.of(cloneableType, serializableType);
25443
9187d77f2c64 8031569: Refactor javac scope implementation to enable lazy imports
jlahoda
parents: 24604
diff changeset
   494
        arrayClass.members_field = WriteableScope.create(arrayClass);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
        lengthVar = new VarSymbol(
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
            PUBLIC | FINAL,
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
            names.length,
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
            intType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
            arrayClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
        arrayClass.members().enter(lengthVar);
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
        arrayCloneMethod = new MethodSymbol(
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
            PUBLIC,
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
            names.clone,
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
            new MethodType(List.<Type>nil(), objectType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
                           List.<Type>nil(), methodClass),
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
            arrayClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
        arrayClass.members().enter(arrayCloneMethod);
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
    }
22442
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   509
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   510
    /** Define a new class given its name and owner.
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   511
     */
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   512
    public ClassSymbol defineClass(Name name, Symbol owner) {
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   513
        ClassSymbol c = new ClassSymbol(0, name, owner);
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   514
        if (owner.kind == PCK)
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   515
            Assert.checkNull(classes.get(c.flatname), c);
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   516
        c.completer = initialCompleter;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   517
        return c;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   518
    }
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   519
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   520
    /** Create a new toplevel or member class symbol with given name
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   521
     *  and owner and enter in `classes' unless already there.
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   522
     */
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   523
    public ClassSymbol enterClass(Name name, TypeSymbol owner) {
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   524
        Name flatname = TypeSymbol.formFlatName(name, owner);
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   525
        ClassSymbol c = classes.get(flatname);
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   526
        if (c == null) {
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   527
            c = defineClass(name, owner);
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   528
            classes.put(flatname, c);
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   529
        } else if ((c.name != name || c.owner != owner) && owner.kind == TYP && c.owner.kind == PCK) {
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   530
            // reassign fields of classes that might have been loaded with
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   531
            // their flat names.
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   532
            c.owner.members().remove(c);
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   533
            c.name = name;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   534
            c.owner = owner;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   535
            c.fullname = ClassSymbol.formFullName(name, owner);
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   536
        }
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   537
        return c;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   538
    }
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   539
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   540
    /**
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   541
     * Creates a new toplevel class symbol with given flat name and
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   542
     * given class (or source) file.
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   543
     *
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   544
     * @param flatName a fully qualified binary class name
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   545
     * @param classFile the class file or compilation unit defining
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   546
     * the class (may be {@code null})
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   547
     * @return a newly created class symbol
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   548
     * @throws AssertionError if the class symbol already exists
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   549
     */
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   550
    public ClassSymbol enterClass(Name flatName, JavaFileObject classFile) {
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   551
        ClassSymbol cs = classes.get(flatName);
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   552
        if (cs != null) {
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   553
            String msg = Log.format("%s: completer = %s; class file = %s; source file = %s",
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   554
                                    cs.fullname,
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   555
                                    cs.completer,
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   556
                                    cs.classfile,
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   557
                                    cs.sourcefile);
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   558
            throw new AssertionError(msg);
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   559
        }
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   560
        Name packageName = Convert.packagePart(flatName);
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   561
        PackageSymbol owner = packageName.isEmpty()
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   562
                                ? unnamedPackage
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   563
                                : enterPackage(packageName);
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   564
        cs = defineClass(Convert.shortName(flatName), owner);
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   565
        cs.classfile = classFile;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   566
        classes.put(flatName, cs);
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   567
        return cs;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   568
    }
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   569
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   570
    /** Create a new member or toplevel class symbol with given flat name
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   571
     *  and enter in `classes' unless already there.
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   572
     */
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   573
    public ClassSymbol enterClass(Name flatname) {
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   574
        ClassSymbol c = classes.get(flatname);
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   575
        if (c == null)
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   576
            return enterClass(flatname, (JavaFileObject)null);
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   577
        else
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   578
            return c;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   579
    }
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   580
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   581
    /** Check to see if a package exists, given its fully qualified name.
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   582
     */
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   583
    public boolean packageExists(Name fullname) {
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   584
        return enterPackage(fullname).exists();
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   585
    }
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   586
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   587
    /** Make a package, given its fully qualified name.
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   588
     */
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   589
    public PackageSymbol enterPackage(Name fullname) {
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   590
        PackageSymbol p = packages.get(fullname);
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   591
        if (p == null) {
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   592
            Assert.check(!fullname.isEmpty(), "rootPackage missing!");
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   593
            p = new PackageSymbol(
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   594
                Convert.shortName(fullname),
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   595
                enterPackage(Convert.packagePart(fullname)));
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   596
            p.completer = initialCompleter;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   597
            packages.put(fullname, p);
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   598
        }
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   599
        return p;
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   600
    }
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   601
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   602
    /** Make a package, given its unqualified name and enclosing package.
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   603
     */
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   604
    public PackageSymbol enterPackage(Name name, PackageSymbol owner) {
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   605
        return enterPackage(TypeSymbol.formFullName(name, owner));
8fd30fc4e3a3 8029690: Move symbol creation from ClassReader to Symtab
jfranck
parents: 22163
diff changeset
   606
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
}