From ae260f6feb50b3eb9c7d026cb995e6e41198e457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krau=C3=9F=2C=20Josefine?= Date: Tue, 25 Jun 2024 15:06:20 +0200 Subject: [PATCH] boolean instead of bool --- src/main/java/Compiler.java | 4 ++-- src/main/java/Input.java | 2 ++ src/main/java/TypeCheck/TypeCheckHelper.java | 4 ++-- .../java/abstractSyntaxTree/Expression/BinaryExpression.java | 4 ++-- .../java/abstractSyntaxTree/Expression/UnaryExpression.java | 4 ++-- src/main/java/abstractSyntaxTree/Program.java | 2 -- .../StatementExpression/AssignStatementExpression.java | 5 +++++ 7 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main/java/Compiler.java b/src/main/java/Compiler.java index 3f197ab..ae45c5e 100644 --- a/src/main/java/Compiler.java +++ b/src/main/java/Compiler.java @@ -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 { diff --git a/src/main/java/Input.java b/src/main/java/Input.java index b047c82..c28e11e 100644 --- a/src/main/java/Input.java +++ b/src/main/java/Input.java @@ -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; diff --git a/src/main/java/TypeCheck/TypeCheckHelper.java b/src/main/java/TypeCheck/TypeCheckHelper.java index b9a4cb3..2ffee4b 100644 --- a/src/main/java/TypeCheck/TypeCheckHelper.java +++ b/src/main/java/TypeCheck/TypeCheckHelper.java @@ -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"; } diff --git a/src/main/java/abstractSyntaxTree/Expression/BinaryExpression.java b/src/main/java/abstractSyntaxTree/Expression/BinaryExpression.java index ba0041d..d2b4713 100644 --- a/src/main/java/abstractSyntaxTree/Expression/BinaryExpression.java +++ b/src/main/java/abstractSyntaxTree/Expression/BinaryExpression.java @@ -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; } diff --git a/src/main/java/abstractSyntaxTree/Expression/UnaryExpression.java b/src/main/java/abstractSyntaxTree/Expression/UnaryExpression.java index 741e673..4a2243c 100644 --- a/src/main/java/abstractSyntaxTree/Expression/UnaryExpression.java +++ b/src/main/java/abstractSyntaxTree/Expression/UnaryExpression.java @@ -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; } diff --git a/src/main/java/abstractSyntaxTree/Program.java b/src/main/java/abstractSyntaxTree/Program.java index 9512434..2a0c919 100644 --- a/src/main/java/abstractSyntaxTree/Program.java +++ b/src/main/java/abstractSyntaxTree/Program.java @@ -37,8 +37,6 @@ public class Program implements Node { // build type context HashMap 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); diff --git a/src/main/java/abstractSyntaxTree/StatementExpression/AssignStatementExpression.java b/src/main/java/abstractSyntaxTree/StatementExpression/AssignStatementExpression.java index 917aa8e..a445ccc 100644 --- a/src/main/java/abstractSyntaxTree/StatementExpression/AssignStatementExpression.java +++ b/src/main/java/abstractSyntaxTree/StatementExpression/AssignStatementExpression.java @@ -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); }