openjava.ptree
Class UnaryExpression

java.lang.Object
  |
  +--openjava.ptree.ParseTreeObject
        |
        +--openjava.ptree.NonLeaf
              |
              +--openjava.ptree.UnaryExpression

public class UnaryExpression
extends NonLeaf
implements Expression

The UnaryExpression class presents for an expression which consists of unary operator with one Expression.
The unary expressions are :

expr++, expr--, ++expr, --expr, ^expr, !expr, +expr or -expr

,where expr is an expression.
If the operator in the expression of the operand has week unity, this automatically produces the code in which the operand is enclosed by parenthesises.
In the case the operand is y = x and the urary operator is +, this produces the code :
     +(y = x)
 

See Also:
NonLeaf, Expression

Field Summary
static int BIT_NOT
          Post increment operator like:
static int MINUS
          Post increment operator like:
static int NOT
          Post increment operator like:
static int PLUS
          Post increment operator like:
static int POST_DECREMENT
          Post decrement operator like:
static int POST_INCREMENT
          Post increment operator like:
static int PRE_DECREMENT
          Post increment operator like:
static int PRE_INCREMENT
          Pre increment operator like:
 
Fields inherited from class openjava.ptree.ParseTreeObject
debugFlag, debugLevel, LN, out, writerStack
 
Constructor Summary
UnaryExpression(Expression expr, int opr)
          Allocates a new object.
UnaryExpression(int opr, Expression expr)
          Allocates a new object.
 
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.
 Expression getExpression()
          Gets the expression operated in this expression.
 int getOperator()
          Gets the operator of this unary expression.
 OJClass getType(Environment env)
           
 boolean isPostfix()
          Tests if the operator of unary expression is a postfix operator.
 boolean isPrefix()
          Tests if the operator of unary expression is a prefix operator.
 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 setExpression(Expression expr)
          Sets the expression operated in this expression.
 void setOperator(int opr)
          Sets the operator of this unary expression.
 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
 

Field Detail

POST_INCREMENT

public static final int POST_INCREMENT
Post increment operator like:
     i++
 


POST_DECREMENT

public static final int POST_DECREMENT
Post decrement operator like:
     i--
 


PRE_INCREMENT

public static final int PRE_INCREMENT
Pre increment operator like:
     ++i
 


PRE_DECREMENT

public static final int PRE_DECREMENT
Post increment operator like:
     --i
 


BIT_NOT

public static final int BIT_NOT
Post increment operator like:
     ~i
 


NOT

public static final int NOT
Post increment operator like:
     ! c
 


PLUS

public static final int PLUS
Post increment operator like:
     +i
 


MINUS

public static final int MINUS
Post increment operator like:
     -i
 

Constructor Detail

UnaryExpression

public UnaryExpression(int opr,
                       Expression expr)
Allocates a new object.
Parameters:
opr - the operator of this unary expression.
expr - the expression.

UnaryExpression

public UnaryExpression(Expression expr,
                       int opr)
Allocates a new object.
Parameters:
expr - the expression.
opr - the operator of this unary expression.
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.
Overrides:
makeRecursiveCopy in class NonLeaf
Tags copied from interface: 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.
Overrides:
makeCopy in class ParseTreeObject
Tags copied from interface: 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.
Overrides:
writeCode in class NonLeaf

getExpression

public Expression getExpression()
Gets the expression operated in this expression.
Returns:
the expression.

setExpression

public void setExpression(Expression expr)
Sets the expression operated in this expression.
Parameters:
expr - the expression to set.

getOperator

public int getOperator()
Gets the operator of this unary expression.
Returns:
the operator.
See Also:
POST_INCREMENT, POST_DECREMENT, PRE_INCREMENT, PRE_DECREMENT, BIT_NOT, NOT, PLUS, MINUS

setOperator

public void setOperator(int opr)
Sets the operator of this unary expression.
Parameters:
opr - the operator id to set.
See Also:
POST_INCREMENT, POST_DECREMENT, PRE_INCREMENT, PRE_DECREMENT, BIT_NOT, NOT, PLUS, MINUS

isPostfix

public boolean isPostfix()
Tests if the operator of unary expression is a postfix operator.
Returns:
true if the operator is postfix.

isPrefix

public boolean isPrefix()
Tests if the operator of unary expression is a prefix operator.
Returns:
true if the operator is prefix.

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.

Overrides:
accept in class ParseTreeObject
Tags copied from interface: ParseTree
Parameters:
visitor - a visitor

getType

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