jctree.java

来自「是一款用JAVA 编写的编译器 具有很强的编译功能」· Java 代码 · 共 2,048 行 · 第 1/5 页

JAVA
2,048
字号
/* * Copyright 1999-2006 Sun Microsystems, Inc.  All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.  Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. */package com.sun.tools.javac.tree;import java.util.*;import java.io.File;import java.io.IOException;import java.io.PrintWriter;import java.io.StringWriter;import javax.lang.model.element.Modifier;import javax.lang.model.type.TypeKind;import javax.tools.JavaFileObject;import com.sun.tools.javac.util.*;import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;import com.sun.tools.javac.util.List;import com.sun.tools.javac.code.*;import com.sun.tools.javac.code.Scope;import com.sun.tools.javac.code.Symbol.*;import com.sun.source.tree.Tree;import com.sun.source.tree.*;import static com.sun.tools.javac.code.BoundKind.*;/** * Root class for abstract syntax tree nodes. It provides definitions * for specific tree nodes as subclasses nested inside. * * <p>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. * * <p>Except for the methods defined by com.sun.source, 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. * * <p>To avoid ambiguities with the Tree API in com.sun.source all sub * classes should, by convention, start with JC (javac). * * <p><b>This is NOT part of any API supported by Sun Microsystems. * If you write code that depends on this, you do so at your own risk. * This code and its internal interfaces are subject to change or * deletion without notice.</b> * * @see TreeMaker * @see TreeInfo * @see TreeTranslator * @see Pretty */public abstract class JCTree implements Tree, Cloneable, DiagnosticPosition {    /* Tree tag values, identifying kinds of trees */    /** 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;    /** Foreach-loops, of type ForeachLoop.     */    public static final int FOREACHLOOP = FORLOOP + 1;    /** Labelled statements, of type Labelled.     */    public static final int LABELLED = FOREACHLOOP + 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;    /** Type argument.     */    public static final int WILDCARD = TYPEPARAMETER + 1;    /** Bound kind: extends, super, exact, or unbound     */    public static final int TYPEBOUNDKIND = WILDCARD + 1;    /** metadata: Annotation.     */    public static final int ANNOTATION = TYPEBOUNDKIND + 1;    /** metadata: Modifiers     */    public static final int MODIFIERS = ANNOTATION + 1;    /** Error trees, of type Erroneous.     */    public static final int ERRONEOUS = MODIFIERS + 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;           // %=    /** A synthetic let expression, of type LetExpr.     */    public static final int LETEXPR = MOD_ASG + 1;           // ala scheme    /** The offset between assignment operators and normal operators.     */    public static final int ASGOffset = BITOR_ASG - BITOR;    /* The (encoded) position in the source file. @see util.Position.     */    public int pos;    /* The type of this node.     */    public Type type;    /* The tag of this node -- one of the constants declared above.     */    public abstract int getTag();    /** Convert a tree to a pretty-printed string. */    public String toString() {        StringWriter s = new StringWriter();        try {            new Pretty(s, false).printExpr(this);        }        catch (IOException e) {            // should never happen, because StringWriter is defined            // never to throw any IOExceptions	    throw new AssertionError(e);        }        return s.toString();    }    /** Set position field and return this tree.     */    public JCTree setPos(int pos) {        this.pos = pos;        return this;    }    /** Set type field and return this tree.     */    public JCTree setType(Type type) {        this.type = type;        return this;    }    /** Visit this tree with a given visitor.     */    public abstract void accept(Visitor v);    public abstract <R,D> R accept(TreeVisitor<R,D> v, D d);    /** Return a shallow copy of this tree.     */    public Object clone() {        try {            return super.clone();        } catch(CloneNotSupportedException e) {            throw new RuntimeException(e);        }    }    /** Get a default position for this tree node.     */    public DiagnosticPosition pos() {        return this;    }    // for default DiagnosticPosition    public JCTree getTree() {        return this;    }    // for default DiagnosticPosition    public int getStartPosition() {        return TreeInfo.getStartPos(this);    }    // for default DiagnosticPosition    public int getPreferredPosition() {        return pos;    }    // for default DiagnosticPosition    public int getEndPosition(Map<JCTree, Integer> endPosTable) {        return TreeInfo.getEndPos(this, endPosTable);    }    /**     * Everything in one source file is kept in a TopLevel structure.

⌨️ 快捷键说明

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