com.sun.tools.javac.comp
Class ConstFold

java.lang.Object
  extended by com.sun.tools.javac.comp.ConstFold

 class ConstFold
extends java.lang.Object

Helper class for constant folding, used by the attribution phase. This class is marked strictfp as mandated by JLS 15.4.

This is NOT part of any API supported by Sun Microsystems. If you write code that depends on this, you do so at your own risk. This code and its internal interfaces are subject to change or deletion without notice.


Field Summary
protected static Context.Key<ConstFold> constFoldKey
           
(package private) static java.lang.Integer minusOne
           
(package private) static java.lang.Integer one
           
private  Symtab syms
           
(package private) static java.lang.Integer zero
           
 
Constructor Summary
private ConstFold(Context context)
           
 
Method Summary
private static java.lang.Integer b2i(boolean b)
          Convert boolean to integer (true = 1, false = 0).
(package private)  Type coerce(Type etype, Type ttype)
          Coerce constant type to target type.
private static double doubleValue(java.lang.Object x)
           
private static float floatValue(java.lang.Object x)
           
(package private)  Type fold(int opcode, List<Type> argtypes)
          Fold binary or unary operation, returning constant type reflecting the operations result.
(package private)  Type fold1(int opcode, Type operand)
          Fold unary operation.
(package private)  Type fold2(int opcode, Type left, Type right)
          Fold binary operation.
static ConstFold instance(Context context)
           
private static int intValue(java.lang.Object x)
           
private static long longValue(java.lang.Object x)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

constFoldKey

protected static final Context.Key<ConstFold> constFoldKey

syms

private Symtab syms

minusOne

static java.lang.Integer minusOne

zero

static java.lang.Integer zero

one

static java.lang.Integer one
Constructor Detail

ConstFold

private ConstFold(Context context)
Method Detail

instance

public static ConstFold instance(Context context)

b2i

private static java.lang.Integer b2i(boolean b)
Convert boolean to integer (true = 1, false = 0).


intValue

private static int intValue(java.lang.Object x)

longValue

private static long longValue(java.lang.Object x)

floatValue

private static float floatValue(java.lang.Object x)

doubleValue

private static double doubleValue(java.lang.Object x)

fold

Type fold(int opcode,
          List<Type> argtypes)
Fold binary or unary operation, returning constant type reflecting the operations result. Return null if fold failed due to an arithmetic exception.

Parameters:
opcode - The operation's opcode instruction (usually a byte code), as entered by class Symtab.
argtypes - The operation's argument types (a list of length 1 or 2). Argument types are assumed to have non-null constValue's.

fold1

Type fold1(int opcode,
           Type operand)
Fold unary operation.

Parameters:
opcode - The operation's opcode instruction (usually a byte code), as entered by class Symtab. opcode's ifeq to ifge are for postprocessing xcmp; ifxx pairs of instructions.
operand - The operation's operand type. Argument types are assumed to have non-null constValue's.

fold2

Type fold2(int opcode,
           Type left,
           Type right)
Fold binary operation.

Parameters:
opcode - The operation's opcode instruction (usually a byte code), as entered by class Symtab. opcode's ifeq to ifge are for postprocessing xcmp; ifxx pairs of instructions.
left - The type of the operation's left operand.
right - The type of the operation's right operand.

coerce

Type coerce(Type etype,
            Type ttype)
Coerce constant type to target type.

Parameters:
etype - The source type of the coercion, which is assumed to be a constant type compatble with ttype.
ttype - The target type of the coercion.