Unfertiger Stand Backup
This commit is contained in:
parent
d3eb9f1e1c
commit
fc4d3abfe9
@ -47,11 +47,6 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
return cs_cl;
|
return cs_cl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<MethodConstraint> getMethodConstraintsAlternative() {
|
|
||||||
List<GenericsGeneratorResult> ggRes = GenericsGeneratorResult.
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<MethodConstraint> getMethodConstraints(List<TPHConstraint> cs, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
|
public static List<MethodConstraint> getMethodConstraints(List<TPHConstraint> cs, HashMap<String, PairTphMethod<PositionFinder.Position, String>> posOfTphs) {
|
||||||
//TODO: Regeln
|
//TODO: Regeln
|
||||||
List<MethodConstraint> cs_m = new ArrayList<>();
|
List<MethodConstraint> cs_m = new ArrayList<>();
|
||||||
@ -61,7 +56,7 @@ public class FamilyOfGeneratedGenerics {
|
|||||||
cs_m.add(cons);
|
cs_m.add(cons);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
List<MethodConstraint> methodConstraints2 = firstTransitiveSubtypeForMethodTypes();
|
//List<MethodConstraint> methodConstraints2 = firstTransitiveSubtypeForMethodTypes();
|
||||||
return cs_m;
|
return cs_m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,12 +20,10 @@ import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
|||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
import de.dhbwstuttgart.syntaxtree.TypeScope;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||||
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
@ -51,23 +49,16 @@ import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
|||||||
import de.dhbwstuttgart.typeinference.unify.UnifyResultListener;
|
import de.dhbwstuttgart.typeinference.unify.UnifyResultListener;
|
||||||
import de.dhbwstuttgart.typeinference.unify.UnifyResultListenerImpl;
|
import de.dhbwstuttgart.typeinference.unify.UnifyResultListenerImpl;
|
||||||
import de.dhbwstuttgart.typeinference.unify.UnifyResultModel;
|
import de.dhbwstuttgart.typeinference.unify.UnifyResultModel;
|
||||||
import de.dhbwstuttgart.typeinference.unify.UnifyTaskModel;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLClassLoader;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.antlr.v4.runtime.Token;
|
|
||||||
import org.apache.commons.io.output.NullOutputStream;
|
|
||||||
|
|
||||||
|
|
||||||
public class JavaTXCompiler {
|
public class JavaTXCompiler {
|
||||||
|
|
||||||
@ -76,7 +67,6 @@ public class JavaTXCompiler {
|
|||||||
Boolean resultmodel = true;
|
Boolean resultmodel = true;
|
||||||
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
public final Map<File, SourceFile> sourceFiles = new HashMap<>();
|
||||||
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll?
|
Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll?
|
||||||
public volatile UnifyTaskModel usedTasks = new UnifyTaskModel();
|
|
||||||
private final ClassLoader classLoader;
|
private final ClassLoader classLoader;
|
||||||
|
|
||||||
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
||||||
@ -229,321 +219,6 @@ public class JavaTXCompiler {
|
|||||||
return new ArrayList<>(allClasses);
|
return new ArrayList<>(allClasses);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* public List<ResultSet> typeInferenceOld() throws ClassNotFoundException {
|
|
||||||
* List<ClassOrInterface> allClasses = new
|
|
||||||
* ArrayList<>();//environment.getAllAvailableClasses(); //Alle Importierten
|
|
||||||
* Klassen in allen geparsten Sourcefiles kommen ins FC for(SourceFile sf :
|
|
||||||
* this.sourceFiles.values()) { allClasses.addAll(getAvailableClasses(sf));
|
|
||||||
* allClasses.addAll(sf.getClasses()); }
|
|
||||||
*
|
|
||||||
* final ConstraintSet<Pair> cons = getConstraints();
|
|
||||||
*
|
|
||||||
* FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses);
|
|
||||||
* System.out.println(finiteClosure); ConstraintSet<UnifyPair> unifyCons =
|
|
||||||
* UnifyTypeFactory.convert(cons);
|
|
||||||
*
|
|
||||||
* TypeUnify unify = new TypeUnify(); Set<Set<UnifyPair>> results = new
|
|
||||||
* HashSet<>(); try { File logPath = new
|
|
||||||
* File(System.getProperty("user.dir")+"/target/logFiles/"); logPath.mkdirs();
|
|
||||||
* FileWriter logFile = new FileWriter(new File(logPath, "log"));
|
|
||||||
* logFile.write("FC:\\" + finiteClosure.toString()+"\n"); for(SourceFile sf :
|
|
||||||
* this.sourceFiles.values()) { logFile.write(ASTTypePrinter.print(sf)); }
|
|
||||||
* logFile.flush(); Set<List<Constraint<UnifyPair>>> cardProd =
|
|
||||||
* unifyCons.cartesianProduct(); for (List<Constraint<UnifyPair>> xCons :
|
|
||||||
* cardProd ){ Set<UnifyPair> xConsSet = new HashSet<>(); for
|
|
||||||
* (Constraint<UnifyPair> constraint : xCons) { xConsSet.addAll(constraint); }
|
|
||||||
* //.collect(Collectors.toCollection(ArrayList::new))))
|
|
||||||
* System.out.println(xConsSet); Set<String> methodParaTypeVarNames =
|
|
||||||
* allClasses.stream().map(x -> x.getMethods().stream().map(y ->
|
|
||||||
* y.getParameterList().getFormalparalist() .stream().filter(z -> z.getType()
|
|
||||||
* instanceof TypePlaceholder) .map(z ->
|
|
||||||
* ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(
|
|
||||||
* HashSet::new))) .reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return
|
|
||||||
* a;}, (a,b) -> { a.addAll(b); return a;} ) ) .reduce(new HashSet<String>(),
|
|
||||||
* (a,b) -> { a.addAll(b); return a;} );
|
|
||||||
*
|
|
||||||
* Set<String> constructorParaTypeVarNames = allClasses.stream().map(x ->
|
|
||||||
* x.getConstructors().stream().map(y ->
|
|
||||||
* y.getParameterList().getFormalparalist() .stream().filter(z -> z.getType()
|
|
||||||
* instanceof TypePlaceholder) .map(z ->
|
|
||||||
* ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(
|
|
||||||
* HashSet::new))) .reduce(new HashSet<String>(), (a,b) -> { a.addAll(b); return
|
|
||||||
* a;}, (a,b) -> { a.addAll(b); return a;} ) ) .reduce(new HashSet<String>(),
|
|
||||||
* (a,b) -> { a.addAll(b); return a;} );
|
|
||||||
*
|
|
||||||
* Set<String> paraTypeVarNames = methodParaTypeVarNames;
|
|
||||||
* paraTypeVarNames.addAll(constructorParaTypeVarNames);
|
|
||||||
*
|
|
||||||
* Set<String> returnTypeVarNames = allClasses.stream().map(x ->
|
|
||||||
* x.getMethods().stream().filter(y -> y.getReturnType() instanceof
|
|
||||||
* TypePlaceholder) .map(z ->
|
|
||||||
* ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.
|
|
||||||
* toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;}
|
|
||||||
* ).get();
|
|
||||||
*
|
|
||||||
* Set<String> fieldTypeVarNames = allClasses.stream().map(x ->
|
|
||||||
* x.getFieldDecl().stream().filter(y -> y.getReturnType() instanceof
|
|
||||||
* TypePlaceholder) .map(z ->
|
|
||||||
* ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.
|
|
||||||
* toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;}
|
|
||||||
* ).get();
|
|
||||||
*
|
|
||||||
* returnTypeVarNames.addAll(fieldTypeVarNames);
|
|
||||||
*
|
|
||||||
* xConsSet = xConsSet.stream().map(x -> { //Hier muss ueberlegt werden, ob //1.
|
|
||||||
* alle Argument- und Retuntyp-Variablen in allen UnifyPairs // mit
|
|
||||||
* disableWildcardtable() werden. //2. alle Typvariablen mit Argument- oder
|
|
||||||
* Retuntyp-Variablen //in Beziehung auch auf disableWildcardtable() gesetzt
|
|
||||||
* werden muessen //PL 2018-04-23 if ((x.getLhsType() instanceof
|
|
||||||
* PlaceholderType)) { if (paraTypeVarNames.contains(x.getLhsType().getName()))
|
|
||||||
* { ((PlaceholderType)x.getLhsType()).setVariance((byte)1);
|
|
||||||
* ((PlaceholderType)x.getLhsType()).disableWildcardtable(); } if
|
|
||||||
* (returnTypeVarNames.contains(x.getLhsType().getName())) {
|
|
||||||
* ((PlaceholderType)x.getLhsType()).setVariance((byte)-1);
|
|
||||||
* ((PlaceholderType)x.getLhsType()).disableWildcardtable(); } } if
|
|
||||||
* ((x.getRhsType() instanceof PlaceholderType)) { if
|
|
||||||
* (paraTypeVarNames.contains(x.getRhsType().getName())) {
|
|
||||||
* ((PlaceholderType)x.getRhsType()).setVariance((byte)1);
|
|
||||||
* ((PlaceholderType)x.getRhsType()).disableWildcardtable(); } if
|
|
||||||
* (returnTypeVarNames.contains(x.getRhsType().getName())) {
|
|
||||||
* ((PlaceholderType)x.getRhsType()).setVariance((byte)-1);
|
|
||||||
* ((PlaceholderType)x.getRhsType()).disableWildcardtable(); } } return x;//HIER
|
|
||||||
* DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE JEWEILS
|
|
||||||
* ANDERE SEITE }).map( y -> { if ((y.getLhsType() instanceof PlaceholderType)
|
|
||||||
* && (y.getRhsType() instanceof PlaceholderType)) { if
|
|
||||||
* (((PlaceholderType)y.getLhsType()).getVariance() != 0 &&
|
|
||||||
* ((PlaceholderType)y.getRhsType()).getVariance() == 0) {
|
|
||||||
* ((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType(
|
|
||||||
* )).getVariance()); } if (((PlaceholderType)y.getLhsType()).getVariance() == 0
|
|
||||||
* && ((PlaceholderType)y.getRhsType()).getVariance() != 0) {
|
|
||||||
* ((PlaceholderType)y.getLhsType()).setVariance(((PlaceholderType)y.getRhsType(
|
|
||||||
* )).getVariance()); } } return y; } )
|
|
||||||
* .collect(Collectors.toCollection(HashSet::new));
|
|
||||||
* varianceInheritance(xConsSet); Set<Set<UnifyPair>> result =
|
|
||||||
* unify.unifySequential(xConsSet, finiteClosure, logFile, log);
|
|
||||||
* //Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
|
||||||
* System.out.println("RESULT: " + result); logFile.write("RES: " +
|
|
||||||
* result.toString()+"\n"); logFile.flush(); results.addAll(result); }
|
|
||||||
*
|
|
||||||
* results = results.stream().map(x -> { Optional<Set<UnifyPair>> res = new
|
|
||||||
* RuleSet().subst(x.stream().map(y -> { if (y.getPairOp() ==
|
|
||||||
* PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT); return y;
|
|
||||||
* //alle Paare a <.? b erden durch a =. b ersetzt
|
|
||||||
* }).collect(Collectors.toCollection(HashSet::new))); if (res.isPresent())
|
|
||||||
* {//wenn subst ein Erg liefert wurde was veraendert return new
|
|
||||||
* TypeUnifyTask().applyTypeUnificationRules(res.get(), finiteClosure); } else
|
|
||||||
* return x; //wenn nichts veraendert wurde wird x zurueckgegeben
|
|
||||||
* }).collect(Collectors.toCollection(HashSet::new));
|
|
||||||
* System.out.println("RESULT Final: " + results); logFile.write("RES_FINAL: " +
|
|
||||||
* results.toString()+"\n"); logFile.flush(); logFile.write("PLACEHOLDERS: " +
|
|
||||||
* PlaceholderType.EXISTING_PLACEHOLDERS); logFile.flush(); } catch (IOException
|
|
||||||
* e) { e.printStackTrace(); } return results.stream().map((unifyPairs -> new
|
|
||||||
* ResultSet(UnifyTypeFactory.convert(unifyPairs,
|
|
||||||
* generateTPHMap(cons))))).collect(Collectors.toList()); }
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* Vererbt alle Variancen bei Paaren (a <. theta) oder (Theta <. a) wenn a eine
|
|
||||||
* Variance !=0 hat auf alle Typvariablen in Theta.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
/*
|
|
||||||
* private void varianceInheritance(Set<UnifyPair> eq) { Set<PlaceholderType>
|
|
||||||
* usedTPH = new HashSet<>(); Set<PlaceholderType> phSet = eq.stream().map(x ->
|
|
||||||
* { Set<PlaceholderType> pair = new HashSet<>(); if (x.getLhsType() instanceof
|
|
||||||
* PlaceholderType) pair.add((PlaceholderType)x.getLhsType()); if
|
|
||||||
* (x.getRhsType() instanceof PlaceholderType)
|
|
||||||
* pair.add((PlaceholderType)x.getRhsType()); return pair; }).reduce(new
|
|
||||||
* HashSet<>(), (a,b) -> { a.addAll(b); return a;} , (c,d) -> { c.addAll(d);
|
|
||||||
* return c;});
|
|
||||||
*
|
|
||||||
* ArrayList<PlaceholderType> phSetVariance = new ArrayList<>(phSet);
|
|
||||||
* phSetVariance.removeIf(x -> (x.getVariance() == 0));
|
|
||||||
* while(!phSetVariance.isEmpty()) { PlaceholderType a =
|
|
||||||
* phSetVariance.remove(0); usedTPH.add(a); //HashMap<PlaceholderType,Integer>
|
|
||||||
* ht = new HashMap<>(); //ht.put(a, a.getVariance()); Set<UnifyPair> eq1 = new
|
|
||||||
* HashSet<>(eq); eq1.removeIf(x -> !(x.getLhsType() instanceof PlaceholderType
|
|
||||||
* && ((PlaceholderType)x.getLhsType()).equals(a))); eq1.stream().forEach(x -> {
|
|
||||||
* x.getRhsType().accept(new distributeVariance(), a.getVariance());}); eq1 =
|
|
||||||
* new HashSet<>(eq); eq1.removeIf(x -> !(x.getRhsType() instanceof
|
|
||||||
* PlaceholderType && ((PlaceholderType)x.getRhsType()).equals(a)));
|
|
||||||
* eq1.stream().forEach(x -> { x.getLhsType().accept(new distributeVariance(),
|
|
||||||
* a.getVariance());}); phSetVariance = new ArrayList<>(phSet);
|
|
||||||
* phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x))); }
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
|
|
||||||
public UnifyResultModel typeInferenceAsync(UnifyResultListener resultListener, Writer logFile)
|
|
||||||
throws ClassNotFoundException, IOException {
|
|
||||||
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
|
|
||||||
// Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC
|
|
||||||
for (File f : this.sourceFiles.keySet()) {
|
|
||||||
SourceFile sf = sourceFiles.get(f);
|
|
||||||
allClasses.addAll(getAvailableClasses(sf));
|
|
||||||
allClasses.addAll(sf.getClasses());
|
|
||||||
allClasses.addAll(CompilationEnvironment.loadDefaultPackageClasses(f,classLoader).stream().map(ASTFactory::createClass).collect(Collectors.toList()));
|
|
||||||
}
|
|
||||||
|
|
||||||
final ConstraintSet<Pair> cons = getConstraints();
|
|
||||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
|
||||||
UnifyResultModel urm = null;
|
|
||||||
// urm.addUnifyResultListener(resultListener);
|
|
||||||
try {
|
|
||||||
logFile = logFile == null
|
|
||||||
? new FileWriter(new File("log_" + sourceFiles.keySet().iterator().next().getName()))
|
|
||||||
: logFile;
|
|
||||||
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile, classLoader);
|
|
||||||
System.out.println(finiteClosure);
|
|
||||||
urm = new UnifyResultModel(cons, finiteClosure);
|
|
||||||
urm.addUnifyResultListener(resultListener);
|
|
||||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
|
||||||
|
|
||||||
Function<UnifyPair, UnifyPair> distributeInnerVars = x -> {
|
|
||||||
UnifyType lhs, rhs;
|
|
||||||
if (((lhs = x.getLhsType()) instanceof PlaceholderType)
|
|
||||||
&& ((rhs = x.getRhsType()) instanceof PlaceholderType)
|
|
||||||
&& (((PlaceholderType) lhs).isInnerType() || ((PlaceholderType) rhs).isInnerType())) {
|
|
||||||
((PlaceholderType) lhs).setInnerType(true);
|
|
||||||
((PlaceholderType) rhs).setInnerType(true);
|
|
||||||
}
|
|
||||||
return x;
|
|
||||||
|
|
||||||
};
|
|
||||||
logFile.write(unifyCons.toString());
|
|
||||||
unifyCons = unifyCons.map(distributeInnerVars);
|
|
||||||
logFile.write(unifyCons.toString());
|
|
||||||
TypeUnify unify = new TypeUnify();
|
|
||||||
// Set<Set<UnifyPair>> results = new HashSet<>(); Nach vorne gezogen
|
|
||||||
logFile.write("FC:\\" + finiteClosure.toString() + "\n");
|
|
||||||
for (SourceFile sf : this.sourceFiles.values()) {
|
|
||||||
logFile.write(ASTTypePrinter.print(sf));
|
|
||||||
}
|
|
||||||
logFile.flush();
|
|
||||||
|
|
||||||
Set<String> methodParaTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream()
|
|
||||||
.map(y -> y.getParameterList().getFormalparalist().stream()
|
|
||||||
.filter(z -> z.getType() instanceof TypePlaceholder)
|
|
||||||
.map(z -> ((TypePlaceholder) z.getType()).getName())
|
|
||||||
.collect(Collectors.toCollection(HashSet::new)))
|
|
||||||
.reduce(new HashSet<String>(), (a, b) -> {
|
|
||||||
a.addAll(b);
|
|
||||||
return a;
|
|
||||||
}, (a, b) -> {
|
|
||||||
a.addAll(b);
|
|
||||||
return a;
|
|
||||||
})).reduce(new HashSet<String>(), (a, b) -> {
|
|
||||||
a.addAll(b);
|
|
||||||
return a;
|
|
||||||
});
|
|
||||||
|
|
||||||
Set<String> constructorParaTypeVarNames = allClasses.stream().map(x -> x.getConstructors().stream()
|
|
||||||
.map(y -> y.getParameterList().getFormalparalist().stream()
|
|
||||||
.filter(z -> z.getType() instanceof TypePlaceholder)
|
|
||||||
.map(z -> ((TypePlaceholder) z.getType()).getName())
|
|
||||||
.collect(Collectors.toCollection(HashSet::new)))
|
|
||||||
.reduce(new HashSet<String>(), (a, b) -> {
|
|
||||||
a.addAll(b);
|
|
||||||
return a;
|
|
||||||
}, (a, b) -> {
|
|
||||||
a.addAll(b);
|
|
||||||
return a;
|
|
||||||
})).reduce(new HashSet<String>(), (a, b) -> {
|
|
||||||
a.addAll(b);
|
|
||||||
return a;
|
|
||||||
});
|
|
||||||
|
|
||||||
Set<String> paraTypeVarNames = methodParaTypeVarNames;
|
|
||||||
paraTypeVarNames.addAll(constructorParaTypeVarNames);
|
|
||||||
|
|
||||||
Set<String> returnTypeVarNames = allClasses.stream()
|
|
||||||
.map(x -> x.getMethods().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder)
|
|
||||||
.map(z -> ((TypePlaceholder) z.getReturnType()).getName())
|
|
||||||
.collect(Collectors.toCollection(HashSet::new)))
|
|
||||||
.reduce((a, b) -> {
|
|
||||||
a.addAll(b);
|
|
||||||
return a;
|
|
||||||
}).get();
|
|
||||||
|
|
||||||
Set<String> fieldTypeVarNames = allClasses.stream()
|
|
||||||
.map(x -> x.getFieldDecl().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder)
|
|
||||||
.map(z -> ((TypePlaceholder) z.getReturnType()).getName())
|
|
||||||
.collect(Collectors.toCollection(HashSet::new)))
|
|
||||||
.reduce((a, b) -> {
|
|
||||||
a.addAll(b);
|
|
||||||
return a;
|
|
||||||
}).get();
|
|
||||||
|
|
||||||
returnTypeVarNames.addAll(fieldTypeVarNames);
|
|
||||||
|
|
||||||
unifyCons = unifyCons.map(x -> {
|
|
||||||
// Hier muss ueberlegt werden, ob
|
|
||||||
// 1. alle Argument- und Retuntyp-Variablen in allen UnifyPairs
|
|
||||||
// mit disableWildcardtable() werden.
|
|
||||||
// 2. alle Typvariablen mit Argument- oder Retuntyp-Variablen
|
|
||||||
// in Beziehung auch auf disableWildcardtable() gesetzt werden muessen
|
|
||||||
// PL 2018-04-23
|
|
||||||
if ((x.getLhsType() instanceof PlaceholderType)) {
|
|
||||||
if (paraTypeVarNames.contains(x.getLhsType().getName())) {
|
|
||||||
((PlaceholderType) x.getLhsType()).setVariance((byte) 1);
|
|
||||||
((PlaceholderType) x.getLhsType()).disableWildcardtable();
|
|
||||||
}
|
|
||||||
if (returnTypeVarNames.contains(x.getLhsType().getName())) {
|
|
||||||
((PlaceholderType) x.getLhsType()).setVariance((byte) -1);
|
|
||||||
((PlaceholderType) x.getLhsType()).disableWildcardtable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ((x.getRhsType() instanceof PlaceholderType)) {
|
|
||||||
if (paraTypeVarNames.contains(x.getRhsType().getName())) {
|
|
||||||
((PlaceholderType) x.getRhsType()).setVariance((byte) 1);
|
|
||||||
((PlaceholderType) x.getRhsType()).disableWildcardtable();
|
|
||||||
}
|
|
||||||
if (returnTypeVarNames.contains(x.getRhsType().getName())) {
|
|
||||||
((PlaceholderType) x.getRhsType()).setVariance((byte) -1);
|
|
||||||
((PlaceholderType) x.getRhsType()).disableWildcardtable();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return x;// HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE
|
|
||||||
// JEWEILS ANDERE SEITE
|
|
||||||
});
|
|
||||||
Set<PlaceholderType> varianceTPHold;
|
|
||||||
Set<PlaceholderType> varianceTPH = new HashSet<>();
|
|
||||||
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* PL 2018-11-07 wird in varianceInheritanceConstraintSet erledigt do { //PL
|
|
||||||
* 2018-11-05 Huellenbildung Variance auf alle TPHs der Terme auf der jeweiligen
|
|
||||||
* //anderen Seite übertragen varianceTPHold = new HashSet<>(varianceTPH);
|
|
||||||
* varianceTPH = varianceInheritanceConstraintSet(unifyCons); unifyCons.map( y
|
|
||||||
* -> { if ((y.getLhsType() instanceof PlaceholderType) && (y.getRhsType()
|
|
||||||
* instanceof PlaceholderType)) { if
|
|
||||||
* (((PlaceholderType)y.getLhsType()).getVariance() != 0 &&
|
|
||||||
* ((PlaceholderType)y.getRhsType()).getVariance() == 0) {
|
|
||||||
* ((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType(
|
|
||||||
* )).getVariance()); } if (((PlaceholderType)y.getLhsType()).getVariance() == 0
|
|
||||||
* && ((PlaceholderType)y.getRhsType()).getVariance() != 0) {
|
|
||||||
* ((PlaceholderType)y.getLhsType()).setVariance(((PlaceholderType)y.getRhsType(
|
|
||||||
* )).getVariance()); } } return y; } ); } while
|
|
||||||
* (!varianceTPHold.equals(varianceTPH));
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure,
|
|
||||||
// logFile, log);
|
|
||||||
// Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
|
||||||
List<Set<Constraint<UnifyPair>>> oderConstraints = unifyCons.getOderConstraints()/*.stream().map(x -> {
|
|
||||||
Set<Set<UnifyPair>> ret = new HashSet<>();
|
|
||||||
for (Constraint<UnifyPair> y : x) {
|
|
||||||
ret.add(new HashSet<>(y));
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}).collect(Collectors.toCollection(ArrayList::new))*/;
|
|
||||||
unify.unifyAsync(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm,
|
|
||||||
usedTasks);
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.err.println("kein LogFile");
|
|
||||||
}
|
|
||||||
return urm;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ResultSet> typeInference() throws ClassNotFoundException, IOException {
|
public List<ResultSet> typeInference() throws ClassNotFoundException, IOException {
|
||||||
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
|
List<ClassOrInterface> allClasses = new ArrayList<>();// environment.getAllAvailableClasses();
|
||||||
@ -693,45 +368,13 @@ public class JavaTXCompiler {
|
|||||||
})));
|
})));
|
||||||
*/
|
*/
|
||||||
|
|
||||||
System.out.println("Unify nach Oder-Constraints-Anpassung:" + unifyCons.toString());
|
List<Set<Constraint<UnifyPair>>> oderConstraints = unifyCons.getOderConstraints();
|
||||||
Set<PlaceholderType> varianceTPHold;
|
|
||||||
Set<PlaceholderType> varianceTPH = new HashSet<>();
|
|
||||||
varianceTPH = varianceInheritanceConstraintSet(unifyCons);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* PL 2018-11-07 wird in varianceInheritanceConstraintSet erledigt do { //PL
|
|
||||||
* 2018-11-05 Huellenbildung Variance auf alle TPHs der Terme auf der jeweiligen
|
|
||||||
* //anderen Seite übertragen varianceTPHold = new HashSet<>(varianceTPH);
|
|
||||||
* varianceTPH = varianceInheritanceConstraintSet(unifyCons); unifyCons.map( y
|
|
||||||
* -> { if ((y.getLhsType() instanceof PlaceholderType) && (y.getRhsType()
|
|
||||||
* instanceof PlaceholderType)) { if
|
|
||||||
* (((PlaceholderType)y.getLhsType()).getVariance() != 0 &&
|
|
||||||
* ((PlaceholderType)y.getRhsType()).getVariance() == 0) {
|
|
||||||
* ((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType(
|
|
||||||
* )).getVariance()); } if (((PlaceholderType)y.getLhsType()).getVariance() == 0
|
|
||||||
* && ((PlaceholderType)y.getRhsType()).getVariance() != 0) {
|
|
||||||
* ((PlaceholderType)y.getLhsType()).setVariance(((PlaceholderType)y.getRhsType(
|
|
||||||
* )).getVariance()); } } return y; } ); } while
|
|
||||||
* (!varianceTPHold.equals(varianceTPH));
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Set<Set<UnifyPair>> result = unify.unifySequential(xConsSet, finiteClosure,
|
|
||||||
// logFile, log);
|
|
||||||
// Set<Set<UnifyPair>> result = unify.unify(xConsSet, finiteClosure);
|
|
||||||
List<Set<Constraint<UnifyPair>>> oderConstraints = unifyCons.getOderConstraints()//.stream().map(x -> {
|
|
||||||
/*Set<Set<UnifyPair>> ret = new HashSet<>();
|
|
||||||
for (Constraint<UnifyPair> y : x) {
|
|
||||||
ret.add(new HashSet<>(y));
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}).collect(Collectors.toCollection(ArrayList::new))*/;
|
|
||||||
if (resultmodel) {
|
if (resultmodel) {
|
||||||
/* UnifyResultModel Anfang */
|
/* UnifyResultModel Anfang */
|
||||||
UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure);
|
UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure);
|
||||||
UnifyResultListenerImpl li = new UnifyResultListenerImpl();
|
UnifyResultListenerImpl li = new UnifyResultListenerImpl();
|
||||||
urm.addUnifyResultListener(li);
|
urm.addUnifyResultListener(li);
|
||||||
unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm,
|
unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm);
|
||||||
usedTasks);
|
|
||||||
System.out.println("RESULT Final: " + li.getResults());
|
System.out.println("RESULT Final: " + li.getResults());
|
||||||
logFile.write("RES_FINAL: " + li.getResults().toString() + "\n");
|
logFile.write("RES_FINAL: " + li.getResults().toString() + "\n");
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
@ -743,7 +386,7 @@ public class JavaTXCompiler {
|
|||||||
// oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons,
|
// oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons,
|
||||||
// finiteClosure));
|
// finiteClosure));
|
||||||
Set<Set<UnifyPair>> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints,
|
Set<Set<UnifyPair>> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints,
|
||||||
finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure), usedTasks);
|
finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure));
|
||||||
System.out.println("RESULT: " + result);
|
System.out.println("RESULT: " + result);
|
||||||
logFile.write("RES: " + result.toString() + "\n");
|
logFile.write("RES: " + result.toString() + "\n");
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
|
@ -28,8 +28,8 @@ public class TypeUnify {
|
|||||||
* @param cons
|
* @param cons
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Set<Set<UnifyPair>> unify(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
public Set<Set<UnifyPair>> unify(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret) {
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret);
|
||||||
ForkJoinPool pool = new ForkJoinPool();
|
ForkJoinPool pool = new ForkJoinPool();
|
||||||
pool.invoke(unifyTask);
|
pool.invoke(unifyTask);
|
||||||
Set<Set<UnifyPair>> res = unifyTask.join();
|
Set<Set<UnifyPair>> res = unifyTask.join();
|
||||||
@ -54,8 +54,8 @@ public class TypeUnify {
|
|||||||
* @param ret
|
* @param ret
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public UnifyResultModel unifyAsync(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
public UnifyResultModel unifyAsync(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret) {
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret);
|
||||||
ForkJoinPool pool = new ForkJoinPool();
|
ForkJoinPool pool = new ForkJoinPool();
|
||||||
pool.invoke(unifyTask);
|
pool.invoke(unifyTask);
|
||||||
return ret;
|
return ret;
|
||||||
@ -68,12 +68,11 @@ public class TypeUnify {
|
|||||||
* @param fc
|
* @param fc
|
||||||
* @param logFile
|
* @param logFile
|
||||||
* @param log
|
* @param log
|
||||||
* @param cons
|
|
||||||
* @param ret
|
* @param ret
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public UnifyResultModel unifyParallel(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
public UnifyResultModel unifyParallel(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret) {
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret);
|
||||||
ForkJoinPool pool = new ForkJoinPool();
|
ForkJoinPool pool = new ForkJoinPool();
|
||||||
pool.invoke(unifyTask);
|
pool.invoke(unifyTask);
|
||||||
Set<Set<UnifyPair>> res = unifyTask.join();
|
Set<Set<UnifyPair>> res = unifyTask.join();
|
||||||
@ -102,11 +101,10 @@ public class TypeUnify {
|
|||||||
* @param fc
|
* @param fc
|
||||||
* @param logFile
|
* @param logFile
|
||||||
* @param log
|
* @param log
|
||||||
* @param cons
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Set<Set<UnifyPair>> unifyOderConstraints(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
public Set<Set<UnifyPair>> unifyOderConstraints(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret) {
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, ret, usedTasks);
|
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, ret);
|
||||||
Set<Set<UnifyPair>> res = unifyTask.compute();
|
Set<Set<UnifyPair>> res = unifyTask.compute();
|
||||||
try {
|
try {
|
||||||
logFile.write("\nnoShortendElements: " + unifyTask.noShortendElements +"\n");
|
logFile.write("\nnoShortendElements: " + unifyTask.noShortendElements +"\n");
|
||||||
|
@ -18,8 +18,8 @@ public class TypeUnify2Task extends TypeUnifyTask {
|
|||||||
|
|
||||||
Set<Set<UnifyPair>> setToFlatten;
|
Set<Set<UnifyPair>> setToFlatten;
|
||||||
|
|
||||||
public TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, Set<UnifyPair> nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) {
|
public TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, Set<UnifyPair> nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm) {
|
||||||
super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm);
|
||||||
this.setToFlatten = setToFlatten;
|
this.setToFlatten = setToFlatten;
|
||||||
this.nextSetElement = nextSetElement;
|
this.nextSetElement = nextSetElement;
|
||||||
}
|
}
|
||||||
@ -30,35 +30,7 @@ public class TypeUnify2Task extends TypeUnifyTask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Set<Set<UnifyPair>> compute() {
|
protected Set<Set<UnifyPair>> compute() {
|
||||||
if (one) {
|
|
||||||
System.out.println("two");
|
|
||||||
}
|
|
||||||
one = true;
|
|
||||||
Set<Set<UnifyPair>> res = unify2(setToFlatten, eq, oderConstraintsField, fc, parallel, rekTiefeField, true);
|
Set<Set<UnifyPair>> res = unify2(setToFlatten, eq, oderConstraintsField, fc, parallel, rekTiefeField, true);
|
||||||
/*if (isUndefinedPairSetSet(res)) {
|
|
||||||
return new HashSet<>(); }
|
|
||||||
else
|
|
||||||
*/
|
|
||||||
//writeLog("xxx");
|
|
||||||
//noOfThread--;
|
|
||||||
synchronized (usedTasks) {
|
|
||||||
if (this.myIsCancelled()) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void closeLogFile() {
|
|
||||||
|
|
||||||
try {
|
|
||||||
logFile.close();
|
|
||||||
}
|
|
||||||
catch (IOException ioE) {
|
|
||||||
System.err.println("no log-File" + thNo);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -76,11 +76,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
* Fuer die Threads
|
* Fuer die Threads
|
||||||
*/
|
*/
|
||||||
UnifyResultModel urm;
|
UnifyResultModel urm;
|
||||||
protected static int noOfThread = 0;
|
|
||||||
private static int totalnoOfThread = 0;
|
|
||||||
int thNo;
|
|
||||||
protected boolean one = false;
|
|
||||||
Integer MaxNoOfThreads = 8;
|
|
||||||
|
|
||||||
public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/";
|
public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/";
|
||||||
Writer logFile;
|
Writer logFile;
|
||||||
@ -124,30 +119,12 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
static Integer noShortendElements = 0;
|
static Integer noShortendElements = 0;
|
||||||
|
|
||||||
Boolean myIsCanceled = false;
|
|
||||||
|
|
||||||
volatile UnifyTaskModel usedTasks;
|
|
||||||
|
|
||||||
public TypeUnifyTask() {
|
public TypeUnifyTask() {
|
||||||
rules = new RuleSet();
|
rules = new RuleSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
public TypeUnifyTask(Set<UnifyPair> eq, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log) {
|
|
||||||
this.eq = eq;
|
|
||||||
this.fc = fc;
|
|
||||||
this.oup = new OrderingUnifyPair(fc);
|
|
||||||
this.parallel = parallel;
|
|
||||||
this.logFile = logFile;
|
|
||||||
this.log = log;
|
|
||||||
rules = new RuleSet(logFile);
|
|
||||||
noOfThread++;
|
|
||||||
thNo = noOfThread;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
public TypeUnifyTask(Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm) {
|
||||||
public TypeUnifyTask(Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) {
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
this.eq = eq;
|
this.eq = eq;
|
||||||
//this.oderConstraints = oderConstraints.stream().map(x -> x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new));
|
//this.oderConstraints = oderConstraints.stream().map(x -> x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new));
|
||||||
@ -168,20 +145,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
this.logFile = logFile;
|
this.logFile = logFile;
|
||||||
this.log = log;
|
this.log = log;
|
||||||
|
|
||||||
noOfThread++;
|
|
||||||
totalnoOfThread++;
|
|
||||||
//writeLog("thNo1 " + thNo);
|
|
||||||
thNo = totalnoOfThread;
|
|
||||||
writeLog("thNo2 " + thNo);
|
|
||||||
try {
|
|
||||||
this.logFile = //new OutputStreamWriter(new NullOutputStream());
|
|
||||||
//new FileWriter(new File(System.getProperty("user.dir")+"/src/test/resources/logFiles/"+"Thread_"+thNo));
|
|
||||||
new FileWriter(new File(System.getProperty("user.dir")+"/logFiles/"+"Thread_"+thNo));
|
|
||||||
logFile.write("");
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
System.err.println("log-File nicht vorhanden");
|
|
||||||
}
|
|
||||||
/*Abbruchtest
|
/*Abbruchtest
|
||||||
if (thNo > 10) {
|
if (thNo > 10) {
|
||||||
System.out.println("cancel");
|
System.out.println("cancel");
|
||||||
@ -199,56 +162,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
rules = new RuleSet(logFile);
|
rules = new RuleSet(logFile);
|
||||||
this.rekTiefeField = rekTiefe;
|
this.rekTiefeField = rekTiefe;
|
||||||
this.urm = urm;
|
this.urm = urm;
|
||||||
this.usedTasks = usedTasks;
|
|
||||||
this.usedTasks.add(this);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Vererbt alle Variancen
|
|
||||||
* @param eq The set of constraints
|
|
||||||
*/
|
|
||||||
/* PL 2018-05- 17 verschoben nach JavaTXCompiler
|
|
||||||
private void varianceInheritance(Set<UnifyPair> eq) {
|
|
||||||
Set<PlaceholderType> usedTPH = new HashSet<>();
|
|
||||||
Set<PlaceholderType> phSet = eq.stream().map(x -> {
|
|
||||||
Set<PlaceholderType> pair = new HashSet<>();
|
|
||||||
if (x.getLhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getLhsType());
|
|
||||||
if (x.getRhsType() instanceof PlaceholderType) pair.add((PlaceholderType)x.getRhsType());
|
|
||||||
return pair;
|
|
||||||
}).reduce(new HashSet<>(), (a,b) -> { a.addAll(b); return a;} , (c,d) -> { c.addAll(d); return c;});
|
|
||||||
|
|
||||||
ArrayList<PlaceholderType> phSetVariance = new ArrayList<>(phSet);
|
|
||||||
phSetVariance.removeIf(x -> (x.getVariance() == 0));
|
|
||||||
while(!phSetVariance.isEmpty()) {
|
|
||||||
PlaceholderType a = phSetVariance.remove(0);
|
|
||||||
usedTPH.add(a);
|
|
||||||
//HashMap<PlaceholderType,Integer> ht = new HashMap<>();
|
|
||||||
//ht.put(a, a.getVariance());
|
|
||||||
Set<UnifyPair> eq1 = new HashSet<>(eq);
|
|
||||||
eq1.removeIf(x -> !(x.getLhsType() instanceof PlaceholderType && ((PlaceholderType)x.getLhsType()).equals(a)));
|
|
||||||
eq1.stream().forEach(x -> { x.getRhsType().accept(new distributeVariance(), a.getVariance());});
|
|
||||||
eq1 = new HashSet<>(eq);
|
|
||||||
eq1.removeIf(x -> !(x.getRhsType() instanceof PlaceholderType && ((PlaceholderType)x.getRhsType()).equals(a)));
|
|
||||||
eq1.stream().forEach(x -> { x.getLhsType().accept(new distributeVariance(), a.getVariance());});
|
|
||||||
phSetVariance = new ArrayList<>(phSet);
|
|
||||||
phSetVariance.removeIf(x -> (x.getVariance() == 0 || usedTPH.contains(x)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
void myCancel(Boolean b) {
|
|
||||||
myIsCanceled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean myIsCancelled() {
|
|
||||||
return myIsCanceled;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Set<Set<UnifyPair>> compute() {
|
protected Set<Set<UnifyPair>> compute() {
|
||||||
if (one) {
|
|
||||||
System.out.println("two");
|
|
||||||
}
|
|
||||||
one = true;
|
|
||||||
Set<UnifyPair> neweq = new HashSet<>(eq);
|
Set<UnifyPair> neweq = new HashSet<>(eq);
|
||||||
/* 1-elementige Oder-Constraints werden in und-Constraints umgewandelt */
|
/* 1-elementige Oder-Constraints werden in und-Constraints umgewandelt */
|
||||||
oderConstraintsField.stream()
|
oderConstraintsField.stream()
|
||||||
@ -258,7 +175,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
.filter(x -> x.size()>1)
|
.filter(x -> x.size()>1)
|
||||||
.collect(Collectors.toCollection(ArrayList::new));
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
Set<Set<UnifyPair>> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField, true);
|
Set<Set<UnifyPair>> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField, true);
|
||||||
noOfThread--;
|
|
||||||
try {
|
try {
|
||||||
logFile.close();
|
logFile.close();
|
||||||
}
|
}
|
||||||
@ -268,16 +184,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
if (isUndefinedPairSetSet(res)) {
|
if (isUndefinedPairSetSet(res)) {
|
||||||
throw new TypeinferenceException("Unresolved constraints: " + res.toString(), new NullToken()); //return new HashSet<>();
|
throw new TypeinferenceException("Unresolved constraints: " + res.toString(), new NullToken()); //return new HashSet<>();
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
synchronized (usedTasks) {
|
|
||||||
if (this.myIsCancelled()) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@Override
|
@Override
|
||||||
@ -300,22 +211,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
* @return The set of all principal type unifiers
|
* @return The set of all principal type unifiers
|
||||||
*/
|
*/
|
||||||
protected Set<Set<UnifyPair>> unify(final Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) {
|
protected Set<Set<UnifyPair>> unify(final Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) {
|
||||||
//Set<UnifyPair> aas = eq.stream().filter(x -> x.getLhsType().getName().equals("AA") //&& x.getPairOp().equals(PairOperator.SMALLERDOT)
|
|
||||||
// ).collect(Collectors.toCollection(HashSet::new));
|
|
||||||
//writeLog(nOfUnify.toString() + " AA: " + aas.toString());
|
|
||||||
//if (aas.isEmpty()) {
|
|
||||||
// System.out.println("");
|
|
||||||
//}
|
|
||||||
|
|
||||||
//.collect(Collectors.toCollection(HashSet::new)));
|
|
||||||
/*
|
|
||||||
* Step 1: Repeated application of reduce, adapt, erase, swap
|
|
||||||
*/
|
|
||||||
synchronized (usedTasks) {
|
|
||||||
if (this.myIsCancelled()) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rekTiefe++;
|
rekTiefe++;
|
||||||
nOfUnify++;
|
nOfUnify++;
|
||||||
@ -475,11 +370,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
// .collect(Collectors.toCollection(HashSet::new));
|
// .collect(Collectors.toCollection(HashSet::new));
|
||||||
//Muss auskommentiert werden, wenn computeCartesianRecursive ENDE
|
//Muss auskommentiert werden, wenn computeCartesianRecursive ENDE
|
||||||
|
|
||||||
synchronized (usedTasks) {
|
|
||||||
if (this.myIsCancelled()) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<Set<UnifyPair>> eqPrimePrimeSet = new HashSet<>();
|
Set<Set<UnifyPair>> eqPrimePrimeSet = new HashSet<>();
|
||||||
|
|
||||||
@ -837,7 +727,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
/* PL 2019-03-11 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
/* PL 2019-03-11 Ende eingefuegt Vergleich mit anderen Paaren ggf. loeschen */
|
||||||
|
|
||||||
if(parallel && (variance == 1) && noOfThread <= MaxNoOfThreads) {
|
if(parallel && (variance == 1)) {
|
||||||
Set<TypeUnify2Task> forks = new HashSet<>();
|
Set<TypeUnify2Task> forks = new HashSet<>();
|
||||||
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
||||||
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
||||||
@ -847,12 +737,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
/* FORK ANFANG */
|
/* FORK ANFANG */
|
||||||
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
||||||
//forks.add(forkOrig);
|
//forks.add(forkOrig);
|
||||||
synchronized(usedTasks) {
|
|
||||||
if (this.myIsCancelled()) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
forkOrig.fork();
|
|
||||||
}
|
|
||||||
/* FORK ENDE */
|
/* FORK ENDE */
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
package de.dhbwstuttgart.typeinference.unify;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class UnifyTaskModel {
|
|
||||||
|
|
||||||
ArrayList<TypeUnifyTask> usedTasks = new ArrayList<>();
|
|
||||||
|
|
||||||
public synchronized void add(TypeUnifyTask t) {
|
|
||||||
usedTasks.add(t);
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void cancel() {
|
|
||||||
for(TypeUnifyTask t : usedTasks) {
|
|
||||||
t.myCancel(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user