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

📄 tree.java

📁 javac是sun公司开发人员使用java语言编写的优秀的工业级java编译器
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/** * @(#)Tree.java	1.30 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.tree;import java.io.StringWriter;import java.io.PrintWriter;import com.sun.tools.javac.v8.util.*;import com.sun.tools.javac.v8.code.*;import com.sun.tools.javac.v8.code.Symbol.*;/** * Root class for abstract syntax tree nodes. It provides *  definitions for specific tree nodes as subclasses nested inside *  There are 40 such subclasses. * *  Each subclass is highly standardized.  It generally contains only tree *  fields for the syntactic subcomponents of the node.  Some classes that *  represent identifier uses or definitions also define a *  Symbol field that denotes the represented identifier.  Classes *  for non-local jumps also carry the jump target as a field.  The root *  class Tree itself defines fields for the tree's type and *  position.  No other fields are kept in a tree node; instead parameters *  are passed to methods accessing the node. * *  The only method defined in subclasses is `visit' which applies a *  given visitor to the tree. The actual tree processing is done by *  visitor classes in other packages. The abstract class *  Visitor, as well as an Factory interface for trees, are *  defined as inner classes in Tree. *  @see TreeMaker *  @see TreeInfo *  @see TreeTranslator *  @see Pretty */public abstract class Tree {    /**     * Toplevel nodes, of type TopLevel, representing entire source files.     */    public static final int TOPLEVEL = 1;    /**     * Import clauses, of type Import.     */    public static final int IMPORT = TOPLEVEL + 1;    /**     * Class definitions, of type ClassDef.     */    public static final int CLASSDEF = IMPORT + 1;    /**     * Method definitions, of type MethodDef.     */    public static final int METHODDEF = CLASSDEF + 1;    /**     * Variable definitions, of type VarDef.     */    public static final int VARDEF = METHODDEF + 1;    /**     * The no-op statement ";", of type Skip     */    public static final int SKIP = VARDEF + 1;    /**     * Blocks, of type Block.     */    public static final int BLOCK = SKIP + 1;    /**     * Do-while loops, of type DoLoop.     */    public static final int DOLOOP = BLOCK + 1;    /**     * While-loops, of type WhileLoop.     */    public static final int WHILELOOP = DOLOOP + 1;    /**     * For-loops, of type ForLoop.     */    public static final int FORLOOP = WHILELOOP + 1;    /**     * Labelled statements, of type Labelled.     */    public static final int LABELLED = FORLOOP + 1;    /**     * Switch statements, of type Switch.     */    public static final int SWITCH = LABELLED + 1;    /**     * Case parts in switch statements, of type Case.     */    public static final int CASE = SWITCH + 1;    /**     * Synchronized statements, of type Synchonized.     */    public static final int SYNCHRONIZED = CASE + 1;    /**     * Try statements, of type Try.     */    public static final int TRY = SYNCHRONIZED + 1;    /**     * Catch clauses in try statements, of type Catch.     */    public static final int CATCH = TRY + 1;    /**     * Conditional expressions, of type Conditional.     */    public static final int CONDEXPR = CATCH + 1;    /**     * Conditional statements, of type If.     */    public static final int IF = CONDEXPR + 1;    /**     * Expression statements, of type Exec.     */    public static final int EXEC = IF + 1;    /**     * Break statements, of type Break.     */    public static final int BREAK = EXEC + 1;    /**     * Continue statements, of type Continue.     */    public static final int CONTINUE = BREAK + 1;    /**     * Return statements, of type Return.     */    public static final int RETURN = CONTINUE + 1;    /**     * Throw statements, of type Throw.     */    public static final int THROW = RETURN + 1;    /**     * Assert statements, of type Assert.     */    public static final int ASSERT = THROW + 1;    /**     * Method invocation expressions, of type Apply.     */    public static final int APPLY = ASSERT + 1;    /**     * Class instance creation expressions, of type NewClass.     */    public static final int NEWCLASS = APPLY + 1;    /**     * Array creation expressions, of type NewArray.     */    public static final int NEWARRAY = NEWCLASS + 1;    /**     * Parenthesized subexpressions, of type Parens.     */    public static final int PARENS = NEWARRAY + 1;    /**     * Assignment expressions, of type Assign.     */    public static final int ASSIGN = PARENS + 1;    /**     * Type cast expressions, of type TypeCast.     */    public static final int TYPECAST = ASSIGN + 1;    /**     * Type test expressions, of type TypeTest.     */    public static final int TYPETEST = TYPECAST + 1;    /**     * Indexed array expressions, of type Indexed.     */    public static final int INDEXED = TYPETEST + 1;    /**     * Selections, of type Select.     */    public static final int SELECT = INDEXED + 1;    /**     * Simple identifiers, of type Ident.     */    public static final int IDENT = SELECT + 1;    /**     * Literals, of type Literal.     */    public static final int LITERAL = IDENT + 1;    /**     * Basic type identifiers, of type TypeIdent.     */    public static final int TYPEIDENT = LITERAL + 1;    /**     * Array types, of type TypeArray.     */    public static final int TYPEARRAY = TYPEIDENT + 1;    /**     * Parameterized types, of type TypeApply.     */    public static final int TYPEAPPLY = TYPEARRAY + 1;    /**     * Formal type parameters, of type TypeParameter.     */    public static final int TYPEPARAMETER = TYPEAPPLY + 1;    /**     * Error trees, of type Erroneous.     */    public static final int ERRONEOUS = TYPEPARAMETER + 1;    /**     * Unary operators, of type Unary.     */    public static final int POS = ERRONEOUS + 1;    public static final int NEG = POS + 1;    public static final int NOT = NEG + 1;    public static final int COMPL = NOT + 1;    public static final int PREINC = COMPL + 1;    public static final int PREDEC = PREINC + 1;    public static final int POSTINC = PREDEC + 1;    public static final int POSTDEC = POSTINC + 1;    /**     * unary operator for null reference checks, only used internally.     */    public static final int NULLCHK = POSTDEC + 1;    /**     * Binary operators, of type Binary.     */    public static final int OR = NULLCHK + 1;    public static final int AND = OR + 1;    public static final int BITOR = AND + 1;    public static final int BITXOR = BITOR + 1;    public static final int BITAND = BITXOR + 1;    public static final int EQ = BITAND + 1;    public static final int NE = EQ + 1;    public static final int LT = NE + 1;    public static final int GT = LT + 1;    public static final int LE = GT + 1;    public static final int GE = LE + 1;    public static final int SL = GE + 1;    public static final int SR = SL + 1;    public static final int USR = SR + 1;    public static final int PLUS = USR + 1;    public static final int MINUS = PLUS + 1;    public static final int MUL = MINUS + 1;    public static final int DIV = MUL + 1;    public static final int MOD = DIV + 1;    /**     * Assignment operators, of type Assignop.     */    public static final int BITOR_ASG = MOD + 1;    public static final int BITXOR_ASG = BITOR_ASG + 1;    public static final int BITAND_ASG = BITXOR_ASG + 1;    public static final int SL_ASG = SL + BITOR_ASG - BITOR;    public static final int SR_ASG = SL_ASG + 1;    public static final int USR_ASG = SR_ASG + 1;    public static final int PLUS_ASG = USR_ASG + 1;    public static final int MINUS_ASG = PLUS_ASG + 1;    public static final int MUL_ASG = MINUS_ASG + 1;    public static final int DIV_ASG = MUL_ASG + 1;    public static final int MOD_ASG = DIV_ASG + 1;    /**     * The offset between assignment operators and normal operators.     */    public static final int ASGOffset = BITOR_ASG - BITOR;    public int pos;    public Type type;    public int tag;    /**     * Initialize tree with given tag.     */    public Tree(int tag) {        super();        this.tag = tag;    }    /**      * Convert a tree to a pretty-printed string.      */    public String toString() {        StringWriter s = new StringWriter();        new Pretty(new PrintWriter(s), false).printExpr(this);        return s.toString();    }    /**      * An empty list of trees.      */    public static final List emptyList = new List();    /**     * Set position field and return this tree.     */    public Tree setPos(int pos) {        this.pos = pos;        return this;    }    /**      * Set type field and return this tree.      */    public Tree setType(Type type) {        this.type = type;        return this;    }    /**      * Visit this tree with a given visitor.      */    public void accept(Visitor v) {        v.visitTree(this);    }    /**      * Everything in one source file is kept in a TopLevel structure.      * @param pid              The tree representing the package clause.      * @param sourcefile       The source file name.      * @param defs             All definitions in this file.      * @param packge           The package it belongs to.      * @param namedImportScope A scope for all named imports.      * @param starImportScope  A scope for all import-on-demands.      * @param docComments      A hashtable that stores all documentation comments      *                         indexed by the tree nodes they refer to.      *                         defined only if option -s is set.      * @param endPositions     A hashtable that stores ending positions of source      *                         ranges indexed by the tree nodes they belong to.      *                         Defined only if option -Xjcov is set.      */    public static class TopLevel extends Tree {        public Tree pid;        public List defs;        public Name sourcefile;        public PackageSymbol packge;        public Scope namedImportScope;        public Scope starImportScope;        public Hashtable docComments = null;        public Hashtable endPositions = null;        public TopLevel(Tree pid, List defs, Name sourcefile,                PackageSymbol packge, Scope namedImportScope, Scope starImportScope) {            super(TOPLEVEL);            this.pid = pid;            this.defs = defs;            this.sourcefile = sourcefile;            this.packge = packge;            this.namedImportScope = namedImportScope;            this.starImportScope = starImportScope;        }        public void accept(Visitor v) {            v.visitTopLevel(this);        }    }    /**      * An import clause.      * @param qualid    The imported class(es).      */    public static class Import extends Tree {        public Tree qualid;        public Import(Tree qualid) {            super(IMPORT);            this.qualid = qualid;        }        public void accept(Visitor v) {            v.visitImport(this);        }    }    /**      * A class definition.      * @param flags class flags      * @param name the name of the class      * @param typarams formal class parameters      * @param extending the classes this class extends      * @param implementing the interfaces implemented by this class      * @param defs all variables and methods defined in this class      * @param sym the symbol      */    public static class ClassDef extends Tree {        public long flags;        public Name name;        public List typarams;        public Tree extending;        public List implementing;        public List defs;        public ClassSymbol sym;        public ClassDef(long flags, Name name, List typarams, Tree extending,                List implementing, List defs, ClassSymbol sym) {            super(CLASSDEF);            this.flags = flags;            this.name = name;            this.typarams = typarams;            this.extending = extending;            this.implementing = implementing;            this.defs = defs;            this.sym = sym;        }        public void accept(Visitor v) {            v.visitClassDef(this);        }    }    /**      * A method definition.      * @param flags method flags      * @param name method name      * @param restype type of method return value      * @param typarams type parameters      * @param params value parameters      * @param thrown exceptions thrown by this method      * @param stats statements in the method      * @param sym method symbol      */    public static class MethodDef extends Tree {        public long flags;        public Name name;        public Tree restype;        public List typarams;        public List params;        public List thrown;        public Block body;        public MethodSymbol sym;        public MethodDef(long flags, Name name, Tree restype, List typarams,                List params, List thrown, Block body, MethodSymbol sym) {            super(METHODDEF);            this.flags = flags;            this.name = name;            this.restype = restype;            this.typarams = typarams;            this.params = params;            this.thrown = thrown;            this.body = body;            this.sym = sym;        }        public void accept(Visitor v) {            v.visitMethodDef(this);        }    }    /**

⌨️ 快捷键说明

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