/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* 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 supported API.
* 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
*/
/* Tree tag values, identifying kinds of trees */
/** Toplevel nodes, of type TopLevel, representing entire source files.
*/
/** Import clauses, of type Import.
*/
/** Class definitions, of type ClassDef.
*/
/** Method definitions, of type MethodDef.
*/
/** Variable definitions, of type VarDef.
*/
/** The no-op statement ";", of type Skip
*/
/** Blocks, of type Block.
*/
/** Do-while loops, of type DoLoop.
*/
/** While-loops, of type WhileLoop.
*/
/** For-loops, of type ForLoop.
*/
/** Foreach-loops, of type ForeachLoop.
*/
/** Labelled statements, of type Labelled.
*/
/** Switch statements, of type Switch.
*/
/** Case parts in switch statements, of type Case.
*/
/** Synchronized statements, of type Synchonized.
*/
/** Try statements, of type Try.
*/
/** Catch clauses in try statements, of type Catch.
*/
/** Conditional expressions, of type Conditional.
*/
/** Conditional statements, of type If.
*/
/** Expression statements, of type Exec.
*/
/** Break statements, of type Break.
*/
/** Continue statements, of type Continue.
*/
/** Return statements, of type Return.
*/
/** Throw statements, of type Throw.
*/
/** Assert statements, of type Assert.
*/
/** Method invocation expressions, of type Apply.
*/
/** Class instance creation expressions, of type NewClass.
*/
/** Array creation expressions, of type NewArray.
*/
/** Parenthesized subexpressions, of type Parens.
*/
/** Assignment expressions, of type Assign.
*/
/** Type cast expressions, of type TypeCast.
*/
/** Type test expressions, of type TypeTest.
*/
/** Indexed array expressions, of type Indexed.
*/
/** Selections, of type Select.
*/
/** Simple identifiers, of type Ident.
*/
/** Literals, of type Literal.
*/
/** Basic type identifiers, of type TypeIdent.
*/
/** Array types, of type TypeArray.
*/
/** Parameterized types, of type TypeApply.
*/
/** Union types, of type TypeUnion
*/
/** Formal type parameters, of type TypeParameter.
*/
/** Type argument.
*/
/** Bound kind: extends, super, exact, or unbound
*/
/** metadata: Annotation.
*/
/** metadata: Modifiers
*/
/** Error trees, of type Erroneous.
*/
/** Unary operators, of type Unary.
*/
/** unary operator for null reference checks, only used internally.
*/
/** Binary operators, of type Binary.
*/
/** Assignment operators, of type Assignop.
*/
/** A synthetic let expression, of type LetExpr.
*/
/** The offset between assignment operators and normal operators.
*/
/* The (encoded) position in the source file. @see util.Position.
*/
public int pos;
/* The type of this node.
*/
/* The tag of this node -- one of the constants declared above.
*/
public abstract int getTag();
/** Convert a tree to a pretty-printed string. */
StringWriter s = new StringWriter();
try {
}
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.
*/
return this;
}
/** Set type field and return this tree.
*/
return this;
}
/** Visit this tree with a given visitor.
*/
/** Return a shallow copy of this tree.
*/
try {
return super.clone();
} catch(CloneNotSupportedException e) {
throw new RuntimeException(e);
}
}
/** Get a default position for this tree node.
*/
return this;
}
// for default DiagnosticPosition
return this;
}
// for default DiagnosticPosition
public int getStartPosition() {
return TreeInfo.getStartPos(this);
}
// for default DiagnosticPosition
public int getPreferredPosition() {
return pos;
}
// for default DiagnosticPosition
}
/**
* 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 (ClassDef, Import, and Skip)
* @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 lineMap Line starting positions, defined only
* if option -g is set.
* @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 long flags;
this.packageAnnotations = packageAnnotations;
this.sourcefile = sourcefile;
this.namedImportScope = namedImportScope;
this.starImportScope = starImportScope;
}
return packageAnnotations;
}
break;
}
}
return sourcefile;
}
return lineMap;
}
break;
return typeDefs;
}
return v.visitCompilationUnit(this, d);
}
public int getTag() {
return TOPLEVEL;
}
}
/**
* An import clause.
* @param qualid The imported class(es).
*/
public boolean staticImport;
this.staticImport = importStatic;
}
return v.visitImport(this, d);
}
public int getTag() {
return IMPORT;
}
}
return this;
}
return this;
}
}
return this;
}
return this;
}
}
/**
* A class definition.
* @param modifiers the modifiers
* @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
*/
{
this.implementing = implementing;
}
return Kind.ANNOTATION_TYPE;
else
}
return typarams;
}
return implementing;
}
return defs;
}
return v.visitClass(this, d);
}
public int getTag() {
return CLASSDEF;
}
}
/**
* A method definition.
* @param modifiers method modifiers
* @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
*/
{
this.defaultValue = defaultValue;
}
return typarams;
}
return params;
}
return thrown;
}
return defaultValue;
}
return v.visitMethod(this, d);
}
public int getTag() {
return METHODDEF;
}
}
/**
* A variable definition.
* @param modifiers variable modifiers
* @param name variable name
* @param vartype type of the variable
* @param init variables initial value
* @param sym symbol
*/
}
return init;
}
return v.visitVariable(this, d);
}
public int getTag() {
return VARDEF;
}
}
/**
* A no-op statement ";".
*/
protected JCSkip() {
}
return v.visitEmptyStatement(this, d);
}
public int getTag() {
return SKIP;
}
}
/**
* A statement block.
* @param stats statements
* @param flags flags
*/
public long flags;
/** Position of closing brace, optional. */
}
return stats;
}
return v.visitBlock(this, d);
}
public int getTag() {
return BLOCK;
}
}
/**
* A do loop
*/
}
return v.visitDoWhileLoop(this, d);
}
public int getTag() {
return DOLOOP;
}
}
/**
* A while loop
*/
}
return v.visitWhileLoop(this, d);
}
public int getTag() {
return WHILELOOP;
}
}
/**
* A for loop.
*/
{
}
return init;
}
return step;
}
return v.visitForLoop(this, d);
}
public int getTag() {
return FORLOOP;
}
}
/**
* The enhanced for loop.
*/
}
return v.visitEnhancedForLoop(this, d);
}
public int getTag() {
return FOREACHLOOP;
}
}
/**
* A labelled expression or statement.
*/
}
return v.visitLabeledStatement(this, d);
}
public int getTag() {
return LABELLED;
}
}
/**
* A "switch ( ) { }" construction.
*/
}
return v.visitSwitch(this, d);
}
public int getTag() {
return SWITCH;
}
}
/**
* A "case :" of a switch.
*/
}
return v.visitCase(this, d);
}
public int getTag() {
return CASE;
}
}
/**
* A synchronized block.
*/
}
return v.visitSynchronized(this, d);
}
public int getTag() {
return SYNCHRONIZED;
}
}
/**
* A "try { } catch ( ) { } finally { }" block.
*/
}
return catchers;
}
return v.visitTry(this, d);
}
return resources;
}
public int getTag() {
return TRY;
}
}
/**
* A catch block.
*/
}
return v.visitCatch(this, d);
}
public int getTag() {
return CATCH;
}
}
/**
* A ( ) ? ( ) : ( ) conditional expression
*/
{
}
return v.visitConditionalExpression(this, d);
}
public int getTag() {
return CONDEXPR;
}
}
/**
* An "if ( ) { } else { }" block
*/
{
}
return v.visitIf(this, d);
}
public int getTag() {
return IF;
}
}
/**
* an expression statement
* @param expr expression structure
*/
{
}
return v.visitExpressionStatement(this, d);
}
public int getTag() {
return EXEC;
}
}
/**
* A break from a loop or switch.
*/
}
return v.visitBreak(this, d);
}
public int getTag() {
return BREAK;
}
}
/**
* A continue of a loop.
*/
}
return v.visitContinue(this, d);
}
public int getTag() {
return CONTINUE;
}
}
/**
* A return statement.
*/
}
return v.visitReturn(this, d);
}
public int getTag() {
return RETURN;
}
}
/**
* A throw statement.
*/
}
return v.visitThrow(this, d);
}
public int getTag() {
return THROW;
}
}
/**
* An assert statement.
*/
}
return v.visitAssert(this, d);
}
public int getTag() {
return ASSERT;
}
}
/**
* A method invocation
*/
{
: typeargs;
}
return typeargs;
}
return args;
}
return v.visitMethodInvocation(this, d);
}
return this;
}
public int getTag() {
return(APPLY);
}
}
/**
* A new(...) operation.
*/
{
: typeargs;
}
return encl;
}
return typeargs;
}
return args;
}
return v.visitNewClass(this, d);
}
public int getTag() {
return NEWCLASS;
}
}
/**
* A new[...] operation.
*/
{
}
return dims;
}
return elems;
}
return v.visitNewArray(this, d);
}
public int getTag() {
return NEWARRAY;
}
}
/**
* A parenthesized subexpression ( ... )
*/
}
return v.visitParenthesized(this, d);
}
public int getTag() {
return PARENS;
}
}
/**
* A assignment with "=".
*/
}
return v.visitAssignment(this, d);
}
public int getTag() {
return ASSIGN;
}
}
/**
* An assignment with "+=", "|=" ...
*/
private int opcode;
}
return operator;
}
return v.visitCompoundAssignment(this, d);
}
public int getTag() {
return opcode;
}
}
/**
* A unary operation.
*/
private int opcode;
}
return operator;
}
return v.visitUnary(this, d);
}
public int getTag() {
return opcode;
}
}
}
/**
* A binary operation.
*/
private int opcode;
}
return operator;
}
return v.visitBinary(this, d);
}
public int getTag() {
return opcode;
}
}
/**
* A type cast.
*/
}
return v.visitTypeCast(this, d);
}
public int getTag() {
return TYPECAST;
}
}
/**
* A type test.
*/
}
return v.visitInstanceOf(this, d);
}
public int getTag() {
return TYPETEST;
}
}
/**
* An array selection
*/
}
return v.visitArrayAccess(this, d);
}
public int getTag() {
return INDEXED;
}
}
/**
* Selects through packages and classes
* @param selected selected Tree hierarchie
* @param selector name of field to select thru
* @param sym symbol of the selected class
*/
}
return v.visitMemberSelect(this, d);
}
public int getTag() {
return SELECT;
}
}
/**
* An identifier
* @param idname the name
* @param sym the symbol
*/
}
return v.visitIdentifier(this, d);
}
public int getTag() {
return IDENT;
}
}
/**
* A constant value given literally.
* @param value value representation
*/
public int typetag;
}
switch (typetag) {
return Kind.INT_LITERAL;
return Kind.LONG_LITERAL;
return Kind.FLOAT_LITERAL;
return Kind.DOUBLE_LITERAL;
return Kind.BOOLEAN_LITERAL;
return Kind.CHAR_LITERAL;
return Kind.STRING_LITERAL;
return Kind.NULL_LITERAL;
default:
throw new AssertionError("unknown literal kind " + this);
}
}
switch (typetag) {
return (bi != 0);
char c = (char) ci;
if (c != ci)
throw new AssertionError("bad value for char literal");
return c;
default:
return value;
}
}
return v.visitLiteral(this, d);
}
return this;
}
public int getTag() {
return LITERAL;
}
}
/**
* Identifies a basic type.
* @param tag the basic type id
* @see TypeTags
*/
public int typetag;
}
switch (typetag) {
default:
throw new AssertionError("unknown primitive type " + this);
}
}
return v.visitPrimitiveType(this, d);
}
public int getTag() {
return TYPEIDENT;
}
}
/**
* An array type, A[]
*/
}
return v.visitArrayType(this, d);
}
public int getTag() {
return TYPEARRAY;
}
}
/**
* A parameterized type, T<...>
*/
}
return arguments;
}
return v.visitParameterizedType(this, d);
}
public int getTag() {
return TYPEAPPLY;
}
}
/**
* A union type, T1 | T2 | ... Tn (used in multicatch statements)
*/
this.alternatives = components;
}
return alternatives;
}
return v.visitUnionType(this, d);
}
public int getTag() {
return TYPEUNION;
}
}
/**
* A formal class parameter.
* @param name name
* @param bounds bounds
*/
}
return bounds;
}
return v.visitTypeParameter(this, d);
}
public int getTag() {
return TYPEPARAMETER;
}
}
}
case UNBOUND:
return Kind.UNBOUNDED_WILDCARD;
case EXTENDS:
return Kind.EXTENDS_WILDCARD;
case SUPER:
return Kind.SUPER_WILDCARD;
default:
}
}
return v.visitWildcard(this, d);
}
public int getTag() {
return WILDCARD;
}
}
}
throw new AssertionError("TypeBoundKind is not part of a public API");
}
throw new AssertionError("TypeBoundKind is not part of a public API");
}
public int getTag() {
return TYPEBOUNDKIND;
}
}
this.annotationType = annotationType;
}
return args;
}
return v.visitAnnotation(this, d);
}
public int getTag() {
return ANNOTATION;
}
}
public long flags;
this.annotations = annotations;
}
}
return annotations;
}
return v.visitModifiers(this, d);
}
public int getTag() {
return MODIFIERS;
}
}
}
return errs;
}
return v.visitErroneous(this, d);
}
public int getTag() {
return ERRONEOUS;
}
}
/** (let int x = 3; in x+2) */
}
throw new AssertionError("LetExpr is not part of a public API");
}
throw new AssertionError("LetExpr is not part of a public API");
}
public int getTag() {
return LETEXPR;
}
}
/** An interface for tree factories
*/
public interface Factory {
}
/** A generic visitor class for trees.
*/
public static abstract class Visitor {
}
}