langtools/src/share/classes/com/sun/tools/javac/code/Symtab.java
author jjg
Fri, 01 Aug 2008 15:23:18 -0700
changeset 1037 c6b315a34dc6
parent 10 06bc494ca11e
child 1257 873b053bf757
permissions -rw-r--r--
6627362: javac generates code that uses array.clone, which is not available on JavaCard 6627364: javac needs Float and Double on the bootclasspath even when not directly used 6627366: javac needs Cloneable and Serializable on the classpath even when not directly used Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
     2
 * Copyright 1999-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import java.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import com.sun.tools.javac.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import com.sun.tools.javac.util.List;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import com.sun.tools.javac.code.Symbol.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
import com.sun.tools.javac.code.Type.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import com.sun.tools.javac.jvm.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
import static com.sun.tools.javac.jvm.ByteCodes.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
import static com.sun.tools.javac.code.Flags.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
/** A class that defines all predefined constants and operators
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 *  as well as special classes such as java.lang.Object, which need
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 *  to be known to the compiler. All symbols are held in instance
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 *  fields. This makes it possible to work in multiple concurrent
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 *  projects, which might use different class files for library classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
 *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 *  you write code that depends on this, you do so at your own risk.
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
public class Symtab {
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
    /** The context key for the symbol table. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    protected static final Context.Key<Symtab> symtabKey =
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
        new Context.Key<Symtab>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    /** Get the symbol table instance. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
    public static Symtab instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
        Symtab instance = context.get(symtabKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
        if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
            instance = new Symtab(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    /** Builtin types.
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    public final Type byteType = new Type(TypeTags.BYTE, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
    public final Type charType = new Type(TypeTags.CHAR, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
    public final Type shortType = new Type(TypeTags.SHORT, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
    public final Type intType = new Type(TypeTags.INT, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    public final Type longType = new Type(TypeTags.LONG, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
    public final Type floatType = new Type(TypeTags.FLOAT, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
    public final Type doubleType = new Type(TypeTags.DOUBLE, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
    public final Type booleanType = new Type(TypeTags.BOOLEAN, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
    public final Type botType = new BottomType();
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
    public final JCNoType voidType = new JCNoType(TypeTags.VOID);
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
    private final Name.Table names;
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
    private final ClassReader reader;
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
    78
    private final Target target;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    /** A symbol for the root package.
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    public final PackageSymbol rootPackage;
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    /** A symbol for the unnamed package.
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    public final PackageSymbol unnamedPackage;
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    /** A symbol that stands for a missing symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    public final TypeSymbol noSymbol;
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    /** The error symbol.
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
    public final ClassSymbol errSymbol;
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
    /** An instance of the error type.
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
    public final Type errType;
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    /** A value for the unknown type. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    public final Type unknownType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
    /** The builtin type of all arrays. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
    public final ClassSymbol arrayClass;
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
    public final MethodSymbol arrayCloneMethod;
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
    /** VGJ: The (singleton) type of all bound types. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
    public final ClassSymbol boundClass;
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
    /** The builtin type of all methods. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    public final ClassSymbol methodClass;
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
    /** Predefined types.
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    public final Type objectType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    public final Type classType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
    public final Type classLoaderType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
    public final Type stringType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
    public final Type stringBufferType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
    public final Type stringBuilderType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
    public final Type cloneableType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
    public final Type serializableType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    public final Type throwableType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
    public final Type errorType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    public final Type illegalArgumentExceptionType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    public final Type exceptionType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
    public final Type runtimeExceptionType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    public final Type classNotFoundExceptionType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
    public final Type noClassDefFoundErrorType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
    public final Type noSuchFieldErrorType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
    public final Type assertionErrorType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
    public final Type cloneNotSupportedExceptionType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    public final Type annotationType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
    public final TypeSymbol enumSym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
    public final Type listType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
    public final Type collectionsType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
    public final Type comparableType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
    public final Type arraysType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
    public final Type iterableType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
    public final Type iteratorType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
    public final Type annotationTargetType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
    public final Type overrideType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
    public final Type retentionType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
    public final Type deprecatedType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    public final Type suppressWarningsType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
    public final Type inheritedType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    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
   148
    public final Type systemType;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
    /** The symbol representing the length field of an array.
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
    public final VarSymbol lengthVar;
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
    /** The null check operator. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
    public final OperatorSymbol nullcheck;
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
    /** The symbol representing the final finalize method on enums */
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
    public final MethodSymbol enumFinalFinalize;
