polyglot.ast
Interface NodeOps

All Known Subinterfaces:
AmbAssign, AmbExpr, Ambiguous, AmbKeySetNode, AmbPrefix, AmbQualifierNode, AmbReceiver, AmbTypeNode, ArrayAccess, ArrayAccessAssign, ArrayInit, ArrayTypeNode, Assert, Assign, Binary, Block, BooleanLit, Branch, Call, CanonicalKeySetNode, CanonicalTypeNode, Case, Cast, Catch, CharLit, ClassBody, ClassDecl, ClassLit, ClassMember, CodeDecl, CofferClassDecl, CofferConstructorDecl, CofferMethodDecl, CompoundStmt, Conditional, ConstructorCall, ConstructorDecl, Do, Empty, Eval, Expr, Field, FieldAssign, FieldDecl, FloatLit, For, ForInit, Formal, ForUpdate, Free, If, Import, Initializer, Instanceof, IntLit, JL, KeyNode, KeySetNode, Labeled, Lit, Local, LocalAssign, LocalClassDecl, LocalDecl, Loop, MethodDecl, New, NewArray, Node, NullLit, NumLit, PackageNode, Prefix, ProcedureCall, ProcedureDecl, QualifierNode, Receiver, Return, SourceCollection, SourceFile, Special, Stmt, StringLit, Switch, SwitchBlock, SwitchElement, Synchronized, Term, Throw, ThrowConstraintNode, TopLevelDecl, TrackedTypeNode, Try, TypeNode, Unary, VarDecl, Variable, While
All Known Implementing Classes:
AbstractBlock_c, AmbAssign_c, AmbExpr_c, AmbKeySetNode_c, AmbPrefix_c, AmbQualifierNode_c, AmbReceiver_c, AmbTypeNode_c, ArrayAccess_c, ArrayAccessAssign_c, ArrayInit_c, ArrayTypeNode_c, Assert_c, Assign_c, AssignDel_c, Binary_c, Block_c, BooleanLit_c, Branch_c, Call_c, CanonicalKeySetNode_c, CanonicalTypeNode_c, Case_c, Cast_c, Catch_c, CharLit_c, ClassBody_c, ClassDecl_c, ClassLit_c, CofferClassDecl_c, CofferConstructorDecl_c, CofferMethodDecl_c, Conditional_c, ConstructorCall_c, ConstructorDecl_c, Do_c, Empty_c, Eval_c, Expr_c, Field_c, FieldAssign_c, FieldDecl_c, FloatLit_c, For_c, Formal_c, Free_c, If_c, Import_c, Initializer_c, Instanceof_c, IntLit_c, JL_c, KeyNode_c, Labeled_c, Lit_c, Local_c, LocalAssign_c, LocalClassDecl_c, LocalDecl_c, Loop_c, MethodDecl_c, New_c, NewArray_c, Node_c, NullLit_c, NumLit_c, PackageNode_c, PaoInstanceofDel_c, Return_c, SourceCollection_c, SourceFile_c, Special_c, Stmt_c, StringLit_c, Switch_c, SwitchBlock_c, Synchronized_c, Term_c, Throw_c, ThrowConstraintNode_c, TrackedTypeNode_c, Try_c, TypeNode_c, Unary_c, While_c

public interface NodeOps

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.


Method Summary
 void addDecls(Context c)
          Add any declarations to the context that should be in scope when visiting later sibling nodes.
 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 checkConstants(ConstantChecker cc)
           
 Node disambiguate(AmbiguityRemover ar)
          Remove any remaining ambiguities from the AST.
 NodeVisitor disambiguateEnter(AmbiguityRemover ar)
           
 Node disambiguateOverride(Node parent, AmbiguityRemover ar)
          Remove any remaining ambiguities from the AST.
 void dump(java.io.OutputStream os)
          Dump the AST for debugging.
 void dump(java.io.Writer w)
          Dump the AST for debugging.
 Context enterChildScope(Node child, Context c)
          Push a new scope for visiting the child node child.
 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.
 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.
 void prettyPrint(CodeWriter w, PrettyPrinter pp)
          Pretty-print the AST using the given code writer.
 void prettyPrint(java.io.OutputStream os)
          Pretty-print the AST for debugging.
 void prettyPrint(java.io.Writer w)
          Pretty-print the AST for debugging.
 java.util.List throwTypes(TypeSystem ts)
          List of Types of exceptions that might get thrown.
 void translate(CodeWriter w, Translator tr)
          Translate the AST using the given code writer.
 Node typeCheck(TypeChecker tc)
           
 NodeVisitor typeCheckEnter(TypeChecker tc)
          Type check the AST.
 Node typeCheckOverride(Node parent, TypeChecker tc)
          Type check the AST.
 Node visitChildren(NodeVisitor v)
          Visit the children of the node.
 

