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

modified:   src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java
This commit is contained in:
pl@gohorb.ba-horb.de 2021-02-25 00:13:29 +01:00
parent 7e35e09c47
commit 60f2e3def4
2 changed files with 40 additions and 4 deletions

View File

@ -10,6 +10,9 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint; import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint; import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
@ -30,6 +33,9 @@ import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; 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.ConstraintSet;
import de.dhbwstuttgart.typeinference.constraints.Pair;
import de.dhbwstuttgart.typeinference.result.GenericInsertPair; import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
import de.dhbwstuttgart.typeinference.result.ResultPair; import de.dhbwstuttgart.typeinference.result.ResultPair;
import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.result.ResultSet;
@ -185,7 +191,29 @@ public class TPHExtractor extends AbstractASTWalker {
public void visit(Method method) { public void visit(Method method) {
inMethod = true; inMethod = true;
String id = MethodUtility.createID(resolver,method); String id = MethodUtility.createID(resolver,method);
methodAndTph = new MethodAndTPH(id, method.getConstraints()); Predicate<Pair> filterUndConstraints = cs -> ((cs.TA1 instanceof TypePlaceholder) && (cs.TA1 instanceof TypePlaceholder) &&
(resultSet.resolveType((TypePlaceholder)(cs.TA1)).resolvedType instanceof TypePlaceholder) &&
(resultSet.resolveType((TypePlaceholder)(cs.TA2)).resolvedType instanceof TypePlaceholder));
Function<ConstraintSet<Pair>, ConstraintSet<Pair>> filterConstrRemainingTVar =
csS -> {
ConstraintSet<Pair> ret = new ConstraintSet<>();
ret.addAllUndConstraint(
csS.getUndConstraints()
.stream().filter(filterUndConstraints)
.collect(Collectors.toCollection(Constraint<Pair>::new)));
csS.getOderConstraints()
.forEach(oConSSet -> { Set<Constraint<Pair>> setCons = new HashSet<>();
oConSSet.forEach(OConS -> { setCons.add(
OConS.stream()
.filter(filterUndConstraints)
.collect(Collectors.toCollection(Constraint<Pair>::new)) );
} );
ret.addOderConstraint(setCons);} );
return ret;
};
methodAndTph = new MethodAndTPH(id, filterConstrRemainingTVar.apply(method.getConstraints()));
inLocalOrParamOrReturn = true; inLocalOrParamOrReturn = true;
method.getReturnType().accept(this); method.getReturnType().accept(this);
@ -194,7 +222,7 @@ public class TPHExtractor extends AbstractASTWalker {
if(method.block != null) if(method.block != null)
method.block.accept(this); method.block.accept(this);
inMethod = false; inMethod = false;
ListOfMethodsAndTph.add(methodAndTph); ListOfMethodsAndTph.add(methodAndTph);
} }

View File

@ -23,9 +23,17 @@ public class ConstraintSet<A> {
oderConstraints.add(methodConstraints); oderConstraints.add(methodConstraints);
} }
public void addAllUndConstraint(Constraint<A> allUndConstraints){
undConstraints.addAll(allUndConstraints);
}
public void addAllOderConstraint(List<Set<Constraint<A>>> allOderConstraints){
this.oderConstraints.addAll(allOderConstraints);
}
public void addAll(ConstraintSet constraints) { public void addAll(ConstraintSet constraints) {
this.undConstraints.addAll(constraints.undConstraints); this.addAllUndConstraint(constraints.undConstraints);
this.oderConstraints.addAll(constraints.oderConstraints); this.addAllOderConstraint(constraints.oderConstraints);
} }
@Override @Override