public abstract class Node_c extends java.lang.Object implements Node
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.| Modifier and Type | Field and Description |
|---|---|
protected JLDel |
del
Deprecated.
|
protected boolean |
error |
protected Ext |
ext |
protected Position |
position |
| Constructor and Description |
|---|
Node_c(Position pos)
Deprecated.
|
Node_c(Position pos,
Ext ext) |
| Modifier and Type | Method and Description |
|---|---|
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)
Check if the node is a compile-time constant.
|
Type |
childExpectedType(Expr child,
AscriptionVisitor av)
Get the expected type of a child expression of
this. |
Node |
copy() |
Node |
copy(ExtensionInfo extInfo)
Produce a copy of this node using the given ExtensionInfo.
|
Node |
copy(NodeFactory nf)
Produce a copy of this node using the given NodeFactory.
|
protected <N extends Node> |
copyIfNeeded(N n) |
NodeOps |
del()
Deprecated.
|
Node |
del(JLDel del)
Deprecated.
|
Node |
disambiguate(AmbiguityRemover ar)
Remove any remaining ambiguities from the AST.
|
NodeVisitor |
disambiguateEnter(AmbiguityRemover ar)
Remove any remaining ambiguities from the AST.
|
Node |
disambiguateOverride(Node parent,
AmbiguityRemover ar)
Disambiguate the AST.
|
void |
dump(CodeWriter w)
Dump the AST node for debugging purposes.
|
void |
dump(Lang lang,
java.io.OutputStream os)
Dump the AST for debugging.
|
void |
dump(Lang lang,
java.io.Writer w)
Dump the AST for debugging.
|
void |
dump(java.io.OutputStream os)
Deprecated.
|
void |
dump(java.io.Writer w)
Deprecated.
|
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.
|
boolean |
error()
Return true if there an error in this node or its children.
|
Node |
error(boolean flag) |
protected <N extends Node_c> |
error(N n,
boolean flag) |
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.
|
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)
Deprecated.
|
Node |
extRewrite(ExtensionRewriter rw)
Rewrite the AST for the compilation in this language.
|
NodeVisitor |
extRewriteEnter(ExtensionRewriter rw)
Rewrite the AST for the compilation in this language.
|
boolean |
isDisambiguated() |
boolean |
isTypeChecked() |
JLang |
lang()
The language defined by this NodeOps implementation.
|
Position |
position()
Get the position of the node in the source file.
|
protected <N extends Node_c> |
position(N n,
Position position) |
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 |
prettyPrint(Lang lang,
java.io.OutputStream os)
Pretty-print the AST for debugging.
|
void |
prettyPrint(Lang lang,
java.io.Writer w)
Pretty-print the AST for debugging.
|
void |
prettyPrint(java.io.OutputStream os)
Deprecated.
|
void |
prettyPrint(java.io.Writer w)
Deprecated.
|
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<Type> |
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(Node parent,
TypeChecker tc)
Type check the AST.
|
Node |
visit(NodeVisitor v)
Visit the node.
|
<N extends Node> |
visitChild(N 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)
Deprecated.
Call
NodeOps.visitChild(Node, NodeVisitor) instead. |
<T extends Node> |
visitList(java.util.List<T> l,
NodeVisitor v)
Visit all the elements of a list.
|
protected Position position
@Deprecated protected JLDel del
protected Ext ext
protected boolean error
@Deprecated public Node_c(Position pos)
@Deprecated public NodeOps del()
Node@Deprecated public Node del(JLDel del)
Nodepublic Ext ext(int n)
Node@Deprecated public Node ext(int n, Ext ext)
Nodeprotected <N extends Node> N copyIfNeeded(N n)
public Position position()
Nodepublic Node position(Position position)
Nodepublic boolean isDisambiguated()
isDisambiguated in interface Nodepublic boolean isTypeChecked()
isTypeChecked in interface Nodepublic boolean error()
Nodeprotected <N extends Node_c> N error(N n, boolean flag)
public <N extends Node> N visitChild(N n, NodeVisitor v)
NodeOpsvisitChild in interface NodeOpsn - The child to visit.v - The visitor which will traverse/rewrite the AST.child.visit(v), or null
if child was null.public Node visit(NodeVisitor v)
NodevisitEdge(null, v).@Deprecated public Node visitEdge(Node parent, NodeVisitor v)
NodeOps.visitChild(Node, NodeVisitor) instead.NodeNodeVisitor 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.public <T extends Node> java.util.List<T> visitList(java.util.List<T> l, NodeVisitor v)
public final JLang lang()
NodeOpspublic Node visitChildren(NodeVisitor v)
NodeOpsvisitChildren in interface NodeOpsv - The visitor that will traverse/rewrite the AST.this.public Context enterScope(Context c)
enterScope in interface NodeOpsc - the current ContextContext to be used for visiting this node.public Context enterChildScope(Node child, Context c)
NodeOpschild.
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.enterChildScope in interface NodeOpschild - the child node about to be entered.c - the current ContextContext to be used for visiting node
childpublic void addDecls(Context c)
public NodeVisitor buildTypesEnter(TypeBuilder tb) throws SemanticException
NodeOpsTypeSystem.
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.buildTypesEnter in interface NodeOpstb - The visitor which adds new type objects to the
TypeSystem.SemanticExceptionpublic Node buildTypes(TypeBuilder tb) throws SemanticException
NodeOpsTypeSystem.
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.buildTypes in interface NodeOpstb - The visitor which adds new type objects to the
TypeSystem.SemanticExceptionpublic Node disambiguateOverride(Node parent, AmbiguityRemover ar) throws SemanticException
NodeOpsoverride() method of the
visitor. If this method returns non-null, the node's children
will not be visited automatically. Thus, the method should check
both the node this and it's children, usually by
invoking visitChildren with tc or
with another visitor, returning a non-null node. OR, the method
should do nothing and simply return null to allow
enter, visitChildren, and leave
to be invoked on the node.
The default implementation returns null.
Overriding of this method is discouraged, but sometimes necessary.disambiguateOverride in interface NodeOpsar - The visitor which disambiguates.SemanticExceptionpublic NodeVisitor disambiguateEnter(AmbiguityRemover ar) throws SemanticException
NodeOpsenter() 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.disambiguateEnter in interface NodeOpsar - The visitor which disambiguates.SemanticExceptionpublic Node disambiguate(AmbiguityRemover ar) throws SemanticException
NodeOpsleave() 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.disambiguate in interface NodeOpsar - The visitor which disambiguates.SemanticExceptionpublic Node typeCheckOverride(Node parent, TypeChecker tc) throws SemanticException
typeCheckOverride in interface NodeOpstc - The type checking visitor.SemanticExceptionpublic NodeVisitor typeCheckEnter(TypeChecker tc) throws SemanticException
NodeOpsenter() 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.typeCheckEnter in interface NodeOpstc - The type checking visitor.SemanticExceptionpublic Node typeCheck(TypeChecker tc) throws SemanticException
NodeOpsleave() 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.typeCheck in interface NodeOpstc - The type checking visitor.SemanticExceptionpublic Node checkConstants(ConstantChecker cc) throws SemanticException
NodeOpsleave() 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.checkConstants in interface NodeOpscc - The constant checking visitor.SemanticExceptionpublic Type childExpectedType(Expr child, AscriptionVisitor av)
NodeOpsthis.
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.childExpectedType in interface NodeOpschild - A child expression of this node.av - An ascription visitor.child.public NodeVisitor exceptionCheckEnter(ExceptionChecker ec) throws SemanticException
NodeOpsenter() 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.exceptionCheckEnter in interface NodeOpsec - The visitor.SemanticExceptionpublic Node exceptionCheck(ExceptionChecker ec) throws SemanticException
NodeOpsleave() 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.exceptionCheck in interface NodeOpsec - The visitor.SemanticExceptionpublic java.util.List<Type> throwTypes(TypeSystem ts)
NodeOpsthrowTypes in interface NodeOpspublic NodeVisitor extRewriteEnter(ExtensionRewriter rw) throws SemanticException
NodeOpsenter() 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.extRewriteEnter in interface NodeOpsrw - The visitor.SemanticExceptionpublic Node extRewrite(ExtensionRewriter rw) throws SemanticException
NodeOpsleave() 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.extRewrite in interface NodeOpsrw - The visitor.SemanticException@Deprecated public void dump(java.io.OutputStream os)
NodeOpspublic void dump(Lang lang, java.io.OutputStream os)
NodeOps@Deprecated public void dump(java.io.Writer w)
NodeOpspublic void dump(Lang lang, java.io.Writer w)
NodeOps@Deprecated public void prettyPrint(java.io.OutputStream os)
NodeOpsprettyPrint in interface NodeOpspublic void prettyPrint(Lang lang, java.io.OutputStream os)
NodeOpsprettyPrint in interface NodeOps@Deprecated public void prettyPrint(java.io.Writer w)
NodeOpsprettyPrint in interface NodeOpspublic void prettyPrint(Lang lang, java.io.Writer w)
NodeOpsprettyPrint in interface NodeOpspublic void prettyPrint(CodeWriter w, PrettyPrinter pp)
CodeWriter.prettyPrint in interface NodeOpsw - The code writer to which to write.pp - The pretty printer. This is not a visitor.public void printBlock(Node n, CodeWriter w, PrettyPrinter pp)
public void printSubStmt(Stmt stmt, CodeWriter w, PrettyPrinter pp)
public void print(Node child, CodeWriter w, PrettyPrinter pp)
public void translate(CodeWriter w, Translator tr)
NodeOpsCodeWriter.public void dump(CodeWriter w)
Nodepublic java.lang.String toString()
toString in class java.lang.Objectpublic Node copy(NodeFactory nf)
NodeOpspublic Node copy(ExtensionInfo extInfo) throws SemanticException
NodeOpscopy in interface NodeOpsSemanticException - If the type information cannot be copied.