polyglot.ext.jl.ast
Class Node_c

java.lang.Object
  extended by polyglot.ext.jl.ast.Node_c
All Implemented Interfaces:
java.lang.Cloneable, JL, Node, NodeOps, Copy
Direct Known Subclasses:
AmbKeySetNode_c, AmbPrefix_c, AmbQualifierNode_c, CanonicalKeySetNode_c, Import_c, KeyNode_c, PackageNode_c, SourceCollection_c, SourceFile_c, Term_c, ThrowConstraintNode_c, TypeNode_c

public abstract class Node_c
extends java.lang.Object
implements Node

A Node represents an AST node. All AST nodes must implement this interface. Nodes should be immutable: methods which set fields of the node should copy the node, set the field in the copy, and then return the copy.


Field Summary
protected  JL del
           
protected  Ext ext
           
protected  Position position
           
 
Constructor Summary
Node_c(Position pos)
           
 
Method Summary
 void addDecls(Context c)
          Add any declarations to the context that should be in scope when visiting later sibling nodes.
 Node addMembers(AddMemberVisitor am)
          Adds disambiguated methods and fields to the types.
 NodeVisitor addMembersEnter(AddMemberVisitor am)
          Adds disambiguated methods and fields to the types.
 Node addMembersOverride(AddMemberVisitor am)
          Add members to a class.
 Node buildTypes(TypeBuilder tb)
          Collects classes, methods, and fields from the AST rooted at this node and constructs type objects for these.
 NodeVisitor buildTypesEnter(TypeBuilder tb)
          Collects classes, methods, and fields from the AST rooted at this node and constructs type objects for these.
 Node buildTypesOverride(TypeBuilder tb)
           
 Type childExpectedType(Expr child, AscriptionVisitor av)
          Get the expected type of a child expression of this.
 java.lang.Object copy()
           
 JL del()
          Get the node's delegate.
 Node del(JL del)
          Set the delegate of the node.
 Node disambiguate(AmbiguityRemover ar)
          Remove any remaining ambiguities from the AST.
 NodeVisitor disambiguateEnter(AmbiguityRemover ar)
          Remove any remaining ambiguities from the AST.
 Node disambiguateOverride(AmbiguityRemover ar)
          Remove any remaining ambiguities from the AST.
 void dump(CodeWriter w)
          Dump the AST node for debugging purposes.
 Context enterScope(Context c)
          Push a new scope upon entering this node, and add any declarations to the context that should be in scope when visiting children of this node.
 Context enterScope(Node child, Context c)
          Push a new scope for visiting the child node child.
 Node exceptionCheck(ExceptionChecker ec)
          Check that exceptions are properly propagated throughout the AST.
 NodeVisitor exceptionCheckEnter(ExceptionChecker ec)
          Check that exceptions are properly propagated throughout the AST.
 Node exceptionCheckOverride(ExceptionChecker ec)
          Check that exceptions are properly propagated throughout the AST.
 Ext ext()
          Get the node's extension.
 Node ext(Ext ext)
          Set the extension of the node.
 Ext ext(int n)
          Get the node's nth extension, n >= 1.
 Node ext(int n, Ext ext)
          Set the node's nth extension, n >= 1.
 void init(Node node)
          Initialize the back pointer to the node.
 Node node()
          Pointer back to the node we are delegating for, possibly this.
 Position position()
          Get the position of the node in the source file.
 Node position(Position position)
          Create a copy of the node with a new position.
 void prettyPrint(CodeWriter w, PrettyPrinter pp)
          Pretty-print the AST using the given CodeWriter.
 void print(Node child, CodeWriter w, PrettyPrinter pp)
           
 void printBlock(Node n, CodeWriter w, PrettyPrinter pp)
           
 void printSubStmt(Stmt stmt, CodeWriter w, PrettyPrinter pp)
           
 java.util.List throwTypes(TypeSystem ts)
          List of Types of exceptions that might get thrown.
 java.lang.String toString()
           
 void translate(CodeWriter w, Translator tr)
          Translate the AST using the given CodeWriter.
 Node typeCheck(TypeChecker tc)
          Type check the AST.
 NodeVisitor typeCheckEnter(TypeChecker tc)
          Type check the AST.
 Node typeCheckOverride(TypeChecker tc)
          Type check the AST.
 Node visit(NodeVisitor v)
          Visit the node.
 Node visitChild(Node n, NodeVisitor v)
          Visit a single child of the node.
 Node visitChildren(NodeVisitor v)
          Visit the children of the node.
 Node visitEdge(Node parent, NodeVisitor v)
          Visit the node, passing in the node's parent.
 java.util.List visitList(java.util.List l, NodeVisitor v)
          Visit all the elements of a list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

