ESC/Java2
© 2003,2004,2005 David Cok and Joseph Kiniry
© 2005 UCD Dublin
© 2003,2004 Radboud University Nijmegen
© 1999,2000 Compaq Computer Corporation
© 1997,1998,1999 Digital Equipment Corporation
All Rights Reserved

javafe.ast
Class ASTNode

java.lang.Object
  extended byjavafe.ast.ASTNode
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
AnOverview, CatchClause, CompilationUnit, Condition, DefPred, GenericVarDecl, GuardedCmd, IdentifierNode, ImportDecl, InitBlock, LexicalPragma, ModifierPragma, Name, ObjectDesignator, RoutineDecl, Spec, Stmt, Type, TypeDecl, TypeDeclElemPragma, TypeModifierPragma, VarInit

public abstract class ASTNode
extends java.lang.Object
implements java.lang.Cloneable

ASTNode is the root of the abstract syntax tree node hierarchy. Every class representing a node in the AST is a (direct or indirect) subclass of this class.

In designing our AST classes, the following, broad approach was taken:

Measurements:

Node abstract classes: 13
Node concrete classes: 59
Sequence classes: 12
Total classes: 84

Input to code generator: 842 lines of code (513 excluding comments)
Code generator: 993 (675)
Total lines of code: 1835 (1188)
Output of code generator: 4298

The complete list of subclasses is shown below. The names of subclasses of this class correspond (in general) to the syntactic units that they represent. Any exceptions to this rule are documented. All non-leaf classes are abstract. In parenthesis, the names and types of fields holding the locally-defined children classes are listed; a postfix * on a type indicates a sequence. Square brackets indicate optional elements; the only these fields can be null.

 ASTNode
    CompilationUnit ([Name pkgName], [LexicalPragma* lexicalPragmas], ImportDecl* imports, TypeDecl* elems)
    ImportDecl ()
       SingleTypeImport (TypeName typeName)
       OnDemandImport (Name pkgName)
    TypeDecl (int modifiers, [ModifierPragma* pmodifiers], Identifier id, [TypeModifierPragma* tmodifiers], TypeName* superInterfaces, TypeDeclElem* elems)
       ClassDecl ([TypeName superClass])
       InterfaceDecl ()
    TypeDeclElem () NOTE: This is an interface
       TypeDecl
       FieldDecl
       RoutineDecl (int modifiers, [ModifierPragma* pmodifiers], FormalParaDecl* args, TypeName* raises, [BlockStmt body])
          ConstructorDecl ([TypeModifierPragma* tmodifiers])
          MethodDecl (Identifier id, Type returnType)
       InitBlock (int modifiers, [ModifierPragma* pmodifiers], BlockStmt block)
       TypeDeclElemPragma ()
    GenericVarDecl (int modifiers, [ModifierPragma* pmodifiers], Identifier id, Type type)
       LocalVarDecl ([VarInit init])
       FieldDecl ([VarInit init])
       FormalParaDecl ()
    Stmt ()
       GenericBlockStmt (Stmt* stmts)
          BlockStmt ()
          SwitchStmt (Expr expr)
       AssertStmt (Expr expr, String l)
       VarDeclStmt (LocalVarDecl decl)
       ClassDeclStmt (ClassDecl anonDecl)
       WhileStmt (Expr expr, Stmt stmt)
       DoStmt (Expr expr, Stmt stmt)
       SynchronizeStmt (Expr expr, BlockStmt stmt)
       EvalStmt (Expr expr)
       ReturnStmt ([Expr expr])
       ThrowStmt (Expr expr)
       BranchStmt ([Identifier label])
          BreakStmt ()
          ContinueStmt ()
       LabelStmt (Identifier label, Stmt stmt)
       IfStmt (Expr expr, Stmt thn, Stmt els)
       ForStmt (Stmt* forInit, Expr test, Expr* forUpdate, Stmt body)
       SkipStmt ()
       SwitchLabel ([Expr expr])
       TryFinallyStmt (Stmt tryClause, Stmt finallyClause)
       TryCatchStmt (Stmt tryClause, CatchClause* catchClauses)
       StmtPragma ()
       ConstructorInvocation (boolean superCall, [Expr enclosingInstance], Expr* args)
    CatchClause (FormalParaDecl arg, Stmt body)
    VarInit ()
       ArrayInit (VarInit* elems)
       Expr ()
          ThisExpr (Type classPrefix)
          LiteralExpr (int tag, [Object value])
          ArrayRefExpr (Expr array, Expr index)
          NewInstanceExpr ([Expr enclosingInstance], TypeName type, Expr* args, [ClassDecl decl])
          NewArrayExpr (Type type, Expr* dims, [ArrayInit init])
          CondExpr (Expr test, Expr thn, Expr els)
          InstanceOfExpr (Expr expr, Type type)
          CastExpr (Expr expr, Type type)
          BinaryExpr (int op, Expr left, Expr right)
          UnaryExpr (int op, Expr expr)
          ParenExpr (Expr expr)
          AmbiguousVariableAccess (Name name)
          VariableAccess (Identifier id)
          FieldAccess (ObjectDesignator od, Identifier id)
          AmbiguousMethodInvocation (Name name, Expr* args)
          MethodInvocation (ObjectDesignator od, Identifier id, Expr* args)
          ClassLiteral (Type type)
    ObjectDesignator ()  // "expr.", "type." or "super."
       ExprObjectDesignator (Expr expr)
       TypeObjectDesignator (Type type)
       SuperObjectDesignator ()
    Type ()
       ErrorType() // was previously represented as a PrimitiveType
       PrimitiveType (int tag)
       TypeName (Name name)
       ArrayType (Type elemType)
    Name ()
       SimpleName (Identifier id)
       CompoundName (Identifier* ids)
    ModifierPragma ()
    LexicalPragma ()
    TypeModifierPragma ()
 