Method Detail

visitChildren

Node visitChildren(NodeVisitor v)
Visit the children of the node.

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

enterScope

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. This should not update the old context imperatively. Use addDecls when leaving the node for that.

Parameters:
c - the current Context
Returns:
the Context to be used for visiting this node.

enterChildScope

Context enterChildScope(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.

Parameters:
child - The child node about to be entered.
c - The current Context
Returns:
the Context to be used for visiting node child

addDecls

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

Parameters:
c - The context to which to add declarations.

buildTypesEnter

NodeVisitor buildTypesEnter(TypeBuilder tb)
                            throws SemanticException
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.

Parameters:
tb - The visitor which adds new type objects to the TypeSystem.
Throws:
SemanticException

buildTypes

Node buildTypes(TypeBuilder tb)
                throws SemanticException
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.

Parameters:
tb - The visitor which adds new type objects to the TypeSystem.
Throws:
SemanticException

disambiguateOverride

Node disambiguateOverride(Node parent,
                          AmbiguityRemover ar)
                          throws SemanticException
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.

Parameters:
ar - The visitor which disambiguates.
Throws:
SemanticException

disambiguateEnter

NodeVisitor disambiguateEnter(AmbiguityRemover ar)
                              throws SemanticException
Throws:
SemanticException

disambiguate

Node disambiguate(AmbiguityRemover ar)
                  throws SemanticException
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. The node should not assume that its children have been disambiguated. If it depends on a child being disambiguated, it may just return this without doing any work.

Parameters:
ar - The visitor which disambiguates.
Throws:
SemanticException

typeCheckEnter

NodeVisitor typeCheckEnter(TypeChecker tc)
                           throws SemanticException
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.

Parameters:
tc - The type checking visitor.
Throws:
SemanticException

typeCheckOverride

Node typeCheckOverride(Node parent,
                       TypeChecker tc)
                       throws SemanticException
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.

Parameters:
tc - The type checking visitor.
Throws:
SemanticException

typeCheck

Node typeCheck(TypeChecker tc)
               throws SemanticException
Throws:
SemanticException

checkConstants

Node checkConstants(ConstantChecker cc)
                    throws SemanticException
Throws:
SemanticException

exceptionCheckEnter

NodeVisitor exceptionCheckEnter(ExceptionChecker ec)
                                throws SemanticException
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.

Parameters:
ec - The visitor.
Throws:
SemanticException

exceptionCheck

Node exceptionCheck(ExceptionChecker ec)
                    throws SemanticException
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.

Parameters:
ec - The visitor.
Throws:
SemanticException

throwTypes

java.util.List throwTypes(TypeSystem ts)
List of Types of exceptions that might get thrown. The result is not necessarily correct until after type checking.


dump

void dump(java.io.OutputStream os)
Dump the AST for debugging.


dump

void dump(java.io.Writer w)
Dump the AST for debugging.


prettyPrint

void prettyPrint(java.io.OutputStream os)
Pretty-print the AST for debugging.


prettyPrint

void prettyPrint(java.io.Writer w)
Pretty-print the AST for debugging.


prettyPrint

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

Parameters:
w - The code writer to which to write.
pp - The pretty printer. This is not a visitor.

translate

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

Parameters:
w - The code writer to which to write.
tr - The translation pass. This is not a visitor.