forked from JavaTX/JavaCompilerCore
modified: ../../src/de/dhbwstuttgart/typeinference/unify/RuleSet.java
modified: ../../src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/ExtendsType.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/FunNType.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/ReferenceType.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/SuperType.java modified: ../../src/de/dhbwstuttgart/typeinference/unify/model/UnifyType.java modified: ../../test/javFiles/Matrix.jav F-Bounded angefangen
This commit is contained in:
parent
a5ed5a2a46
commit
26d9b1215f
@ -131,7 +131,7 @@ public class RuleSet implements IRuleSet{
|
|||||||
if(x instanceof ExtendsType)
|
if(x instanceof ExtendsType)
|
||||||
xFromFc = new ExtendsType(xFromFc);
|
xFromFc = new ExtendsType(xFromFc);
|
||||||
|
|
||||||
UnifyType extYFromFc = fc.grArg(xFromFc).stream().filter(t -> t.getName().equals(extY.getName())).filter(t -> t.getTypeParams().arePlaceholders()).findAny().orElse(null);
|
UnifyType extYFromFc = fc.grArg(xFromFc, new HashSet<>()).stream().filter(t -> t.getName().equals(extY.getName())).filter(t -> t.getTypeParams().arePlaceholders()).findAny().orElse(null);
|
||||||
|
|
||||||
if(extYFromFc == null || extYFromFc.getTypeParams() != xFromFc.getTypeParams())
|
if(extYFromFc == null || extYFromFc.getTypeParams() != xFromFc.getTypeParams())
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
@ -183,7 +183,7 @@ public class RuleSet implements IRuleSet{
|
|||||||
if(x instanceof SuperType)
|
if(x instanceof SuperType)
|
||||||
xFromFc = new SuperType(xFromFc);
|
xFromFc = new SuperType(xFromFc);
|
||||||
|
|
||||||
UnifyType supYFromFc = fc.grArg(xFromFc).stream().filter(t -> t.getName().equals(supY.getName())).filter(t -> t.getTypeParams().arePlaceholders()).findAny().orElse(null);
|
UnifyType supYFromFc = fc.grArg(xFromFc, new HashSet<>()).stream().filter(t -> t.getName().equals(supY.getName())).filter(t -> t.getTypeParams().arePlaceholders()).findAny().orElse(null);
|
||||||
|
|
||||||
if(supYFromFc == null || supYFromFc.getTypeParams() != xFromFc.getTypeParams())
|
if(supYFromFc == null || supYFromFc.getTypeParams() != xFromFc.getTypeParams())
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
@ -380,7 +380,7 @@ public class RuleSet implements IRuleSet{
|
|||||||
if(!(rhsType instanceof ReferenceType) && !(rhsType instanceof PlaceholderType))
|
if(!(rhsType instanceof ReferenceType) && !(rhsType instanceof PlaceholderType))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return fc.greater(lhsType).contains(rhsType);
|
return fc.greater(lhsType, new HashSet<>()).contains(rhsType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -391,7 +391,7 @@ public class RuleSet implements IRuleSet{
|
|||||||
UnifyType lhsType = pair.getLhsType();
|
UnifyType lhsType = pair.getLhsType();
|
||||||
UnifyType rhsType = pair.getRhsType();
|
UnifyType rhsType = pair.getRhsType();
|
||||||
|
|
||||||
return fc.grArg(lhsType).contains(rhsType);
|
return fc.grArg(lhsType, new HashSet<>()).contains(rhsType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -497,7 +497,7 @@ public class RuleSet implements IRuleSet{
|
|||||||
if(typeDgen == null)
|
if(typeDgen == null)
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
||||||
Set<UnifyType> grArg = fc.grArg(typeDgen);
|
Set<UnifyType> grArg = fc.grArg(typeDgen, new HashSet<>());
|
||||||
|
|
||||||
Optional<UnifyType> opt = grArg.stream().filter(x -> x.getName().equals(typeExtDs.getName())).findAny();
|
Optional<UnifyType> opt = grArg.stream().filter(x -> x.getName().equals(typeExtDs.getName())).findAny();
|
||||||
|
|
||||||
@ -543,7 +543,7 @@ public class RuleSet implements IRuleSet{
|
|||||||
|
|
||||||
// Use of smArg instead of grArg because
|
// Use of smArg instead of grArg because
|
||||||
// a in grArg(b) => b in smArg(a)
|
// a in grArg(b) => b in smArg(a)
|
||||||
Set<UnifyType> smArg = fc.smArg(typeSupDgen);
|
Set<UnifyType> smArg = fc.smArg(typeSupDgen, new HashSet<>());
|
||||||
opt = smArg.stream().filter(x -> x.getName().equals(typeDs.getName())).findAny();
|
opt = smArg.stream().filter(x -> x.getName().equals(typeDs.getName())).findAny();
|
||||||
|
|
||||||
if(!opt.isPresent())
|
if(!opt.isPresent())
|
||||||
|
@ -944,7 +944,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
for(UnifyType c : csPHRenamed) {
|
for(UnifyType c : csPHRenamed) {
|
||||||
//PL 18-02-05 getChildren durch smaller ersetzt in getChildren werden die Varianlen nicht ersetzt.
|
//PL 18-02-05 getChildren durch smaller ersetzt in getChildren werden die Varianlen nicht ersetzt.
|
||||||
Set<UnifyType> thetaQs = fc.smaller(c).stream().collect(Collectors.toCollection(HashSet::new));
|
Set<UnifyType> thetaQs = fc.smaller(c, new HashSet<>()).stream().collect(Collectors.toCollection(HashSet::new));
|
||||||
//Set<UnifyType> thetaQs = fc.getChildren(c).stream().collect(Collectors.toCollection(HashSet::new));
|
//Set<UnifyType> thetaQs = fc.getChildren(c).stream().collect(Collectors.toCollection(HashSet::new));
|
||||||
//thetaQs.add(thetaPrime); //PL 18-02-05 wieder geloescht
|
//thetaQs.add(thetaPrime); //PL 18-02-05 wieder geloescht
|
||||||
//PL 2017-10-03: War auskommentiert habe ich wieder einkommentiert,
|
//PL 2017-10-03: War auskommentiert habe ich wieder einkommentiert,
|
||||||
@ -962,7 +962,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
ArrayList<Set<UnifyType>> candidateParams = new ArrayList<>();
|
ArrayList<Set<UnifyType>> candidateParams = new ArrayList<>();
|
||||||
|
|
||||||
for(UnifyType param : cParams)
|
for(UnifyType param : cParams)
|
||||||
candidateParams.add(fc.grArg(param));
|
candidateParams.add(fc.grArg(param, new HashSet<>()));
|
||||||
|
|
||||||
for(TypeParams tp : permuteParams(candidateParams))
|
for(TypeParams tp : permuteParams(candidateParams))
|
||||||
thetaQPrimes.add(c.setTypeParams(tp));
|
thetaQPrimes.add(c.setTypeParams(tp));
|
||||||
@ -985,7 +985,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
//List<UnifyType> freshTphs = new ArrayList<>(); PL 18-02-06 in die For-Schleife verschoben
|
//List<UnifyType> freshTphs = new ArrayList<>(); PL 18-02-06 in die For-Schleife verschoben
|
||||||
for (UnifyType tq : thetaQs) {
|
for (UnifyType tq : thetaQs) {
|
||||||
Set<UnifyType> smaller = fc.smaller(unifier.apply(tq));
|
Set<UnifyType> smaller = fc.smaller(unifier.apply(tq), new HashSet<>());
|
||||||
//eingefuegt PL 2018-03-29 Anfang ? ext. theta hinzufuegen
|
//eingefuegt PL 2018-03-29 Anfang ? ext. theta hinzufuegen
|
||||||
if (a.isWildcardable()) {
|
if (a.isWildcardable()) {
|
||||||
Set<UnifyType> smaller_ext = smaller.stream().filter(x -> !(x instanceof ExtendsType) && !(x instanceof SuperType))
|
Set<UnifyType> smaller_ext = smaller.stream().filter(x -> !(x instanceof ExtendsType) && !(x instanceof SuperType))
|
||||||
@ -1106,7 +1106,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(UnifyType thetaS : fc.greater(theta)) {
|
for(UnifyType thetaS : fc.greater(theta, new HashSet<>())) {
|
||||||
Set<UnifyPair> resultPrime = new HashSet<>();
|
Set<UnifyPair> resultPrime = new HashSet<>();
|
||||||
|
|
||||||
UnifyType[] freshTphs = new UnifyType[thetaS.getTypeParams().size()];
|
UnifyType[] freshTphs = new UnifyType[thetaS.getTypeParams().size()];
|
||||||
|
@ -21,42 +21,42 @@ public interface IFiniteClosure {
|
|||||||
* Returns all types of the finite closure that are subtypes of the argument.
|
* Returns all types of the finite closure that are subtypes of the argument.
|
||||||
* @return The set of subtypes of the argument.
|
* @return The set of subtypes of the argument.
|
||||||
*/
|
*/
|
||||||
public Set<UnifyType> smaller(UnifyType type);
|
public Set<UnifyType> smaller(UnifyType type, Set<UnifyType> fBounded);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all types of the finite closure that are supertypes of the argument.
|
* Returns all types of the finite closure that are supertypes of the argument.
|
||||||
* @return The set of supertypes of the argument.
|
* @return The set of supertypes of the argument.
|
||||||
*/
|
*/
|
||||||
public Set<UnifyType> greater(UnifyType type);
|
public Set<UnifyType> greater(UnifyType type, Set<UnifyType> fBounded);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wo passt Type rein?
|
* Wo passt Type rein?
|
||||||
* @param type
|
* @param type
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Set<UnifyType> grArg(UnifyType type);
|
public Set<UnifyType> grArg(UnifyType type, Set<UnifyType> fBounded);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Was passt in Type rein?
|
* Was passt in Type rein?
|
||||||
* @param type
|
* @param type
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Set<UnifyType> smArg(UnifyType type);
|
public Set<UnifyType> smArg(UnifyType type, Set<UnifyType> fBounded);
|
||||||
|
|
||||||
public Set<UnifyType> grArg(ReferenceType type);
|
public Set<UnifyType> grArg(ReferenceType type, Set<UnifyType> fBounded);
|
||||||
public Set<UnifyType> smArg(ReferenceType type);
|
public Set<UnifyType> smArg(ReferenceType type, Set<UnifyType> fBounded);
|
||||||
|
|
||||||
public Set<UnifyType> grArg(ExtendsType type);
|
public Set<UnifyType> grArg(ExtendsType type, Set<UnifyType> fBounded);
|
||||||
public Set<UnifyType> smArg(ExtendsType type);
|
public Set<UnifyType> smArg(ExtendsType type, Set<UnifyType> fBounded);
|
||||||
|
|
||||||
public Set<UnifyType> grArg(SuperType type);
|
public Set<UnifyType> grArg(SuperType type, Set<UnifyType> fBounded);
|
||||||
public Set<UnifyType> smArg(SuperType type);
|
public Set<UnifyType> smArg(SuperType type, Set<UnifyType> fBounded);
|
||||||
|
|
||||||
public Set<UnifyType> grArg(PlaceholderType type);
|
public Set<UnifyType> grArg(PlaceholderType type, Set<UnifyType> fBounded);
|
||||||
public Set<UnifyType> smArg(PlaceholderType type);
|
public Set<UnifyType> smArg(PlaceholderType type, Set<UnifyType> fBounded);
|
||||||
|
|
||||||
public Set<UnifyType> grArg(FunNType type);
|
public Set<UnifyType> grArg(FunNType type, Set<UnifyType> fBounded);
|
||||||
public Set<UnifyType> smArg(FunNType type);
|
public Set<UnifyType> smArg(FunNType type, Set<UnifyType> fBounded);
|
||||||
|
|
||||||
public Optional<UnifyType> getLeftHandedType(String typeName);
|
public Optional<UnifyType> getLeftHandedType(String typeName);
|
||||||
public Set<UnifyType> getAncestors(UnifyType t);
|
public Set<UnifyType> getAncestors(UnifyType t);
|
||||||
|
@ -47,13 +47,13 @@ public final class ExtendsType extends WildcardType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Set<UnifyType> smArg(IFiniteClosure fc) {
|
Set<UnifyType> smArg(IFiniteClosure fc, Set<UnifyType> fBounded) {
|
||||||
return fc.smArg(this);
|
return fc.smArg(this, fBounded);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Set<UnifyType> grArg(IFiniteClosure fc) {
|
Set<UnifyType> grArg(IFiniteClosure fc, Set<UnifyType> fBounded) {
|
||||||
return fc.grArg(this);
|
return fc.grArg(this, fBounded);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -4,8 +4,11 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Hashtable;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.function.BinaryOperator;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.google.common.collect.Ordering;
|
import com.google.common.collect.Ordering;
|
||||||
@ -92,36 +95,43 @@ public class FiniteClosure extends Ordering<UnifyType> implements IFiniteClosure
|
|||||||
* @return The set of subtypes of the argument.
|
* @return The set of subtypes of the argument.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Set<UnifyType> smaller(UnifyType type) {
|
public Set<UnifyType> smaller(UnifyType type, Set<UnifyType> fBounded) {
|
||||||
if(type instanceof FunNType)
|
if(type instanceof FunNType)
|
||||||
return computeSmallerFunN((FunNType) type);
|
return computeSmallerFunN((FunNType) type, fBounded);
|
||||||
|
|
||||||
Set<UnifyType> ts = new HashSet<>();
|
Set<Pair<UnifyType,Set<UnifyType>>> ts = new HashSet<>();
|
||||||
ts.add(type);
|
ts.add(new Pair<>(type, fBounded));
|
||||||
return computeSmaller(ts);
|
return computeSmaller(ts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Computes the smaller functions for every type except FunNTypes.
|
* Computes the smaller functions for every type except FunNTypes.
|
||||||
*/
|
*/
|
||||||
private Set<UnifyType> computeSmaller(Set<UnifyType> types) {
|
private Set<UnifyType> computeSmaller(Set<Pair<UnifyType,Set<UnifyType>>> types) {
|
||||||
HashSet<UnifyType> result = new HashSet<>();
|
Set<Pair<UnifyType,Set<UnifyType>>> result = new HashSet<>();
|
||||||
|
|
||||||
//PL 18-02-05 Unifier durch Matcher ersetzt
|
//PL 18-02-05 Unifier durch Matcher ersetzt
|
||||||
//IUnify unify = new MartelliMontanariUnify();
|
//IUnify unify = new MartelliMontanariUnify();
|
||||||
Match match = new Match();
|
Match match = new Match();
|
||||||
|
|
||||||
for(UnifyType t : types) {
|
for(Pair<UnifyType,Set<UnifyType>> pt : types) {
|
||||||
|
UnifyType t = pt.getKey();
|
||||||
|
Set<UnifyType> fBounded = pt.getValue().get();
|
||||||
|
|
||||||
// if T = T' then T <* T'
|
// if T = T' then T <* T'
|
||||||
result.add(t);
|
try {
|
||||||
|
result.add(new Pair<>(t, fBounded));
|
||||||
|
}
|
||||||
|
catch (StackOverflowError e) {
|
||||||
|
System.out.println("");
|
||||||
|
}
|
||||||
|
|
||||||
// if C<...> <* C<...> then ... (third case in definition of <*)
|
// if C<...> <* C<...> then ... (third case in definition of <*)
|
||||||
if(t.getTypeParams().size() > 0) {
|
if(t.getTypeParams().size() > 0) {
|
||||||
ArrayList<Set<UnifyType>> paramCandidates = new ArrayList<>();
|
ArrayList<Set<UnifyType>> paramCandidates = new ArrayList<>();
|
||||||
for (int i = 0; i < t.getTypeParams().size(); i++)
|
for (int i = 0; i < t.getTypeParams().size(); i++)
|
||||||
paramCandidates.add(smArg(t.getTypeParams().get(i)));
|
paramCandidates.add(smArg(t.getTypeParams().get(i), fBounded));
|
||||||
permuteParams(paramCandidates).forEach(x -> result.add(t.setTypeParams(x)));
|
permuteParams(paramCandidates).forEach(x -> result.add(new Pair<>(t.setTypeParams(x), fBounded)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!strInheritanceGraph.containsKey(t.getName()))
|
if(!strInheritanceGraph.containsKey(t.getName()))
|
||||||
@ -147,19 +157,21 @@ public class FiniteClosure extends Ordering<UnifyType> implements IFiniteClosure
|
|||||||
Set<UnifyType> theta1Set = candidate.getContentOfDescendants();
|
Set<UnifyType> theta1Set = candidate.getContentOfDescendants();
|
||||||
|
|
||||||
for(UnifyType theta1 : theta1Set)
|
for(UnifyType theta1 : theta1Set)
|
||||||
result.add(theta1.apply(sigma));
|
result.add(new Pair<>(theta1.apply(sigma), fBounded));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(result.equals(types))
|
HashSet<UnifyType> resut = result.stream().map(x -> x.getKey()).collect(Collectors.toCollection(HashSet::new));
|
||||||
return result;
|
System.out.println(resut);
|
||||||
|
if(resut.equals(types.stream().map(x -> x.getKey()).collect(Collectors.toCollection(HashSet::new))))
|
||||||
|
return resut;
|
||||||
return computeSmaller(result);
|
return computeSmaller(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Computes the smaller-Function for FunNTypes.
|
* Computes the smaller-Function for FunNTypes.
|
||||||
*/
|
*/
|
||||||
private Set<UnifyType> computeSmallerFunN(FunNType type) {
|
private Set<UnifyType> computeSmallerFunN(FunNType type, Set<UnifyType> fBounded) {
|
||||||
Set<UnifyType> result = new HashSet<>();
|
Set<UnifyType> result = new HashSet<>();
|
||||||
|
|
||||||
// if T = T' then T <=* T'
|
// if T = T' then T <=* T'
|
||||||
@ -168,9 +180,9 @@ public class FiniteClosure extends Ordering<UnifyType> implements IFiniteClosure
|
|||||||
// Because real function types are implicitly variant
|
// Because real function types are implicitly variant
|
||||||
// it is enough to permute the params with the values of greater / smaller.
|
// it is enough to permute the params with the values of greater / smaller.
|
||||||
ArrayList<Set<UnifyType>> paramCandidates = new ArrayList<>();
|
ArrayList<Set<UnifyType>> paramCandidates = new ArrayList<>();
|
||||||
paramCandidates.add(smaller(type.getTypeParams().get(0)));
|
paramCandidates.add(smaller(type.getTypeParams().get(0), fBounded));
|
||||||
for (int i = 1; i < type.getTypeParams().size(); i++)
|
for (int i = 1; i < type.getTypeParams().size(); i++)
|
||||||
paramCandidates.add(greater(type.getTypeParams().get(i)));
|
paramCandidates.add(greater(type.getTypeParams().get(i), new HashSet<>()));
|
||||||
|
|
||||||
permuteParams(paramCandidates).forEach(x -> result.add(type.setTypeParams(x)));
|
permuteParams(paramCandidates).forEach(x -> result.add(type.setTypeParams(x)));
|
||||||
return result;
|
return result;
|
||||||
@ -181,36 +193,51 @@ public class FiniteClosure extends Ordering<UnifyType> implements IFiniteClosure
|
|||||||
* @return The set of supertypes of the argument.
|
* @return The set of supertypes of the argument.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Set<UnifyType> greater(UnifyType type) {
|
public Set<UnifyType> greater(UnifyType type, Set<UnifyType> fBounded) {
|
||||||
if(type instanceof FunNType)
|
if(type instanceof FunNType)
|
||||||
return computeGreaterFunN((FunNType) type);
|
return computeGreaterFunN((FunNType) type, fBounded);
|
||||||
|
|
||||||
Set<UnifyType> ts = new HashSet<>();
|
Set<Pair<UnifyType,Set<UnifyType>>> ts = new HashSet<>();
|
||||||
ts.add(type);
|
ts.add(new Pair<>(type, fBounded));
|
||||||
return computeGreater(ts);
|
return computeGreater(ts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Computes the greater function for all types except function types.
|
* Computes the greater function for all types except function types.
|
||||||
*/
|
*/
|
||||||
protected Set<UnifyType> computeGreater(Set<UnifyType> types) {
|
protected Set<UnifyType> computeGreater(Set<Pair<UnifyType,Set<UnifyType>>> types) {
|
||||||
HashSet<UnifyType> result = new HashSet<>();
|
Set<Pair<UnifyType,Set<UnifyType>>> result = new HashSet<>();
|
||||||
|
|
||||||
//PL 18-04-05 Unifier durch Matcher ersetzt
|
//PL 18-04-05 Unifier durch Matcher ersetzt
|
||||||
//IUnify unify = new MartelliMontanariUnify();
|
//IUnify unify = new MartelliMontanariUnify();
|
||||||
Match match = new Match();
|
Match match = new Match();
|
||||||
|
|
||||||
for(UnifyType t : types) {
|
for(Pair<UnifyType,Set<UnifyType>> pt : types) {
|
||||||
|
UnifyType t = pt.getKey();
|
||||||
|
Set<UnifyType> fBounded = pt.getValue().get();
|
||||||
// if T = T' then T <=* T'
|
// if T = T' then T <=* T'
|
||||||
result.add(t);
|
result.add(pt);
|
||||||
|
|
||||||
// if C<...> <* C<...> then ... (third case in definition of <*)
|
// if C<...> <* C<...> then ... (third case in definition of <*)
|
||||||
if(t.getTypeParams().size() > 0) {
|
if(t.getTypeParams().size() > 0) {
|
||||||
ArrayList<Set<UnifyType>> paramCandidates = new ArrayList<>();
|
ArrayList<Set<UnifyType>> paramCandidates = new ArrayList<>();
|
||||||
for (int i = 0; i < t.getTypeParams().size(); i++)
|
for (int i = 0; i < t.getTypeParams().size(); i++) {
|
||||||
paramCandidates.add(grArg(t.getTypeParams().get(i)));
|
UnifyType parai = t.getTypeParams().get(i);
|
||||||
permuteParams(paramCandidates).forEach(x -> result.add(t.setTypeParams(x)));
|
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 (fBounded.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(new Pair<>(t.setTypeParams(x), new HashSet<>(fBounded))));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!strInheritanceGraph.containsKey(t.getName()))
|
if(!strInheritanceGraph.containsKey(t.getName()))
|
||||||
@ -220,6 +247,7 @@ public class FiniteClosure extends Ordering<UnifyType> implements IFiniteClosure
|
|||||||
Set<Node<UnifyType>> candidates = strInheritanceGraph.get(t.getName());
|
Set<Node<UnifyType>> candidates = strInheritanceGraph.get(t.getName());
|
||||||
for(Node<UnifyType> candidate : candidates) {
|
for(Node<UnifyType> candidate : candidates) {
|
||||||
UnifyType theta1 = candidate.getContent();
|
UnifyType theta1 = candidate.getContent();
|
||||||
|
|
||||||
//PL 18-04-05 Unifier durch Matcher ersetzt ANFANG
|
//PL 18-04-05 Unifier durch Matcher ersetzt ANFANG
|
||||||
ArrayList<UnifyPair> termList= new ArrayList<UnifyPair>();
|
ArrayList<UnifyPair> termList= new ArrayList<UnifyPair>();
|
||||||
termList.add(new UnifyPair(theta1,t, PairOperator.EQUALSDOT));
|
termList.add(new UnifyPair(theta1,t, PairOperator.EQUALSDOT));
|
||||||
@ -231,23 +259,27 @@ public class FiniteClosure extends Ordering<UnifyType> implements IFiniteClosure
|
|||||||
Unifier sigma = optSigma.get();
|
Unifier sigma = optSigma.get();
|
||||||
sigma.swapPlaceholderSubstitutionsReverse(theta1.getTypeParams());
|
sigma.swapPlaceholderSubstitutionsReverse(theta1.getTypeParams());
|
||||||
|
|
||||||
|
Set<UnifyType> fBoundedNew = new HashSet<>(fBounded);
|
||||||
|
fBoundedNew.add(theta1);
|
||||||
Set<UnifyType> theta2Set = candidate.getContentOfPredecessors();
|
Set<UnifyType> theta2Set = candidate.getContentOfPredecessors();
|
||||||
|
|
||||||
for(UnifyType theta2 : theta2Set)
|
for(UnifyType theta2 : theta2Set)
|
||||||
result.add(theta2.apply(sigma));
|
result.add(new Pair<>(theta2.apply(sigma), fBoundedNew));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(result.equals(types))
|
HashSet<UnifyType> resut = result.stream().map(x -> x.getKey()).collect(Collectors.toCollection(HashSet::new));
|
||||||
return result;
|
System.out.println(resut);
|
||||||
|
if(resut.equals(types.stream().map(x -> x.getKey()).collect(Collectors.toCollection(HashSet::new))))
|
||||||
|
return resut;
|
||||||
return computeGreater(result);
|
return computeGreater(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Computes the greater function for FunN-Types
|
* Computes the greater function for FunN-Types
|
||||||
*/
|
*/
|
||||||
protected Set<UnifyType> computeGreaterFunN(FunNType type) {
|
protected Set<UnifyType> computeGreaterFunN(FunNType type, Set<UnifyType> fBounded) {
|
||||||
Set<UnifyType> result = new HashSet<>();
|
Set<UnifyType> result = new HashSet<>();
|
||||||
|
|
||||||
// if T = T' then T <=* T'
|
// if T = T' then T <=* T'
|
||||||
@ -256,88 +288,88 @@ public class FiniteClosure extends Ordering<UnifyType> implements IFiniteClosure
|
|||||||
// Because real function types are implicitly variant
|
// Because real function types are implicitly variant
|
||||||
// it is enough to permute the params with the values of greater / smaller.
|
// it is enough to permute the params with the values of greater / smaller.
|
||||||
ArrayList<Set<UnifyType>> paramCandidates = new ArrayList<>();
|
ArrayList<Set<UnifyType>> paramCandidates = new ArrayList<>();
|
||||||
paramCandidates.add(greater(type.getTypeParams().get(0)));
|
paramCandidates.add(greater(type.getTypeParams().get(0), new HashSet<>()));
|
||||||
for (int i = 1; i < type.getTypeParams().size(); i++)
|
for (int i = 1; i < type.getTypeParams().size(); i++)
|
||||||
paramCandidates.add(smaller(type.getTypeParams().get(i)));
|
paramCandidates.add(smaller(type.getTypeParams().get(i), fBounded));
|
||||||
permuteParams(paramCandidates).forEach(x -> result.add(type.setTypeParams(x)));
|
permuteParams(paramCandidates).forEach(x -> result.add(type.setTypeParams(x)));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<UnifyType> grArg(UnifyType type) {
|
public Set<UnifyType> grArg(UnifyType type, Set<UnifyType> fBounded) {
|
||||||
return type.grArg(this);
|
return type.grArg(this, fBounded);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<UnifyType> grArg(ReferenceType type) {
|
public Set<UnifyType> grArg(ReferenceType type, Set<UnifyType> fBounded) {
|
||||||
Set<UnifyType> result = new HashSet<UnifyType>();
|
Set<UnifyType> result = new HashSet<UnifyType>();
|
||||||
result.add(type);
|
result.add(type);
|
||||||
smaller(type).forEach(x -> result.add(new SuperType(x)));
|
smaller(type, fBounded).forEach(x -> result.add(new SuperType(x)));
|
||||||
greater(type).forEach(x -> result.add(new ExtendsType(x)));
|
greater(type,fBounded).forEach(x -> result.add(new ExtendsType(x)));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<UnifyType> grArg(FunNType type) {
|
public Set<UnifyType> grArg(FunNType type, Set<UnifyType> fBounded) {
|
||||||
Set<UnifyType> result = new HashSet<UnifyType>();
|
Set<UnifyType> result = new HashSet<UnifyType>();
|
||||||
result.add(type);
|
result.add(type);
|
||||||
smaller(type).forEach(x -> result.add(new SuperType(x)));
|
smaller(type, fBounded).forEach(x -> result.add(new SuperType(x)));
|
||||||
greater(type).forEach(x -> result.add(new ExtendsType(x)));
|
greater(type, fBounded).forEach(x -> result.add(new ExtendsType(x)));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<UnifyType> grArg(ExtendsType type) {
|
public Set<UnifyType> grArg(ExtendsType type, Set<UnifyType> fBounded) {
|
||||||
Set<UnifyType> result = new HashSet<UnifyType>();
|
Set<UnifyType> result = new HashSet<UnifyType>();
|
||||||
result.add(type);
|
result.add(type);
|
||||||
UnifyType t = type.getExtendedType();
|
UnifyType t = type.getExtendedType();
|
||||||
greater(t).forEach(x -> result.add(new ExtendsType(x)));
|
greater(t, fBounded).forEach(x -> result.add(new ExtendsType(x)));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<UnifyType> grArg(SuperType type) {
|
public Set<UnifyType> grArg(SuperType type, Set<UnifyType> fBounded) {
|
||||||
Set<UnifyType> result = new HashSet<UnifyType>();
|
Set<UnifyType> result = new HashSet<UnifyType>();
|
||||||
result.add(type);
|
result.add(type);
|
||||||
UnifyType t = type.getSuperedType();
|
UnifyType t = type.getSuperedType();
|
||||||
smaller(t).forEach(x -> result.add(new SuperType(x)));
|
smaller(t, fBounded).forEach(x -> result.add(new SuperType(x)));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<UnifyType> grArg(PlaceholderType type) {
|
public Set<UnifyType> grArg(PlaceholderType type, Set<UnifyType> fBounded) {
|
||||||
HashSet<UnifyType> result = new HashSet<>();
|
HashSet<UnifyType> result = new HashSet<>();
|
||||||
result.add(type);
|
result.add(type);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<UnifyType> smArg(UnifyType type) {
|
public Set<UnifyType> smArg(UnifyType type, Set<UnifyType> fBounded) {
|
||||||
return type.smArg(this);
|
return type.smArg(this, fBounded);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<UnifyType> smArg(ReferenceType type) {
|
public Set<UnifyType> smArg(ReferenceType type, Set<UnifyType> fBounded) {
|
||||||
Set<UnifyType> result = new HashSet<UnifyType>();
|
Set<UnifyType> result = new HashSet<UnifyType>();
|
||||||
result.add(type);
|
result.add(type);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<UnifyType> smArg(FunNType type) {
|
public Set<UnifyType> smArg(FunNType type, Set<UnifyType> fBounded) {
|
||||||
Set<UnifyType> result = new HashSet<UnifyType>();
|
Set<UnifyType> result = new HashSet<UnifyType>();
|
||||||
result.add(type);
|
result.add(type);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<UnifyType> smArg(ExtendsType type) {
|
public Set<UnifyType> smArg(ExtendsType type, Set<UnifyType> fBounded) {
|
||||||
Set<UnifyType> result = new HashSet<UnifyType>();
|
Set<UnifyType> result = new HashSet<UnifyType>();
|
||||||
result.add(type);
|
result.add(type);
|
||||||
UnifyType t = type.getExtendedType();
|
UnifyType t = type.getExtendedType();
|
||||||
result.add(t);
|
result.add(t);
|
||||||
smaller(t).forEach(x -> {
|
smaller(t, fBounded).forEach(x -> {
|
||||||
result.add(new ExtendsType(x));
|
result.add(new ExtendsType(x));
|
||||||
result.add(x);
|
result.add(x);
|
||||||
});
|
});
|
||||||
@ -346,12 +378,13 @@ public class FiniteClosure extends Ordering<UnifyType> implements IFiniteClosure
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<UnifyType> smArg(SuperType type) {
|
public Set<UnifyType> smArg(SuperType type, Set<UnifyType> fBounded) {
|
||||||
Set<UnifyType> result = new HashSet<UnifyType>();
|
Set<UnifyType> result = new HashSet<UnifyType>();
|
||||||
result.add(type);
|
result.add(type);
|
||||||
UnifyType t = type.getSuperedType();
|
UnifyType t = type.getSuperedType();
|
||||||
result.add(t);
|
result.add(t);
|
||||||
greater(t).forEach(x -> {
|
//*** ACHTUNG das koennte FALSCH sein PL 2018-05-23 evtl. HashSet durch smArg durchschleifen
|
||||||
|
greater(t, fBounded).forEach(x -> {
|
||||||
result.add(new SuperType(x));
|
result.add(new SuperType(x));
|
||||||
result.add(x);
|
result.add(x);
|
||||||
});
|
});
|
||||||
@ -359,7 +392,7 @@ public class FiniteClosure extends Ordering<UnifyType> implements IFiniteClosure
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<UnifyType> smArg(PlaceholderType type) {
|
public Set<UnifyType> smArg(PlaceholderType type, Set<UnifyType> fBounded) {
|
||||||
HashSet<UnifyType> result = new HashSet<>();
|
HashSet<UnifyType> result = new HashSet<>();
|
||||||
result.add(type);
|
result.add(type);
|
||||||
return result;
|
return result;
|
||||||
|
@ -55,13 +55,13 @@ public class FunNType extends UnifyType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Set<UnifyType> smArg(IFiniteClosure fc) {
|
Set<UnifyType> smArg(IFiniteClosure fc, Set<UnifyType> fBounded) {
|
||||||
return fc.smArg(this);
|
return fc.smArg(this, fBounded);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Set<UnifyType> grArg(IFiniteClosure fc) {
|
Set<UnifyType> grArg(IFiniteClosure fc, Set<UnifyType> fBounded) {
|
||||||
return fc.grArg(this);
|
return fc.grArg(this, fBounded);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -113,13 +113,13 @@ public final class PlaceholderType extends UnifyType{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Set<UnifyType> smArg(IFiniteClosure fc) {
|
Set<UnifyType> smArg(IFiniteClosure fc, Set<UnifyType> fBounded) {
|
||||||
return fc.smArg(this);
|
return fc.smArg(this, fBounded);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Set<UnifyType> grArg(IFiniteClosure fc) {
|
Set<UnifyType> grArg(IFiniteClosure fc, Set<UnifyType> fBounded) {
|
||||||
return fc.grArg(this);
|
return fc.grArg(this, fBounded);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -34,13 +34,13 @@ public final class ReferenceType extends UnifyType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Set<UnifyType> smArg(IFiniteClosure fc) {
|
Set<UnifyType> smArg(IFiniteClosure fc, Set<UnifyType> fBounded) {
|
||||||
return fc.smArg(this);
|
return fc.smArg(this, fBounded);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Set<UnifyType> grArg(IFiniteClosure fc) {
|
Set<UnifyType> grArg(IFiniteClosure fc, Set<UnifyType> fBounded) {
|
||||||
return fc.grArg(this);
|
return fc.grArg(this, fBounded);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -48,13 +48,13 @@ public final class SuperType extends WildcardType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Set<UnifyType> smArg(IFiniteClosure fc) {
|
Set<UnifyType> smArg(IFiniteClosure fc, Set<UnifyType> fBounded) {
|
||||||
return fc.smArg(this);
|
return fc.smArg(this, fBounded);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Set<UnifyType> grArg(IFiniteClosure fc) {
|
Set<UnifyType> grArg(IFiniteClosure fc, Set<UnifyType> fBounded) {
|
||||||
return fc.grArg(this);
|
return fc.grArg(this, fBounded);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -68,7 +68,7 @@ public abstract class UnifyType {
|
|||||||
* @param fc The FC that is called.
|
* @param fc The FC that is called.
|
||||||
* @return The set that is smArg(this)
|
* @return The set that is smArg(this)
|
||||||
*/
|
*/
|
||||||
abstract Set<UnifyType> smArg(IFiniteClosure fc);
|
abstract Set<UnifyType> smArg(IFiniteClosure fc, Set<UnifyType> fBounded);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of the visitor-pattern. Returns the set of grArg
|
* Implementation of the visitor-pattern. Returns the set of grArg
|
||||||
@ -76,7 +76,7 @@ public abstract class UnifyType {
|
|||||||
* @param fc The FC that is called.
|
* @param fc The FC that is called.
|
||||||
* @return The set that is grArg(this)
|
* @return The set that is grArg(this)
|
||||||
*/
|
*/
|
||||||
abstract Set<UnifyType> grArg(IFiniteClosure fc);
|
abstract Set<UnifyType> grArg(IFiniteClosure fc, Set<UnifyType> fBounded);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies a unifier to this object.
|
* Applies a unifier to this object.
|
||||||
|
@ -15,9 +15,9 @@ class Matrix extends Vector<Vector<Integer>> {
|
|||||||
var erg = 0;
|
var erg = 0;
|
||||||
var k = 0;
|
var k = 0;
|
||||||
while(k < v1.size()) {
|
while(k < v1.size()) {
|
||||||
erg = erg + v1.elementAt(k) * m.elementAt(k).elementAt(j);
|
//erg = erg + v1.elementAt(k) * m.elementAt(k).elementAt(j);
|
||||||
//erg = add1(erg, mul1(v1.elementAt(k),
|
erg = add1(erg, mul1(v1.elementAt(k),
|
||||||
// m.elementAt(k).elementAt(j)));
|
m.elementAt(k).elementAt(j)));
|
||||||
k++; }
|
k++; }
|
||||||
v2.addElement(new Integer(erg));
|
v2.addElement(new Integer(erg));
|
||||||
j++; }
|
j++; }
|
||||||
|
Loading…
Reference in New Issue
Block a user