Skip to content

Commit

Permalink
Remove unneeded source of fake booleans
Browse files Browse the repository at this point in the history
Signed-off-by: Robbe Pincket <[email protected]>

Fully remove fakeBooleans and useless copy

Signed-off-by: Robbe Pincket <[email protected]>

This change was on the wrong changelist

Signed-off-by: Robbe Pincket <[email protected]>

I always forget kotlin

Signed-off-by: Robbe Pincket <[email protected]>
  • Loading branch information
Kroppeb committed Oct 12, 2023
1 parent 60c6c17 commit 305eb38
Show file tree
Hide file tree
Showing 16 changed files with 25 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,8 @@ public CheckTypesResult checkExprTypeBounds() {
result.addMinTypeExprent(param1, VarType.VARTYPE_BYTECHAR);
}
else { // both are booleans
boolean param1_false_boolean =
type1.isFalseBoolean() || (param1 instanceof ConstExprent && !((ConstExprent)param1).hasBooleanValue());
boolean param2_false_boolean =
type1.isFalseBoolean() || (param2 instanceof ConstExprent && !((ConstExprent)param2).hasBooleanValue());
boolean param1_false_boolean = (param1 instanceof ConstExprent && !((ConstExprent)param1).hasBooleanValue());
boolean param2_false_boolean = (param2 instanceof ConstExprent && !((ConstExprent)param2).hasBooleanValue());

if (param1_false_boolean || param2_false_boolean) {
result.addMinTypeExprent(param1, VarType.VARTYPE_BYTECHAR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class KType extends VarType {
public final TypeArgument @Nullable [] typeArguments;

public KType(VarType type, String kotlinType, boolean isNullable, TypeArgument @Nullable [] typeArguments) {
super(type.type, type.arrayDim, type.value, type.typeFamily, type.stackSize, type.falseBoolean);
super(type.type, type.arrayDim, type.value, type.typeFamily, type.stackSize);
this.kotlinType = kotlinType;
this.isNullable = isNullable;
this.typeArguments = typeArguments;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,14 +436,14 @@ private static void processSpecialInstructions(DataPoint data, Instruction instr
case CodeConstants.opc_dup_x1:
case CodeConstants.opc_dup_x2:
int depth1 = 88 - instr.opcode;
stack.insertByOffset(depth1, stack.getByOffset(-1).copy());
stack.insertByOffset(depth1, stack.getByOffset(-1));
break;
case CodeConstants.opc_dup2:
case CodeConstants.opc_dup2_x1:
case CodeConstants.opc_dup2_x2:
int depth2 = 90 - instr.opcode;
stack.insertByOffset(depth2, stack.getByOffset(-2).copy());
stack.insertByOffset(depth2, stack.getByOffset(-1).copy());
stack.insertByOffset(depth2, stack.getByOffset(-2));
stack.insertByOffset(depth2, stack.getByOffset(-1));
break;
case CodeConstants.opc_swap:
var1 = stack.pop();
Expand Down
2 changes: 1 addition & 1 deletion src/org/jetbrains/java/decompiler/main/ClassWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ private static void methodLambdaToJava(ClassNode lambdaNode,
buffer.append(", ");
}

VarType type = md_content.params[i].copy();
VarType type = md_content.params[i];
String typeName = ExprProcessor.getCastTypeName(type);
if (ExprProcessor.UNDEFINED_TYPE_STRING.equals(typeName) &&
DecompilerContext.getOption(IFernflowerPreferences.UNDEFINED_PARAM_TYPE_OBJECT)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public Exprent copy() {
public VarType getExprType() {
VarType exprType = array.getExprType();
if (exprType.equals(VarType.VARTYPE_NULL)) {
return hardType.copy();
return hardType;
}
else {
return exprType.decreaseArrayDim();
Expand All @@ -44,7 +44,7 @@ public VarType getExprType() {
public VarType getInferredExprType(VarType upperBound) {
VarType exprType = array.getInferredExprType(upperBound);
if (exprType.equals(VarType.VARTYPE_NULL)) {
return hardType.copy();
return hardType;
}
else {
return exprType.decreaseArrayDim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,8 @@ protected ConstExprent(VarType constType, Object value, boolean boolPermitted, B
}

private static VarType guessType(int val, boolean boolPermitted) {
if (boolPermitted) {
VarType constType = VarType.VARTYPE_BOOLEAN;
if (val != 0 && val != 1) {
constType = constType.copy(true);
}
return constType;
if (boolPermitted && (val == 0 || val == 1)) {
return VarType.VARTYPE_BOOLEAN;
}
else if (0 <= val && val <= 127) {
return VarType.VARTYPE_BYTECHAR;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,10 +420,8 @@ public CheckTypesResult checkExprTypeBounds() {
result.addMinTypeExprent(param1, VarType.VARTYPE_BYTECHAR);
}
else { // both are booleans
boolean param1_false_boolean =
type1.isFalseBoolean() || (param1 instanceof ConstExprent && !((ConstExprent)param1).hasBooleanValue());
boolean param2_false_boolean =
type1.isFalseBoolean() || (param2 instanceof ConstExprent && !((ConstExprent)param2).hasBooleanValue());
boolean param1_false_boolean = (param1 instanceof ConstExprent && !((ConstExprent)param1).hasBooleanValue());
boolean param2_false_boolean = (param2 instanceof ConstExprent && !((ConstExprent)param2).hasBooleanValue());

if (param1_false_boolean || param2_false_boolean) {
result.addMinTypeExprent(param1, VarType.VARTYPE_BYTECHAR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -983,12 +983,6 @@ private VarType getMergedType(VarType fromMin, VarType toMin, VarType fromMax, V

return null;
} else {

// Special case: merging from false boolean to integral type, should be correct always
if (toMin.typeFamily == CodeConstants.TYPE_FAMILY_INTEGER && fromMin.isFalseBoolean()) {
return toMin;
}

// Both nonnull at this point
if (!fromMin.isStrictSuperset(toMin)) {
// If type we're merging into the old type isn't a strict superset of the old type, we cannot merge
Expand Down
31 changes: 3 additions & 28 deletions src/org/jetbrains/java/decompiler/struct/gen/VarType.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

import org.jetbrains.annotations.Nullable;
import org.jetbrains.java.decompiler.code.CodeConstants;
import org.jetbrains.java.decompiler.main.DecompilerContext;
import org.jetbrains.java.decompiler.struct.gen.generics.GenericType;
import org.jetbrains.java.decompiler.util.InterpreterUtil;

public class VarType { // TODO: optimize switch
Expand Down Expand Up @@ -58,7 +56,6 @@ public class VarType { // TODO: optimize switch
public final String value;
public final int typeFamily;
public final int stackSize;
public final boolean falseBoolean;

public VarType(int type) {
this(type, 0);
Expand All @@ -69,16 +66,15 @@ public VarType(int type, int arrayDim) {
}

public VarType(int type, int arrayDim, String value) {
this(type, arrayDim, value, getFamily(type, arrayDim), getStackSize(type, arrayDim), false);
this(type, arrayDim, value, getFamily(type, arrayDim), getStackSize(type, arrayDim));
}

protected VarType(int type, int arrayDim, String value, int typeFamily, int stackSize, boolean falseBoolean) {
protected VarType(int type, int arrayDim, String value, int typeFamily, int stackSize) {
this.type = type;
this.arrayDim = arrayDim;
this.value = value;
this.typeFamily = typeFamily;
this.stackSize = stackSize;
this.falseBoolean = falseBoolean;
}

public VarType(String signature) {
Expand Down Expand Up @@ -121,7 +117,6 @@ public VarType(String signature, boolean clType) {
this.value = value;
this.typeFamily = getFamily(type, arrayDim);
this.stackSize = getStackSize(type, arrayDim);
this.falseBoolean = false;
}

public static String getChar(int type) {
Expand Down Expand Up @@ -221,19 +216,7 @@ public VarType decreaseArrayDim() {
}

public VarType resizeArrayDim(int newArrayDim) {
return new VarType(type, newArrayDim, value, typeFamily, stackSize, falseBoolean);
}

public VarType copy() {
return copy(false);
}

public VarType copy(boolean forceFalseBoolean) {
return new VarType(type, arrayDim, value, typeFamily, stackSize, falseBoolean || forceFalseBoolean);
}

public boolean isFalseBoolean() {
return falseBoolean;
return new VarType(type, newArrayDim, value, typeFamily, stackSize);
}

public boolean isSuperset(VarType val) {
Expand Down Expand Up @@ -322,10 +305,6 @@ public String toString() {
// type1 and type2 must not be null
// Result should be the intersection of both types
public static @Nullable VarType getCommonMinType(VarType type1, VarType type2) {
if (type1.type == CodeConstants.TYPE_BOOLEAN && type2.type == CodeConstants.TYPE_BOOLEAN) { // special case booleans
return type1.isFalseBoolean() ? type2 : type1;
}

if (type1.isSuperset(type2)) {
return type2;
}
Expand Down Expand Up @@ -353,10 +332,6 @@ else if (type1.typeFamily == type2.typeFamily) {
// type1 and type2 must not be null
// Result should be the union of both types
public static @Nullable VarType getCommonSupertype(VarType type1, VarType type2) {
if (type1.type == CodeConstants.TYPE_BOOLEAN && type2.type == CodeConstants.TYPE_BOOLEAN) { // special case booleans
return type1.isFalseBoolean() ? type1 : type2;
}

if (type1.isSuperset(type2)) {
return type1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.jetbrains.java.decompiler.code.CodeConstants;
import org.jetbrains.java.decompiler.main.DecompilerContext;
import org.jetbrains.java.decompiler.modules.decompiler.ExprProcessor;
import org.jetbrains.java.decompiler.modules.decompiler.exps.InvocationExprent;
import org.jetbrains.java.decompiler.struct.StructClass;
import org.jetbrains.java.decompiler.struct.gen.VarType;
import org.jetbrains.java.decompiler.util.InterpreterUtil;
Expand All @@ -30,7 +29,7 @@ public class GenericType extends VarType {
public static final GenericType DUMMY_VAR = new GenericType(CodeConstants.TYPE_GENVAR, 0, "", null, null, GenericType.WILDCARD_NO);

public GenericType(int type, int arrayDim, String value, VarType parent, List<VarType> arguments, int wildcard) {
super(type, arrayDim, value, getFamily(type, arrayDim), getStackSize(type, arrayDim), false);
super(type, arrayDim, value, getFamily(type, arrayDim), getStackSize(type, arrayDim));
this.parent = parent;
this.arguments = arguments == null ? Collections.emptyList() : arguments;
this.wildcard = wildcard;
Expand Down
4 changes: 2 additions & 2 deletions testData/results/pkg/TestForCyclicVarDef.dec
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class TestForCyclicVarDef {
}// 6 13

public void test1() {
boolean var9 = true;// 17
short var9 = 12338;// 17
float var9x = 22.22F;

while (var9x > 133.07F) {
Expand Down Expand Up @@ -150,4 +150,4 @@ Lines mapping:
27 <-> 29
28 <-> 32
29 <-> 33
31 <-> 36
31 <-> 36
2 changes: 1 addition & 1 deletion testData/results/pkg/TestIfElseTernary1.dec
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public class TestIfElseTernary1 {
}// 116
} else {
try {
boolean vvv11 = true;// 122
short vvv11 = 209;// 122
} catch (Exception var15) {// 124
System.out.println(var15);// 126
System.out.println(vvv3);// 127
Expand Down
2 changes: 1 addition & 1 deletion testData/results/pkg/TestIfElseTernary1J17.dec
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public class TestIfElseTernary1J17 {
}// 116
} else {
try {
boolean vvv11 = true;// 122
short vvv11 = 209;// 122
} catch (Exception var15) {// 124
System.out.println(var15);// 126
System.out.println(vvv3);// 127
Expand Down
2 changes: 1 addition & 1 deletion testData/results/pkg/TestInfiniteLoop.dec
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class TestInfiniteLoop {
public void testSuccessor2(int i) {
int a = 0;// 56
if (i == 0) {// 57
a = 3;// 58
int var3 = 3;// 58
}

while (true) {
Expand Down
2 changes: 1 addition & 1 deletion testData/results/pkg/TestNestedTernaryCondition.dec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package pkg;
public class TestNestedTernaryCondition {
public void test(boolean bl, int a, int b) {
if (bl ? a <= b : a >= b) {// 5
boolean var5 = true;
byte var5 = 16;
} else {
boolean var10000 = false;
}
Expand Down
4 changes: 2 additions & 2 deletions testData/results/pkg/TestTryReturn.dec
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public class TestTryReturn {
continue;
}
} finally {
boolean var7 = true;// 156
byte var7 = 28;// 156
}
}
}// 159
Expand Down Expand Up @@ -686,4 +686,4 @@ Not mapped:
157
175
191
196
196

0 comments on commit 305eb38

Please sign in to comment.