methods in statementgenerator implemented
Tests + visit
This commit is contained in:
parent
8e1c1765ff
commit
b88b9e2534
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||
|
||||
import com.sun.javafx.fxml.expression.UnaryExpression;
|
||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||
import de.dhbwstuttgart.parser.NullToken;
|
||||
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
||||
@ -278,6 +279,7 @@ public class StatementGenerator {
|
||||
}
|
||||
|
||||
private Statement convert(Java8Parser.PostIncrementExpressionContext stmt) {
|
||||
Expression expr = convert(stmt.postfixExpression());
|
||||
//TODO
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
@ -320,9 +322,19 @@ public class StatementGenerator {
|
||||
return new IfStmt(TypePlaceholder.fresh(stmt.getStart()),expr,thenBlock,elseBlock,stmt.getStart());
|
||||
}
|
||||
|
||||
private Statement convert(Java8Parser.AssertStatementContext stmt){
|
||||
//TODO
|
||||
throw new NotImplementedException();
|
||||
private Statement convert(Java8Parser.AssertStatementContext stmt)
|
||||
{
|
||||
if (stmt.expression().size()<2)
|
||||
{
|
||||
Expression expr = convert(stmt.expression(0));
|
||||
return new AssertStmt(expr,stmt.getStart());
|
||||
}
|
||||
else {
|
||||
Expression expr1 = convert(stmt.expression(0));
|
||||
Expression expr2 = convert(stmt.expression(1));
|
||||
return new AssertStmt(expr1,expr2,stmt.getStart());
|
||||
}
|
||||
//TODO: Check Felix_K
|
||||
}
|
||||
|
||||
private Statement convert(Java8Parser.SwitchStatementContext stmt){
|
||||
|
22
src/de/dhbwstuttgart/syntaxtree/statement/AssertStmt.java
Normal file
22
src/de/dhbwstuttgart/syntaxtree/statement/AssertStmt.java
Normal file
@ -0,0 +1,22 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
/**
|
||||
* Created by Felix_K on 21.09.2017.
|
||||
*/
|
||||
public class AssertStmt extends Statement
|
||||
{
|
||||
final Expression expr;
|
||||
public AssertStmt(RefTypeOrTPHOrWildcardOrGeneric type, Expression expr, Token offset){
|
||||
super(type, offset);
|
||||
this.expr=expr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(StatementVisitor visitor) {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package de.dhbwstuttgart.syntaxtree.statement;
|
||||
|
||||
/**
|
||||
* Created by Felix_K on 21.09.2017.
|
||||
*/
|
||||
public class CatchesStatement
|
||||
{
|
||||
|
||||
}
|
@ -232,7 +232,11 @@ public class OutputGenerator implements ASTVisitor {
|
||||
|
||||
@Override
|
||||
public void visit(IfStmt ifStmt) {
|
||||
|
||||
out.append("if");
|
||||
ifStmt.expr.accept(this);
|
||||
ifStmt.then_block.accept(this);
|
||||
out.append("\nelse");
|
||||
ifStmt.else_block.accept(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
24
test/parser/IfTest.jav
Normal file
24
test/parser/IfTest.jav
Normal file
@ -0,0 +1,24 @@
|
||||
class IfTest
|
||||
{
|
||||
|
||||
public void IfStatementTest();
|
||||
|
||||
public void ifThenNoShortIfTest()
|
||||
{
|
||||
if(y)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public void ifThenElseTest()
|
||||
{
|
||||
if(z)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -38,10 +38,11 @@ public class JavaTXCompilerTest extends JavaTXCompiler {
|
||||
//filesToTest.add(new File(rootDirectory+"Import.jav"));
|
||||
filesToTest.add(new File(rootDirectory+"BreakTest.jav"));
|
||||
filesToTest.add(new File(rootDirectory+"WhileTest.jav"));
|
||||
filesToTest.add(new File(rootDirectory+"IfTest.jav"));
|
||||
for(File f : filesToTest){
|
||||
SourceFile sf = this.parse(f);
|
||||
System.out.println(ASTTypePrinter.print(this.sourceFiles.get(sourceFiles.size()-1)));
|
||||
|
||||
System.out.println("-----------------------------------------------------------------------------------");
|
||||
/*
|
||||
for(ResultSet resultSet : this.typeInference()){
|
||||
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet);
|
||||
|
Loading…
Reference in New Issue
Block a user