Fehler im Trailing Return anhängen beheben

This commit is contained in:
JanUlrich 2018-01-30 02:23:58 +01:00
parent 027538a082
commit 3ce4937bc1
7 changed files with 34 additions and 11 deletions

View File

@ -141,6 +141,8 @@ public class FCGenerator {
public UnifyType visit(GenericRefType genericRefType) {
if(! gtvs.containsKey(genericRefType.getParsedName()))
throw new DebugException("Dieser Fall darf nicht auftreten");
//TODO: Diesen Dirty-Hack beseitigen. Fehler tritt bei java.lang.invoke.LambdaFormEditor$Transform$Kind auf.
//return UnifyTypeFactory.convert(ASTFactory.createObjectType());
return gtvs.get(genericRefType.getParsedName());
}

View File

@ -96,7 +96,7 @@ public class StatementGenerator {
private Statement convert(Java8Parser.StatementWithoutTrailingSubstatementContext stmt) {
if(stmt.block() != null){
return convert(stmt.block());
return convert(stmt.block(), false);
}else if(stmt.emptyStatement() != null){
return new EmptyStmt(stmt.getStart());
}else if(stmt.expressionStatement() != null){
@ -122,14 +122,14 @@ public class StatementGenerator {
}else throw new NotImplementedException();
}
public Block convert(Java8Parser.BlockContext block) {
public Block convert(Java8Parser.BlockContext block, boolean addTrailingReturn) {
List<Statement> statements = new ArrayList<>();
if(block.blockStatements() != null)
for(Java8Parser.BlockStatementContext statementContext : block.blockStatements().blockStatement()){
List<Statement> stmt = convert(statementContext);
statements.addAll(stmt);
}
statements = SyntacticSugar.addTrailingReturn(statements);
if(addTrailingReturn)statements = SyntacticSugar.addTrailingReturn(statements);
return new Block(statements, block.getStart());
}
@ -857,7 +857,7 @@ public class StatementGenerator {
expression.lambdaBody().expression().getStart()));
block = new Block(statements, expression.lambdaBody().getStart());
}else{
block = lambdaGenerator.convert(expression.lambdaBody().block());
block = lambdaGenerator.convert(expression.lambdaBody().block(), true);
}
List<RefTypeOrTPHOrWildcardOrGeneric> funNParams = new ArrayList<>();
funNParams.add(TypePlaceholder.fresh(expression.getStart()));//ret-Type

View File

@ -136,7 +136,7 @@ public class SyntaxTreeGenerator{
//TODO: Error! Abstrakte Methode ohne abstrakt Keyword
}
}else{
block = stmtGen.convert(body.block());
block = stmtGen.convert(body.block(),true);
}
if(parentClass.equals(new JavaClassName(name))){
return new Constructor(modifiers, name, retType, parameterList, block, gtvDeclarations, header.getStart(), fieldInitializations);

View File

@ -158,12 +158,13 @@ public abstract class AbstractASTWalker implements ASTVisitor{
@Override
public void visit(ForStmt forStmt) {
forStmt.body_Loop_block.accept(this);
}
@Override
public void visit(IfStmt ifStmt) {
ifStmt.then_block.accept(this);
ifStmt.else_block.accept(this);
}
@Override
@ -235,12 +236,12 @@ public abstract class AbstractASTWalker implements ASTVisitor{
@Override
public void visit(WhileStmt whileStmt) {
whileStmt.loopBlock.accept(this);
}
@Override
public void visit(DoStmt whileStmt) {
whileStmt.loopBlock.accept(this);
}
@Override

View File

@ -347,6 +347,24 @@ public class OutputGenerator implements ASTVisitor{
@Override
public void visit(UnaryExpr unaryExpr) {
throw new NotImplementedException();
if(unaryExpr.operation == UnaryExpr.Operation.MINUS){
out.append("-");
}
if(unaryExpr.operation == UnaryExpr.Operation.PLUS){
out.append("+");
}
if(unaryExpr.operation == UnaryExpr.Operation.PREDECREMENT){
out.append("--");
}
if(unaryExpr.operation == UnaryExpr.Operation.PREINCREMENT){
out.append("++");
}
unaryExpr.expr.accept(this);
if(unaryExpr.operation == UnaryExpr.Operation.POSTDECREMENT){
out.append("--");
}
if(unaryExpr.operation == UnaryExpr.Operation.POSTINCREMENT){
out.append("++");
}
}
}

View File

@ -2,6 +2,7 @@ package typeinference;
import de.dhbwstuttgart.core.JavaTXCompiler;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
import de.dhbwstuttgart.syntaxtree.visual.ASTTypePrinter;
import de.dhbwstuttgart.typedeployment.TypeInsert;
import de.dhbwstuttgart.typedeployment.TypeInsertFactory;
@ -51,6 +52,7 @@ public class JavaTXCompilerTest {
for(File f : compiler.sourceFiles.keySet()){
SourceFile sf = compiler.sourceFiles.get(f);
System.out.println(ASTTypePrinter.print(sf));
System.out.println(ASTPrinter.print(sf));
//List<ResultSet> results = compiler.typeInference(); PL 2017-10-03 vor die For-Schleife gezogen
assert results.size()>0;
Set<String> insertedTypes = new HashSet<>();