Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

openjava.ptree
Class BinaryExpression  view BinaryExpression download BinaryExpression.java

java.lang.Object
  extended byopenjava.ptree.ParseTreeObject
      extended byopenjava.ptree.NonLeaf
          extended byopenjava.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)
 


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
           
private  int opr
          the operator
(package private) static java.lang.String[] opr_string
           
private static int OTHER
           
static int PLUS
           
static int SHIFT_L
           
static int SHIFT_R
           
static int SHIFT_RR
           
private static int STRING
           
static int TIMES
           
static int XOR
           
 
Fields inherited from class openjava.ptree.NonLeaf
 
Fields inherited from class openjava.ptree.ParseTreeObject
LN
 
Constructor Summary
(package private) BinaryExpression()
           
  BinaryExpression(Expression lexp, int opr, Expression rexp)
          Allocates a new object.
  BinaryExpression(Expression lexp, java.lang.String opr, Expression rexp)
           
 
Method Summary
 void accept(openjava.ptree.util.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 openjava.mop.OJClass chooseType(openjava.mop.OJClass left, openjava.mop.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.
 openjava.mop.OJClass getType(openjava.mop.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)
           
 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.
private static int strength(openjava.mop.OJClass type)
           
 
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, equal, getObjectID, getParent, hashCode, lastObjectID, replace, setParent, toFlattenString, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface openjava.ptree.ParseTree
childrenAccept, equals, getObjectID, replace, toFlattenString, toString
 

Field Detail

TIMES

public static final int TIMES
See Also:
Constant Field Values

DIVIDE

public static final int DIVIDE
See Also:
Constant Field Values

MOD

public static final int MOD
See Also:
Constant Field Values

PLUS

public static final int PLUS
See Also:
Constant Field Values

MINUS

public static final int MINUS
See Also:
Constant Field Values

SHIFT_L

public static final int SHIFT_L
See Also:
Constant Field Values

SHIFT_R

public static final int SHIFT_R
See Also:
Constant Field Values

SHIFT_RR

public static final int SHIFT_RR
See Also:
Constant Field Values

LESS

public static final int LESS
See Also:
Constant Field Values

GREATER

public static final int GREATER
See Also:
Constant Field Values

LESSEQUAL

public static final int LESSEQUAL
See Also:
Constant Field Values

GREATEREQUAL

public static final int GREATEREQUAL
See Also:
Constant Field Values

INSTANCEOF

public static final int INSTANCEOF
See Also:
Constant Field Values

EQUAL

public static final int EQUAL
See Also:
Constant Field Values

NOTEQUAL

public static final int NOTEQUAL
See Also:
Constant Field Values

BITAND

public static final int BITAND
See Also:
Constant Field Values

XOR

public static final int XOR
See Also:
Constant Field Values

BITOR

public static final int BITOR
See Also:
Constant Field Values

LOGICAL_AND

public static final int LOGICAL_AND
See Also:
Constant Field Values

LOGICAL_OR

public static final int LOGICAL_OR
See Also:
Constant Field Values

opr_string

static final java.lang.String[] opr_string

opr

private int opr
the operator


STRING

private static final int STRING
See Also:
Constant Field Values

OTHER

private static final int OTHER
See Also:
Constant Field Values
Constructor Detail

BinaryExpression

public BinaryExpression(Expression lexp,
                        int opr,
                        Expression rexp)
Allocates a new object.


BinaryExpression

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

BinaryExpression

BinaryExpression()
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

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

needsLeftPar

private final boolean needsLeftPar(Expression leftexpr)

needsRightPar

private final boolean needsRightPar(Expression rightexpr)

strength

protected static final int strength(int op)
Returns the strength of the union of the operator.


getLeft

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


setLeft

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


getRight

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


setRight

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


getOperator

public int getOperator()
Gets the id number of the operator.


setOperator

public void setOperator(int opr)
Sets the id number of the operator.


operatorString

public java.lang.String operatorString()

accept

public void accept(openjava.ptree.util.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
Specified by:
accept in class ParseTreeObject

getType

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

chooseType

static openjava.mop.OJClass chooseType(openjava.mop.OJClass left,
                                       openjava.mop.OJClass right)

strength

private static int strength(openjava.mop.OJClass type)