polyglot.ext.jl.ast
Class Switch_c

java.lang.Object
  extended by polyglot.ext.jl.ast.Node_c
      extended by polyglot.ext.jl.ast.Term_c
          extended by polyglot.ext.jl.ast.Stmt_c
              extended by polyglot.ext.jl.ast.Switch_c
All Implemented Interfaces:
java.lang.Cloneable, CompoundStmt, JL, Node, NodeOps, Stmt, Switch, Term, Copy

public class Switch_c
extends Stmt_c
implements Switch

A 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 lablled default.


Field Summary
protected  java.util.List elements
           
protected  Expr expr
           
 
Fields inherited from class polyglot.ext.jl.ast.Term_c
exceptions, reachable
 
Fields inherited from class polyglot.ext.jl.ast.Node_c
del, ext, position
 
Constructor Summary
Switch_c(Position pos, Expr expr, java.util.List elements)
           
 
Method Summary
 java.util.List acceptCFG(CFGBuilder v, java.util.List succs)
          Visit this term in evaluation order.
 Type childExpectedType(Expr child, AscriptionVisitor av)
          Get the expected type of a child expression of this.
 java.util.List elements()
          Get the switch elements of the statement.
 Switch elements(java.util.List elements)
          Set the switch elements of the statement.
 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.
 Term entry()
          Return the first (sub)term performed when evaluating this term.
 Expr expr()
          Get the expression to switch on.
 Switch expr(Expr expr)
          Set the expression to switch on.
 void prettyPrint(CodeWriter w, PrettyPrinter tr)
          Write the statement to an output file.
protected  Switch_c reconstruct(Expr expr, java.util.List elements)
          Reconstruct the statement.
 java.lang.String toString()
           
 Node typeCheck(TypeChecker tc)
          Type check the statement.
 Node visitChildren(NodeVisitor v)
          Visit the children of the statement.
 
Methods inherited from class polyglot.ext.jl.ast.Term_c
exceptionCheck, exceptions, exceptions, listEntry, reachable, reachable
 
Methods inherited from class polyglot.ext.jl.ast.Node_c
addDecls, addMembers, addMembersEnter, addMembersOverride, buildTypes, buildTypesEnter, buildTypesOverride, copy, del, del, disambiguate, disambiguateEnter, disambiguateOverride, dump, enterScope, exceptionCheckEnter, exceptionCheckOverride, ext, ext, ext, ext, init, node, position, position, print, printBlock, printSubStmt, throwTypes, translate, typeCheckEnter, typeCheckOverride, visit, visitChild, visitEdge, visitList
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface polyglot.ast.Term
exceptions, exceptions, reachable, reachable
 
Methods inherited from interface polyglot.ast.Node
del, del, dump, ext, ext, ext, ext, position, position, visit, visitChild, visitEdge, visitList
 
Methods inherited from interface polyglot.ast.JL
init, node
 
Methods inherited from interface polyglot.ast.NodeOps
addDecls, addMembers, addMembersEnter, buildTypes, buildTypesEnter, disambiguate, disambiguateEnter, enterScope, exceptionCheck, exceptionCheckEnter, throwTypes, translate, typeCheckEnter
 
Methods inherited from interface polyglot.util.Copy
copy
 

Field Detail

expr

protected Expr expr

elements

protected java.util.List elements
Constructor Detail

Switch_c

public Switch_c(Position pos,
                Expr expr,
                java.util.List elements)
Method Detail

expr

public Expr expr()
Get the expression to switch on.

Specified by:
expr in interface Switch

expr

public Switch expr(Expr expr)
Set the expression to switch on.

Specified by:
expr in interface Switch

elements

public java.util.List elements()
Get the switch elements of the statement.

Specified by:
elements in interface Switch
Returns:
A list of SwitchElement.

elements

public Switch elements(java.util.List elements)
Set the switch elements of the statement.

Specified by:
elements in interface Switch
Parameters:
elements - A list of SwitchElement.

reconstruct

protected Switch_c reconstruct(Expr expr,
                               java.util.List elements)
Reconstruct the statement.


enterScope

public Context enterScope(Context c)
Description copied from class: Node_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.

Specified by:
enterScope in interface NodeOps
Overrides:
enterScope in class Node_c
Parameters:
c - the current Context
Returns:
the Context to be used for visiting this node.

visitChildren

public Node visitChildren(NodeVisitor v)
Visit the children of the statement.

Specified by:
visitChildren in interface NodeOps
Overrides:
visitChildren in class Node_c
Parameters:
v - The visitor that will traverse/rewrite the AST.
Returns:
A new AST if a change was made, or this.

typeCheck

public Node typeCheck(TypeChecker tc)
               throws SemanticException
Type check the statement.

Specified by:
typeCheck in interface NodeOps
Overrides:
typeCheck in class Node_c
Parameters:
tc - The type checking visitor.
Throws:
SemanticException

childExpectedType

public Type childExpectedType(Expr child,
                              AscriptionVisitor av)
Description copied from interface: Node
Get the expected type of a child expression of 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.

Specified by:
childExpectedType in interface Node
Overrides:
childExpectedType in class Node_c
Parameters:
child - A child expression of this node.
av - An ascription visitor.
Returns:
The expected type of child.

toString

public java.lang.String toString()
Overrides:
toString in class Node_c

prettyPrint

public void prettyPrint(CodeWriter w,
                        PrettyPrinter tr)
Write the statement to an output file.

Specified by:
prettyPrint in interface NodeOps
Overrides:
prettyPrint in class Node_c
Parameters:
w - The code writer to which to write.
tr - The pretty printer. This is not a visitor.

entry

public Term entry()
Description copied from class: Term_c
Return the first (sub)term performed when evaluating this term.

Specified by:
entry in interface Term
Specified by:
entry in class Term_c

acceptCFG

public java.util.List acceptCFG(CFGBuilder v,
                                java.util.List succs)
Description copied from class: Term_c
Visit this term in evaluation order.

Specified by:
acceptCFG in interface Term
Specified by:
acceptCFG in class Term_c