public interface NodeOps
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 | 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(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.
|
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(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.
|
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 |
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.
|
Lang |
lang()
The language defined by this NodeOps implementation.
|
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.
|
java.util.List<Type> |
throwTypes(TypeSystem ts)
List of Types of exceptions that might get thrown.
|
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.
|
<N extends Node> |
visitChild(N child,
NodeVisitor v)
Visit a single child of the node.
|
Node |
visitChildren(NodeVisitor v)
Visit the children of the node.
|
<N extends Node> |
visitList(java.util.List<N> l,
NodeVisitor v)
Visit all the elements of a list.
|
Lang lang()
<N extends Node> N visitChild(N child, NodeVisitor v)
v
- The visitor which will traverse/rewrite the AST.child
- The child to visit.child.visit(v)
, or null
if child
was null
.<N extends Node> java.util.List<N> visitList(java.util.List<N> l, NodeVisitor v)
l
- The list to visit.v
- The visitor to use.l
is null
,
null
is returned.Node visitChildren(NodeVisitor v)
v
- The visitor that will traverse/rewrite the AST.this
.Context enterScope(Context c)
addDecls
when leaving the node
for that.c
- the current Context
Context
to be used for visiting this node.Context enterChildScope(Node child, Context c)
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.child
- the child node about to be entered.c
- the current Context
Context
to be used for visiting node
child
void addDecls(Context c)
c
- The context to which to add declarations.NodeVisitor buildTypesEnter(TypeBuilder tb) throws SemanticException
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.tb
- The visitor which adds new type objects to the
TypeSystem
.SemanticException
Node buildTypes(TypeBuilder tb) throws SemanticException
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.tb
- The visitor which adds new type objects to the
TypeSystem
.SemanticException
Node disambiguateOverride(Node parent, AmbiguityRemover ar) throws SemanticException
override()
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.ar
- The visitor which disambiguates.SemanticException
NodeVisitor disambiguateEnter(AmbiguityRemover ar) throws SemanticException
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.ar
- The visitor which disambiguates.SemanticException
Node disambiguate(AmbiguityRemover ar) throws SemanticException
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.ar
- The visitor which disambiguates.SemanticException
Node typeCheckOverride(Node parent, TypeChecker tc) throws SemanticException
override()
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.tc
- The type checking visitor.SemanticException
NodeVisitor typeCheckEnter(TypeChecker tc) throws SemanticException
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.tc
- The type checking visitor.SemanticException
Node typeCheck(TypeChecker tc) throws SemanticException
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.tc
- The type checking visitor.SemanticException
Type childExpectedType(Expr child, AscriptionVisitor av)
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.child
- A child expression of this node.av
- An ascription visitor.child
.Node checkConstants(ConstantChecker cc) throws SemanticException
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.cc
- The constant checking visitor.SemanticException
NodeVisitor exceptionCheckEnter(ExceptionChecker ec) throws SemanticException
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.ec
- The visitor.SemanticException
Node exceptionCheck(ExceptionChecker ec) throws SemanticException
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.ec
- The visitor.SemanticException
java.util.List<Type> throwTypes(TypeSystem ts)
NodeVisitor extRewriteEnter(ExtensionRewriter rw) throws SemanticException
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.rw
- The visitor.SemanticException
Node extRewrite(ExtensionRewriter rw) throws SemanticException
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.rw
- The visitor.SemanticException
@Deprecated void dump(java.io.OutputStream os)
void dump(Lang lang, java.io.OutputStream os)
@Deprecated void dump(java.io.Writer w)
void dump(Lang lang, java.io.Writer w)
@Deprecated void prettyPrint(java.io.OutputStream os)
void prettyPrint(Lang lang, java.io.OutputStream os)
@Deprecated void prettyPrint(java.io.Writer w)
void prettyPrint(Lang lang, java.io.Writer w)
void prettyPrint(CodeWriter w, PrettyPrinter pp)
CodeWriter
.w
- The code writer to which to write.pp
- The pretty printer. This is not a visitor.void translate(CodeWriter w, Translator tr)
CodeWriter
.w
- The code writer to which to write.tr
- The translation pass. This is not a visitor.Node copy(NodeFactory nf)
Node copy(ExtensionInfo extInfo) throws SemanticException
SemanticException
- If the type information cannot be copied.