📄 symtab.java
字号:
/** * @(#)Symtab.java 1.18 01/08/17 * * Copyright 2003 Sun Microsystems, Inc. All Rights Reserved. * * This software is the proprietary information of Sun Microsystems, Inc. * Use is subject to license terms. * */package com.sun.tools.javac.v8.comp;import com.sun.tools.javac.v8.util.*;import com.sun.tools.javac.v8.code.*;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 current class reader. */ public ClassReader reader; /** * The current class writer. */ public ClassWriter writer; /** * Predefined types. */ public Type objectType; public Type classType; public Type classLoaderType; public Type stringType; public Type stringBufferType; public Type cloneableType; public Type serializableType; public Type throwableType; public Type errorType; public Type exceptionType; public Type runtimeExceptionType; public Type classNotFoundExceptionType; public Type noClassDefFoundErrorType; public Type assertionErrorType; /** * The symbol representing the length field of an array. */ public VarSymbol lengthVar; /** * Predefined constants. */ public VarSymbol nullConst; public VarSymbol trueConst; public VarSymbol falseConst; /** * The class symbol that owns all predefined symbols. */ public 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, StaticName.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(StaticName.fromString(name), new MethodType(List.make(left, right), res, Type.emptyList), 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 void enterUnop(String name, Type arg, Type res, int opcode) { predefClass.members().enter( new OperatorSymbol(StaticName.fromString(name), new MethodType(List.make(arg), res, Type.emptyList), opcode, predefClass)); } /** * Enter a class into symbol table. * @param The name of the class. */ private Type enterClass(String s) { return reader.enterClass(StaticName.fromString(s)).type; } /** * Constructor; enters all predefined identifiers and operators * into symbol table. */ public Symtab(ClassReader reader, ClassWriter writer) throws CompletionFailure { super(); predefClass = new ClassSymbol(PUBLIC, Names.empty, Symbol.rootPackage); Scope scope = new Scope(predefClass); predefClass.members_field = scope; this.reader = reader; this.writer = writer; reader.classes.put(predefClass.fullname, predefClass); scope.enter(Type.byteType.tsym); scope.enter(Type.shortType.tsym); scope.enter(Type.charType.tsym); scope.enter(Type.intType.tsym); scope.enter(Type.longType.tsym); scope.enter(Type.floatType.tsym); scope.enter(Type.doubleType.tsym); scope.enter(Type.booleanType.tsym); scope.enter(Type.errType.tsym); objectType = enterClass("java.lang.Object"); classType = enterClass("java.lang.Class"); stringType = enterClass("java.lang.String"); stringBufferType = enterClass("java.lang.StringBuffer"); cloneableType = enterClass("java.lang.Cloneable"); throwableType = enterClass("java.lang.Throwable"); serializableType = enterClass("java.io.Serializable");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -