forked from JavaTX/JavaCompilerCore
modified: ../../../main/java/de/dhbwstuttgart/core/JavaTXCompiler.java
modified: ../../../main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java Set<UnifyType> fBounded = new HashSet<>(pair.getfBounded()); //PL 2019-01-09 new HashSet eingefuegt modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/interfaces/IFiniteClosure.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/model/PlaceholderType.java modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java modified: ../../resources/bytecode/javFiles/Matrix.jav
This commit is contained in:
parent
72a84323de
commit
d0a261f55c
@ -272,15 +272,16 @@ public class JavaTXCompiler {
|
||||
}
|
||||
|
||||
final ConstraintSet<Pair> cons = getConstraints();
|
||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||
try {
|
||||
FileWriter logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName()));
|
||||
|
||||
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses);
|
||||
FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile);
|
||||
System.out.println(finiteClosure);
|
||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||
|
||||
TypeUnify unify = new TypeUnify();
|
||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||
try {
|
||||
FileWriter logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName()));
|
||||
//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));
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.dhbwstuttgart.syntaxtree.factory;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -29,7 +30,7 @@ public class UnifyTypeFactory {
|
||||
|
||||
private static ArrayList<PlaceholderType> PLACEHOLDERS = new ArrayList<>();
|
||||
|
||||
public static FiniteClosure generateFC(List<ClassOrInterface> fromClasses) throws ClassNotFoundException {
|
||||
public static FiniteClosure generateFC(List<ClassOrInterface> fromClasses, FileWriter logFile) throws ClassNotFoundException {
|
||||
/*
|
||||
Die transitive Hülle muss funktionieren.
|
||||
Man darf schreiben List<A> extends AL<A>
|
||||
@ -40,7 +41,7 @@ public class UnifyTypeFactory {
|
||||
Generell dürfen sie immer die gleichen Namen haben.
|
||||
TODO: die transitive Hülle bilden
|
||||
*/
|
||||
return new FiniteClosure(FCGenerator.toUnifyFC(fromClasses));
|
||||
return new FiniteClosure(FCGenerator.toUnifyFC(fromClasses), logFile);
|
||||
}
|
||||
|
||||
public static UnifyPair generateSmallerPair(UnifyType tl, UnifyType tr){
|
||||
|
@ -814,6 +814,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
|
||||
//Alle Variablen bestimmen die nicht hinzugefügt wurden in a
|
||||
//PL 2018-12-28: Hier gab es eine ClassCastException, war nicht reproduzierbar
|
||||
System.out.println("");
|
||||
List<PlaceholderType> vars_a =
|
||||
a.stream().filter(x -> (x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName())
|
||||
||x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName())))
|
||||
@ -1483,7 +1484,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
// System.out.println("");
|
||||
//}
|
||||
Set<UnifyType> cs = fc.getAllTypesByName(thetaPrime.getName());//cs= [java.util.Vector<NP>, java.util.Vector<java.util.Vector<java.lang.Integer>>, ????java.util.Vector<gen_hv>???]
|
||||
//Set<UnifyType> cs = fc.getAllTypesByMatch(thetaPrime); //PL 2019-01-02 geaendet wegen Bug 127//SO GEHT ES NICHT
|
||||
|
||||
|
||||
//PL 18-02-06 entfernt, kommt durch unify wieder rein
|
||||
@ -1607,6 +1607,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
|
||||
UnifyType aPrime = PlaceholderType.freshPlaceholder();
|
||||
((PlaceholderType)aPrime).setVariance(((PlaceholderType)a).getVariance());
|
||||
((PlaceholderType)aPrime).disableWildcardtable();
|
||||
UnifyType extAPrime = new ExtendsType(aPrime);
|
||||
UnifyType thetaPrime = extThetaPrime.getExtendedType();
|
||||
Set<UnifyPair> resultPrime = new HashSet<>();
|
||||
@ -1627,12 +1628,14 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
*/
|
||||
private Set<Set<UnifyPair>> unifyCase3(UnifyPair pair, IFiniteClosure fc) {
|
||||
PlaceholderType a = (PlaceholderType) pair.getLhsType();
|
||||
a.reversVariance();
|
||||
SuperType subThetaPrime = (SuperType) pair.getRhsType();
|
||||
byte variance = pair.getVariance();
|
||||
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||
|
||||
UnifyType aPrime = PlaceholderType.freshPlaceholder();
|
||||
((PlaceholderType)aPrime).setVariance(((PlaceholderType)a).getVariance());
|
||||
((PlaceholderType)aPrime).disableWildcardtable();
|
||||
UnifyType supAPrime = new SuperType(aPrime);
|
||||
UnifyType thetaPrime = subThetaPrime.getSuperedType();
|
||||
Set<UnifyPair> resultPrime = new HashSet<>();
|
||||
@ -1666,7 +1669,28 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
break;
|
||||
}
|
||||
|
||||
for(UnifyType thetaS : fc.greater(theta, pair.getfBounded())) {
|
||||
//eingefuegt PL 2019-01-03 ANFANG
|
||||
fc.setLogTrue();
|
||||
writeLog("FBOUNDED: " + pair.getfBounded());
|
||||
writeLog("Pair: " + pair);
|
||||
Set<UnifyType> greater = fc.greater(theta, pair.getfBounded());
|
||||
writeLog("GREATER: " + greater + pair + "THETA: " + theta + "FBOUNDED: " + pair.getfBounded() + " ");
|
||||
|
||||
/*if (a.isWildcardable()) {
|
||||
Set<UnifyType> greater_ext = greater.stream().filter(x -> !(x instanceof ExtendsType) && !(x instanceof SuperType))
|
||||
.map(x -> {
|
||||
//BinaryOperator<HashMap<PlaceholderType,PlaceholderType>> combiner = (aa,b) -> { aa.putAll(b); return aa;}; //Variablenumbenennung rausgenommen
|
||||
//HashMap<PlaceholderType,PlaceholderType> hm = x.getInvolvedPlaceholderTypes().stream() //Variablen muessen wahrscheinlich erhalten bleiben
|
||||
// .reduce(new HashMap<PlaceholderType,PlaceholderType>(),
|
||||
// (aa, b)-> { aa.put(b,PlaceholderType.freshPlaceholder()); return aa; }, combiner);
|
||||
return new SuperType (x);})//.accept(new freshPlaceholder(), hm));}
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
greater.addAll(greater_ext);
|
||||
}
|
||||
//eingefuegt PL 2019-01-03 ENDE
|
||||
*/
|
||||
//for(UnifyType thetaS : fc.greater(theta, pair.getfBounded())) {
|
||||
for(UnifyType thetaS : greater) {
|
||||
Set<UnifyPair> resultPrime = new HashSet<>();
|
||||
Match match = new Match();
|
||||
|
||||
@ -1674,7 +1698,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
for(int i = 0; !allGen && i < freshTphs.length; i++) {
|
||||
freshTphs[i] = PlaceholderType.freshPlaceholder();
|
||||
((PlaceholderType)freshTphs[i]).setVariance(((PlaceholderType)a).getVariance());
|
||||
Set<UnifyType> fBounded = pair.getfBounded();
|
||||
Set<UnifyType> fBounded = new HashSet<>(pair.getfBounded()); //PL 2019-01-09 new HashSet eingefuegt
|
||||
|
||||
int i_ef = i;
|
||||
BiFunction<Boolean,UnifyType,Boolean> f = (x,y) ->
|
||||
@ -1688,7 +1712,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
//}
|
||||
BinaryOperator<Boolean> bo = (x,y) -> (x || y);
|
||||
if (fBounded.stream().reduce(false,f,bo)) {
|
||||
resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.EQUALSDOT, pair.getSubstitution(), pair));
|
||||
resultPrime.add(new UnifyPair(freshTphs[i], thetaS.getTypeParams().get(i), PairOperator.EQUALSDOT, pair.getSubstitution(), pair));
|
||||
}
|
||||
else {
|
||||
fBounded.add(thetaS.getTypeParams().get(i));
|
||||
@ -1702,7 +1726,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
resultPrime.add(new UnifyPair(a, thetaS.setTypeParams(new TypeParams(freshTphs)), PairOperator.EQUALSDOT, pair.getSubstitution(), pair));
|
||||
resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new));
|
||||
result.add(resultPrime);
|
||||
//writeLog(resultPrime.toString());
|
||||
writeLog("FBOUNDED2: " + pair.getfBounded());
|
||||
//writeLog("resultPrime Theta < a: " + greater + pair + "THETA: " + theta + "FBOUNDED: " + pair.getfBounded() + " " + resultPrime.toString());
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -17,6 +17,7 @@ import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
||||
*/
|
||||
public interface IFiniteClosure {
|
||||
|
||||
public void setLogTrue();
|
||||
/**
|
||||
* Returns all types of the finite closure that are subtypes of the argument.
|
||||
* @return The set of subtypes of the argument.
|
||||
|
@ -1,5 +1,7 @@
|
||||
package de.dhbwstuttgart.typeinference.unify.model;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@ -30,6 +32,11 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify;
|
||||
public class FiniteClosure //extends Ordering<UnifyType> //entfernt PL 2018-12-11
|
||||
implements IFiniteClosure {
|
||||
|
||||
FileWriter logFile;
|
||||
static Boolean log = false;
|
||||
public void setLogTrue() {
|
||||
log = true;
|
||||
}
|
||||
/**
|
||||
* A map that maps every type to the node in the inheritance graph that contains that type.
|
||||
*/
|
||||
@ -49,7 +56,8 @@ implements IFiniteClosure {
|
||||
/**
|
||||
* Creates a new instance using the inheritance tree defined in the pairs.
|
||||
*/
|
||||
public FiniteClosure(Set<UnifyPair> pairs) {
|
||||
public FiniteClosure(Set<UnifyPair> pairs, FileWriter logFile) {
|
||||
this.logFile = logFile;
|
||||
this.pairs = new HashSet<>(pairs);
|
||||
inheritanceGraph = new HashMap<UnifyType, Node<UnifyType>>();
|
||||
|
||||
@ -214,6 +222,15 @@ implements IFiniteClosure {
|
||||
|
||||
// if T <* T' then sigma(T) <* sigma(T')
|
||||
Set<Node<UnifyType>> candidates = strInheritanceGraph.get(type.getName());
|
||||
|
||||
try {
|
||||
if (log) logFile.write(candidates.toString());
|
||||
//log = false;
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.err.println("no LogFile");
|
||||
}
|
||||
|
||||
for(Node<UnifyType> candidate : candidates) {
|
||||
UnifyType theta1 = candidate.getContent();
|
||||
|
||||
@ -222,9 +239,13 @@ implements IFiniteClosure {
|
||||
termList.add(new UnifyPair(theta1,type, PairOperator.EQUALSDOT));
|
||||
Optional<Unifier> optSigma = match.match(termList);
|
||||
//PL 18-04-05 Unifier durch Matcher ersetzt ENDE
|
||||
if(!optSigma.isPresent())
|
||||
if(!optSigma.isPresent()) {
|
||||
if ((type.getName().equals("java.util.Vector")) && (type instanceof ReferenceType) &&
|
||||
(((ReferenceType)type).getTypeParams().get(0).getName().equals("java.lang.Integer"))) {
|
||||
System.out.println(type.toString() + candidates);
|
||||
}
|
||||
continue;
|
||||
|
||||
}
|
||||
Unifier sigma = optSigma.get();
|
||||
sigma.swapPlaceholderSubstitutionsReverse(theta1.getTypeParams());
|
||||
|
||||
@ -237,7 +258,13 @@ implements IFiniteClosure {
|
||||
PairResultFBounded.add(new Pair<>(theta2.apply(sigma), fBoundedNew));
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (log) logFile.write(PairResultFBounded.toString());
|
||||
log = false;
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.err.println("no LogFile");
|
||||
}
|
||||
for(Pair<UnifyType,Set<UnifyType>> pt : PairResultFBounded) {
|
||||
UnifyType t = pt.getKey();
|
||||
Set<UnifyType> lfBounded = pt.getValue().get();
|
||||
|
@ -110,17 +110,25 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
||||
&& x.getPairOp() == PairOperator.SMALLERDOTWC))
|
||||
.collect(Collectors.toCollection(HashSet::new));
|
||||
//System.out.println(left.toString());
|
||||
//Fall 2 und 3
|
||||
//Fall 2
|
||||
//if (lefteq.iterator().next().getLhsType().getName().equals("AJO")) {
|
||||
// System.out.print("");
|
||||
//}
|
||||
if (lefteq.size() == 1 && leftle.size() == 1 && righteq.size() == 0 && rightle.size() == 1) {
|
||||
if (lefteq.size() == 1 && lefteq.iterator().next().getRhsType() instanceof ExtendsType && leftle.size() == 1 && righteq.size() == 0 && rightle.size() == 1) {
|
||||
return 1;
|
||||
}
|
||||
//Fall 2 und 3
|
||||
if (lefteq.size() == 0 && leftle.size() == 1 && righteq.size() == 1 && rightle.size() == 1) {
|
||||
//Fall 2
|
||||
if (lefteq.size() == 0 && leftle.size() == 1 && righteq.size() == 1 && righteq.iterator().next().getRhsType() instanceof ExtendsType && rightle.size() == 1) {
|
||||
return -1;
|
||||
}
|
||||
//Fall 3
|
||||
if (lefteq.size() == 1 && lefteq.iterator().next().getRhsType() instanceof SuperType && leftle.size() == 1 && righteq.size() == 0 && rightle.size() == 1) {
|
||||
return -1;
|
||||
}
|
||||
//Fall 3
|
||||
if (lefteq.size() == 0 && leftle.size() == 1 && righteq.size() == 1 && righteq.iterator().next().getRhsType() instanceof SuperType && rightle.size() == 1) {
|
||||
return 1;
|
||||
}
|
||||
//Fall 5
|
||||
if (lefteq.size() == 1 && leftle.size() == 0 && righteq.size() == 1 && rightle.size() == 1) {
|
||||
return -1;
|
||||
|
@ -108,6 +108,15 @@ public final class PlaceholderType extends UnifyType{
|
||||
return variance;
|
||||
}
|
||||
|
||||
public void reversVariance() {
|
||||
if (variance == 1) {
|
||||
setVariance(-1);
|
||||
} else {
|
||||
if (variance == -1) {
|
||||
setVariance(1);
|
||||
}}
|
||||
}
|
||||
|
||||
public Boolean isWildcardable() {
|
||||
return wildcardable;
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ public class UnifyPair {
|
||||
if (rhs instanceof PlaceholderType) {
|
||||
ret = ret + ", " + new Integer(((PlaceholderType)rhs).getVariance()).toString();
|
||||
}
|
||||
return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + ", [" + getfBounded().toString()+ "])";
|
||||
return "(" + lhs + " " + pairOp + " " + rhs + ", " + ret + "])"; //+ ", [" + getfBounded().toString()+ "])";
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1,6 +1,6 @@
|
||||
import java.util.Vector;
|
||||
import java.lang.Integer;
|
||||
import java.lang.Float;
|
||||
//import java.lang.Float;
|
||||
//import java.lang.Byte;
|
||||
//import java.lang.Boolean;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user