antlr
Class ASTFactory

java.lang.Object
  |
  +--antlr.ASTFactory

public class ASTFactory
extends java.lang.Object

AST Support code shared by TreeParser and Parser. We use delegation to share code (and have only one bit of code to maintain) rather than subclassing or superclassing (forces AST support code to be loaded even when you don't want to do AST stuff). Typically, setASTNodeType is used to specify the type of node to create, but you can override create to make heterogeneous nodes etc...


Field Summary
protected  java.lang.String theASTNodeType
          Name of AST class to create during tree construction.
protected  java.lang.Class theASTNodeTypeClass
           
 
Constructor Summary
ASTFactory()
           
 
Method Summary
 void addASTChild(ASTPair currentAST, AST child)
          Add a child to the current AST
 AST create()
          Create a new empty AST node; if the user did not specify an AST node type, then create a default one: CommonAST.
 AST create(AST tr)
          Create a new empty AST node; if the user did not specify an AST node type, then create a default one: CommonAST.
 AST create(int type)
           
 AST create(int type, java.lang.String txt)
           
 AST create(Token tok)
           
 AST dup(AST t)
          Copy a single node.
 AST dupList(AST t)
          Duplicate tree including siblings of root.
 AST dupTree(AST t)
          Duplicate a tree, assuming this is a root node of a tree-- duplicate that node and what's below; ignore siblings of root node.
 AST make(AST[] nodes)
          Make a tree from a list of nodes.
 AST make(ASTArray nodes)
          Make a tree from a list of nodes, where the nodes are contained in an ASTArray object
 void makeASTRoot(ASTPair currentAST, AST root)
          Make an AST the root of current AST
 void setASTNodeType(java.lang.String t)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

theASTNodeType

protected java.lang.String theASTNodeType
Name of AST class to create during tree construction. Null implies that the create method should create a default AST type such as CommonAST.


theASTNodeTypeClass

protected java.lang.Class theASTNodeTypeClass
Constructor Detail

ASTFactory

public ASTFactory()
Method Detail

addASTChild

public void addASTChild(ASTPair currentAST,
                        AST child)
Add a child to the current AST


create

public AST create()
Create a new empty AST node; if the user did not specify an AST node type, then create a default one: CommonAST.


create

public AST create(int type)

create

public AST create(int type,
                  java.lang.String txt)

create

public AST create(AST tr)
Create a new empty AST node; if the user did not specify an AST node type, then create a default one: CommonAST.


create

public AST create(Token tok)

dup

public AST dup(AST t)
Copy a single node. clone() is not used because we want to return an AST not a plain object...a type safety issue. Further, we want to have all AST node creation go through the factory so creation can be tracked. Returns null if t is null.


dupList

public AST dupList(AST t)
Duplicate tree including siblings of root.


dupTree

public AST dupTree(AST t)
Duplicate a tree, assuming this is a root node of a tree-- duplicate that node and what's below; ignore siblings of root node.


make

public AST make(AST[] nodes)
Make a tree from a list of nodes. The first element in the array is the root. If the root is null, then the tree is a simple list not a tree. Handles null children nodes correctly. For example, build(a, b, null, c) yields tree (a b c). build(null,a,b) yields tree (nil a b).


make

public AST make(ASTArray nodes)
Make a tree from a list of nodes, where the nodes are contained in an ASTArray object


makeASTRoot

public void makeASTRoot(ASTPair currentAST,
                        AST root)
Make an AST the root of current AST


setASTNodeType

public void setASTNodeType(java.lang.String t)