06bc494ca11e Initial load
duke
parents:
diff changeset
   159
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
    /** The predefined type that belongs to a tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
    public final Type[] typeOfTag = new Type[TypeTags.TypeTagCount];
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
06bc494ca11e Initial load
duke
parents:
diff changeset
   164
    /** The name of the class that belongs to a basix type tag.
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   166
    public final Name[] boxedName = new Name[TypeTags.TypeTagCount];
06bc494ca11e Initial load
duke
parents:
diff changeset
   167
06bc494ca11e Initial load
duke
parents:
diff changeset
   168
    /** A hashtable containing the encountered top-level and member classes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   169
     *  indexed by flat names. The table does not contain local classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     *  It should be updated from the outside to reflect classes defined
06bc494ca11e Initial load
duke
parents:
diff changeset
   171
     *  by compiled source files.
06bc494ca11e Initial load
duke
parents:
diff changeset
   172
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   173
    public final Map<Name, ClassSymbol> classes = new HashMap<Name, ClassSymbol>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   174
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
    /** A hashtable containing the encountered packages.
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
     *  the table should be updated from outside to reflect packages defined
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
     *  by compiled source files.
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
    public final Map<Name, PackageSymbol> packages = new HashMap<Name, PackageSymbol>();
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
    public void initType(Type type, ClassSymbol c) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
        type.tsym = c;
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
        typeOfTag[type.tag] = type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
    public void initType(Type type, String name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
        initType(
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
            type,
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
            new ClassSymbol(
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
                PUBLIC, names.fromString(name), type, rootPackage));
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
    public void initType(Type type, String name, String bname) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   194
        initType(type, name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   195
        boxedName[type.tag] = names.fromString("java.lang." + bname);
06bc494ca11e Initial load
duke
parents:
diff changeset
   196
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   197
06bc494ca11e Initial load
duke
parents:
diff changeset
   198
    /** The class symbol that owns all predefined symbols.
06bc494ca11e Initial load
duke
parents:
diff changeset
   199
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   200
    public final ClassSymbol predefClass;
06bc494ca11e Initial load
duke
parents:
diff changeset
   201
06bc494ca11e Initial load
duke
parents:
diff changeset
   202
    /** Enter a constant into symbol table.
06bc494ca11e Initial load
duke
parents:
diff changeset
   203
     *  @param name   The constant's name.
06bc494ca11e Initial load
duke
parents:
diff changeset
   204
     *  @param type   The constant's type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   205
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   206
    private VarSymbol enterConstant(String name, Type type) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   207
        VarSymbol c = new VarSymbol(
06bc494ca11e Initial load
duke
parents:
diff changeset
   208
            PUBLIC | STATIC | FINAL,
06bc494ca11e Initial load
duke
parents:
diff changeset
   209
            names.fromString(name),
06bc494ca11e Initial load
duke
parents:
diff changeset
   210
            type,
06bc494ca11e Initial load
duke
parents:
diff changeset
   211
            predefClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
   212
        c.setData(type.constValue());
06bc494ca11e Initial load
duke
parents:
diff changeset
   213
        predefClass.members().enter(c);
06bc494ca11e Initial load
duke
parents:
diff changeset
   214
        return c;
06bc494ca11e Initial load
duke
parents:
diff changeset
   215
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   216
06bc494ca11e Initial load
duke
parents:
diff changeset
   217
    /** Enter a binary operation into symbol table.
06bc494ca11e Initial load
duke
parents:
diff changeset
   218
     *  @param name     The name of the operator.
06bc494ca11e Initial load
duke
parents:
diff changeset
   219
     *  @param left     The type of the left operand.
06bc494ca11e Initial load
duke
parents:
diff changeset
   220
     *  @param right    The type of the left operand.
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
     *  @param res      The operation's result type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   222
     *  @param opcode   The operation's bytecode instruction.
06bc494ca11e Initial load
duke
parents:
diff changeset
   223
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   224
    private void enterBinop(String name,
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
                            Type left, Type right, Type res,
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
                            int opcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
        predefClass.members().enter(
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
            new OperatorSymbol(
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
                names.fromString(name),
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
                new MethodType(List.of(left, right), res,
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
                               List.<Type>nil(), methodClass),
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
                opcode,
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
                predefClass));
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
    /** Enter a binary operation, as above but with two opcodes,
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
     *  which get encoded as (opcode1 << ByteCodeTags.preShift) + opcode2.
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
     *  @param opcode1     First opcode.
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
     *  @param opcode2     Second opcode.
06bc494ca11e Initial load
duke
parents:
diff changeset
   240
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
    private void enterBinop(String name,
06bc494ca11e Initial load
duke
parents:
diff changeset
   242
                            Type left, Type right, Type res,
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
                            int opcode1, int opcode2) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
        enterBinop(
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
            name, left, right, res, (opcode1 << ByteCodes.preShift) | opcode2);
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
06bc494ca11e Initial load
duke
parents:
diff changeset
   248
    /** Enter a unary operation into symbol table.
06bc494ca11e Initial load
duke
parents:
diff changeset
   249
     *  @param name     The name of the operator.
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
     *  @param arg      The type of the operand.
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
     *  @param res      The operation's result type.
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
     *  @param opcode   The operation's bytecode instruction.
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
    private OperatorSymbol enterUnop(String name,
06bc494ca11e Initial load
duke
parents:
diff changeset
   255
                                     Type arg,
06bc494ca11e Initial load
duke
parents:
diff changeset
   256
                                     Type res,
06bc494ca11e Initial load
duke
parents:
diff changeset
   257
                                     int opcode) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   258
        OperatorSymbol sym =
06bc494ca11e Initial load
duke
parents:
diff changeset
   259
            new OperatorSymbol(names.fromString(name),
06bc494ca11e Initial load
duke
parents:
diff changeset
   260
                               new MethodType(List.of(arg),
06bc494ca11e Initial load
duke
parents:
diff changeset
   261
                                              res,
06bc494ca11e Initial load
duke
parents:
diff changeset
   262
                                              List.<Type>nil(),
06bc494ca11e Initial load
duke
parents:
diff changeset
   263
                                              methodClass),
06bc494ca11e Initial load
duke
parents:
diff changeset
   264
                               opcode,
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
                               predefClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
        predefClass.members().enter(sym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
        return sym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
    /** Enter a class into symbol table.
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
     *  @param    The name of the class.
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   273
    private Type enterClass(String s) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
        return reader.enterClass(names.fromString(s)).type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   275
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   277
    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
   278
        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
   279
        if (completer != null) {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   280
            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
   281
                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
   282
                    try {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   283
                        completer.complete(sym);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   284
                    } catch (CompletionFailure e) {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   285
                        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
   286
                        ((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
   287
                    }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   288
                }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   289
            };
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   290
        }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   291
    }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   292
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   293
    public void synthesizeBoxTypeIfMissing(final Type type) {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   294
        ClassSymbol sym = reader.enterClass(boxedName[type.tag]);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   295
        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
   296
        if (completer != null) {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   297
            sym.completer = new Completer() {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   298
                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
   299
                    try {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   300
                        completer.complete(sym);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   301
                    } catch (CompletionFailure e) {
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   302
                        sym.flags_field |= PUBLIC;
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   303
                        ((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
   304
                        Name n = target.boxWithConstructors() ? names.init : names.valueOf;
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   305
                        MethodSymbol boxMethod =
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   306
                            new MethodSymbol(PUBLIC | STATIC,
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   307
                                n,
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   308
                                new MethodType(List.of(type), sym.type,
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   309
                                    List.<Type>nil(), methodClass),
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   310
                                sym);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   311
                        sym.members().enter(boxMethod);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   312
                        MethodSymbol unboxMethod =
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   313
                            new MethodSymbol(PUBLIC,
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   314
                                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
   315
                                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
   316
                                    List.<Type>nil(), methodClass),
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   317
                                sym);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   318
                        sym.members().enter(unboxMethod);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   319
                    }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   320
                }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   321
            };
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   322
        }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   323
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   324
    }
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   325
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   326
    /** Constructor; enters all predefined identifiers and operators
06bc494ca11e Initial load
duke
parents:
diff changeset
   327
     *  into symbol table.
06bc494ca11e Initial load
duke
parents:
diff changeset
   328
     */
