Fixed Bugs in bytecode generation
This commit is contained in:
parent
87e863e773
commit
9ff069827a
@ -24,7 +24,7 @@ public class TypeCheckHelper {
|
|||||||
}
|
}
|
||||||
public static boolean typeExists(String type, List<String> customTypeslist) {
|
public static boolean typeExists(String type, List<String> customTypeslist) {
|
||||||
|
|
||||||
if(type.equals("int") || type.equals("bool") || type.equals("char")){
|
if(type.equals("int") || type.equals("boolean") || type.equals("char")){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return customTypeslist.contains(type);
|
return customTypeslist.contains(type);
|
||||||
|
@ -125,7 +125,7 @@ public class MethodDecl implements Node {
|
|||||||
for (Parameter param : parameters.parameterList) {
|
for (Parameter param : parameters.parameterList) {
|
||||||
switch (param.type) {
|
switch (param.type) {
|
||||||
case "int" -> descriptor.append("I");
|
case "int" -> descriptor.append("I");
|
||||||
case "bool" -> descriptor.append("Z");
|
case "boolean" -> descriptor.append("Z");
|
||||||
case "char" -> descriptor.append("C");
|
case "char" -> descriptor.append("C");
|
||||||
case "void" -> descriptor.append("V");
|
case "void" -> descriptor.append("V");
|
||||||
default -> {
|
default -> {
|
||||||
@ -144,11 +144,12 @@ public class MethodDecl implements Node {
|
|||||||
} else {
|
} else {
|
||||||
switch (returnType) {
|
switch (returnType) {
|
||||||
case "int" -> descriptor.append("I");
|
case "int" -> descriptor.append("I");
|
||||||
case "bool" -> descriptor.append("Z");
|
case "boolean" -> descriptor.append("Z");
|
||||||
case "char" -> descriptor.append("C");
|
case "char" -> descriptor.append("C");
|
||||||
case "void" -> descriptor.append("V");
|
case "void" -> descriptor.append("V");
|
||||||
default -> {
|
default -> {
|
||||||
// object
|
// object
|
||||||
|
// methodContext (class, (returnType, (identifier, parameter)))
|
||||||
HashMap<String, HashMap<String, ParameterList>> classMethods = methodContext.get(classThatContainsMethod);
|
HashMap<String, HashMap<String, ParameterList>> classMethods = methodContext.get(classThatContainsMethod);
|
||||||
HashMap<String, ParameterList> methodDetails = classMethods.get(name);
|
HashMap<String, ParameterList> methodDetails = classMethods.get(name);
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ public class LocalVarDecl extends AbstractType implements IStatement{
|
|||||||
mv.visitInsn(Opcodes.ICONST_0);
|
mv.visitInsn(Opcodes.ICONST_0);
|
||||||
mv.visitVarInsn(Opcodes.ISTORE, index);
|
mv.visitVarInsn(Opcodes.ISTORE, index);
|
||||||
break;
|
break;
|
||||||
case "bool":
|
case "boolean":
|
||||||
mv.visitInsn(Opcodes.ICONST_0);
|
mv.visitInsn(Opcodes.ICONST_0);
|
||||||
mv.visitVarInsn(Opcodes.ISTORE, index);
|
mv.visitVarInsn(Opcodes.ISTORE, index);
|
||||||
break;
|
break;
|
||||||
|
@ -47,7 +47,7 @@ public class AssignStatementExpression extends AbstractType implements IExpressi
|
|||||||
|
|
||||||
String upperbound = helper.upperBound(leftType.type, rightType.type);
|
String upperbound = helper.upperBound(leftType.type, rightType.type);
|
||||||
if(Objects.equals(leftType.type, "boolean"))
|
if(Objects.equals(leftType.type, "boolean"))
|
||||||
leftType.type = "bool";
|
leftType.type = "boolean";
|
||||||
if (!Objects.equals(upperbound, leftType.type)) {
|
if (!Objects.equals(upperbound, leftType.type)) {
|
||||||
throw new TypeCheckException("The upper bound of assignment is not the left type.");
|
throw new TypeCheckException("The upper bound of assignment is not the left type.");
|
||||||
}
|
}
|
||||||
@ -78,7 +78,7 @@ public class AssignStatementExpression extends AbstractType implements IExpressi
|
|||||||
int counter = 0;
|
int counter = 0;
|
||||||
for (String key : localVars.keySet()) {
|
for (String key : localVars.keySet()) {
|
||||||
if (key.equals(varName)) {
|
if (key.equals(varName)) {
|
||||||
index = counter;
|
index = counter+1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
counter++;
|
counter++;
|
||||||
@ -90,8 +90,7 @@ public class AssignStatementExpression extends AbstractType implements IExpressi
|
|||||||
|
|
||||||
String type = localVars.get(localVar.getIdentifier());
|
String type = localVars.get(localVar.getIdentifier());
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "int":
|
case "int", "char", "boolean":
|
||||||
case "bool":
|
|
||||||
mv.visitVarInsn(Opcodes.ISTORE, index);
|
mv.visitVarInsn(Opcodes.ISTORE, index);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user