net.sf.jode.expr
Class Expression

java.lang.Object
  extended by net.sf.jode.expr.Expression
Direct Known Subclasses:
NopOperator, Operator

public abstract class Expression
extends Object


Field Summary
static Expression EMPTYSTRING
           
protected  Type type
           
 
Constructor Summary
Expression(Type type)
           
 
Method Summary
abstract  Expression addOperand(Expression op)
           
 int canCombine(CombineableOperator combOp)
          Checks if the given Expression (which should be a CombineableOperator) can be combined into this expression.
 Expression combine(CombineableOperator comb)
          Combines the given Expression (which should be a StoreInstruction) into this expression.
 boolean containsConflictingLoad(MatchableOperator op)
          Checks if this expression contains a conflicting load, that matches the given CombineableOperator.
 boolean containsMatchingLoad(CombineableOperator e)
          Checks if this expression contains a load, that matches the given CombineableOperator (which must be an Operator)
 void dumpExpression(int options, TabbedPrintWriter writer)
           
abstract  void dumpExpression(TabbedPrintWriter writer)
           
 void dumpExpression(TabbedPrintWriter writer, int minPriority)
           
 void fillDeclarables(Collection used)
           
 void fillInGenSet(Collection in, Collection gen)
           
 int getBreakPenalty()
          Get the penalty for splitting up this operator.
abstract  int getFreeOperandCount()
          Get the number of operands.
 Operator getParent()
           
abstract  int getPriority()
          Get priority of the operator.
 Type getType()
           
 boolean hasSideEffects(Expression expr)
          Checks if the value of the given expression can change, due to side effects in this expression.
 boolean isConstant()
           
 boolean isVoid()
           
 void makeDeclaration(Set done)
           
 void makeInitializer(Type type)
           
 Expression negate()
           
 Expression removeOnetimeLocals()
          This method should remove local variables that are only written and read one time directly after another.
 void setType(Type otherType)
           
 Expression simplify()
           
 Expression simplifyString()
           
 Expression simplifyStringBuffer()
           
 String toString()
           
 void updateParentType(Type otherType)
           
abstract  void updateSubTypes()
          Tells an expression that an outer expression has changed our type and that the inner types should be recalculated.
abstract  void updateType()
          Tells an expression that an inner expression may have changed and that the type should be recalculated.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

type

protected Type type

EMPTYSTRING

public static Expression EMPTYSTRING
Constructor Detail

Expression

public Expression(Type type)
Method Detail

setType

public void setType(Type otherType)

updateParentType

public void updateParentType(Type otherType)

updateType

public abstract void updateType()
Tells an expression that an inner expression may have changed and that the type should be recalculated. This may call setType of the caller again.


updateSubTypes

public abstract void updateSubTypes()
Tells an expression that an outer expression has changed our type and that the inner types should be recalculated.


getType

public Type getType()

getParent

public Operator getParent()

getPriority

public abstract int getPriority()
Get priority of the operator. Currently this priorities are known:


getBreakPenalty

public int getBreakPenalty()
Get the penalty for splitting up this operator.


getFreeOperandCount

public abstract int getFreeOperandCount()
Get the number of operands.

Returns:
The number of stack entries this expression needs.

addOperand

public abstract Expression addOperand(Expression op)

negate

public Expression negate()

hasSideEffects

public boolean hasSideEffects(Expression expr)
Checks if the value of the given expression can change, due to side effects in this expression. If this returns false, the expression can safely be moved behind the current expresion.

Parameters:
expr - the expression that should not change.

canCombine

public int canCombine(CombineableOperator combOp)
Checks if the given Expression (which should be a CombineableOperator) can be combined into this expression.

Parameters:
combOp - The store expression, must be of type void.
Returns:
1, if it can, 0, if no match was found and -1, if a conflict was found. You may wish to check for >0.

containsMatchingLoad

public boolean containsMatchingLoad(CombineableOperator e)
Checks if this expression contains a load, that matches the given CombineableOperator (which must be an Operator)

Parameters:
e - The store expression.
Returns:
if this expression contains a matching load.
Throws:
ClassCastException, - if e.getOperator is not a CombineableOperator.

containsConflictingLoad

public boolean containsConflictingLoad(MatchableOperator op)
Checks if this expression contains a conflicting load, that matches the given CombineableOperator. The sub expressions are not checked.

Parameters:
op - The combineable operator.
Returns:
if this expression contains a matching load.

combine

public Expression combine(CombineableOperator comb)
Combines the given Expression (which should be a StoreInstruction) into this expression. You must only call this if canCombine returns the value 1.

Parameters:
comb - The store expression, the operator must be a CombineableOperator.
Returns:
The combined expression.
Throws:
ClassCastException, - if e.getOperator is not a CombineableOperator.

removeOnetimeLocals

public Expression removeOnetimeLocals()
This method should remove local variables that are only written and read one time directly after another.
In this case this is a non void LocalStoreOperator, whose local isn't used in other places.

Returns:
an expression where the locals are removed.

simplify

public Expression simplify()

simplifyString

public Expression simplifyString()

simplifyStringBuffer

public Expression simplifyStringBuffer()

makeInitializer

public void makeInitializer(Type type)

isConstant

public boolean isConstant()

fillInGenSet

public void fillInGenSet(Collection in,
                         Collection gen)

fillDeclarables

public void fillDeclarables(Collection used)

makeDeclaration

public void makeDeclaration(Set done)

dumpExpression

public abstract void dumpExpression(TabbedPrintWriter writer)
                             throws IOException
Throws:
IOException

dumpExpression

public void dumpExpression(int options,
                           TabbedPrintWriter writer)
                    throws IOException
Throws:
IOException

dumpExpression

public void dumpExpression(TabbedPrintWriter writer,
                           int minPriority)
                    throws IOException
Throws:
IOException

toString

public String toString()
Overrides:
toString in class Object

isVoid

public boolean isVoid()