convert(StatementContext) Implementierung fortgesetzt

This commit is contained in:
luca9913 2023-02-12 07:51:31 +01:00
parent 40d0d6b63e
commit 0e981ce95c
2 changed files with 448 additions and 387 deletions

View File

@ -521,25 +521,25 @@ localTypeDeclaration
; ;
statement statement
: blockLabel=block : blockLabel=block #blockstmt
| ASSERT expression (':' expression)? ';' | ASSERT expression (':' expression)? ';' #assertstmt
| IF parExpression statement (ELSE statement)? | IF parExpression statement (ELSE statement)? #conditionalstmt
| FOR '(' forControl ')' statement | FOR '(' forControl ')' statement #forloop
| WHILE parExpression statement | WHILE parExpression statement #whileloop
| DO statement WHILE parExpression ';' | DO statement WHILE parExpression ';' #dowhileloop
| TRY block (catchClause+ finallyBlock? | finallyBlock) | TRY block (catchClause+ finallyBlock? | finallyBlock) #trycatchblock
| TRY resourceSpecification block catchClause* finallyBlock? | TRY resourceSpecification block catchClause* finallyBlock? #trycatchresource
| SWITCH parExpression '{' switchBlockStatementGroup* switchLabel* '}' | SWITCH parExpression '{' switchBlockStatementGroup* switchLabel* '}' #switchstmt
| SYNCHRONIZED parExpression block | SYNCHRONIZED parExpression block #synchronizedstmt
| RETURN expression? ';' | RETURN expression? ';' #returnstmt
| THROW expression ';' | THROW expression ';' #throstmt
| BREAK identifier? ';' | BREAK identifier? ';' #breakstmt
| CONTINUE identifier? ';' | CONTINUE identifier? ';' #continuestmt
| YIELD expression ';' // Java17 | YIELD expression ';' #yieldstmt // Java17
| SEMI | SEMI #semistmt
| statementExpression=expression ';' | statementExpression=expression ';' #stmtexpression
| switchExpression ';'? // Java17 | switchExpression ';'? #switchexpression // Java17
| identifierLabel=identifier ':' statement | identifierLabel=identifier ':' statement #identifierlabel
; ;
catchClause catchClause

View File

@ -3,6 +3,10 @@ package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
import de.dhbwstuttgart.exceptions.NotImplementedException; import de.dhbwstuttgart.exceptions.NotImplementedException;
import de.dhbwstuttgart.parser.NullToken; import de.dhbwstuttgart.parser.NullToken;
import de.dhbwstuttgart.parser.antlr.Java17Parser; import de.dhbwstuttgart.parser.antlr.Java17Parser;
import de.dhbwstuttgart.parser.antlr.Java17Parser.AssertstmtContext;
import de.dhbwstuttgart.parser.antlr.Java17Parser.BlockstmtContext;
import de.dhbwstuttgart.parser.antlr.Java17Parser.ConditionalstmtContext;
import de.dhbwstuttgart.parser.antlr.Java17Parser.ForloopContext;
import de.dhbwstuttgart.parser.scope.GenericsRegistry; import de.dhbwstuttgart.parser.scope.GenericsRegistry;
import de.dhbwstuttgart.parser.scope.JavaClassRegistry; import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
import de.dhbwstuttgart.syntaxtree.*; import de.dhbwstuttgart.syntaxtree.*;
@ -22,11 +26,14 @@ import java.util.stream.Collectors;
public class StatementGenerator { public class StatementGenerator {
private JavaClassRegistry reg; private JavaClassRegistry reg;
private Map<String, RefTypeOrTPHOrWildcardOrGeneric> fields; //PL 2018-11-01 fields eingefuegt, damit die fields immer die gleiche TPH bekommen private Map<String, RefTypeOrTPHOrWildcardOrGeneric> fields; // PL 2018-11-01 fields eingefuegt, damit die fields
// immer die gleiche TPH bekommen
private Map<String, RefTypeOrTPHOrWildcardOrGeneric> localVars; private Map<String, RefTypeOrTPHOrWildcardOrGeneric> localVars;
private GenericsRegistry generics; private GenericsRegistry generics;
public StatementGenerator(JavaClassRegistry reg, GenericsRegistry generics, Map<String, RefTypeOrTPHOrWildcardOrGeneric> fields, Map<String, RefTypeOrTPHOrWildcardOrGeneric> localVars){ public StatementGenerator(JavaClassRegistry reg, GenericsRegistry generics,
Map<String, RefTypeOrTPHOrWildcardOrGeneric> fields,
Map<String, RefTypeOrTPHOrWildcardOrGeneric> localVars) {
this.reg = reg; this.reg = reg;
this.generics = generics; this.generics = generics;
this.fields = fields; this.fields = fields;
@ -39,19 +46,22 @@ public class StatementGenerator {
if (formalParameterListContext == null || formalParameterListContext.lastFormalParameter() == null) if (formalParameterListContext == null || formalParameterListContext.lastFormalParameter() == null)
return new ParameterList(ret, new NullToken()); // Dann ist die Parameterliste leer return new ParameterList(ret, new NullToken()); // Dann ist die Parameterliste leer
if(formalParameterListContext.lastFormalParameter().formalParameter() == null)throw new NotImplementedException(); /*
* Restrukturierung Java17-Grammatik
* Zeile wird nicht mehr benötigt, da Regel für Parameter-Liste nicht mehr
* rekursiv ist. "lastFormalParameter" hat kein Kind "formalParameter" mehr.
*
* if(formalParameterListContext.lastFormalParameter().formalParameter() ==
* null) throw new NotImplementedException();
*/
if(formalParameterListContext != null && formalParameterListContext.formalParameters() != null fps = formalParameterListContext.formalParameter();
&& formalParameterListContext.formalParameters().formalParameter() != null){
fps = new ArrayList<>(formalParameterListContext.formalParameters().formalParameter());
}
fps.add(formalParameterListContext.lastFormalParameter().formalParameter());
for (Java17Parser.FormalParameterContext fp : fps) { for (Java17Parser.FormalParameterContext fp : fps) {
String paramName = SyntaxTreeGenerator.convert(fp.variableDeclaratorId()); String paramName = SyntaxTreeGenerator.convert(fp.variableDeclaratorId());
RefTypeOrTPHOrWildcardOrGeneric type; RefTypeOrTPHOrWildcardOrGeneric type;
if(fp.unannType() != null){ if (fp.typeType() != null) {
type = TypeGenerator.convert(fp.unannType(), reg, generics); type = TypeGenerator.convert(fp.typeType(), reg, generics);
} else { } else {
type = TypePlaceholder.fresh(fp.getStart()); type = TypePlaceholder.fresh(fp.getStart());
} }
@ -66,6 +76,22 @@ public class StatementGenerator {
*/ */
private Statement convert(Java17Parser.StatementContext stmt) { private Statement convert(Java17Parser.StatementContext stmt) {
switch (stmt) {
case AssertstmtContext assertstmt:
return convert(assertstmt);
break;
case BlockstmtContext blockstmt:
return convert(blockstmt.block(), false);
break;
case ConditionalstmtContext condition:
return convert(condition);
break;
case ForloopContext forloop:
break;
default:
throw new NotImplementedException();
}
if (stmt.statementWithoutTrailingSubstatement() != null) { if (stmt.statementWithoutTrailingSubstatement() != null) {
return convert(stmt.statementWithoutTrailingSubstatement()); return convert(stmt.statementWithoutTrailingSubstatement());
} else if (stmt.whileStatement() != null) { } else if (stmt.whileStatement() != null) {
@ -78,22 +104,28 @@ public class StatementGenerator {
return convert(stmt.ifThenStatement()); return convert(stmt.ifThenStatement());
} else if (stmt.labeledStatement() != null) { } else if (stmt.labeledStatement() != null) {
return convert(stmt.labeledStatement()); return convert(stmt.labeledStatement());
}else throw new NotImplementedException(); } else
throw new NotImplementedException();
} }
private Statement convert(Java17Parser.StatementNoShortIfContext stmt){ /*
if(stmt.statementWithoutTrailingSubstatement() != null){ * Restrukturierung Java17-Grammatik
return convert(stmt.statementWithoutTrailingSubstatement()); * Fällt weg
}else if(stmt.labeledStatementNoShortIf() != null){ * private Statement convert(Java17Parser.StatementNoShortIfContext stmt) {
return convert(stmt.labeledStatementNoShortIf()); * if (stmt.statementWithoutTrailingSubstatement() != null) {
}else if(stmt.ifThenElseStatementNoShortIf() != null){ * return convert(stmt.statementWithoutTrailingSubstatement());
return convert(stmt.ifThenElseStatementNoShortIf()); * } else if (stmt.labeledStatementNoShortIf() != null) {
}else if(stmt.whileStatementNoShortIf() != null){ * return convert(stmt.labeledStatementNoShortIf());
return convert(stmt.whileStatementNoShortIf()); * } else if (stmt.ifThenElseStatementNoShortIf() != null) {
}else if(stmt.forStatementNoShortIf() != null){ * return convert(stmt.ifThenElseStatementNoShortIf());
return convert(stmt.forStatementNoShortIf()); * } else if (stmt.whileStatementNoShortIf() != null) {
}else throw new NotImplementedException(); * return convert(stmt.whileStatementNoShortIf());
} * } else if (stmt.forStatementNoShortIf() != null) {
* return convert(stmt.forStatementNoShortIf());
* } else
* throw new NotImplementedException();
* }
*/
private Statement convert(Java17Parser.StatementWithoutTrailingSubstatementContext stmt) { private Statement convert(Java17Parser.StatementWithoutTrailingSubstatementContext stmt) {
if (stmt.block() != null) { if (stmt.block() != null) {
@ -120,7 +152,8 @@ public class StatementGenerator {
return convert(stmt.throwStatement()); return convert(stmt.throwStatement());
} else if (stmt.tryStatement() != null) { } else if (stmt.tryStatement() != null) {
return convert(stmt.tryStatement()); return convert(stmt.tryStatement());
}else throw new NotImplementedException(); } else
throw new NotImplementedException();
} }
public Block convert(Java17Parser.BlockContext block, boolean addTrailingReturn) { public Block convert(Java17Parser.BlockContext block, boolean addTrailingReturn) {
@ -130,7 +163,8 @@ public class StatementGenerator {
List<Statement> stmt = convert(statementContext); List<Statement> stmt = convert(statementContext);
statements.addAll(stmt); statements.addAll(stmt);
} }
if(addTrailingReturn)statements = SyntacticSugar.addTrailingReturn(statements); if (addTrailingReturn)
statements = SyntacticSugar.addTrailingReturn(statements);
return new Block(statements, block.getStart()); return new Block(statements, block.getStart());
} }
@ -178,7 +212,8 @@ public class StatementGenerator {
return convert(stmt.methodInvocation()); return convert(stmt.methodInvocation());
} else if (stmt.classInstanceCreationExpression() != null) { } else if (stmt.classInstanceCreationExpression() != null) {
return convert(stmt.classInstanceCreationExpression()); return convert(stmt.classInstanceCreationExpression());
}else throw new NotImplementedException(); } else
throw new NotImplementedException();
} }
public Receiver getReceiver(Expression expr) { public Receiver getReceiver(Expression expr) {
@ -198,7 +233,8 @@ public class StatementGenerator {
} }
Expression receiver; Expression receiver;
if (methodInvocationContext.typeName() != null) { if (methodInvocationContext.typeName() != null) {
receiver = generateLocalOrFieldVarOrClassName(methodInvocationContext.typeName().getText(), methodInvocationContext.typeName().getStart()); receiver = generateLocalOrFieldVarOrClassName(methodInvocationContext.typeName().getText(),
methodInvocationContext.typeName().getStart());
} else if (methodInvocationContext.expressionName() != null) { } else if (methodInvocationContext.expressionName() != null) {
receiver = convert(methodInvocationContext.expressionName()); receiver = convert(methodInvocationContext.expressionName());
} else if (methodInvocationContext.primary() != null) { } else if (methodInvocationContext.primary() != null) {
@ -207,7 +243,8 @@ public class StatementGenerator {
receiver = new Super(methodInvocationContext.getStart()); receiver = new Super(methodInvocationContext.getStart());
} else if (methodInvocationContext.methodName() != null) { } else if (methodInvocationContext.methodName() != null) {
receiver = new This(methodInvocationContext.getStart()); receiver = new This(methodInvocationContext.getStart());
}else throw new NotImplementedException(); } else
throw new NotImplementedException();
ArgumentList argumentList = convert(methodInvocationContext.argumentList()); ArgumentList argumentList = convert(methodInvocationContext.argumentList());
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = argumentList.getArguments().stream() ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = argumentList.getArguments().stream()
@ -221,14 +258,16 @@ public class StatementGenerator {
} }
private ArgumentList convert(Java17Parser.ArgumentListContext argumentListContext) { private ArgumentList convert(Java17Parser.ArgumentListContext argumentListContext) {
if(argumentListContext == null)return new ArgumentList(new ArrayList<>(), new NullToken()); if (argumentListContext == null)
return new ArgumentList(new ArrayList<>(), new NullToken());
List<Expression> args = new ArrayList<>(); List<Expression> args = new ArrayList<>();
Token offset = new NullToken(); Token offset = new NullToken();
for (Java17Parser.ExpressionContext expr : argumentListContext.expression()) { for (Java17Parser.ExpressionContext expr : argumentListContext.expression()) {
args.add(convert(expr)); args.add(convert(expr));
} }
if(args.size()>0)offset = args.get(0).getOffset(); if (args.size() > 0)
offset = args.get(0).getOffset();
return new ArgumentList(args, offset); return new ArgumentList(args, offset);
} }
@ -236,6 +275,7 @@ public class StatementGenerator {
/** /**
* Der Parser kann nicht zwischen einer lokalen Variable, einem Feldzugriff und * Der Parser kann nicht zwischen einer lokalen Variable, einem Feldzugriff und
* einer Klassenangabe unterscheiden. * einer Klassenangabe unterscheiden.
*
* @param expression * @param expression
* @param offset * @param offset
* @return * @return
@ -247,14 +287,16 @@ public class StatementGenerator {
if (localVars.get(expression) != null) { if (localVars.get(expression) != null) {
return new LocalVar(expression, localVars.get(expression), offset); return new LocalVar(expression, localVars.get(expression), offset);
} else { } else {
if(fields.get(expression) != null){//PL 2018-11-01 fields eingefuegt, damit die fields immer die gleiche TPH bekommen if (fields.get(expression) != null) {// PL 2018-11-01 fields eingefuegt, damit die fields immer die
// gleiche TPH bekommen
return new FieldVar(new This(offset), expression, fields.get(expression), offset); return new FieldVar(new This(offset), expression, fields.get(expression), offset);
} else { } else {
// kann eigentlich nicht vorkommen // kann eigentlich nicht vorkommen
// Dann Muss es ein Feld sein! // Dann Muss es ein Feld sein!
return new FieldVar(new This(offset), expression, TypePlaceholder.fresh(offset), offset); return new FieldVar(new This(offset), expression, TypePlaceholder.fresh(offset), offset);
}} }
}
} }
return generateFieldVarOrClassname(expression, offset); return generateFieldVarOrClassname(expression, offset);
} }
@ -287,19 +329,21 @@ public class StatementGenerator {
return generateLocalOrFieldVarOrClassName(expressionNameContext.getText(), expressionNameContext.getStart()); return generateLocalOrFieldVarOrClassName(expressionNameContext.getText(), expressionNameContext.getStart());
} }
private Statement convert(Java17Parser.ClassInstanceCreationExpressionContext newExpression) { private Statement convert(Java17Parser.ClassInstanceCreationExpressionContext newExpression) {
Java17Parser.TypeArgumentsContext genericArgs = null; Java17Parser.TypeArgumentsContext genericArgs = null;
if(newExpression.expressionName()!= null)throw new NotImplementedException(); if (newExpression.expressionName() != null)
throw new NotImplementedException();
if (newExpression.typeArgumentsOrDiamond() != null) { if (newExpression.typeArgumentsOrDiamond() != null) {
if (newExpression.typeArgumentsOrDiamond().typeArguments() != null) { if (newExpression.typeArgumentsOrDiamond().typeArguments() != null) {
genericArgs = newExpression.typeArgumentsOrDiamond().typeArguments(); genericArgs = newExpression.typeArgumentsOrDiamond().typeArguments();
} }
} }
if(newExpression.typeArguments()!= null)throw new NotImplementedException(); if (newExpression.typeArguments() != null)
throw new NotImplementedException();
TerminalNode identifier = newExpression.Identifier(0); TerminalNode identifier = newExpression.Identifier(0);
RefType newClass = (RefType) TypeGenerator.convertTypeName(identifier.getText(),genericArgs,identifier.getSymbol(),reg,generics); RefType newClass = (RefType) TypeGenerator.convertTypeName(identifier.getText(), genericArgs,
identifier.getSymbol(), reg, generics);
ArgumentList args = convert(newExpression.argumentList()); ArgumentList args = convert(newExpression.argumentList());
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = args.getArguments().stream() ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = args.getArguments().stream()
@ -313,7 +357,8 @@ public class StatementGenerator {
private Statement convert(Java17Parser.PreIncrementExpressionContext stmt) { private Statement convert(Java17Parser.PreIncrementExpressionContext stmt) {
Expression argument = convert(stmt.unaryExpression()); Expression argument = convert(stmt.unaryExpression());
Token offset = stmt.getStart(); Token offset = stmt.getStart();
Statement ret = new UnaryExpr(UnaryExpr.Operation.PREINCREMENT, argument, TypePlaceholder.fresh(offset), offset); Statement ret = new UnaryExpr(UnaryExpr.Operation.PREINCREMENT, argument, TypePlaceholder.fresh(offset),
offset);
ret.setStatement(); ret.setStatement();
return ret; return ret;
} }
@ -348,17 +393,17 @@ public class StatementGenerator {
private AssignLeftSide convert(Java17Parser.LeftHandSideContext leftHandSide) { private AssignLeftSide convert(Java17Parser.LeftHandSideContext leftHandSide) {
Expression leftSide = generateLocalOrFieldVarOrClassName(leftHandSide.getText(), leftHandSide.getStart()); Expression leftSide = generateLocalOrFieldVarOrClassName(leftHandSide.getText(), leftHandSide.getStart());
if(leftSide instanceof FieldVar)return new AssignToField((FieldVar) leftSide); if (leftSide instanceof FieldVar)
else if (leftSide instanceof LocalVar)return new AssignToLocal((LocalVar) leftSide); return new AssignToField((FieldVar) leftSide);
else throw new NotImplementedException(); else if (leftSide instanceof LocalVar)
} return new AssignToLocal((LocalVar) leftSide);
else
private Statement convert(Java17Parser.IfThenStatementContext stmt){
//TODO
throw new NotImplementedException(); throw new NotImplementedException();
} }
private Statement convert(Java17Parser.IfThenElseStatementContext stmt){ private Statement convert(Java17Parser.ConditionalstmtContext stmt) {
if (Objects.isNull(stmt.ELSE()))
throw new NotImplementedException();
Expression expr = convert(stmt.parExpression().expression()); Expression expr = convert(stmt.parExpression().expression());
Statement thenBlock = convert(stmt.statementNoShortIf()); Statement thenBlock = convert(stmt.statementNoShortIf());
Statement elseBlock = convert(stmt.statement()); Statement elseBlock = convert(stmt.statement());
@ -370,7 +415,7 @@ public class StatementGenerator {
throw new NotImplementedException(); throw new NotImplementedException();
} }
private Statement convert(Java17Parser.AssertStatementContext stmt){ private Statement convert(Java17Parser.AssertstmtContext stmt) {
// TODO // TODO
throw new NotImplementedException(); throw new NotImplementedException();
} }
@ -412,7 +457,8 @@ public class StatementGenerator {
return convert(stmt.basicForStatement()); return convert(stmt.basicForStatement());
} else if (stmt.enhancedForStatement() != null) { } else if (stmt.enhancedForStatement() != null) {
return convert(stmt.enhancedForStatement()); return convert(stmt.enhancedForStatement());
}else throw new NotImplementedException(); } else
throw new NotImplementedException();
} }
private Statement convert(Java17Parser.ForStatementNoShortIfContext stmt) { private Statement convert(Java17Parser.ForStatementNoShortIfContext stmt) {
@ -420,7 +466,8 @@ public class StatementGenerator {
return convert(stmt.basicForStatementNoShortIf()); return convert(stmt.basicForStatementNoShortIf());
} else if (stmt.enhancedForStatementNoShortIf() != null) { } else if (stmt.enhancedForStatementNoShortIf() != null) {
return convert(stmt.enhancedForStatementNoShortIf()); return convert(stmt.enhancedForStatementNoShortIf());
}else throw new NotImplementedException(); } else
throw new NotImplementedException();
} }
private Statement convert(Java17Parser.BasicForStatementContext stmt) { private Statement convert(Java17Parser.BasicForStatementContext stmt) {
@ -438,7 +485,8 @@ public class StatementGenerator {
return Arrays.asList(convert(stmt.statementExpressionList())); return Arrays.asList(convert(stmt.statementExpressionList()));
} else if (stmt.localVariableDeclaration() != null) { } else if (stmt.localVariableDeclaration() != null) {
return convert(stmt.localVariableDeclaration()); return convert(stmt.localVariableDeclaration());
}else throw new NotImplementedException(); } else
throw new NotImplementedException();
} }
private List<Statement> convert(Java17Parser.LocalVariableDeclarationContext declaration) { private List<Statement> convert(Java17Parser.LocalVariableDeclarationContext declaration) {
@ -457,7 +505,8 @@ public class StatementGenerator {
return ret; return ret;
} }
private List<Statement> generateLocalVariableAssignments(List<Java17Parser.VariableDeclaratorContext> varDeclarators, RefTypeOrTPHOrWildcardOrGeneric type){ private List<Statement> generateLocalVariableAssignments(
List<Java17Parser.VariableDeclaratorContext> varDeclarators, RefTypeOrTPHOrWildcardOrGeneric type) {
List<Statement> ret = new ArrayList<>(); List<Statement> ret = new ArrayList<>();
for (Java17Parser.VariableDeclaratorContext varDecl : varDeclarators) { for (Java17Parser.VariableDeclaratorContext varDecl : varDeclarators) {
TerminalNode name = varDecl.variableDeclaratorId().Identifier(); TerminalNode name = varDecl.variableDeclaratorId().Identifier();
@ -471,14 +520,15 @@ public class StatementGenerator {
} else { } else {
initValue = convert(varDecl.variableInitializer().expression()); initValue = convert(varDecl.variableInitializer().expression());
} }
ret.add(new Assign(new AssignToLocal(new LocalVar(name.getText(), type, name.getSymbol())) ret.add(new Assign(new AssignToLocal(new LocalVar(name.getText(), type, name.getSymbol())), initValue,
, initValue, name.getSymbol())); name.getSymbol()));
} }
} }
return ret; return ret;
} }
public Statement generateFieldAssignment(Java17Parser.VariableDeclaratorContext varDecl, RefTypeOrTPHOrWildcardOrGeneric type){ public Statement generateFieldAssignment(Java17Parser.VariableDeclaratorContext varDecl,
RefTypeOrTPHOrWildcardOrGeneric type) {
TerminalNode name = varDecl.variableDeclaratorId().Identifier(); TerminalNode name = varDecl.variableDeclaratorId().Identifier();
Expression initValue; Expression initValue;
if (varDecl.variableInitializer().arrayInitializer() != null) { if (varDecl.variableInitializer().arrayInitializer() != null) {
@ -629,7 +679,8 @@ public class StatementGenerator {
String operator = expression.getChild(1).getText(); String operator = expression.getChild(1).getText();
Expression leftSide = convert(expression.equalityExpression()); Expression leftSide = convert(expression.equalityExpression());
Expression rightSide = convert(expression.relationalExpression()); Expression rightSide = convert(expression.relationalExpression());
return new BinaryExpr(convertBinaryOperator(operator), TypePlaceholder.fresh(expression.getStart()), leftSide, rightSide, expression.getStart()); return new BinaryExpr(convertBinaryOperator(operator), TypePlaceholder.fresh(expression.getStart()),
leftSide, rightSide, expression.getStart());
} }
} }
@ -749,7 +800,8 @@ public class StatementGenerator {
} else if (expressionContext.lambdaExpression() != null) { } else if (expressionContext.lambdaExpression() != null) {
expr = convert(expressionContext.lambdaExpression()); expr = convert(expressionContext.lambdaExpression());
} }
return new CastExpr(TypeGenerator.convert(expressionContext.referenceType(), reg, generics),expr, expressionContext.getStart()); return new CastExpr(TypeGenerator.convert(expressionContext.referenceType(), reg, generics), expr,
expressionContext.getStart());
} }
private Expression convert(Java17Parser.PostfixExpressionContext expression) { private Expression convert(Java17Parser.PostfixExpressionContext expression) {
@ -764,11 +816,15 @@ public class StatementGenerator {
return expr; return expr;
} }
for(Java17Parser.PostIncrementExpression_lf_postfixExpressionContext inc : expression.postIncrementExpression_lf_postfixExpression()){ for (Java17Parser.PostIncrementExpression_lf_postfixExpressionContext inc : expression
expr = new UnaryExpr(UnaryExpr.Operation.POSTINCREMENT, expr, TypePlaceholder.fresh(inc.getStart()), inc.getStart()); .postIncrementExpression_lf_postfixExpression()) {
expr = new UnaryExpr(UnaryExpr.Operation.POSTINCREMENT, expr, TypePlaceholder.fresh(inc.getStart()),
inc.getStart());
} }
for(Java17Parser.PostDecrementExpression_lf_postfixExpressionContext dec : expression.postDecrementExpression_lf_postfixExpression()){ for (Java17Parser.PostDecrementExpression_lf_postfixExpressionContext dec : expression
expr = new UnaryExpr(UnaryExpr.Operation.POSTDECREMENT, expr, TypePlaceholder.fresh(dec.getStart()), dec.getStart()); .postDecrementExpression_lf_postfixExpression()) {
expr = new UnaryExpr(UnaryExpr.Operation.POSTDECREMENT, expr, TypePlaceholder.fresh(dec.getStart()),
dec.getStart());
} }
return expr; return expr;
@ -849,16 +905,19 @@ public class StatementGenerator {
private Expression convert(Java17Parser.ClassInstanceCreationExpression_lfno_primaryContext newExpression) { private Expression convert(Java17Parser.ClassInstanceCreationExpression_lfno_primaryContext newExpression) {
Java17Parser.TypeArgumentsContext genericArgs = null; Java17Parser.TypeArgumentsContext genericArgs = null;
if(newExpression.expressionName()!= null)throw new NotImplementedException(); if (newExpression.expressionName() != null)
throw new NotImplementedException();
if (newExpression.typeArgumentsOrDiamond() != null) { if (newExpression.typeArgumentsOrDiamond() != null) {
if (newExpression.typeArgumentsOrDiamond().typeArguments() != null) { if (newExpression.typeArgumentsOrDiamond().typeArguments() != null) {
genericArgs = newExpression.typeArgumentsOrDiamond().typeArguments(); genericArgs = newExpression.typeArgumentsOrDiamond().typeArguments();
} }
} }
if(newExpression.typeArguments()!= null)throw new NotImplementedException(); if (newExpression.typeArguments() != null)
throw new NotImplementedException();
TerminalNode identifier = newExpression.Identifier(0); TerminalNode identifier = newExpression.Identifier(0);
RefType newClass = (RefType) TypeGenerator.convertTypeName(identifier.getText(),genericArgs,identifier.getSymbol(),reg,generics); RefType newClass = (RefType) TypeGenerator.convertTypeName(identifier.getText(), genericArgs,
identifier.getSymbol(), reg, generics);
ArgumentList args = convert(newExpression.argumentList()); ArgumentList args = convert(newExpression.argumentList());
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = args.getArguments().stream() ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = args.getArguments().stream()
@ -910,7 +969,8 @@ public class StatementGenerator {
} }
Expression receiver; Expression receiver;
if (methodInvocationContext.typeName() != null) { if (methodInvocationContext.typeName() != null) {
receiver = generateLocalOrFieldVarOrClassName(methodInvocationContext.typeName().getText(), methodInvocationContext.typeName().getStart()); receiver = generateLocalOrFieldVarOrClassName(methodInvocationContext.typeName().getText(),
methodInvocationContext.typeName().getStart());
} else if (methodInvocationContext.expressionName() != null) { } else if (methodInvocationContext.expressionName() != null) {
receiver = convert(methodInvocationContext.expressionName()); receiver = convert(methodInvocationContext.expressionName());
} else if (methodInvocationContext.toString().startsWith("super")) { } else if (methodInvocationContext.toString().startsWith("super")) {
@ -967,7 +1027,8 @@ public class StatementGenerator {
params.getFormalparalist().forEach(formalParameter -> // Für jeden Parameter einen TPH anfügen: params.getFormalparalist().forEach(formalParameter -> // Für jeden Parameter einen TPH anfügen:
funNParams.add(TypePlaceholder.fresh(expression.getStart()))); funNParams.add(TypePlaceholder.fresh(expression.getStart())));
RefTypeOrTPHOrWildcardOrGeneric lambdaType = TypePlaceholder.fresh(expression.getStart()); RefTypeOrTPHOrWildcardOrGeneric lambdaType = TypePlaceholder.fresh(expression.getStart());
//RefType lambdaType = new RefType(reg.getName("Fun"+params.getFormalparalist().size()), // RefType lambdaType = new
// RefType(reg.getName("Fun"+params.getFormalparalist().size()),
// funNParams, name.getStart()); // funNParams, name.getStart());
return new LambdaExpression(lambdaType, params, block, expression.getStart()); return new LambdaExpression(lambdaType, params, block, expression.getStart());
} }