📄 constfold.java
字号:
case iushrl:
return syms.intType.constType(
new Integer(intValue(l)>>> intValue(r)));
case if_icmpeq:
return syms.booleanType.constType(
b2i(intValue(l) == intValue(r)))
;
case if_icmpne:
return syms.booleanType.constType(
b2i(intValue(l) != intValue(r)))
;
case if_icmplt:
return syms.booleanType.constType(b2i(intValue(l) < intValue(r)))
;
case if_icmpgt:
return syms.booleanType.constType(b2i(intValue(l) > intValue(r)))
;
case if_icmple:
return syms.booleanType.constType(
b2i(intValue(l) <= intValue(r)))
;
case if_icmpge:
return syms.booleanType.constType(
b2i(intValue(l) >= intValue(r)))
;
case ladd:
return syms.longType.constType(
new Long(longValue(l) + longValue(r)));
case lsub:
return syms.longType.constType(
new Long(longValue(l) - longValue(r)));
case lmul:
return syms.longType.constType(
new Long(longValue(l) * longValue(r)));
case ldiv:
return syms.longType.constType(
new Long(longValue(l) / longValue(r)));
case lmod:
return syms.longType.constType(
new Long(longValue(l) % longValue(r)));
case land:
return syms.longType.constType(
new Long(longValue(l) & longValue(r)));
case lor:
return syms.longType.constType(
new Long(longValue(l) | longValue(r)));
case lxor:
return syms.longType.constType(
new Long(longValue(l) ^ longValue(r)));
case lshl:
case lshll:
return syms.longType.constType(
new Long(longValue(l)<< intValue(r)));
case lshr:
case lshrl:
return syms.longType.constType(
new Long(longValue(l)>> intValue(r)));
case lushr:
return syms.longType.constType(
new Long(longValue(l)>>> intValue(r)));
case lcmp:
if (longValue(l) < longValue(r))
return syms.intType.constType(minusOne);
else if (longValue(l) > longValue(r))
return syms.intType.constType(one);
else
return syms.intType.constType(zero);
case fadd:
return syms.floatType.constType(
new Float(floatValue(l) + floatValue(r)));
case fsub:
return syms.floatType.constType(
new Float(floatValue(l) - floatValue(r)));
case fmul:
return syms.floatType.constType(
new Float(floatValue(l) * floatValue(r)));
case fdiv:
return syms.floatType.constType(
new Float(floatValue(l) / floatValue(r)));
case fmod:
return syms.floatType.constType(
new Float(floatValue(l) % floatValue(r)));
case fcmpg:
case fcmpl:
if (floatValue(l) < floatValue(r))
return syms.intType.constType(minusOne);
else if (floatValue(l) > floatValue(r))
return syms.intType.constType(one);
else if (floatValue(l) == floatValue(r))
return syms.intType.constType(zero);
else if (opcode == fcmpg)
return syms.intType.constType(one);
else
return syms.intType.constType(minusOne);
case dadd:
return syms.doubleType.constType(
new Double(doubleValue(l) + doubleValue(r)));
case dsub:
return syms.doubleType.constType(
new Double(doubleValue(l) - doubleValue(r)));
case dmul:
return syms.doubleType.constType(
new Double(doubleValue(l) * doubleValue(r)));
case ddiv:
return syms.doubleType.constType(
new Double(doubleValue(l) / doubleValue(r)));
case dmod:
return syms.doubleType.constType(
new Double(doubleValue(l) % doubleValue(r)));
case dcmpg:
case dcmpl:
if (doubleValue(l) < doubleValue(r))
return syms.intType.constType(minusOne);
else if (doubleValue(l) > doubleValue(r))
return syms.intType.constType(one);
else if (doubleValue(l) == doubleValue(r))
return syms.intType.constType(zero);
else if (opcode == dcmpg)
return syms.intType.constType(one);
else
return syms.intType.constType(minusOne);
case if_acmpeq:
return syms.booleanType.constType(b2i(l.equals(r)))
;
case if_acmpne:
return syms.booleanType.constType(b2i(!l.equals(r)))
;
case string_add:
return syms.stringType.constType(left.stringValue() +
right.stringValue());
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.
*/
Type coerce(Type etype, Type ttype) {
if (etype.baseType() == ttype.baseType())
return etype;
if (etype.tag <= DOUBLE) {
Object n = etype.constValue;
switch (ttype.tag) {
case BYTE:
return syms.byteType.constType(new Integer((byte) intValue(n)));
case CHAR:
return syms.charType.constType(new Integer((char) intValue(n)));
case SHORT:
return syms.shortType.constType(new Integer((short) intValue(n)));
case INT:
return syms.intType.constType(new Integer(intValue(n)));
case LONG:
return syms.longType.constType(new Long(longValue(n)));
case FLOAT:
return syms.floatType.constType(new Float(floatValue(n)));
case DOUBLE:
return syms.doubleType.constType(new Double(doubleValue(n)));
}
}
return ttype;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -