forked from JavaTX/JavaCompilerCore
modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java
F-Bounded Problematik durche neues greater ggf. geloest. Es werden Falle ausgeschlossen. Diese Faelle muessen noch ergaenzt werden.
This commit is contained in:
parent
704415ae3b
commit
87dede5d5f
@ -193,7 +193,83 @@ public class FiniteClosure extends Ordering<UnifyType> implements IFiniteClosure
|
||||
* @return The set of supertypes of the argument.
|
||||
*/
|
||||
@Override
|
||||
//Eingefuegt PL 2018-05-24 F-Bounded Problematik
|
||||
public Set<UnifyType> greater(UnifyType type, Set<UnifyType> fBounded) {
|
||||
Set<UnifyType> result = new HashSet<>();
|
||||
Set<Pair<UnifyType,Set<UnifyType>>> PairResultFBounded = new HashSet<>();
|
||||
|
||||
Match match = new Match();
|
||||
|
||||
|
||||
// if T = T' then T <=* T'
|
||||
result.add(type);
|
||||
if(!strInheritanceGraph.containsKey(type.getName()))
|
||||
return result;
|
||||
|
||||
// if T <* T' then sigma(T) <* sigma(T')
|
||||
Set<Node<UnifyType>> candidates = strInheritanceGraph.get(type.getName());
|
||||
for(Node<UnifyType> candidate : candidates) {
|
||||
UnifyType theta1 = candidate.getContent();
|
||||
|
||||
//PL 18-04-05 Unifier durch Matcher ersetzt ANFANG
|
||||
ArrayList<UnifyPair> termList= new ArrayList<UnifyPair>();
|
||||
termList.add(new UnifyPair(theta1,type, PairOperator.EQUALSDOT));
|
||||
Optional<Unifier> optSigma = match.match(termList);
|
||||
//PL 18-04-05 Unifier durch Matcher ersetzt ENDE
|
||||
if(!optSigma.isPresent())
|
||||
continue;
|
||||
|
||||
Unifier sigma = optSigma.get();
|
||||
sigma.swapPlaceholderSubstitutionsReverse(theta1.getTypeParams());
|
||||
|
||||
Set<UnifyType> fBoundedNew = new HashSet<>(fBounded);
|
||||
fBoundedNew.add(theta1);
|
||||
Set<UnifyType> theta2Set = candidate.getContentOfPredecessors();
|
||||
|
||||
for(UnifyType theta2 : theta2Set) {
|
||||
result.add(theta2.apply(sigma));
|
||||
PairResultFBounded.add(new Pair<>(theta2.apply(sigma), fBoundedNew));
|
||||
}
|
||||
}
|
||||
|
||||
for(Pair<UnifyType,Set<UnifyType>> pt : PairResultFBounded) {
|
||||
UnifyType t = pt.getKey();
|
||||
Set<UnifyType> lfBounded = pt.getValue().get();
|
||||
|
||||
// if C<...> <* C<...> then ... (third case in definition of <*)
|
||||
//TypeParams typeparams = t.getTypeParams();
|
||||
if(t.getTypeParams().size() > 0) {
|
||||
ArrayList<Set<UnifyType>> paramCandidates = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < t.getTypeParams().size(); i++) {
|
||||
//UnifyType parai = t.getTypeParams().get(i);
|
||||
int i_ef = i;
|
||||
BiFunction<Boolean,UnifyType,Boolean> f = (x,y) ->
|
||||
{
|
||||
ArrayList<UnifyPair> termList = new ArrayList<UnifyPair>();
|
||||
termList.add(new UnifyPair(y,t.getTypeParams().get(i_ef), PairOperator.EQUALSDOT));
|
||||
return ((match.match(termList).isPresent()) || x);
|
||||
};
|
||||
//if (parai.getName().equals("java.lang.Integer")) {
|
||||
// System.out.println("");
|
||||
//}
|
||||
BinaryOperator<Boolean> bo = (a,b) -> (a || b);
|
||||
if (lfBounded.stream().reduce(false,f,bo)) continue; //F-Bounded Endlosrekursion
|
||||
paramCandidates.add(grArg(t.getTypeParams().get(i), new HashSet<>(fBounded) ));
|
||||
}
|
||||
permuteParams(paramCandidates).forEach(x -> result.add(t.setTypeParams(x)));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* auskommentiert PL 2018-05-24
|
||||
/**
|
||||
* Returns all types of the finite closure that are supertypes of the argument.
|
||||
* @return The set of supertypes of the argument.
|
||||
*
|
||||
//@Override
|
||||
public Set<UnifyType> oldgreater(UnifyType type, Set<UnifyType> fBounded) {
|
||||
if(type instanceof FunNType)
|
||||
return computeGreaterFunN((FunNType) type, fBounded);
|
||||
|
||||
@ -204,7 +280,7 @@ public class FiniteClosure extends Ordering<UnifyType> implements IFiniteClosure
|
||||
|
||||
/**
|
||||
* Computes the greater function for all types except function types.
|
||||
*/
|
||||
*
|
||||
protected Set<UnifyType> computeGreater(Set<Pair<UnifyType,Set<UnifyType>>> types) {
|
||||
Set<Pair<UnifyType,Set<UnifyType>>> result = new HashSet<>();
|
||||
|
||||
@ -275,6 +351,7 @@ public class FiniteClosure extends Ordering<UnifyType> implements IFiniteClosure
|
||||
return resut;
|
||||
return computeGreater(result);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Computes the greater function for FunN-Types
|
||||
|
Loading…
Reference in New Issue
Block a user