public class Switch_c extends Stmt_c implements Switch
Switch
is an immutable representation of a Java
switch
statement. Such a statement has an expression which
is evaluated to determine where to branch to, an a list of labels
and block statements which are conditionally evaluated. One of the
labels, rather than having a constant expression, may be labelled
default.Term.Instance
Modifier and Type | Field and Description |
---|---|
protected java.util.List<SwitchElement> |
elements |
protected Expr |
expr |
exceptions, reachable
Constructor and Description |
---|
Switch_c(Position pos,
Expr expr,
java.util.List<SwitchElement> elements) |
Switch_c(Position pos,
Expr expr,
java.util.List<SwitchElement> elements,
Ext ext) |
Modifier and Type | Method and Description |
---|---|
<T> java.util.List<T> |
acceptCFG(CFGBuilder<?> v,
java.util.List<T> succs)
Visit this term in evaluation order, calling v.edge() for each successor
in succs, if data flows on that edge.
|
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(NodeFactory nf)
Produce a copy of this node using the given NodeFactory.
|
java.util.List<SwitchElement> |
elements()
List of switch elements: case statements or blocks.
|
Switch |
elements(java.util.List<SwitchElement> elements)
Set the list of switch elements: case statements or blocks.
|
protected <N extends Switch_c> |
elements(N n,
java.util.List<SwitchElement> elements) |
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.
|
Expr |
expr()
The expression on which to switch.
|
Switch |
expr(Expr expr)
Set the expression on which to switch.
|
protected <N extends Switch_c> |
expr(N n,
Expr expr) |
Term |
firstChild()
Return the first direct subterm performed when evaluating this term.
|
void |
prettyPrint(CodeWriter w,
PrettyPrinter tr)
Pretty-print the AST using the given
CodeWriter . |
protected <N extends Switch_c> |
reconstruct(N n,
Expr expr,
java.util.List<SwitchElement> elements)
Reconstruct the statement.
|
java.lang.String |
toString() |
Node |
typeCheck(TypeChecker tc)
Type check the AST.
|
Node |
visitChildren(NodeVisitor v)
Visit the children of the node.
|
exceptionCheck, exceptions, exceptions, exceptions, extRewrite, listChild, reachable, reachable, reachable
addDecls, buildTypes, buildTypesEnter, copy, copy, copyIfNeeded, del, del, disambiguate, disambiguateEnter, disambiguateOverride, dump, dump, dump, dump, dump, enterChildScope, error, error, error, exceptionCheckEnter, ext, ext, ext, ext, extRewriteEnter, isDisambiguated, isTypeChecked, lang, position, position, position, prettyPrint, prettyPrint, prettyPrint, prettyPrint, print, printBlock, printSubStmt, throwTypes, translate, typeCheckEnter, typeCheckOverride, visit, visitChild, visitEdge, visitList
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
exceptions, exceptions, reachable, reachable
del, del, dump, error, error, ext, ext, ext, ext, isDisambiguated, isTypeChecked, position, position, visit, visitEdge
addDecls, buildTypes, buildTypesEnter, copy, disambiguate, disambiguateEnter, disambiguateOverride, dump, dump, dump, dump, enterChildScope, exceptionCheck, exceptionCheckEnter, extRewrite, extRewriteEnter, lang, prettyPrint, prettyPrint, prettyPrint, prettyPrint, throwTypes, translate, typeCheckEnter, typeCheckOverride, visitChild, visitList
protected Expr expr
protected java.util.List<SwitchElement> elements
public Switch_c(Position pos, Expr expr, java.util.List<SwitchElement> elements)
public Switch_c(Position pos, Expr expr, java.util.List<SwitchElement> elements, Ext ext)
public Expr expr()
Switch
public Switch expr(Expr expr)
Switch
public java.util.List<SwitchElement> elements()
Switch
elements
in interface Switch
SwitchElement
.public Switch elements(java.util.List<SwitchElement> elements)
Switch
elements
in interface Switch
elements
- A list of SwitchElement
.protected <N extends Switch_c> N elements(N n, java.util.List<SwitchElement> elements)
protected <N extends Switch_c> N reconstruct(N n, Expr expr, java.util.List<SwitchElement> elements)
public Node visitChildren(NodeVisitor v)
NodeOps
visitChildren
in interface NodeOps
visitChildren
in class Node_c
v
- The visitor that will traverse/rewrite the AST.this
.public Context enterScope(Context c)
Node_c
enterScope
in interface NodeOps
enterScope
in class Node_c
c
- the current Context
Context
to be used for visiting this node.public Node typeCheck(TypeChecker tc) throws SemanticException
NodeOps
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.typeCheck
in interface NodeOps
typeCheck
in class Node_c
tc
- The type checking visitor.SemanticException
public Node checkConstants(ConstantChecker cc) throws SemanticException
NodeOps
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.checkConstants
in interface NodeOps
checkConstants
in class Node_c
cc
- The constant checking visitor.SemanticException
public Type childExpectedType(Expr child, AscriptionVisitor av)
NodeOps
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.childExpectedType
in interface NodeOps
childExpectedType
in class Node_c
child
- A child expression of this node.av
- An ascription visitor.child
.public void prettyPrint(CodeWriter w, PrettyPrinter tr)
Node_c
CodeWriter
.prettyPrint
in interface NodeOps
prettyPrint
in class Node_c
w
- The code writer to which to write.tr
- The pretty printer. This is not a visitor.public Term firstChild()
TermOps
firstChild
in interface TermOps
firstChild
in class Term_c
public <T> java.util.List<T> acceptCFG(CFGBuilder<?> v, java.util.List<T> succs)
TermOps