public class ErrorHandlingVisitor extends HaltingVisitor
Modifier and Type | Field and Description |
---|---|
protected boolean |
error |
protected Job |
job |
protected NodeFactory |
nf |
protected TypeSystem |
ts |
bypass, bypassParent
Constructor and Description |
---|
ErrorHandlingVisitor(Job job,
TypeSystem ts,
NodeFactory nf) |
Modifier and Type | Method and Description |
---|---|
NodeVisitor |
begin()
Part of the initialization done by begin() in an ErrorHandlingVisitor
method is initializing the error-handling state.
|
protected boolean |
catchErrors(Node n)
Return true if we should catch errors thrown when visiting the node.
|
NodeVisitor |
enter(Node parent,
Node n)
Begin normal traversal of a subtree rooted at
n . |
protected NodeVisitor |
enterCall(Node n) |
protected NodeVisitor |
enterCall(Node parent,
Node n)
Replaces the functionality of the
enter() method; all
sub-classes should over-ride this method instead of
enter() if there is any chance of exceptions being
generated. |
protected NodeVisitor |
enterError(Node n)
This method determines what should be returned by
enter()
should its call to enterCall() throw a
SemanticException . |
ErrorQueue |
errorQueue()
Returns the
ErrorQueue for the current Job. |
boolean |
hasErrors()
Returns true if some errors have been reported, even if cleared.
|
Job |
job()
Returns the
Job that this Visitor is part of. |
Node |
leave(Node parent,
Node old,
Node n,
NodeVisitor v)
This method is called after all of the children of
n
have been visited. |
protected Node |
leaveCall(Node n) |
protected Node |
leaveCall(Node parent,
Node old,
Node n,
NodeVisitor v)
Contains all of the functionality that can be done in the
leave
method, but allows SemanticExceptions to be
thrown. |
protected Node |
leaveCall(Node old,
Node n,
NodeVisitor v) |
NodeFactory |
nodeFactory()
Returns the
NodeFactory that this Visitor is using. |
TypeSystem |
typeSystem()
Returns the
TypeSystem that this Visitor is using. |
bypass, bypass, bypassChildren, override, visitChildren
protected boolean error
protected Job job
protected TypeSystem ts
protected NodeFactory nf
public ErrorHandlingVisitor(Job job, TypeSystem ts, NodeFactory nf)
public NodeVisitor begin()
begin
in class NodeVisitor
NodeVisitor
to traverse the ast with. If
null
is returned, the ast is not traversed.public ErrorQueue errorQueue()
ErrorQueue
for the current Job.ErrorQueue
public boolean hasErrors()
public NodeFactory nodeFactory()
NodeFactory
that this Visitor is using.NodeFactory
public TypeSystem typeSystem()
TypeSystem
that this Visitor is using.TypeSystem
protected NodeVisitor enterCall(Node parent, Node n) throws SemanticException
enter()
method; all
sub-classes should over-ride this method instead of
enter()
if there is any chance of exceptions being
generated.
This method is the replacement for the enter()
method,
so that all of its subclasses gain the error handling capabilities
of this visitor without having to rewrite it for the
enter()
for each sub-class.
This method allows for a SemanticException
to be
thrown in the body, while enter()
does not.n
- The root of the subtree to be traversed.ErrorHandlingVisitor
which should be
used to visit the children of n
.SemanticException
NodeVisitor.enter(Node, Node)
protected NodeVisitor enterCall(Node n) throws SemanticException
SemanticException
protected NodeVisitor enterError(Node n)
enter()
should its call to enterCall()
throw a
SemanticException
.n
- The root of the subtree that was traversed.ErrorHandlingVisitor
which should be
used to visit the children of n
.protected Node leaveCall(Node parent, Node old, Node n, NodeVisitor v) throws SemanticException
leave
method, but allows SemanticExceptions
to be
thrown.
This method is in addition to the leave
method,
and allows the compiler writer to write code that can throw errors
and let the Polyglot infrastructure handle the exceptions.old
- The original state of root of the current subtree.n
- The current state of the root of the current subtree.v
- The NodeVisitor
object used to visit the children.n
.SemanticException
NodeVisitor.leave(Node, Node, NodeVisitor)
protected Node leaveCall(Node old, Node n, NodeVisitor v) throws SemanticException
SemanticException
protected Node leaveCall(Node n) throws SemanticException
SemanticException
protected boolean catchErrors(Node n)
public NodeVisitor enter(Node parent, Node n)
n
. This gives
the visitor the option of changing internal state or returning a new
visitor which will be used to visit the children of n
.
This method delegates all responsibility of functionality to the
enterCall
method, and handles and reports any exceptions
generated by enterCall
.
In overriding this method, unless the class explicitly does not
want to maintain any of the error handling aspects of this class, a call
super.enter
should be embedded within the method at the
end.enter
in class NodeVisitor
n
- The root of the subtree to be traversed.parent
- The parent of n
, null
if n
has no parent.NodeVisitor
which should be used to visit the
children of n
.public Node leave(Node parent, Node old, Node n, NodeVisitor v)
n
have been visited. In this case, these children were visited by the
visitor v
. This is the last chance for the visitor to
modify the tree rooted at n
. This method will be called
exactly the same number of times as entry
is called.
That is, for each node that is not overridden, enter
and
leave
are each called exactly once.
Note that if old == n
then the visitor should make a copy
of n
before modifying it. It should then return the
modified copy.
This method delegates all responsibility of functionality to the
leaveCall
method, and handles and reports any exceptions
generated by leaveCall
.
In overriding this method, unless the class explicitly does not
want to maintain any of the error handling aspects of this class, a call
super.leave
should be embedded within the method at the
end.
leave
in class NodeVisitor
old
- The original state of root of the current subtree.n
- The current state of the root of the current subtree.v
- The NodeVisitor
object used to visit the children.parent
- The parent of old
,
null
if old
has no parent.n
.