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
switch (type){
case "int":
mv.visitVarInsn(Opcodes.ILOAD, index);
break;
case "boolean":
case "int", "boolean", "char":
mv.visitVarInsn(Opcodes.ILOAD, index);
break;
case "void":

View File

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