Implemented Continue, Catches, Break visit ...

This commit is contained in:
FelixKrespach 2017-09-22 18:19:34 +02:00
parent 881830235a
commit 07303ffa71
15 changed files with 74 additions and 31 deletions

View File

@ -269,24 +269,19 @@ public class StatementGenerator {
}
private Statement convert(Java8Parser.PreIncrementExpressionContext stmt) {
//TODO
throw new NotImplementedException();
return new PreIncExpr(convert(stmt.unaryExpression()),stmt.getStart());
}
private Statement convert(Java8Parser.PreDecrementExpressionContext stmt) {
//TODO
throw new NotImplementedException();
return new PreDecExpr(convert(stmt.unaryExpression()),stmt.getStart());
}
private Statement convert(Java8Parser.PostIncrementExpressionContext stmt) {
Expression expr = convert(stmt.postfixExpression());
//TODO
throw new NotImplementedException();
return new PostIncExpr(convert(stmt.postfixExpression()));
}
private Statement convert(Java8Parser.PostDecrementExpressionContext stmt) {
//TODO
throw new NotImplementedException();
return new PostDecExpr(convert(stmt.postfixExpression()));
}
private Statement convert(Java8Parser.AssignmentContext stmt) {
@ -341,7 +336,7 @@ public class StatementGenerator {
}
private Statement convert(Java8Parser.SwitchStatementContext stmt){
//TODO
//TODO Felix K
throw new NotImplementedException();
}
@ -506,16 +501,20 @@ public class StatementGenerator {
}
private Statement convert(Java8Parser.BreakStatementContext stmt){
if (stmt.Identifier()!=null)
if (stmt.Identifier()==null)
{
new BreakStmt(TypePlaceholder.fresh(stmt.getStart()),stmt.Identifier(),stmt.getStart());
String indentifier = "";
return new BreakStmt(TypePlaceholder.fresh(stmt.getStart()),indentifier,stmt.getStart());
}
return new BreakStmt(TypePlaceholder.fresh(stmt.getStart()),stmt.Identifier(),stmt.getStart());
return new BreakStmt(TypePlaceholder.fresh(stmt.getStart()),stmt.Identifier().getText(),stmt.getStart());
}
private Statement convert(Java8Parser.ContinueStatementContext stmt){
//TODO
throw new NotImplementedException();
if (stmt.Identifier()==null){
String indentifier = "";
return new ContinueStmt(TypePlaceholder.fresh(stmt.getStart()),indentifier, stmt.getStart());
}
return new BreakStmt(TypePlaceholder.fresh(stmt.getStart()),stmt.Identifier().getText(),stmt.getStart());
}
private Statement convert(Java8Parser.ReturnStatementContext stmt){
@ -541,7 +540,8 @@ public class StatementGenerator {
throw new NotImplementedException();
}
private Statement convert(Java8Parser.CatchesContext stmt){
private Statement convert(Java8Parser.CatchesContext stmt)
{
//TODO
throw new NotImplementedException();
}

View File

@ -35,4 +35,6 @@ public interface ASTVisitor extends StatementVisitor{
void visit(ExtendsWildcardType extendsWildcardType);
void visit(GenericRefType genericRefType);
void visit(BreakStmt breakStmt);
}

View File

@ -268,4 +268,8 @@ public abstract class AbstractASTWalker implements ASTVisitor{
public void visit(SuperCall superCall) {
this.visit((MethodCall)superCall);
}
@Override
public void visit(BreakStmt breakStmt) {
}
}

View File

@ -18,6 +18,8 @@ public interface StatementVisitor {
void visit(Block block);
void visit(BreakStmt breakStmt);
void visit(CastExpr castExpr);
void visit(EmptyStmt emptyStmt);

View File

@ -11,14 +11,15 @@ import org.antlr.v4.runtime.tree.TerminalNode;
*/
public class BreakStmt extends Statement
{
public final TerminalNode indentifier;
public final String indentifier;
public BreakStmt(RefTypeOrTPHOrWildcardOrGeneric type, TerminalNode Indentifier, Token offset)
public BreakStmt(RefTypeOrTPHOrWildcardOrGeneric type, String Indentifier, Token offset)
{
super(type, offset);
this.indentifier=Indentifier;
}
@Override
public void accept(StatementVisitor visitor) {
visitor.visit(this);
}
}

View File

@ -1,9 +1,15 @@
package de.dhbwstuttgart.syntaxtree.statement;
import java.util.List;
/**
* Created by Felix_K on 21.09.2017.
*/
public class CatchesStatement
{
final List<Statement> catchClauses;
public CatchesStatement(List<Statement> catches)
{
catchClauses = catches;
}
}

View File

@ -0,0 +1,14 @@
package de.dhbwstuttgart.syntaxtree.statement;
import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import org.antlr.v4.runtime.Token;
/**
* Created by Felix_K on 22.09.2017.
*/
public class ContinueStmt extends BreakStmt {
public ContinueStmt(RefTypeOrTPHOrWildcardOrGeneric type, String indent, Token offset){
super(type, indent, offset);
}
}

View File

@ -12,8 +12,10 @@ import org.apache.bcel.generic.InstructionList;
public class PreDecExpr extends UnaryExpr
{
public PreDecExpr(Token offset)
Expression expr;
public PreDecExpr(Expression expr, Token offset)
{
super(offset);
this.expr=expr;
}
}

View File

@ -5,8 +5,10 @@ import org.antlr.v4.runtime.Token;
public class PreIncExpr extends UnaryExpr
{
public PreIncExpr(Token offset)
final Expression expr;
public PreIncExpr(Expression expr,Token offset)
{
super(offset);
this.expr=expr;
}
}

View File

@ -209,6 +209,12 @@ public class OutputGenerator implements ASTVisitor {
out.append("}");
}
@Override
public void visit(BreakStmt breakStmt)
{
out.append("break" + breakStmt.indentifier+";");
}
@Override
public void visit(CastExpr castExpr) {
@ -235,7 +241,7 @@ public class OutputGenerator implements ASTVisitor {
out.append("if");
ifStmt.expr.accept(this);
ifStmt.then_block.accept(this);
out.append("\nelse");
out.append("else");
ifStmt.else_block.accept(this);
//TODO Felix_K

View File

@ -1,6 +1,8 @@
package de.dhbwstuttgart.typedeployment;
import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.syntaxtree.statement.BreakStmt;
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.result.ResultSet;
@ -70,4 +72,5 @@ class TypeInsertPlacerClass extends AbstractASTWalker{
public void visit(LambdaExpression lambdaExpression) {
//Lambda-Ausdrücke brauchen keine Typeinsetzungen
}
}

View File

@ -87,6 +87,8 @@ public class TYPEStmt implements StatementVisitor{
stmt.accept(this);
}
}
@Override
public void visit(BreakStmt breakStmt){throw new NotImplementedException();}
@Override
public void visit(CastExpr castExpr) {

View File

@ -2,8 +2,6 @@ class BreakTest
{
void methode()
{
break;
break BREAKTEST;
}
}

View File

@ -2,11 +2,10 @@ class WhileTest
{
void methode()
{
Boolean test;
Boolean BoolTrue=true;
do
{
test=test;
}while(test);
}while(testTrue);
while(test)

View File

@ -2,7 +2,9 @@ package typeinference;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
import de.dhbwstuttgart.syntaxtree.visual.OutputGenerator;
import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
import de.dhbwstuttgart.typeinference.result.ResultSet;
@ -36,12 +38,12 @@ 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+"BreakTest.jav"));
filesToTest.add(new File(rootDirectory+"WhileTest.jav"));
filesToTest.add(new File(rootDirectory+"IfTest.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(ASTPrinter.print(this.sourceFiles.get(sourceFiles.size()-1)));
System.out.println("-----------------------------------------------------------------------------------");
/*
for(ResultSet resultSet : this.typeInference()){