modified: src/main/java/de/dhbwstuttgart/bytecode/TPHExtractor.java

modified:   src/main/java/de/dhbwstuttgart/bytecode/insertGenerics/FamilyOfGeneratedGenerics.java
	modified:   src/main/java/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java
	modified:   src/main/java/de/dhbwstuttgart/syntaxtree/statement/MethodCall.java
	modified:   src/main/java/de/dhbwstuttgart/syntaxtree/statement/Statement.java
	modified:   src/main/java/de/dhbwstuttgart/typeinference/constraints/Constraint.java
	modified:   src/main/java/de/dhbwstuttgart/typeinference/typeAlgo/TYPEStmt.java
	modified:   src/test/java/insertGenerics/TestLocalVarLambda.java
This commit is contained in:
pl@gohorb.ba-horb.de 2021-04-13 10:03:48 +02:00
parent 3363037854
commit be9ee49878
8 changed files with 72 additions and 26 deletions

View File

@ -209,10 +209,12 @@ public class TPHExtractor extends AbstractASTWalker {
csS.getOderConstraints() csS.getOderConstraints()
.forEach(oConSSet -> { Set<Constraint<Pair>> setCons = new HashSet<>(); .forEach(oConSSet -> { Set<Constraint<Pair>> setCons = new HashSet<>();
oConSSet.forEach(OConS -> { setCons.add( oConSSet.forEach(OConS -> { Constraint<Pair> newConsPair = new Constraint<Pair>();
newConsPair.isStatement = OConS.isStatement;
setCons.add(
OConS.stream() OConS.stream()
.filter(filterUndConstraints) .filter(filterUndConstraints)
.collect(Collectors.toCollection(Constraint<Pair>::new)) ); .collect(Collectors.toCollection(() -> newConsPair)) );
} ); } );
ret.addOderConstraint(setCons);} ); ret.addOderConstraint(setCons);} );
return ret; return ret;

View File

@ -8,6 +8,7 @@ import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
import java.util.*; import java.util.*;
import java.util.function.Predicate; import java.util.function.Predicate;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typeinference.constraints.Constraint; import de.dhbwstuttgart.typeinference.constraints.Constraint;
import de.dhbwstuttgart.typeinference.constraints.Pair; import de.dhbwstuttgart.typeinference.constraints.Pair;
@ -590,8 +591,9 @@ public class FamilyOfGeneratedGenerics {
Iterator<Pair> itExtends2 = extendsSet.iterator(); Iterator<Pair> itExtends2 = extendsSet.iterator();
while(itExtends2.hasNext()) { while(itExtends2.hasNext()) {
Pair pairExtends2 = itExtends2.next(); Pair pairExtends2 = itExtends2.next();
Set<String> containedVars = new HashSet<>(methodAndTPH.getTphs());
String pairExtends2RHSName = ((TypePlaceholder)((resSet.resolveType((TypePlaceholder)pairExtends2.TA2)).resolvedType)).getName();
Iterator<Pair> itEqual2 = equalSet.iterator(); Iterator<Pair> itEqual2 = equalSet.iterator();
while (itEqual2.hasNext()) { while (itEqual2.hasNext()) {
boolean transClo = false; boolean transClo = false;
Pair pairEqual2 = itEqual2.next(); Pair pairEqual2 = itEqual2.next();
@ -635,23 +637,29 @@ public class FamilyOfGeneratedGenerics {
tempSet2.add(pairExtends2); tempSet2.add(pairExtends2);
} }
} }
else {
containedVars.remove(((TypePlaceholder)newPair2.TA2).getName());
}
} }
Set<String> containedVars = new HashSet<>();
String key = ((TypePlaceholder)((resSet.resolveType((TypePlaceholder)pairExtends2.TA2)).resolvedType)).getName(); //String key = ((TypePlaceholder)((resSet.resolveType((TypePlaceholder)pairExtends2.TA2)).resolvedType)).getName();
//TODO: containedVars stimmt noch nicht. Ueberpruefen, ob ggf. mit den containedVars möglicherweise auch die anderen Faelle //TODO: containedVars stimmt noch nicht. Ueberpruefen, ob ggf. mit den containedVars möglicherweise auch die anderen Faelle
// rEqExRtilde isPairInTExTapostrophe abgedeckt sind => ggf. integrieren // rEqExRtilde isPairInTExTapostrophe abgedeckt sind => ggf. integrieren
/*
posOfTphs.forEach((x,y) -> { posOfTphs.forEach((x,y) -> {
if (y.contains(new PairTphMethod<>(PositionFinder.Position.METHOD, methodAndTPH.getId()))) { if (y.contains(new PairTphMethod<>(PositionFinder.Position.METHOD, methodAndTPH.getId()))) {
containedVars.add(x); containedVars.add(x);
}; };
} }
); );
if (containedVars.stream().filter(v -> tcOfCs.contains(new TPHConstraint(key, v, Relation.EXTENDS))) */
if (containedVars.stream().filter(v -> tcOfCs.contains(new TPHConstraint(pairExtends2RHSName, v, Relation.EXTENDS)))
.count() > 0) { .count() > 0) {
tempSet2.add(pairExtends2); tempSet2.add(pairExtends2);
} }
if (posOfTphs.containsKey(key)) { if (posOfTphs.containsKey(pairExtends2RHSName)) {
if (posOfTphs.get(key).contains(new PairTphMethod<>(PositionFinder.Position.METHOD, methodAndTPH.getId()))) { if (posOfTphs.get(pairExtends2RHSName).contains(new PairTphMethod<>(PositionFinder.Position.METHOD, methodAndTPH.getId()))) {
tempSet2.add(pairExtends2); tempSet2.add(pairExtends2);
} }
} }

