public class

AddExpression

extends BinaryArithmeticExpression
java.lang.Object
   ↳ sun.tools.tree.Node
     ↳ sun.tools.tree.Expression
       ↳ sun.tools.tree.UnaryExpression
         ↳ sun.tools.tree.BinaryExpression
           ↳ sun.tools.tree.BinaryArithmeticExpression
             ↳ sun.tools.tree.AddExpression

Class Overview

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.

Summary

[Expand]
Inherited Constants
From interface sun.tools.java.Constants
From interface sun.tools.java.RuntimeConstants
[Expand]
Inherited Fields
From interface sun.tools.java.Constants
From interface sun.tools.java.RuntimeConstants
Public Constructors
AddExpression(long where, Expression left, Expression right)
constructor
Public Methods
void codeValue(Environment env, Context ctx, Assembler asm)
int costInline(int thresh, Environment env, Context ctx)
The cost of inlining this expression
Expression inlineValue(Environment env, Context ctx)
Inline the value of an AddExpression.
boolean isNonNull()
Check if the expression cannot be a null reference.
Protected Methods
StringBuffer inlineValueSB(Environment env, Context ctx, StringBuffer buffer)
Attempt to evaluate this expression.
[Expand]
Inherited Methods
From class sun.tools.tree.BinaryExpression
From class sun.tools.tree.UnaryExpression
From class sun.tools.tree.Expression
From class sun.tools.tree.Node
From class java.lang.Object

Public Constructors

public AddExpression (long where, Expression left, Expression right)

constructor

Public Methods

public void codeValue (Environment env, Context ctx, Assembler asm)

public int costInline (int thresh, Environment env, Context ctx)

The cost of inlining this expression

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.

public boolean isNonNull ()

Check if the expression cannot be a null reference.

Protected Methods

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().