Merge branch 'bytecode2' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecode2
This commit is contained in:
commit
3fb95600a0
@ -29,6 +29,7 @@ import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure;
|
|||||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@ -200,7 +201,9 @@ public class JavaTXCompiler {
|
|||||||
if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT);
|
if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT);
|
||||||
return y; //alle Paare a <.? b erden durch a =. b ersetzt
|
return y; //alle Paare a <.? b erden durch a =. b ersetzt
|
||||||
}).collect(Collectors.toCollection(HashSet::new)));
|
}).collect(Collectors.toCollection(HashSet::new)));
|
||||||
if (res.isPresent()) return res.get(); //wenn subst ein Erg liefert wurde was veraendert
|
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
|
else return x; //wenn nichts veraendert wurde wird x zurueckgegeben
|
||||||
}).collect(Collectors.toCollection(HashSet::new));
|
}).collect(Collectors.toCollection(HashSet::new));
|
||||||
System.out.println("RESULT Final: " + results);
|
System.out.println("RESULT Final: " + results);
|
||||||
|
@ -23,4 +23,8 @@ public abstract class ResultPair<A extends RefTypeOrTPHOrWildcardOrGeneric,B ext
|
|||||||
public B getRight() {
|
public B getRight() {
|
||||||
return right;
|
return right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "(" + left.toString() + ", " + right.toString() + ")";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,10 @@ public class ResultSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//TODO Beim Einsetzen eines Generics, müssen die new und Methodenaufrufe verändert werden
|
//TODO Beim Einsetzen eines Generics, müssen die new und Methodenaufrufe verändert werden
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return results.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,6 +48,7 @@ class Resolver implements ResultSetVisitor {
|
|||||||
public ResolvedType resolve(TypePlaceholder tph){
|
public ResolvedType resolve(TypePlaceholder tph){
|
||||||
toResolve = tph;
|
toResolve = tph;
|
||||||
resolved = null;
|
resolved = null;
|
||||||
|
System.out.println(tph.toString());
|
||||||
for(ResultPair resultPair : result.results){
|
for(ResultPair resultPair : result.results){
|
||||||
if(resultPair instanceof PairTPHEqualTPH && ((PairTPHEqualTPH) resultPair).getLeft().equals(toResolve)){
|
if(resultPair instanceof PairTPHEqualTPH && ((PairTPHEqualTPH) resultPair).getLeft().equals(toResolve)){
|
||||||
return resolve(((PairTPHEqualTPH) resultPair).getRight());
|
return resolve(((PairTPHEqualTPH) resultPair).getRight());
|
||||||
@ -108,6 +113,8 @@ class Resolver implements ResultSetVisitor {
|
|||||||
public void visit(ExtendsWildcardType extendsWildcardType) {
|
public void visit(ExtendsWildcardType extendsWildcardType) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -379,7 +379,17 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (literal.value instanceof Integer) {
|
if (literal.value instanceof Integer) {
|
||||||
constraintsSet.addUndConstraint(new Pair(literal.getType(), integer, PairOperator.EQUALSDOT));
|
//constraintsSet.addUndConstraint(new Pair(literal.getType(),integer, PairOperator.EQUALSDOT));
|
||||||
|
// /*
|
||||||
|
Set<Constraint> oderConstraints = new HashSet<>();
|
||||||
|
Constraint constraint = new Constraint();
|
||||||
|
constraint.add(new Pair(literal.getType(), integer, PairOperator.EQUALSDOT));
|
||||||
|
oderConstraints.add(constraint);
|
||||||
|
constraint = new Constraint();
|
||||||
|
constraint.add(new Pair(literal.getType(), doublee, PairOperator.EQUALSDOT));
|
||||||
|
oderConstraints.add(constraint);
|
||||||
|
constraintsSet.addOderConstraint(oderConstraints);
|
||||||
|
// */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (literal.value instanceof Short) {
|
if (literal.value instanceof Short) {
|
||||||
|
@ -23,14 +23,17 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet;
|
|||||||
import de.dhbwstuttgart.typeinference.unify.interfaces.ISetOperations;
|
import de.dhbwstuttgart.typeinference.unify.interfaces.ISetOperations;
|
||||||
import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify;
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
|
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.FunNType;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.SuperType;
|
import de.dhbwstuttgart.typeinference.unify.model.SuperType;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
|
import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.Unifier;
|
import de.dhbwstuttgart.typeinference.unify.model.Unifier;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair;
|
import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.Pair;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
@ -82,7 +85,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
Integer noAllErasedElements = 0;
|
Integer noAllErasedElements = 0;
|
||||||
|
|
||||||
Integer noBacktracking = 0;
|
static int noBacktracking;
|
||||||
|
|
||||||
public TypeUnifyTask() {
|
public TypeUnifyTask() {
|
||||||
rules = new RuleSet();
|
rules = new RuleSet();
|
||||||
@ -553,8 +556,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* auskommentiert um alle Max und min Betrachtung auszuschalten ENDE */
|
/* auskommentiert um alle Max und min Betrachtung auszuschalten ENDE */
|
||||||
|
|
||||||
if (isUndefinedPairSetSet(res)) {
|
if (isUndefinedPairSetSet(res)) {
|
||||||
|
int nofstred= 0;
|
||||||
Set<UnifyPair> abhSubst = res.stream()
|
Set<UnifyPair> abhSubst = res.stream()
|
||||||
.map(b ->
|
.map(b ->
|
||||||
b.stream()
|
b.stream()
|
||||||
@ -566,23 +570,41 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
.filter(x -> b.contains(x))
|
.filter(x -> b.contains(x))
|
||||||
//.filter(y -> abhSubst.contains(y))
|
//.filter(y -> abhSubst.contains(y))
|
||||||
.collect(Collectors.toCollection(HashSet::new));
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
Set<PlaceholderType> vars = durchschnitt.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new));
|
//Set<PlaceholderType> vars = durchschnitt.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new));
|
||||||
int len = nextSetasList.size();
|
int len = nextSetasList.size();
|
||||||
|
Set<UnifyPair> undefRes = res.stream().reduce((y,z) -> { y.addAll(z); return y;}).get(); //flatten aller undef results
|
||||||
|
Set<Pair<Set<UnifyPair>, UnifyPair>> reducedUndefResSubstGroundedBasePair = undefRes.stream()
|
||||||
|
.map(x -> { Set<UnifyPair> su = x.getAllSubstitutions(); //alle benutzten Substitutionen
|
||||||
|
su.add(x.getGroundBasePair()); // urspruengliches Paar
|
||||||
|
su.removeAll(durchschnitt); //alle aktuell genänderten Paare entfernen
|
||||||
|
return new Pair<>(su, x.getGroundBasePair());})
|
||||||
|
.collect(Collectors.toCollection(HashSet::new));
|
||||||
|
if (res.size() > 1) {
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
nextSetasList = nextSetasList.stream().filter(x -> {
|
nextSetasList = nextSetasList.stream().filter(x -> {
|
||||||
//Boolean ret = false;
|
//Boolean ret = false;
|
||||||
//for (PlaceholderType var : vars) {
|
//for (PlaceholderType var : vars) {
|
||||||
// ret = ret || x.stream().map(b -> b.getLhsType().equals(var)).reduce((c,d) -> c || d).get();
|
// ret = ret || x.stream().map(b -> b.getLhsType().equals(var)).reduce((c,d) -> c || d).get();
|
||||||
//}
|
//}
|
||||||
return (!x.containsAll(durchschnitt));
|
return (!x.containsAll(durchschnitt));
|
||||||
}).collect(Collectors.toCollection(ArrayList::new));
|
})//.filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y)) //fuer testzwecke auskommentiert um nofstred zu bestimmen PL 2018-10-10
|
||||||
|
.collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
nofstred = nextSetasList.size();
|
||||||
|
//NOCH NICHT korrekt PL 2018-10-12
|
||||||
|
//nextSetasList = nextSetasList.stream().filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y))
|
||||||
|
// .collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
writeLog("res (undef): " + res.toString());
|
||||||
writeLog("abhSubst: " + abhSubst.toString());
|
writeLog("abhSubst: " + abhSubst.toString());
|
||||||
writeLog("a: " + a.toString());
|
writeLog("a: " + a.toString());
|
||||||
writeLog("Durchschnitt: " + durchschnitt.toString());
|
writeLog("Durchschnitt: " + durchschnitt.toString());
|
||||||
writeLog("nextSet: " + nextSet.toString());
|
writeLog("nextSet: " + nextSet.toString());
|
||||||
writeLog("nextSetasList: " + nextSetasList.toString());
|
writeLog("nextSetasList: " + nextSetasList.toString());
|
||||||
|
writeLog("Number first erased Elements (undef): " + (len - nofstred));
|
||||||
|
writeLog("Number second erased Elements (undef): " + (nofstred- nextSetasList.size()));
|
||||||
writeLog("Number erased Elements (undef): " + (len - nextSetasList.size()));
|
writeLog("Number erased Elements (undef): " + (len - nextSetasList.size()));
|
||||||
noAllErasedElements = noAllErasedElements + (len - nextSetasList.size());
|
noAllErasedElements = noAllErasedElements + (len - nextSetasList.size());
|
||||||
writeLog("Number erased Elements (undef): " + noAllErasedElements.toString());
|
writeLog("Number of all erased Elements (undef): " + noAllErasedElements.toString());
|
||||||
noBacktracking++;
|
noBacktracking++;
|
||||||
writeLog("Number of Backtracking: " + noBacktracking);
|
writeLog("Number of Backtracking: " + noBacktracking);
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
@ -598,7 +620,95 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean couldBecorrect(Set<Pair<Set<UnifyPair>, UnifyPair>> reducedUndefResSubstGroundedBasePair, Set<UnifyPair> nextElem) {
|
||||||
|
return reducedUndefResSubstGroundedBasePair.stream()
|
||||||
|
.map(pair -> {
|
||||||
|
Set<UnifyPair> reducedAbhSubst = pair.getKey();
|
||||||
|
reducedAbhSubst.addAll(nextElem);
|
||||||
|
Optional<Set<UnifyPair>> substRes = rules.subst(reducedAbhSubst);
|
||||||
|
if (!substRes.isPresent()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
//PL 2018-10-12
|
||||||
|
//Evtl. zurest applyTypeUnification aufrufen
|
||||||
|
//evtl auch unify aufrufen
|
||||||
|
else {
|
||||||
|
UnifyPair checkPair = substRes.get().stream()
|
||||||
|
.filter(x -> x.getGroundBasePair().equals(pair.getValue().get())).findFirst().get();
|
||||||
|
if (((checkPair.getLhsType() instanceof PlaceholderType) || (checkPair.getRhsType() instanceof PlaceholderType))
|
||||||
|
&& (checkPair.getPairOp() == PairOperator.SMALLERDOT || checkPair.getPairOp() == PairOperator.SMALLERDOTWC))
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
Set<UnifyPair> setCheckPair = new HashSet<>();
|
||||||
|
setCheckPair.add(checkPair);
|
||||||
|
Set<UnifyPair> setReturnCheckPair = applyTypeUnificationRules(setCheckPair, fc);
|
||||||
|
UnifyPair checkPair1 = setReturnCheckPair.iterator().next();
|
||||||
|
Set<UnifyPair> up = new HashSet<>();
|
||||||
|
up.add(checkPair1);
|
||||||
|
Set<UnifyPair> undef = new HashSet<>();
|
||||||
|
*/
|
||||||
|
PairOperator pairOp = checkPair.getPairOp();
|
||||||
|
UnifyType lhsType = checkPair.getLhsType();
|
||||||
|
UnifyType rhsType = checkPair.getRhsType();
|
||||||
|
///* Case 1: (a <. Theta')
|
||||||
|
if ((((pairOp == PairOperator.SMALLERDOT) || (pairOp == PairOperator.SMALLERNEQDOT)) && lhsType instanceof PlaceholderType)
|
||||||
|
// Case 2: (a <.? ? ext Theta')
|
||||||
|
|| (pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof ExtendsType)
|
||||||
|
// Case 3: (a <.? ? sup Theta')
|
||||||
|
|| (pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof SuperType)
|
||||||
|
|
||||||
|
// Case 4 was replaced by an inference rule
|
||||||
|
// Case 4: (a <.? Theta')
|
||||||
|
|| (pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType)
|
||||||
|
// Case 5: (Theta <. a)
|
||||||
|
|| ((pairOp == PairOperator.SMALLERDOT) && rhsType instanceof PlaceholderType)
|
||||||
|
// Case 6 was replaced by an inference rule.
|
||||||
|
// Case 6: (? ext Theta <.? a)
|
||||||
|
|| (pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof ExtendsType && rhsType instanceof PlaceholderType)
|
||||||
|
// Case 7 was replaced by an inference rule
|
||||||
|
// Case 7: (? sup Theta <.? a)
|
||||||
|
|| (pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof SuperType && rhsType instanceof PlaceholderType)
|
||||||
|
// Case 8: (Theta <.? a)
|
||||||
|
|| (pairOp == PairOperator.SMALLERDOTWC && rhsType instanceof PlaceholderType)
|
||||||
|
//reduceWildcardLow
|
||||||
|
|| (pairOp == PairOperator.SMALLERDOTWC && (lhsType instanceof ExtendsType) && (rhsType instanceof ExtendsType))
|
||||||
|
//reduceWildcardLowRight
|
||||||
|
|| ((pairOp == PairOperator.SMALLERDOTWC) && (lhsType instanceof ReferenceType) && (rhsType instanceof ExtendsType))
|
||||||
|
//reduceWildcardUp
|
||||||
|
|| ((pairOp == PairOperator.SMALLERDOTWC) && (lhsType instanceof SuperType) && (rhsType instanceof SuperType))
|
||||||
|
//reduceWildcardUpRight
|
||||||
|
|| ((pairOp == PairOperator.SMALLERDOTWC) && (lhsType instanceof ReferenceType) && (rhsType instanceof SuperType))
|
||||||
|
//reduceFunN
|
||||||
|
|| (((pairOp == PairOperator.SMALLERDOT) || (pairOp == PairOperator.EQUALSDOT))
|
||||||
|
//PL 2017-10-03 hinzugefuegt
|
||||||
|
//da Regel auch fuer EQUALSDOT anwendbar
|
||||||
|
&& (lhsType instanceof FunNType) && (rhsType instanceof FunNType))
|
||||||
|
//greaterFunN
|
||||||
|
|| ((pairOp== PairOperator.SMALLERDOT) && (lhsType instanceof FunNType) && (rhsType instanceof PlaceholderType))
|
||||||
|
//smallerFunN
|
||||||
|
|| ((pairOp == PairOperator.SMALLERDOT) && (lhsType instanceof PlaceholderType && rhsType instanceof FunNType))
|
||||||
|
//reduceTph
|
||||||
|
|| ((pairOp == PairOperator.SMALLERDOTWC) && (lhsType instanceof PlaceholderType && rhsType instanceof ReferenceType))
|
||||||
|
//reduceTphExt
|
||||||
|
|| ((pairOp == PairOperator.SMALLERDOTWC) && (lhsType instanceof ExtendsType) && rhsType instanceof PlaceholderType)
|
||||||
|
//reduceTphSup
|
||||||
|
|| ((pairOp == PairOperator.SMALLERDOTWC) && (lhsType instanceof SuperType) && rhsType instanceof PlaceholderType)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// Case unknown: If a pair fits no other case, then the type unification has failed.
|
||||||
|
// Through application of the rules, every pair should have one of the above forms.
|
||||||
|
// Pairs that do not have one of the aboves form are contradictory.
|
||||||
|
else {
|
||||||
|
writeLog("Second erase:" +checkPair.toString());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
//*/
|
||||||
|
} else {
|
||||||
|
//Pair type <. ? extends ? extends type betrachten TODO PL 2018-10-09
|
||||||
|
}}
|
||||||
|
return true;}).reduce((xx, yy) -> xx || yy).get();
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean isUndefinedPairSet(Set<UnifyPair> s) {
|
protected boolean isUndefinedPairSet(Set<UnifyPair> s) {
|
||||||
if (s.size() >= 1 ) {
|
if (s.size() >= 1 ) {
|
||||||
Boolean ret = s.stream().map(x -> x.isUndefinedPair()).reduce(true, (x,y)-> (x && y));
|
Boolean ret = s.stream().map(x -> x.isUndefinedPair()).reduce(true, (x,y)-> (x && y));
|
||||||
|
@ -18,4 +18,8 @@ public class Pair<T, T1> {
|
|||||||
public T getKey() {
|
public T getKey() {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "(" + key.toString() + "," + "," + value.toString() + ")\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
@ -151,6 +152,18 @@ public class UnifyPair {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UnifyPair getGroundBasePair () {
|
||||||
|
if (basePair == null) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
if (basePair.getBasePair() == null) {
|
||||||
|
return basePair;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return basePair.getGroundBasePair();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Boolean wrongWildcard() {
|
public Boolean wrongWildcard() {
|
||||||
return lhs.wrongWildcard() || rhs.wrongWildcard();
|
return lhs.wrongWildcard() || rhs.wrongWildcard();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user