From 1cb335b46b296a15feac79e313f26e3c186c6e76 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Tue, 28 Apr 2015 15:27:16 +0200 Subject: [PATCH] ConstraintsSet umgebaut in eine KomplexeMenge von Pairs --- .../dhbwstuttgart/syntaxtree/SourceFile.java | 4 +- .../typeinference/ConstraintsSet.java | 37 +++++++++++++++---- .../typeinference/SingleConstraint.java | 22 ++++++----- .../typeinference/UndConstraint.java | 13 +++++-- .../typeinference/unify/CSubstitutionSet.java | 2 +- .../typeinference/unify/CVectorSet.java | 18 ++++----- .../TypeInsertTests/LambdaTest25.jav | 4 +- 7 files changed, 68 insertions(+), 32 deletions(-) diff --git a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java index 13e176f9..2732fac9 100755 --- a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -712,7 +712,8 @@ public class SourceFile oderConstraints.unifyUndConstraints(unifier); typinferenzLog.debug("Übriggebliebene Konstraints:\n"+oderConstraints+"\n", Section.TYPEINFERENCE); //Die Constraints in Pair's umwandeln (Karthesisches Produkt bilden): - Menge> xConstraints = new Menge>();// = oderConstraints.getConstraints(); + Menge> xConstraints = oderConstraints.cartesianProduct(); + /* for(Menge uC : oderConstraints.getConstraints()){ //mit dem getConstraints-Aufruf wird das Karthesische Produkt erzeugt. Menge cons = new Menge(); for(UndConstraint undCons:uC){ @@ -720,6 +721,7 @@ public class SourceFile } xConstraints.add(cons); } + */ typinferenzLog.debug("Karthesisches Produkt der Constraints: "+xConstraints, Section.TYPEINFERENCE); finiteClosure.generateFullyNamedTypes(globalAssumptions); diff --git a/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java b/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java index 905eb82a..e31ddfa7 100755 --- a/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java +++ b/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java @@ -6,8 +6,20 @@ import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.logger.*; import de.dhbwstuttgart.typeinference.unify.Unifier; -public class ConstraintsSet{ +public class ConstraintsSet extends UndMenge{ private static final Logger log = Logger.getLogger(ConstraintsSet.class.getName()); + + public void add(ConstraintsSet CSet){ + for(KomplexeMenge i : CSet.set){ + this.addItems(i); + } + } + + public void add(KomplexeMenge constraint){ + this.addItems(constraint); + } + + /* private UndConstraint constraintsSet; public ConstraintsSet(){ @@ -15,38 +27,44 @@ public class ConstraintsSet{ } public void add(ConstraintsSet CSet){ - for(OderConstraint element : CSet) - add(element); + constraintsSet.addItems(CSet.getConstraints()); } public void add(OderConstraint constraint){ constraintsSet.addItems(constraint); } + public UndConstraint getConstraints(){ + return constraintsSet; + } + */ /** * Liefert alle Constraint-Variationen * @return */ + /* public Menge> getConstraints(){ - /* + Menge> ret = new Menge>(); for(OderConstraint con : constraintsSet){ ret.add(con.getUndConstraints()); } ret = new KarthesischesProdukt().berechneKarthesischesProdukt(ret); return ret; - */ + } + @Override public String toString(){ return constraintsSet.toString(); } - - public void filterWrongConstraints(Unifier unify) { +*/ + public void filterWrongConstraints(Unifier unify) {/* for(OderConstraint constraint : this){ constraint.filterWrongConstraints(unify); } + */ } /** @@ -54,6 +72,7 @@ public class ConstraintsSet{ * @param unifier */ public void unifyUndConstraints(Unifier unifier) { + /* Menge uCons = this.filterUndConstraints(); Menge alleUndConstraints = new Menge<>(); for(UndConstraint undConstraint : uCons){ @@ -69,6 +88,7 @@ public class ConstraintsSet{ Menge> unifyResult = unifier.apply(undConstraintsUndPairs); return unifyResult; }); + */ } /** @@ -77,11 +97,14 @@ public class ConstraintsSet{ * @return [u1, ... , uN] */ private Menge filterUndConstraints() { + /* Menge ret = new Menge<>(); for(OderConstraint con : constraintsSet){ UndConstraint filtered = con.filterUndConstraints(); if(filtered != null)ret.add(filtered); } return ret; + */ + return null; } } diff --git a/src/de/dhbwstuttgart/typeinference/SingleConstraint.java b/src/de/dhbwstuttgart/typeinference/SingleConstraint.java index 4aa140c4..49639533 100755 --- a/src/de/dhbwstuttgart/typeinference/SingleConstraint.java +++ b/src/de/dhbwstuttgart/typeinference/SingleConstraint.java @@ -20,22 +20,24 @@ import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException; * Die Klasse stellt ein OderConstraint-Set dar, welches nur aus einem Constraint besteht. * */ -public class SingleConstraint extends UndConstraint{ - private Pair constraintPair; //entspricht θ condition θ' +public class SingleConstraint extends EinzelElement{ + //private Pair constraintPair; //entspricht θ condition θ' //private R condition; //entspricht der condition (R) public SingleConstraint(ConstraintType p1, ConstraintType p2){ + super(new ConstraintPair(p1,p2).getPair()); //super(p1,p2); - ConstraintPair constraintPair = new ConstraintPair(p1,p2);//super.getConstraintPairs().firstElement(); - this.addConstraint(constraintPair); + //ConstraintPair constraintPair = new ConstraintPair(p1,p2);//super.getConstraintPairs().firstElement(); + //this.addConstraint(constraintPair); } public SingleConstraint(ConstraintPair toAdd) { - this.addConstraint(toAdd); + super(toAdd.getPair()); + //this.addConstraint(toAdd); } public Pair getPair(){ - return constraintPair; + return this.getItems().firstElement(); } /* @@ -48,12 +50,12 @@ public class SingleConstraint extends UndConstraint{ */ public void addConstraint(ConstraintPair toAdd){ - if(constraintPair != null)throw new DebugException("Ein Constraint darf nur aus einem ConstraintPair bestehen. Das hinzufügen von "+ toAdd + " ist nicht möglich."); + //if(constraintPair != null)throw new DebugException("Ein Constraint darf nur aus einem ConstraintPair bestehen. Das hinzufügen von "+ toAdd + " ist nicht möglich."); Type p1 = toAdd.getPair().TA1; Type p2 = toAdd.getPair().TA2; if(p1==null || p2 == null)throw new NullPointerException(); - + this.addItem(toAdd.getPair()); //Hier werden die GTVs zu TPH gewandelt. //if(p1 instanceof RefType)((RefType)p1).GTV2TPH(); @@ -73,11 +75,13 @@ public class SingleConstraint extends UndConstraint{ //if(!(p1 instanceof RefType) && !(p1 instanceof TypePlaceholder))throw new DebugException("Fehler: "+p2+" kann nicht in TPH oder RefType umgewandelt werden"); //if(!(p2 instanceof RefType) && !(p2 instanceof TypePlaceholder))throw new DebugException("Fehler: "+p2+" kann nicht in TPH oder RefType umgewandelt werden"); - constraintPair = new Pair(p1,p2); + //constraintPair = new Pair(p1,p2); } + /* @Override public String toString(){ return ""+constraintPair.TA1.toString()+" < "+constraintPair.TA2.toString(); } + */ } diff --git a/src/de/dhbwstuttgart/typeinference/UndConstraint.java b/src/de/dhbwstuttgart/typeinference/UndConstraint.java index 7375eaf4..d2f6694a 100755 --- a/src/de/dhbwstuttgart/typeinference/UndConstraint.java +++ b/src/de/dhbwstuttgart/typeinference/UndConstraint.java @@ -11,10 +11,11 @@ import de.dhbwstuttgart.typeinference.unify.Unifier; * @author janulrich * */ -public class UndConstraint extends OderConstraint implements Iterable{ +public class UndConstraint extends UndMenge implements Iterable{ public UndConstraint(ConstraintType p1, ConstraintType p2) { - super(p1, p2); + //super(p1, p2); + this.addItem(new SingleConstraint(p1,p2).getPair()); } public UndConstraint() { @@ -41,6 +42,7 @@ public class UndConstraint extends OderConstraint implements Iterable{ return ret+"]"; } + /* @Override void filterWrongConstraints(Unifier unifier) { //In einem UndConstraint gibt es keine falschen Constraints @@ -50,9 +52,14 @@ public class UndConstraint extends OderConstraint implements Iterable{ UndConstraint filterUndConstraints(){ return this; } - + */ + @Override public Iterator iterator() { return this.getItems().iterator(); } + + public void addConstraint(ConstraintType type, ConstraintType type2) { + this.addItem(new ConstraintPair(type,type2).getPair()); + } } diff --git a/src/de/dhbwstuttgart/typeinference/unify/CSubstitutionSet.java b/src/de/dhbwstuttgart/typeinference/unify/CSubstitutionSet.java index 7c4b60a7..f02fd605 100755 --- a/src/de/dhbwstuttgart/typeinference/unify/CSubstitutionSet.java +++ b/src/de/dhbwstuttgart/typeinference/unify/CSubstitutionSet.java @@ -17,7 +17,7 @@ import de.dhbwstuttgart.typeinference.Pair; */ // ino.end // ino.class.CSubstitutionSet.27471.declaration -public class CSubstitutionSet extends CMengeSet +public class CSubstitutionSet extends CVectorSet // ino.end // ino.class.CSubstitutionSet.27471.body { diff --git a/src/de/dhbwstuttgart/typeinference/unify/CVectorSet.java b/src/de/dhbwstuttgart/typeinference/unify/CVectorSet.java index 527382a8..e126c557 100755 --- a/src/de/dhbwstuttgart/typeinference/unify/CVectorSet.java +++ b/src/de/dhbwstuttgart/typeinference/unify/CVectorSet.java @@ -14,7 +14,7 @@ import de.dhbwstuttgart.typeinference.Menge; */ // ino.end // ino.class.CMengeSet.27519.declaration -public abstract class CMengeSet extends CSet +public abstract class CVectorSet extends CSet // ino.end // ino.class.CMengeSet.27519.body { @@ -23,7 +23,7 @@ public abstract class CMengeSet extends CSet // ino.end // ino.method.CMengeSet.27526.definition - public CMengeSet() + public CVectorSet() // ino.end // ino.method.CMengeSet.27526.body { @@ -49,7 +49,7 @@ public abstract class CMengeSet extends CSet } // ino.end - public void addAll( CMengeSet set ) + public void addAll( CVectorSet set ) { for( int i=0;i extends CSet // ino.end // ino.method.unite.27544.body { - if(!(anotherSet instanceof CMengeSet)){ + if(!(anotherSet instanceof CVectorSet)){ return; } - CMengeSet MengeSet = (CMengeSet)anotherSet; + CVectorSet MengeSet = (CVectorSet)anotherSet; // Elemente der anderen Menge hinzuf�gen: Iterator it = MengeSet.getIterator(); @@ -116,10 +116,10 @@ public abstract class CMengeSet extends CSet // ino.end // ino.method.subtract.27547.body { - if(!(anotherSet instanceof CMengeSet)){ + if(!(anotherSet instanceof CVectorSet)){ return; } - CMengeSet MengeSet = (CMengeSet)anotherSet; + CVectorSet MengeSet = (CVectorSet)anotherSet; // Elemente der anderen Menge entfernen: m_Elements.removeAll(MengeSet.m_Elements); @@ -140,8 +140,8 @@ public abstract class CMengeSet extends CSet // ino.end // ino.method.equals.27553.body { - if(obj instanceof CMengeSet){ - CMengeSet tripSet= (CMengeSet)obj; + if(obj instanceof CVectorSet){ + CVectorSet tripSet= (CVectorSet)obj; boolean ret = true; ret &= (m_Elements.containsAll(tripSet.m_Elements)); ret &= (tripSet.m_Elements.containsAll(m_Elements)); diff --git a/test/plugindevelopment/TypeInsertTests/LambdaTest25.jav b/test/plugindevelopment/TypeInsertTests/LambdaTest25.jav index b89c4b86..6a9130f5 100644 --- a/test/plugindevelopment/TypeInsertTests/LambdaTest25.jav +++ b/test/plugindevelopment/TypeInsertTests/LambdaTest25.jav @@ -1,8 +1,8 @@ -import de.dhbwstuttgart.typeinference.Menge; +import de.dhbwstuttgart.typeinference.Vector; class ImportGeneric { - m (Menge x) { + m (Vector x) { return x.elementAt(1); } }