From 52f51c7932b164e4d0ae11b92106a4221f9aaf23 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Wed, 1 Mar 2017 15:34:57 +0100 Subject: [PATCH] Parser erweitern --- .../parser/SyntaxTreeGenerator.java | 585 ++++++++++++++++-- .../parser/SyntaxTreeStatementGenerator.java | 308 --------- .../syntaxtree/operator/AndOp.java | 5 +- .../syntaxtree/operator/LogOp.java | 4 +- .../syntaxtree/operator/OrOp.java | 13 +- .../syntaxtree/statement/Binary.java | 4 +- .../syntaxtree/statement/BinaryExpr.java | 2 +- .../syntaxtree/statement/CastExpr.java | 2 +- .../syntaxtree/statement/Executable.java | 17 - .../syntaxtree/statement/Expr.java | 7 +- .../syntaxtree/statement/ExprStmt.java | 2 +- .../syntaxtree/statement/Expression.java | 14 + .../syntaxtree/statement/InstVar.java | 9 +- .../statement/LambdaExpression.java | 5 +- .../syntaxtree/statement/Literal.java | 2 +- .../statement/LocalOrFieldVarOrClassname.java | 18 +- .../statement/LocalVarBunchDeclaration.java | 16 + .../syntaxtree/statement/MethodCall.java | 2 +- .../syntaxtree/statement/NewArray.java | 2 +- .../syntaxtree/statement/NewClass.java | 2 +- .../syntaxtree/statement/PostDecExpr.java | 13 +- .../syntaxtree/statement/PostIncExpr.java | 8 +- .../syntaxtree/statement/Return.java | 2 +- .../syntaxtree/statement/Statement.java | 5 +- .../syntaxtree/statement/This.java | 2 +- .../syntaxtree/statement/UnaryExpr.java | 3 +- .../syntaxtree/statement/UnaryMinus.java | 9 +- .../syntaxtree/statement/UnaryPlus.java | 9 +- 28 files changed, 647 insertions(+), 423 deletions(-) delete mode 100644 src/de/dhbwstuttgart/parser/SyntaxTreeStatementGenerator.java delete mode 100755 src/de/dhbwstuttgart/syntaxtree/statement/Executable.java create mode 100755 src/de/dhbwstuttgart/syntaxtree/statement/Expression.java create mode 100644 src/de/dhbwstuttgart/syntaxtree/statement/LocalVarBunchDeclaration.java diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java index 79440c8a..381368d3 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java @@ -1,24 +1,25 @@ package de.dhbwstuttgart.parser; -import com.sun.corba.se.spi.monitoring.StatisticMonitoredAttribute; import de.dhbwstuttgart.parser.antlr.Java8Parser; import de.dhbwstuttgart.syntaxtree.*; import de.dhbwstuttgart.syntaxtree.modifier.*; import de.dhbwstuttgart.syntaxtree.modifier.fieldModifier.*; import de.dhbwstuttgart.syntaxtree.modifier.methodModifier.MethodModifier; +import de.dhbwstuttgart.syntaxtree.operator.AndOp; +import de.dhbwstuttgart.syntaxtree.operator.Operator; +import de.dhbwstuttgart.syntaxtree.operator.OrOp; import de.dhbwstuttgart.syntaxtree.statement.*; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typecheck.*; import java.util.ArrayList; -import java.util.Arrays; +import java.util.Iterator; import java.util.List; -import java.lang.ClassNotFoundException; import org.antlr.v4.runtime.Token; +import org.antlr.v4.runtime.atn.SemanticContext; import org.antlr.v4.runtime.tree.TerminalNode; -import org.antlr.v4.runtime.RecognitionException; import sun.reflect.generics.reflectiveObjects.NotImplementedException; @@ -260,41 +261,6 @@ public class SyntaxTreeGenerator{ return null; } - private Block convert(Java8Parser.BlockContext block) { - List statements = new ArrayList<>(); - if(block.blockStatements() != null) - for(Java8Parser.BlockStatementContext statementContext : block.blockStatements().blockStatement()){ - List stmt = convert(statementContext); - statements.addAll(stmt); - } - - return new Block(statements, block.getStart()); - } - - private List convert(Java8Parser.BlockStatementContext statementContext) { - List ret = new ArrayList<>(); - if(statementContext.localVariableDeclarationStatement() != null){ - Java8Parser.LocalVariableDeclarationContext declaration = statementContext.localVariableDeclarationStatement().localVariableDeclaration(); - RefTypeOrTPH type; - if(declaration.unannType()==null){ - type = TypePlaceholder.fresh(declaration.getStart()); - }else{ - type = convert(declaration.unannType()); - } - for(Java8Parser.VariableDeclaratorContext varDecl : declaration.variableDeclaratorList().variableDeclarator()){ - TerminalNode name = varDecl.variableDeclaratorId().Identifier(); - ret.add(new LocalVarDecl(name.getText(), type, name.getSymbol())); - } - return ret; - }else if(statementContext.classDeclaration() != null){ - throw new NotImplementedException(); - }else{ - Java8Parser.StatementContext stmt = statementContext.statement(); - ret.add(SyntaxTreeStatementGenerator.convert(stmt)); - return ret; - } - } - private ParameterList convert(Java8Parser.FormalParameterListContext formalParameterListContext) { List ret = new ArrayList<>(); List fps = new ArrayList<>(); @@ -375,7 +341,6 @@ public class SyntaxTreeGenerator{ return new RefType(reg.getName(name), unannClassOrInterfaceTypeContext.getStart()); } - private Modifier convert(Java8Parser.ClassModifierContext ctx){ Modifier newModifier = null; if(ctx.annotation() == null){ @@ -456,4 +421,544 @@ public class SyntaxTreeGenerator{ private ClassOrInterface convertInterface(Java8Parser.InterfaceDeclarationContext ctx){ return null; } + + /* + * StatementGeneration: + */ + + public Statement convert(Java8Parser.StatementContext stmt) { + if (stmt.statementWithoutTrailingSubstatement() != null) { + return convert(stmt.statementWithoutTrailingSubstatement()); + } else if (stmt.whileStatement() != null) { + return convert(stmt.whileStatement()); + } else if (stmt.forStatement() != null) { + return convert(stmt.forStatement()); + } else if (stmt.ifThenElseStatement() != null) { + return convert(stmt.ifThenElseStatement()); + } else if (stmt.ifThenStatement() != null) { + return convert(stmt.ifThenStatement()); + } else if (stmt.labeledStatement() != null) { + return convert(stmt.labeledStatement() ); + }else throw new NotImplementedException(); + } + + private Statement convert(Java8Parser.StatementNoShortIfContext stmt){ + if(stmt.statementWithoutTrailingSubstatement() != null){ + return convert(stmt.statementWithoutTrailingSubstatement()); + }else if(stmt.labeledStatementNoShortIf() != null){ + return convert(stmt.labeledStatementNoShortIf()); + }else if(stmt.ifThenElseStatementNoShortIf() != null){ + return convert(stmt.ifThenElseStatementNoShortIf()); + }else if(stmt.whileStatementNoShortIf() != null){ + return convert(stmt.whileStatementNoShortIf()); + }else if(stmt.forStatementNoShortIf() != null){ + return convert(stmt.forStatementNoShortIf()); + }else throw new NotImplementedException(); + } + + private Statement convert(Java8Parser.StatementWithoutTrailingSubstatementContext stmt) { + if(stmt.block() != null){ + return convert(stmt.block()); + }else if(stmt.emptyStatement() != null){ + return new EmptyStmt(); + }else if(stmt.expressionStatement() != null){ + return convert(stmt.expressionStatement()); + }else if(stmt.assertStatement() != null){ + return convert(stmt.assertStatement()); + }else if(stmt.switchStatement() != null){ + return convert(stmt.switchStatement()); + }else if(stmt.doStatement() != null){ + return convert(stmt.doStatement()); + }else if(stmt.breakStatement() != null){ + return convert(stmt.breakStatement()); + }else if(stmt.continueStatement() != null){ + return convert(stmt.continueStatement()); + }else if(stmt.returnStatement() != null){ + return convert(stmt.returnStatement()); + }else if(stmt.synchronizedStatement() != null){ + return convert(stmt.synchronizedStatement()); + }else if(stmt.throwStatement() != null){ + return convert(stmt.throwStatement()); + }else if(stmt.tryStatement() != null){ + return convert(stmt.tryStatement()); + }else throw new NotImplementedException(); + } + + private Block convert(Java8Parser.BlockContext block) { + List statements = new ArrayList<>(); + if(block.blockStatements() != null) + for(Java8Parser.BlockStatementContext statementContext : block.blockStatements().blockStatement()){ + Statement stmt = convert(statementContext); + statements.add(stmt); + } + + return new Block(statements, block.getStart()); + } + + private de.dhbwstuttgart.syntaxtree.statement.Statement convert(Java8Parser.BlockStatementContext statementContext) { + List ret = new ArrayList<>(); + if(statementContext.localVariableDeclarationStatement() != null){ + return convert(statementContext.localVariableDeclarationStatement()); + }else if(statementContext.classDeclaration() != null){ + throw new NotImplementedException(); + }else{ + Java8Parser.StatementContext stmt = statementContext.statement(); + return convert(stmt); + } + } + + private Statement convert(Java8Parser.LocalVariableDeclarationStatementContext stmt) { + Java8Parser.LocalVariableDeclarationContext declaration = stmt.localVariableDeclaration(); + return convert(declaration); + } + + private static Statement convert(Java8Parser.LabeledStatementContext labeledStatementContext) { + throw new NotImplementedException(); + //return convert(labeledStatementContext.statement()); + } + + private static Statement convert(Java8Parser.LabeledStatementNoShortIfContext stmt){ + throw new NotImplementedException(); + //return convert(stmt.statementNoShortIf()); + } + + private static Statement convert(Java8Parser.ExpressionStatementContext stmt){ + return convert(stmt.statementExpression()); + } + + private static Statement convert(Java8Parser.StatementExpressionContext stmt) { + if(stmt.assignment() != null){ + return convert(stmt.assignment()); + }else if(stmt.preIncrementExpression() != null){ + return convert(stmt.preIncrementExpression()); + }else if(stmt.preDecrementExpression() != null){ + return convert(stmt.preDecrementExpression()); + }else if(stmt.postIncrementExpression() != null){ + return convert(stmt.postIncrementExpression()); + }else if(stmt.postDecrementExpression() != null){ + return convert(stmt.postDecrementExpression()); + }else if(stmt.methodInvocation() != null){ + return convert(stmt.methodInvocation()); + }else if(stmt.classInstanceCreationExpression() != null){ + return convert(stmt.classInstanceCreationExpression()); + }else throw new NotImplementedException(); + } + + private static Statement convert(Java8Parser.MethodInvocationContext methodInvocationContext) { + String name = methodInvocationContext.methodName().Identifier().getText(); + Expr receiver; + if(methodInvocationContext.typeName() != null){ + receiver = new LocalOrFieldVarOrClassname(methodInvocationContext.typeName().getText(), methodInvocationContext.typeArguments().getStart()); + }else if(methodInvocationContext.expressionName()!=null){ + receiver = convert(methodInvocationContext.expressionName()); + }else{ + receiver = new This(methodInvocationContext.getStart()); + } + + ArgumentList argumentList = null; + MethodCall ret = new MethodCall(new Receiver(receiver), name, argumentList, methodInvocationContext.getStart()); + return ret; + } + + private static Expr convert(Java8Parser.ExpressionNameContext expressionNameContext) { + /* + Der Parser könnte feststellen, ob es sich um einen Klassennamen, + eine lokale Variable oder einen Feldzugriff handelt. + Das überprüft allerdings sowieso der Typinferenzalgorithmus, + da er auch die Typchecks übernimmt. Code wäre redundant und würde + Möglichkeiten des Typinferenzalgorithmus einschränken. + */ + return new LocalOrFieldVarOrClassname(expressionNameContext.getText(), expressionNameContext.getStart()); + } + + + private static Statement convert(Java8Parser.ClassInstanceCreationExpressionContext stmt) { + //TODO + throw new NotImplementedException(); + } + + private static ExprStmt convert(Java8Parser.PreIncrementExpressionContext stmt) { + //TODO + throw new NotImplementedException(); + } + + private static ExprStmt convert(Java8Parser.PreDecrementExpressionContext stmt) { + //TODO + throw new NotImplementedException(); + } + + private static Statement convert(Java8Parser.PostIncrementExpressionContext stmt) { + //TODO + throw new NotImplementedException(); + } + + private static Statement convert(Java8Parser.PostDecrementExpressionContext stmt) { + //TODO + throw new NotImplementedException(); + } + + private static ExprStmt convert(Java8Parser.AssignmentContext stmt) { + //TODO + //return new StatementReturn(new Assign()) + throw new NotImplementedException(); + } + + private static Statement convert(Java8Parser.IfThenStatementContext stmt){ + //TODO + throw new NotImplementedException(); + } + + private static Statement convert(Java8Parser.IfThenElseStatementContext stmt){ + //TODO + throw new NotImplementedException(); + } + + private static Statement convert(Java8Parser.IfThenElseStatementNoShortIfContext stmt){ + //TODO + throw new NotImplementedException(); + } + + private static Statement convert(Java8Parser.AssertStatementContext stmt){ + //TODO + throw new NotImplementedException(); + } + + private static Statement convert(Java8Parser.SwitchStatementContext stmt){ + //TODO + throw new NotImplementedException(); + } + + private static Statement convert(Java8Parser.SwitchBlockContext stmt){ + //TODO + throw new NotImplementedException(); + } + + private static Statement convert(Java8Parser.SwitchBlockStatementGroupContext stmt){ + //TODO + throw new NotImplementedException(); + } + + private static Statement convert(Java8Parser.WhileStatementContext stmt){ + //TODO + throw new NotImplementedException(); + } + + private static Statement convert(Java8Parser.WhileStatementNoShortIfContext stmt){ + //TODO + throw new NotImplementedException(); + } + + private static Statement convert(Java8Parser.DoStatementContext stmt){ + //TODO + throw new NotImplementedException(); + } + + private static Statement convert(Java8Parser.ForStatementContext stmt){ + if(stmt.basicForStatement() != null){ + return convert(stmt.basicForStatement()); + }else if(stmt.enhancedForStatement() != null){ + return convert(stmt.enhancedForStatement()); + }else throw new NotImplementedException(); + } + + private static Statement convert(Java8Parser.ForStatementNoShortIfContext stmt){ + if(stmt.basicForStatementNoShortIf() != null){ + return convert(stmt.basicForStatementNoShortIf()); + }else if(stmt.enhancedForStatementNoShortIf() != null){ + return convert(stmt.enhancedForStatementNoShortIf()); + }else throw new NotImplementedException(); + } + + private static Statement convert(Java8Parser.BasicForStatementContext stmt){ + //TODO + throw new NotImplementedException(); + } + + private static Statement convert(Java8Parser.BasicForStatementNoShortIfContext stmt){ + //TODO + throw new NotImplementedException(); + } + + private Statement convert(Java8Parser.ForInitContext stmt){ + if(stmt.statementExpressionList() != null){ + return convert(stmt.statementExpressionList()); + }else if(stmt.localVariableDeclaration() != null){ + return convert(stmt.localVariableDeclaration()); + }else throw new NotImplementedException(); + } + + private Statement convert(Java8Parser.LocalVariableDeclarationContext declaration) { + List declarations = new ArrayList<>(); + if(declaration.variableModifier() != null && declaration.variableModifier().size() > 0){ + //TODO + } + RefTypeOrTPH type; + if(declaration.unannType()==null){ + type = TypePlaceholder.fresh(declaration.getStart()); + }else{ + type = convert(declaration.unannType()); + } + for(Java8Parser.VariableDeclaratorContext varDecl : declaration.variableDeclaratorList().variableDeclarator()){ + TerminalNode name = varDecl.variableDeclaratorId().Identifier(); + declarations.add(new LocalVarDecl(name.getText(), type, name.getSymbol())); + } + if(declarations.size()==1)return declarations.get(0); + return new LocalVarBunchDeclaration(declarations, declaration.getStart()); + } + + private static Statement convert(Java8Parser.ForUpdateContext stmt){ + return convert(stmt.statementExpressionList()); + } + + private static Statement convert(Java8Parser.StatementExpressionListContext stmt){ + //TODO + throw new NotImplementedException(); + } + + private static Statement convert(Java8Parser.EnhancedForStatementContext stmt){ + //TODO + throw new NotImplementedException(); + } + + private static Statement convert(Java8Parser.EnhancedForStatementNoShortIfContext stmt){ + //TODO + throw new NotImplementedException(); + } + + private static Statement convert(Java8Parser.BreakStatementContext stmt){ + //TODO + throw new NotImplementedException(); + } + + private static Statement convert(Java8Parser.ContinueStatementContext stmt){ + //TODO + throw new NotImplementedException(); + } + + private static Statement convert(Java8Parser.ReturnStatementContext stmt){ + return new Return(convert(stmt.expression()),stmt.getStart()); + //throw new NotImplementedException(); + } + + private static Statement convert(Java8Parser.ThrowStatementContext stmt){ + //TODO + throw new NotImplementedException(); + } + + private static Statement convert(Java8Parser.SynchronizedStatementContext stmt){ + //TODO + throw new NotImplementedException(); + } + + private static Statement convert(Java8Parser.TryStatementContext stmt){ + //TODO + throw new NotImplementedException(); + } + + private static Statement convert(Java8Parser.CatchesContext stmt){ + //TODO + throw new NotImplementedException(); + } + + private static Statement convert(Java8Parser.CatchClauseContext stmt){ + //TODO + throw new NotImplementedException(); + } + +/* +***************+ Expression Conversions: + */ + + private static Expr convert(Java8Parser.ExpressionContext expression) { + if(expression.lambdaExpression()!=null){ + return convert(expression.lambdaExpression()); + }else{ + return convert(expression.assignmentExpression()); + } + } + + private static Expr convert(Java8Parser.AssignmentExpressionContext expression) { + if(expression.conditionalExpression() != null){ + return convert(expression.conditionalExpression()); + }else{ + return convert(expression.assignment()); + } + } + + private static Expr convert(Java8Parser.ConditionalExpressionContext expression) { + if(expression.conditionalOrExpression() != null){ + return convert(expression.conditionalOrExpression()); + }else{ + throw new NotImplementedException(); + } + } + + private static Expr convert(Java8Parser.ConditionalOrExpressionContext expression) { + if(expression.conditionalOrExpression() == null){ + return convert(expression.conditionalAndExpression()); + }else{ + return new Binary(convert(expression.conditionalOrExpression()), + convert(expression.conditionalAndExpression()), new OrOp(null)); + } + } + + private static Expr convert(Java8Parser.ConditionalAndExpressionContext expression) { + if(expression.conditionalAndExpression() == null){ + return convert(expression.inclusiveOrExpression()); + }else{ + return new Binary(convert(expression.conditionalAndExpression()), + convert(expression.inclusiveOrExpression()), new AndOp(null)); + } + } + + private static Expr convert(Java8Parser.InclusiveOrExpressionContext expression) { + if(expression.inclusiveOrExpression() == null){ + return convert(expression.exclusiveOrExpression()); + }else{ + throw new NotImplementedException(); + } + } + + private static Expr convert(Java8Parser.ExclusiveOrExpressionContext expression) { + if(expression.exclusiveOrExpression() == null){ + return convert(expression.andExpression()); + }else{ + throw new NotImplementedException(); + } + } + + private static Expr convert(Java8Parser.AndExpressionContext expression) { + if(expression.andExpression() == null){ + return convert(expression.equalityExpression()); + }else{ + throw new NotImplementedException(); + } + } + + private static Expr convert(Java8Parser.EqualityExpressionContext expression) { + if(expression.equalityExpression() == null){ + return convert(expression.relationalExpression()); + }else{ + throw new NotImplementedException(); + } + } + + private static Expr convert(Java8Parser.RelationalExpressionContext expression) { + if(expression.relationalExpression() == null){ + return convert(expression.shiftExpression()); + }else{ + throw new NotImplementedException(); + } + } + + private static Expr convert(Java8Parser.ShiftExpressionContext expression) { + if(expression.shiftExpression() == null){ + return convert(expression.additiveExpression()); + }else{ + throw new NotImplementedException(); + } + } + + private static Expr convert(Java8Parser.AdditiveExpressionContext expression) { + if(expression.additiveExpression() == null){ + return convert(expression.multiplicativeExpression()); + }else{ + throw new NotImplementedException(); + } + } + + private static Expr convert(Java8Parser.MultiplicativeExpressionContext expression) { + if(expression.multiplicativeExpression() == null){ + return convert(expression.unaryExpression()); + }else{ + throw new NotImplementedException(); + } + } + + private static Expr convert(Java8Parser.UnaryExpressionContext expression) { + if(expression.preIncrementExpression() != null){ + return convert(expression.preIncrementExpression()); + }else if(expression.preDecrementExpression() != null){ + return convert(expression.preDecrementExpression()); + }else if(expression.unaryExpressionNotPlusMinus() != null){ + return convert(expression.unaryExpressionNotPlusMinus()); + }else if(expression.getText().startsWith("+")){ + return new UnaryPlus(convert(expression.unaryExpression())); + }else if(expression.getText().startsWith("-")){ + return new UnaryMinus(convert(expression.unaryExpression())); + }else{ + //Diese Exceptions sollte nie geworfen werden. + //Der Code wurde nur noch nicht getestet. Sollte zur Sicherheit drin bleiben. + throw new NotImplementedException(); + } + } + + private static Expr convert(Java8Parser.UnaryExpressionNotPlusMinusContext expression) { + if(expression.postfixExpression() != null){ + return convert(expression.postfixExpression()); + }else if(expression.castExpression() != null){ + return convert(expression.castExpression()); + }else{ + throw new NotImplementedException(); + } + } + + private static Expr convert(Java8Parser.PostfixExpressionContext expression) { + Expr expr; + if(expression.primary() != null){ + expr = convert(expression.primary()); + }else{ + expr = convert(expression.expressionName()); + } + if(expression.postDecrementExpression_lf_postfixExpression() == null && + expression.postIncrementExpression_lf_postfixExpression() == null){ + return expr; + } + + for(Java8Parser.PostIncrementExpression_lf_postfixExpressionContext inc : expression.postIncrementExpression_lf_postfixExpression()){ + expr = new PostIncExpr(expr); + } + for(Java8Parser.PostDecrementExpression_lf_postfixExpressionContext dec : expression.postDecrementExpression_lf_postfixExpression()){ + expr = new PostDecExpr(expr); + } + + return expr; + } + + private static Expr convert(Java8Parser.PrimaryContext primary) { + Expr expr; + if(primary.primaryNoNewArray_lfno_primary()!=null){ + expr = convert(primary.primaryNoNewArray_lfno_primary()); + }else{ + expr = convert(primary.arrayCreationExpression()); + } + + if(primary.primaryNoNewArray_lf_primary() != null && primary.primaryNoNewArray_lf_primary().size()>0){ + for(Java8Parser.PrimaryNoNewArray_lf_primaryContext e : primary.primaryNoNewArray_lf_primary()){ + expr = new LocalOrFieldVarOrClassname(expr, e.getText()); + } + } + return expr; + } + + private static Expr convert(Java8Parser.PrimaryNoNewArray_lfno_primaryContext expression) { + if(expression.literal() != null){ + return convert(expression.literal()); + }else if(expression.expression()!=null){ + return convert(expression.expression()); + }else if(expression.methodInvocation_lfno_primary() != null){ + return convert(expression.methodInvocation_lfno_primary()); + }else{ + throw new NotImplementedException(); + } + } + + private static Expr convert(Java8Parser.MethodInvocation_lfno_primaryContext expression) { + throw new NotImplementedException(); + } + + private static Expr convert(Java8Parser.LambdaExpressionContext expression) { + throw new NotImplementedException(); + } + } diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeStatementGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeStatementGenerator.java deleted file mode 100644 index c802ec21..00000000 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeStatementGenerator.java +++ /dev/null @@ -1,308 +0,0 @@ -package de.dhbwstuttgart.parser; - -import de.dhbwstuttgart.parser.antlr.Java8Parser; -import de.dhbwstuttgart.syntaxtree.*; -import de.dhbwstuttgart.syntaxtree.modifier.*; -import de.dhbwstuttgart.syntaxtree.modifier.fieldModifier.*; -import de.dhbwstuttgart.syntaxtree.modifier.methodModifier.MethodModifier; -import de.dhbwstuttgart.syntaxtree.statement.*; -import de.dhbwstuttgart.syntaxtree.type.RefType; -import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; -import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; -import de.dhbwstuttgart.typecheck.JavaClassName; -import de.dhbwstuttgart.typecheck.JavaClassRegistry; -import org.antlr.v4.runtime.Token; -import org.antlr.v4.runtime.tree.TerminalNode; -import sun.reflect.generics.reflectiveObjects.NotImplementedException; - -import java.util.ArrayList; -import java.util.List; - -public class SyntaxTreeStatementGenerator { - - public static StatementReturn convert(Java8Parser.StatementContext stmt) { - if (stmt.statementWithoutTrailingSubstatement() != null) { - return convert(stmt.statementWithoutTrailingSubstatement()); - } else if (stmt.whileStatement() != null) { - return convert(stmt.whileStatement()); - } else if (stmt.forStatement() != null) { - return convert(stmt.forStatement()); - } else if (stmt.ifThenElseStatement() != null) { - return convert(stmt.ifThenElseStatement()); - } else if (stmt.ifThenStatement() != null) { - return convert(stmt.ifThenStatement()); - } else if (stmt.labeledStatement() != null) { - return convert(stmt.labeledStatement() ); - }else throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.StatementNoShortIfContext stmt){ - if(stmt.statementWithoutTrailingSubstatement() != null){ - return convert(stmt.statementWithoutTrailingSubstatement()); - }else if(stmt.labeledStatementNoShortIf() != null){ - return convert(stmt.labeledStatementNoShortIf()); - }else if(stmt.ifThenElseStatementNoShortIf() != null){ - return convert(stmt.ifThenElseStatementNoShortIf()); - }else if(stmt.whileStatementNoShortIf() != null){ - return convert(stmt.whileStatementNoShortIf()); - }else if(stmt.forStatementNoShortIf() != null){ - return convert(stmt.forStatementNoShortIf()); - }else throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.StatementWithoutTrailingSubstatementContext stmt) { - if(stmt.block() != null){ - return convert(stmt.block()); - }else if(stmt.emptyStatement() != null){ - return new StatementReturn(new EmptyStmt()); - }else if(stmt.expressionStatement() != null){ - return convert(stmt.expressionStatement()); - }else if(stmt.assertStatement() != null){ - return convert(stmt.assertStatement()); - }else if(stmt.switchStatement() != null){ - return convert(stmt.switchStatement()); - }else if(stmt.doStatement() != null){ - return convert(stmt.doStatement()); - }else if(stmt.breakStatement() != null){ - return convert(stmt.breakStatement()); - }else if(stmt.continueStatement() != null){ - return convert(stmt.continueStatement()); - }else if(stmt.returnStatement() != null){ - return convert(stmt.returnStatement()); - }else if(stmt.synchronizedStatement() != null){ - return convert(stmt.synchronizedStatement()); - }else if(stmt.throwStatement() != null){ - return convert(stmt.throwStatement()); - }else if(stmt.tryStatement() != null){ - return convert(stmt.tryStatement()); - }else throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.LabeledStatementContext labeledStatementContext) { - throw new NotImplementedException(); - //return convert(labeledStatementContext.statement()); - } - - private static StatementReturn convert(Java8Parser.LabeledStatementNoShortIfContext stmt){ - throw new NotImplementedException(); - //return convert(stmt.statementNoShortIf()); - } - - private static StatementReturn convert(Java8Parser.ExpressionStatementContext stmt){ - return convert(stmt.statementExpression()); - } - - private static StatementReturn convert(Java8Parser.StatementExpressionContext stmt) { - if(stmt.assignment() != null){ - return convert(stmt.assignment()); - }else if(stmt.preIncrementExpression() != null){ - return convert(stmt.preIncrementExpression()); - }else if(stmt.preDecrementExpression() != null){ - return convert(stmt.preDecrementExpression()); - }else if(stmt.postIncrementExpression() != null){ - return convert(stmt.postIncrementExpression()); - }else if(stmt.postDecrementExpression() != null){ - return convert(stmt.postDecrementExpression()); - }else if(stmt.methodInvocation() != null){ - return convert(stmt.methodInvocation()); - }else if(stmt.classInstanceCreationExpression() != null){ - return convert(stmt.classInstanceCreationExpression()); - }else throw new NotImplementedException(); - } - - private StatementReturn convert(Java8Parser.MethodInvocationContext methodInvocationContext) { - String name = methodInvocationContext.methodName().Identifier().getText(); - Expr receiver; - if(methodInvocationContext.typeName() == null){ - receiver = new This(methodInvocationContext.getStart()); - }else{ - receiver = convert(methodInvocationContext.typeName()); - } - - ArgumentList argumentList = null; - MethodCall ret = new MethodCall(new Receiver(receiver), name, argumentList, methodInvocationContext.getStart()); - return new StatementReturn(ret); - } - - private static StatementReturn convert(Java8Parser.ClassInstanceCreationExpressionContext stmt) { - //TODO - throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.PreIncrementExpressionContext stmt) { - //TODO - throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.PreDecrementExpressionContext stmt) { - //TODO - throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.PostIncrementExpressionContext stmt) { - //TODO - throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.PostDecrementExpressionContext stmt) { - //TODO - throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.AssignmentContext stmt) { - //TODO - //return new StatementReturn(new Assign()) - throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.IfThenStatementContext stmt){ - //TODO - throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.IfThenElseStatementContext stmt){ - //TODO - throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.IfThenElseStatementNoShortIfContext stmt){ - //TODO - throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.AssertStatementContext stmt){ - //TODO - throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.SwitchStatementContext stmt){ - //TODO - throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.SwitchBlockContext stmt){ - //TODO - throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.SwitchBlockStatementGroupContext stmt){ - //TODO - throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.WhileStatementContext stmt){ - //TODO - throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.WhileStatementNoShortIfContext stmt){ - //TODO - throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.DoStatementContext stmt){ - //TODO - throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.ForStatementContext stmt){ - if(stmt.basicForStatement() != null){ - return convert(stmt.basicForStatement()); - }else if(stmt.enhancedForStatement() != null){ - return convert(stmt.enhancedForStatement()); - }else throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.ForStatementNoShortIfContext stmt){ - if(stmt.basicForStatementNoShortIf() != null){ - return convert(stmt.basicForStatementNoShortIf()); - }else if(stmt.enhancedForStatementNoShortIf() != null){ - return convert(stmt.enhancedForStatementNoShortIf()); - }else throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.BasicForStatementContext stmt){ - //TODO - throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.BasicForStatementNoShortIfContext stmt){ - //TODO - throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.ForInitContext stmt){ - if(stmt.statementExpressionList() != null){ - return convert(stmt.statementExpressionList()); - }else if(stmt.localVariableDeclaration() != null){ - return convert(stmt.localVariableDeclaration()); - }else throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.ForUpdateContext stmt){ - return convert(stmt.statementExpressionList()); - } - - private static StatementReturn convert(Java8Parser.StatementExpressionListContext stmt){ - //TODO - throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.EnhancedForStatementContext stmt){ - //TODO - throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.EnhancedForStatementNoShortIfContext stmt){ - //TODO - throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.BreakStatementContext stmt){ - //TODO - throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.ContinueStatementContext stmt){ - //TODO - throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.ReturnStatementContext stmt){ - return new StatementReturn(new Return(convert(stmt.expression()),stmt.getStart())); - } - - private static StatementReturn convert(Java8Parser.ThrowStatementContext stmt){ - //TODO - throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.SynchronizedStatementContext stmt){ - //TODO - throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.TryStatementContext stmt){ - //TODO - throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.CatchesContext stmt){ - //TODO - throw new NotImplementedException(); - } - - private static StatementReturn convert(Java8Parser.CatchClauseContext stmt){ - //TODO - throw new NotImplementedException(); - } - - - -} - -class StatementReturn{ - public StatementReturn(Statement statement){ - - } -} \ No newline at end of file diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/AndOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/AndOp.java index d2d2e700..945bd0b6 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/AndOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/AndOp.java @@ -2,14 +2,15 @@ package de.dhbwstuttgart.syntaxtree.operator; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.statement.Binary; +import org.antlr.v4.runtime.Token; import org.apache.bcel.generic.InstructionList; public class AndOp extends LogOp { - public AndOp(int offset, int variableLength) + public AndOp(Token offset) { - super(offset,variableLength); + super(offset); } diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/LogOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/LogOp.java index 595d7e2b..ced15bf3 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/LogOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/LogOp.java @@ -1,4 +1,6 @@ package de.dhbwstuttgart.syntaxtree.operator; +import org.antlr.v4.runtime.Token; + import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; @@ -8,7 +10,7 @@ import java.util.Iterator; public abstract class LogOp extends Operator { - public LogOp(int offset, int variableLength) + public LogOp(Token offset) { } diff --git a/src/de/dhbwstuttgart/syntaxtree/operator/OrOp.java b/src/de/dhbwstuttgart/syntaxtree/operator/OrOp.java index 66581ab4..856be57d 100755 --- a/src/de/dhbwstuttgart/syntaxtree/operator/OrOp.java +++ b/src/de/dhbwstuttgart/syntaxtree/operator/OrOp.java @@ -1,21 +1,14 @@ package de.dhbwstuttgart.syntaxtree.operator; -import org.apache.bcel.Constants; -import org.apache.bcel.generic.BranchInstruction; -import org.apache.bcel.generic.GOTO; -import org.apache.bcel.generic.IFEQ; -import org.apache.bcel.generic.IFNE; -import org.apache.bcel.generic.InstructionConstants; -import org.apache.bcel.generic.InstructionList; -import org.apache.bcel.generic.ObjectType; +import org.antlr.v4.runtime.Token; public class OrOp extends LogOp { - public OrOp(int offset, int variableLength) + public OrOp(Token offset) { - super(offset,variableLength); + super(offset); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java b/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java index f0cc1fa3..d38ba089 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java @@ -17,6 +17,8 @@ public class Binary extends BinaryExpr super(null); } - + public Binary(Expr expr1, Expr expr2, Operator op){ + super(null); + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/BinaryExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/BinaryExpr.java index 1ee156fc..7d9270e0 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/BinaryExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/BinaryExpr.java @@ -3,7 +3,7 @@ package de.dhbwstuttgart.syntaxtree.statement; import org.antlr.v4.runtime.Token; -public abstract class BinaryExpr extends Expr +public abstract class BinaryExpr extends Expression { public BinaryExpr(Token offset) diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java index 77194997..e265e7f5 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java @@ -3,7 +3,7 @@ package de.dhbwstuttgart.syntaxtree.statement; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; -public class CastExpr extends Expr +public class CastExpr extends Expression { public CastExpr(RefTypeOrTPH castType, Expr expr, int offset) { diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Executable.java b/src/de/dhbwstuttgart/syntaxtree/statement/Executable.java deleted file mode 100755 index 1251f92c..00000000 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Executable.java +++ /dev/null @@ -1,17 +0,0 @@ - -package de.dhbwstuttgart.syntaxtree.statement; - -import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; -import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; -import org.antlr.v4.runtime.Token; - -public abstract class Executable extends SyntaxTreeNode -{ - private RefTypeOrTPH type; - - public Executable(RefTypeOrTPH type, Token offset) { - this.type = type; - } - - //public abstract String getTypeInformation(); -} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Expr.java b/src/de/dhbwstuttgart/syntaxtree/statement/Expr.java index 9889b293..b7f9c707 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Expr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Expr.java @@ -5,11 +5,6 @@ import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; import org.antlr.v4.runtime.Token; -public abstract class Expr extends Executable +public interface Expr { - - public Expr(RefTypeOrTPH type, Token offset) { - super(type, offset); - } - } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/ExprStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/ExprStmt.java index c0108c9e..05ad9090 100644 --- a/src/de/dhbwstuttgart/syntaxtree/statement/ExprStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/ExprStmt.java @@ -3,7 +3,7 @@ package de.dhbwstuttgart.syntaxtree.statement; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; import org.antlr.v4.runtime.Token; -public abstract class ExprStmt extends Executable { +public abstract class ExprStmt extends Statement implements Expr { public ExprStmt(RefTypeOrTPH type, Token offset) { super(type, offset); diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Expression.java b/src/de/dhbwstuttgart/syntaxtree/statement/Expression.java new file mode 100755 index 00000000..c73cd282 --- /dev/null +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Expression.java @@ -0,0 +1,14 @@ + +package de.dhbwstuttgart.syntaxtree.statement; + + +import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; +import org.antlr.v4.runtime.Token; + +public class Expression extends SyntaxTreeNode implements Expr +{ + public Expression(RefTypeOrTPH type, Token offset){ + + } +} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/InstVar.java b/src/de/dhbwstuttgart/syntaxtree/statement/InstVar.java index edd319e6..708b19cb 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/InstVar.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/InstVar.java @@ -3,20 +3,19 @@ import java.util.Enumeration; import java.util.Hashtable; import java.util.Iterator; +import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import org.apache.bcel.generic.ClassGen; import org.apache.bcel.generic.InstructionList; -public class InstVar extends Expr +public class InstVar extends SyntaxTreeNode implements Expr { private Expr expr; - protected String type; //???? BRAUCHT MAN DEN??? - public InstVar(Expr e, String n, int offset) + public InstVar(Expr instanz, String name, int offset) { - super(null,null); - expr = e; + expr = instanz; } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java b/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java index 4fbf7b2f..e6c55349 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java @@ -1,6 +1,7 @@ package de.dhbwstuttgart.syntaxtree.statement; import de.dhbwstuttgart.syntaxtree.ParameterList; +import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.type.FunN; /** @@ -10,7 +11,7 @@ import de.dhbwstuttgart.syntaxtree.type.FunN; * LambdaExpression Aufbau: * ( ParameterList ) -> { method_body }; */ -public class LambdaExpression extends Expr{ +public class LambdaExpression extends Expression{ /** @@ -22,7 +23,7 @@ public class LambdaExpression extends Expr{ private ParameterList params; public LambdaExpression(int offset, int variableLength) { - super(null, null); + super(null,null); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Literal.java b/src/de/dhbwstuttgart/syntaxtree/statement/Literal.java index 17c734a2..2136e303 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Literal.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Literal.java @@ -3,7 +3,7 @@ package de.dhbwstuttgart.syntaxtree.statement; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; -public abstract class Literal extends Expr +public abstract class Literal extends Expression { // Gibt an, ob das Literal fuer einen Objekttyp oder // als primitive Konstante generiert werden soll. diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVarOrClassname.java b/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVarOrClassname.java index e5692873..7945ea6d 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVarOrClassname.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVarOrClassname.java @@ -14,8 +14,15 @@ import org.apache.bcel.generic.ObjectType; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; - -public class LocalOrFieldVarOrClassname extends Expr +/* +* Ausdrücke der Form [Identifier....]Identifier werden zu dieser Klasse geparst. +* Typinferenzalgorithmus muss herausfinden um was es sich handelt: +* Es können folgende Dinge sein +* package.name.Classname - Classname +* LocalOrFieldVarOrClassname.FieldVar[.Fieldvar...] - FieldVar +* Identifier - Lokale Variable oder FieldVar +*/ +public class LocalOrFieldVarOrClassname extends Expression { private final String name; @@ -29,5 +36,12 @@ public class LocalOrFieldVarOrClassname extends Expr } + public LocalOrFieldVarOrClassname(Expr e1, String access) + { + super(TypePlaceholder.fresh(null),null); + this.name = n; + } + + } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarBunchDeclaration.java b/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarBunchDeclaration.java new file mode 100644 index 00000000..3a724efc --- /dev/null +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarBunchDeclaration.java @@ -0,0 +1,16 @@ +package de.dhbwstuttgart.syntaxtree.statement; + +import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; +import de.dhbwstuttgart.syntaxtree.type.Void; +import org.antlr.v4.runtime.Token; + +import java.util.List; + +/** + * Created by janulrich on 27.02.17. + */ +public class LocalVarBunchDeclaration extends Statement { + public LocalVarBunchDeclaration(List declarations, Token start) { + super(new Void(start), start); + } +} diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java b/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java index d203aa00..937bf3dc 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java @@ -15,7 +15,7 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; -public class MethodCall extends Statement +public class MethodCall extends ExprStmt { public MethodCall(Receiver receiver, String methodName, ArgumentList argumentList, Token offset){ super(TypePlaceholder.fresh(offset),offset); diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/NewArray.java b/src/de/dhbwstuttgart/syntaxtree/statement/NewArray.java index 360280ce..281d7f20 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/NewArray.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/NewArray.java @@ -4,7 +4,7 @@ import java.util.List; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; -public class NewArray extends Expr +public class NewArray extends Expression { public NewArray(int offset,int variableLength) { diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java b/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java index ee1c33e2..11830845 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java @@ -7,7 +7,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; -public class NewClass extends Expr +public class NewClass extends ExprStmt { public NewClass(int offset,int variableLength) { diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java index e8d0d0e5..94411a75 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/PostDecExpr.java @@ -2,21 +2,20 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.Hashtable; import java.util.Iterator; +import de.dhbwstuttgart.parser.antlr.Java8Parser; import org.apache.bcel.generic.ClassGen; import org.apache.bcel.generic.InstructionList; -public class PostDecExpr extends UnaryExpr +public class PostDecExpr extends PostIncExpr { - public PostDecExpr(int offset,int variableLength) - { - super(offset,variableLength); + + public PostDecExpr(Expr expr) { + super(expr); } - - - + public void set_Expr(Expr ex) { this.expr = ex; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java index a3110267..05b323ac 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/PostIncExpr.java @@ -15,13 +15,11 @@ import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; public class PostIncExpr extends UnaryExpr { - public PostIncExpr(int offset,int variableLength) - { - super(offset,variableLength); + public PostIncExpr(Expr expr) { + super(null); } - - + public void set_Expr(Expr ex) { this.expr = ex; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Return.java b/src/de/dhbwstuttgart/syntaxtree/statement/Return.java index 5b1119fb..9bdece76 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Return.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Return.java @@ -15,7 +15,7 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; public class Return extends Statement { - public Return(Statement retExpr, Token offset) + public Return(Expr retExpr, Token offset) { super(null,null); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java b/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java index 7c6310f2..3cfd8815 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java @@ -1,16 +1,17 @@ package de.dhbwstuttgart.syntaxtree.statement; +import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; import org.antlr.v4.runtime.Token; -public abstract class Statement extends Executable +public abstract class Statement extends SyntaxTreeNode { public Statement(RefTypeOrTPH type, Token offset) { - super(type,offset); + } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/This.java b/src/de/dhbwstuttgart/syntaxtree/statement/This.java index 461a131d..39a0aebf 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/This.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/This.java @@ -3,7 +3,7 @@ package de.dhbwstuttgart.syntaxtree.statement; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; import org.antlr.v4.runtime.Token; -public class This extends Expr +public class This extends Expression { public This(Token offset) { diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/UnaryExpr.java index 53c4fb37..55c15b94 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/UnaryExpr.java @@ -1,12 +1,13 @@ package de.dhbwstuttgart.syntaxtree.statement; +import org.antlr.v4.runtime.Token; public abstract class UnaryExpr extends MethodCall { public Expr expr; - public UnaryExpr(int offset,int variableLength) + public UnaryExpr(Token offset) { super(null,null,null,null); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryMinus.java b/src/de/dhbwstuttgart/syntaxtree/statement/UnaryMinus.java index 7247a988..d6dcbb46 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryMinus.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/UnaryMinus.java @@ -1,9 +1,12 @@ package de.dhbwstuttgart.syntaxtree.statement; -public class UnaryMinus +import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; + +public class UnaryMinus extends UnaryPlus { - - + public UnaryMinus(Expr expression) { + super(expression); + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryPlus.java b/src/de/dhbwstuttgart/syntaxtree/statement/UnaryPlus.java index bedd66bd..f473f4f2 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryPlus.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/UnaryPlus.java @@ -1,5 +1,10 @@ package de.dhbwstuttgart.syntaxtree.statement; -public class UnaryPlus -{ +import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; + +public class UnaryPlus extends SyntaxTreeNode implements Expr +{ + public UnaryPlus(Expr expression){ + + } }