From 8a5f307947dd18fdf219507be46b31da518c6cec Mon Sep 17 00:00:00 2001 From: Bruder John Date: Fri, 31 May 2024 11:27:02 +0200 Subject: [PATCH] Fix Type --- .idea/misc.xml | 2 +- src/main/java/ast/literal/LiteralNode.java | 9 +++++---- src/main/java/classFileOutput/Example.class | Bin 167 -> 166 bytes src/main/java/classFileOutput/Test.class | Bin 97 -> 148 bytes src/main/java/parser/ASTBuilder.java | 14 +++++++------- src/main/java/semantic/SemanticAnalyzer.java | 3 --- src/main/resources/CompilerInput.java | 4 ++++ 7 files changed, 17 insertions(+), 15 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 4e21abf..459a2c6 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -40,7 +40,7 @@ - + \ No newline at end of file diff --git a/src/main/java/ast/literal/LiteralNode.java b/src/main/java/ast/literal/LiteralNode.java index 66dbc74..b3cb896 100644 --- a/src/main/java/ast/literal/LiteralNode.java +++ b/src/main/java/ast/literal/LiteralNode.java @@ -1,24 +1,25 @@ package ast.literal; import ast.expression.ExpressionNode; +import ast.type.TypeNode; import semantic.SemanticVisitor; import typechecker.TypeCheckResult; public class LiteralNode implements ExpressionNode { public String value; - private String type; + private TypeNode type; - public LiteralNode(String value, String type) { + public LiteralNode(String value, TypeNode type) { this.value = value; this.type = type; } - public String getType() { + public TypeNode getType() { return type; } - public void setType(String type) { + public void setType(TypeNode type) { this.type = type; } diff --git a/src/main/java/classFileOutput/Example.class b/src/main/java/classFileOutput/Example.class index 522ae9edd25429b756d2dd98d755bdedb11f81c3..e34760ad5214618f0188bdd98631358127ac36ce 100644 GIT binary patch delta 12 TcmZ3^xQuZ^EE9{y!~}N$81)0A delta 13 UcmZ3+xSVl9EHkTy=frq-033}2?EnA( diff --git a/src/main/java/classFileOutput/Test.class b/src/main/java/classFileOutput/Test.class index 8ba4c23343d79136e322bf6f22591360f6985b92..98f27991c1557e7e05c706e183ff37e4f9036fe4 100644 GIT binary patch delta 109 zcmYeC!pL>%->!WO3=D=0JQKO}qj?xu8Q8cOSQywD8MsPPi%Wb{OEU6P7#UbKJUul% w85vld^HWk87#Wy=YCwPq$OdWwlH5R^AdqGR(yUtB88|kA!WO3=Ad=oD;e9H5eIKN>YnU7=a>;3``6xV49JEoq+?&Vr5_hvKRna CG6!1# diff --git a/src/main/java/parser/ASTBuilder.java b/src/main/java/parser/ASTBuilder.java index 446b7eb..7e7422d 100644 --- a/src/main/java/parser/ASTBuilder.java +++ b/src/main/java/parser/ASTBuilder.java @@ -230,22 +230,22 @@ public class ASTBuilder extends SimpleJavaBaseVisitor { @Override public ASTNode visitLiteral(SimpleJavaParser.LiteralContext ctx) { - String type; + TypeNode type; String value; if(ctx.INTEGERLITERAL() != null) { - type = "int"; + type = new BaseTypeNode(EnumTypeNode.INT); value = ctx.INTEGERLITERAL().getText(); - return new LiteralNode(type, value); + return new LiteralNode(value, type); } else if(ctx.booleanLiteral() != null) { - type= "boolean"; + type= new BaseTypeNode(EnumTypeNode.BOOLEAN); BooleanLiteralNode booleanNode = (BooleanLiteralNode) visitBooleanLiteral(ctx.booleanLiteral()); value = booleanNode.getValue(); - return new LiteralNode(type, value); + return new LiteralNode(value, type); } else if(ctx.charLiteral() != null) { - type= "char"; + type= new BaseTypeNode(EnumTypeNode.CHAR); CharLiteralNode charNode = (CharLiteralNode) visitCharLiteral(ctx.charLiteral()); value = charNode.getValue(); - return new LiteralNode(type, value); + return new LiteralNode(value, type); } return null; } diff --git a/src/main/java/semantic/SemanticAnalyzer.java b/src/main/java/semantic/SemanticAnalyzer.java index 9ccfe98..253a7b7 100644 --- a/src/main/java/semantic/SemanticAnalyzer.java +++ b/src/main/java/semantic/SemanticAnalyzer.java @@ -146,9 +146,6 @@ public class SemanticAnalyzer implements SemanticVisitor { @Override public TypeCheckResult analyze(AssignmentStatementNode assignmentStatementNode) { boolean valid = true; - BinaryExpressionNode binaryExpressionNode = assignmentStatementNode.expression; - var result = binaryExpressionNode.accept(this); - valid = valid && result.isValid(); return new TypeCheckResult(valid, null); } diff --git a/src/main/resources/CompilerInput.java b/src/main/resources/CompilerInput.java index 1cbe5ca..0f8297b 100644 --- a/src/main/resources/CompilerInput.java +++ b/src/main/resources/CompilerInput.java @@ -4,6 +4,10 @@ public class Example { public static int testMethod(char x){ + a = 12; + + a = x; + } }