06bc494ca11e Initial load
duke
parents:
diff changeset
   329
    protected Symtab(Context context) throws CompletionFailure {
06bc494ca11e Initial load
duke
parents:
diff changeset
   330
        context.put(symtabKey, this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   331
06bc494ca11e Initial load
duke
parents:
diff changeset
   332
        names = Name.Table.instance(context);
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   333
        target = Target.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   334
06bc494ca11e Initial load
duke
parents:
diff changeset
   335
        // Create the unknown type
06bc494ca11e Initial load
duke
parents:
diff changeset
   336
        unknownType = new Type(TypeTags.UNKNOWN, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   337
06bc494ca11e Initial load
duke
parents:
diff changeset
   338
        // create the basic builtin symbols
06bc494ca11e Initial load
duke
parents:
diff changeset
   339
        rootPackage = new PackageSymbol(names.empty, null);
06bc494ca11e Initial load
duke
parents:
diff changeset
   340
        final Messages messages = Messages.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   341
        unnamedPackage = new PackageSymbol(names.empty, rootPackage) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   342
                public String toString() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   343
                    return messages.getLocalizedString("compiler.misc.unnamed.package");
06bc494ca11e Initial load
duke
parents:
diff changeset
   344
                }
06bc494ca11e Initial load
duke
parents:
diff changeset
   345
            };
06bc494ca11e Initial load
duke
parents:
diff changeset
   346
        noSymbol = new TypeSymbol(0, names.empty, Type.noType, rootPackage);
06bc494ca11e Initial load
duke
parents:
diff changeset
   347
        noSymbol.kind = Kinds.NIL;
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);
06bc494ca11e Initial load
duke
parents:
diff changeset
   351
        errType = new ErrorType(errSymbol);
06bc494ca11e Initial load
duke
parents:
diff changeset
   352
06bc494ca11e Initial load
duke
parents:
diff changeset
   353
        // initialize builtin types
06bc494ca11e Initial load
duke
parents:
diff changeset
   354
        initType(byteType, "byte", "Byte");
06bc494ca11e Initial load
duke
parents:
diff changeset
   355
        initType(shortType, "short", "Short");
06bc494ca11e Initial load
duke
parents:
diff changeset
   356
        initType(charType, "char", "Character");
06bc494ca11e Initial load
duke
parents:
diff changeset
   357
        initType(intType, "int", "Integer");
06bc494ca11e Initial load
duke
parents:
diff changeset
   358
        initType(longType, "long", "Long");
06bc494ca11e Initial load
duke
parents:
diff changeset
   359
        initType(floatType, "float", "Float");
06bc494ca11e Initial load
duke
parents:
diff changeset
   360
        initType(doubleType, "double", "Double");
06bc494ca11e Initial load
duke
parents:
diff changeset
   361
        initType(booleanType, "boolean", "Boolean");
06bc494ca11e Initial load
duke
parents:
diff changeset
   362
        initType(voidType, "void", "Void");
06bc494ca11e Initial load
duke
parents:
diff changeset
   363
        initType(botType, "<nulltype>");
06bc494ca11e Initial load
duke
parents:
diff changeset
   364
        initType(errType, errSymbol);
06bc494ca11e Initial load
duke
parents:
diff changeset
   365
        initType(unknownType, "<any?>");
06bc494ca11e Initial load
duke
parents:
diff changeset
   366
06bc494ca11e Initial load
duke
parents:
diff changeset
   367
        // the builtin class of all arrays
06bc494ca11e Initial load
duke
parents:
diff changeset
   368
        arrayClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Array, noSymbol);
06bc494ca11e Initial load
duke
parents:
diff changeset
   369
06bc494ca11e Initial load
duke
parents:
diff changeset
   370
        // VGJ
06bc494ca11e Initial load
duke
parents:
diff changeset
   371
        boundClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Bound, noSymbol);
06bc494ca11e Initial load
duke
parents:
diff changeset
   372
06bc494ca11e Initial load
duke
parents:
diff changeset
   373
        // the builtin class of all methods
06bc494ca11e Initial load
duke
parents:
diff changeset
   374
        methodClass = new ClassSymbol(PUBLIC|ACYCLIC, names.Method, noSymbol);
06bc494ca11e Initial load
duke
parents:
diff changeset
   375
06bc494ca11e Initial load
duke
parents:
diff changeset
   376
        // Create class to hold all predefined constants and operations.
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
        predefClass = new ClassSymbol(PUBLIC|ACYCLIC, names.empty, rootPackage);
