Updated switch statements in case of char

This commit is contained in:
Jochen Seyfried 2024-06-28 18:44:03 +02:00
parent 66c7722728
commit c30dcdb773
2 changed files with 11 additions and 14 deletions

View File

@ -69,10 +69,7 @@ public class LocalVarIdentifier extends AbstractType implements IExpression{
// Load the variable onto the stack // Load the variable onto the stack
switch (type){ switch (type){
case "int": case "int", "boolean", "char":
mv.visitVarInsn(Opcodes.ILOAD, index);
break;
case "boolean":
mv.visitVarInsn(Opcodes.ILOAD, index); mv.visitVarInsn(Opcodes.ILOAD, index);
break; break;
case "void": case "void":

View File

@ -52,12 +52,16 @@ public class LocalVarDecl extends AbstractType implements IStatement{
int index = -1; int index = -1;
int counter = 0; int counter = 0;
// Get the index of the local variable for (String key : localVars.keySet()){
for (String key : localVars.keySet()) { if (key.equals(identifier)){
counter++; index = counter+1; // +1 because the first local variable is at index 1, 0 is used for "this"
if (key.equals(identifier)) { break;
index = counter;
} }
counter++;
}
if (index == -1){
throw new Exception("Variable " + identifier + " not found");
} }
if (expression != null) { if (expression != null) {
@ -75,11 +79,7 @@ public class LocalVarDecl extends AbstractType implements IStatement{
// Set a default value for the variable --> less problems // Set a default value for the variable --> less problems
switch (type) { switch (type) {
case "int": case "int", "boolean", "char":
mv.visitInsn(Opcodes.ICONST_1);
mv.visitVarInsn(Opcodes.ISTORE, index);
break;
case "boolean":
mv.visitInsn(Opcodes.ICONST_0); mv.visitInsn(Opcodes.ICONST_0);
mv.visitVarInsn(Opcodes.ISTORE, index); mv.visitVarInsn(Opcodes.ISTORE, index);
break; break;