position

protected Position position

del

protected JL del

ext

protected Ext ext
Constructor Detail

Node_c

public Node_c(Position pos)
Method Detail

init

public void init(Node node)
Description copied from interface: JL
Initialize the back pointer to the node.

Specified by:
init in interface JL

node

public Node node()
Description copied from interface: JL
Pointer back to the node we are delegating for, possibly this.

Specified by:
node in interface JL

del

public JL del()
Description copied from interface: Node
Get the node's delegate.

Specified by:
del in interface Node

del

public Node del(JL del)
Description copied from interface: Node
Set the delegate of the node.

Specified by:
del in interface Node

ext

public Ext ext(int n)
Description copied from interface: Node
Get the node's nth extension, n >= 1.

Specified by:
ext in interface Node

ext

public Node ext(int n,
                Ext ext)
Description copied from interface: Node
Set the node's nth extension, n >= 1.

Specified by:
ext in interface Node

ext

public Ext ext()
Description copied from interface: Node
Get the node's extension.

Specified by:
ext in interface Node

ext

public Node ext(Ext ext)
Description copied from interface: Node
Set the extension of the node.

Specified by:
ext in interface Node

copy

public java.lang.Object copy()
Specified by:
copy in interface Copy

position

public Position position()
Description copied from interface: Node
Get the position of the node in the source file. Returns null if the position is not set.

Specified by:
position in interface Node

position

public Node position(Position position)
Description copied from interface: Node
Create a copy of the node with a new position.

Specified by:
position in interface Node

visitChild

public Node visitChild(Node n,
                       NodeVisitor v)
Description copied from interface: Node
Visit a single child of the node.

Specified by:
visitChild in interface Node
Parameters:
n - The child to visit.
v - The visitor which will traverse/rewrite the AST.
Returns:
The result of child.visit(v), or null if child was null.

visit

public Node visit(NodeVisitor v)
Description copied from interface: Node
Visit the node. This method is equivalent to visitEdge(null, v).

Specified by:
visit in interface Node
Parameters:
v - The visitor which will traverse/rewrite the AST.
Returns:
A new AST if a change was made, or this.

visitEdge

public Node visitEdge(Node parent,
                      NodeVisitor v)
Description copied from interface: Node
Visit the node, passing in the node's parent. This method is called by a NodeVisitor to traverse the AST starting at this node. This method should call the override, enter, and leave methods of the visitor. The method may return a new version of the node.

Specified by:
visitEdge in interface Node
Parameters:
parent - The parent of this in the AST.
v - The visitor which will traverse/rewrite the AST.
Returns:
A new AST if a change was made, or this.

visitList

public java.util.List visitList(java.util.List l,
                                NodeVisitor v)
Visit all the elements of a list.

Specified by:
visitList in interface Node
Parameters:
l - The list to visit.
v - The visitor to use.
Returns:
A new list with each element from the old list replaced by the result of visiting that element. If l is a TypedList, the new list will also be typed with the same type as l. If l is null, null is returned.

visitChildren

public Node visitChildren(NodeVisitor v)
Description copied from interface: NodeOps
Visit the children of the node.

Specified by:
visitChildren in interface NodeOps
Parameters:
v - The visitor that will traverse/rewrite the AST.
Returns:
A new AST if a change was made, or this.

enterScope

public Context enterScope(Context c)
Push a new scope upon entering this node, and add any declarations to the context that should be in scope when visiting children of this node.

Specified by:
enterScope in interface NodeOps
Parameters:
c - the current Context
Returns:
the Context to be used for visiting this node.

