Module xl.compiler

Class Expression

All Implemented Interfaces:
Manageable, PersistenceCapable, Shareable, TypeId, UserFields, XObject, Map, ExpressionFactory, ValueObserver, Serializable, Cloneable
Direct Known Subclasses:
Assignment, EvalExpression, FieldObserver, FilterGuard, FinishIteratorGenerator, Guard, IterableGenerator, ModelExpression, OpenArgument, Pop, Production, Root, VoidExpression

public class Expression extends Node implements TypeId, ValueObserver, Cloneable, ExpressionFactory
Expression is the base class for the internal representation of compiled expression trees. These are used by the XL compiler as an intermediate step in the creation of byte-code. However, they are evaluatable on their own (though this is not as performant as byte-code). Expression trees are used for both expressions and statements.
Author:
Ole Kniemeyer
See Also:
  • Field Details

  • Constructor Details

    • Expression

      public Expression()
    • Expression

      public Expression(Type type)
  • Method Details

    • getNTypeImpl

      protected Node.NType getNTypeImpl()
      Description copied from class: Node
      This method returns the Node.NType which describes the managed fields of the class of this node. This method has to be implemented in every concrete subclass.
      Overrides:
      getNTypeImpl in class Node
      Returns:
      type describing the managed fields of the class of this node
    • newInstance

      protected Node newInstance()
      Description copied from class: Node
      This method returns a new instance of the class of this node. This method has to be implemented in every concrete subclass.
      Overrides:
      newInstance in class Node
      Returns:
      new instance of class of this node
    • getType

      public Type getType()
      Specified by:
      getType in interface ExpressionFactory
    • createExpression

      public Expression createExpression(Scope scope, antlr.collections.AST ast)
      Specified by:
      createExpression in interface ExpressionFactory
    • clone

      public Object clone()
      Overrides:
      clone in class Node
    • hasType

      public boolean hasType(Type type)
    • hasType

      public boolean hasType(Class type)
    • isPrimitiveOrStringConstant

      public boolean isPrimitiveOrStringConstant()
    • setType

      public Expression setType(Type type)
    • checkSetType

      protected void checkSetType(Type type)
    • isRequired

      public boolean isRequired(int index)
    • discards

      public boolean discards(int index)
    • needsEmptyOperandStackForFinally

      public boolean needsEmptyOperandStackForFinally()
    • allowsIteration

      public boolean allowsIteration(int index)
    • getTypeLoader

      public TypeLoader getTypeLoader()
    • link

      public void link(boolean checkTypes)
    • linkGraph

      public final void linkGraph(boolean checkTypes)
    • unlinkTree

      public final void unlinkTree()
    • getSupportedTypes

      public int getSupportedTypes(int arg)
    • fireValueChanged

      protected void fireValueChanged(Transaction t)
    • valueChanged

      public void valueChanged(Expression expr, int index, Transaction t)
      Specified by:
      valueChanged in interface ValueObserver
    • evaluateRet

      public AbruptCompletion.Return evaluateRet(VMXState t)
    • evaluateAsVoid

      public final void evaluateAsVoid(VMXState t)
    • evaluateAsObject

      public final Object evaluateAsObject(VMXState t)
    • evaluateBoolean

      public final boolean evaluateBoolean()
    • evaluateBoolean

      public final boolean evaluateBoolean(VMXState t)
    • evaluateBooleanImpl

      protected boolean evaluateBooleanImpl(VMXState t)
    • evaluateByte

      public final byte evaluateByte()
    • evaluateByte

      public final byte evaluateByte(VMXState t)
    • evaluateByteImpl

      protected byte evaluateByteImpl(VMXState t)
    • evaluateShort

      public final short evaluateShort()
    • evaluateShort

      public final short evaluateShort(VMXState t)
    • evaluateShortImpl

      protected short evaluateShortImpl(VMXState t)
    • evaluateChar

      public final char evaluateChar()
    • evaluateChar

      public final char evaluateChar(VMXState t)
    • evaluateCharImpl

      protected char evaluateCharImpl(VMXState t)
    • evaluateInt

      public final int evaluateInt()
    • evaluateInt

      public final int evaluateInt(VMXState t)
    • evaluateIntImpl

      protected int evaluateIntImpl(VMXState t)
    • evaluateLong

      public final long evaluateLong()
    • evaluateLong

      public final long evaluateLong(VMXState t)
    • evaluateLongImpl

      protected long evaluateLongImpl(VMXState t)
    • evaluateFloat

      public final float evaluateFloat()
    • evaluateFloat

      public final float evaluateFloat(VMXState t)
    • evaluateFloatImpl

      protected float evaluateFloatImpl(VMXState t)
    • evaluateDouble

      public final double evaluateDouble()
    • evaluateDouble

      public final double evaluateDouble(VMXState t)
    • evaluateDoubleImpl

      protected double evaluateDoubleImpl(VMXState t)
    • evaluateObject

      public final Object evaluateObject()
    • evaluateObject

      public final Object evaluateObject(VMXState t)
    • evaluateObjectImpl

      protected Object evaluateObjectImpl(VMXState t)
    • evaluateVoidImpl

      protected void evaluateVoidImpl(VMXState t)
    • toConst

      public Expression toConst()
    • toConstImpl

      protected Expression toConstImpl()
    • push

      public final void push(VMXState t)
    • add

      public Expression add(Expression expr)
    • setNextSibling

      public Expression setNextSibling(Expression expr)
    • receiveChildren

      public Expression receiveChildren(Expression source)
    • substitute

      public Expression substitute(Expression prev)
    • getFirstExpression

      public Expression getFirstExpression()
    • getNextExpression

      public Expression getNextExpression()
    • getLastExpression

      public Expression getLastExpression()
    • getExpressionCount

      public int getExpressionCount()
    • getExpression

      public Expression getExpression(int index)
    • getLeastCommonAncestor

      public Expression getLeastCommonAncestor(Expression other)
    • getPromotedType

      public int getPromotedType(Expression expr1, Expression expr2)
      Determines the type id (see TypeId) of the binarily promoted type of the operands expr1 and expr2 (binary promotion is defined by the Java Language Specification, it includes unboxing).
      Parameters:
      expr1 - first operand
      expr2 - second operand
      Returns:
      type id of promoted type
    • promote

      public Expression promote(Scope scope, int supportedTypes)
      Converts this expression by unary promotion to one of the types whose mask (see TypeId) is present in supportedTypes. The most specific type is chosen, i.e. the type which is a subtype of all other possible, supported types.
      Parameters:
      scope - TODO
      supportedTypes - union of allowed type masks for the promoted expression
      Returns:
      promoted expression, its type being one of the supported types
      Throws:
      IllegalOperandTypeException - if promotion cannot be performed
    • compile

      public Expression compile(Scope scope, Expression e)
    • compile

      public Expression compile(Scope scope, Expression e1, Expression e2)
    • implicitConversion

      public Expression implicitConversion(Scope scope, Type type)
    • unboxingConversion

      public Expression unboxingConversion()
      If this expression is a boxed value, return its unboxed expression. Otherwise return this expression itself.
      Returns:
    • cast

      public Expression cast(Type type)
    • checkExpressionCount

      public final void checkExpressionCount(int count)
    • getExpression

      public final Expression getExpression(int index, int typeId, boolean checkTypes)
    • getExpression

      public final Expression getExpression(int index, Class cls)
    • getObjectExpression

      public final Expression getObjectExpression(int index, Class type, boolean checkTypes)
    • getObjectExpression

      public final Expression getObjectExpression(int index, Type type, boolean checkTypes)
    • createConst

      public static final Expression createConst(Type type, Object value)
    • createMinConst

      public static final Expression createMinConst(int typeId)
    • createMaxConst

      public static final Expression createMaxConst(int typeId)
    • evaluatesWithoutSideeffect

      public boolean evaluatesWithoutSideeffect()
    • toString

      public String toString()
      Overrides:
      toString in class Node
    • paramString

      protected String paramString()
      Description copied from class: Node
      Computes the class-specific part of the string returned by Node.toString() which shall be enclosed in brackets. This should be used to show important properties of this node.
      Overrides:
      paramString in class Node
      Returns:
      string describing some important properties of this node
    • opcode

      public static int opcode(int typeId, int[] opcodes)
    • opcode

      public int opcode(int[] opcodes)
    • writeChildren

      public void writeChildren(BytecodeWriter writer)
    • write

      public final void write(BytecodeWriter writer, boolean discard)
    • writeImpl

      protected void writeImpl(BytecodeWriter writer, boolean discard)
    • isConditional

      public boolean isConditional()
    • writeConditional

      public int writeConditional(BytecodeWriter writer, org.objectweb.asm.Label falseLabel, org.objectweb.asm.Label trueLabel)
    • writeConditional

      protected void writeConditional(BytecodeWriter writer, boolean discard)
    • writeFinally

      public void writeFinally(BytecodeWriter writer, int label, ControlTransfer cause)
    • writeOperator

      protected void writeOperator(BytecodeWriter writer)