From 656b014ad4753624d6188d6951389e285180c8fd Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Fri, 17 Feb 2017 16:34:40 +0100 Subject: [PATCH] Parser um return und method call erweitern --- .../parser/CompilationUnitEvaluator.java | 25 ------- .../parser/SyntaxTreeGenerator.java | 66 +++++++++++++++++++ src/de/dhbwstuttgart/parser/antlr/Java8.g4 | 2 +- .../syntaxtree/statement/Assign.java | 3 +- .../syntaxtree/statement/Binary.java | 2 +- .../syntaxtree/statement/BinaryExpr.java | 9 +-- .../syntaxtree/statement/Block.java | 5 +- .../syntaxtree/statement/CastExpr.java | 2 +- .../syntaxtree/statement/EmptyStmt.java | 2 +- .../{Executeable.java => Executable.java} | 5 +- .../syntaxtree/statement/Expr.java | 5 +- .../syntaxtree/statement/ExprStmt.java | 5 +- .../syntaxtree/statement/ForStmt.java | 2 +- .../syntaxtree/statement/IfStmt.java | 2 +- .../syntaxtree/statement/InstVar.java | 2 +- .../syntaxtree/statement/InstanceOf.java | 2 +- .../statement/LambdaExpression.java | 2 +- .../syntaxtree/statement/Literal.java | 2 +- .../statement/LocalOrFieldVarOrClassname.java | 15 ++--- .../syntaxtree/statement/LocalVarDecl.java | 14 ++-- .../syntaxtree/statement/MethodCall.java | 13 ++-- .../syntaxtree/statement/NewArray.java | 2 +- .../syntaxtree/statement/NewClass.java | 2 +- .../syntaxtree/statement/Return.java | 6 +- .../syntaxtree/statement/Statement.java | 5 +- .../syntaxtree/statement/This.java | 9 +-- .../syntaxtree/statement/ThisCall.java | 2 +- .../syntaxtree/statement/UnaryExpr.java | 2 +- .../syntaxtree/statement/WhileStmt.java | 2 +- test/parser/GeneralParserTest.java | 1 + test/parser/StatementsTest.jav | 8 +++ 31 files changed, 139 insertions(+), 85 deletions(-) delete mode 100644 src/de/dhbwstuttgart/parser/CompilationUnitEvaluator.java rename src/de/dhbwstuttgart/syntaxtree/statement/{Executeable.java => Executable.java} (63%) create mode 100644 test/parser/StatementsTest.jav diff --git a/src/de/dhbwstuttgart/parser/CompilationUnitEvaluator.java b/src/de/dhbwstuttgart/parser/CompilationUnitEvaluator.java deleted file mode 100644 index af5935ce..00000000 --- a/src/de/dhbwstuttgart/parser/CompilationUnitEvaluator.java +++ /dev/null @@ -1,25 +0,0 @@ -package de.dhbwstuttgart.parser; -import de.dhbwstuttgart.parser.antlr.Java8BaseListener; -import de.dhbwstuttgart.parser.antlr.Java8Parser; - -public class CompilationUnitEvaluator extends Java8BaseListener { - @Override - public void enterCompilationUnit(Java8Parser.CompilationUnitContext ctx) { - System.out.println("SourceFile("); - } - @Override - public void exitCompilationUnit(Java8Parser.CompilationUnitContext ctx) { - System.out.println(")"); - } - - @Override - public void enterPackageDeclaration(Java8Parser.PackageDeclarationContext ctx) { - System.out.println("package("); - } - - @Override - public void exitPackageDeclaration(Java8Parser.PackageDeclarationContext ctx) { - System.out.println(ctx.Identifier()); - System.out.println(")"); - } -} diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java index 685841ad..8339e717 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java @@ -1,5 +1,6 @@ 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.*; @@ -178,6 +179,71 @@ public class SyntaxTreeGenerator{ } 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(); + if(stmt.statementWithoutTrailingSubstatement() != null){ + if(stmt.statementWithoutTrailingSubstatement().returnStatement() != null){ + Java8Parser.ReturnStatementContext returnStatementContext = stmt.statementWithoutTrailingSubstatement().returnStatement(); + Statement retExpr = convert(returnStatementContext.expression()); + ret.add(new Return(retExpr,returnStatementContext.getStart())); + }else if(stmt.statementWithoutTrailingSubstatement().expressionStatement().statementExpression().methodInvocation() != null){ + Java8Parser.MethodInvocationContext methodInvocationContext = stmt.statementWithoutTrailingSubstatement().expressionStatement().statementExpression().methodInvocation(); + ret.add(convert(methodInvocationContext)); + }else throw new NotImplementedException(); + + }else if(stmt.whileStatement() != null){ + throw new NotImplementedException(); + + }else throw new NotImplementedException(); + return ret; + } + } + + private Statement 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; + return new MethodCall(new Receiver(receiver), name, argumentList, methodInvocationContext.getStart()); + } + + private Expr convert(Java8Parser.TypeNameContext typeNameContext) { + return null; + } + + private Statement convert(Java8Parser.ExpressionContext expression) { return null; } diff --git a/src/de/dhbwstuttgart/parser/antlr/Java8.g4 b/src/de/dhbwstuttgart/parser/antlr/Java8.g4 index eb2b7bf6..c79f52ba 100644 --- a/src/de/dhbwstuttgart/parser/antlr/Java8.g4 +++ b/src/de/dhbwstuttgart/parser/antlr/Java8.g4 @@ -352,7 +352,7 @@ variableDeclaratorList ; variableDeclarator - : variableDeclaratorId ('=' variableInitializer)? + : variableDeclaratorId //('=' variableInitializer)? //auskommentiert, weil variablenDecklaration sonst nicht eindeutig ; variableDeclaratorId diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java b/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java index ed0717c0..9dd8a2de 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Assign.java @@ -2,12 +2,13 @@ package de.dhbwstuttgart.syntaxtree.statement; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; +import org.antlr.v4.runtime.Token; public class Assign extends ExprStmt { - public Assign(RefTypeOrTPH type, int offset) { + public Assign(RefTypeOrTPH type, Token offset) { super(type, offset); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java b/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java index 333cfce8..f0cc1fa3 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Binary.java @@ -14,7 +14,7 @@ public class Binary extends BinaryExpr public Binary(int offset, int variableLength) { - super(offset,variableLength); + super(null); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/BinaryExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/BinaryExpr.java index 29a3e719..1ee156fc 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/BinaryExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/BinaryExpr.java @@ -1,17 +1,14 @@ package de.dhbwstuttgart.syntaxtree.statement; +import org.antlr.v4.runtime.Token; public abstract class BinaryExpr extends Expr { - public BinaryExpr(int offset,int variableLength) + public BinaryExpr(Token offset) { - super(null,variableLength); + super(null,null); } - - - // abstract public void if_codegen(ClassFile classfile, Code_attribute code, boolean sw) throws jvmCode_Exception; - // abstract public void not_codegen(ClassFile classfile, Code_attribute code) throws jvmCode_Exception; } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Block.java b/src/de/dhbwstuttgart/syntaxtree/statement/Block.java index 8be8c275..7d949658 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Block.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Block.java @@ -1,6 +1,7 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.*; +import org.antlr.v4.runtime.Token; import org.apache.bcel.Constants; import org.apache.bcel.generic.ClassGen; import org.apache.bcel.generic.ConstantPoolGen; @@ -18,8 +19,8 @@ public class Block extends Statement private ConstantPoolGen _cp; private ClassGen _cg; - public Block(List statements, int offset) { - super(null, 0); + public Block(List statements, Token offset) { + super(null, offset); this.statements = statements; } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java index d116f9a7..77194997 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java @@ -7,7 +7,7 @@ public class CastExpr extends Expr { public CastExpr(RefTypeOrTPH castType, Expr expr, int offset) { - super(null, 0); + super(null, null); } public Expr expr; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/EmptyStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/EmptyStmt.java index b8896145..15b4acfc 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/EmptyStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/EmptyStmt.java @@ -12,7 +12,7 @@ public class EmptyStmt extends Statement { public EmptyStmt() { - super(null,-1); + super(null,null); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Executeable.java b/src/de/dhbwstuttgart/syntaxtree/statement/Executable.java similarity index 63% rename from src/de/dhbwstuttgart/syntaxtree/statement/Executeable.java rename to src/de/dhbwstuttgart/syntaxtree/statement/Executable.java index 699a4b2b..1251f92c 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Executeable.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Executable.java @@ -3,12 +3,13 @@ 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 Executeable extends SyntaxTreeNode +public abstract class Executable extends SyntaxTreeNode { private RefTypeOrTPH type; - public Executeable(RefTypeOrTPH type, int offset) { + public Executable(RefTypeOrTPH type, Token offset) { this.type = type; } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Expr.java b/src/de/dhbwstuttgart/syntaxtree/statement/Expr.java index 9b0e93d6..9889b293 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Expr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Expr.java @@ -2,12 +2,13 @@ package de.dhbwstuttgart.syntaxtree.statement; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; +import org.antlr.v4.runtime.Token; -public abstract class Expr extends Executeable +public abstract class Expr extends Executable { - public Expr(RefTypeOrTPH type, int offset) { + 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 ee088c16..c0108c9e 100644 --- a/src/de/dhbwstuttgart/syntaxtree/statement/ExprStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/ExprStmt.java @@ -1,10 +1,11 @@ package de.dhbwstuttgart.syntaxtree.statement; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; +import org.antlr.v4.runtime.Token; -public abstract class ExprStmt extends Executeable{ +public abstract class ExprStmt extends Executable { - public ExprStmt(RefTypeOrTPH type, int offset) { + public ExprStmt(RefTypeOrTPH type, Token offset) { super(type, offset); } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java index 9f9c1f95..aeeaf1c0 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/ForStmt.java @@ -18,7 +18,7 @@ public class ForStmt extends Statement public ForStmt(int offset, int variableLength) { - super(null,variableLength); + super(null,null); } void sc_check(List classname, Hashtable ch, Hashtable bh, boolean ext, Hashtable parach, Hashtable parabh) diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java index 365f9d4e..fa131b8b 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/IfStmt.java @@ -25,7 +25,7 @@ public class IfStmt extends Statement { public IfStmt(int offset, int variableLength) { - super(null,variableLength); + super(null,null); } public boolean hamaDebug = true; //hama: Debug Ausgaben von mir ein- bzw. ausschalten diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/InstVar.java b/src/de/dhbwstuttgart/syntaxtree/statement/InstVar.java index cd9e0151..edd319e6 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/InstVar.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/InstVar.java @@ -15,7 +15,7 @@ public class InstVar extends Expr protected String type; //???? BRAUCHT MAN DEN??? public InstVar(Expr e, String n, int offset) { - super(null,n.length()); + super(null,null); expr = e; } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/InstanceOf.java b/src/de/dhbwstuttgart/syntaxtree/statement/InstanceOf.java index 16b915f6..18a505f8 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/InstanceOf.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/InstanceOf.java @@ -13,7 +13,7 @@ public class InstanceOf extends BinaryExpr public InstanceOf(int offset,int variableLength) { - super(offset,variableLength); + super(null); // #JB# 20.04.2005 } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java b/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java index 2dfc862a..4fbf7b2f 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java @@ -22,7 +22,7 @@ public class LambdaExpression extends Expr{ private ParameterList params; public LambdaExpression(int offset, int variableLength) { - super(null, variableLength); + super(null, null); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Literal.java b/src/de/dhbwstuttgart/syntaxtree/statement/Literal.java index b3839628..17c734a2 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Literal.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Literal.java @@ -12,7 +12,7 @@ public abstract class Literal extends Expr private boolean primitiveFlag=true; public Literal(RefTypeOrTPH o, int i) { - super(null, i); + super(null, null); } public void setPrimitiveFlag(boolean b) diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVarOrClassname.java b/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVarOrClassname.java index 4e36219a..e5692873 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVarOrClassname.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LocalOrFieldVarOrClassname.java @@ -2,6 +2,8 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.Enumeration; import java.util.Hashtable; +import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; +import org.antlr.v4.runtime.Token; import org.apache.bcel.Constants; import org.apache.bcel.generic.ClassGen; import org.apache.bcel.generic.Instruction; @@ -16,17 +18,14 @@ import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; public class LocalOrFieldVarOrClassname extends Expr { - private boolean isFieldAccess = false; + private final String name; + private boolean isFieldAccess = false; private boolean isClassAccess = false; - public LocalOrFieldVarOrClassname(int offset, int variableLength) + public LocalOrFieldVarOrClassname(String n, Token offset) { - super(null,variableLength); - } - - public LocalOrFieldVarOrClassname(String n, int offset) - { - super(null,n.length()); + super(TypePlaceholder.fresh(offset),offset); + this.name = n; } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java b/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java index 568d11f7..b5b4271b 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LocalVarDecl.java @@ -1,13 +1,19 @@ package de.dhbwstuttgart.syntaxtree.statement; +import de.dhbwstuttgart.syntaxtree.type.RefType; +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; +import org.antlr.v4.runtime.Token; + public class LocalVarDecl extends Statement { - public LocalVarDecl(int offset,int variableLength) + + private String name; + + public LocalVarDecl(String name, RefTypeOrTPH type, Token offset) { - super(null,variableLength); + super(type, offset); + this.name = name; } - public Block block; - } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java b/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java index 99781c4c..d203aa00 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java @@ -1,6 +1,7 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.Hashtable; +import org.antlr.v4.runtime.Token; import org.apache.bcel.Const; import org.apache.bcel.Constants; import org.apache.bcel.generic.ClassGen; @@ -14,17 +15,13 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; -public class MethodCall extends Expr +public class MethodCall extends Statement { - public MethodCall(Receiver receiver, String methodName, ArgumentList argumentList, int offset){ - this(offset, 0); + public MethodCall(Receiver receiver, String methodName, ArgumentList argumentList, Token offset){ + super(TypePlaceholder.fresh(offset),offset); this.set_ArgumentList(argumentList); } - - public MethodCall(int offset, int variableLength) - { - super(null,variableLength); - } + /** * Diese Variable speichert die Expression, welche die Klasse von welcher die Methode aufgerufen wird darstellt. diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/NewArray.java b/src/de/dhbwstuttgart/syntaxtree/statement/NewArray.java index 38b38591..360280ce 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/NewArray.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/NewArray.java @@ -8,7 +8,7 @@ public class NewArray extends Expr { public NewArray(int offset,int variableLength) { - super(null,variableLength); + super(null,null); } private RefTypeOrTPH type; public List expr; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java b/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java index 63d9ce4e..ee1c33e2 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/NewClass.java @@ -11,7 +11,7 @@ public class NewClass extends Expr { public NewClass(int offset,int variableLength) { - super(null,variableLength); + super(null,null); } private ArgumentList arglist; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Return.java b/src/de/dhbwstuttgart/syntaxtree/statement/Return.java index a0eb8ba0..5b1119fb 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Return.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Return.java @@ -1,6 +1,8 @@ package de.dhbwstuttgart.syntaxtree.statement; import java.util.Hashtable; +import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; +import org.antlr.v4.runtime.Token; import org.apache.bcel.generic.ConstantPoolGen; import org.apache.bcel.generic.InstructionFactory; import org.apache.bcel.generic.InstructionList; @@ -13,9 +15,9 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; public class Return extends Statement { - public Return(int offset,int variableLength) + public Return(Statement retExpr, Token offset) { - super(null,variableLength); + super(null,null); } public Expr retexpr; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java b/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java index 62560830..7c6310f2 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/Statement.java @@ -1,13 +1,14 @@ package de.dhbwstuttgart.syntaxtree.statement; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; +import org.antlr.v4.runtime.Token; -public abstract class Statement extends Executeable +public abstract class Statement extends Executable { - public Statement(RefTypeOrTPH type, int offset) + 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 6cd80486..461a131d 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/This.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/This.java @@ -1,16 +1,13 @@ package de.dhbwstuttgart.syntaxtree.statement; import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode; +import org.antlr.v4.runtime.Token; public class This extends Expr { - public This(int offset,int variableLength) + public This(Token offset) { - super(null,variableLength); - } - - public This(SyntaxTreeNode parent){ - this(0,0); + super(null,null); } public ArgumentList arglist; diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/ThisCall.java b/src/de/dhbwstuttgart/syntaxtree/statement/ThisCall.java index 592c3cb0..8dea4bbd 100644 --- a/src/de/dhbwstuttgart/syntaxtree/statement/ThisCall.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/ThisCall.java @@ -8,7 +8,7 @@ public class ThisCall extends MethodCall { public ThisCall(Receiver receiver, ArgumentList arglist, int offset) { - super(null, null, null, 0); + super(null, null, null, null); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/UnaryExpr.java index d3b4cd06..53c4fb37 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/UnaryExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/UnaryExpr.java @@ -8,7 +8,7 @@ public abstract class UnaryExpr extends MethodCall public UnaryExpr(int offset,int variableLength) { - super(offset,variableLength); + super(null,null,null,null); } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java b/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java index 4921961c..ceb7648a 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/WhileStmt.java @@ -5,7 +5,7 @@ public class WhileStmt extends Statement { public WhileStmt(int offset, int variableLength) { - super(null,variableLength); + super(null,null); } public Expr expr; diff --git a/test/parser/GeneralParserTest.java b/test/parser/GeneralParserTest.java index 4a6aeaf6..b19d2335 100644 --- a/test/parser/GeneralParserTest.java +++ b/test/parser/GeneralParserTest.java @@ -27,6 +27,7 @@ public class GeneralParserTest{ List filenames = new ArrayList(); filenames.add("FieldInitializationTest.jav"); filenames.add("ImportTest.jav"); + filenames.add("StatementsTest.jav"); filenames.add("ImportTestGeneric.jav"); //filenames.add("BoundedParameter.jav"); //filenames.add("GenericFieldVarTest.jav"); diff --git a/test/parser/StatementsTest.jav b/test/parser/StatementsTest.jav new file mode 100644 index 00000000..891dff12 --- /dev/null +++ b/test/parser/StatementsTest.jav @@ -0,0 +1,8 @@ +class Statements{ + +public void methodeTest(){ + methodeTest(); + return null; +} + +}