openjava.ptree
Class BinaryExpression

java.lang.Object
  |
  +--openjava.ptree.ParseTreeObject
        |
        +--openjava.ptree.NonLeaf
              |
              +--openjava.ptree.BinaryExpression
All Implemented Interfaces:
java.lang.Cloneable, Expression, ParseTree, VariableInitializer

public class BinaryExpression
extends NonLeaf
implements Expression

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)
 

See Also:
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 INSTANCEOF
           
static int LESS
           
static int LESSEQUAL
           
static int LOGICAL_AND
           
static int LOGICAL_OR
           
static int MINUS
           
static int MOD
           
static int NOTEQUAL
           
static int PLUS
           
static int SHIFT_L
           
static int SHIFT_R
           
static int SHIFT_RR
           
static int TIMES
           
static int XOR
           
 
Fields inherited from class openjava.ptree.ParseTreeObject
debugFlag, debugLevel, LN, out, writerStack
 
Constructor Summary
BinaryExpression(Expression lexp, int opr, Expression rexp)
          Allocates a new object.
BinaryExpression(Expression lexp, java.lang.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. This invoke an appropriate visit() method on the accepted visitor.
 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.
 java.lang.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.
 void writeCode()
          Writes the code this parse-tree presents for.
 
Methods inherited from class openjava.ptree.NonLeaf
childrenAccept, elementAt, equals, getComment, getContents, getLength, 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.ParseTree
childrenAccept, eq, equals, getObjectID, replace, toFlattenString, toString
 

Field Detail

TIMES

public static final int TIMES

DIVIDE

public static final int DIVIDE

MOD

public static final int MOD

PLUS

public static final int PLUS

MINUS

public static final int MINUS

SHIFT_L

public static final int SHIFT_L

SHIFT_R

public static final int SHIFT_R

SHIFT_RR

public static final int SHIFT_RR

LESS

public static final int LESS

GREATER

public static final int GREATER

LESSEQUAL

public static final int LESSEQUAL

GREATEREQUAL

public static final int GREATEREQUAL

INSTANCEOF

public static final int INSTANCEOF

EQUAL

public static final int EQUAL

NOTEQUAL

public static final int NOTEQUAL

BITAND

public static final int BITAND

XOR

public static final int XOR

BITOR

public static final int BITOR

LOGICAL_AND

public static final int LOGICAL_AND

LOGICAL_OR

public static final int LOGICAL_OR
Constructor Detail

BinaryExpression

public BinaryExpression(Expression lexp,
                        int opr,
                        Expression rexp)
Allocates a new object.
Parameters:
lexp - the expression of the left operand.
opr - the id number of operator.
rexp - the expression of the right operand.

BinaryExpression

public BinaryExpression(Expression lexp,
                        java.lang.String opr,
                        Expression rexp)
Method Detail

makeRecursiveCopy

public ParseTree makeRecursiveCopy()
Description copied from interface: ParseTree
Makes a new copy (another object) of this nonleaf-node recursively. The objects contained by this object will also be copied.
Specified by:
makeRecursiveCopy in interface ParseTree
Overrides:
makeRecursiveCopy in class NonLeaf
Following copied from interface: openjava.ptree.ParseTree
Returns:
the copy of this nonleaf-node as a ptree-node.

makeCopy

public ParseTree makeCopy()
Description copied from interface: ParseTree
Makes a new copy of this nonleaf-node as a ptree-node. The objects contained by the new object are same as these contained by the original object.
Specified by:
makeCopy in interface ParseTree
Overrides:
makeCopy in class ParseTreeObject
Following copied from interface: openjava.ptree.ParseTree
Returns:
the copy of this nonleaf-node as a ptree-node.

writeCode

public void writeCode()
Description copied from class: NonLeaf
Writes the code this parse-tree presents for.
Specified by:
writeCode in interface ParseTree
Overrides:
writeCode in class NonLeaf

strength

protected static final int strength(int op)
Returns the strength of the union of the operator.
Parameters:
op - the id number of operator.
Returns:
the strength of the union.

getLeft

public Expression getLeft()
Gets the expression of the left operand.
Returns:
the left expression.

setLeft

public void setLeft(Expression lexpr)
Sets the expression of the left operand.
Parameters:
lexpr - the left expression.

getRight

public Expression getRight()
Gets the expression of the right operand.
Returns:
the right expression.

setRight

public void setRight(Expression rexpr)
Sets the expression of the right operand.
Parameters:
rexpr - the right expression.

getOperator

public int getOperator()
Gets the id number of the operator.
Returns:
the id number of the operator.
See Also:
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

setOperator

public void setOperator(int opr)
Sets the id number of the operator.
Parameters:
opr - the id number of the operator.
See Also:
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

operatorString

public java.lang.String operatorString()

accept

public void accept(ParseTreeVisitor v)
            throws ParseTreeException
Description copied from interface: ParseTree
Accepts a 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.

Specified by:
accept in interface ParseTree
Overrides:
accept in class ParseTreeObject
Following copied from interface: openjava.ptree.ParseTree
Parameters:
visitor - a visitor

getType

public OJClass getType(Environment env)
                throws java.lang.Exception
Specified by:
getType in interface Expression