/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/** Helper class for constant folding, used by the attribution phase.
* This class is marked strictfp as mandated by JLS 15.4.
*
* <p><b>This is NOT part of any supported API.
* 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.</b>
*/
strictfp class ConstFold {
return instance;
}
}
/** Convert boolean to integer (true = 1, false = 0).
*/
}
/** Fold binary or unary operation, returning constant type reflecting the
* operations result. Return null if fold failed due to an
* arithmetic exception.
* @param opcode The operation's opcode instruction (usually a byte code),
* as entered by class Symtab.
* @param argtypes The operation's argument types (a list of length 1 or 2).
* Argument types are assumed to have non-null constValue's.
*/
if (argCount == 1)
else if (argCount == 2)
else
throw new AssertionError();
}
/** Fold unary operation.
* @param 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.
* @param operand The operation's operand type.
* Argument types are assumed to have non-null constValue's.
*/
try {
switch (opcode) {
case nop:
return operand;
case ineg: // unary -
case ixor: // ~
case bool_not: // !
case ifeq:
case ifne:
case iflt:
case ifgt:
case ifle:
case ifge:
case lneg: // unary -
case lxor: // ~
case fneg: // unary -
case dneg: // ~
default:
return null;
}
} catch (ArithmeticException e) {
return null;
}
}
/** Fold binary operation.
* @param 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.
* @param left The type of the operation's left operand.
* @param right The type of the operation's right operand.
*/
try {
// we are seeing a composite instruction of the form xcmp; ifxx.
// In this case fold both instructions separately.
} else {
switch (opcode) {
case iadd:
case isub:
case imul:
case idiv:
case imod:
case iand:
case bool_and:
case ior:
case bool_or:
case ixor:
case if_icmpeq:
case if_icmpne:
case if_icmplt:
case if_icmpgt:
case if_icmple:
case if_icmpge:
case ladd:
case lsub:
case lmul:
case ldiv:
case lmod:
case land:
case lor:
case lxor:
case lushr:
case lcmp:
else
case fadd:
case fsub:
case fmul:
case fdiv:
case fmod:
if (floatValue(l) < floatValue(r))
else if (floatValue(l) > floatValue(r))
else if (floatValue(l) == floatValue(r))
else
case dadd:
case dsub:
case dmul:
case ddiv:
case dmod:
if (doubleValue(l) < doubleValue(r))
else if (doubleValue(l) > doubleValue(r))
else if (doubleValue(l) == doubleValue(r))
else
case if_acmpeq:
case if_acmpne:
case string_add:
default:
return null;
}
}
} catch (ArithmeticException e) {
return null;
}
}
/** Coerce constant type to target type.
* @param etype The source type of the coercion,
* which is assumed to be a constant type compatble with
* ttype.
* @param ttype The target type of the coercion.
*/
// WAS if (etype.baseType() == ttype.baseType())
return etype;
case BYTE:
case CHAR:
case SHORT:
case INT:
case LONG:
case FLOAT:
case DOUBLE:
}
}
return ttype;
}
}