enterScope

public Context enterScope(Node child,
                          Context c)
Push a new scope for visiting the child node child. The default behavior is to delegate the call to the child node, and let it add appropriate declarations that should be in scope. However, this method gives parent nodes have the ability to modify this behavior.

Specified by:
enterScope in interface NodeOps
Parameters:
child - the child node about to be entered.
c - the current Context
Returns:
the Context to be used for visiting node child

addDecls

public void addDecls(Context c)
Add any declarations to the context that should be in scope when visiting later sibling nodes.

Specified by:
addDecls in interface NodeOps
Parameters:
c - The context to which to add declarations.

buildTypesOverride

public Node buildTypesOverride(TypeBuilder tb)
                        throws SemanticException
Throws:
SemanticException

buildTypesEnter

public NodeVisitor buildTypesEnter(TypeBuilder tb)
                            throws SemanticException
Description copied from interface: NodeOps
Collects classes, methods, and fields from the AST rooted at this node and constructs type objects for these. These type objects may be ambiguous. Inserts classes into the TypeSystem. This method is called by the enter() method of the visitor. The * method should perform work that should be done before visiting the children of the node. The method may return this or a new copy of the node on which visitChildren() and leave() will be invoked.

Specified by:
buildTypesEnter in interface NodeOps
Parameters:
tb - The visitor which adds new type objects to the TypeSystem.
Throws:
SemanticException

buildTypes

public Node buildTypes(TypeBuilder tb)
                throws SemanticException
Description copied from interface: NodeOps
Collects classes, methods, and fields from the AST rooted at this node and constructs type objects for these. These type objects may be ambiguous. Inserts classes into the TypeSystem. This method is called by the leave() method of the visitor. The method should perform work that should be done after visiting the children of the node. The method may return this or a new copy of the node which will be installed as a child of the node's parent.

Specified by:
buildTypes in interface NodeOps
Parameters:
tb - The visitor which adds new type objects to the TypeSystem.
Throws:
SemanticException

disambiguateOverride

public Node disambiguateOverride(AmbiguityRemover ar)
                          throws SemanticException
Remove any remaining ambiguities from the AST.

Throws:
SemanticException

disambiguateEnter

public NodeVisitor disambiguateEnter(AmbiguityRemover ar)
                              throws SemanticException
Description copied from interface: NodeOps
Remove any remaining ambiguities from the AST. This method is called by the enter() method of the visitor. The * method should perform work that should be done before visiting the children of the node. The method may return this or a new copy of the node on which visitChildren() and leave() will be invoked.

Specified by:
disambiguateEnter in interface NodeOps
Parameters:
ar - The visitor which disambiguates.
Throws:
SemanticException

disambiguate

public Node disambiguate(AmbiguityRemover ar)
                  throws SemanticException
Description copied from interface: NodeOps
Remove any remaining ambiguities from the AST. This method is called by the leave() method of the visitor. The method should perform work that should be done after visiting the children of the node. The method may return this or a new copy of the node which will be installed as a child of the node's parent.

Specified by:
disambiguate in interface NodeOps
Parameters:
ar - The visitor which disambiguates.
Throws:
SemanticException

addMembersOverride

public Node addMembersOverride(AddMemberVisitor am)
                        throws SemanticException
Add members to a class.

Throws:
SemanticException

addMembersEnter

public NodeVisitor addMembersEnter(AddMemberVisitor am)
                            throws SemanticException
Description copied from interface: NodeOps
Adds disambiguated methods and fields to the types. This method is called by the enter() method of the visitor. The * method should perform work that should be done before visiting the children of the node. The method may return this or a new copy of the node on which visitChildren() and leave() will be invoked.

Specified by:
addMembersEnter in interface NodeOps
Parameters:
am - The visitor which builds types.
Throws:
SemanticException

addMembers

public Node addMembers(AddMemberVisitor am)
                throws SemanticException
Description copied from interface: NodeOps
Adds disambiguated methods and fields to the types. This method is called by the leave() method of the visitor. The method should perform work that should be done after visiting the children of the node. The method may return this or a new copy of the node which will be installed as a child of the node's parent.

