bugfix in fieldvaraccess

This commit is contained in:
404Simon 2024-05-20 21:22:16 +02:00
parent ad57e4baff
commit 8bccfc3a56
3 changed files with 8 additions and 41 deletions

View File

@ -205,38 +205,4 @@ public class TypedClass implements TypedNode {
return cw.toByteArray();
}
public static void main(String[] args) {
TypedClass c = new TypedClass();
c.setClassName("SomeClass");
//Fields
TypedDeclaration f1 = new TypedDeclaration("someNumber", Type.INT);
TypedDeclaration f2 = new TypedDeclaration("someChar", Type.CHAR);
c.typedDeclarations = List.of(f1, f2);
//Constructors
TypedConstructor constructor = new TypedConstructor("SomeClass", List.of(new TypedParameter("test", Type.INT)), new TypedBlock(new ArrayList<>(), new ArrayList<>()));
c.typedConstructors = List.of(constructor);
//Methods
c.typedMethods = new ArrayList<>();
TypedMethod m = new TypedMethod();
m.setName("someMethod");
m.setReturnType(Type.INT);
m.setTypedParameters(List.of(new TypedParameter("test", Type.INT)));
TypedIfElse ifs = new TypedIfElse();
TypedBinary cond = new TypedBinary();
cond.setOp(Operator.GT);
//cond.setLeft(??);
cond.setRight(new TypedIntLiteral(12));
ifs.setTypedCon(cond);
m.setTypedBlock(new TypedBlock(List.of(), List.of(ifs, new TypedReturn())));
c.typedMethods.add(m);
//codeGen
byte[] code = c.codeGen();
CodeGenUtils.writeClassfile(code, "SomeClass");
}
}

View File

@ -119,7 +119,11 @@ public class TypedFieldVarAccess implements TypedExpression {
if (recursiveOwnerChain != null) {
ownerChainName = recursiveOwnerChain.getType().getReference();
} else {
ownerChainName = type.getReference();
if (type.getKind() == Type.Kind.REFERENCE) {
ownerChainName = type.getReference();
} else {
ownerChainName = ctx.getClassContext().getName();
}
}
ctx.getMv().visitFieldInsn(Opcodes.GETFIELD, ownerChainName, name, type.getDescriptor());
} else {

View File

@ -6,12 +6,9 @@ public class ClassCanBeBytecoded {
public int test(int var1) {
int i;
i = 0;
while (i < 10) {
i = i + 1;
var1 = var1 + 1;
if (var1 == 5) {
for (int i = 0; i < 12; i = i + 1) {
var1 = this.c.c.c.c.x + this.x;
if (var1 * 3 == 0) {
break;
}
}