forked from JavaTX/JavaCompilerCore
Compare commits
9 Commits
targetByte
...
antlr2
Author | SHA1 | Date | |
---|---|---|---|
|
998c146f4b | ||
|
88c78342d5 | ||
|
86b2118770 | ||
|
03080c43cb | ||
|
df1c19e60d | ||
|
07303ffa71 | ||
|
881830235a | ||
|
b88b9e2534 | ||
|
8e1c1765ff |
@ -1,5 +1,6 @@
|
|||||||
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||||
|
|
||||||
|
import com.sun.javafx.fxml.expression.UnaryExpression;
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
||||||
@ -266,25 +267,21 @@ public class StatementGenerator {
|
|||||||
//TODO
|
//TODO
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
//TODO Felix_K
|
||||||
private Statement convert(Java8Parser.PreIncrementExpressionContext stmt) {
|
private Statement convert(Java8Parser.PreIncrementExpressionContext stmt) {
|
||||||
//TODO
|
return new PreIncExpr(convert(stmt.unaryExpression()),stmt.getStart());
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
}
|
||||||
|
//TODO Felix_K
|
||||||
private Statement convert(Java8Parser.PreDecrementExpressionContext stmt) {
|
private Statement convert(Java8Parser.PreDecrementExpressionContext stmt) {
|
||||||
//TODO
|
return new PreDecExpr(convert(stmt.unaryExpression()),stmt.getStart());
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
}
|
||||||
|
//TODO Felix_K
|
||||||
private Statement convert(Java8Parser.PostIncrementExpressionContext stmt) {
|
private Statement convert(Java8Parser.PostIncrementExpressionContext stmt) {
|
||||||
//TODO
|
return new PostIncExpr(convert(stmt.postfixExpression()));
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
}
|
||||||
|
//TODO Felix_K
|
||||||
private Statement convert(Java8Parser.PostDecrementExpressionContext stmt) {
|
private Statement convert(Java8Parser.PostDecrementExpressionContext stmt) {
|
||||||
//TODO
|
return new PostDecExpr(convert(stmt.postfixExpression()));
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Statement convert(Java8Parser.AssignmentContext stmt) {
|
private Statement convert(Java8Parser.AssignmentContext stmt) {
|
||||||
@ -298,35 +295,50 @@ public class StatementGenerator {
|
|||||||
else if (leftSide instanceof LocalVar)return new AssignToLocal((LocalVar) leftSide);
|
else if (leftSide instanceof LocalVar)return new AssignToLocal((LocalVar) leftSide);
|
||||||
else throw new NotImplementedException();
|
else throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
//TODO Felix_K
|
||||||
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());
|
||||||
}
|
}
|
||||||
|
//TODO Felix_K
|
||||||
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());
|
||||||
}
|
}
|
||||||
|
//TODO Felix_K
|
||||||
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());
|
||||||
}
|
}
|
||||||
|
//TODO Felix_K
|
||||||
private Statement convert(Java8Parser.AssertStatementContext stmt){
|
private Statement convert(Java8Parser.AssertStatementContext stmt)
|
||||||
//TODO
|
{
|
||||||
throw new NotImplementedException();
|
List<Expression> exprList= new ArrayList<Expression>();
|
||||||
|
for (int i =0; i<stmt.expression().size();i++){
|
||||||
|
exprList.add(convert(stmt.expression(i)));
|
||||||
|
}
|
||||||
|
return new AssertStmt(TypePlaceholder.fresh(stmt.getStart()),exprList,stmt.getStart());
|
||||||
}
|
}
|
||||||
|
//TODO Felix_K
|
||||||
private Statement convert(Java8Parser.SwitchStatementContext stmt){
|
private Statement convert(Java8Parser.SwitchStatementContext stmt){
|
||||||
//TODO
|
Expression expr = convert(stmt.expression());
|
||||||
throw new NotImplementedException();
|
List<Statement> statementList = new ArrayList<Statement>();
|
||||||
|
statementList.add( convert(stmt.switchBlock()));
|
||||||
|
statementList.add(new BreakStmt(TypePlaceholder.fresh(stmt.getStart()),"",stmt.getStart()));
|
||||||
|
Block block = new Block(statementList, stmt.getStart());
|
||||||
|
return new SwitchStmt(TypePlaceholder.fresh(stmt.getStart()),expr,block,stmt.getStart());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Statement convert(Java8Parser.SwitchBlockContext stmt){
|
private Statement convert(Java8Parser.SwitchBlockContext stmt){
|
||||||
//TODO
|
//TODO
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Statement convert(Java8Parser.SwitchBlockStatementGroupContext stmt){
|
private Statement convert(Java8Parser.SwitchBlockStatementGroupContext stmt){
|
||||||
@ -339,12 +351,13 @@ public class StatementGenerator {
|
|||||||
Statement block = convert(stmt.statement());
|
Statement block = convert(stmt.statement());
|
||||||
return new WhileStmt(expr, block,stmt.getStart());
|
return new WhileStmt(expr, block,stmt.getStart());
|
||||||
}
|
}
|
||||||
|
//TODO Felix_K
|
||||||
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());
|
||||||
}
|
}
|
||||||
|
//TODO Felix_K
|
||||||
private Statement convert(Java8Parser.DoStatementContext stmt){
|
private Statement convert(Java8Parser.DoStatementContext stmt){
|
||||||
Statement block = convert(stmt.statement());
|
Statement block = convert(stmt.statement());
|
||||||
Expression expr = convert(stmt.expression());
|
Expression expr = convert(stmt.expression());
|
||||||
@ -366,15 +379,43 @@ public class StatementGenerator {
|
|||||||
return convert(stmt.enhancedForStatementNoShortIf());
|
return convert(stmt.enhancedForStatementNoShortIf());
|
||||||
}else throw new NotImplementedException();
|
}else throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
//TODO Felix_K
|
||||||
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());
|
||||||
}
|
}
|
||||||
|
//TODO Felix_K
|
||||||
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){
|
||||||
@ -384,7 +425,7 @@ public class StatementGenerator {
|
|||||||
return convert(stmt.localVariableDeclaration());
|
return convert(stmt.localVariableDeclaration());
|
||||||
}else throw new NotImplementedException();
|
}else throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
//TODO Felix_K
|
||||||
private List<Statement> convert(Java8Parser.LocalVariableDeclarationContext declaration) {
|
private List<Statement> convert(Java8Parser.LocalVariableDeclarationContext declaration) {
|
||||||
List<Statement> ret = new ArrayList<>();
|
List<Statement> ret = new ArrayList<>();
|
||||||
if(declaration.variableModifier() != null && declaration.variableModifier().size() > 0){
|
if(declaration.variableModifier() != null && declaration.variableModifier().size() > 0){
|
||||||
@ -454,15 +495,22 @@ public class StatementGenerator {
|
|||||||
//TODO
|
//TODO
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
//TODO Felix_K
|
||||||
private Statement convert(Java8Parser.BreakStatementContext stmt){
|
private Statement convert(Java8Parser.BreakStatementContext stmt){
|
||||||
//TODO
|
if (stmt.Identifier()==null)
|
||||||
throw new NotImplementedException();
|
{
|
||||||
|
String indentifier = "";
|
||||||
|
return new BreakStmt(TypePlaceholder.fresh(stmt.getStart()),indentifier,stmt.getStart());
|
||||||
|
}
|
||||||
|
return new BreakStmt(TypePlaceholder.fresh(stmt.getStart()),stmt.Identifier().getText(),stmt.getStart());
|
||||||
}
|
}
|
||||||
|
//TODO Felix_K
|
||||||
private Statement convert(Java8Parser.ContinueStatementContext stmt){
|
private Statement convert(Java8Parser.ContinueStatementContext stmt){
|
||||||
//TODO
|
if (stmt.Identifier()==null){
|
||||||
throw new NotImplementedException();
|
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){
|
private Statement convert(Java8Parser.ReturnStatementContext stmt){
|
||||||
@ -488,7 +536,8 @@ public class StatementGenerator {
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Statement convert(Java8Parser.CatchesContext stmt){
|
private Statement convert(Java8Parser.CatchesContext stmt)
|
||||||
|
{
|
||||||
//TODO
|
//TODO
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
||||||
|
@ -35,4 +35,6 @@ public interface ASTVisitor extends StatementVisitor{
|
|||||||
void visit(ExtendsWildcardType extendsWildcardType);
|
void visit(ExtendsWildcardType extendsWildcardType);
|
||||||
|
|
||||||
void visit(GenericRefType genericRefType);
|
void visit(GenericRefType genericRefType);
|
||||||
|
|
||||||
|
void visit(BreakStmt breakStmt);
|
||||||
}
|
}
|
||||||
|
@ -268,4 +268,8 @@ public abstract class AbstractASTWalker implements ASTVisitor{
|
|||||||
public void visit(SuperCall superCall) {
|
public void visit(SuperCall superCall) {
|
||||||
this.visit((MethodCall)superCall);
|
this.visit((MethodCall)superCall);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(BreakStmt breakStmt) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,8 @@ public interface StatementVisitor {
|
|||||||
|
|
||||||
void visit(Block block);
|
void visit(Block block);
|
||||||
|
|
||||||
|
void visit(BreakStmt breakStmt);
|
||||||
|
|
||||||
void visit(CastExpr castExpr);
|
void visit(CastExpr castExpr);
|
||||||
|
|
||||||
void visit(EmptyStmt emptyStmt);
|
void visit(EmptyStmt emptyStmt);
|
||||||
|
24
src/de/dhbwstuttgart/syntaxtree/statement/AssertStmt.java
Normal file
24
src/de/dhbwstuttgart/syntaxtree/statement/AssertStmt.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
package de.dhbwstuttgart.syntaxtree.statement;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Felix_K on 21.09.2017.
|
||||||
|
*/
|
||||||
|
public class AssertStmt extends Statement
|
||||||
|
{
|
||||||
|
public final List<Expression> expr;
|
||||||
|
public AssertStmt(RefTypeOrTPHOrWildcardOrGeneric type, List<Expression> expr, Token offset){
|
||||||
|
super(type, offset);
|
||||||
|
this.expr=expr;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(StatementVisitor visitor) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
25
src/de/dhbwstuttgart/syntaxtree/statement/BreakStmt.java
Normal file
25
src/de/dhbwstuttgart/syntaxtree/statement/BreakStmt.java
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package de.dhbwstuttgart.syntaxtree.statement;
|
||||||
|
|
||||||
|
import com.sun.scenario.effect.Offset;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
import org.antlr.v4.runtime.Token;
|
||||||
|
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Felix_K on 20.09.2017.
|
||||||
|
*/
|
||||||
|
public class BreakStmt extends Statement
|
||||||
|
{
|
||||||
|
public final String indentifier;
|
||||||
|
|
||||||
|
public BreakStmt(RefTypeOrTPHOrWildcardOrGeneric type, String Indentifier, Token offset)
|
||||||
|
{
|
||||||
|
super(type, offset);
|
||||||
|
this.indentifier=Indentifier;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void accept(StatementVisitor visitor) {
|
||||||
|
visitor.visit(this);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +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;
|
||||||
|
}
|
||||||
|
}
|
14
src/de/dhbwstuttgart/syntaxtree/statement/ContinueStmt.java
Normal file
14
src/de/dhbwstuttgart/syntaxtree/statement/ContinueStmt.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
@ -3,6 +3,7 @@ import java.util.Hashtable;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
||||||
|
import org.antlr.v4.runtime.Token;
|
||||||
import org.apache.bcel.generic.ClassGen;
|
import org.apache.bcel.generic.ClassGen;
|
||||||
import org.apache.bcel.generic.InstructionList;
|
import org.apache.bcel.generic.InstructionList;
|
||||||
|
|
||||||
|
@ -4,12 +4,15 @@ import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
|||||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
|
|
||||||
public class PostIncExpr extends UnaryExpr
|
public class PostIncExpr extends UnaryExpr
|
||||||
{
|
{
|
||||||
|
final Expression expr;
|
||||||
public PostIncExpr(Expression expr) {
|
public PostIncExpr(Expression expr) {
|
||||||
super(null);
|
super(null);
|
||||||
|
this.expr=expr;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,10 @@ import org.apache.bcel.generic.InstructionList;
|
|||||||
|
|
||||||
public class PreDecExpr extends UnaryExpr
|
public class PreDecExpr extends UnaryExpr
|
||||||
{
|
{
|
||||||
public PreDecExpr(Token offset)
|
Expression expr;
|
||||||
|
public PreDecExpr(Expression expr, Token offset)
|
||||||
{
|
{
|
||||||
super(offset);
|
super(offset);
|
||||||
|
this.expr=expr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,10 @@ import org.antlr.v4.runtime.Token;
|
|||||||
|
|
||||||
public class PreIncExpr extends UnaryExpr
|
public class PreIncExpr extends UnaryExpr
|
||||||
{
|
{
|
||||||
public PreIncExpr(Token offset)
|
final Expression expr;
|
||||||
|
public PreIncExpr(Expression expr,Token offset)
|
||||||
{
|
{
|
||||||
super(offset);
|
super(offset);
|
||||||
|
this.expr=expr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
24
src/de/dhbwstuttgart/syntaxtree/statement/SwitchStmt.java
Normal file
24
src/de/dhbwstuttgart/syntaxtree/statement/SwitchStmt.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
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 23.09.2017.
|
||||||
|
*/
|
||||||
|
public class SwitchStmt extends Statement
|
||||||
|
{
|
||||||
|
public final Expression expr;
|
||||||
|
public final Block switchBlock;
|
||||||
|
|
||||||
|
public SwitchStmt(RefTypeOrTPHOrWildcardOrGeneric type,Expression expr, Block block, Token offset){
|
||||||
|
super(type,offset);
|
||||||
|
this.expr=expr;
|
||||||
|
this.switchBlock=block;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void accept(StatementVisitor visitor) {
|
||||||
|
}
|
||||||
|
}
|
@ -209,6 +209,12 @@ public class OutputGenerator implements ASTVisitor {
|
|||||||
out.append("}");
|
out.append("}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(BreakStmt breakStmt)
|
||||||
|
{
|
||||||
|
out.append("break"+ " " + breakStmt.indentifier);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(CastExpr castExpr) {
|
public void visit(CastExpr castExpr) {
|
||||||
|
|
||||||
@ -232,7 +238,15 @@ public class OutputGenerator implements ASTVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(IfStmt ifStmt) {
|
public void visit(IfStmt ifStmt) {
|
||||||
|
out.append("if (");
|
||||||
|
ifStmt.expr.accept(this);
|
||||||
|
out.append(")");
|
||||||
|
//TODO implement to set ; if then block is empty
|
||||||
|
ifStmt.then_block.accept(this);
|
||||||
|
out.append("else");
|
||||||
|
ifStmt.else_block.accept(this);
|
||||||
|
|
||||||
|
//TODO Felix_K
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package de.dhbwstuttgart.typedeployment;
|
package de.dhbwstuttgart.typedeployment;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.syntaxtree.*;
|
import de.dhbwstuttgart.syntaxtree.*;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.BreakStmt;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
@ -70,4 +72,5 @@ class TypeInsertPlacerClass extends AbstractASTWalker{
|
|||||||
public void visit(LambdaExpression lambdaExpression) {
|
public void visit(LambdaExpression lambdaExpression) {
|
||||||
//Lambda-Ausdrücke brauchen keine Typeinsetzungen
|
//Lambda-Ausdrücke brauchen keine Typeinsetzungen
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -87,6 +87,8 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
stmt.accept(this);
|
stmt.accept(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public void visit(BreakStmt breakStmt){throw new NotImplementedException();}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(CastExpr castExpr) {
|
public void visit(CastExpr castExpr) {
|
||||||
|
7
test/parser/AssertTest.jav
Normal file
7
test/parser/AssertTest.jav
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
class AssertTest
|
||||||
|
{
|
||||||
|
void assertMethod()
|
||||||
|
{
|
||||||
|
assert true;
|
||||||
|
}
|
||||||
|
}
|
7
test/parser/BreakTest.jav
Normal file
7
test/parser/BreakTest.jav
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
class BreakTest
|
||||||
|
{
|
||||||
|
void methode()
|
||||||
|
{
|
||||||
|
break BREAKTEST;
|
||||||
|
}
|
||||||
|
}
|
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
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
test/parser/PrePostOperationTest.jav
Normal file
10
test/parser/PrePostOperationTest.jav
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
class TestClass
|
||||||
|
{
|
||||||
|
void testMethod()
|
||||||
|
{
|
||||||
|
//++i;
|
||||||
|
//i++;
|
||||||
|
//--i;
|
||||||
|
//i--;
|
||||||
|
}
|
||||||
|
}
|
11
test/parser/SwitchTest.jav
Normal file
11
test/parser/SwitchTest.jav
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
public class SwitchTest
|
||||||
|
{
|
||||||
|
void testMethod()
|
||||||
|
{
|
||||||
|
switch(i)
|
||||||
|
{
|
||||||
|
case i:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
test/parser/TryCatchTest.jav
Normal file
14
test/parser/TryCatchTest.jav
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
class TryCatchTest
|
||||||
|
{
|
||||||
|
public void TryTest()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
catch()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,14 +1,16 @@
|
|||||||
class WhileTest{
|
class WhileTest
|
||||||
void methode(){
|
{
|
||||||
Boolean test;
|
void methode()
|
||||||
do{
|
{
|
||||||
test=test;
|
Boolean boolVar=true;
|
||||||
}while(test);
|
do
|
||||||
|
{
|
||||||
|
}while(boolVar);
|
||||||
|
|
||||||
|
|
||||||
while(test){
|
while(boolVar)
|
||||||
test = test;
|
{
|
||||||
}
|
test = test;
|
||||||
return;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,7 +2,9 @@ package typeinference;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||||
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.visual.OutputGenerator;
|
||||||
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
import de.dhbwstuttgart.typedeployment.TypeInsert;
|
||||||
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
@ -20,14 +22,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 +38,20 @@ 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"));
|
||||||
|
//filesToTest.add(new File(rootDirectory+"IfTest.jav"));
|
||||||
|
filesToTest.add(new File(rootDirectory+"AssertTest.jav"));
|
||||||
|
//filesToTest.add(new File(rootDirectory+"PrePostOperationTest.jav"));
|
||||||
|
//filesToTest.add(new File(rootDirectory+"SwitchTest.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("-------------------------------------|"+f.getName()+"|----------------------------------------------");
|
||||||
|
System.out.println(ASTPrinter.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 +59,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