|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.transjvm.Expression
public abstract class Expression
This class represents expressions. Each expression generates code which leaves a single value at the top of the stack.
ConstructorID.newInstance()
,
MethodID.call(Expression object)
,
Variable.assign(Expression value)
Field Summary | |
---|---|
static Expression |
FALSE
Expression representing the constant false . |
static Expression |
NULL
Expression representing the constant null . |
static Expression |
ONE
Expression representing the int constant 1 (one). |
static Expression |
TRUE
Expression representing the constant true . |
static Expression |
ZERO
Expression representing the int constant 0 (zero). |
Constructor Summary | |
---|---|
protected |
Expression(TypeID type)
|
Method Summary | |
---|---|
abstract java.lang.Object |
accept(ExpressionVisitor visitor)
|
Expression |
bitwise(Operator.Math op,
Expression right)
Deprecated. Use math(op, right) instead. |
Expression |
bitwiseNot()
Returns an expression representing the bitwise not of this Expression. |
Statement |
branch(boolean branch,
Label target)
Returns a conditional branch statement. |
void |
branch(boolean onTrue,
Label target,
InstructionStream stream)
Branches to target if this Expression evaluates to onTrue. |
void |
branch(boolean onTrue,
Label target,
InstructionStream stream,
int depth)
|
Expression |
cast(TypeID cls)
Casts this expression to type cls. |
Expression |
compare(Operator.Compare op,
Expression right)
Returns an expression representing the comparison this op right . |
Expression |
conditional(Expression ifTrue,
Expression ifFalse)
Returns an Expression which evaluates to either ifTrue or ifFalse. |
static Expression |
constant(double value)
Returns an Expression representing a double constant. |
static Expression |
constant(float value)
Returns an Expression representing the constant value. |
static Expression |
constant(int value)
Returns an Expression representing an int constant. |
static Expression |
constant(long value)
Returns an Expression representing a long constant. |
static Expression |
constant(java.lang.String value)
Returns an Expression representing a string constant |
Expression |
convert(TypeID to)
Converts this expression to type to . |
static Expression |
emptyArray(TypeID componentType,
Expression size)
|
abstract void |
eval(InstructionStream stream,
int depth)
Writes the code to stream necessary for the evaluation of this Expression. |
static Expression |
filledArray(TypeID memberType,
Expression... items)
Returns an expression for an array of type memberType, containing items. |
TypeID |
getType()
Gets the type of this Expression |
Variable |
index(Expression index)
Returns a variable for an indexed array member. |
Expression |
isInstanceOf(TypeID type)
Returns an expression representing this instanceof type . |
Expression |
length()
Returns a Expression for the length of this array. |
Expression |
logicalNot()
Returns an expression representing the logical converse of this Expression. |
Expression |
math(Operator.Math op,
Expression right)
Returns an Expression representing this op right . |
Expression |
negate()
Returns an expression representing the negative of this Expression. |
Expression |
not()
Deprecated. Use logicalNot() or bitwiseNot() instead.
Acts as logicalNot() if this expression is boolean, bitwiseNot() otherwise. |
Expression |
shortCut(Operator.Boolean op,
Expression right)
Returns an Expression representing this op right . |
Statement |
toStm()
Returns a statement which evaluates this Expression, then discards the result. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static Expression TRUE
true
.
public static Expression FALSE
false
.
public static final Expression NULL
null
.
public static final Expression ZERO
0
(zero).
public static final Expression ONE
1
(one).
Constructor Detail |
---|
protected Expression(TypeID type)
Method Detail |
---|
public abstract java.lang.Object accept(ExpressionVisitor visitor)
public abstract void eval(InstructionStream stream, int depth)
depth
- The stack depth before evaluationstream
- Description of the ParameterInstructionStream.stackDepth(int depth)
public final TypeID getType()
public final void branch(boolean onTrue, Label target, InstructionStream stream)
onTrue
- If true, branches when thisExpression evaluates to true.target
- Target of the jump.stream
- The instruction stream.public Statement branch(boolean branch, Label target)
branch
- If this expression evaluates to branch jump to target.target
- The target Label.
- Returns:
- A conditional branch statement.
- Throws:
java.lang.IllegalStateException
- if type is not boolean.
public void branch(boolean onTrue, Label target, InstructionStream stream, int depth)
public Statement toStm()
public static Expression constant(int value)
value
- An int constant
public static Expression constant(long value)
value
- A long constant
public static Expression constant(double value)
value
- A double constant
public static Expression constant(float value)
value
- A float constant
public static Expression constant(java.lang.String value)
value
- A String constant
public Expression logicalNot()
@Deprecated public final Expression not()
logicalNot()
or bitwiseNot()
instead.
Acts as logicalNot() if this expression is boolean, bitwiseNot() otherwise.
public Expression bitwiseNot()
public final Expression negate()
public final Expression conditional(Expression ifTrue, Expression ifFalse)
ifTrue
- The true ExpressionifFalse
- The false Expression
public Expression shortCut(Operator.Boolean op, Expression right)
this op right
.
Both this and right should be booleans.
Short-cut evaluation is used, ie. right is only evaluated if required to produce the result.
If you require right to be evaluated, use binary(BinaryOperator op, Expression right).
op
- The operatorright
- The right hand Expression
public Expression math(Operator.Math op, Expression right)
this op right
.
op
- The operatorright
- The right hand Expression
@Deprecated public Expression bitwise(Operator.Math op, Expression right)
math(op, right)
instead.
this op right
.
op
- The operatorright
- The right hand Expression
public Expression cast(TypeID cls)
cls
- TypeID to be cast to
java.lang.IllegalArgumentException
- if cls is primitivepublic Expression convert(TypeID to)
to
- The type converted to.
public Variable index(Expression index)
index
- The index of the array member, must be of type INT32.
Also getType().isArray()
must be true,
ie. This expression must represent an array.public static Expression emptyArray(TypeID componentType, Expression size)
componentType
- The type of the components of the array.size
- The size of the new array, must be of type Int32
public static Expression filledArray(TypeID memberType, Expression... items)
memberType
- The type of the array items. ie array has type memberType[].items
- The values to fill the array.
public Expression compare(Operator.Compare op, Expression right)
this op right
.
op
- The operator.right
- The rhs of the comparison.
this op right
.public Expression isInstanceOf(TypeID type)
this instanceof type
.
type
- The type.
this instanceof type
.
java.lang.IllegalArgumentException
- if type is primitive.public Expression length()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |