forked from JavaTX/JavaCompilerCore
Many methods in statementgenerator implemented
This commit is contained in:
parent
201a0978bc
commit
8e1c1765ff
@ -300,18 +300,24 @@ public class StatementGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Statement convert(Java8Parser.IfThenStatementContext stmt){
|
private Statement convert(Java8Parser.IfThenStatementContext stmt){
|
||||||
//TODO
|
Expression expr = convert(stmt.expression());
|
||||||
throw new NotImplementedException();
|
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){
|
private Statement convert(Java8Parser.IfThenElseStatementContext stmt){
|
||||||
//TODO
|
Expression expr = convert(stmt.expression());
|
||||||
throw new NotImplementedException();
|
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){
|
private Statement convert(Java8Parser.IfThenElseStatementNoShortIfContext stmt){
|
||||||
//TODO
|
Expression expr = convert(stmt.expression());
|
||||||
throw new NotImplementedException();
|
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){
|
private Statement convert(Java8Parser.AssertStatementContext stmt){
|
||||||
@ -341,8 +347,9 @@ public class StatementGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Statement convert(Java8Parser.WhileStatementNoShortIfContext stmt){
|
private Statement convert(Java8Parser.WhileStatementNoShortIfContext stmt){
|
||||||
//TODO
|
Expression expr = convert(stmt.expression());
|
||||||
throw new NotImplementedException();
|
Statement block = convert(stmt.statementNoShortIf());
|
||||||
|
return new WhileStmt(expr, block, stmt.getStart());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Statement convert(Java8Parser.DoStatementContext stmt){
|
private Statement convert(Java8Parser.DoStatementContext stmt){
|
||||||
@ -368,13 +375,41 @@ public class StatementGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Statement convert(Java8Parser.BasicForStatementContext stmt){
|
private Statement convert(Java8Parser.BasicForStatementContext stmt){
|
||||||
//TODO
|
List<Statement> stateList = new ArrayList<>();
|
||||||
throw new NotImplementedException();
|
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){
|
private Statement convert(Java8Parser.BasicForStatementNoShortIfContext stmt){
|
||||||
//TODO
|
List<Statement> stateList = new ArrayList<>();
|
||||||
throw new NotImplementedException();
|
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){
|
private List<Statement> convert(Java8Parser.ForInitContext stmt){
|
||||||
@ -456,8 +491,11 @@ public class StatementGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Statement convert(Java8Parser.BreakStatementContext stmt){
|
private Statement convert(Java8Parser.BreakStatementContext stmt){
|
||||||
//TODO
|
if (stmt.Identifier()!=null)
|
||||||
throw new NotImplementedException();
|
{
|
||||||
|
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){
|
private Statement convert(Java8Parser.ContinueStatementContext stmt){
|
||||||
|
@ -15,8 +15,8 @@ public class SyntacticSugar {
|
|||||||
//TODO
|
//TODO
|
||||||
//if (hasReturn(((WhileStmt) lastStmt).loopBlock)) return statements;
|
//if (hasReturn(((WhileStmt) lastStmt).loopBlock)) return statements;
|
||||||
} else if (lastStmt instanceof IfStmt) {
|
} else if (lastStmt instanceof IfStmt) {
|
||||||
if (hasReturn(((IfStmt) lastStmt).then_block)
|
//if (hasReturn(((IfStmt) lastStmt).then_block)
|
||||||
&& hasReturn(((IfStmt) lastStmt).else_block)) return statements;
|
//&& hasReturn(((IfStmt) lastStmt).else_block)) return statements;
|
||||||
} else if (lastStmt instanceof ForStmt) {
|
} else if (lastStmt instanceof ForStmt) {
|
||||||
if (hasReturn(((ForStmt) lastStmt).body_Loop_block)) return statements;
|
if (hasReturn(((ForStmt) lastStmt).body_Loop_block)) return statements;
|
||||||
} else {
|
} else {
|
||||||
|
@ -11,11 +11,11 @@ import org.antlr.v4.runtime.Token;
|
|||||||
public class IfStmt extends Statement
|
public class IfStmt extends Statement
|
||||||
{
|
{
|
||||||
public final Expression expr;
|
public final Expression expr;
|
||||||
public final Block then_block;
|
public final Statement then_block;
|
||||||
public final Block else_block;
|
public final Statement else_block;
|
||||||
|
|
||||||
public IfStmt(RefTypeOrTPHOrWildcardOrGeneric type,
|
public IfStmt(RefTypeOrTPHOrWildcardOrGeneric type,
|
||||||
Expression expr, Block thenBlock, Block elseBlock, Token offset)
|
Expression expr, Statement thenBlock, Statement elseBlock, Token offset)
|
||||||
{
|
{
|
||||||
super(type,offset);
|
super(type,offset);
|
||||||
this.expr = expr;
|
this.expr = expr;
|
||||||
@ -23,6 +23,7 @@ public class IfStmt extends Statement
|
|||||||
this.else_block = elseBlock;
|
this.else_block = elseBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(StatementVisitor visitor) {
|
public void accept(StatementVisitor visitor) {
|
||||||
visitor.visit(this);
|
visitor.visit(this);
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
class WhileTest{
|
class WhileTest
|
||||||
|
{
|
||||||
void methode(){
|
void methode(){
|
||||||
Boolean test;
|
Boolean test;
|
||||||
do{
|
do
|
||||||
|
{
|
||||||
test=test;
|
test=test;
|
||||||
}while(test);
|
}while(test);
|
||||||
|
|
||||||
|
@ -20,14 +20,14 @@ import java.util.Set;
|
|||||||
|
|
||||||
public class JavaTXCompilerTest extends JavaTXCompiler {
|
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<>();
|
private static final List<File> filesToTest = new ArrayList<>();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() throws IOException, java.lang.ClassNotFoundException {
|
public void test() throws IOException, java.lang.ClassNotFoundException {
|
||||||
//filesToTest.add(new File(rootDirectory+"Faculty.jav"));
|
//filesToTest.add(new File(rootDirectory+"Faculty.jav"));
|
||||||
//filesToTest.add(new File(rootDirectory+"mathStruc.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+"Lambda.jav"));
|
||||||
//filesToTest.add(new File(rootDirectory+"Lambda2.jav"));
|
//filesToTest.add(new File(rootDirectory+"Lambda2.jav"));
|
||||||
//filesToTest.add(new File(rootDirectory+"Lambda3.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+"MethodsEasy.jav"));
|
||||||
//filesToTest.add(new File(rootDirectory+"Matrix.jav"));
|
//filesToTest.add(new File(rootDirectory+"Matrix.jav"));
|
||||||
//filesToTest.add(new File(rootDirectory+"Import.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){
|
for(File f : filesToTest){
|
||||||
SourceFile sf = this.parse(f);
|
SourceFile sf = this.parse(f);
|
||||||
System.out.println(ASTTypePrinter.print(this.sourceFiles.get(sourceFiles.size()-1)));
|
System.out.println(ASTTypePrinter.print(this.sourceFiles.get(sourceFiles.size()-1)));
|
||||||
|
|
||||||
|
/*
|
||||||
for(ResultSet resultSet : this.typeInference()){
|
for(ResultSet resultSet : this.typeInference()){
|
||||||
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet);
|
Set<TypeInsert> result = TypeInsertFactory.createTypeInsertPoints(sf, resultSet);
|
||||||
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
|
String content = readFile(f.getPath(), StandardCharsets.UTF_8);
|
||||||
@ -46,6 +50,7 @@ public class JavaTXCompilerTest extends JavaTXCompiler {
|
|||||||
System.out.println(tip.insert(content));
|
System.out.println(tip.insert(content));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user