public abstract class Expression extends BytecodeProducer
resultType() and can generate code to evaluate the
expression.
Expressions should:
These rules make it easier to compose and reason about the effect of composing expressions. In particular it makes it easier to maintain the stack height and type invariants of the JVM.
Due to these constraints there are some natural consequences, a few examples include:
return and throw are special cases that are allowed)
| Modifier and Type | Class and Description |
|---|---|
static class |
Expression.Feature
Expression features track additional metadata for expressions.
|
static class |
Expression.Features
An immutable wrapper of an EnumSet of
Expression.Feature. |
location| Modifier | Constructor and Description |
|---|---|
protected |
Expression(org.objectweb.asm.Type resultType) |
protected |
Expression(org.objectweb.asm.Type resultType,
Expression.Feature first,
Expression.Feature... rest) |
protected |
Expression(org.objectweb.asm.Type resultType,
Expression.Features features) |
protected |
Expression(org.objectweb.asm.Type resultType,
Expression.Features features,
SourceLocation location) |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
areAllCheap(Expression first,
Expression... rest)
Returns true if all referenced expressions are cheap.
|
static boolean |
areAllCheap(Iterable<? extends Expression> args)
Returns true if all referenced expressions are cheap.
|
Expression |
asCheap()
Returns an equivalent expression where
isCheap() returns true. |
Expression |
asNonNullable()
Returns an equivalent expression where
isNonNullable() returns true. |
Expression |
asNullable() |
void |
checkAssignableTo(org.objectweb.asm.Type expected)
Check that this expression is assignable to
expected. |
void |
checkAssignableTo(org.objectweb.asm.Type expected,
String fmt,
Object... args)
Check that this expression is assignable to
expected. |
Expression |
checkedCast(Class<?> target)
Returns an expression that performs a checked cast from the current type to the target type.
|
Expression |
checkedCast(org.objectweb.asm.Type target)
Returns an expression that performs a checked cast from the current type to the target type.
|
static void |
checkTypes(com.google.common.collect.ImmutableList<org.objectweb.asm.Type> types,
Expression... exprs)
Checks that the given expressions are compatible with the given types.
|
protected abstract void |
doGen(CodeBuilder adapter)
Generate code to evaluate the expression.
|
protected void |
extraToStringProperties(com.google.common.base.MoreObjects.ToStringHelper helper)
Subclasses can override this to supply extra properties for the toString method.
|
Expression.Features |
features()
Returns all the feature bits.
|
Expression |
invoke(MethodRef method,
Expression... args)
A simple helper that calls through to
MethodRef.invoke(Expression...), but allows a
more natural fluent call style. |
Statement |
invokeVoid(MethodRef method,
Expression... args)
A simple helper that calls through to
MethodRef.invokeVoid(Expression...), but allows a
more natural fluent call style. |
boolean |
isCheap()
Whether or not this expression is
cheap. |
boolean |
isNonNullable()
Whether or not this expression is
non nullable. |
Expression |
labelEnd(org.objectweb.asm.Label label)
Returns a new expression identical to this one but with the given label applied at the end of
the expression.
|
Expression |
labelStart(org.objectweb.asm.Label label)
Returns a new expression identical to this one but with the given label applied at the start of
the expression.
|
org.objectweb.asm.Type |
resultType()
The type of the expression.
|
Statement |
toStatement()
Convert this expression to a statement, by executing it and throwing away the result.
|
String |
toString() |
Expression |
withSourceLocation(SourceLocation location)
Returns an identical
Expression with the given source location. |
gen, traceprotected Expression(org.objectweb.asm.Type resultType)
protected Expression(org.objectweb.asm.Type resultType,
Expression.Feature first,
Expression.Feature... rest)
protected Expression(org.objectweb.asm.Type resultType,
Expression.Features features)
protected Expression(org.objectweb.asm.Type resultType,
Expression.Features features,
SourceLocation location)
public static boolean areAllCheap(Iterable<? extends Expression> args)
public static boolean areAllCheap(Expression first, Expression... rest)
public static void checkTypes(com.google.common.collect.ImmutableList<org.objectweb.asm.Type> types,
Expression... exprs)
protected abstract void doGen(CodeBuilder adapter)
The generated code satisfies the invariant that the top of the runtime stack will contain a
value with this resultType() immediately after evaluation of the code.
doGen in class BytecodeProducerpublic Expression withSourceLocation(SourceLocation location)
Expression with the given source location.public final org.objectweb.asm.Type resultType()
public boolean isCheap()
cheap.public boolean isNonNullable()
non nullable.public Expression.Features features()
isCheap() or isNonNullable().public final void checkAssignableTo(org.objectweb.asm.Type expected)
expected.public final void checkAssignableTo(org.objectweb.asm.Type expected,
String fmt,
Object... args)
expected.public Statement toStatement()
This is useful for invoking non-void methods when we don't care about the result.
public Expression asCheap()
isCheap() returns true.public Expression asNonNullable()
isNonNullable() returns true.public Expression asNullable()
public Expression checkedCast(org.objectweb.asm.Type target)
IllegalArgumentException - if either type is not a reference type.public Expression checkedCast(Class<?> target)
IllegalArgumentException - if either type is not a reference type.public Expression invoke(MethodRef method, Expression... args)
MethodRef.invoke(Expression...), but allows a
more natural fluent call style.public Statement invokeVoid(MethodRef method, Expression... args)
MethodRef.invokeVoid(Expression...), but allows a
more natural fluent call style.public Expression labelStart(org.objectweb.asm.Label label)
public Expression labelEnd(org.objectweb.asm.Label label)
protected void extraToStringProperties(com.google.common.base.MoreObjects.ToStringHelper helper)