|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--openjava.ptree.ParseTreeObject | +--openjava.ptree.NonLeaf | +--openjava.ptree.BinaryExpression
The BinaryExpression
class represents
an expression which consists of an operators and two operands.
This doesn't includes the expression whose operator is
the instanceof
operator
nor the expression whose operator is one of the
assignment operators.
If the operator in the expression of the left operand or
the right operand has week unity,
this automatically produces the code in which the left operand
is enclosed by parenthesises.
In the case the left is a + b
,
the operator is *
the right is c + d
,
this produces the code :
(a + b) * (c + d)
Expression
,
InstanceofExpression
,
AssignmentExpression
Field Summary | |
static int |
BITAND
|
static int |
BITOR
|
static int |
DIVIDE
|
static int |
EQUAL
|
static int |
GREATER
|
static int |
GREATEREQUAL
|
static int |
IN
|
static int |
INSTANCEOF
|
static int |
INTERSECT
|
static int |
LESS
|
static int |
LESSEQUAL
|
static int |
LOGICAL_AND
|
static int |
LOGICAL_OR
|
static int |
MINUS
|
static int |
MOD
|
static int |
NOTEQUAL
|
private int |
opr
the operator |
(package private) static String[] |
opr_string
|
private static int |
OTHER
|
static int |
PLUS
|
static int |
REL_MINUS
|
static int |
SHIFT_L
|
static int |
SHIFT_R
|
static int |
SHIFT_RR
|
private static int |
STRING
|
static int |
TIMES
|
static int |
UNION
|
static int |
XOR
|
Fields inherited from class openjava.ptree.NonLeaf |
|
Fields inherited from class openjava.ptree.ParseTreeObject |
debugFlag, debugLevel, LN, out, writerStack |
Constructor Summary | |
(package private) |
BinaryExpression()
|
|
BinaryExpression(Expression lexp,
int opr,
Expression rexp)
Allocates a new object. |
|
BinaryExpression(Expression lexp,
String opr,
Expression rexp)
|
Method Summary | |
void |
accept(ParseTreeVisitor v)
Accepts a ParseTreeVisitor object as the role of a
Visitor in the Visitor pattern, as the role of an Element in the
Visitor pattern. |
(package private) static OJClass |
chooseType(OJClass left,
OJClass right)
|
Expression |
getLeft()
Gets the expression of the left operand. |
int |
getOperator()
Gets the id number of the operator. |
Expression |
getRight()
Gets the expression of the right operand. |
OJClass |
getType(Environment env)
|
ParseTree |
makeCopy()
Makes a new copy of this nonleaf-node as a ptree-node. |
ParseTree |
makeRecursiveCopy()
Makes a new copy (another object) of this nonleaf-node recursively. |
private boolean |
needsLeftPar(Expression leftexpr)
|
private boolean |
needsRightPar(Expression rightexpr)
|
String |
operatorString()
|
void |
setLeft(Expression lexpr)
Sets the expression of the left operand. |
void |
setOperator(int opr)
Sets the id number of the operator. |
void |
setRight(Expression rexpr)
Sets the expression of the right operand. |
protected static int |
strength(int op)
Returns the strength of the union of the operator. |
private static int |
strength(OJClass type)
|
void |
writeCode()
Writes the code this parse-tree presents for. |
Methods inherited from class openjava.ptree.NonLeaf |
childrenAccept, childrenAreEqual, elementAt, equals, getComment, getContents, getLength, getRowType, replaceChildWith, set, set, set, set, set, set, set, set, set, setComment, setElementAt |
Methods inherited from class openjava.ptree.ParseTreeObject |
clone, eq, eq, equal, flushPrintWriter, getDebugFlag, getNest, getObjectID, getParent, getPrintWriter, getTab, hashCode, lastObjectID, popNest, popPrintWriter, pushNest, pushPrintWriter, replace, setDebugFlag, setDebugLevel, setNest, setParent, setPrintStream, setTab, toFlattenString, toString, writeDebug, writeDebugL, writeDebugLln, writeDebugln, writeDebugLR, writeDebugR, writeDebugRln, writeTab |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface openjava.ptree.Expression |
getRowType |
Methods inherited from interface openjava.ptree.ParseTree |
childrenAccept, eq, equals, getObjectID, replace, toFlattenString, toString |
Field Detail |
public static final int TIMES
public static final int DIVIDE
public static final int MOD
public static final int PLUS
public static final int MINUS
public static final int SHIFT_L
public static final int SHIFT_R
public static final int SHIFT_RR
public static final int LESS
public static final int GREATER
public static final int LESSEQUAL
public static final int GREATEREQUAL
public static final int INSTANCEOF
public static final int EQUAL
public static final int NOTEQUAL
public static final int BITAND
public static final int XOR
public static final int BITOR
public static final int LOGICAL_AND
public static final int LOGICAL_OR
public static final int IN
public static final int UNION
public static final int REL_MINUS
public static final int INTERSECT
static final String[] opr_string
private int opr
private static final int STRING
private static final int OTHER
Constructor Detail |
public BinaryExpression(Expression lexp, int opr, Expression rexp)
lexp
- the expression of the left operand.opr
- the id number of operator.rexp
- the expression of the right operand.public BinaryExpression(Expression lexp, String opr, Expression rexp)
BinaryExpression()
Method Detail |
public ParseTree makeRecursiveCopy()
ParseTree
makeRecursiveCopy
in interface ParseTree
makeRecursiveCopy
in class NonLeaf
public ParseTree makeCopy()
ParseTree
makeCopy
in interface ParseTree
makeCopy
in class ParseTreeObject
public void writeCode()
NonLeaf
writeCode
in interface ParseTree
writeCode
in class NonLeaf
private final boolean needsLeftPar(Expression leftexpr)
private final boolean needsRightPar(Expression rightexpr)
protected static final int strength(int op)
op
- the id number of operator.
public Expression getLeft()
public void setLeft(Expression lexpr)
lexpr
- the left expression.public Expression getRight()
public void setRight(Expression rexpr)
rexpr
- the right expression.public int getOperator()
TIMES
,
DIVIDE
,
MOD
,
PLUS
,
MINUS
,
SHIFT_L
,
SHIFT_R
,
SHIFT_RR
,
LESS
,
GREATER
,
LESSEQUAL
,
GREATEREQUAL
,
INSTANCEOF
,
EQUAL
,
NOTEQUAL
,
BITAND
,
XOR
,
BITOR
,
LOGICAL_AND
,
LOGICAL_OR
,
IN
public void setOperator(int opr)
opr
- the id number of the operator.TIMES
,
DIVIDE
,
MOD
,
PLUS
,
MINUS
,
SHIFT_L
,
SHIFT_R
,
SHIFT_RR
,
LESS
,
GREATER
,
LESSEQUAL
,
GREATEREQUAL
,
INSTANCEOF
,
EQUAL
,
NOTEQUAL
,
BITAND
,
XOR
,
BITOR
,
LOGICAL_AND
,
LOGICAL_OR
,
IN
public String operatorString()
public void accept(ParseTreeVisitor v) throws ParseTreeException
ParseTree
ParseTreeVisitor
object as the role of a
Visitor in the Visitor pattern, as the role of an Element in the
Visitor pattern.
This invoke an appropriate visit()
method on the
accepted visitor.
accept
in interface ParseTree
accept
in class ParseTreeObject
v
- a visitor
ParseTreeException
public OJClass getType(Environment env) throws Exception
getType
in interface Expression
Exception
static OJClass chooseType(OJClass left, OJClass right)
private static int strength(OJClass type)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |