ConstraintsSet umgebaut in eine KomplexeMenge von Pairs

This commit is contained in:
JanUlrich 2015-04-28 15:27:16 +02:00
parent 7ba9688702
commit 1cb335b46b
7 changed files with 68 additions and 32 deletions

View File

@ -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<Menge<Pair>> xConstraints = new Menge<Menge<Pair>>();// = oderConstraints.getConstraints();
Menge<Menge<Pair>> xConstraints = oderConstraints.cartesianProduct();
/*
for(Menge<UndConstraint> uC : oderConstraints.getConstraints()){ //mit dem getConstraints-Aufruf wird das Karthesische Produkt erzeugt.
Menge<Pair> cons = new Menge<Pair>();
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);

View File

@ -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<Pair>{
private static final Logger log = Logger.getLogger(ConstraintsSet.class.getName());
public void add(ConstraintsSet CSet){
for(KomplexeMenge<Pair> i : CSet.set){
this.addItems(i);
}
}
public void add(KomplexeMenge<Pair> 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<Menge<UndConstraint>> getConstraints(){
/*
public Menge<Menge<UndConstraint>> getConstraints(){
Menge<Menge<UndConstraint>> ret = new Menge<Menge<UndConstraint>>();
for(OderConstraint con : constraintsSet){
ret.add(con.getUndConstraints());
}
ret = new KarthesischesProdukt<UndConstraint>().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<UndConstraint> uCons = this.filterUndConstraints();
Menge<Pair> alleUndConstraints = new Menge<>();
for(UndConstraint undConstraint : uCons){
@ -69,6 +88,7 @@ public class ConstraintsSet{
Menge<Menge<Pair>> unifyResult = unifier.apply(undConstraintsUndPairs);
return unifyResult;
});
*/
}
/**
@ -77,11 +97,14 @@ public class ConstraintsSet{
* @return [u1, ... , uN]
*/
private Menge<UndConstraint> filterUndConstraints() {
/*
Menge<UndConstraint> ret = new Menge<>();
for(OderConstraint con : constraintsSet){
UndConstraint filtered = con.filterUndConstraints();
if(filtered != null)ret.add(filtered);
}
return ret;
*/
return null;
}
}

View File

@ -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<Pair>{
//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();
}
*/
}

View File

@ -11,10 +11,11 @@ import de.dhbwstuttgart.typeinference.unify.Unifier;
* @author janulrich
*
*/
public class UndConstraint extends OderConstraint implements Iterable<Pair>{
public class UndConstraint extends UndMenge<Pair> implements Iterable<Pair>{
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<Pair>{
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<Pair>{
UndConstraint filterUndConstraints(){
return this;
}
*/
@Override
public Iterator<Pair> iterator() {
return this.getItems().iterator();
}
public void addConstraint(ConstraintType type, ConstraintType type2) {
this.addItem(new ConstraintPair(type,type2).getPair());
}
}

View File

@ -17,7 +17,7 @@ import de.dhbwstuttgart.typeinference.Pair;
*/
// ino.end
// ino.class.CSubstitutionSet.27471.declaration
public class CSubstitutionSet extends CMengeSet<CSubstitution>
public class CSubstitutionSet extends CVectorSet<CSubstitution>
// ino.end
// ino.class.CSubstitutionSet.27471.body
{

View File

@ -14,7 +14,7 @@ import de.dhbwstuttgart.typeinference.Menge;
*/
// ino.end
// ino.class.CMengeSet.27519.declaration
public abstract class CMengeSet<E> extends CSet<E>
public abstract class CVectorSet<E> extends CSet<E>
// ino.end
// ino.class.CMengeSet.27519.body
{
@ -23,7 +23,7 @@ public abstract class CMengeSet<E> extends CSet<E>
// 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<E> extends CSet<E>
}
// ino.end
public void addAll( CMengeSet<E> set )
public void addAll( CVectorSet<E> set )
{
for( int i=0;i<set.getCardinality(); i++ ){
m_Elements.addElement(set.m_Elements.elementAt(i));
@ -94,10 +94,10 @@ public abstract class CMengeSet<E> extends CSet<E>
// ino.end
// ino.method.unite.27544.body
{
if(!(anotherSet instanceof CMengeSet)){
if(!(anotherSet instanceof CVectorSet)){
return;
}
CMengeSet<E> MengeSet = (CMengeSet<E>)anotherSet;
CVectorSet<E> MengeSet = (CVectorSet<E>)anotherSet;
// Elemente der anderen Menge hinzuf<EFBFBD>gen:
Iterator<E> it = MengeSet.getIterator();
@ -116,10 +116,10 @@ public abstract class CMengeSet<E> extends CSet<E>
// ino.end
// ino.method.subtract.27547.body
{
if(!(anotherSet instanceof CMengeSet)){
if(!(anotherSet instanceof CVectorSet)){
return;
}
CMengeSet<E> MengeSet = (CMengeSet<E>)anotherSet;
CVectorSet<E> MengeSet = (CVectorSet<E>)anotherSet;
// Elemente der anderen Menge entfernen:
m_Elements.removeAll(MengeSet.m_Elements);
@ -140,8 +140,8 @@ public abstract class CMengeSet<E> extends CSet<E>
// 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));

View File

@ -1,8 +1,8 @@
import de.dhbwstuttgart.typeinference.Menge;
import de.dhbwstuttgart.typeinference.Vector;
class ImportGeneric {
m (Menge<Integer> x) {
m (Vector<Integer> x) {
return x.elementAt(1);
}
}