net.janino
Class Java.Rvalue

java.lang.Object
  |
  +--net.janino.Java.Located
        |
        +--net.janino.Java.Atom
              |
              +--net.janino.Java.Rvalue
All Implemented Interfaces:
Java.Locatable
Direct Known Subclasses:
Java.ArrayInitializer, Java.Assignment, Java.BooleanRvalue, Java.Cast, Java.ClassLiteral, Java.ConditionalExpression, Java.Crement, Java.Instanceof, Java.Invocation, Java.Literal, Java.Lvalue, Java.NewArray, Java.NewClassInstance, Java.ThisReference
Enclosing class:
Java

public abstract static class Java.Rvalue
extends Java.Atom

Representation of an "rvalue", i.e. an expression that has a type and a value, but cannot be assigned to: An expression that can be the right-hand-side of an assignment.


Field Summary
static boolean JUMP_IF_FALSE
           
static boolean JUMP_IF_TRUE
           
 
Constructor Summary
protected Java.Rvalue(Scanner.Location location)
           
 
Method Summary
 void compile(ClassFile.CodeAttribute codeAttribute)
          Some Java.Rvalues compile more efficiently when their value is not needed, e.g.
 void compileBoolean(ClassFile.CodeAttribute codeAttribute, ClassFile.CodeAttribute.Offset dst, boolean orientation)
          Some Java.Rvalues compile more efficiently when their value is the condition for a branch.
Notice that if "this" is a constant, then either "dst" is never branched to, or it is unconditionally branched to.
 int compileContext(ClassFile.CodeAttribute codeAttribute)
          Generates code that determines the context of the Java.Rvalue and puts it on the operand stack.
abstract  IClass compileGet(ClassFile.CodeAttribute codeAttribute)
          Generates code that determines the value of the Java.Rvalue and puts it on the operand stack.
 IClass compileGetValue(ClassFile.CodeAttribute codeAttribute)
          Convenience function that calls compileContext(ClassFile.CodeAttribute) and compileGet(ClassFile.CodeAttribute).
 java.lang.Object getConstantValue()
          Attempts to evaluate as a constant expression.
 java.lang.Object getNegatedConstantValue()
          Attempts to evaluate the negated value of a constant Java.Rvalue.
 
Methods inherited from class net.janino.Java.Atom
getLocation, getType, isType, throwCompileException, throwParseException, toLvalue, toRvalue, toType
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JUMP_IF_TRUE

public static final boolean JUMP_IF_TRUE

JUMP_IF_FALSE

public static final boolean JUMP_IF_FALSE
Constructor Detail

Java.Rvalue

protected Java.Rvalue(Scanner.Location location)
Method Detail

compile

public void compile(ClassFile.CodeAttribute codeAttribute)
             throws Java.CompileException
Some Java.Rvalues compile more efficiently when their value is not needed, e.g. "i++".

compileGetValue

public final IClass compileGetValue(ClassFile.CodeAttribute codeAttribute)
                             throws Java.CompileException
Convenience function that calls compileContext(ClassFile.CodeAttribute) and compileGet(ClassFile.CodeAttribute).
Returns:
The type of the Rvalue

compileContext

public int compileContext(ClassFile.CodeAttribute codeAttribute)
                   throws Java.CompileException
Generates code that determines the context of the Java.Rvalue and puts it on the operand stack. Most expressions do not have a "context", but some do. E.g. for "x[y]", the context is "x, y". The bottom line is that for statements like "x[y] += 3" the context is only evaluated once.
Returns:
The size of the context on the operand stack

compileGet

public abstract IClass compileGet(ClassFile.CodeAttribute codeAttribute)
                           throws Java.CompileException
Generates code that determines the value of the Java.Rvalue and puts it on the operand stack. This method relies on that the "context" of the Java.Rvalue is on top of the operand stack (see compileContext(ClassFile.CodeAttribute)).
Returns:
The type of the Java.Rvalue

compileBoolean

public void compileBoolean(ClassFile.CodeAttribute codeAttribute,
                           ClassFile.CodeAttribute.Offset dst,
                           boolean orientation)
                    throws Java.CompileException
Some Java.Rvalues compile more efficiently when their value is the condition for a branch.
Notice that if "this" is a constant, then either "dst" is never branched to, or it is unconditionally branched to. "Unexamined code" errors may result during bytecode validation.

getConstantValue

public java.lang.Object getConstantValue()
                                  throws Java.CompileException
Attempts to evaluate as a constant expression.
Returns:
null if value is not constant; otherwise a String, Byte, Short, Integer, Boolean, Character, Float, Long or Double

getNegatedConstantValue

public java.lang.Object getNegatedConstantValue()
                                         throws Java.CompileException
Attempts to evaluate the negated value of a constant Java.Rvalue. This is particularly relevant for the smalles value of a numeric literal.
Returns:
null if value is not constant; otherwise a String, Byte, Short, Integer, Boolean, Character, Float, Long or Double