Many methods in statementgenerator implemented

This commit is contained in:
FelixKrespach 2017-09-20 17:36:16 +02:00
parent 201a0978bc
commit 8e1c1765ff
5 changed files with 72 additions and 26 deletions

View File

@ -300,18 +300,24 @@ public class StatementGenerator {
}
private Statement convert(Java8Parser.IfThenStatementContext stmt){
//TODO
throw new NotImplementedException();
Expression expr = convert(stmt.expression());
Statement thenBlock = convert(stmt.statement());
Statement elseBlock = new EmptyStmt(stmt.getStart());
return new IfStmt(TypePlaceholder.fresh(stmt.getStart()),expr,thenBlock,elseBlock,stmt.getStart());
}
private Statement convert(Java8Parser.IfThenElseStatementContext stmt){
//TODO
throw new NotImplementedException();
Expression expr = convert(stmt.expression());
Statement thenBlock = convert(stmt.statementNoShortIf());
Statement elseBlock = convert(stmt.statement());
return new IfStmt(TypePlaceholder.fresh(stmt.getStart()),expr,thenBlock,elseBlock,stmt.getStart());
}
private Statement convert(Java8Parser.IfThenElseStatementNoShortIfContext stmt){
//TODO
throw new NotImplementedException();
Expression expr = convert(stmt.expression());
Statement thenBlock = convert(stmt.statementNoShortIf().get(0));
Statement elseBlock = convert(stmt.statementNoShortIf().get(1));
return new IfStmt(TypePlaceholder.fresh(stmt.getStart()),expr,thenBlock,elseBlock,stmt.getStart());
}
private Statement convert(Java8Parser.AssertStatementContext stmt){
@ -341,8 +347,9 @@ public class StatementGenerator {
}
private Statement convert(Java8Parser.WhileStatementNoShortIfContext stmt){
//TODO
throw new NotImplementedException();
Expression expr = convert(stmt.expression());
Statement block = convert(stmt.statementNoShortIf());
return new WhileStmt(expr, block, stmt.getStart());
}
private Statement convert(Java8Parser.DoStatementContext stmt){
@ -368,13 +375,41 @@ public class StatementGenerator {
}
private Statement convert(Java8Parser.BasicForStatementContext stmt){
//TODO
throw new NotImplementedException();
List<Statement> stateList = new ArrayList<>();
List<Statement> whileList = new ArrayList<>();
if (stmt.forInit().localVariableDeclaration()==null)
{
whileList.addAll(convert(stmt.forInit().localVariableDeclaration()));
}
else
{
whileList.add(convert(stmt.forInit().statementExpressionList()));
}
Expression expr = convert(stmt.expression());
stateList.add(convert(stmt.statement()));
stateList.add(convert(stmt.forUpdate()));
Block forBlock = new Block(stateList,stmt.getStart());
whileList.add(new WhileStmt(expr,forBlock,stmt.getStart()));
return new Block(whileList,stmt.getStart());
}
private Statement convert(Java8Parser.BasicForStatementNoShortIfContext stmt){
//TODO
throw new NotImplementedException();
List<Statement> stateList = new ArrayList<>();
List<Statement> whileList = new ArrayList<>();
if (stmt.forInit().localVariableDeclaration()==null)
{
whileList.addAll(convert(stmt.forInit().localVariableDeclaration()));
}
else
{
whileList.add(convert(stmt.forInit().statementExpressionList()));
}
Expression expr = convert(stmt.expression());
stateList.add(convert(stmt.statementNoShortIf()));
stateList.add(convert(stmt.forUpdate()));
Block forBlock = new Block(stateList,stmt.getStart());
whileList.add(new WhileStmt(expr,forBlock,stmt.getStart()));
return new Block(whileList,stmt.getStart());
}
private List<Statement> convert(Java8Parser.ForInitContext stmt){
@ -456,8 +491,11 @@ public class StatementGenerator {
}
private Statement convert(Java8Parser.BreakStatementContext stmt){
//TODO
throw new NotImplementedException();
if (stmt.Identifier()!=null)
{
new BreakStmt(TypePlaceholder.fresh(stmt.getStart()),stmt.Identifier(),stmt.getStart());
}
return new BreakStmt(TypePlaceholder.fresh(stmt.getStart()),stmt.Identifier(),stmt.getStart());
}
private Statement convert(Java8Parser.ContinueStatementContext stmt){

View File

@ -15,8 +15,8 @@ public class SyntacticSugar {
//TODO
//if (hasReturn(((WhileStmt) lastStmt).loopBlock)) return statements;
} else if (lastStmt instanceof IfStmt) {
if (hasReturn(((IfStmt) lastStmt).then_block)
&& hasReturn(((IfStmt) lastStmt).else_block)) return statements;
//if (hasReturn(((IfStmt) lastStmt).then_block)
//&& hasReturn(((IfStmt) lastStmt).else_block)) return statements;
} else if (lastStmt instanceof ForStmt) {
if (hasReturn(((ForStmt) lastStmt).body_Loop_block)) return statements;
} else {

View File

@ -11,11 +11,11 @@ import org.antlr.v4.runtime.Token;
public class IfStmt extends Statement
{
public final Expression expr;
public final Block then_block;
public final Block else_block;
public final Statement then_block;
public final Statement else_block;
public IfStmt(RefTypeOrTPHOrWildcardOrGeneric type,
Expression expr, Block thenBlock, Block elseBlock, Token offset)
public IfStmt(RefTypeOrTPHOrWildcardOrGeneric type,
Expression expr, Statement thenBlock, Statement elseBlock, Token offset)
{
super(type,offset);
this.expr = expr;
@ -23,6 +23,7 @@ public class IfStmt extends Statement
this.else_block = elseBlock;
}
@Override
public void accept(StatementVisitor visitor) {
visitor.visit(this);

View File

@ -1,9 +1,11 @@
class WhileTest{
class WhileTest
{
void methode(){
Boolean test;
do{
test=test;
}while(test);
do
{
test=test;
}while(test);
while(test){

View File

@ -20,14 +20,14 @@ import java.util.Set;
public class JavaTXCompilerTest extends JavaTXCompiler {
private static final String rootDirectory = System.getProperty("user.dir")+"/test/javFiles/";
private static final String rootDirectory = System.getProperty("user.dir")+"/test/parser/";
private static final List<File> filesToTest = new ArrayList<>();
@Test
public void test() throws IOException, java.lang.ClassNotFoundException {
//filesToTest.add(new File(rootDirectory+"Faculty.jav"));
//filesToTest.add(new File(rootDirectory+"mathStruc.jav"));
filesToTest.add(new File(rootDirectory+"test.jav"));
//filesToTest.add(new File(rootDirectory+"test.jav"));
//filesToTest.add(new File(rootDirectory+"Lambda.jav"));
//filesToTest.add(new File(rootDirectory+"Lambda2.jav"));
//filesToTest.add(new File(rootDirectory+"Lambda3.jav"));
@ -36,9 +36,13 @@ public class JavaTXCompilerTest extends JavaTXCompiler {
//filesToTest.add(new File(rootDirectory+"MethodsEasy.jav"));
//filesToTest.add(new File(rootDirectory+"Matrix.jav"));
//filesToTest.add(new File(rootDirectory+"Import.jav"));
filesToTest.add(new File(rootDirectory+"BreakTest.jav"));
filesToTest.add(new File(rootDirectory+"WhileTest.jav"));
for(File f : filesToTest){
SourceFile sf = this.parse(f);
System.out.println(ASTTypePrinter.print(this.sourceFiles.get(sourceFiles.size()-1)));
/*
for(ResultSet resultSet : this.typeInference()){
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet);
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
@ -46,6 +50,7 @@ public class JavaTXCompilerTest extends JavaTXCompiler {
System.out.println(tip.insert(content));
}
}
*/
}
}