diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java index 49e83aae..067430e2 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java @@ -21,12 +21,14 @@ import java.util.*; public class StatementGenerator { private JavaClassRegistry reg; + private Map fields; //PL 2018-11-01 fields eingefuegt, damit die fields immer die gleiche TPH bekommen private Map localVars; private GenericsRegistry generics; - public StatementGenerator(JavaClassRegistry reg, GenericsRegistry generics, Map localVars){ + public StatementGenerator(JavaClassRegistry reg, GenericsRegistry generics, Map fields, Map localVars){ this.reg = reg; this.generics = generics; + this.fields = fields; this.localVars = localVars; } @@ -238,9 +240,14 @@ public class StatementGenerator { if(localVars.get(expression) != null){ return new LocalVar(expression, localVars.get(expression), offset); }else{ + 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); + + } else { + //kann eigentlich nicht vorkommen //Dann Muss es ein Feld sein! return new FieldVar(new This(offset), expression, TypePlaceholder.fresh(offset), offset); - } + }} } return generateFieldVarOrClassname(expression, offset); } @@ -896,7 +903,7 @@ public class StatementGenerator { for(FormalParameter param : params.getFormalparalist()){ lambdaLocals.put(param.getName(), param.getType()); } - StatementGenerator lambdaGenerator = new StatementGenerator(reg, generics, lambdaLocals); + StatementGenerator lambdaGenerator = new StatementGenerator(reg, generics, fields, lambdaLocals); Block block; if(expression.lambdaBody().expression() != null){ diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java index 73b0e55f..b0331a00 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java @@ -33,6 +33,7 @@ public class SyntaxTreeGenerator{ private final GenericsRegistry globalGenerics; private String pkgName = ""; Set imports = new HashSet(); + private Map fields = new HashMap<>(); //PL 2018-11-01 fields eingefuegt, damit die fields immer die gleiche TPH bekommen List fieldInitializations = new ArrayList<>(); @@ -122,7 +123,7 @@ public class SyntaxTreeGenerator{ private Method convert(int modifiers, Java8Parser.MethodHeaderContext header, Java8Parser.MethodBodyContext body, JavaClassName parentClass, RefType superClass, GenericsRegistry localGenerics) { - StatementGenerator stmtGen = new StatementGenerator(reg, localGenerics, new HashMap<>()); + StatementGenerator stmtGen = new StatementGenerator(reg, localGenerics, fields, new HashMap<>()); String name = header.methodDeclarator().Identifier().getText(); GenericDeclarationList gtvDeclarations = new GenericDeclarationList(new ArrayList<>(), header.getStart()); @@ -346,6 +347,7 @@ public class SyntaxTreeGenerator{ } for(Java8Parser.VariableDeclaratorContext varCtx : fieldDeclarationContext.variableDeclaratorList().variableDeclarator()){ String fieldName = convert(varCtx.variableDeclaratorId()); + fields.put(fieldName, fieldType); if(varCtx.variableInitializer() != null){ initializeField(varCtx, fieldType, generics); } @@ -360,7 +362,7 @@ public class SyntaxTreeGenerator{ // Initialize a field by creating implicit constructor. private void initializeField(Java8Parser.VariableDeclaratorContext ctx, RefTypeOrTPHOrWildcardOrGeneric typeOfField, GenericsRegistry generics){ - StatementGenerator statementGenerator = new StatementGenerator(reg, generics, new HashMap<>()); + StatementGenerator statementGenerator = new StatementGenerator(reg, generics, fields, new HashMap<>()); fieldInitializations.add(statementGenerator.generateFieldAssignment(ctx, typeOfField)); } diff --git a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java index ea3616eb..cad3a62f 100644 --- a/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java +++ b/src/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java @@ -518,8 +518,16 @@ public class TYPEStmt implements StatementVisitor{ RefTypeOrTPHOrWildcardOrGeneric receiverType = new RefType(assumption.getReceiver().getClassName(), params, forMethod.getOffset()); */ - methodConstraint.add(new Pair(forMethod.receiver.getType(), assumption.getReceiverType(resolver), - PairOperator.SMALLERDOT)); + + RefTypeOrTPHOrWildcardOrGeneric retType = assumption.getReceiverType(resolver); + /* if (retType instanceof FunN) { + methodConstraint.add(new Pair(forMethod.receiver.getType(), retType, + PairOperator.EQUALSDOT)); + } + else {//RefType */ + methodConstraint.add(new Pair(forMethod.receiver.getType(), retType, + PairOperator.SMALLERDOT)); + //} methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(), PairOperator.EQUALSDOT)); methodConstraint.addAll(generateParameterConstraints(forMethod, assumption, info, resolver));