johns-branch #12

Merged
i22005 merged 23 commits from johns-branch into main 2024-06-21 16:30:56 +00:00
4 changed files with 42 additions and 3 deletions
Showing only changes of commit 5bf9a4fc73 - Show all commits

View File

@ -175,7 +175,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
@Override @Override
public TypeCheckResult analyze(IfStatementNode toCheck) { public TypeCheckResult analyze(IfStatementNode toCheck) {
return null; return new TypeCheckResult(true, null);
} }
@Override @Override
@ -275,7 +275,7 @@ public class SemanticAnalyzer implements SemanticVisitor {
@Override @Override
public TypeCheckResult analyze(IfElseStatementNode toCheck) { public TypeCheckResult analyze(IfElseStatementNode toCheck) {
return null; return new TypeCheckResult(true, null);
} }
@Override @Override

View File

@ -49,6 +49,7 @@ public class EndToTAST {
ASTNode tast = SemanticAnalyzer.generateTast(abstractSyntaxTree); ASTNode tast = SemanticAnalyzer.generateTast(abstractSyntaxTree);
assertEquals(SemanticAnalyzer.errors.size(), 0); assertEquals(SemanticAnalyzer.errors.size(), 0);
assertNotNull(tast); assertNotNull(tast);
@ -254,4 +255,28 @@ public class EndToTAST {
} }
@Test
public void wrongTypeInIfClause(){
CharStream codeCharStream = null;
try {
codeCharStream = CharStreams.fromPath(Paths.get("src/test/resources/semantic/endToTAST/WrongIfClause.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);
assertFalse(SemanticAnalyzer.errors.isEmpty());
}
} }

View File

@ -2,10 +2,17 @@ public class Example {
public int a; public int a;
public static int testMethod(int b){ public static int testMethod(int b, boolean bo){
a = b; a = b;
if(bo){
}
return a; return a;
} }
public static void testMethod(int b){
}
} }

View File

@ -0,0 +1,7 @@
public class Example {
public static void testMethod(int x){
}
}