modified: ../../src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java

modified:   ../../src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java
FieldVars eingefuegt, dass sie genauso wie localsvars immer die gleiche Typvariable in der abstrakten Syntax bekommen
This commit is contained in:
Martin Plümicke 2018-11-02 22:53:34 +01:00
parent 5849cd6f39
commit 4ef360e41e
3 changed files with 24 additions and 7 deletions

View File

@ -21,12 +21,14 @@ import java.util.*;
public class StatementGenerator {
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> localVars;
private GenericsRegistry generics;
public StatementGenerator(JavaClassRegistry reg, GenericsRegistry generics, Map<String, RefTypeOrTPHOrWildcardOrGeneric> localVars){
public StatementGenerator(JavaClassRegistry reg, GenericsRegistry generics, Map<String, RefTypeOrTPHOrWildcardOrGeneric> fields, Map<String, RefTypeOrTPHOrWildcardOrGeneric> 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){

View File

@ -33,6 +33,7 @@ public class SyntaxTreeGenerator{
private final GenericsRegistry globalGenerics;
private String pkgName = "";
Set<JavaClassName> imports = new HashSet();
private Map<String, RefTypeOrTPHOrWildcardOrGeneric> fields = new HashMap<>(); //PL 2018-11-01 fields eingefuegt, damit die fields immer die gleiche TPH bekommen
List<Statement> 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));
}

View File

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