06bc494ca11e Initial load
duke
parents:
diff changeset
   378
        Scope scope = new Scope(predefClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
        predefClass.members_field = scope;
06bc494ca11e Initial load
duke
parents:
diff changeset
   380
06bc494ca11e Initial load
duke
parents:
diff changeset
   381
        // Enter symbols for basic types.
06bc494ca11e Initial load
duke
parents:
diff changeset
   382
        scope.enter(byteType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   383
        scope.enter(shortType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   384
        scope.enter(charType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   385
        scope.enter(intType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   386
        scope.enter(longType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   387
        scope.enter(floatType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   388
        scope.enter(doubleType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   389
        scope.enter(booleanType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   390
        scope.enter(errType.tsym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   391
06bc494ca11e Initial load
duke
parents:
diff changeset
   392
        classes.put(predefClass.fullname, predefClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
   393
06bc494ca11e Initial load
duke
parents:
diff changeset
   394
        reader = ClassReader.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   395
        reader.init(this);
06bc494ca11e Initial load
duke
parents:
diff changeset
   396
06bc494ca11e Initial load
duke
parents:
diff changeset
   397
        // Enter predefined classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
   398
        objectType = enterClass("java.lang.Object");
06bc494ca11e Initial load
duke
parents:
diff changeset
   399
        classType = enterClass("java.lang.Class");
06bc494ca11e Initial load
duke
parents:
diff changeset
   400
        stringType = enterClass("java.lang.String");
06bc494ca11e Initial load
duke
parents:
diff changeset
   401
        stringBufferType = enterClass("java.lang.StringBuffer");
06bc494ca11e Initial load
duke
parents:
diff changeset
   402
        stringBuilderType = enterClass("java.lang.StringBuilder");
06bc494ca11e Initial load
duke
parents:
diff changeset
   403
        cloneableType = enterClass("java.lang.Cloneable");
06bc494ca11e Initial load
duke
parents:
diff changeset
   404
        throwableType = enterClass("java.lang.Throwable");
06bc494ca11e Initial load
duke
parents:
diff changeset
   405
        serializableType = enterClass("java.io.Serializable");
06bc494ca11e Initial load
duke
parents:
diff changeset
   406
        errorType = enterClass("java.lang.Error");
06bc494ca11e Initial load
duke
parents:
diff changeset
   407
        illegalArgumentExceptionType = enterClass("java.lang.IllegalArgumentException");
06bc494ca11e Initial load
duke
parents:
diff changeset
   408
        exceptionType = enterClass("java.lang.Exception");
06bc494ca11e Initial load
duke
parents:
diff changeset
   409
        runtimeExceptionType = enterClass("java.lang.RuntimeException");
06bc494ca11e Initial load
duke
parents:
diff changeset
   410
        classNotFoundExceptionType = enterClass("java.lang.ClassNotFoundException");
06bc494ca11e Initial load
duke
parents:
diff changeset
   411
        noClassDefFoundErrorType = enterClass("java.lang.NoClassDefFoundError");
06bc494ca11e Initial load
duke
parents:
diff changeset
   412
        noSuchFieldErrorType = enterClass("java.lang.NoSuchFieldError");
06bc494ca11e Initial load
duke
parents:
diff changeset
   413
        assertionErrorType = enterClass("java.lang.AssertionError");
06bc494ca11e Initial load
duke
parents:
diff changeset
   414
        cloneNotSupportedExceptionType = enterClass("java.lang.CloneNotSupportedException");
06bc494ca11e Initial load
duke
parents:
diff changeset
   415
        annotationType = enterClass("java.lang.annotation.Annotation");
06bc494ca11e Initial load
duke
parents:
diff changeset
   416
        classLoaderType = enterClass("java.lang.ClassLoader");
06bc494ca11e Initial load
duke
parents:
diff changeset
   417
        enumSym = reader.enterClass(names.java_lang_Enum);
06bc494ca11e Initial load
duke
parents:
diff changeset
   418
        enumFinalFinalize =
06bc494ca11e Initial load
duke
parents:
diff changeset
   419
            new MethodSymbol(PROTECTED|FINAL|HYPOTHETICAL,
06bc494ca11e Initial load
duke
parents:
diff changeset
   420
                             names.finalize,
06bc494ca11e Initial load
duke
parents:
diff changeset
   421
                             new MethodType(List.<Type>nil(), voidType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   422
                                            List.<Type>nil(), methodClass),
06bc494ca11e Initial load
duke
parents:
diff changeset
   423
                             enumSym);
06bc494ca11e Initial load
duke
parents:
diff changeset
   424
        listType = enterClass("java.util.List");
06bc494ca11e Initial load
duke
parents:
diff changeset
   425
        collectionsType = enterClass("java.util.Collections");
06bc494ca11e Initial load
duke
parents:
diff changeset
   426
        comparableType = enterClass("java.lang.Comparable");
06bc494ca11e Initial load
duke
parents:
diff changeset
   427
        arraysType = enterClass("java.util.Arrays");
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   428
        iterableType = target.hasIterable()
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   429
            ? enterClass("java.lang.Iterable")
06bc494ca11e Initial load
duke
parents:
diff changeset
   430
            : enterClass("java.util.Collection");
06bc494ca11e Initial load
duke
parents:
diff changeset
   431
        iteratorType = enterClass("java.util.Iterator");
06bc494ca11e Initial load
duke
parents:
diff changeset
   432
        annotationTargetType = enterClass("java.lang.annotation.Target");
06bc494ca11e Initial load
duke
parents:
diff changeset
   433
        overrideType = enterClass("java.lang.Override");
06bc494ca11e Initial load
duke
parents:
diff changeset
   434
        retentionType = enterClass("java.lang.annotation.Retention");
06bc494ca11e Initial load
duke
parents:
diff changeset
   435
        deprecatedType = enterClass("java.lang.Deprecated");
06bc494ca11e Initial load
duke
parents:
diff changeset
   436
        suppressWarningsType = enterClass("java.lang.SuppressWarnings");
06bc494ca11e Initial load
duke
parents:
diff changeset
   437
        inheritedType = enterClass("java.lang.annotation.Inherited");
1037
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   438
        systemType = enterClass("java.lang.System");
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   439
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   440
        synthesizeEmptyInterfaceIfMissing(cloneableType);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   441
        synthesizeEmptyInterfaceIfMissing(serializableType);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   442
        synthesizeBoxTypeIfMissing(doubleType);
c6b315a34dc6 6627362: javac generates code that uses array.clone, which is not available on JavaCard
jjg
parents: 10
diff changeset
   443
        synthesizeBoxTypeIfMissing(floatType);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   444
06bc494ca11e Initial load
duke
parents:
diff changeset
   445
        // Enter a synthetic class that is used to mark Sun
06bc494ca11e Initial load
duke
parents:
diff changeset
   446
        // proprietary classes in ct.sym.  This class does not have a
06bc494ca11e Initial load
duke
parents:
diff changeset
   447
        // class file.
06bc494ca11e Initial load
duke
parents:
diff changeset
   448
        ClassType proprietaryType = (ClassType)enterClass("sun.Proprietary+Annotation");
06bc494ca11e Initial load
duke
parents:
diff changeset
   449
        this.proprietaryType = proprietaryType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   450
        ClassSymbol proprietarySymbol = (ClassSymbol)proprietaryType.tsym;
06bc494ca11e Initial load
duke
parents:
diff changeset
   451
        proprietarySymbol.completer = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   452
        proprietarySymbol.flags_field = PUBLIC|ACYCLIC|ANNOTATION|INTERFACE;
06bc494ca11e Initial load
duke
parents:
diff changeset
   453
        proprietarySymbol.erasure_field = proprietaryType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   454
        proprietarySymbol.members_field = new Scope(proprietarySymbol);
06bc494ca11e Initial load
duke
parents:
diff changeset
   455
        proprietaryType.typarams_field = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   456
        proprietaryType.allparams_field = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   457
        proprietaryType.supertype_field = annotationType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   458
        proprietaryType.interfaces_field = List.nil();
06bc494ca11e Initial load
duke
parents:
diff changeset
   459
06bc494ca11e Initial load
duke
parents:
diff changeset
   460
        // Enter a class for arrays.
06bc494ca11e Initial load
duke
parents:
diff changeset
   461
        // The class implements java.lang.Cloneable and java.io.Serializable.
06bc494ca11e Initial load
duke
parents:
diff changeset
   462
        // It has a final length field and a clone method.
06bc494ca11e Initial load
duke
parents:
diff changeset
   463
        ClassType arrayClassType = (ClassType)arrayClass.type;
06bc494ca11e Initial load
duke
parents:
diff changeset
   464
        arrayClassType.supertype_field = objectType;
06bc494ca11e Initial load
duke
parents:
diff changeset
   465
        arrayClassType.interfaces_field = List.of(cloneableType, serializableType);
06bc494ca11e Initial load
duke
parents:
diff changeset
   466
        arrayClass.members_field = new Scope(arrayClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
   467
        lengthVar = new VarSymbol(
06bc494ca11e Initial load
duke
parents:
diff changeset
   468
            PUBLIC | FINAL,
06bc494ca11e Initial load
duke
parents:
diff changeset
   469
            names.length,
06bc494ca11e Initial load
duke
parents:
diff changeset
   470
            intType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   471
            arrayClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
   472
        arrayClass.members().enter(lengthVar);
06bc494ca11e Initial load
duke
parents:
diff changeset
   473
        arrayCloneMethod = new MethodSymbol(
06bc494ca11e Initial load
duke
parents:
diff changeset
   474
            PUBLIC,
06bc494ca11e Initial load
duke
parents:
diff changeset
   475
            names.clone,
06bc494ca11e Initial load
duke
parents:
diff changeset
   476
            new MethodType(List.<Type>nil(), objectType,
06bc494ca11e Initial load
duke
parents:
diff changeset
   477
                           List.<Type>nil(), methodClass),
06bc494ca11e Initial load
duke
parents:
diff changeset
   478
            arrayClass);
06bc494ca11e Initial load
duke
parents:
diff changeset
   479
        arrayClass.members().enter(arrayCloneMethod);
06bc494ca11e Initial load
duke
parents:
diff changeset
   480
06bc494ca11e Initial load
duke
parents:
diff changeset
   481
        // Enter operators.
06bc494ca11e Initial load
duke
parents:
diff changeset
   482
        enterUnop("+", doubleType, doubleType, nop);
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
        enterUnop("+", floatType, floatType, nop);
06bc494ca11e Initial load
duke
parents:
diff changeset
   484
        enterUnop("+", longType, longType, nop);
06bc494ca11e Initial load
duke
parents:
diff changeset
   485
        enterUnop("+", intType, intType, nop);
06bc494ca11e Initial load
duke
parents:
diff changeset
   486
06bc494ca11e Initial load
duke
parents:
diff changeset
   487
        enterUnop("-", doubleType, doubleType, dneg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   488
        enterUnop("-", floatType, floatType, fneg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   489
        enterUnop("-", longType, longType, lneg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   490
        enterUnop("-", intType, intType, ineg);
06bc494ca11e Initial load
duke
parents:
diff changeset
   491
06bc494ca11e Initial load
duke
parents:
diff changeset
   492
        enterUnop("~", longType, longType, lxor);
06bc494ca11e Initial load
duke
parents:
diff changeset
   493
        enterUnop("~", intType, intType, ixor);
06bc494ca11e Initial load
duke
parents:
diff changeset
   494
06bc494ca11e Initial load
duke
parents:
diff changeset
   495
        enterUnop("++", doubleType, doubleType, dadd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   496
        enterUnop("++", floatType, floatType, fadd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   497
        enterUnop("++", longType, longType, ladd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   498
        enterUnop("++", intType, intType, iadd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   499
        enterUnop("++", charType, charType, iadd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   500
        enterUnop("++", shortType, shortType, iadd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   501
        enterUnop("++", byteType, byteType, iadd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   502
06bc494ca11e Initial load
duke
parents:
diff changeset
   503
        enterUnop("--", doubleType, doubleType, dsub);
06bc494ca11e Initial load
duke
parents:
diff changeset
   504
        enterUnop("--", floatType, floatType, fsub);
06bc494ca11e Initial load
duke
parents:
diff changeset
   505
        enterUnop("--", longType, longType, lsub);
06bc494ca11e Initial load
duke
parents:
diff changeset
   506
        enterUnop("--", intType, intType, isub);
06bc494ca11e Initial load
duke
parents:
diff changeset
   507
        enterUnop("--", charType, charType, isub);
06bc494ca11e Initial load
duke
parents:
diff changeset
   508
        enterUnop("--", shortType, shortType, isub);
06bc494ca11e Initial load
duke
parents:
diff changeset
   509
        enterUnop("--", byteType, byteType, isub);
06bc494ca11e Initial load
duke
parents:
diff changeset
   510
06bc494ca11e Initial load
duke
parents:
diff changeset
   511
        enterUnop("!", booleanType, booleanType, bool_not);
06bc494ca11e Initial load
duke
parents:
diff changeset
   512
        nullcheck = enterUnop("<*nullchk*>", objectType, objectType, nullchk);
06bc494ca11e Initial load
duke
parents:
diff changeset
   513
06bc494ca11e Initial load
duke
parents:
diff changeset
   514
        // string concatenation
06bc494ca11e Initial load
duke
parents:
diff changeset
   515
        enterBinop("+", stringType, objectType, stringType, string_add);
06bc494ca11e Initial load
duke
parents:
diff changeset
   516
        enterBinop("+", objectType, stringType, stringType, string_add);
06bc494ca11e Initial load
duke
parents:
diff changeset
   517
        enterBinop("+", stringType, stringType, stringType, string_add);
06bc494ca11e Initial load
duke
parents:
diff changeset
   518
        enterBinop("+", stringType, intType, stringType, string_add);
06bc494ca11e Initial load
duke
parents:
diff changeset
   519
        enterBinop("+", stringType, longType, stringType, string_add);
06bc494ca11e Initial load
duke
parents:
diff changeset
   520
        enterBinop("+", stringType, floatType, stringType, string_add);
06bc494ca11e Initial load
duke
parents:
diff changeset
   521
        enterBinop("+", stringType, doubleType, stringType, string_add);
06bc494ca11e Initial load
duke
parents:
diff changeset
   522
        enterBinop("+", stringType, booleanType, stringType, string_add);
06bc494ca11e Initial load
duke
parents:
diff changeset
   523
        enterBinop("+", stringType, botType, stringType, string_add);
06bc494ca11e Initial load
duke
parents:
diff changeset
   524
        enterBinop("+", intType, stringType, stringType, string_add);
06bc494ca11e Initial load
duke
parents:
diff changeset
   525
        enterBinop("+", longType, stringType, stringType, string_add);
06bc494ca11e Initial load
duke
parents:
diff changeset
   526
        enterBinop("+", floatType, stringType, stringType, string_add);
06bc494ca11e Initial load
duke
parents:
diff changeset
   527
        enterBinop("+", doubleType, stringType, stringType, string_add);
06bc494ca11e Initial load
duke
parents:
diff changeset
   528
        enterBinop("+", booleanType, stringType, stringType, string_add);
06bc494ca11e Initial load
duke
parents:
diff changeset
   529
        enterBinop("+", botType, stringType, stringType, string_add);
06bc494ca11e Initial load
duke
parents:
diff changeset
   530
06bc494ca11e Initial load
duke
parents:
diff changeset
   531
        // these errors would otherwise be matched as string concatenation
06bc494ca11e Initial load
duke
parents:
diff changeset
   532
        enterBinop("+", botType, botType, botType, error);
06bc494ca11e Initial load
duke
parents:
diff changeset
   533
        enterBinop("+", botType, intType, botType, error);
06bc494ca11e Initial load
duke
parents:
diff changeset
   534
        enterBinop("+", botType, longType, botType, error);
06bc494ca11e Initial load
duke
parents:
diff changeset
   535
        enterBinop("+", botType, floatType, botType, error);
06bc494ca11e Initial load
duke
parents:
diff changeset
   536
        enterBinop("+", botType, doubleType, botType, error);
06bc494ca11e Initial load
duke
parents:
diff changeset
   537
        enterBinop("+", botType, booleanType, botType, error);
06bc494ca11e Initial load
duke
parents:
diff changeset
   538
        enterBinop("+", botType, objectType, botType, error);
06bc494ca11e Initial load
duke
parents:
diff changeset
   539
        enterBinop("+", intType, botType, botType, error);
06bc494ca11e Initial load
duke
parents:
diff changeset
   540
        enterBinop("+", longType, botType, botType, error);
06bc494ca11e Initial load
duke
parents:
diff changeset
   541
        enterBinop("+", floatType, botType, botType, error);
06bc494ca11e Initial load
duke
parents:
diff changeset
   542
        enterBinop("+", doubleType, botType, botType, error);
06bc494ca11e Initial load
duke
parents:
diff changeset
   543
        enterBinop("+", booleanType, botType, botType, error);
06bc494ca11e Initial load
duke
parents:
diff changeset
   544
        enterBinop("+", objectType, botType, botType, error);
06bc494ca11e Initial load
duke
parents:
diff changeset
   545
06bc494ca11e Initial load
duke
parents:
diff changeset
   546
        enterBinop("+", doubleType, doubleType, doubleType, dadd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   547
        enterBinop("+", floatType, floatType, floatType, fadd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   548
        enterBinop("+", longType, longType, longType, ladd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   549
        enterBinop("+", intType, intType, intType, iadd);
06bc494ca11e Initial load
duke
parents:
diff changeset
   550
06bc494ca11e Initial load
duke
parents:
diff changeset
   551
        enterBinop("-", doubleType, doubleType, doubleType, dsub);
06bc494ca11e Initial load
duke
parents:
diff changeset
   552
        enterBinop("-", floatType, floatType, floatType, fsub);
06bc494ca11e Initial load
duke
parents:
diff changeset
   553
        enterBinop("-", longType, longType, longType, lsub);
06bc494ca11e Initial load
duke
parents:
diff changeset
   554
        enterBinop("-", intType, intType, intType, isub);
06bc494ca11e Initial load
duke
parents:
diff changeset
   555
06bc494ca11e Initial load
duke
parents:
diff changeset
   556
        enterBinop("*", doubleType, doubleType, doubleType, dmul);
06bc494ca11e Initial load
duke
parents:
diff changeset
   557
        enterBinop("*", floatType, floatType, floatType, fmul);
06bc494ca11e Initial load
duke
parents:
diff changeset
   558
        enterBinop("*", longType, longType, longType, lmul);
06bc494ca11e Initial load
duke
parents:
diff changeset
   559
        enterBinop("*", intType, intType, intType, imul);
06bc494ca11e Initial load
duke
parents:
diff changeset
   560
06bc494ca11e Initial load
duke
parents:
diff changeset
   561
        enterBinop("/", doubleType, doubleType, doubleType, ddiv);
06bc494ca11e Initial load
duke
parents:
diff changeset
   562
        enterBinop("/", floatType, floatType, floatType, fdiv);
06bc494ca11e Initial load
duke
parents:
diff changeset
   563
        enterBinop("/", longType, longType, longType, ldiv);
06bc494ca11e Initial load
duke
parents:
diff changeset
   564
        enterBinop("/", intType, intType, intType, idiv);
06bc494ca11e Initial load
duke
parents:
diff changeset
   565
06bc494ca11e Initial load
duke
parents:
diff changeset
   566
        enterBinop("%", doubleType, doubleType, doubleType, dmod);
06bc494ca11e Initial load
duke
parents:
diff changeset
   567
        enterBinop("%", floatType, floatType, floatType, fmod);
06bc494ca11e Initial load
duke
parents:
diff changeset
   568
        enterBinop("%", longType, longType, longType, lmod);
06bc494ca11e Initial load
duke
parents:
diff changeset
   569
        enterBinop("%", intType, intType, intType, imod);
06bc494ca11e Initial load
duke
parents:
diff changeset
   570
06bc494ca11e Initial load
duke
parents:
diff changeset
   571
        enterBinop("&", booleanType, booleanType, booleanType, iand);
06bc494ca11e Initial load
duke
parents:
diff changeset
   572
        enterBinop("&", longType, longType, longType, land);
06bc494ca11e Initial load
duke
parents:
diff changeset
   573
        enterBinop("&", intType, intType, intType, iand);
06bc494ca11e Initial load
duke
parents:
diff changeset
   574
06bc494ca11e Initial load
duke
parents:
diff changeset
   575
        enterBinop("|", booleanType, booleanType, booleanType, ior);
06bc494ca11e Initial load
duke
parents:
diff changeset
   576
        enterBinop("|", longType, longType, longType, lor);
06bc494ca11e Initial load
duke
parents:
diff changeset
   577
        enterBinop("|", intType, intType, intType, ior);
06bc494ca11e Initial load
duke
parents:
diff changeset
   578
06bc494ca11e Initial load
duke
parents:
diff changeset
   579
        enterBinop("^", booleanType, booleanType, booleanType, ixor);
06bc494ca11e Initial load
duke
parents:
diff changeset
   580
        enterBinop("^", longType, longType, longType, lxor);
06bc494ca11e Initial load
duke
parents:
diff changeset
   581
        enterBinop("^", intType, intType, intType, ixor);
06bc494ca11e Initial load
duke
parents:
diff changeset
   582
06bc494ca11e Initial load
duke
parents:
diff changeset
   583
        enterBinop("<<", longType, longType, longType, lshll);
06bc494ca11e Initial load
duke
parents:
diff changeset
   584
        enterBinop("<<", intType, longType, intType, ishll);
06bc494ca11e Initial load
duke
parents:
diff changeset
   585
        enterBinop("<<", longType, intType, longType, lshl);
06bc494ca11e Initial load
duke
parents:
diff changeset
   586
        enterBinop("<<", intType, intType, intType, ishl);
06bc494ca11e Initial load
duke
parents:
diff changeset
   587
06bc494ca11e Initial load
duke
parents:
diff changeset
   588
        enterBinop(">>", longType, longType, longType, lshrl);
06bc494ca11e Initial load
duke
parents:
diff changeset
   589
        enterBinop(">>", intType, longType, intType, ishrl);
06bc494ca11e Initial load
duke
parents:
diff changeset
   590
        enterBinop(">>", longType, intType, longType, lshr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   591
        enterBinop(">>", intType, intType, intType, ishr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   592
06bc494ca11e Initial load
duke
parents:
diff changeset
   593
        enterBinop(">>>", longType, longType, longType, lushrl);
06bc494ca11e Initial load
duke
parents:
diff changeset
   594
        enterBinop(">>>", intType, longType, intType, iushrl);
06bc494ca11e Initial load
duke
parents:
diff changeset
   595
        enterBinop(">>>", longType, intType, longType, lushr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   596
        enterBinop(">>>", intType, intType, intType, iushr);
06bc494ca11e Initial load
duke
parents:
diff changeset
   597
06bc494ca11e Initial load
duke
parents:
diff changeset
   598
        enterBinop("<", doubleType, doubleType, booleanType, dcmpg, iflt);
06bc494ca11e Initial load
duke
parents:
diff changeset
   599
        enterBinop("<", floatType, floatType, booleanType, fcmpg, iflt);
06bc494ca11e Initial load
duke
parents:
diff changeset
   600
        enterBinop("<", longType, longType, booleanType, lcmp, iflt);
06bc494ca11e Initial load
duke
parents:
diff changeset
   601
        enterBinop("<", intType, intType, booleanType, if_icmplt);
06bc494ca11e Initial load
duke
parents:
diff changeset
   602
06bc494ca11e Initial load
duke
parents:
diff changeset
   603
        enterBinop(">", doubleType, doubleType, booleanType, dcmpl, ifgt);
06bc494ca11e Initial load
duke
parents:
diff changeset
   604
        enterBinop(">", floatType, floatType, booleanType, fcmpl, ifgt);
06bc494ca11e Initial load
duke
parents:
diff changeset
   605
        enterBinop(">", longType, longType, booleanType, lcmp, ifgt);
06bc494ca11e Initial load
duke
parents:
diff changeset
   606
        enterBinop(">", intType, intType, booleanType, if_icmpgt);
06bc494ca11e Initial load
duke
parents:
diff changeset
   607
06bc494ca11e Initial load
duke
parents:
diff changeset
   608
        enterBinop("<=", doubleType, doubleType, booleanType, dcmpg, ifle);
06bc494ca11e Initial load
duke
parents:
diff changeset
   609
        enterBinop("<=", floatType, floatType, booleanType, fcmpg, ifle);
06bc494ca11e Initial load
duke
parents:
diff changeset
   610
        enterBinop("<=", longType, longType, booleanType, lcmp, ifle);
06bc494ca11e Initial load
duke
parents:
diff changeset
   611
        enterBinop("<=", intType, intType, booleanType, if_icmple);
06bc494ca11e Initial load
duke
parents:
diff changeset
   612
06bc494ca11e Initial load
duke
parents:
diff changeset
   613
        enterBinop(">=", doubleType, doubleType, booleanType, dcmpl, ifge);
06bc494ca11e Initial load
duke
parents:
diff changeset
   614
        enterBinop(">=", floatType, floatType, booleanType, fcmpl, ifge);
06bc494ca11e Initial load
duke
parents:
diff changeset
   615
        enterBinop(">=", longType, longType, booleanType, lcmp, ifge);
06bc494ca11e Initial load
duke
parents:
diff changeset
   616
        enterBinop(">=", intType, intType, booleanType, if_icmpge);
06bc494ca11e Initial load
duke
parents:
diff changeset
   617
06bc494ca11e Initial load
duke
parents:
diff changeset
   618
        enterBinop("==", objectType, objectType, booleanType, if_acmpeq);
06bc494ca11e Initial load
duke
parents:
diff changeset
   619
        enterBinop("==", booleanType, booleanType, booleanType, if_icmpeq);
06bc494ca11e Initial load
duke
parents:
diff changeset
   620
        enterBinop("==", doubleType, doubleType, booleanType, dcmpl, ifeq);
06bc494ca11e Initial load
duke
parents:
diff changeset
   621
        enterBinop("==", floatType, floatType, booleanType, fcmpl, ifeq);
06bc494ca11e Initial load
duke
parents:
diff changeset
   622
        enterBinop("==", longType, longType, booleanType, lcmp, ifeq);
06bc494ca11e Initial load
duke
parents:
diff changeset
   623
        enterBinop("==", intType, intType, booleanType, if_icmpeq);
06bc494ca11e Initial load
duke
parents:
diff changeset
   624
06bc494ca11e Initial load
duke
parents:
diff changeset
   625
        enterBinop("!=", objectType, objectType, booleanType, if_acmpne);
06bc494ca11e Initial load
duke
parents:
diff changeset
   626
        enterBinop("!=", booleanType, booleanType, booleanType, if_icmpne);
06bc494ca11e Initial load
duke
parents:
diff changeset
   627
        enterBinop("!=", doubleType, doubleType, booleanType, dcmpl, ifne);
06bc494ca11e Initial load
duke
parents:
diff changeset
   628
        enterBinop("!=", floatType, floatType, booleanType, fcmpl, ifne);
06bc494ca11e Initial load
duke
parents:
diff changeset
   629
        enterBinop("!=", longType, longType, booleanType, lcmp, ifne);
06bc494ca11e Initial load
duke
parents:
diff changeset
   630
        enterBinop("!=", intType, intType, booleanType, if_icmpne);
06bc494ca11e Initial load
duke
parents:
diff changeset
   631
06bc494ca11e Initial load
duke
parents:
diff changeset
   632
        enterBinop("&&", booleanType, booleanType, booleanType, bool_and);
06bc494ca11e Initial load
duke
parents:
diff changeset
   633
        enterBinop("||", booleanType, booleanType, booleanType, bool_or);
06bc494ca11e Initial load
duke
parents:
diff changeset
   634
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   635
}