boolean instead of bool

This commit is contained in:
Krauß, Josefine 2024-06-25 15:06:20 +02:00
parent 7daece9b8f
commit ae260f6feb
7 changed files with 15 additions and 10 deletions

View File

@ -28,12 +28,12 @@ public class Compiler {
public static void main(String[] args) throws Exception{
Path filePath = Paths.get("src/main/java/InputTest.java");
Path filePath = Paths.get("src/main/java/Input.java");
// todo remove this debug info
Path absolutePath = filePath.toAbsolutePath();
System.out.println("Full path: " + absolutePath);
System.out.println("Processing input: " + absolutePath);
String content;
try {

View File

@ -2,7 +2,9 @@ class Example1 {
int i;
int a = 12345;
Example e;
public Example1(){i = 3456;}
int m(int n){
boolean b123;
int x;
x = -3;
int i = 5;

View File

@ -13,10 +13,10 @@ public class TypeCheckHelper {
if(Objects.equals(type1, type2)){
result = type1;
}else{
throw new TypeCheckException("There is no upper bound.");
throw new TypeCheckException("There is no upper bound between " + type1 + " and " + type2 + ".");
}
}else if(type1Primitiv || type2Primitiv){
throw new TypeCheckException("There is no upper bound.");
throw new TypeCheckException("There is no upper bound between " + type1 + " and " + type2 + ".");
}else{
result = "class";
}

View File

@ -35,8 +35,8 @@ public class BinaryExpression extends AbstractType implements IExpression{
case "&&":
case "||" :{
if (Objects.equals(TypeCheckHelper.upperBound(leftType.type, rightType.type), "bool")){
result.type = "bool";
if (Objects.equals(TypeCheckHelper.upperBound(leftType.type, rightType.type), "boolean")){
result.type = "boolean";
}
break;
}

View File

@ -30,8 +30,8 @@ public class UnaryExpression extends AbstractType implements IExpression{
switch (operator) {
case "!" :{
if (Objects.equals(operandType, "bool")){
result.type = "bool";
if (Objects.equals(operandType, "boolean")){
result.type = "boolean";
}
break;
}

View File

@ -37,8 +37,6 @@ public class Program implements Node {
// build type context
HashMap<String, String> classVars = new HashMap<>();
for (FieldDecl fieldDecl: oneClass.fieldDecls){
if(fieldDecl.type == "boolean")
fieldDecl.type = "bool";
classVars.put(fieldDecl.identifier, fieldDecl.type);
}
typeContext.put(oneClass.name, classVars);

View File

@ -39,6 +39,11 @@ public class AssignStatementExpression extends AbstractType implements IExpressi
LocalVarIdentifier localVarIdentifier = (LocalVarIdentifier) left;
String identifier = localVarIdentifier.getIdentifier();
leftType.type = localVars.get(identifier);
// actually instavar of this
// if(leftType == null){
// localVarIdentifier.
// }
}else{
leftType = left.typeCheck(methodContext, typeContext, localVars);
}