View File

@ -213,10 +213,10 @@ public class StatementGenerator {
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = argumentList.getArguments().stream() ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = argumentList.getArguments().stream()
.map(x -> TypePlaceholder.fresh(methodInvocationContext.getStart())) .map(x -> TypePlaceholder.fresh(methodInvocationContext.getStart()))
.collect(Collectors.toCollection(ArrayList::new)); .collect(Collectors.toCollection(ArrayList::new));
MethodCall ret = new MethodCall(//new Void(new NullToken()), MethodCall ret = new MethodCall(TypePlaceholder.fresh(methodInvocationContext.getStart()),
TypePlaceholder.fresh(methodInvocationContext.getStart()),
getReceiver(receiver), name, argumentList, TypePlaceholder.fresh(methodInvocationContext.getStart()), getReceiver(receiver), name, argumentList, TypePlaceholder.fresh(methodInvocationContext.getStart()),
argTypes, methodInvocationContext.getStart()); argTypes, methodInvocationContext.getStart());
ret.setStatement();
return ret; return ret;
} }
@ -303,33 +303,45 @@ public class StatementGenerator {
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = args.getArguments().stream() ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes = args.getArguments().stream()
.map(x -> TypePlaceholder.fresh(newExpression.getStart())) .map(x -> TypePlaceholder.fresh(newExpression.getStart()))
.collect(Collectors.toCollection(ArrayList::new)); .collect(Collectors.toCollection(ArrayList::new));
return new NewClass(newClass, args, null, argTypes, newExpression.getStart()); Statement ret = new NewClass(newClass, args, null, argTypes, newExpression.getStart());
ret.setStatement();
return ret;
} }
private Statement convert(Java8Parser.PreIncrementExpressionContext stmt) { private Statement convert(Java8Parser.PreIncrementExpressionContext stmt) {
Expression argument = convert(stmt.unaryExpression()); Expression argument = convert(stmt.unaryExpression());
Token offset = stmt.getStart(); Token offset = stmt.getStart();
return new UnaryExpr(UnaryExpr.Operation.PREINCREMENT, argument, TypePlaceholder.fresh(offset), offset); Statement ret = new UnaryExpr(UnaryExpr.Operation.PREINCREMENT, argument, TypePlaceholder.fresh(offset), offset);
} ret.setStatement();
return ret;
}
private Statement convert(Java8Parser.PreDecrementExpressionContext stmt) { private Statement convert(Java8Parser.PreDecrementExpressionContext stmt) {
return new UnaryExpr(UnaryExpr.Operation.PREDECREMENT, convert(stmt.unaryExpression()), Statement ret = new UnaryExpr(UnaryExpr.Operation.PREDECREMENT, convert(stmt.unaryExpression()),
TypePlaceholder.fresh(stmt.getStart()), stmt.getStart()); TypePlaceholder.fresh(stmt.getStart()), stmt.getStart());
ret.setStatement();
return ret;
} }
private Statement convert(Java8Parser.PostIncrementExpressionContext stmt) { private Statement convert(Java8Parser.PostIncrementExpressionContext stmt) {
return new UnaryExpr(UnaryExpr.Operation.POSTINCREMENT, convert(stmt.postfixExpression()), Statement ret = new UnaryExpr(UnaryExpr.Operation.POSTINCREMENT, convert(stmt.postfixExpression()),
TypePlaceholder.fresh(stmt.getStart()), stmt.getStart()); TypePlaceholder.fresh(stmt.getStart()), stmt.getStart());
ret.setStatement();
return ret;
} }
private Statement convert(Java8Parser.PostDecrementExpressionContext stmt) { private Statement convert(Java8Parser.PostDecrementExpressionContext stmt) {
return new UnaryExpr(UnaryExpr.Operation.POSTDECREMENT, convert(stmt.postfixExpression()), Statement ret = new UnaryExpr(UnaryExpr.Operation.POSTDECREMENT, convert(stmt.postfixExpression()),
TypePlaceholder.fresh(stmt.getStart()), stmt.getStart()); TypePlaceholder.fresh(stmt.getStart()), stmt.getStart());
ret.setStatement();
return ret;
} }
private Statement convert(Java8Parser.AssignmentContext stmt) { private Statement convert(Java8Parser.AssignmentContext stmt) {
AssignLeftSide leftHandSide = convert(stmt.leftHandSide()); AssignLeftSide leftHandSide = convert(stmt.leftHandSide());
return new Assign(leftHandSide, convert(stmt.expression()), stmt.getStart()); Statement ret = new Assign(leftHandSide, convert(stmt.expression()), stmt.getStart());
ret.setStatement();
return ret;
} }
private AssignLeftSide convert(Java8Parser.LeftHandSideContext leftHandSide) { private AssignLeftSide convert(Java8Parser.LeftHandSideContext leftHandSide) {

View File

@ -24,13 +24,9 @@ public class MethodCall extends Statement
public final ArgumentList arglist; public final ArgumentList arglist;
/*
* noetig fuer Bytecodegenerierung
*/
public RefTypeOrTPHOrWildcardOrGeneric receiverType; public RefTypeOrTPHOrWildcardOrGeneric receiverType;
public final ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes; public final ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes;
public MethodCall(RefTypeOrTPHOrWildcardOrGeneric retType, Receiver receiver, String methodName, ArgumentList argumentList, public MethodCall(RefTypeOrTPHOrWildcardOrGeneric retType, Receiver receiver, String methodName, ArgumentList argumentList,
RefTypeOrTPHOrWildcardOrGeneric receiverType, ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes, Token offset){ RefTypeOrTPHOrWildcardOrGeneric receiverType, ArrayList<RefTypeOrTPHOrWildcardOrGeneric> argTypes, Token offset){
super(retType,offset); super(retType,offset);
@ -40,6 +36,7 @@ public class MethodCall extends Statement
this.receiverType = receiverType; this.receiverType = receiverType;
this.argTypes = argTypes; this.argTypes = argTypes;
} }
@Override @Override
public void accept(StatementVisitor visitor) { public void accept(StatementVisitor visitor) {

View File

@ -6,11 +6,20 @@ import org.antlr.v4.runtime.Token;
public abstract class Statement extends Expression public abstract class Statement extends Expression
{ {
/* zeigt an, dass eine StatementExpression als Statement benutzt wird
*/
private boolean isStatement = false;
public Statement(RefTypeOrTPHOrWildcardOrGeneric type, Token offset) public Statement(RefTypeOrTPHOrWildcardOrGeneric type, Token offset)
{ {
super(type, offset); super(type, offset);
} }
public void setStatement() {
isStatement=true;
}
public boolean getStatement() {
return isStatement;
}
} }

View File

@ -9,6 +9,12 @@ import java.util.Set;
public class Constraint<A> extends HashSet<A> { public class Constraint<A> extends HashSet<A> {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private Boolean isInherited = false;//wird nur für die Method-Constraints benoetigt private Boolean isInherited = false;//wird nur für die Method-Constraints benoetigt
/* es darf kein Constraint für den Return-Type erstellt werden, sonst gibt
* es Probleme beim Generated Generics
*/
public boolean isStatement = false;
private Constraint<A> extendConstraint = null; private Constraint<A> extendConstraint = null;
public Constraint() { public Constraint() {
@ -41,7 +47,7 @@ public class Constraint<A> extends HashSet<A> {
} }
public String toString() { public String toString() {
return super.toString() + " isInherited = " + isInherited return super.toString() + "\nisInherited = " + isInherited + "\nisStatement = " + isStatement
//" + extendsContraint: " + (extendConstraint != null ? extendConstraint.toStringBase() : "null" ) //" + extendsContraint: " + (extendConstraint != null ? extendConstraint.toStringBase() : "null" )
+ "\n" ; + "\n" ;
} }

View File

@ -11,6 +11,7 @@ import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
import de.dhbwstuttgart.syntaxtree.factory.NameGenerator; import de.dhbwstuttgart.syntaxtree.factory.NameGenerator;
import de.dhbwstuttgart.syntaxtree.statement.*; import de.dhbwstuttgart.syntaxtree.statement.*;
import de.dhbwstuttgart.syntaxtree.type.*; import de.dhbwstuttgart.syntaxtree.type.*;
import de.dhbwstuttgart.syntaxtree.type.Void;
import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption; import de.dhbwstuttgart.typeinference.assumptions.FieldAssumption;
import de.dhbwstuttgart.typeinference.assumptions.FunNClass; import de.dhbwstuttgart.typeinference.assumptions.FunNClass;
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption; import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
@ -180,6 +181,7 @@ public class TYPEStmt implements StatementVisitor{
? new Pair(x.TA1, new ExtendsWildcardType(x.TA2, x.TA2.getOffset()), PairOperator.EQUALSDOT) ? new Pair(x.TA1, new ExtendsWildcardType(x.TA2, x.TA2.getOffset()), PairOperator.EQUALSDOT)
: x) : x)
.collect(Collectors.toCollection(() -> new Constraint<Pair>(oneMethodConstraint.isInherited()))); .collect(Collectors.toCollection(() -> new Constraint<Pair>(oneMethodConstraint.isInherited())));
extendsOneMethodConstraint.isStatement = oneMethodConstraint.isStatement;
oneMethodConstraint.setExtendConstraint(extendsOneMethodConstraint); oneMethodConstraint.setExtendConstraint(extendsOneMethodConstraint);
extendsOneMethodConstraint.setExtendConstraint(oneMethodConstraint); extendsOneMethodConstraint.setExtendConstraint(oneMethodConstraint);
methodConstraints.add(extendsOneMethodConstraint); methodConstraints.add(extendsOneMethodConstraint);
@ -594,9 +596,11 @@ public class TYPEStmt implements StatementVisitor{
//methodConstraint.add(new Pair(forMethod.receiverType, retType, //methodConstraint.add(new Pair(forMethod.receiverType, retType,
// PairOperator.EQUALSDOT)); // PairOperator.EQUALSDOT));
//Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ENDE //Fuer Bytecodegenerierung PL 2020-03-09 wird derzeit nicht benutzt ENDE
methodConstraint.isStatement = forMethod.getStatement();
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));
return methodConstraint; return methodConstraint;
} }

View File

@ -76,7 +76,15 @@ public class TestLocalVarLambda {
lmc.add(new MethodConstraint("SY", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("SY", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH DIUm(TPH O)", lmc); methodConstraintsWithPositionTest.put("TPH DIUm(TPH O)", lmc);
} }
else { else if (fogg.allConstraints.contains((new MethodConstraint("O", "DIV", Relation.EXTENDS)))) {
lmc.add(new MethodConstraint("O", "DIV", Relation.EXTENDS));
lmc.add(new MethodConstraint("N", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("DIV", "N", Relation.EXTENDS));
lmc.add(new MethodConstraint("SY", "java/lang/Object", Relation.EXTENDS));
methodConstraintsWithPositionTest.put("TPH Nm(TPH O)", lmc);
}
else
{
lmc.add(new MethodConstraint("O", "DIU", Relation.EXTENDS)); lmc.add(new MethodConstraint("O", "DIU", Relation.EXTENDS));
lmc.add(new MethodConstraint("N", "java/lang/Object", Relation.EXTENDS)); lmc.add(new MethodConstraint("N", "java/lang/Object", Relation.EXTENDS));
lmc.add(new MethodConstraint("DIU", "N", Relation.EXTENDS)); lmc.add(new MethodConstraint("DIU", "N", Relation.EXTENDS));