Merge branch 'bytecode2' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bytecode2
This commit is contained in:
commit
e380c77ce6
@ -225,6 +225,8 @@ public class JavaTXCompiler {
|
|||||||
System.out.println("RESULT Final: " + results);
|
System.out.println("RESULT Final: " + results);
|
||||||
logFile.write("RES_FINAL: " + results.toString()+"\n");
|
logFile.write("RES_FINAL: " + results.toString()+"\n");
|
||||||
logFile.flush();
|
logFile.flush();
|
||||||
|
logFile.write("PLACEHOLDERS: " + PlaceholderType.EXISTING_PLACEHOLDERS);
|
||||||
|
logFile.flush();
|
||||||
}
|
}
|
||||||
catch (IOException e) { }
|
catch (IOException e) { }
|
||||||
return results.stream().map((unifyPairs ->
|
return results.stream().map((unifyPairs ->
|
||||||
|
@ -254,7 +254,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
numeric = new Constraint<>();
|
numeric = new Constraint<>();
|
||||||
numeric.add(new Pair(binary.lexpr.getType(), integer, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.lexpr.getType(), integer, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.rexpr.getType(), integer, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.rexpr.getType(), integer, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.getType(), integer, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(integer, binary.getType(), PairOperator.SMALLERDOT));
|
||||||
numericAdditionOrStringConcatenation.add(numeric);
|
numericAdditionOrStringConcatenation.add(numeric);
|
||||||
}
|
}
|
||||||
//PL eingefuegt 2018-07-17
|
//PL eingefuegt 2018-07-17
|
||||||
@ -262,7 +262,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
numeric = new Constraint<>();
|
numeric = new Constraint<>();
|
||||||
numeric.add(new Pair(binary.lexpr.getType(), longg, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.lexpr.getType(), longg, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.rexpr.getType(), longg, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.rexpr.getType(), longg, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.getType(), longg, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(longg, binary.getType(), PairOperator.SMALLERDOT));
|
||||||
numericAdditionOrStringConcatenation.add(numeric);
|
numericAdditionOrStringConcatenation.add(numeric);
|
||||||
}
|
}
|
||||||
//PL eingefuegt 2018-07-17
|
//PL eingefuegt 2018-07-17
|
||||||
@ -270,7 +270,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
numeric = new Constraint<>();
|
numeric = new Constraint<>();
|
||||||
numeric.add(new Pair(binary.lexpr.getType(), floatt, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.lexpr.getType(), floatt, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.rexpr.getType(), floatt, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.rexpr.getType(), floatt, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.getType(), floatt, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(floatt, binary.getType(), PairOperator.SMALLERDOT));
|
||||||
numericAdditionOrStringConcatenation.add(numeric);
|
numericAdditionOrStringConcatenation.add(numeric);
|
||||||
}
|
}
|
||||||
//PL eingefuegt 2018-07-17
|
//PL eingefuegt 2018-07-17
|
||||||
@ -278,7 +278,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
numeric = new Constraint<>();
|
numeric = new Constraint<>();
|
||||||
numeric.add(new Pair(binary.lexpr.getType(), doublee, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.lexpr.getType(), doublee, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.rexpr.getType(), doublee, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(binary.rexpr.getType(), doublee, PairOperator.SMALLERDOT));
|
||||||
numeric.add(new Pair(binary.getType(), doublee, PairOperator.SMALLERDOT));
|
numeric.add(new Pair(doublee, binary.getType(), PairOperator.SMALLERDOT));
|
||||||
numericAdditionOrStringConcatenation.add(numeric);
|
numericAdditionOrStringConcatenation.add(numeric);
|
||||||
}
|
}
|
||||||
/* PL auskommentiert Anfang 2018-07-17
|
/* PL auskommentiert Anfang 2018-07-17
|
||||||
@ -298,7 +298,7 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
Constraint<Pair> stringConcat = new Constraint<>();
|
Constraint<Pair> stringConcat = new Constraint<>();
|
||||||
stringConcat.add(new Pair(binary.lexpr.getType(), string, PairOperator.EQUALSDOT));
|
stringConcat.add(new Pair(binary.lexpr.getType(), string, PairOperator.EQUALSDOT));
|
||||||
stringConcat.add(new Pair(binary.rexpr.getType(), string, PairOperator.EQUALSDOT));
|
stringConcat.add(new Pair(binary.rexpr.getType(), string, PairOperator.EQUALSDOT));
|
||||||
stringConcat.add(new Pair(binary.getType(), string, PairOperator.EQUALSDOT));
|
stringConcat.add(new Pair(string, binary.getType(), PairOperator.EQUALSDOT));
|
||||||
numericAdditionOrStringConcatenation.add(stringConcat);
|
numericAdditionOrStringConcatenation.add(stringConcat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -452,8 +452,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
if (nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1)
|
if (nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("D")).findFirst().isPresent() && nextSetasList.size()>1)
|
||||||
System.out.print("");
|
System.out.print("");
|
||||||
writeLog("nextSetasList: " + nextSetasList.toString());
|
writeLog("nextSetasList: " + nextSetasList.toString());
|
||||||
|
Set<UnifyPair> a = null;
|
||||||
while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) {
|
while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) {
|
||||||
Set<UnifyPair> a = null;
|
Set<UnifyPair> a_last = a;
|
||||||
if (variance == 1) {
|
if (variance == 1) {
|
||||||
a = oup.max(nextSetasList.iterator());
|
a = oup.max(nextSetasList.iterator());
|
||||||
nextSetasList.remove(a);
|
nextSetasList.remove(a);
|
||||||
@ -503,9 +504,57 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result))
|
if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result))
|
||||||
|| (!isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result))
|
|| (!isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result))
|
||||||
|| result.isEmpty()) {
|
|| result.isEmpty()) {
|
||||||
|
|
||||||
|
if (!result.isEmpty() && !res.isEmpty() && !isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) {
|
||||||
|
|
||||||
|
//Alle Variablen bestimmen die nicht hinzugefügt wurden in a
|
||||||
|
List<PlaceholderType> vars_a = a.stream().filter(x -> (x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName())
|
||||||
|
||x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName()))).map(y -> (PlaceholderType)y.getLhsType()).collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
Set<UnifyPair> fstElemRes = res.iterator().next();
|
||||||
|
Set<UnifyPair> compRes = fstElemRes.stream().filter(x -> vars_a.contains(((PlaceholderType)x.getLhsType()))).collect(Collectors.toCollection(HashSet::new));
|
||||||
|
|
||||||
|
//Alle Variablen bestimmen die nicht hinzugefügt wurden in a_last
|
||||||
|
List<PlaceholderType> varsLast_a = a_last.stream().filter(x -> (x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName())
|
||||||
|
||x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName()))).map(y -> (PlaceholderType)y.getLhsType()).collect(Collectors.toCollection(ArrayList::new));
|
||||||
|
//erstes Element genügt, da vars immer auf die gleichen Elemente zugeordnet werden muessen
|
||||||
|
Set<UnifyPair> fstElemResult = result.iterator().next();
|
||||||
|
Set<UnifyPair> compResult = fstElemResult.stream().filter(x -> varsLast_a.contains(((PlaceholderType)x.getLhsType()))).collect(Collectors.toCollection(HashSet::new));;
|
||||||
|
|
||||||
|
if (variance == 1) {
|
||||||
|
int resOfCompare = oup.compare(compResult, compRes);
|
||||||
|
if (resOfCompare == -1) {
|
||||||
|
writeLog("Geloescht result: " + result);
|
||||||
|
result = res;
|
||||||
|
} else {
|
||||||
|
if (resOfCompare == 0) {
|
||||||
|
result.addAll(res);
|
||||||
|
} //else {
|
||||||
|
if (resOfCompare == 1) {
|
||||||
|
writeLog("Geloescht res: " + res);
|
||||||
|
//result = result;
|
||||||
|
}}}
|
||||||
|
else { if (variance == -1) {
|
||||||
|
int resOfCompare = oup.compare(compResult, compRes);
|
||||||
|
if (resOfCompare == 1) {
|
||||||
|
writeLog("Geloescht result: " + result);
|
||||||
|
result = res;
|
||||||
|
} else {
|
||||||
|
if (resOfCompare == 0) {
|
||||||
|
result.addAll(res);
|
||||||
|
} else {
|
||||||
|
if (resOfCompare == -1) {
|
||||||
|
writeLog("Geloescht res: " + res);
|
||||||
|
//result = result;
|
||||||
|
}}}}
|
||||||
|
else { if (variance == 0) {
|
||||||
|
result.addAll(res);
|
||||||
|
}}}
|
||||||
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
|
//alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden
|
||||||
result.addAll(res);
|
}
|
||||||
}
|
else {
|
||||||
|
result.addAll(res);
|
||||||
|
}
|
||||||
|
}
|
||||||
//else {
|
//else {
|
||||||
//wenn Korrekte Ergebnisse da und Feherfälle dazukommen Fehlerfälle ignorieren
|
//wenn Korrekte Ergebnisse da und Feherfälle dazukommen Fehlerfälle ignorieren
|
||||||
// if (isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) {
|
// if (isUndefinedPairSetSet(res) && !isUndefinedPairSetSet(result)) {
|
||||||
@ -523,7 +572,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
if (!result.isEmpty() && !isUndefinedPairSetSet(res)) {
|
if (!result.isEmpty() && !isUndefinedPairSetSet(res)) {
|
||||||
if (nextSetasList.iterator().hasNext() && nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("B")).findFirst().isPresent() && nextSetasList.size()>1)
|
if (nextSetasList.iterator().hasNext() && nextSetasList.iterator().next().stream().filter(x -> x.getLhsType().getName().equals("B")).findFirst().isPresent() && nextSetasList.size()>1)
|
||||||
System.out.print("");
|
System.out.print("");
|
||||||
Iterator<Set<UnifyPair>> nextSetasListIt = new ArrayList<Set<UnifyPair>>(nextSetasList).iterator();
|
Iterator<Set<UnifyPair>> nextSetasListIt = new ArrayList<Set<UnifyPair>>(nextSetasList).iterator();
|
||||||
if (variance == 1) {
|
if (variance == 1) {
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
while (nextSetasListIt.hasNext()) {
|
while (nextSetasListIt.hasNext()) {
|
||||||
@ -1144,7 +1193,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<UnifyPair> resultPrime = new HashSet<>();
|
Set<UnifyPair> resultPrime = new HashSet<>();
|
||||||
|
|
||||||
for(int i = 0; !allGen && i < theta.getTypeParams().size(); i++) {
|
for(int i = 0; !allGen && i < theta.getTypeParams().size(); i++) {
|
||||||
if(freshTphs.size()-1 < i)
|
if(freshTphs.size()-1 < i)//IST DAS RICHTIG??? PL 2018-12-12
|
||||||
freshTphs.add(PlaceholderType.freshPlaceholder());
|
freshTphs.add(PlaceholderType.freshPlaceholder());
|
||||||
resultPrime.add(new UnifyPair(freshTphs.get(i), theta.getTypeParams().get(i), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair));
|
resultPrime.add(new UnifyPair(freshTphs.get(i), theta.getTypeParams().get(i), PairOperator.SMALLERDOTWC, pair.getSubstitution(), pair));
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import java.util.Arrays;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
@ -26,7 +27,8 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify;
|
|||||||
* The finite closure for the type unification
|
* The finite closure for the type unification
|
||||||
* @author Florian Steurer
|
* @author Florian Steurer
|
||||||
*/
|
*/
|
||||||
public class FiniteClosure extends Ordering<UnifyType> implements IFiniteClosure {
|
public class FiniteClosure //extends Ordering<UnifyType> //entfernt PL 2018-12-11
|
||||||
|
implements IFiniteClosure {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A map that maps every type to the node in the inheritance graph that contains that type.
|
* A map that maps every type to the node in the inheritance graph that contains that type.
|
||||||
@ -561,14 +563,53 @@ public class FiniteClosure extends Ordering<UnifyType> implements IFiniteClosure
|
|||||||
return this.inheritanceGraph.toString();
|
return this.inheritanceGraph.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* entfernt PL 2018-12-11
|
||||||
public int compare (UnifyType left, UnifyType right) {
|
public int compare (UnifyType left, UnifyType right) {
|
||||||
return compare(left, right, PairOperator.SMALLERDOT);
|
return compare(left, right, PairOperator.SMALLERDOT);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
public int compare (UnifyType left, UnifyType right, PairOperator pairop) {
|
public int compare (UnifyType left, UnifyType right, PairOperator pairop) {
|
||||||
if ((left instanceof ExtendsType && right instanceof ReferenceType)
|
if ((left instanceof ExtendsType && right instanceof ReferenceType)
|
||||||
|| (right instanceof ExtendsType && left instanceof ReferenceType))
|
|| (right instanceof ExtendsType && left instanceof ReferenceType))
|
||||||
System.out.println("");
|
System.out.println("");
|
||||||
|
/*
|
||||||
|
List<UnifyType> al = new ArrayList<>();
|
||||||
|
PlaceholderType xx =new PlaceholderType("xx");
|
||||||
|
al.add(xx);
|
||||||
|
left = new ExtendsType(new ReferenceType("Vector", new TypeParams(al)));
|
||||||
|
right = new ReferenceType("Vector", new TypeParams(new ArrayList<>(al)));
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
List<UnifyType> al = new ArrayList<>();
|
||||||
|
PlaceholderType xx =new PlaceholderType("xx");
|
||||||
|
al.add(xx);
|
||||||
|
left = new ExtendsType(xx);
|
||||||
|
right = xx;
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
List<UnifyType> al = new ArrayList<>();
|
||||||
|
PlaceholderType xx =new PlaceholderType("xx");
|
||||||
|
PlaceholderType yy =new PlaceholderType("yy");
|
||||||
|
al.add(xx);
|
||||||
|
left = yy;
|
||||||
|
right = new ExtendsType(xx);
|
||||||
|
*/
|
||||||
|
//Die Faelle abfangen, bei den Variablen verglichen werden PL 2018-12-11
|
||||||
|
UnifyType ex;
|
||||||
|
if (left instanceof PlaceholderType) {
|
||||||
|
if ((right instanceof WildcardType)
|
||||||
|
&& ((ex = ((WildcardType)right).wildcardedType) instanceof PlaceholderType)
|
||||||
|
&& ((PlaceholderType)left).getName().equals(((PlaceholderType)ex).getName())) {// a <.? ? extends a oder a <.? ? super a
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((right instanceof PlaceholderType) && (left instanceof WildcardType)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
UnifyPair up = new UnifyPair(left, right, pairop);
|
UnifyPair up = new UnifyPair(left, right, pairop);
|
||||||
TypeUnifyTask unifyTask = new TypeUnifyTask();
|
TypeUnifyTask unifyTask = new TypeUnifyTask();
|
||||||
HashSet<UnifyPair> hs = new HashSet<>();
|
HashSet<UnifyPair> hs = new HashSet<>();
|
||||||
|
@ -151,7 +151,7 @@ public class OrderingUnifyPair extends Ordering<Set<UnifyPair>> {
|
|||||||
System.out.print("");
|
System.out.print("");
|
||||||
//Set<PlaceholderType> varsleft = lefteq.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new));
|
//Set<PlaceholderType> varsleft = lefteq.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new));
|
||||||
//Set<PlaceholderType> varsright = righteq.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new));
|
//Set<PlaceholderType> varsright = righteq.stream().map(x -> (PlaceholderType)x.getLhsType()).collect(Collectors.toCollection(HashSet::new));
|
||||||
//filtern des Paares a = Theta, das durch a <. Thata' generiert wurde (nur im Fall 1 relevant)
|
//filtern des Paares a = Theta, das durch a <. Thata' generiert wurde (nur im Fall 1 relevant) andere Substitutioen werden rausgefiltert
|
||||||
lefteq.removeIf(x -> !(x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName())
|
lefteq.removeIf(x -> !(x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName())
|
||||||
||x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName())));//removeIf(x -> !varsright.contains(x.getLhsType()));
|
||x.getLhsType().getName().equals(x.getBasePair().getRhsType().getName())));//removeIf(x -> !varsright.contains(x.getLhsType()));
|
||||||
righteq.removeIf(x -> !(x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName())
|
righteq.removeIf(x -> !(x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName())
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package de.dhbwstuttgart.typeinference.unify.model;
|
package de.dhbwstuttgart.typeinference.unify.model;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -21,7 +23,7 @@ public final class PlaceholderType extends UnifyType{
|
|||||||
* Static list containing the names of all existing placeholders.
|
* Static list containing the names of all existing placeholders.
|
||||||
* Used for generating fresh placeholders.
|
* Used for generating fresh placeholders.
|
||||||
*/
|
*/
|
||||||
protected static final HashSet<String> EXISTING_PLACEHOLDERS = new HashSet<String>();
|
public static final ArrayList<String> EXISTING_PLACEHOLDERS = new ArrayList<String>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prefix of auto-generated placeholder names.
|
* Prefix of auto-generated placeholder names.
|
||||||
@ -81,11 +83,12 @@ public final class PlaceholderType extends UnifyType{
|
|||||||
* A user could later instantiate a type using the same name that is equivalent to this type.
|
* A user could later instantiate a type using the same name that is equivalent to this type.
|
||||||
* @return A fresh placeholder type.
|
* @return A fresh placeholder type.
|
||||||
*/
|
*/
|
||||||
public static PlaceholderType freshPlaceholder() {
|
public synchronized static PlaceholderType freshPlaceholder() {
|
||||||
String name = nextName + (char) (rnd.nextInt(22) + 97); // Returns random char between 'a' and 'z'
|
String name = nextName + (char) (rnd.nextInt(22) + 97); // Returns random char between 'a' and 'z'
|
||||||
// Add random chars while the name is in use.
|
// Add random chars while the name is in use.
|
||||||
while(EXISTING_PLACEHOLDERS.contains(name));
|
while(EXISTING_PLACEHOLDERS.contains(name)) {
|
||||||
name += (char) (rnd.nextInt(22) + 97); // Returns random char between 'a' and 'z'
|
name += (char) (rnd.nextInt(22) + 97); // Returns random char between 'a' and 'z'
|
||||||
|
}
|
||||||
return new PlaceholderType(name, true);
|
return new PlaceholderType(name, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user