Some small changes for SemanticAnalyzer
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run

This commit is contained in:
Bruder John 2024-07-05 09:13:27 +02:00
parent 5a12d61623
commit dbde4e8047
35 changed files with 32 additions and 8 deletions

View File

@ -4,5 +4,6 @@ public enum TypeEnum {
VOID,
INT,
CHAR,
BOOL
BOOL,
NULL
}

View File

@ -254,6 +254,11 @@ public class SemanticAnalyzer implements SemanticVisitor {
return new TypeCheckResult(true, type);
} else if (currentScope.getLocalVar(toCheck.identifier) != null) {
var type = currentScope.getLocalVar(toCheck.identifier);
MemberAccessNode memberAccessNode = new MemberAccessNode(false);
memberAccessNode.identifiers.add(currentClass.identifier);
memberAccessNode.identifiers.add(toCheck.identifier);
toCheck.memberAccess = memberAccessNode;
toCheck.setTypeNode(type);
return new TypeCheckResult(true, type);
}
}
@ -328,7 +333,16 @@ public class SemanticAnalyzer implements SemanticVisitor {
if (toCheck.target != null) {
if(toCheck.target.memberAccess == null){
MemberAccessNode memberAccessNode = new MemberAccessNode(false);
var identifierType = currentFields.get(toCheck.target.identifier);
if(identifierType == null){
identifierType = currentScope.getLocalVar(toCheck.target.identifier);
}
if(identifierType instanceof ReferenceType referenceType){
memberAccessNode.identifiers.add(referenceType.getIdentifier());
} else {
memberAccessNode.identifiers.add(currentClass.identifier);
}
memberAccessNode.identifiers.add(toCheck.target.identifier);
toCheck.target.memberAccess = memberAccessNode;
}
@ -688,6 +702,9 @@ public class SemanticAnalyzer implements SemanticVisitor {
case BOOLEAN_VALUE -> {
return new TypeCheckResult(true, new BaseType(TypeEnum.BOOL));
}
case NULL_VALUE -> {
return new TypeCheckResult(true, currentNullType);
}
default -> {
return new TypeCheckResult(false, null);
}

View File

@ -1,8 +1,14 @@
public class If {
public If() {
int intValue = 5;
if(intValue == 5) {
intValue--;
}
public class Class1 {
public int test(){
Class2 class2 = new Class2();
int a = class2.test();
return a;
}
}
public class Class2
{
public int test(){
return 6+2*2;
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.