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

    • isNonNull

      public boolean isNonNull()
      Description copied from class: Expression
      Check if the expression cannot be a null reference.
      Overrides:
      isNonNull in class Expression
    • 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
    • costInline

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

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