From 027538a0829f02d4d20103075ac735a702314f6a Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Tue, 30 Jan 2018 01:08:21 +0100 Subject: [PATCH] =?UTF-8?q?Unary=20Expression=20und=20while=20statement=20?= =?UTF-8?q?anf=C3=BCgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../syntaxtree/statement/NegativeExpr.html | 2 +- .../syntaxtree/statement/NotExpr.html | 2 +- .../syntaxtree/statement/PositivExpr.html | 2 +- .../syntaxtree/statement/PostDecExpr.html | 2 +- .../syntaxtree/statement/PostIncExpr.html | 2 +- .../syntaxtree/statement/PreDecExpr.html | 2 +- .../syntaxtree/statement/PreIncExpr.html | 2 +- .../statement/class-use/NegativeExpr.html | 6 +- .../statement/class-use/NotExpr.html | 6 +- .../statement/class-use/PositivExpr.html | 6 +- .../statement/class-use/PostDecExpr.html | 6 +- .../statement/class-use/PostIncExpr.html | 6 +- .../statement/class-use/PreDecExpr.html | 6 +- .../statement/class-use/PreIncExpr.html | 6 +- .../dhbwstuttgart/bytecode/BytecodeGen.java | 12 ++-- .../bytecode/BytecodeGenMethod.java | 11 +-- .../dhbwstuttgart/bytecode/KindOfLambda.java | 12 ++-- .../StatementGenerator.java | 27 ++++--- .../SyntaxTreeGenerator/SyntacticSugar.java | 30 +++++--- .../SyntaxTreeGenerator/TypeGenerator.java | 7 +- .../syntaxtree/AbstractASTWalker.java | 11 +-- .../syntaxtree/StatementVisitor.java | 4 +- .../syntaxtree/factory/ASTFactory.java | 2 +- .../syntaxtree/statement/IfStmt.java | 6 +- .../statement/JavaInternalExpression.java | 12 ++++ .../syntaxtree/statement/NegativeExpr.java | 18 ----- .../syntaxtree/statement/NotExpr.java | 14 ---- .../syntaxtree/statement/PositivExpr.java | 15 ---- .../syntaxtree/statement/PostDecExpr.java | 17 ----- .../syntaxtree/statement/PostIncExpr.java | 15 ---- .../syntaxtree/statement/PreDecExpr.java | 17 ----- .../syntaxtree/statement/PreIncExpr.java | 12 ---- .../syntaxtree/statement/UnaryExpr.java | 29 +++++++- .../syntaxtree/statement/UnaryMinus.java | 12 ---- .../syntaxtree/statement/UnaryNot.java | 7 -- .../syntaxtree/statement/UnaryPlus.java | 20 ------ .../syntaxtree/visual/OutputGenerator.java | 10 +-- .../visual/TypeOutputGenerator.java | 5 -- .../typedeployment/TypeInsertPlacer.java | 2 + .../typeinference/typeAlgo/TYPEStmt.java | 28 ++++++-- test/javFiles/Matrix.jav | 70 ++++++------------- 41 files changed, 187 insertions(+), 294 deletions(-) create mode 100644 src/de/dhbwstuttgart/syntaxtree/statement/JavaInternalExpression.java delete mode 100644 src/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.java delete mode 100644 src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java delete mode 100644 src/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.java delete mode 100644 src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java delete mode 100644 src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java delete mode 100644 src/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.java delete mode 100644 src/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.java delete mode 100644 src/de/dhbwstuttgart/syntaxtree/statement/UnaryMinus.java delete mode 100644 src/de/dhbwstuttgart/syntaxtree/statement/UnaryNot.java delete mode 100644 src/de/dhbwstuttgart/syntaxtree/statement/UnaryPlus.java diff --git a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.html b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.html index 274fb17d4..7ddcc7466 100644 --- a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.html +++ b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.html @@ -115,7 +115,7 @@ var activeTableTab = "activeTableTab";
  • de.dhbwstuttgart.syntaxtree.statement.UnaryExpr
  • diff --git a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/NotExpr.html b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/NotExpr.html index d59ab82bc..1eb88e1d6 100644 --- a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/NotExpr.html +++ b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/NotExpr.html @@ -115,7 +115,7 @@ var activeTableTab = "activeTableTab";
  • de.dhbwstuttgart.syntaxtree.statement.UnaryExpr
  • diff --git a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.html b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.html index 6dfdb37bc..e02874de6 100644 --- a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.html +++ b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.html @@ -115,7 +115,7 @@ var activeTableTab = "activeTableTab";
  • de.dhbwstuttgart.syntaxtree.statement.UnaryExpr
  • diff --git a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.html b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.html index 86c5a8fa3..9c293c667 100644 --- a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.html +++ b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.html @@ -115,7 +115,7 @@ var activeTableTab = "activeTableTab";
  • de.dhbwstuttgart.syntaxtree.statement.UnaryExpr
  • diff --git a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.html b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.html index 94b06b129..4d52f3996 100644 --- a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.html +++ b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.html @@ -115,7 +115,7 @@ var activeTableTab = "activeTableTab";
  • de.dhbwstuttgart.syntaxtree.statement.UnaryExpr
  • diff --git a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.html b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.html index 47989bf28..3027535ed 100644 --- a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.html +++ b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.html @@ -115,7 +115,7 @@ var activeTableTab = "activeTableTab";
  • de.dhbwstuttgart.syntaxtree.statement.UnaryExpr
  • diff --git a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.html b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.html index 437a143fd..e2caa4bd8 100644 --- a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.html +++ b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.html @@ -115,7 +115,7 @@ var activeTableTab = "activeTableTab";
  • de.dhbwstuttgart.syntaxtree.statement.UnaryExpr
  • diff --git a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/NegativeExpr.html b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/NegativeExpr.html index beb55c1f2..6e30f09e8 100644 --- a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/NegativeExpr.html +++ b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/NegativeExpr.html @@ -3,7 +3,7 @@ -Uses of Class de.dhbwstuttgart.syntaxtree.statement.NegativeExpr +Uses of Class de.dhbwstuttgart.syntaxtree.statement.javaInternal.NegativeExpr @@ -70,9 +70,9 @@
    -

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.NegativeExpr

    +

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.NegativeExpr

    -
    No usage of de.dhbwstuttgart.syntaxtree.statement.NegativeExpr
    +
    No usage of de.dhbwstuttgart.syntaxtree.statement.javaInternal.NegativeExpr
    diff --git a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/NotExpr.html b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/NotExpr.html index 0ebf95847..27253c0f8 100644 --- a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/NotExpr.html +++ b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/NotExpr.html @@ -3,7 +3,7 @@ -Uses of Class de.dhbwstuttgart.syntaxtree.statement.NotExpr +Uses of Class de.dhbwstuttgart.syntaxtree.statement.javaInternal.NotExpr @@ -70,9 +70,9 @@
    -

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.NotExpr

    +

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.NotExpr

    -
    No usage of de.dhbwstuttgart.syntaxtree.statement.NotExpr
    +
    No usage of de.dhbwstuttgart.syntaxtree.statement.javaInternal.NotExpr
    diff --git a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/PositivExpr.html b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/PositivExpr.html index 6694e69df..91ed2bf91 100644 --- a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/PositivExpr.html +++ b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/PositivExpr.html @@ -3,7 +3,7 @@ -Uses of Class de.dhbwstuttgart.syntaxtree.statement.PositivExpr +Uses of Class de.dhbwstuttgart.syntaxtree.statement.javaInternal.PositivExpr @@ -70,9 +70,9 @@
    -

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.PositivExpr

    +

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.PositivExpr

    -
    No usage of de.dhbwstuttgart.syntaxtree.statement.PositivExpr
    +
    No usage of de.dhbwstuttgart.syntaxtree.statement.javaInternal.PositivExpr
    diff --git a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/PostDecExpr.html b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/PostDecExpr.html index d6af3f573..317627d34 100644 --- a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/PostDecExpr.html +++ b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/PostDecExpr.html @@ -3,7 +3,7 @@ -Uses of Class de.dhbwstuttgart.syntaxtree.statement.PostDecExpr +Uses of Class de.dhbwstuttgart.syntaxtree.statement.javaInternal.PostDecExpr @@ -70,9 +70,9 @@
    -

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.PostDecExpr

    +

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.PostDecExpr

    -
    No usage of de.dhbwstuttgart.syntaxtree.statement.PostDecExpr
    +
    No usage of de.dhbwstuttgart.syntaxtree.statement.javaInternal.PostDecExpr
    diff --git a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/PostIncExpr.html b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/PostIncExpr.html index 73f60a522..8d6cfd7c2 100644 --- a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/PostIncExpr.html +++ b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/PostIncExpr.html @@ -3,7 +3,7 @@ -Uses of Class de.dhbwstuttgart.syntaxtree.statement.PostIncExpr +Uses of Class de.dhbwstuttgart.syntaxtree.statement.javaInternal.PostIncExpr @@ -70,9 +70,9 @@
    -

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.PostIncExpr

    +

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.PostIncExpr

    -
    No usage of de.dhbwstuttgart.syntaxtree.statement.PostIncExpr
    +
    No usage of de.dhbwstuttgart.syntaxtree.statement.javaInternal.PostIncExpr
    diff --git a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/PreDecExpr.html b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/PreDecExpr.html index d61069646..3fccd8b68 100644 --- a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/PreDecExpr.html +++ b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/PreDecExpr.html @@ -3,7 +3,7 @@ -Uses of Class de.dhbwstuttgart.syntaxtree.statement.PreDecExpr +Uses of Class de.dhbwstuttgart.syntaxtree.statement.javaInternal.PreDecExpr @@ -70,9 +70,9 @@
    -

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.PreDecExpr

    +

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.PreDecExpr

    -
    No usage of de.dhbwstuttgart.syntaxtree.statement.PreDecExpr
    +
    No usage of de.dhbwstuttgart.syntaxtree.statement.javaInternal.PreDecExpr
    diff --git a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/PreIncExpr.html b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/PreIncExpr.html index 310db4d9c..005ea2e54 100644 --- a/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/PreIncExpr.html +++ b/doc/LambdaJavadoc/de/dhbwstuttgart/syntaxtree/statement/class-use/PreIncExpr.html @@ -3,7 +3,7 @@ -Uses of Class de.dhbwstuttgart.syntaxtree.statement.PreIncExpr +Uses of Class de.dhbwstuttgart.syntaxtree.statement.javaInternal.PreIncExpr @@ -70,9 +70,9 @@
    -

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.PreIncExpr

    +

    Uses of Class
    de.dhbwstuttgart.syntaxtree.statement.PreIncExpr

    -
    No usage of de.dhbwstuttgart.syntaxtree.statement.PreIncExpr
    +
    No usage of de.dhbwstuttgart.syntaxtree.statement.javaInternal.PreIncExpr
    diff --git a/src/de/dhbwstuttgart/bytecode/BytecodeGen.java b/src/de/dhbwstuttgart/bytecode/BytecodeGen.java index f1994c204..6fff6729c 100644 --- a/src/de/dhbwstuttgart/bytecode/BytecodeGen.java +++ b/src/de/dhbwstuttgart/bytecode/BytecodeGen.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; +import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.syntaxtree.statement.*; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.FieldVisitor; @@ -382,12 +383,6 @@ public class BytecodeGen implements ASTVisitor { } - @Override - public void visit(UnaryPlus unaryPlus) { - // TODO Auto-generated method stub - - } - @Override public void visit(WhileStmt whileStmt) { // TODO Auto-generated method stub @@ -453,4 +448,9 @@ public class BytecodeGen implements ASTVisitor { } + @Override + public void visit(UnaryExpr unaryExpr) { + throw new NotImplementedException(); + } + } diff --git a/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java b/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java index 5368cf936..0d0f8ceaa 100644 --- a/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java +++ b/src/de/dhbwstuttgart/bytecode/BytecodeGenMethod.java @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; +import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.syntaxtree.statement.*; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Handle; @@ -336,6 +337,11 @@ public class BytecodeGenMethod implements StatementVisitor{ receiver.expr.accept(this); } + @Override + public void visit(UnaryExpr unaryExpr) { + throw new NotImplementedException(); + } + @Override public void visit(Return aReturn) { aReturn.retexpr.accept(this); @@ -367,11 +373,6 @@ public class BytecodeGenMethod implements StatementVisitor{ mv.visitVarInsn(Opcodes.ALOAD, 0); } - @Override - public void visit(UnaryPlus unaryPlus) { - System.out.println("++ In UnaryPlus: "); - } - @Override public void visit(WhileStmt whileStmt) { // TODO Auto-generated method stub diff --git a/src/de/dhbwstuttgart/bytecode/KindOfLambda.java b/src/de/dhbwstuttgart/bytecode/KindOfLambda.java index 36a28ce6f..5264888ca 100644 --- a/src/de/dhbwstuttgart/bytecode/KindOfLambda.java +++ b/src/de/dhbwstuttgart/bytecode/KindOfLambda.java @@ -1,5 +1,6 @@ package de.dhbwstuttgart.bytecode; +import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.syntaxtree.statement.*; import java.util.ArrayList; @@ -126,6 +127,11 @@ public class KindOfLambda implements StatementVisitor{ receiver.expr.accept(this); } + @Override + public void visit(UnaryExpr unaryExpr) { + throw new NotImplementedException(); + } + @Override public void visit(Return aReturn) { aReturn.retexpr.accept(this); @@ -155,12 +161,6 @@ public class KindOfLambda implements StatementVisitor{ this.argumentList.add(aThis.getType()); } - @Override - public void visit(UnaryPlus unaryPlus) { - // TODO Auto-generated method stub - - } - @Override public void visit(WhileStmt whileStmt) { // TODO Auto-generated method stub diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java index f4ada6b2e..a1d17e8ad 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java @@ -16,6 +16,7 @@ import de.dhbwstuttgart.syntaxtree.type.Void; import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.tree.TerminalNode; +import java.lang.reflect.Type; import java.util.*; public class StatementGenerator { @@ -289,8 +290,8 @@ public class StatementGenerator { } private Statement convert(Java8Parser.PostIncrementExpressionContext stmt) { - //TODO - throw new NotImplementedException(); + return new UnaryExpr(UnaryExpr.Operation.POSTINCREMENT, convert(stmt.postfixExpression()), + TypePlaceholder.fresh(stmt.getStart()), stmt.getStart()); } private Statement convert(Java8Parser.PostDecrementExpressionContext stmt) { @@ -316,8 +317,10 @@ public class StatementGenerator { } 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){ @@ -591,7 +594,7 @@ public class StatementGenerator { if(expression.relationalExpression() == null){ return convert(expression.shiftExpression()); }else{ - throw new NotImplementedException(); + return convert(expression.relationalExpression()); } } @@ -604,7 +607,9 @@ public class StatementGenerator { } private Expression convert(Java8Parser.AdditiveExpressionContext expression) { - if(expression.additiveExpression() == null){ + if(expression.additiveExpression() != null){ + return convert(expression.additiveExpression()); + }else if(expression.multiplicativeExpression() != null){ return convert(expression.multiplicativeExpression()); }else{ throw new NotImplementedException(); @@ -627,9 +632,11 @@ public class StatementGenerator { }else if(expression.unaryExpressionNotPlusMinus() != null){ return convert(expression.unaryExpressionNotPlusMinus()); }else if(expression.getText().startsWith("+")){ - return new UnaryPlus(convert(expression.unaryExpression())); + return new UnaryExpr(UnaryExpr.Operation.PLUS, convert(expression.unaryExpression()), + TypePlaceholder.fresh(expression.getStart()), expression.getStart()); }else if(expression.getText().startsWith("-")){ - return new UnaryMinus(convert(expression.unaryExpression())); + return new UnaryExpr(UnaryExpr.Operation.MINUS, convert(expression.unaryExpression()), + TypePlaceholder.fresh(expression.getStart()), expression.getStart()); }else{ //Diese Exceptions sollte nie geworfen werden. //Der Code wurde nur noch nicht getestet. Sollte zur Sicherheit drin bleiben. @@ -672,10 +679,10 @@ public class StatementGenerator { } for(Java8Parser.PostIncrementExpression_lf_postfixExpressionContext inc : expression.postIncrementExpression_lf_postfixExpression()){ - expr = new PostIncExpr(expr); + expr = new UnaryExpr(UnaryExpr.Operation.POSTINCREMENT, expr, TypePlaceholder.fresh(inc.getStart()), inc.getStart()); } for(Java8Parser.PostDecrementExpression_lf_postfixExpressionContext dec : expression.postDecrementExpression_lf_postfixExpression()){ - expr = new PostDecExpr(expr); + expr = new UnaryExpr(UnaryExpr.Operation.POSTDECREMENT, expr, TypePlaceholder.fresh(dec.getStart()), dec.getStart()); } return expr; diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntacticSugar.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntacticSugar.java index d758f52bb..d79260048 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntacticSugar.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntacticSugar.java @@ -1,6 +1,9 @@ package de.dhbwstuttgart.parser.SyntaxTreeGenerator; +import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.parser.NullToken; +import de.dhbwstuttgart.syntaxtree.AbstractASTWalker; +import de.dhbwstuttgart.syntaxtree.Constructor; import de.dhbwstuttgart.syntaxtree.statement.*; import java.util.List; @@ -10,22 +13,27 @@ public class SyntacticSugar { public static List addTrailingReturn(List statements){ if(statements.size()!=0) { Statement lastStmt = statements.get(statements.size() - 1); - if (lastStmt instanceof Return) return statements; - if (lastStmt instanceof WhileStmt) { - //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; - } else if (lastStmt instanceof ForStmt) { - if (hasReturn(((ForStmt) lastStmt).body_Loop_block)) return statements; - } else { - } + ReturnFinder hasReturn = new ReturnFinder(); + lastStmt.accept(hasReturn); + if(hasReturn.hasReturn)return statements; } statements.add(new ReturnVoid(new NullToken())); return statements; } + private static class ReturnFinder extends AbstractASTWalker{ + public boolean hasReturn = false; + @Override + public void visit(Return aReturn) { + hasReturn = true; + } + + @Override + public void visit(ReturnVoid aReturn) { + hasReturn = true; + } + } + private static boolean hasReturn(Block block){ for(Statement s : block.getStatements()) if(s instanceof Return)return true; diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java index d54b682a1..1dd259d0d 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java @@ -40,7 +40,12 @@ public class TypeGenerator { public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.UnannTypeContext unannTypeContext, JavaClassRegistry reg, GenericsRegistry genericsRegistry) { if(unannTypeContext.unannPrimitiveType()!=null){ - throw new NotImplementedException(); + if(unannTypeContext.unannPrimitiveType().getText().equals("boolean")){ + return new RefType(ASTFactory.createClass(Boolean.class).getClassName(), unannTypeContext.getStart()); + }else{ + Java8Parser.NumericTypeContext numericType = unannTypeContext.unannPrimitiveType().numericType(); + throw new NotImplementedException(); + } }else if(unannTypeContext.unannReferenceType().unannArrayType()!=null){ //System.out.println(unannTypeContext.getText()); diff --git a/src/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java b/src/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java index 8a66629bf..054c3915e 100644 --- a/src/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java +++ b/src/de/dhbwstuttgart/syntaxtree/AbstractASTWalker.java @@ -7,6 +7,7 @@ import de.dhbwstuttgart.syntaxtree.statement.literal.Literal; import de.dhbwstuttgart.syntaxtree.statement.literal.Null; import de.dhbwstuttgart.syntaxtree.type.*; +import javax.management.Notification; import java.lang.reflect.Modifier; import java.util.Iterator; @@ -202,6 +203,11 @@ public abstract class AbstractASTWalker implements ASTVisitor{ receiver.expr.accept(this); } + @Override + public void visit(UnaryExpr unaryExpr) { + unaryExpr.expr.accept(this); + } + @Override public void visit(Return aReturn) { aReturn.retexpr.accept(this); @@ -227,11 +233,6 @@ public abstract class AbstractASTWalker implements ASTVisitor{ } - @Override - public void visit(UnaryPlus unaryPlus) { - - } - @Override public void visit(WhileStmt whileStmt) { diff --git a/src/de/dhbwstuttgart/syntaxtree/StatementVisitor.java b/src/de/dhbwstuttgart/syntaxtree/StatementVisitor.java index 195db2301..1c4e149c1 100644 --- a/src/de/dhbwstuttgart/syntaxtree/StatementVisitor.java +++ b/src/de/dhbwstuttgart/syntaxtree/StatementVisitor.java @@ -50,8 +50,6 @@ public interface StatementVisitor { void visit(This aThis); - void visit(UnaryPlus unaryPlus); - void visit(WhileStmt whileStmt); void visit(DoStmt whileStmt); @@ -67,4 +65,6 @@ public interface StatementVisitor { void visit(SuperCall superCall); void visit(ExpressionReceiver expressionReceiver); + + void visit(UnaryExpr unaryExpr); } diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java index 6acb4214d..b06835695 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java @@ -133,7 +133,7 @@ public class ASTFactory { } */ - public static RefTypeOrTPHOrWildcardOrGeneric createType(java.lang.reflect.Type type, JavaClassName parentClass, String parentMethod){ + private static RefTypeOrTPHOrWildcardOrGeneric createType(java.lang.reflect.Type type, JavaClassName parentClass, String parentMethod){ if(type.getTypeName().equals("void")){ return new Void(new NullToken()); }else if(type.getTypeName().equals("int")){ diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java index 5d6a46589..4af1e7700 100644 --- a/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java @@ -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) + Expression expr, Statement thenBlock, Statement elseBlock, Token offset) { super(type,offset); this.expr = expr; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/JavaInternalExpression.java b/src/de/dhbwstuttgart/syntaxtree/statement/JavaInternalExpression.java new file mode 100644 index 000000000..366c06020 --- /dev/null +++ b/src/de/dhbwstuttgart/syntaxtree/statement/JavaInternalExpression.java @@ -0,0 +1,12 @@ +package de.dhbwstuttgart.syntaxtree.statement; + +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; +import org.antlr.v4.runtime.Token; + +import java.nio.charset.StandardCharsets; + +public abstract class JavaInternalExpression extends Statement{ + public JavaInternalExpression(RefTypeOrTPHOrWildcardOrGeneric retType, Token offset){ + super(retType, offset); + } +} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.java deleted file mode 100644 index 67e71e95e..000000000 --- a/src/de/dhbwstuttgart/syntaxtree/statement/NegativeExpr.java +++ /dev/null @@ -1,18 +0,0 @@ -package de.dhbwstuttgart.syntaxtree.statement; -import java.util.Hashtable; -import java.util.Iterator; - -import org.antlr.v4.runtime.Token; - - - -public class NegativeExpr extends UnaryExpr -{ - public NegativeExpr(Token offset) - { - super(offset); - } - private UnaryMinus neg; - public Expression expr; - -} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java deleted file mode 100644 index 0fcfd3338..000000000 --- a/src/de/dhbwstuttgart/syntaxtree/statement/NotExpr.java +++ /dev/null @@ -1,14 +0,0 @@ -package de.dhbwstuttgart.syntaxtree.statement; - - -import org.antlr.v4.runtime.Token; - -public class NotExpr extends UnaryExpr -{ - public NotExpr(Token offset) - { - super(offset); - } - private UnaryNot not; - public Expression expr; -} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.java deleted file mode 100644 index bec6ffbe3..000000000 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PositivExpr.java +++ /dev/null @@ -1,15 +0,0 @@ -package de.dhbwstuttgart.syntaxtree.statement; - - -import org.antlr.v4.runtime.Token; - -public class PositivExpr extends UnaryExpr -{ - public PositivExpr(Token offset) - { - super(offset); - } - protected UnaryPlus plus; - public Expression expr; - -} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java deleted file mode 100644 index 18b56f96f..000000000 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java +++ /dev/null @@ -1,17 +0,0 @@ -package de.dhbwstuttgart.syntaxtree.statement; -import java.util.Hashtable; -import java.util.Iterator; - -import de.dhbwstuttgart.parser.antlr.Java8Parser; - - - - -public class PostDecExpr extends PostIncExpr -{ - - public PostDecExpr(Expression expr) { - super(expr); - } - -} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java deleted file mode 100644 index 1292192b3..000000000 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java +++ /dev/null @@ -1,15 +0,0 @@ -package de.dhbwstuttgart.syntaxtree.statement; - -import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation; -import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; -import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation; -import de.dhbwstuttgart.exceptions.NotImplementedException; - - -public class PostIncExpr extends UnaryExpr -{ - public PostIncExpr(Expression expr) { - super(null); - } - -} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.java deleted file mode 100644 index de0fb0b19..000000000 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PreDecExpr.java +++ /dev/null @@ -1,17 +0,0 @@ -package de.dhbwstuttgart.syntaxtree.statement; -import java.util.Hashtable; -import java.util.Iterator; - -import org.antlr.v4.runtime.Token; - - - - - -public class PreDecExpr extends UnaryExpr -{ - public PreDecExpr(Token offset) - { - super(offset); - } -} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.java deleted file mode 100644 index 736dc3116..000000000 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PreIncExpr.java +++ /dev/null @@ -1,12 +0,0 @@ -package de.dhbwstuttgart.syntaxtree.statement; - - -import org.antlr.v4.runtime.Token; - -public class PreIncExpr extends UnaryExpr -{ - public PreIncExpr(Token offset) - { - super(offset); - } -} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/UnaryExpr.java index 2157560c4..ca06146a8 100644 --- a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/UnaryExpr.java @@ -1,14 +1,37 @@ package de.dhbwstuttgart.syntaxtree.statement; +import de.dhbwstuttgart.syntaxtree.StatementVisitor; +import de.dhbwstuttgart.syntaxtree.statement.Expression; +import de.dhbwstuttgart.syntaxtree.statement.JavaInternalExpression; +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; import org.antlr.v4.runtime.Token; -public abstract class UnaryExpr extends MethodCall +public class UnaryExpr extends JavaInternalExpression { + public enum Operation{ + NOT, + MINUS, + PREINCREMENT, + PREDECREMENT, + POSTINCREMENT, + PLUS, POSTDECREMENT + } + + + public final Operation operation; public Expression expr; - public UnaryExpr(Token offset) + public UnaryExpr(Operation operation, Expression argument, RefTypeOrTPHOrWildcardOrGeneric retType, Token offset) { - super(null,null,null,null,null); + super(retType, offset); + this.expr = argument; + this.operation = operation; } + @Override + public void accept(StatementVisitor visitor) { + visitor.visit(this); + } + + } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryMinus.java b/src/de/dhbwstuttgart/syntaxtree/statement/UnaryMinus.java deleted file mode 100644 index 6c1002258..000000000 --- a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryMinus.java +++ /dev/null @@ -1,12 +0,0 @@ -package de.dhbwstuttgart.syntaxtree.statement; - - -import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; - -public class UnaryMinus extends UnaryPlus -{ - - public UnaryMinus(Expression expression) { - super(expression); - } -} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryNot.java b/src/de/dhbwstuttgart/syntaxtree/statement/UnaryNot.java deleted file mode 100644 index 2dce91bd7..000000000 --- a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryNot.java +++ /dev/null @@ -1,7 +0,0 @@ -package de.dhbwstuttgart.syntaxtree.statement; - - -public class UnaryNot -{ - -} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryPlus.java b/src/de/dhbwstuttgart/syntaxtree/statement/UnaryPlus.java deleted file mode 100644 index b374166f0..000000000 --- a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryPlus.java +++ /dev/null @@ -1,20 +0,0 @@ -package de.dhbwstuttgart.syntaxtree.statement; - -import de.dhbwstuttgart.syntaxtree.StatementVisitor; -import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation; -import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; -import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation; -import de.dhbwstuttgart.exceptions.NotImplementedException; - -public class UnaryPlus extends Expression -{ - public UnaryPlus(Expression expression){ - super(expression.getType(),expression.getOffset()); - - } - - @Override - public void accept(StatementVisitor visitor) { - visitor.visit(this); - } -} diff --git a/src/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java b/src/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java index d56c39d8c..191d58a02 100644 --- a/src/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java +++ b/src/de/dhbwstuttgart/syntaxtree/visual/OutputGenerator.java @@ -296,11 +296,6 @@ public class OutputGenerator implements ASTVisitor{ out.append("this"); } - @Override - public void visit(UnaryPlus unaryPlus) { - - } - @Override public void visit(WhileStmt whileStmt) { out.append("while("); @@ -349,4 +344,9 @@ public class OutputGenerator implements ASTVisitor{ public void visit(ExpressionReceiver receiver) { receiver.expr.accept(this); } + + @Override + public void visit(UnaryExpr unaryExpr) { + throw new NotImplementedException(); + } } \ No newline at end of file diff --git a/src/de/dhbwstuttgart/syntaxtree/visual/TypeOutputGenerator.java b/src/de/dhbwstuttgart/syntaxtree/visual/TypeOutputGenerator.java index dcefafa44..6f90051a3 100644 --- a/src/de/dhbwstuttgart/syntaxtree/visual/TypeOutputGenerator.java +++ b/src/de/dhbwstuttgart/syntaxtree/visual/TypeOutputGenerator.java @@ -214,11 +214,6 @@ public class TypeOutputGenerator extends OutputGenerator { aThis.getType().accept(this); } - @Override - public void visit(UnaryPlus unaryPlus) { - super.visit(unaryPlus); - } - @Override public void visit(WhileStmt whileStmt) { super.visit(whileStmt); diff --git a/src/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java b/src/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java index 8dea5748d..ad591ebe5 100644 --- a/src/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java +++ b/src/de/dhbwstuttgart/typedeployment/TypeInsertPlacer.java @@ -1,6 +1,8 @@ package de.dhbwstuttgart.typedeployment; +import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.syntaxtree.*; +import de.dhbwstuttgart.syntaxtree.statement.JavaInternalExpression; import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.result.ResultSet; diff --git a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index 3448e8e3d..ed5837adb 100644 --- a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -2,12 +2,14 @@ package de.dhbwstuttgart.typeinference.typeAlgo; //import com.sun.org.apache.xpath.internal.Arg; +import com.sun.org.apache.xpath.internal.operations.Bool; import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.exceptions.TypeinferenceException; import de.dhbwstuttgart.parser.NullToken; import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal; import de.dhbwstuttgart.parser.antlr.Java8Parser; import de.dhbwstuttgart.syntaxtree.*; +import de.dhbwstuttgart.syntaxtree.factory.ASTFactory; import de.dhbwstuttgart.syntaxtree.statement.*; import de.dhbwstuttgart.syntaxtree.statement.literal.Literal; import de.dhbwstuttgart.syntaxtree.statement.literal.Null; @@ -193,6 +195,23 @@ public class TYPEStmt implements StatementVisitor{ receiver.expr.accept(this); } + @Override + public void visit(UnaryExpr unaryExpr) { + if(unaryExpr.operation == UnaryExpr.Operation.POSTDECREMENT || + unaryExpr.operation == UnaryExpr.Operation.POSTINCREMENT || + unaryExpr.operation == UnaryExpr.Operation.PREDECREMENT || + unaryExpr.operation == UnaryExpr.Operation.PREINCREMENT){ + //@see: https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.14.2 + //Expression muss zu Numeric Convertierbar sein. also von Numeric erben + RefType number = new RefType(ASTFactory.createClass(Number.class).getClassName(), unaryExpr.getOffset()); + constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), number, PairOperator.EQUALSDOT)); + //The type of the postfix increment expression is the type of the variable + constraintsSet.addUndConstraint(new Pair(unaryExpr.expr.getType(), unaryExpr.getType(), PairOperator.EQUALSDOT)); + }else{ + throw new NotImplementedException(); + } + } + @Override public void visit(Return returnExpr) { returnExpr.retexpr.accept(this); @@ -241,14 +260,11 @@ public class TYPEStmt implements StatementVisitor{ }; } - @Override - public void visit(UnaryPlus unaryPlus) { - throw new NotImplementedException(); - } - @Override public void visit(WhileStmt whileStmt) { - throw new NotImplementedException(); + RefType booleanType = new RefType(ASTFactory.createClass(java.lang.Boolean.class).getClassName(), new NullToken()); + constraintsSet.addUndConstraint(new Pair(whileStmt.expr.getType(), booleanType, PairOperator.EQUALSDOT)); + whileStmt.loopBlock.accept(this); } @Override diff --git a/test/javFiles/Matrix.jav b/test/javFiles/Matrix.jav index e6aa84cd4..66abd5e03 100644 --- a/test/javFiles/Matrix.jav +++ b/test/javFiles/Matrix.jav @@ -1,54 +1,24 @@ import java.util.Vector; class Matrix extends Vector> { - - methode(Matrix m) { - Vector> i; - methode(i); - } - } - -/* -import java.util.Vector; - -class Matrix extends Vector> { - - Matrix mul_rec(Matrix m) { - auto v1 = new Vector(); - auto v2 = new Vector(); - auto i = 0; - while(i < m.size()) { - auto v; - v = m.elementAt(i); - v2.addElement(v.remove(v.size()-1)); - i++; - } - Matrix ret; - if (m.elementAt(0).size() > 0) { - ret = this.mul_rec(m); - } - else { - ret = new Matrix(); - i = 0; - while (i < this.size()) { - ret.addElement(new Vector()); - i++; - } - } - i = 0; - while (i < this.size()) { - int erg = 0; - auto j; - j = 0; - while (j < v2.size()) { - erg = erg + this.elementAt(i).elementAt(j).intValue() - * v2.elementAt(j).intValue(); - j++; - } - ret.elementAt(i).addElement(erg); - i++; - } - return ret; - } + mul(m) { + var ret = new Matrix(); + var i = 0; + while(i (); + var j = 0; + while(j < v1.size()) { + var erg = 0; + var k = 0; + while(k < v1.size()) { + erg = erg + v1.elementAt(k) + * m.elementAt(k).elementAt(j); + k++; } + v2.addElement(new Integer(erg)); + j++; } + ret.addElement(v2); + i++; } + return ret; + } } -*/ \ No newline at end of file