- Value promoteString() {
- if (type.equals(STRING_TYPE)) {
- return this;
- } else {
- switch (type.getSort()) {
- case Type.BOOLEAN:
- return then(mv -> mv.visitMethodInsn(INVOKESTATIC, "java/lang/Boolean", "toString", "(Z)Ljava/lang/String;", false));
- case Type.INT:
- return then(mv -> mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "toString", "(I)Ljava/lang/String;", false));
- case Type.LONG:
- return then(mv -> mv.visitMethodInsn(INVOKESTATIC, "java/lang/Long", "toString", "(J)Ljava/lang/String;", false));
- case Type.FLOAT:
- return then(mv -> mv.visitMethodInsn(INVOKESTATIC, "java/lang/Float", "toString", "(F)Ljava/lang/String;", false));
- case Type.DOUBLE:
- return then(mv -> mv.visitMethodInsn(INVOKESTATIC, "java/lang/Double", "toString", "(D)Ljava/lang/String;", false));
- case Type.OBJECT:
- default:
- return then(mv -> mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "toString", "(Ljava/lang/Object;)Ljava/lang/String;", false));
- }
- }
+ static Value DoubleTo(Value self, Type type) {
+ if (type.equals(DOUBLE_OBJECT_TYPE))
+ return self;
+ else
+ return NumberTo(self, type);
+ }
+
+ static Value IntegerTo(Value self, Type type) {
+ if (type.equals(INTEGER_OBJECT_TYPE))
+ return self;
+ else
+ return NumberTo(self, type);
+ }
+
+ static Value LongTo(Value self, Type type) {
+ if (type.equals(LONG_OBJECT_TYPE))
+ return self;
+ else
+ return NumberTo(self, type);
+ }
+
+ static Value BooleanTo(Value self, Type type) {
+ if (type.getSort() == Type.BOOLEAN)
+ return self.rval(type, Value::booleanTo, (mv, o) -> mv.visitMethodInsn(INVOKEINTERFACE, "java/lang/Boolean", "booleanValue", "()Z", true));
+ else if (type.equals(Type.BOOLEAN_TYPE))
+ return self;
+ else if (type.equals(STRING_TYPE))
+ return self.rval(type, Value::stringTo, (mv, o) -> mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "toString", "()Ljava/lang/String;", false));
+ else
+ throw new UnsupportedOperationException();
+ }
+
+ static public Value constant(float v) {
+ return new Value(Type.FLOAT_TYPE, Value::floatTo, (mv, o) -> mv.visitLdcInsn(v));
+ }
+
+ static public Value constant(double v) {
+ return new Value(Type.DOUBLE_TYPE, Value::doubleTo, (mv, o) -> mv.visitLdcInsn(v));
+ }
+
+ /*
+ static public Value constant(byte v) {
+ return new Value(Type.BYTE_TYPE, Value::byteTo, (mv, o) -> mv.visitLdcInsn(v));
+ }
+
+ static public Value constant(short v) {
+ return new Value(Type.SHORT_TYPE, Value::shortTo, (mv, o) -> mv.visitLdcInsn(v));
+ }
+ */
+ static public Value constant(int v) {
+ return new Value(Type.INT_TYPE, Value::intTo, (mv, o) -> mv.visitLdcInsn(v));
+ }
+
+ static public Value constant(long v) {
+ return new Value(Type.LONG_TYPE, Value::longTo, (mv, o) -> mv.visitLdcInsn(v));
+ }
+
+ static public Value constant(boolean v) {
+ return new Value(Type.BOOLEAN_TYPE, Value::booleanTo, (mv, o) -> mv.visitLdcInsn(v));
+ }
+
+ static public Value constant(String v) {
+ return new Value(STRING_TYPE, Value::stringTo, (mv, o) -> mv.visitLdcInsn(v));
+ }
+
+ /*
+ static public Value constant(Object v) {
+ return new Value(Type.getType(v.getClass()), (mv, o) -> mv.visitLdcInsn(v));
+ }*/
+ public boolean isNumber() {
+ return type.equals(INTEGER_OBJECT_TYPE)
+ || type.equals(FLOAT_OBJECT_TYPE)
+ || type.equals(LONG_OBJECT_TYPE)
+ || type.equals(DOUBLE_OBJECT_TYPE)
+ || type.equals(BYTE_OBJECT_TYPE);
+ }
+
+ public boolean isBoolean() {
+ return type.equals(BOOLEAN_OBJECT_TYPE);