Some small changes for SemanticAnalyzer
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run
This commit is contained in:
parent
5a12d61623
commit
dbde4e8047
@ -4,5 +4,6 @@ public enum TypeEnum {
|
||||
VOID,
|
||||
INT,
|
||||
CHAR,
|
||||
BOOL
|
||||
BOOL,
|
||||
NULL
|
||||
}
|
||||
|
@ -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);
|
||||
memberAccessNode.identifiers.add(currentClass.identifier);
|
||||
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);
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
src/test/resources/input/combinedFeatureTests/LoopExamples.class
Normal file
BIN
src/test/resources/input/combinedFeatureTests/LoopExamples.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
src/test/resources/input/singleFeatureTests/TestClass2.class
Normal file
BIN
src/test/resources/input/singleFeatureTests/TestClass2.class
Normal file
Binary file not shown.
@ -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;
|
||||
}
|
||||
}
|
BIN
src/test/resources/output/javac/Char.class
Normal file
BIN
src/test/resources/output/javac/Char.class
Normal file
Binary file not shown.
BIN
src/test/resources/output/javac/Comments.class
Normal file
BIN
src/test/resources/output/javac/Comments.class
Normal file
Binary file not shown.
BIN
src/test/resources/output/javac/ConstructorMethodCall.class
Normal file
BIN
src/test/resources/output/javac/ConstructorMethodCall.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
src/test/resources/output/javac/ConstructorParameter.class
Normal file
BIN
src/test/resources/output/javac/ConstructorParameter.class
Normal file
Binary file not shown.
BIN
src/test/resources/output/javac/ConstructorThisDot.class
Normal file
BIN
src/test/resources/output/javac/ConstructorThisDot.class
Normal file
Binary file not shown.
BIN
src/test/resources/output/javac/DoWhile.class
Normal file
BIN
src/test/resources/output/javac/DoWhile.class
Normal file
Binary file not shown.
BIN
src/test/resources/output/javac/EmptyClass.class
Normal file
BIN
src/test/resources/output/javac/EmptyClass.class
Normal file
Binary file not shown.
BIN
src/test/resources/output/javac/EmptyClassWithConstructor.class
Normal file
BIN
src/test/resources/output/javac/EmptyClassWithConstructor.class
Normal file
Binary file not shown.
BIN
src/test/resources/output/javac/Field.class
Normal file
BIN
src/test/resources/output/javac/Field.class
Normal file
Binary file not shown.
BIN
src/test/resources/output/javac/FieldWithAccessModifier.class
Normal file
BIN
src/test/resources/output/javac/FieldWithAccessModifier.class
Normal file
Binary file not shown.
BIN
src/test/resources/output/javac/For.class
Normal file
BIN
src/test/resources/output/javac/For.class
Normal file
Binary file not shown.
BIN
src/test/resources/output/javac/If.class
Normal file
BIN
src/test/resources/output/javac/If.class
Normal file
Binary file not shown.
BIN
src/test/resources/output/javac/IfElse.class
Normal file
BIN
src/test/resources/output/javac/IfElse.class
Normal file
Binary file not shown.
BIN
src/test/resources/output/javac/IfElseIfElse.class
Normal file
BIN
src/test/resources/output/javac/IfElseIfElse.class
Normal file
Binary file not shown.
BIN
src/test/resources/output/javac/Increment.class
Normal file
BIN
src/test/resources/output/javac/Increment.class
Normal file
Binary file not shown.
BIN
src/test/resources/output/javac/MainMethod.class
Normal file
BIN
src/test/resources/output/javac/MainMethod.class
Normal file
Binary file not shown.
BIN
src/test/resources/output/javac/MultipleClasses.class
Normal file
BIN
src/test/resources/output/javac/MultipleClasses.class
Normal file
Binary file not shown.
BIN
src/test/resources/output/javac/SelfReference.class
Normal file
BIN
src/test/resources/output/javac/SelfReference.class
Normal file
Binary file not shown.
BIN
src/test/resources/output/javac/ThisDot.class
Normal file
BIN
src/test/resources/output/javac/ThisDot.class
Normal file
Binary file not shown.
BIN
src/test/resources/output/javac/VariableCalculation.class
Normal file
BIN
src/test/resources/output/javac/VariableCalculation.class
Normal file
Binary file not shown.
BIN
src/test/resources/output/javac/VariableCompare.class
Normal file
BIN
src/test/resources/output/javac/VariableCompare.class
Normal file
Binary file not shown.
BIN
src/test/resources/output/javac/VoidMethod.class
Normal file
BIN
src/test/resources/output/javac/VoidMethod.class
Normal file
Binary file not shown.
BIN
src/test/resources/output/javac/While.class
Normal file
BIN
src/test/resources/output/javac/While.class
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user