Field Summary
(package private)  java.lang.Object[] decorations
          The decorations that have been attached to this node.
 
Constructor Summary
protected ASTNode()
          Construct a raw ASTNode whose class invariant(s) have not yet been established.
 
Method Summary
abstract  void accept(Visitor v)
          Accept a visit from v.
abstract  java.lang.Object accept(VisitorArgResult v, java.lang.Object o)
           
 void check()
           
abstract  java.lang.Object childAt(int i)
          Return the first-but-ith child of a node.
abstract  int childCount()
          Return the number of children a node has.
 java.lang.Object clone()
          Clone node, where the clone has the same decorations as original.
 java.lang.Object clone(boolean b)
           
 java.lang.Object[] getDecorations()
           
 int getEndLoc()
           
abstract  int getStartLoc()
           
abstract  int getTag()
          Return the tag of a node.
 void setDecorations(java.lang.Object[] d)
           
abstract  java.lang.String toString()
          Return a string representation of this.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

decorations

java.lang.Object[] decorations
The decorations that have been attached to this node. This is a package-level field accessed by the ASTDecoration class. There are different ways to implement decorations; this way is not space-efficient, but it's pretty fast.

Constructor Detail

ASTNode

protected ASTNode()
Construct a raw ASTNode whose class invariant(s) have not yet been established. It is the caller's job to initialize the returned node's fields so that any class invariants hold.

Method Detail

getStartLoc

public abstract int getStartLoc()

getEndLoc

public int getEndLoc()

clone

public java.lang.Object clone(boolean b)

clone

public java.lang.Object clone()
Clone node, where the clone has the same decorations as original.


getDecorations

public java.lang.Object[] getDecorations()

setDecorations

public void setDecorations(java.lang.Object[] d)

childCount

public abstract int childCount()
Return the number of children a node has.


childAt

public abstract java.lang.Object childAt(int i)
Return the first-but-ith child of a node.


getTag

public abstract int getTag()
Return the tag of a node.


toString

public abstract java.lang.String toString()
Return a string representation of this. Meant for debugging use only, not for presentation.


accept

public abstract void accept(Visitor v)
Accept a visit from v. This method simply calls the method of v corresponding to the allocated type of this, passing this as the argument. See the design patterns book.


accept

public abstract java.lang.Object accept(VisitorArgResult v,
                                        java.lang.Object o)

check

public void check()

ESC/Java2
© 2003,2004,2005 David Cok and Joseph Kiniry
© 2005 UCD Dublin
© 2003,2004 Radboud University Nijmegen
© 1999,2000 Compaq Computer Corporation
© 1997,1998,1999 Digital Equipment Corporation
All Rights Reserved

The ESC/Java2 Project Homepage