Updated switch statements in case of char
This commit is contained in:
parent
66c7722728
commit
c30dcdb773
@ -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":
|
||||
|
@ -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;
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user