forked from JavaTX/JavaCompilerCore
Umstellung auf MPair beginnen
This commit is contained in:
parent
ad2804fab9
commit
fa337c5546
@ -3,4 +3,6 @@ encoding//src/de/dhbwstuttgart/core/MyCompiler.java=UTF-8
|
|||||||
encoding//src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java=UTF-8
|
encoding//src/de/dhbwstuttgart/syntaxtree/statement/LambdaExpression.java=UTF-8
|
||||||
encoding//src/de/dhbwstuttgart/typeinference/SingleConstraint.java=UTF-8
|
encoding//src/de/dhbwstuttgart/typeinference/SingleConstraint.java=UTF-8
|
||||||
encoding//src/de/dhbwstuttgart/typeinference/UndConstraint.java=UTF-8
|
encoding//src/de/dhbwstuttgart/typeinference/UndConstraint.java=UTF-8
|
||||||
|
encoding//src/de/dhbwstuttgart/typeinference/UnifySingleConstraint.java=UTF-8
|
||||||
|
encoding//src/de/dhbwstuttgart/typeinference/UnifyUndConstraint.java=UTF-8
|
||||||
encoding/<project>=UTF-8
|
encoding/<project>=UTF-8
|
||||||
|
@ -46,6 +46,7 @@ import de.dhbwstuttgart.typeinference.ResultSet;
|
|||||||
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet;
|
||||||
import de.dhbwstuttgart.typeinference.TypeinferenceResults;
|
import de.dhbwstuttgart.typeinference.TypeinferenceResults;
|
||||||
import de.dhbwstuttgart.typeinference.UndConstraint;
|
import de.dhbwstuttgart.typeinference.UndConstraint;
|
||||||
|
import de.dhbwstuttgart.typeinference.UnifyConstraintsSet;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption;
|
import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
|
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.ParameterAssumption;
|
import de.dhbwstuttgart.typeinference.assumptions.ParameterAssumption;
|
||||||
@ -255,22 +256,27 @@ public class SourceFile
|
|||||||
|
|
||||||
|
|
||||||
////////////////
|
////////////////
|
||||||
//Karthesisches Produkt bilden:
|
//Typen in UnifyTypen umwandeln:
|
||||||
////////////////
|
////////////////
|
||||||
|
UnifyConstraintsSet unifyConstraints = UnifyTypeFactory.convert(oderConstraints);
|
||||||
|
|
||||||
//Unmögliche ConstraintsSets aussortieren durch Unifizierung
|
//Unmögliche ConstraintsSets aussortieren durch Unifizierung
|
||||||
Function<Menge<Pair>,Menge<Menge<Pair>>> unifier = (pairs)->{
|
Function<Menge<MPair>,Menge<Menge<MPair>>> unifier = (pairs)->{
|
||||||
Menge<Menge<Pair>> retValue = new Menge<>();
|
Menge<Menge<MPair>> retValue = new Menge<>();
|
||||||
Set<MPair> convertPairs = UnifyTypeFactory.convert(pairs);
|
Set<Set<MPair>> unifiedPairs = new Unify().unify(pairs, finiteClosure);
|
||||||
Set<Set<MPair>> unifiedPairs = new Unify().unify(convertPairs, finiteClosure);
|
|
||||||
return retValue;};
|
return retValue;};
|
||||||
//oderConstraints.filterWrongConstraints(unifier);
|
//oderConstraints.filterWrongConstraints(unifier);
|
||||||
|
|
||||||
//oderConstraints.unifyUndConstraints(unifier); //rausgeworfen für Tests (08.12.2015)
|
//oderConstraints.unifyUndConstraints(unifier); //rausgeworfen für Tests (08.12.2015)
|
||||||
|
|
||||||
typinferenzLog.debug("Ãbriggebliebene Konstraints:\n"+oderConstraints+"\n", Section.TYPEINFERENCE);
|
typinferenzLog.debug("Ãbriggebliebene Konstraints:\n"+oderConstraints+"\n", Section.TYPEINFERENCE);
|
||||||
//Die Constraints in Pair's umwandeln (Karthesisches Produkt bilden):
|
|
||||||
Set<Set<Pair>> xConstraints = oderConstraints.cartesianProduct();
|
////////////////
|
||||||
|
//Karthesisches Produkt bilden:
|
||||||
|
////////////////
|
||||||
|
Set<Set<MPair>> xConstraints = unifyConstraints.cartesianProduct();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typinferenzLog.debug("Karthesisches Produkt der Constraints: "+xConstraints, Section.TYPEINFERENCE);
|
typinferenzLog.debug("Karthesisches Produkt der Constraints: "+xConstraints, Section.TYPEINFERENCE);
|
||||||
|
|
||||||
@ -280,28 +286,15 @@ public class SourceFile
|
|||||||
// Unifizierung der Constraints:
|
// Unifizierung der Constraints:
|
||||||
//////////////////////////////
|
//////////////////////////////
|
||||||
boolean unifyFail = true;
|
boolean unifyFail = true;
|
||||||
for(Set<Pair> constraints : xConstraints){
|
for(Set<MPair> constraints : xConstraints){
|
||||||
//Alle durch das Karthesische Produkt entstandenen Möglichkeiten durchgehen:
|
//Alle durch das Karthesische Produkt entstandenen Möglichkeiten durchgehen:
|
||||||
Menge<Menge<Pair>> result = new Menge<Menge<Pair>>();
|
Menge<Menge<Pair>> result = new Menge<Menge<Pair>>();
|
||||||
|
|
||||||
//Alle FunN-Typen werden per clone-methode in RefTypes verwandelt. (Die clone Methode in FunN darf nicht überschrieben werden.
|
|
||||||
for(Pair p : constraints){
|
|
||||||
if(p.TA1 instanceof FunN){
|
|
||||||
p.TA1 = p.TA1.clone();
|
|
||||||
}
|
|
||||||
if(p.TA2 instanceof FunN){
|
|
||||||
p.TA2 = p.TA2.clone();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Erst die Unifizierung erstellen:
|
|
||||||
Menge<MPair> constraintsClone = (Menge<MPair>)constraints.clone();
|
|
||||||
|
|
||||||
//IDEE: Man bildet Zusammenhangskomponenten von Paaren, die gemeinsame Variablen haben
|
//IDEE: Man bildet Zusammenhangskomponenten von Paaren, die gemeinsame Variablen haben
|
||||||
// und unifizert nur die Zusammenhangskomponenten in Schritten 1 - 5
|
// und unifizert nur die Zusammenhangskomponenten in Schritten 1 - 5
|
||||||
|
/*
|
||||||
//Schritt 1: Alle Variablen in den Paaren von Elementen einsammeln
|
//Schritt 1: Alle Variablen in den Paaren von Elementen einsammeln
|
||||||
Menge<Menge<TypePlaceholder>> constraintsclonevars = constraintsClone.stream().map(p -> {Menge<TypePlaceholder> TPHs = new Menge<>();
|
Menge<Menge<TypePlaceholder>> constraintsclonevars = constraints.stream().map(p -> {Menge<TypePlaceholder> TPHs = new Menge<>();
|
||||||
TPHs.addAll(p.TA1.getInvolvedTypePlaceholder());
|
TPHs.addAll(p.TA1.getInvolvedTypePlaceholder());
|
||||||
TPHs.addAll(p.TA2.getInvolvedTypePlaceholder());
|
TPHs.addAll(p.TA2.getInvolvedTypePlaceholder());
|
||||||
return TPHs;}
|
return TPHs;}
|
||||||
@ -362,7 +355,8 @@ public class SourceFile
|
|||||||
return new Menge<>(); //kein unifiziertes Ergebnis, damit wird das Geseamtergebnis []
|
return new Menge<>(); //kein unifiziertes Ergebnis, damit wird das Geseamtergebnis []
|
||||||
return cardprodret;
|
return cardprodret;
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
|
Set<Set<MPair>> unifyResult = new Unify().unify(constraints, finiteClosure);
|
||||||
//Dann den Ergebnissen anfügen
|
//Dann den Ergebnissen anfügen
|
||||||
typinferenzLog.debug("\nErgebnis der Unifizierung:\n"+unifyResult, Section.TYPEINFERENCE);
|
typinferenzLog.debug("\nErgebnis der Unifizierung:\n"+unifyResult, Section.TYPEINFERENCE);
|
||||||
result.addAll(unifyResult);
|
result.addAll(unifyResult);
|
||||||
|
@ -11,11 +11,18 @@ import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
|||||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.WildcardType;
|
import de.dhbwstuttgart.syntaxtree.type.WildcardType;
|
||||||
|
import de.dhbwstuttgart.typeinference.ConstraintsSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.EinzelElement;
|
||||||
import de.dhbwstuttgart.typeinference.KomplexeMenge;
|
import de.dhbwstuttgart.typeinference.KomplexeMenge;
|
||||||
import de.dhbwstuttgart.typeinference.Menge;
|
import de.dhbwstuttgart.typeinference.Menge;
|
||||||
|
import de.dhbwstuttgart.typeinference.OderConstraint;
|
||||||
import de.dhbwstuttgart.typeinference.OderMenge;
|
import de.dhbwstuttgart.typeinference.OderMenge;
|
||||||
import de.dhbwstuttgart.typeinference.Pair;
|
import de.dhbwstuttgart.typeinference.Pair;
|
||||||
|
import de.dhbwstuttgart.typeinference.UndConstraint;
|
||||||
import de.dhbwstuttgart.typeinference.UndMenge;
|
import de.dhbwstuttgart.typeinference.UndMenge;
|
||||||
|
import de.dhbwstuttgart.typeinference.UnifyConstraintsSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.UnifyOderConstraint;
|
||||||
|
import de.dhbwstuttgart.typeinference.UnifyUndConstraint;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption;
|
import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
|
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
|
||||||
@ -85,11 +92,34 @@ public class UnifyTypeFactory {
|
|||||||
return new SimpleType(t.get_Name());
|
return new SimpleType(t.get_Name());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UndMenge<MPair> convert(UndMenge<Pair> constraints) {
|
public static UnifyConstraintsSet convert(ConstraintsSet constraints) {
|
||||||
return null;
|
UnifyConstraintsSet ret = new UnifyConstraintsSet();
|
||||||
|
for(OderConstraint oC : constraints.getOderConstraints()){
|
||||||
|
ret.add(UnifyTypeFactory.convert(oC));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static UnifyOderConstraint convert(OderConstraint set) {
|
||||||
|
UnifyOderConstraint ret = new UnifyOderConstraint();
|
||||||
|
for(UndConstraint oC : set.getUndConstraints()){
|
||||||
|
ret.addConstraint(UnifyTypeFactory.convert(oC));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static OderMenge<MPair> convert(OderMenge<Pair> constraints) {
|
private static UnifyUndConstraint convert(UndConstraint set) {
|
||||||
return null;
|
UnifyUndConstraint ret = new UnifyUndConstraint();
|
||||||
|
for(EinzelElement<Pair> oC : set.getPairs()){
|
||||||
|
ret.add(UnifyTypeFactory.convert(oC));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static MPair convert(EinzelElement<Pair> p) {
|
||||||
|
if(!p.getItem().OperatorSmaller())throw new NotImplementedException();
|
||||||
|
MPair ret = smaller(UnifyTypeFactory.convert(p.getItem().TA1)
|
||||||
|
, UnifyTypeFactory.convert(p.getItem().TA2));
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,10 @@ public class ConstraintsSet extends UndMenge<Pair> implements Iterable<OderConst
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Menge<? extends KomplexeMenge<Pair>> getSet() {
|
public Menge<? extends KomplexeMenge<Pair>> getSet() {
|
||||||
|
return this.getOderConstraints();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Menge<OderConstraint> getOderConstraints() {
|
||||||
return this.constraintsSet;
|
return this.constraintsSet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,4 +30,8 @@ public class EinzelElement<A> implements KomplexeMenge<A>{
|
|||||||
return item.toString();
|
return item.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public A getItem(){
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package de.dhbwstuttgart.typeinference;
|
package de.dhbwstuttgart.typeinference;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||||
@ -41,6 +42,9 @@ public class UndConstraint extends UndMenge<Pair> {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<EinzelElement<Pair>> getPairs(){
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
public UndConstraint(ConstraintType p1, ConstraintType p2) {
|
public UndConstraint(ConstraintType p1, ConstraintType p2) {
|
||||||
|
@ -2,10 +2,10 @@ package de.dhbwstuttgart.typeinference.unify;
|
|||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import de.dhbwstuttgart.typeinference.Pair;
|
import de.dhbwstuttgart.typeinference.unify.model.MPair;
|
||||||
|
|
||||||
public interface Unifier {
|
public interface Unifier {
|
||||||
|
|
||||||
public Set<Set<Pair>> apply (Set<Pair> E);
|
public Set<Set<MPair>> apply (Set<MPair> E);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user