From 88bcfa5fa3a8e6addd936993ed32f51eb709a2a6 Mon Sep 17 00:00:00 2001 From: Jochen Seyfried Date: Wed, 3 Jul 2024 07:49:39 +0200 Subject: [PATCH] Fixed Error with InstVars in Assign, where the class in which the field was going to be in was not correct, due to the InstVar parameter not being set and it being treated as a localVar --- .../StatementExpression/AssignStatementExpression.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/abstractSyntaxTree/StatementExpression/AssignStatementExpression.java b/src/main/java/abstractSyntaxTree/StatementExpression/AssignStatementExpression.java index 2b1b305..fc0cfd2 100644 --- a/src/main/java/abstractSyntaxTree/StatementExpression/AssignStatementExpression.java +++ b/src/main/java/abstractSyntaxTree/StatementExpression/AssignStatementExpression.java @@ -93,7 +93,7 @@ public class AssignStatementExpression extends AbstractType implements IExpressi // Call the codeGen on the right expression which will push the value of the right expression onto the stack right.codeGen(mv, localVars, typeContext, methodContext); // Get the field descriptor - String descriptor = getFieldDescriptor(fieldType, typeContext); + String descriptor = getFieldDescriptor(fieldType, typeContext, varName, thisClass); // Store the value in the field mv.visitFieldInsn(Opcodes.PUTFIELD, thisClass, varName, descriptor); return; @@ -146,14 +146,14 @@ public class AssignStatementExpression extends AbstractType implements IExpressi String fieldType = typeContext.get(instVar.thisClass).get(instVar.fieldName); // Get the field descriptor - String descriptor = getFieldDescriptor(fieldType, typeContext); + String descriptor = getFieldDescriptor(fieldType, typeContext, instVar.fieldName, instVar.thisClass); // Store the value in the field mv.visitFieldInsn(Opcodes.PUTFIELD, instVar.thisClass, instVar.fieldName, descriptor); } } - private String getFieldDescriptor(String type, HashMap> typeContext) { + private String getFieldDescriptor(String type, HashMap> typeContext, String varName, String classToSearchFieldIn) { StringBuilder descriptor = new StringBuilder(); switch (type) { case "int": @@ -163,7 +163,7 @@ public class AssignStatementExpression extends AbstractType implements IExpressi case "char": return "C"; default: { - String fullReturnType = typeContext.get(instVar.thisClass).get(instVar.fieldName); + String fullReturnType = typeContext.get(classToSearchFieldIn).get(varName); // If it is a class reference replace the "." with "/" and return it if (type.contains(".")) fullReturnType = fullReturnType.replaceAll("\\.", "/");