Specified by:
addMembers in interface NodeOps
Parameters:
am - The visitor which builds types.
Throws:
SemanticException

typeCheckOverride

public Node typeCheckOverride(TypeChecker tc)
                       throws SemanticException
Type check the AST.

Throws:
SemanticException

typeCheckEnter

public NodeVisitor typeCheckEnter(TypeChecker tc)
                           throws SemanticException
Description copied from interface: NodeOps
Type check the AST. This method is called by the enter() method of the visitor. The * method should perform work that should be done before visiting the children of the node. The method may return this or a new copy of the node on which visitChildren() and leave() will be invoked.

Specified by:
typeCheckEnter in interface NodeOps
Parameters:
tc - The type checking visitor.
Throws:
SemanticException

typeCheck

public Node typeCheck(TypeChecker tc)
               throws SemanticException
Description copied from interface: NodeOps
Type check the AST. This method is called by the leave() method of the visitor. The method should perform work that should be done after visiting the children of the node. The method may return this or a new copy of the node which will be installed as a child of the node's parent.

Specified by:
typeCheck in interface NodeOps
Parameters:
tc - The type checking visitor.
Throws:
SemanticException

childExpectedType

public Type childExpectedType(Expr child,
                              AscriptionVisitor av)
Description copied from interface: Node
Get the expected type of a child expression of this. The expected type is determined by the context in that the child occurs (e.g., for x = e, the expected type of e is the declared type of x. The expected type should impose the least constraints on the child's type that are allowed by the parent node.

Specified by:
childExpectedType in interface Node
Parameters:
child - A child expression of this node.
av - An ascription visitor.
Returns:
The expected type of child.

exceptionCheckOverride

public Node exceptionCheckOverride(ExceptionChecker ec)
                            throws SemanticException
Check that exceptions are properly propagated throughout the AST.

Throws:
SemanticException

exceptionCheckEnter

public NodeVisitor exceptionCheckEnter(ExceptionChecker ec)
                                throws SemanticException
Description copied from interface: NodeOps
Check that exceptions are properly propagated throughout the AST. This method is called by the enter() method of the visitor. The * method should perform work that should be done before visiting the children of the node. The method may return this or a new copy of the node on which visitChildren() and leave() will be invoked.

Specified by:
exceptionCheckEnter in interface NodeOps
Parameters:
ec - The visitor.
Throws:
SemanticException

exceptionCheck

public Node exceptionCheck(ExceptionChecker ec)
                    throws SemanticException
Description copied from interface: NodeOps
Check that exceptions are properly propagated throughout the AST. This method is called by the leave() method of the visitor. The method should perform work that should be done after visiting the children of the node. The method may return this or a new copy of the node which will be installed as a child of the node's parent.

Specified by:
exceptionCheck in interface NodeOps
Parameters:
ec - The visitor.
Throws:
SemanticException

throwTypes

public java.util.List throwTypes(TypeSystem ts)
Description copied from interface: NodeOps
List of Types of exceptions that might get thrown. The result is not necessarily correct until after type checking.

Specified by:
throwTypes in interface NodeOps

prettyPrint

public void prettyPrint(CodeWriter w,
                        PrettyPrinter pp)
Pretty-print the AST using the given CodeWriter.

Specified by:
prettyPrint in interface NodeOps
Parameters:
w - The code writer to which to write.
pp - The pretty printer. This is not a visitor.

printBlock

public void printBlock(Node n,
                       CodeWriter w,
                       PrettyPrinter pp)

printSubStmt

public void printSubStmt(Stmt stmt,
                         CodeWriter w,
                         PrettyPrinter pp)

print

public void print(Node child,
                  CodeWriter w,
                  PrettyPrinter pp)

translate

public void translate(CodeWriter w,
                      Translator tr)
Translate the AST using the given CodeWriter.

Specified by:
translate in interface NodeOps
Parameters:
w - The code writer to which to write.
tr - The translation pass. This is not a visitor.

dump

public void dump(CodeWriter w)
Description copied from interface: Node
Dump the AST node for debugging purposes.

Specified by:
dump in interface Node

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object