Parser erweitern

This commit is contained in:
JanUlrich 2017-03-01 15:34:57 +01:00
parent a51cef7100
commit 52f51c7932
28 changed files with 647 additions and 423 deletions

View File

@ -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<Statement> statements = new ArrayList<>();
if(block.blockStatements() != null)
for(Java8Parser.BlockStatementContext statementContext : block.blockStatements().blockStatement()){
List<Statement> stmt = convert(statementContext);
statements.addAll(stmt);
}
return new Block(statements, block.getStart());
}
private List<Statement> convert(Java8Parser.BlockStatementContext statementContext) {
List<Statement> 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<FormalParameter> ret = new ArrayList<>();
List<Java8Parser.FormalParameterContext> 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<de.dhbwstuttgart.syntaxtree.statement.Statement> 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<de.dhbwstuttgart.syntaxtree.statement.Statement> 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<LocalVarDecl> 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();
}
}

View File

@ -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){
}
}

View File

@ -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);
}

View File

@ -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)
{
}

View File

@ -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);
}

View File

@ -17,6 +17,8 @@ public class Binary extends BinaryExpr
super(null);
}
public Binary(Expr expr1, Expr expr2, Operator op){
super(null);
}
}

View File

@ -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)

View File

@ -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)
{

View File

@ -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();
}

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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){
}
}

View File

@ -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;
}
}

View File

@ -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);
}

View File

@ -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.

View File

@ -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;
}
}

View File

@ -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<LocalVarDecl> declarations, Token start) {
super(new Void(start), start);
}
}

View File

@ -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);

View File

@ -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)
{

View File

@ -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)
{

View File

@ -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;

View File

@ -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;

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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)
{

View File

@ -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);
}

View File

@ -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);
}
}

View File

@ -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){
}
}