Removed setConstType() from is isBoxingCall() to avoid hidden side effect

Const type is now adjusted correctly also when the target is
java.lang.Character or java.lang.Integer
master
Dmitry Cherniachenko 8 years ago committed by Egor.Ushakov
parent d382ba2709
commit 5db9ad29c8
  1. 8
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/ConstExprent.java
  2. 4
      src/org/jetbrains/java/decompiler/modules/decompiler/exps/InvocationExprent.java
  3. 2
      src/org/jetbrains/java/decompiler/struct/gen/VarType.java
  4. BIN
      testData/classes/pkg/TestPrimitives.class
  5. 446
      testData/results/TestPrimitives.dec
  6. 9
      testData/src/pkg/TestPrimitives.java

@ -369,16 +369,16 @@ public class ConstExprent extends Exprent {
public void adjustConstType(VarType expectedType) { public void adjustConstType(VarType expectedType) {
// BYTECHAR and SHORTCHAR => CHAR in the CHAR context // BYTECHAR and SHORTCHAR => CHAR in the CHAR context
if (expectedType.equals(VarType.VARTYPE_CHAR) && if ((expectedType.equals(VarType.VARTYPE_CHAR) || expectedType.equals(VarType.VARTYPE_CHARACTER)) &&
(constType.equals(VarType.VARTYPE_BYTECHAR) || constType.equals(VarType.VARTYPE_SHORTCHAR))) { (constType.equals(VarType.VARTYPE_BYTECHAR) || constType.equals(VarType.VARTYPE_SHORTCHAR))) {
int intValue = getIntValue(); int intValue = getIntValue();
if (isPrintableAscii(intValue) || CHAR_ESCAPES.containsKey(intValue)) { if (isPrintableAscii(intValue) || CHAR_ESCAPES.containsKey(intValue)) {
setConstType(VarType.VARTYPE_CHAR); setConstType(VarType.VARTYPE_CHAR);
} }
} }
// CHAR => INT in the INT context // BYTE, BYTECHAR, SHORTCHAR, SHORT, CHAR => INT in the INT context
else if (expectedType.equals(VarType.VARTYPE_INT) && else if ((expectedType.equals(VarType.VARTYPE_INT) || expectedType.equals(VarType.VARTYPE_INTEGER)) &&
constType.equals(VarType.VARTYPE_CHAR)) { constType.typeFamily == CodeConstants.TYPE_FAMILY_INTEGER) {
setConstType(VarType.VARTYPE_INT); setConstType(VarType.VARTYPE_INT);
} }
} }

@ -410,10 +410,10 @@ public class InvocationExprent extends Exprent {
// special handling for ambiguous types // special handling for ambiguous types
if (lstParameters.get(0).type == Exprent.EXPRENT_CONST) { if (lstParameters.get(0).type == Exprent.EXPRENT_CONST) {
// 'Integer.valueOf(1)' has '1' type detected as TYPE_BYTECHAR // 'Integer.valueOf(1)' has '1' type detected as TYPE_BYTECHAR
// 'Integer.valueOf(40_000)' has '40_000' type detected as TYPE_CHAR
// so we check the type family instead
if (lstParameters.get(0).getExprType().typeFamily == CodeConstants.TYPE_FAMILY_INTEGER) { if (lstParameters.get(0).getExprType().typeFamily == CodeConstants.TYPE_FAMILY_INTEGER) {
if (classname.equals("java/lang/Integer")) { if (classname.equals("java/lang/Integer")) {
// 'Integer.valueOf(40_000)' will change to '40_000' and that will be interpreted as 'char' type
((ConstExprent) lstParameters.get(0)).setConstType(VarType.VARTYPE_INT);
return true; return true;
} }
} }

@ -38,6 +38,8 @@ public class VarType { // TODO: optimize switch
public static final VarType VARTYPE_STRING = new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/String"); public static final VarType VARTYPE_STRING = new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/String");
public static final VarType VARTYPE_CLASS = new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/Class"); public static final VarType VARTYPE_CLASS = new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/Class");
public static final VarType VARTYPE_OBJECT = new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/Object"); public static final VarType VARTYPE_OBJECT = new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/Object");
public static final VarType VARTYPE_INTEGER = new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/Integer");
public static final VarType VARTYPE_CHARACTER = new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/Character");
public static final VarType VARTYPE_VOID = new VarType(CodeConstants.TYPE_VOID); public static final VarType VARTYPE_VOID = new VarType(CodeConstants.TYPE_VOID);
public final int type; public final int type;

@ -10,82 +10,87 @@ public class TestPrimitives {
this.printFloat(1.23F);// 11 this.printFloat(1.23F);// 11
this.printDouble(1.23D);// 12 this.printDouble(1.23D);// 12
this.printChar('Z');// 13 this.printChar('Z');// 13
String.format("%b, %d, %d, %d, %c", true, 1, 213, 40000, 'c', 42L);// 15 this.printIntBoxed(40000);// 15
System.out.println(String.format("%b, %d, %d, %d", this.getBoolean(), this.getByte(), this.getShort(), this.getInt()));// 16 String.format("%b, %d, %d, %d, %c, %d", true, 1, 213, 40000, 'c', 42L);// 17
}// 17 System.out.println(String.format("%b, %d, %d, %d", this.getBoolean(), this.getByte(), this.getShort(), this.getInt()));// 18
}// 19
public void printBoolean(boolean b) { public void printBoolean(boolean b) {
System.out.println(String.format("%b", b));// 20 System.out.println(String.format("%b", b));// 22
}// 21 }// 23
public void printByte(byte b) { public void printByte(byte b) {
System.out.println(String.format("%d", b));// 24 System.out.println(String.format("%d", b));// 26
}// 25 }// 27
public void printShort(short s) { public void printShort(short s) {
System.out.println(String.format("%d", s));// 28 System.out.println(String.format("%d", s));// 30
}// 29 }// 31
public void printInt(int i) { public void printInt(int i) {
System.out.println(String.format("%d", i));// 32 System.out.println(String.format("%d", i));// 34
}// 33 }// 35
public void printLong(long l) { public void printLong(long l) {
System.out.println(String.format("%d", l));// 36 System.out.println(String.format("%d", l));// 38
}// 37 }// 39
public void printFloat(float f) { public void printFloat(float f) {
System.out.println(String.format("%f", f));// 40 System.out.println(String.format("%f", f));// 42
}// 41 }// 43
public void printDouble(double d) { public void printDouble(double d) {
System.out.println(String.format("%f", d));// 44 System.out.println(String.format("%f", d));// 46
}// 45 }// 47
public void printChar(char c) { public void printChar(char c) {
System.out.println(String.format("%c", c));// 48 System.out.println(String.format("%c", c));// 50
}// 49 }// 51
public void printIntBoxed(Integer i) {
System.out.println(String.format("%d", i));// 55
}// 56
public boolean getBoolean() { public boolean getBoolean() {
return false;// 53 return false;// 60
} }
public byte getByte() { public byte getByte() {
return -128;// 57 return -128;// 64
} }
public short getShort() { public short getShort() {
return -32768;// 61 return -32768;// 68
} }
public int getInt() { public int getInt() {
return 42;// 65 return 42;// 72
} }
public void printNarrowed() { public void printNarrowed() {
this.printByte((byte)this.getInt());// 69 this.printByte((byte)this.getInt());// 76
this.printShort((short)this.getInt());// 70 this.printShort((short)this.getInt());// 77
}// 71 }// 78
public void constructor() { public void constructor() {
new Byte((byte)1);// 74 new Byte((byte)1);// 81
}// 75 }// 82
private boolean compare(char c) { private boolean compare(char c) {
boolean res = c > -1;// 78 boolean res = c > -1;// 85
res = c > 0;// 79 res = c > 0;// 86
res = c > 1;// 80 res = c > 1;// 87
res = c > '\b';// 81 res = c > '\b';// 88
res = c > '\t';// 82 res = c > '\t';// 89
res = c > '\n';// 83 res = c > '\n';// 90
res = c > '\f';// 84 res = c > '\f';// 91
res = c > '\r';// 85 res = c > '\r';// 92
res = c > ' ';// 86 res = c > ' ';// 93
res = c > 'a';// 87 res = c > 'a';// 94
res = c > 'Z';// 88 res = c > 'Z';// 95
res = c > 127;// 89 res = c > 127;// 96
res = c > 255;// 90 res = c > 255;// 97
return res;// 91 return res;// 98
} }
} }
@ -107,182 +112,192 @@ class 'pkg/TestPrimitives' {
29 10 29 10
2d 11 2d 11
2f 11 2f 11
32 12 33 12
3b 12 38 12
3c 12 3b 13
42 12 44 13
43 12 45 13
49 12 4b 13
4c 12 4c 13
52 12 52 13
54 12 55 13
5a 12 5b 13
5c 12 5d 13
62 12 63 13
65 12 65 13
69 12 6b 13
6d 13 6e 13
70 13 72 13
79 13 76 14
7c 13 79 14
83 13 82 14
86 13 85 14
8d 13 8c 14
90 13 8f 14
97 13 96 14
9a 13 99 14
9e 13 a0 14
a1 13 a3 14
a4 14 a7 14
aa 14
ad 15
} }
method 'printBoolean (Z)V' { method 'printBoolean (Z)V' {
0 17 0 18
3 17 3 18
c 17 c 18
10 17 10 18
13 17 13 18
16 18 16 19
} }
method 'printByte (B)V' { method 'printByte (B)V' {
0 21 0 22
3 21 3 22
c 21 c 22
10 21 10 22
13 21 13 22
16 22 16 23
} }
method 'printShort (S)V' { method 'printShort (S)V' {
0 25 0 26
3 25 3 26
c 25 c 26
10 25 10 26
13 25 13 26
16 26 16 27
} }
method 'printInt (I)V' { method 'printInt (I)V' {
0 29 0 30
3 29 3 30
c 29 c 30
10 29 10 30
13 29 13 30
16 30 16 31
} }
method 'printLong (J)V' { method 'printLong (J)V' {
0 33 0 34
3 33 3 34
c 33 c 34
10 33 10 34
13 33 13 34
16 34 16 35
} }
method 'printFloat (F)V' { method 'printFloat (F)V' {
0 37 0 38
3 37 3 38
c 37 c 38
10 37 10 38
13 37 13 38
16 38 16 39
} }
method 'printDouble (D)V' { method 'printDouble (D)V' {
0 41 0 42
3 41 3 42
c 41 c 42
10 41 10 42
13 41 13 42
16 42 16 43
} }
method 'printChar (C)V' { method 'printChar (C)V' {
0 45 0 46
3 45 3 46
c 45 c 46
10 45 10 46
13 45 13 46
16 46 16 47
}
method 'printIntBoxed (Ljava/lang/Integer;)V' {
0 50
3 50
d 50
10 50
13 51
} }
method 'getBoolean ()Z' { method 'getBoolean ()Z' {
0 49 0 54
1 49 1 54
} }
method 'getByte ()B' { method 'getByte ()B' {
0 53 0 58
2 53 2 58
} }
method 'getShort ()S' { method 'getShort ()S' {
0 57 0 62
3 57 3 62
} }
method 'getInt ()I' { method 'getInt ()I' {
0 61 0 66
2 61 2 66
} }
method 'printNarrowed ()V' { method 'printNarrowed ()V' {
2 65 2 70
5 65 5 70
6 65 6 70
b 66 b 71
e 66 e 71
f 66 f 71
12 67 12 72
} }
method 'constructor ()V' { method 'constructor ()V' {
4 70 4 75
9 71 9 76
} }
method 'compare (C)Z' { method 'compare (C)Z' {
1 74 1 79
2 74 2 79
a 74 a 79
c 75 c 80
14 75 14 80
16 76 16 81
17 76 17 81
1f 76 1f 81
21 77 21 82
23 77 23 82
2b 77 2b 82
2d 78 2d 83
2f 78 2f 83
37 78 37 83
39 79 39 84
3b 79 3b 84
43 79 43 84
45 80 45 85
47 80 47 85
4f 80 4f 85
51 81 51 86
53 81 53 86
5b 81 5b 86
5d 82 5d 87
5f 82 5f 87
67 82 67 87
69 83 69 88
6b 83 6b 88
73 83 73 88
75 84 75 89
77 84 77 89
7f 84 7f 89
81 85 81 90
83 85 83 90
8b 85 8b 90
8d 86 8d 91
90 86 90 91
98 86 98 91
9a 87 9a 92
} }
} }
@ -296,44 +311,47 @@ Lines mapping:
12 <-> 11 12 <-> 11
13 <-> 12 13 <-> 12
15 <-> 13 15 <-> 13
16 <-> 14 17 <-> 14
17 <-> 15 18 <-> 15
20 <-> 18 19 <-> 16
21 <-> 19 22 <-> 19
24 <-> 22 23 <-> 20
25 <-> 23 26 <-> 23
28 <-> 26 27 <-> 24
29 <-> 27 30 <-> 27
32 <-> 30 31 <-> 28
33 <-> 31 34 <-> 31
36 <-> 34 35 <-> 32
37 <-> 35 38 <-> 35
40 <-> 38 39 <-> 36
41 <-> 39 42 <-> 39
44 <-> 42 43 <-> 40
45 <-> 43 46 <-> 43
48 <-> 46 47 <-> 44
49 <-> 47 50 <-> 47
53 <-> 50 51 <-> 48
57 <-> 54 55 <-> 51
61 <-> 58 56 <-> 52
65 <-> 62 60 <-> 55
69 <-> 66 64 <-> 59
70 <-> 67 68 <-> 63
71 <-> 68 72 <-> 67
74 <-> 71 76 <-> 71
75 <-> 72 77 <-> 72
78 <-> 75 78 <-> 73
79 <-> 76 81 <-> 76
80 <-> 77 82 <-> 77
81 <-> 78 85 <-> 80
82 <-> 79 86 <-> 81
83 <-> 80 87 <-> 82
84 <-> 81 88 <-> 83
85 <-> 82 89 <-> 84
86 <-> 83 90 <-> 85
87 <-> 84 91 <-> 86
88 <-> 85 92 <-> 87
89 <-> 86 93 <-> 88
90 <-> 87 94 <-> 89
91 <-> 88 95 <-> 90
96 <-> 91
97 <-> 92
98 <-> 93

@ -12,7 +12,9 @@ public class TestPrimitives {
printDouble(1.23); printDouble(1.23);
printChar('Z'); printChar('Z');
String.format("%b, %d, %d, %d, %c", true, 1, 213, 40_000, 'c', 42L); printIntBoxed(40_000);
String.format("%b, %d, %d, %d, %c, %d", true, 1, 213, 40_000, 'c', 42L);
System.out.println(String.format("%b, %d, %d, %d", getBoolean(), getByte(), getShort(), getInt())); System.out.println(String.format("%b, %d, %d, %d", getBoolean(), getByte(), getShort(), getInt()));
} }
@ -49,6 +51,11 @@ public class TestPrimitives {
} }
public void printIntBoxed(Integer i) {
System.out.println(String.format("%d", i));
}
public boolean getBoolean() { public boolean getBoolean() {
return false; return false;
} }

Loading…
Cancel
Save