⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 symtab.java

📁 这是实现Javac功能的GJC的最新源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/** * @(#)Symtab.java	1.27 03/01/23 * * Copyright 2003 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package com.sun.tools.javac.v8.code;import com.sun.tools.javac.v8.util.*;import com.sun.tools.javac.v8.code.Symbol.*;import com.sun.tools.javac.v8.code.Type.*;/** * A class that defines all predefined constants and operators *  as well as special classes such as java.lang.Object, which need *  to be known to the compiler. All symbols are held in instance *  fields. This makes it possible to work in multiple concurrent *  projects, which might use different class files for library classes. */public class Symtab implements Flags, ByteCodes {    /**     * The context key for the symbol table.     */    private static final Context.Key symtabKey = new Context.Key();    /**     * Get the symbol table instance.     */    public static Symtab instance(Context context) {        Symtab instance = (Symtab) context.get(symtabKey);        if (instance == null)            instance = new Symtab(context);        return instance;    }    private final Name.Table names;    private final ClassReader reader;    /**     * A symbol for the root package.     */    public final PackageSymbol rootPackage;    /**     * A symbol for the empty package.     */    public final PackageSymbol emptyPackage;    /**     * A symbol that stands for a missing symbol.     */    public final TypeSymbol noSymbol;    /**     * The error symbol.     */    public final ClassSymbol errSymbol;    /**     * Builtin types.     */    public final Type byteType;    public final Type charType;    public final Type shortType;    public final Type intType;    public final Type longType;    public final Type floatType;    public final Type doubleType;    public final Type booleanType;    public final Type voidType;    public final Type botType;    public final Type errType;    /**     * A value for the unknown type.     */    public final Type unknownType;    /**     * The builtin type of all arrays.     */    public final ClassSymbol arrayClass;    /**     * The builtin type of all methods.     */    public final ClassSymbol methodClass;    /**     * Predefined types.     */    public final Type objectType;    public final Type classType;    public final Type classLoaderType;    public final Type stringType;    public final Type stringBufferType;    public final Type cloneableType;    public final Type serializableType;    public final Type throwableType;    public final Type errorType;    public final Type exceptionType;    public final Type runtimeExceptionType;    public final Type classNotFoundExceptionType;    public final Type noClassDefFoundErrorType;    public final Type assertionErrorType;    /**     * The symbol representing the length field of an array.     */    public final VarSymbol lengthVar;    /**     * Predefined constants.     */    public final VarSymbol nullConst;    public final VarSymbol trueConst;    public final VarSymbol falseConst;    /**     * The null check operator.     */    public final OperatorSymbol nullcheck;    /**     * The predefined type that belongs to a tag.     */    public final Type[] typeOfTag = new Type[TypeTags.TypeTagCount];    /**     * The name of the class that belongs to a basix type tag.     */    public final Name[] boxedName = new Name[TypeTags.TypeTagCount];    /**     * A hashtable containing the encountered top-level and member classes,     *  indexed by flat names. The table does not contain local classes.     *  It should be updated from the outside to reflect classes defined     *  by compiled source files.     */    public final Hashtable classes = Hashtable.make();    /**     * A hashtable containing the encountered packages.     *  the table should be updated from outside to reflect packages defined     *  by compiled source files.     */    public final Hashtable packages = Hashtable.make();    public void initType(Type type, ClassSymbol c) {        type.tsym = c;        typeOfTag[type.tag] = type;    }    public void initType(Type type, String name) {        initType(type,                new ClassSymbol(PUBLIC, names.fromString(name), type, rootPackage));    }    public void initType(Type type, String name, String bname) {        initType(type, name);        boxedName[type.tag] = names.fromString("java.lang." + bname);    }    /**      * The class symbol that owns all predefined symbols.      */    public final ClassSymbol predefClass;    /**     * Enter a constant into symbol table.     *  @param name   The constant's name.     *  @param type   The constant's type.     */    private VarSymbol enterConstant(String name, Type type) {        VarSymbol c = new VarSymbol(PUBLIC | STATIC | FINAL, names.fromString(name),                type, predefClass);        c.constValue = type.constValue;        predefClass.members().enter(c);        return c;    }    /**      * Enter a binary operation into symbol table.      *  @param name     The name of the operator.      *  @param left     The type of the left operand.      *  @param right    The type of the left operand.      *  @param res      The operation's result type.      *  @param opcode   The operation's bytecode instruction.      */    private void enterBinop(String name, Type left, Type right, Type res,            int opcode) {        predefClass.members().enter( new OperatorSymbol(names.fromString(name),                new MethodType(List.make(left, right), res, Type.emptyList,                methodClass), opcode, predefClass));    }    /**      * Enter a binary operation, as above but with two opcodes,      *  which get encoded as (opcode1 << ByteCodeTags.preShift) + opcode2.      *  @param opcode1     First opcode.      *  @param opcode2     Second opcode.      */    private void enterBinop(String name, Type left, Type right, Type res,            int opcode1, int opcode2) {        enterBinop(name, left, right, res, (opcode1 << ByteCodes.preShift) | opcode2);    }    /**      * Enter a unary operation into symbol table.      *  @param name     The name of the operator.      *  @param arg      The type of the operand.      *  @param res      The operation's result type.      *  @param opcode   The operation's bytecode instruction.      */    private OperatorSymbol enterUnop(String name, Type arg, Type res, int opcode) {        OperatorSymbol sym = new OperatorSymbol(names.fromString(name),                new MethodType(List.make(arg), res, Type.emptyList,                methodClass), opcode, predefClass);        predefClass.members().enter(sym);        return sym;    }    /**      * Enter a class into symbol table.      *  @param    The name of the class.      */    private Type enterClass(String s) {        return reader.enterClass(names.fromString(s)).type;    }    /**

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -