Fehler in deepCopy behoben

This commit is contained in:
JanUlrich 2015-07-15 17:09:49 +02:00
parent 6321f1308d
commit 3601d11b0b
5 changed files with 50 additions and 6 deletions

View File

@ -810,7 +810,7 @@ public class SourceFile
// In streamconstraintsclone sind die Mengen von Paar enthalten die unifiziert werden muessen
Stream<Menge<Pair>> streamconstraintsclone = indexeset.stream().map(x -> x.stream()
.map(i -> constraintsClone.elementAt(i))
.collect(Menge::new, Menge::add, Menge::addAll));
.<Menge<Pair>>collect(Menge::new, Menge::add, Menge::addAll));
//Menge<Menge<Pair>> vecconstraintsclone = streamconstraintsclone.collect(Menge::new, Menge::add, Menge::addAll);
System.out.println();
//Schritt 4: Unifikation

View File

@ -0,0 +1,18 @@
package de.dhbwstuttgart.typeinference;
public interface DeepCloneable{
public <A> A deepClone();
}
/*
public class CloneableMenge<A extends DeepCloneable> extends Menge<A>{
public CloneableMenge<A> deepClone(){
CloneableMenge<A> ret = new CloneableMenge<>();
for(A i : this){
ret.add(i.deepClone());
}
return ret;
}
}
*/

View File

@ -3,6 +3,7 @@ package de.dhbwstuttgart.typeinference;
import java.util.Set;
import java.util.Vector;
public class Menge<A> extends Vector<A> implements Set<A>{
}

View File

@ -31,7 +31,7 @@ import de.dhbwstuttgart.syntaxtree.type.WildcardType;
// Klasse, die ein Paar in der Menge Eq speichern kann
// ino.end
// ino.class.Pair.26540.declaration
public class Pair implements Serializable
public class Pair implements Serializable, DeepCloneable
// ino.end
// ino.class.Pair.26540.body
{
@ -414,6 +414,7 @@ public class Pair implements Serializable
}
public Pair deepClone() {
/*
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
@ -427,6 +428,8 @@ public class Pair implements Serializable
} catch (ClassNotFoundException e) {
return null;
}
*/
return clone();
}
}
// ino.end

View File

@ -11,6 +11,9 @@ import java.util.Set;
import de.dhbwstuttgart.typeinference.Menge;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;
import com.google.common.collect.Sets;
@ -41,6 +44,7 @@ import de.dhbwstuttgart.syntaxtree.type.ObjectType;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.syntaxtree.type.WildcardType;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.DeepCloneable;
import de.dhbwstuttgart.typeinference.OderConstraint;
import de.dhbwstuttgart.typeinference.Pair;
import de.dhbwstuttgart.typeinference.Pair.PairOperator;
@ -674,7 +678,7 @@ public class Unify
for (Menge<Menge<Pair>> vecvecpair : cartProduktSets){
if(vecvecpair.size() == 1){//gibt es nur eine UndMenge in diesem Set, dann kommt diese in jedem Karthesischen Produkt vor:
//undMenge.addAll(cloner.deepClone(vecvecpair.firstElement()));
undMenge.addAll(vecvecpair.firstElement());
undMenge.addAll(Unify.deepClone(vecvecpair.firstElement()));
temp.add(vecvecpair);
}else{//gibt es mehrere Mengen, kann gefiltert werden:
oderConstraints.add(vecvecpair); //die Menge zu den zu filternden OderConstraints anfügen
@ -2469,7 +2473,19 @@ throws MatchException
inferencelog.debug("Nummer: " + nTypnrInPair);
inferencelog.debug("TV: " + a.getName());
inferencelog.debug("Bedingung: " + bMitVorbedingung);
/*
Cloner cloner = new Cloner();
cloner.setDumpClonedClasses(true);
SectionLogger log = Logger.getSectionLogger("Subst-Methode", Section.UNIFY);
Timewatch timer = Timewatch.getTimewatch();
de.dhbwstuttgart.logger.Timestamp timestamp = timer.start("Unify-Subst");
P = cloner.deepClone(P);
a = cloner.deepClone(a);
o = cloner.deepClone(o);
long time = timestamp.stop();
log.debug("Benötigte Zeit für DeepClone: "+time);
*/
// richtiger Typ aus Pair raussuchen
Type T = null;
if( nTypnrInPair == 1 )
@ -3632,5 +3648,11 @@ tempKlasse.get_Superclass_Name() ); System.out.println( "P. S.:
return T instanceof FreshWildcardType;
}
private static <A extends DeepCloneable> Menge<A> deepClone(Menge<A> m){
Menge<A> ret = m.stream().<A>map((Function<A,A>)(x -> x.deepClone())).<Menge<A>>collect(Menge::new, Menge::add, Menge::addAll);
return ret;
}
}
// ino.end
// ino.end