forked from JavaTX/JavaCompilerCore
reduceExt
This commit is contained in:
parent
2483044e0c
commit
c08a8fd347
@ -1,15 +1,13 @@
|
||||
package de.dhbwstuttgart.syntaxtree.factory;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.syntaxtree.type.WildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.ObjectType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.syntaxtree.type.WildcardType;
|
||||
import de.dhbwstuttgart.typeinference.Menge;
|
||||
import de.dhbwstuttgart.typeinference.Pair;
|
||||
import de.dhbwstuttgart.typeinference.Pair.PairOperator;
|
||||
|
||||
public class UnifyTypeFactory {
|
||||
|
||||
|
@ -84,8 +84,34 @@ public class RuleSet implements IRuleSet{
|
||||
else if(lhsType instanceof ExtendsType)
|
||||
lhsSType = (SimpleType) ((ExtendsType) lhsType).GetExtendedType();
|
||||
else
|
||||
return Optional.empty();
|
||||
|
||||
return null;
|
||||
if(lhsSType.getTypeParams().empty())
|
||||
return Optional.empty();
|
||||
|
||||
Type rhsType = pair.getRhsType();
|
||||
|
||||
if(!(rhsType instanceof ExtendsType))
|
||||
return Optional.empty();
|
||||
|
||||
SimpleType rhsSType = (SimpleType) ((ExtendsType) rhsType).GetExtendedType();
|
||||
|
||||
if(rhsSType.getTypeParams().size() != lhsSType.getTypeParams().size())
|
||||
return Optional.empty();
|
||||
|
||||
int[] pi = pi(lhsSType, rhsType);
|
||||
|
||||
if(pi.length == 0)
|
||||
return Optional.empty();
|
||||
|
||||
Type[] rhsTypeParams = rhsSType.getTypeParams().asArray();
|
||||
Type[] lhsTypeParams = lhsSType.getTypeParams().asArray();
|
||||
Set<MPair> result = new HashSet<>();
|
||||
|
||||
for(int rhsIdx = 0; rhsIdx < rhsTypeParams.length; rhsIdx++)
|
||||
result.add(new MPair(lhsTypeParams[pi[rhsIdx]], rhsTypeParams[rhsIdx], PairOperator.SMALLERDOTWC));
|
||||
|
||||
return Optional.of(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -116,7 +142,7 @@ public class RuleSet implements IRuleSet{
|
||||
SimpleType lhsSType = (SimpleType) lhsType;
|
||||
SimpleType rhsSType = (SimpleType) rhsType;
|
||||
|
||||
if(lhsSType.getTypeParams().empty()|| rhsSType.getTypeParams().empty() || lhsSType.getTypeParams().size() != rhsSType.getTypeParams().size())
|
||||
if(lhsSType.getTypeParams().empty() || rhsSType.getTypeParams().empty() || lhsSType.getTypeParams().size() != rhsSType.getTypeParams().size())
|
||||
return Optional.empty();
|
||||
|
||||
int[] pi = pi(lhsSType, rhsSType);
|
||||
@ -129,7 +155,7 @@ public class RuleSet implements IRuleSet{
|
||||
Set<MPair> result = new HashSet<>();
|
||||
|
||||
for(int rhsIdx = 0; rhsIdx < rhsTypeParams.length; rhsIdx++)
|
||||
result.add(new MPair(lhsTypeParams[pi[rhsIdx]], rhsTypeParams[rhsIdx], PairOperator.SMALLERDOT));
|
||||
result.add(new MPair(lhsTypeParams[pi[rhsIdx]], rhsTypeParams[rhsIdx], PairOperator.SMALLERDOTWC));
|
||||
|
||||
return Optional.of(result);
|
||||
}
|
||||
@ -165,12 +191,13 @@ public class RuleSet implements IRuleSet{
|
||||
rhsSType = (SimpleType) ((SuperType) rhsType).GetSuperedType();
|
||||
else
|
||||
return Optional.empty();
|
||||
|
||||
if(rhsSType.getTypeParams().empty())
|
||||
|
||||
if(!rhsSType.getName().equals(lhsSType.getName()))
|
||||
return Optional.empty();
|
||||
|
||||
if(rhsSType.getTypeParams().size() != lhsSType.getTypeParams().size())
|
||||
return Optional.empty();
|
||||
Assert.assertEquals(lhsSType.getTypeParams().size(), rhsSType.getTypeParams().size());
|
||||
//if(rhsSType.getTypeParams().size() != lhsSType.getTypeParams().size())
|
||||
// return Optional.empty();
|
||||
|
||||
Set<MPair> result = new HashSet<>();
|
||||
|
||||
@ -261,17 +288,31 @@ public class RuleSet implements IRuleSet{
|
||||
* @return An array containing the values of pi for every type argument of C or an empty array if the search failed.
|
||||
*/
|
||||
private int[] pi(Type C, Type D) {
|
||||
Type dFromFc = finiteClosure.getType(D.getName());
|
||||
if(dFromFc == null)
|
||||
Type cFromFc = finiteClosure.getType(C.getName());
|
||||
if(cFromFc == null)
|
||||
return new int[0];
|
||||
|
||||
Set<Type> smallerRhs = finiteClosure.smaller(dFromFc);
|
||||
Optional<Type> opt = smallerRhs.stream().filter(x -> x.getName().equals(C.getName())).findAny();
|
||||
Optional<Type> opt = Optional.empty();
|
||||
if(D instanceof ExtendsType) {
|
||||
SimpleType dSType = (SimpleType) ((ExtendsType) D).GetExtendedType();
|
||||
opt = finiteClosure.grArg(cFromFc).stream()
|
||||
.filter(x -> x instanceof ExtendsType)
|
||||
.filter(x -> ((ExtendsType) x).GetExtendedType().equals(dSType.getName())).findAny();
|
||||
}
|
||||
else if(D instanceof SuperType) {
|
||||
SimpleType dSType = (SimpleType) ((SuperType) D).GetSuperedType();
|
||||
opt = finiteClosure.grArg(cFromFc).stream()
|
||||
.filter(x -> x instanceof SuperType)
|
||||
.filter(x -> ((SuperType) x).GetSuperedType().equals(dSType.getName())).findAny();
|
||||
}
|
||||
else if (D instanceof SimpleType)
|
||||
opt = finiteClosure.greater(cFromFc).stream()
|
||||
.filter(x -> x.getName().equals(D.getName())).findAny();
|
||||
|
||||
if(!opt.isPresent())
|
||||
return new int[0];
|
||||
|
||||
Type cFromFc = opt.get();
|
||||
Type dFromFc = opt.get();
|
||||
|
||||
Assert.assertEquals(cFromFc.getTypeParams().size(), dFromFc.getTypeParams().size());
|
||||
Assert.assertTrue(dFromFc.getTypeParams().size() > 0);
|
||||
|
@ -1,9 +1,18 @@
|
||||
package de.dhbwstuttgart.typinference.unify.model;
|
||||
|
||||
public class ExtendsType extends Type {
|
||||
private Type extendedType;
|
||||
|
||||
public ExtendsType(Type extendedType) {
|
||||
this.extendedType = extendedType;
|
||||
}
|
||||
|
||||
public Type GetExtendedType() {
|
||||
return null;
|
||||
// TODO
|
||||
return extendedType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeParams getTypeParams() {
|
||||
return extendedType.getTypeParams();
|
||||
}
|
||||
}
|
||||
|
@ -16,4 +16,9 @@ public class SuperType extends Type {
|
||||
public String toString() {
|
||||
return "? super " + superedType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeParams getTypeParams() {
|
||||
return superedType.getTypeParams();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user