From d925a3258c9280460b255e5388fa29b270f7009d Mon Sep 17 00:00:00 2001 From: Bruder John Date: Thu, 4 Jul 2024 15:58:46 +0200 Subject: [PATCH 1/3] Add Class name to Memberaccesnode and identifier to assignable --- src/main/java/semantic/SemanticAnalyzer.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/semantic/SemanticAnalyzer.java b/src/main/java/semantic/SemanticAnalyzer.java index 732a6e6..7b6e2cb 100644 --- a/src/main/java/semantic/SemanticAnalyzer.java +++ b/src/main/java/semantic/SemanticAnalyzer.java @@ -253,6 +253,7 @@ public class SemanticAnalyzer implements SemanticVisitor { if (toCheck.memberAccess != null) { var result = toCheck.memberAccess.accept(this); + toCheck.identifier = toCheck.memberAccess.identifiers.getLast(); toCheck.setTypeNode(result.getType()); return result; } else { @@ -608,11 +609,15 @@ public class SemanticAnalyzer implements SemanticVisitor { ITypeNode currentType = null; int start = 0; if(!memberAccessNode.identifiers.isEmpty()){ - if(currentFields.get(memberAccessNode.identifiers.get(0)) != null){ - memberAccessNode.identifiers.add(0, currentClass.identifier); - start = 1; + if(currentFields.get(memberAccessNode.identifiers.getFirst()) != null){ + memberAccessNode.identifiers.addFirst(currentClass.identifier); + start++; } } + if(context.getClasses().get(memberAccessNode.identifiers.getFirst()) != null){ + memberAccessNode.identifiers.addFirst(currentClass.identifier); + start++; + } for (int i = start; i < memberAccessNode.identifiers.size(); i++) { String s = memberAccessNode.identifiers.get(i); From 2e3a7850a40815180326ddb80d5a15f6e8ba3c84 Mon Sep 17 00:00:00 2001 From: Bruder John Date: Thu, 4 Jul 2024 16:29:42 +0200 Subject: [PATCH 2/3] Fix Double Name --- src/main/java/semantic/SemanticAnalyzer.java | 2 +- .../typedAstFeatureTests/CorrectTest.java | 21 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/semantic/SemanticAnalyzer.java b/src/main/java/semantic/SemanticAnalyzer.java index 7b6e2cb..0a9e373 100644 --- a/src/main/java/semantic/SemanticAnalyzer.java +++ b/src/main/java/semantic/SemanticAnalyzer.java @@ -614,7 +614,7 @@ public class SemanticAnalyzer implements SemanticVisitor { start++; } } - if(context.getClasses().get(memberAccessNode.identifiers.getFirst()) != null){ + if(context.getClasses().get(memberAccessNode.identifiers.getFirst()) == null){ memberAccessNode.identifiers.addFirst(currentClass.identifier); start++; } diff --git a/src/test/resources/input/typedAstFeatureTests/CorrectTest.java b/src/test/resources/input/typedAstFeatureTests/CorrectTest.java index 53a8f3c..d5533fd 100644 --- a/src/test/resources/input/typedAstFeatureTests/CorrectTest.java +++ b/src/test/resources/input/typedAstFeatureTests/CorrectTest.java @@ -1,13 +1,16 @@ -public class Klasse1 { - public int test; - - public int test1() { - test = 5; - return 1; +public class Compiler { + Node node; + public int add(int i, int j) { + node = new Node(); + node.x = 1; + return i+j; } +} - public void test2() { - int testInt; - testInt = this.test1(); +public class Node { + public int x; + public void main() { + Compiler compiler = new Compiler(); + int i = compiler.add(5, 8); } } \ No newline at end of file From 9b8155ebab61ce6ad53930d7d3035e1ac584f491 Mon Sep 17 00:00:00 2001 From: Bruder John Date: Thu, 4 Jul 2024 16:31:45 +0200 Subject: [PATCH 3/3] added class identifier to member acces node --- src/main/java/semantic/SemanticAnalyzer.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/semantic/SemanticAnalyzer.java b/src/main/java/semantic/SemanticAnalyzer.java index 0a9e373..8146052 100644 --- a/src/main/java/semantic/SemanticAnalyzer.java +++ b/src/main/java/semantic/SemanticAnalyzer.java @@ -635,7 +635,8 @@ public class SemanticAnalyzer implements SemanticVisitor { } else { if (currentType instanceof ReferenceType reference) { var currentTypeClass = context.getClass(reference.getIdentifier()); - + memberAccessNode.identifiers.add(i, reference.getIdentifier()); + i++; var currentField = currentTypeClass.getField(s); if (currentField.getAccessModifier().accessType == EnumAccessModifierNode.PUBLIC) { currentType = currentField.getType();