Class AddExpression

All Implemented Interfaces:
Cloneable, Constants, RuntimeConstants

public class AddExpression extends BinaryArithmeticExpression
WARNING: The contents of this source file are not part of any supported API. Code that depends on them does so at its own risk: they are subject to change or removal without notice.
  • Constructor Details

  • Method Details

    • selectType

      void selectType(Environment env, Context ctx, int tm)
      Select the type
      Overrides:
      selectType in class BinaryArithmeticExpression
    • isNonNull

      public boolean isNonNull()
      Description copied from class: Expression
      Check if the expression cannot be a null reference.
      Overrides:
      isNonNull in class Expression
    • eval

      Expression eval(int a, int b)
      Evaluate
      Overrides:
      eval in class BinaryExpression
    • eval

      Expression eval(long a, long b)
      Overrides:
      eval in class BinaryExpression
    • eval

      Expression eval(float a, float b)
      Overrides:
      eval in class BinaryExpression
    • eval

      Expression eval(double a, double b)
      Overrides:
      eval in class BinaryExpression
    • eval

      Expression eval(String a, String b)
      Overrides:
      eval in class BinaryExpression
    • inlineValue

      public Expression inlineValue(Environment env, Context ctx)
      Inline the value of an AddExpression. If this AddExpression represents a concatenation of compile-time constant strings, dispatch to the special method inlineValueSB, which handles the inlining more efficiently.
      Overrides:
      inlineValue in class BinaryExpression
    • inlineValueSB

      protected StringBuffer inlineValueSB(Environment env, Context ctx, StringBuffer buffer)
      Attempt to evaluate this expression. If this expression yields a value, append it to the StringBuffer `buffer'. If this expression cannot be evaluated at this time (for example if it contains a division by zero, a non-constant subexpression, or a subexpression which "refuses" to evaluate) then return `null' to indicate failure. It is anticipated that this method will be called to evaluate concatenations of compile-time constant strings. The call originates from AddExpression#inlineValue(). This method does not use associativity to good effect in folding string concatenations. This is room for improvement. ------------- A bit of history: this method was added because an expression like... "a" + "b" + "c" + "d" ...was evaluated at compile-time as... (new StringBuffer((new StringBuffer("a")).append("b").toString())). append((new StringBuffer("c")).append("d").toString()).toString() Alex Garthwaite, in profiling the memory allocation of the compiler, noticed this and suggested that the method inlineValueSB() be added to evaluate constant string concatenations in a more efficient manner. The compiler now builds the string in a top-down fashion, by accumulating the result in a StringBuffer which is allocated once and passed in as a parameter. The new evaluation scheme is equivalent to... (new StringBuffer("a")).append("b").append("c").append("d") .toString() ...which is more efficient. Since then, the code has been modified to fix certain problems. Now, for example, it can return `null' when it encounters a concatenation which it is not able to evaluate. See also Expression#inlineValueSB() and ExprExpression#inlineValueSB().
      Overrides:
      inlineValueSB in class Expression
    • simplify

      Expression simplify()
      Simplify
      Overrides:
      simplify in class Expression
    • costInline

      public int costInline(int thresh, Environment env, Context ctx)
      The cost of inlining this expression
      Overrides:
      costInline in class BinaryExpression
    • codeOperation

      void codeOperation(Environment env, Context ctx, Assembler asm)
      Code
      Overrides:
      codeOperation in class BinaryExpression
    • codeAppend

      void codeAppend(Environment env, Context ctx, Assembler asm, ClassDeclaration sbClass, boolean needBuffer) throws ClassNotFound, AmbiguousMember
      Convert this expression to a string and append it to the string buffer on the top of the stack. If the needBuffer argument is true, the string buffer needs to be created, initialized, and pushed on the stack, first.
      Overrides:
      codeAppend in class Expression
      Throws:
      ClassNotFound
      AmbiguousMember
    • codeValue

      public void codeValue(Environment env, Context ctx, Assembler asm)
      Overrides:
      codeValue in class BinaryExpression