diff --git a/src/main/java/semantic/SemanticAnalyzer.java b/src/main/java/semantic/SemanticAnalyzer.java index 191e3a9..8a16b47 100644 --- a/src/main/java/semantic/SemanticAnalyzer.java +++ b/src/main/java/semantic/SemanticAnalyzer.java @@ -175,7 +175,7 @@ public class SemanticAnalyzer implements SemanticVisitor { @Override public TypeCheckResult analyze(IfStatementNode toCheck) { - return null; + return new TypeCheckResult(true, null); } @Override @@ -275,7 +275,7 @@ public class SemanticAnalyzer implements SemanticVisitor { @Override public TypeCheckResult analyze(IfElseStatementNode toCheck) { - return null; + return new TypeCheckResult(true, null); } @Override diff --git a/src/test/java/semantic/EndToTAST.java b/src/test/java/semantic/EndToTAST.java index dc30e0b..3189802 100644 --- a/src/test/java/semantic/EndToTAST.java +++ b/src/test/java/semantic/EndToTAST.java @@ -49,6 +49,7 @@ public class EndToTAST { ASTNode tast = SemanticAnalyzer.generateTast(abstractSyntaxTree); + assertEquals(SemanticAnalyzer.errors.size(), 0); 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()); + + } + } diff --git a/src/test/resources/semantic/endToTAST/CorrectTest.java b/src/test/resources/semantic/endToTAST/CorrectTest.java index f0cdb30..054a49b 100644 --- a/src/test/resources/semantic/endToTAST/CorrectTest.java +++ b/src/test/resources/semantic/endToTAST/CorrectTest.java @@ -2,10 +2,17 @@ public class Example { public int a; - public static int testMethod(int b){ + public static int testMethod(int b, boolean bo){ a = b; + if(bo){ + + } return a; } + public static void testMethod(int b){ + + } + } \ No newline at end of file diff --git a/src/test/resources/semantic/endToTAST/WrongIfClause.java b/src/test/resources/semantic/endToTAST/WrongIfClause.java new file mode 100644 index 0000000..f73f052 --- /dev/null +++ b/src/test/resources/semantic/endToTAST/WrongIfClause.java @@ -0,0 +1,7 @@ +public class Example { + + public static void testMethod(int x){ + + } + +}