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:
parent
5849cd6f39
commit
4ef360e41e
@ -21,12 +21,14 @@ import java.util.*;
|
|||||||
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> localVars;
|
private Map<String, RefTypeOrTPHOrWildcardOrGeneric> localVars;
|
||||||
private GenericsRegistry generics;
|
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.reg = reg;
|
||||||
this.generics = generics;
|
this.generics = generics;
|
||||||
|
this.fields = fields;
|
||||||
this.localVars = localVars;
|
this.localVars = localVars;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,9 +240,14 @@ 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
|
||||||
|
return new FieldVar(new This(offset), expression, fields.get(expression), offset);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
//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);
|
||||||
}
|
}
|
||||||
@ -896,7 +903,7 @@ public class StatementGenerator {
|
|||||||
for(FormalParameter param : params.getFormalparalist()){
|
for(FormalParameter param : params.getFormalparalist()){
|
||||||
lambdaLocals.put(param.getName(), param.getType());
|
lambdaLocals.put(param.getName(), param.getType());
|
||||||
}
|
}
|
||||||
StatementGenerator lambdaGenerator = new StatementGenerator(reg, generics, lambdaLocals);
|
StatementGenerator lambdaGenerator = new StatementGenerator(reg, generics, fields, lambdaLocals);
|
||||||
|
|
||||||
Block block;
|
Block block;
|
||||||
if(expression.lambdaBody().expression() != null){
|
if(expression.lambdaBody().expression() != null){
|
||||||
|
@ -33,6 +33,7 @@ public class SyntaxTreeGenerator{
|
|||||||
private final GenericsRegistry globalGenerics;
|
private final GenericsRegistry globalGenerics;
|
||||||
private String pkgName = "";
|
private String pkgName = "";
|
||||||
Set<JavaClassName> imports = new HashSet();
|
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<>();
|
List<Statement> fieldInitializations = new ArrayList<>();
|
||||||
|
|
||||||
@ -122,7 +123,7 @@ public class SyntaxTreeGenerator{
|
|||||||
private Method convert(int modifiers, Java8Parser.MethodHeaderContext header, Java8Parser.MethodBodyContext body,
|
private Method convert(int modifiers, Java8Parser.MethodHeaderContext header, Java8Parser.MethodBodyContext body,
|
||||||
JavaClassName parentClass, RefType superClass, GenericsRegistry localGenerics) {
|
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();
|
String name = header.methodDeclarator().Identifier().getText();
|
||||||
GenericDeclarationList gtvDeclarations = new GenericDeclarationList(new ArrayList<>(), header.getStart());
|
GenericDeclarationList gtvDeclarations = new GenericDeclarationList(new ArrayList<>(), header.getStart());
|
||||||
@ -346,6 +347,7 @@ public class SyntaxTreeGenerator{
|
|||||||
}
|
}
|
||||||
for(Java8Parser.VariableDeclaratorContext varCtx : fieldDeclarationContext.variableDeclaratorList().variableDeclarator()){
|
for(Java8Parser.VariableDeclaratorContext varCtx : fieldDeclarationContext.variableDeclaratorList().variableDeclarator()){
|
||||||
String fieldName = convert(varCtx.variableDeclaratorId());
|
String fieldName = convert(varCtx.variableDeclaratorId());
|
||||||
|
fields.put(fieldName, fieldType);
|
||||||
if(varCtx.variableInitializer() != null){
|
if(varCtx.variableInitializer() != null){
|
||||||
initializeField(varCtx, fieldType, generics);
|
initializeField(varCtx, fieldType, generics);
|
||||||
}
|
}
|
||||||
@ -360,7 +362,7 @@ public class SyntaxTreeGenerator{
|
|||||||
|
|
||||||
// Initialize a field by creating implicit constructor.
|
// Initialize a field by creating implicit constructor.
|
||||||
private void initializeField(Java8Parser.VariableDeclaratorContext ctx, RefTypeOrTPHOrWildcardOrGeneric typeOfField, GenericsRegistry generics){
|
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));
|
fieldInitializations.add(statementGenerator.generateFieldAssignment(ctx, typeOfField));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -518,8 +518,16 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
|
|
||||||
RefTypeOrTPHOrWildcardOrGeneric receiverType = new RefType(assumption.getReceiver().getClassName(), params, forMethod.getOffset());
|
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(),
|
methodConstraint.add(new Pair(assumption.getReturnType(resolver), forMethod.getType(),
|
||||||
PairOperator.EQUALSDOT));
|
PairOperator.EQUALSDOT));
|
||||||
methodConstraint.addAll(generateParameterConstraints(forMethod, assumption, info, resolver));
|
methodConstraint.addAll(generateParameterConstraints(forMethod, assumption, info, resolver));
|
||||||
|
Loading…
Reference in New Issue
Block a user