Fixed all Tests
Some checks are pending
Gitea Actions Demo / Explore-Gitea-Actions (push) Waiting to run

This commit is contained in:
Bruder John 2024-06-21 17:03:49 +02:00
parent cf41babcb7
commit 7b41c45cd5
4 changed files with 10 additions and 57 deletions

View File

@ -254,7 +254,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
currentNullType = lResult.getType();
var rResult = rExpression.accept(this);
if (!Objects.equals(currentFields.get(toCheck.assignable.identifier), rExpression.getType())) {
if (!Objects.equals(currentScope.getLocalVar(toCheck.assignable.identifier), rExpression.getType())) {
errors.add(new TypeMismatchException(
"Mismatch types in Assign-Statement: cannot convert from \"" + lResult.getType() + "\" to \""
+ rResult.getType() + "\""));
@ -265,7 +265,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
// }
valid = valid && lResult.isValid() && rResult.isValid();
currentNullType = null;
return new TypeCheckResult(valid, new BaseType(TypeEnum.VOID)); // return type is null to get the return type sufficently
return new TypeCheckResult(valid, null); // return type is null to get the return type sufficently
}
@Override
@ -352,12 +352,14 @@ public class SemanticAnalyzer implements SemanticVisitor {
public TypeCheckResult analyze(UnaryExpressionNode unary) {
var valid = true;
if (!currentScope.contains(unary.identifier)) {
errors.add(new NotDeclearedException("Not declared " + unary.identifier));
return new TypeCheckResult(false, null);
if (currentScope.contains(unary.identifier)) {
return new TypeCheckResult(valid, currentScope.getLocalVar(unary.identifier));
} else if(currentFields.get(unary.identifier) != null) {
return new TypeCheckResult(valid, currentFields.get(unary.identifier));
} else {
errors.add(new NotDeclearedException("Var is not Decleared"));
}
return new TypeCheckResult(valid, currentScope.getLocalVar(unary.identifier));
return new TypeCheckResult(valid, null);
}
}

View File

@ -155,30 +155,6 @@ public class EndToTAST {
}
@Test
public void correctInstVarTest(){
CharStream codeCharStream = null;
try {
codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/semantic/endToTAST/CorrectInstVar.java"));
} catch (IOException e) {
throw new RuntimeException(e);
}
SimpleJavaLexer lexer = new SimpleJavaLexer(codeCharStream);
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
SimpleJavaParser parser = new SimpleJavaParser(tokenStream);
ParseTree parseTree = parser.program();
ASTBuilder astBuilder = new ASTBuilder();
ProgramNode abstractSyntaxTree = (ProgramNode) astBuilder.visit(parseTree);
ASTNode tast = SemanticAnalyzer.generateTast(abstractSyntaxTree);
assertTrue(SemanticAnalyzer.errors.isEmpty());
}
@Test
public void typeMismatchRefType(){

View File

@ -1,18 +0,0 @@
public class Test {
public Example ex;
public static int testMethod(char x){
int b = this.ex.a;
return x;
}
}
public class Example {
public int a;
}

View File

@ -3,16 +3,9 @@ public class Example {
public int a;
public static int testMethod(int b){
a = b;
return a;
}
}
public class Test {
public static int testMethod(char x, int a){
return x;
}
}