polyglot.ext.jl.ast
Class Expr_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.Expr_c
All Implemented Interfaces:
java.lang.Cloneable, Expr, JL, Node, NodeOps, Prefix, Receiver, Term, Typed, Copy
Direct Known Subclasses:
AmbExpr_c, ArrayAccess_c, ArrayInit_c, Assign_c, Binary_c, Call_c, Cast_c, Conditional_c, Field_c, Instanceof_c, Lit_c, Local_c, New_c, NewArray_c, Special_c, Unary_c

public abstract class Expr_c
extends Term_c
implements Expr

An Expr represents any Java expression. All expressions must be subtypes of Expr.


Field Summary
protected  Type type
           
 
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
Expr_c(Position pos)
           
 
Method Summary
 boolean booleanValue()
           
 Node buildTypes(TypeBuilder tb)
          Collects classes, methods, and fields from the AST rooted at this node and constructs type objects for these.
 byte byteValue()
           
 char charValue()
           
 java.lang.Object constantValue()
          Returns the constant value of the expression, if any.
 double doubleValue()
           
 void dump(CodeWriter w)
          Dump the AST node for debugging purposes.
 float floatValue()
           
 int intValue()
           
 boolean isConstant()
          Return whether the expression evaluates to a constant.
 long longValue()
           
 Precedence precedence()
          Get the precedence of the expression.
 void printSubExpr(Expr expr, boolean associative, CodeWriter w, PrettyPrinter pp)
          Correctly parenthesize the subexpression expr given the its precendence and the precedence of the current expression.
 void printSubExpr(Expr expr, CodeWriter w, PrettyPrinter pp)
          Correctly parenthesize the subexpression expr given the its precendence and the precedence of the current expression.
 short shortValue()
           
 java.lang.String stringValue()
           
 Type type()
          Get the type of the expression.
 Expr type(Type type)
          Set the type of the expression.
 
Methods inherited from class polyglot.ext.jl.ast.Term_c
acceptCFG, entry, exceptionCheck, exceptions, exceptions, listEntry, reachable, reachable
 
Methods inherited from class polyglot.ext.jl.ast.Node_c
addDecls, addMembers, addMembersEnter, addMembersOverride, buildTypesEnter, buildTypesOverride, childExpectedType, copy, del, del, disambiguate, disambiguateEnter, disambiguateOverride, enterScope, enterScope, exceptionCheckEnter, exceptionCheckOverride, ext, ext, ext, ext, init, node, position, position, prettyPrint, print, printBlock, printSubStmt, throwTypes, toString, translate, typeCheck, typeCheckEnter, typeCheckOverride, visit, visitChild, visitChildren, 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.Node
childExpectedType, del, del, 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, buildTypesEnter, disambiguate, disambiguateEnter, enterScope, enterScope, exceptionCheck, exceptionCheckEnter, prettyPrint, throwTypes, translate, typeCheck, typeCheckEnter, visitChildren
 
Methods inherited from interface polyglot.util.Copy
copy
 
Methods inherited from interface polyglot.ast.Term
acceptCFG, entry, exceptions, exceptions, reachable, reachable
 

Field Detail

type

protected Type type
Constructor Detail

Expr_c

public Expr_c(Position pos)
Method Detail

type

public Type type()
Get the type of the expression. This may return an UnknownType before type-checking, but should return the correct type after type-checking.

Specified by:
type in interface Typed

type

public Expr type(Type type)
Set the type of the expression.

Specified by:
type in interface Expr

dump

public void dump(CodeWriter w)
Description copied from interface: Node
Dump the AST node for debugging purposes.

Specified by:
dump in interface Node
Overrides:
dump in class Node_c

precedence

public Precedence precedence()
Get the precedence of the expression.

Specified by:
precedence in interface Expr

isConstant

public boolean isConstant()
Description copied from interface: Expr
Return whether the expression evaluates to a constant. This is not valid until after disambiguation.

Specified by:
isConstant in interface Expr

constantValue

public java.lang.Object constantValue()
Description copied from interface: Expr
Returns the constant value of the expression, if any.

Specified by:
constantValue in interface Expr

stringValue

public java.lang.String stringValue()

booleanValue

public boolean booleanValue()

byteValue

public byte byteValue()

shortValue

public short shortValue()

charValue

public char charValue()

intValue

public int intValue()

longValue

public long longValue()

floatValue

public float floatValue()

doubleValue

public double doubleValue()

buildTypes

public Node buildTypes(TypeBuilder tb)
                throws SemanticException
Description copied from interface: NodeOps
Collects classes, methods, and fields from the AST rooted at this node and constructs type objects for these. These type objects may be ambiguous. Inserts classes into the 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.

Specified by:
buildTypes in interface NodeOps
Overrides:
buildTypes in class Node_c
Parameters:
tb - The visitor which adds new type objects to the TypeSystem.
Throws:
SemanticException

printSubExpr

public void printSubExpr(Expr expr,
                         CodeWriter w,
                         PrettyPrinter pp)
Correctly parenthesize the subexpression expr given the its precendence and the precedence of the current expression. If the sub-expression has the same precedence as this expression we do not parenthesize.

Specified by:
printSubExpr in interface Expr
Parameters:
expr - The subexpression. (right-) associative operator.
w - The output writer.
pp - The pretty printer.

printSubExpr

public void printSubExpr(Expr expr,
                         boolean associative,
                         CodeWriter w,
                         PrettyPrinter pp)
Correctly parenthesize the subexpression expr given the its precendence and the precedence of the current expression. If the sub-expression has the same precedence as this expression we parenthesize if the sub-expression does not associate; e.g., we parenthesis the right sub-expression of a left-associative operator.

Specified by:
printSubExpr in interface Expr
Parameters:
expr - The subexpression.
associative - Whether expr is the left (right) child of a left- (right-) associative operator.
w - The output writer.
pp - The pretty printer.