Compare commits
43 Commits
unify-test
...
plugin
Author | SHA1 | Date | |
---|---|---|---|
|
8c80a11675 | ||
|
789b13aea9 | ||
|
b3897d2260 | ||
|
3649f7f767 | ||
|
d288a0f27d | ||
|
9ab98a7e1d | ||
|
6c83206f3a | ||
|
6a6e6b343d | ||
|
9d93fa63fa | ||
|
666bf26594 | ||
|
29963dfbc3 | ||
|
82d8ecba74 | ||
|
42aee3dbec | ||
|
87547fdcd6 | ||
|
85144cb6d8 | ||
|
fde462eb16 | ||
|
f7e1a34c5a | ||
|
21c92d4cab | ||
|
a373aa7313 | ||
|
898aedcb4a | ||
|
f9c0ea8b52 | ||
|
d9cda2779f | ||
|
aa662b58fe | ||
|
2908613499 | ||
|
a867231348 | ||
|
757c6e0ec1 | ||
|
65e0a22477 | ||
|
f79e4c6df0 | ||
|
67e35ed8d9 | ||
|
07c35fef10 | ||
|
66b6bb7c5d | ||
|
978f222dfa | ||
|
8e6b9a9ece | ||
|
7417a3abe1 | ||
|
fd8568532a | ||
|
b416931dee | ||
|
dd8dbd755e | ||
cb13b0baa9 | |||
03ef170b6e | |||
|
4e939a6131 | ||
|
ac49f26df3 | ||
|
57a82e8863 | ||
|
89b7d99621 |
Binary file not shown.
4
pom.xml
4
pom.xml
@@ -7,7 +7,7 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
|||||||
<artifactId>JavaTXcompiler</artifactId>
|
<artifactId>JavaTXcompiler</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<version>0.2</version>
|
<version>0.1</version>
|
||||||
<name>JavaTXcompiler</name>
|
<name>JavaTXcompiler</name>
|
||||||
<url>http://maven.apache.org</url>
|
<url>http://maven.apache.org</url>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -127,7 +127,7 @@ http://maven.apache.org/maven-v4_0_0.xsd">
|
|||||||
<!-- specify your depencies here -->
|
<!-- specify your depencies here -->
|
||||||
<!-- groupId:artifactId:version -->
|
<!-- groupId:artifactId:version -->
|
||||||
<artifact>
|
<artifact>
|
||||||
<id>de.dhbwstuttgart:JavaTXcompiler:0.2</id>
|
<id>de.dhbwstuttgart:JavaTXcompiler:0.1</id>
|
||||||
</artifact>
|
</artifact>
|
||||||
<artifact>
|
<artifact>
|
||||||
<id>org.reflections:reflections:0.9.11</id>
|
<id>org.reflections:reflections:0.9.11</id>
|
||||||
|
929
src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
Normal file
929
src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
Normal file
@@ -0,0 +1,929 @@
|
|||||||
|
package de.dhbwstuttgart.typeinference.unify;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.RecursiveTask;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.interfaces.ISetOperations;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.ExtendsType;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.PairOperator;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.SuperType;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.TypeParams;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.Unifier;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
|
||||||
|
import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import com.google.common.collect.Ordering;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of the type unification algorithm
|
||||||
|
* @author Florian Steurer
|
||||||
|
*/
|
||||||
|
public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private static int i = 0;
|
||||||
|
private boolean printtag = false;
|
||||||
|
|
||||||
|
public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/";
|
||||||
|
FileWriter logFile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The implementation of setOps that will be used during the unification
|
||||||
|
*/
|
||||||
|
protected ISetOperations setOps = new GuavaSetOperations();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The implementation of the standard unify that will be used during the unification
|
||||||
|
*/
|
||||||
|
protected IUnify stdUnify = new MartelliMontanariUnify();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The implementation of the rules that will be used during the unification.
|
||||||
|
*/
|
||||||
|
protected IRuleSet rules;
|
||||||
|
|
||||||
|
protected Set<UnifyPair> eq;
|
||||||
|
|
||||||
|
protected IFiniteClosure fc;
|
||||||
|
|
||||||
|
protected Ordering<Set<UnifyPair>> oup;
|
||||||
|
|
||||||
|
protected boolean parallel;
|
||||||
|
|
||||||
|
public TypeUnifyTask() {
|
||||||
|
rules = new RuleSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
public TypeUnifyTask(Set<UnifyPair> eq, IFiniteClosure fc, boolean parallel, FileWriter logFile) {
|
||||||
|
this.eq = eq;
|
||||||
|
this.fc = fc;
|
||||||
|
this.oup = new OrderingUnifyPair(fc);
|
||||||
|
this.parallel = parallel;
|
||||||
|
this.logFile = logFile;
|
||||||
|
rules = new RuleSet(logFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Set<Set<UnifyPair>> compute() {
|
||||||
|
return unify(eq, fc, parallel);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes all principal type unifiers for a set of constraints.
|
||||||
|
* @param eq The set of constraints
|
||||||
|
* @param fc The finite closure
|
||||||
|
* @return The set of all principal type unifiers
|
||||||
|
*/
|
||||||
|
protected Set<Set<UnifyPair>> unify(Set<UnifyPair> eq, IFiniteClosure fc, boolean parallel) {
|
||||||
|
/*
|
||||||
|
* Step 1: Repeated application of reduce, adapt, erase, swap
|
||||||
|
*/
|
||||||
|
writeLog("Unifikation: " + eq.toString());
|
||||||
|
eq = eq.stream().map(x -> {x.setVariance((byte)-1); return x;}).collect(Collectors.toCollection(HashSet::new));
|
||||||
|
Set<UnifyPair> eq0 = applyTypeUnificationRules(eq, fc);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Step 2 and 3: Create a subset eq1s of pairs where both sides are TPH and eq2s of the other pairs
|
||||||
|
*/
|
||||||
|
Set<UnifyPair> eq1s = new HashSet<>();
|
||||||
|
Set<UnifyPair> eq2s = new HashSet<>();
|
||||||
|
splitEq(eq0, eq1s, eq2s);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Step 4: Create possible typings
|
||||||
|
*
|
||||||
|
* "Manche Autoren identifizieren die Paare (a, (b,c)) und ((a,b),c)
|
||||||
|
* mit dem geordneten Tripel (a,b,c), wodurch das kartesische Produkt auch assoziativ wird." - Wikipedia
|
||||||
|
*/
|
||||||
|
|
||||||
|
// There are up to 10 toplevel set. 8 of 10 are the result of the
|
||||||
|
// cartesian product of the sets created by pattern matching.
|
||||||
|
List<Set<Set<UnifyPair>>> topLevelSets = new ArrayList<>();
|
||||||
|
|
||||||
|
//System.out.println(eq2s);
|
||||||
|
|
||||||
|
if(eq1s.size() != 0) { // Do not add empty sets or the cartesian product will always be empty.
|
||||||
|
Set<Set<UnifyPair>> wrap = new HashSet<>();
|
||||||
|
wrap.add(eq1s);
|
||||||
|
topLevelSets.add(wrap); // Add Eq1'
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the set of [a =. Theta | (a=. Theta) in Eq2']
|
||||||
|
Set<UnifyPair> bufferSet = eq2s.stream()
|
||||||
|
.filter(x -> x.getPairOp() == PairOperator.EQUALSDOT && x.getLhsType() instanceof PlaceholderType)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
if(bufferSet.size() != 0) { // Do not add empty sets or the cartesian product will always be empty.
|
||||||
|
Set<Set<UnifyPair>> wrap = new HashSet<>();
|
||||||
|
wrap.add(bufferSet);
|
||||||
|
topLevelSets.add(wrap);
|
||||||
|
eq2s.removeAll(bufferSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sets that originate from pair pattern matching
|
||||||
|
// Sets of the "second level"
|
||||||
|
Set<UnifyPair> undefinedPairs = new HashSet<>();
|
||||||
|
if (printtag) System.out.println("eq2s " + eq2s);
|
||||||
|
//writeLog("BufferSet: " + bufferSet.toString()+"\n");
|
||||||
|
Set<Set<Set<Set<UnifyPair>>>> secondLevelSets = calculatePairSets(eq2s, fc, undefinedPairs);
|
||||||
|
//PL 2017-09-20: Im calculatePairSets wird möglicherweise O .< java.lang.Integer
|
||||||
|
//nicht ausgewertet Faculty Beispiel im 1. Schritt
|
||||||
|
//PL 2017-10-03 geloest, muesste noch mit FCs mit kleineren
|
||||||
|
//Typen getestet werden.
|
||||||
|
if (printtag) System.out.println("secondLevelSets:" +secondLevelSets);
|
||||||
|
// If pairs occured that did not match one of the cartesian product cases,
|
||||||
|
// those pairs are contradictory and the unification is impossible.
|
||||||
|
if(!undefinedPairs.isEmpty()) {
|
||||||
|
writeLog("UndefinedPairs; " + undefinedPairs);
|
||||||
|
Set<Set<UnifyPair>> error = new HashSet<>();
|
||||||
|
error.add(undefinedPairs);
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Up to here, no cartesian products are calculated.
|
||||||
|
* filters for pairs and sets can be applied here */
|
||||||
|
|
||||||
|
// Alternative: Sub cartesian products of the second level (pattern matched) sets
|
||||||
|
// "the big (x)"
|
||||||
|
/* for(Set<Set<Set<UnifyPair>>> secondLevelSet : secondLevelSets) {
|
||||||
|
//System.out.println("secondLevelSet "+secondLevelSet.size());
|
||||||
|
List<Set<Set<UnifyPair>>> secondLevelSetList = new ArrayList<>(secondLevelSet);
|
||||||
|
Set<List<Set<UnifyPair>>> cartResult = setOps.cartesianProduct(secondLevelSetList);
|
||||||
|
//System.out.println("CardResult: "+cartResult.size());
|
||||||
|
// Flatten and add to top level sets
|
||||||
|
Set<Set<UnifyPair>> flat = new HashSet<>();
|
||||||
|
int j = 0;
|
||||||
|
for(List<Set<UnifyPair>> s : cartResult) {
|
||||||
|
j++;
|
||||||
|
//System.out.println("s from CardResult: "+cartResult.size() + " " + j);
|
||||||
|
Set<UnifyPair> flat1 = new HashSet<>();
|
||||||
|
for(Set<UnifyPair> s1 : s)
|
||||||
|
flat1.addAll(s1);
|
||||||
|
flat.add(flat1);
|
||||||
|
}
|
||||||
|
//topLevelSets.add(flat);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Alternative KEIN KARTESISCHES PRODUKT der secondlevel Ebene bilden
|
||||||
|
for(Set<Set<Set<UnifyPair>>> secondLevelSet : secondLevelSets) {
|
||||||
|
for (Set<Set<UnifyPair>> secondlevelelem : secondLevelSet) {
|
||||||
|
topLevelSets.add(secondlevelelem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//System.out.println(topLevelSets);
|
||||||
|
//System.out.println();
|
||||||
|
|
||||||
|
|
||||||
|
//Aufruf von computeCartesianRecursive ANFANG
|
||||||
|
return computeCartesianRecursive(new HashSet<>(), new ArrayList<>(topLevelSets), eq, fc, parallel);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Set<Set<UnifyPair>> unify2(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, IFiniteClosure fc, boolean parallel) {
|
||||||
|
//Aufruf von computeCartesianRecursive ENDE
|
||||||
|
|
||||||
|
//keine Ahnung woher das kommt
|
||||||
|
//Set<Set<UnifyPair>> setToFlatten = topLevelSets.stream().map(x -> x.iterator().next()).collect(Collectors.toCollection(HashSet::new));
|
||||||
|
|
||||||
|
//Muss auskommentiert werden, wenn computeCartesianRecursive ANFANG
|
||||||
|
// Cartesian product over all (up to 10) top level sets
|
||||||
|
//Set<Set<Set<UnifyPair>>> eqPrimeSet = setOps.cartesianProduct(topLevelSets)
|
||||||
|
// .stream().map(x -> new HashSet<>(x))
|
||||||
|
// .collect(Collectors.toCollection(HashSet::new));
|
||||||
|
//Muss auskommentiert werden, wenn computeCartesianRecursive ENDE
|
||||||
|
|
||||||
|
Set<Set<UnifyPair>> eqPrimePrimeSet = new HashSet<>();
|
||||||
|
|
||||||
|
Set<TypeUnifyTask> forks = new HashSet<>();
|
||||||
|
|
||||||
|
//Muss auskommentiert werden, wenn computeCartesianRecursive ANFANG
|
||||||
|
//for(Set<Set<UnifyPair>> setToFlatten : eqPrimeSet) {
|
||||||
|
// Flatten the cartesian product
|
||||||
|
//Muss auskommentiert werden, wenn computeCartesianRecursive ENDE
|
||||||
|
Set<UnifyPair> eqPrime = new HashSet<>();
|
||||||
|
setToFlatten.stream().forEach(x -> eqPrime.addAll(x));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Step 5: Substitution
|
||||||
|
*/
|
||||||
|
//System.out.println("vor Subst: " + eqPrime);
|
||||||
|
Optional<Set<UnifyPair>> eqPrimePrime = rules.subst(eqPrime);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Step 6 a) Restart (fork) for pairs where subst was applied
|
||||||
|
*/
|
||||||
|
if(parallel) {
|
||||||
|
if (eqPrime.equals(eq)) //PL 2017-09-29 auskommentiert und durch
|
||||||
|
//(!eqPrimePrime.isPresent()) //PL 2071-09-29 dies ersetzt
|
||||||
|
//Begruendung: Wenn in der Substitution keine Veraenderung
|
||||||
|
//(!eqPrimePrime.isPresent()) erfolgt ist, ist das Ergebnis erzielt.
|
||||||
|
eqPrimePrimeSet.add(eqPrime);
|
||||||
|
else if(eqPrimePrime.isPresent()) {
|
||||||
|
//System.out.println("nextStep: " + eqPrimePrime.get());
|
||||||
|
TypeUnifyTask fork = new TypeUnifyTask(eqPrimePrime.get(), fc, true, logFile);
|
||||||
|
forks.add(fork);
|
||||||
|
fork.fork();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
//System.out.println("nextStep: " + eqPrime);
|
||||||
|
TypeUnifyTask fork = new TypeUnifyTask(eqPrime, fc, true, logFile);
|
||||||
|
forks.add(fork);
|
||||||
|
fork.fork();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else { // sequentiell (Step 6b is included)
|
||||||
|
if (printtag) System.out.println("nextStep: " + eqPrimePrime);
|
||||||
|
if (eqPrime.equals(eq)) { //PL 2017-09-29 auskommentiert und durch
|
||||||
|
//(!eqPrimePrime.isPresent()) //PL 2071-09-29 dies ersetzt
|
||||||
|
//Begruendung: Wenn in der Substitution keine Veraenderung
|
||||||
|
//(!eqPrimePrime.isPresent()) erfolgt ist, ist das Ergebnis erzielt.
|
||||||
|
try {
|
||||||
|
if (isSolvedForm(eqPrime)) {
|
||||||
|
logFile.write(eqPrime.toString()+"\n");
|
||||||
|
logFile.flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (IOException e) { }
|
||||||
|
eqPrimePrimeSet.add(eqPrime);
|
||||||
|
}
|
||||||
|
else if(eqPrimePrime.isPresent()) {
|
||||||
|
Set<Set<UnifyPair>> unifyres = unify(eqPrimePrime.get(), fc, false);
|
||||||
|
|
||||||
|
eqPrimePrimeSet.addAll(unifyres);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Set<Set<UnifyPair>> unifyres = unify(eqPrime, fc, false);
|
||||||
|
|
||||||
|
|
||||||
|
eqPrimePrimeSet.addAll(unifyres);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//Muss auskommentiert werden, wenn computeCartesianRecursive ANFANG
|
||||||
|
//}
|
||||||
|
//Muss auskommentiert werden, wenn computeCartesianRecursive ENDE
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Step 6 b) Build the union over everything.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if(parallel)
|
||||||
|
for(TypeUnifyTask fork : forks)
|
||||||
|
eqPrimePrimeSet.addAll(fork.join());
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Step 7: Filter empty sets;
|
||||||
|
*/
|
||||||
|
eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x)).collect(Collectors.toCollection(HashSet::new));
|
||||||
|
if (!eqPrimePrimeSet.isEmpty())
|
||||||
|
writeLog("Result " + eqPrimePrimeSet.toString());
|
||||||
|
return eqPrimePrimeSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Set<Set<UnifyPair>> computeCartesianRecursive(Set<Set<UnifyPair>> fstElems, ArrayList<Set<Set<UnifyPair>>> topLevelSets, Set<UnifyPair> eq, IFiniteClosure fc, boolean parallel) {
|
||||||
|
ArrayList<Set<Set<UnifyPair>>> remainingSets = new ArrayList<>(topLevelSets);
|
||||||
|
Set<Set<UnifyPair>> nextSet = remainingSets.remove(0);
|
||||||
|
ArrayList<Set<UnifyPair>> nextSetasList = new ArrayList<>(nextSet);
|
||||||
|
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||||
|
int i = 0;
|
||||||
|
byte variance = nextSetasList.iterator().next().iterator().next().getVariance();
|
||||||
|
Set<UnifyPair> a_next = null;
|
||||||
|
if (nextSetasList.iterator().next().iterator().next().getLhsType().getName().equals("D"))
|
||||||
|
System.out.print("");
|
||||||
|
if (nextSetasList.size()>1) {
|
||||||
|
if (variance == 1) {
|
||||||
|
a_next = oup.max(nextSetasList.iterator());
|
||||||
|
}
|
||||||
|
else if (variance == -1) {
|
||||||
|
a_next = oup.min(nextSetasList.iterator());
|
||||||
|
}
|
||||||
|
else if (variance == 0) {
|
||||||
|
a_next = nextSetasList.iterator().next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
a_next = nextSetasList.iterator().next();
|
||||||
|
}
|
||||||
|
while (nextSetasList.size() != 0) {
|
||||||
|
Set<UnifyPair> a = a_next;
|
||||||
|
//writeLog("nextSet: " + nextSetasList.toString()+ "\n");
|
||||||
|
nextSetasList.remove(a);
|
||||||
|
if (nextSetasList.size() > 0) {
|
||||||
|
if (nextSetasList.size()>1) {
|
||||||
|
if (variance == 1) {
|
||||||
|
a_next = oup.max(nextSetasList.iterator());
|
||||||
|
}
|
||||||
|
else if (variance == -1) {
|
||||||
|
a_next = oup.min(nextSetasList.iterator());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
a_next = nextSetasList.iterator().next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
a_next = nextSetasList.iterator().next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//PL 2018-03-01
|
||||||
|
//TODO: 1. Maximum und Minimum unterscheiden
|
||||||
|
//TODO: 2. compare noch für alle Elmemente die nicht X =. ty sind erweitern
|
||||||
|
//for(Set<UnifyPair> a : newSet) {
|
||||||
|
i++;
|
||||||
|
Set<Set<UnifyPair>> elems = new HashSet<Set<UnifyPair>>(fstElems);
|
||||||
|
elems.add(a);
|
||||||
|
if (remainingSets.isEmpty()) {
|
||||||
|
result.addAll(unify2(elems, eq, fc, parallel));
|
||||||
|
System.out.println("");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel));
|
||||||
|
}
|
||||||
|
if (!result.isEmpty()) {
|
||||||
|
if (variance == 1) {
|
||||||
|
if (a.iterator().next().getLhsType().getName().equals("WL"))
|
||||||
|
System.out.print("");
|
||||||
|
if (a.equals(a_next) ||
|
||||||
|
(oup.compare(a, a_next) == 1)) {
|
||||||
|
System.out.print("");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.print("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else { if (variance == -1) {
|
||||||
|
if (a.iterator().next().getLhsType().getName().equals("A"))
|
||||||
|
System.out.print("");
|
||||||
|
if (a.equals(a_next) || (oup.compare(a, a_next) == -1)) {
|
||||||
|
System.out.print("");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.print("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (variance == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean isUndefinedPairSet(Set<Set<UnifyPair>> s) {
|
||||||
|
boolean res = true;
|
||||||
|
if (s.size() ==1) {
|
||||||
|
s.iterator().next().stream().forEach(x -> { res = res && x.isUndefinedPair(); return; });
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Checks whether a set of pairs is in solved form.
|
||||||
|
* @param eqPrimePrime The set of pair
|
||||||
|
* @return True if in solved form, false otherwise.
|
||||||
|
*/
|
||||||
|
protected boolean isSolvedForm(Set<UnifyPair> eqPrimePrime) {
|
||||||
|
for(UnifyPair pair : eqPrimePrime) {
|
||||||
|
UnifyType lhsType = pair.getLhsType();
|
||||||
|
UnifyType rhsType = pair.getRhsType();
|
||||||
|
|
||||||
|
if(!(lhsType instanceof PlaceholderType))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// If operator is not equals, both sides must be placeholders
|
||||||
|
if(pair.getPairOp() != PairOperator.EQUALSDOT && !(rhsType instanceof PlaceholderType))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repeatedly applies type unification rules to a set of equations.
|
||||||
|
* This is step one of the unification algorithm.
|
||||||
|
* @return The set of pairs that results from repeated application of the inference rules.
|
||||||
|
*/
|
||||||
|
public Set<UnifyPair> applyTypeUnificationRules(Set<UnifyPair> eq, IFiniteClosure fc) {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Rule Application Strategy:
|
||||||
|
*
|
||||||
|
* 1. Swap all pairs and erase all erasable pairs
|
||||||
|
* 2. Apply all possible rules to a single pair, then move it to the result set.
|
||||||
|
* Iterating over pairs first, then iterating over rules prevents the application
|
||||||
|
* of rules to a "finished" pair over and over.
|
||||||
|
* 2.1 Apply all rules repeatedly except for erase rules. If
|
||||||
|
* the application of a rule creates new pairs, check immediately
|
||||||
|
* against the erase rules.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
LinkedHashSet<UnifyPair> targetSet = new LinkedHashSet<UnifyPair>();
|
||||||
|
LinkedList<UnifyPair> eqQueue = new LinkedList<>();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Swap all pairs and erase all erasable pairs
|
||||||
|
*/
|
||||||
|
eq.forEach(x -> swapAddOrErase(x, fc, eqQueue));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Apply rules until the queue is empty
|
||||||
|
*/
|
||||||
|
while(!eqQueue.isEmpty()) {
|
||||||
|
UnifyPair pair = eqQueue.pollFirst();
|
||||||
|
|
||||||
|
// ReduceUp, ReduceLow, ReduceUpLow
|
||||||
|
Optional<UnifyPair> opt = rules.reduceUpLow(pair);
|
||||||
|
opt = opt.isPresent() ? opt : rules.reduceLow(pair);
|
||||||
|
opt = opt.isPresent() ? opt : rules.reduceUp(pair);
|
||||||
|
opt = opt.isPresent() ? opt : rules.reduceWildcardLow(pair);
|
||||||
|
opt = opt.isPresent() ? opt : rules.reduceWildcardLowRight(pair);
|
||||||
|
opt = opt.isPresent() ? opt : rules.reduceWildcardUp(pair);
|
||||||
|
opt = opt.isPresent() ? opt : rules.reduceWildcardUpRight(pair);
|
||||||
|
//PL 2018-03-06 auskommentiert muesste falsch sein vgl. JAVA_BSP/Wildcard6.java
|
||||||
|
//opt = opt.isPresent() ? opt : rules.reduceWildcardLowUp(pair);
|
||||||
|
//opt = opt.isPresent() ? opt : rules.reduceWildcardUpLow(pair);
|
||||||
|
//opt = opt.isPresent() ? opt : rules.reduceWildcardLeft(pair);
|
||||||
|
|
||||||
|
// Reduce TPH
|
||||||
|
opt = opt.isPresent() ? opt : rules.reduceTph(pair);
|
||||||
|
|
||||||
|
// One of the rules has been applied
|
||||||
|
if(opt.isPresent()) {
|
||||||
|
swapAddOrErase(opt.get(), fc, eqQueue);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reduce1, Reduce2, ReduceExt, ReduceSup, ReduceEq
|
||||||
|
//try {
|
||||||
|
// logFile.write("PAIR1 " + pair + "\n");
|
||||||
|
// logFile.flush();
|
||||||
|
//}
|
||||||
|
//catch (IOException e) { }
|
||||||
|
|
||||||
|
Optional<Set<UnifyPair>> optSet = rules.reduce1(pair, fc);
|
||||||
|
optSet = optSet.isPresent() ? optSet : rules.reduce2(pair);
|
||||||
|
optSet = optSet.isPresent() ? optSet : rules.reduceExt(pair, fc);
|
||||||
|
optSet = optSet.isPresent() ? optSet : rules.reduceSup(pair, fc);
|
||||||
|
optSet = optSet.isPresent() ? optSet : rules.reduceEq(pair);
|
||||||
|
|
||||||
|
// ReduceTphExt, ReduceTphSup
|
||||||
|
optSet = optSet.isPresent() ? optSet : rules.reduceTphExt(pair);
|
||||||
|
optSet = optSet.isPresent() ? optSet : rules.reduceTphSup(pair);
|
||||||
|
|
||||||
|
|
||||||
|
// FunN Rules
|
||||||
|
optSet = optSet.isPresent() ? optSet : rules.reduceFunN(pair);
|
||||||
|
optSet = optSet.isPresent() ? optSet : rules.greaterFunN(pair);
|
||||||
|
optSet = optSet.isPresent() ? optSet : rules.smallerFunN(pair);
|
||||||
|
|
||||||
|
// One of the rules has been applied
|
||||||
|
if(optSet.isPresent()) {
|
||||||
|
optSet.get().forEach(x -> swapAddOrErase(x, fc, eqQueue));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Adapt, AdaptExt, AdaptSup
|
||||||
|
//try {
|
||||||
|
// logFile.write("PAIR2 " + pair + "\n");
|
||||||
|
// logFile.flush();
|
||||||
|
//}
|
||||||
|
//catch (IOException e) { }
|
||||||
|
opt = rules.adapt(pair, fc);
|
||||||
|
opt = opt.isPresent() ? opt : rules.adaptExt(pair, fc);
|
||||||
|
opt = opt.isPresent() ? opt : rules.adaptSup(pair, fc);
|
||||||
|
|
||||||
|
// One of the rules has been applied
|
||||||
|
if(opt.isPresent()) {
|
||||||
|
swapAddOrErase(opt.get(), fc, eqQueue);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// None of the rules has been applied
|
||||||
|
targetSet.add(pair);
|
||||||
|
}
|
||||||
|
|
||||||
|
return targetSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Applies the rule swap to a pair if possible. Then adds the pair to the set if no erase rule applies.
|
||||||
|
* If an erase rule applies, the pair is not added (erased).
|
||||||
|
* @param pair The pair to swap and add or erase.
|
||||||
|
* @param collection The collection to which the pairs are added.
|
||||||
|
*/
|
||||||
|
protected void swapAddOrErase(UnifyPair pair, IFiniteClosure fc, Collection<UnifyPair> collection) {
|
||||||
|
Optional<UnifyPair> opt = rules.swap(pair);
|
||||||
|
UnifyPair pair2 = opt.isPresent() ? opt.get() : pair;
|
||||||
|
|
||||||
|
if(rules.erase1(pair2, fc) || rules.erase3(pair2) || rules.erase2(pair2, fc))
|
||||||
|
return;
|
||||||
|
|
||||||
|
collection.add(pair2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits the equation eq into a set eq1s where both terms are type variables,
|
||||||
|
* and a set eq2s where one of both terms is not a type variable.
|
||||||
|
* @param eq Set of pairs to be splitted.
|
||||||
|
* @param eq1s Subset of eq where both terms are type variables.
|
||||||
|
* @param eq2s eq/eq1s.
|
||||||
|
*/
|
||||||
|
protected void splitEq(Set<UnifyPair> eq, Set<UnifyPair> eq1s, Set<UnifyPair> eq2s) {
|
||||||
|
for(UnifyPair pair : eq)
|
||||||
|
if(pair.getLhsType() instanceof PlaceholderType && pair.getRhsType() instanceof PlaceholderType)
|
||||||
|
eq1s.add(pair);
|
||||||
|
else
|
||||||
|
eq2s.add(pair);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates sets of pairs specified in the fourth step. Does not calculate cartesian products.
|
||||||
|
* @param undefined All pairs that did not match one of the 8 cases are added to this set.
|
||||||
|
* @return The set of the eight cases (without empty sets). Each case is a set, containing sets generated
|
||||||
|
* from the pairs that matched the case. Each generated set contains singleton sets or sets with few elements
|
||||||
|
* (as in case 1 where sigma is added to the innermost set).
|
||||||
|
*/
|
||||||
|
protected Set<Set<Set<Set<UnifyPair>>>> calculatePairSets(Set<UnifyPair> eq2s, IFiniteClosure fc, Set<UnifyPair> undefined) {
|
||||||
|
List<Set<Set<Set<UnifyPair>>>> result = new ArrayList<>(8);
|
||||||
|
|
||||||
|
// Init all 8 cases
|
||||||
|
for(int i = 0; i < 8; i++)
|
||||||
|
result.add(new HashSet<>());
|
||||||
|
Boolean first = true;
|
||||||
|
for(UnifyPair pair : eq2s) {
|
||||||
|
PairOperator pairOp = pair.getPairOp();
|
||||||
|
UnifyType lhsType = pair.getLhsType();
|
||||||
|
UnifyType rhsType = pair.getRhsType();
|
||||||
|
|
||||||
|
// Case 1: (a <. Theta')
|
||||||
|
if(pairOp == PairOperator.SMALLERDOT && lhsType instanceof PlaceholderType) {
|
||||||
|
//System.out.println(pair);
|
||||||
|
if (first) { //writeLog(pair.toString()+"\n");
|
||||||
|
Set<Set<UnifyPair>> x1 = unifyCase1((PlaceholderType) pair.getLhsType(), pair.getRhsType(), (byte)1, fc);
|
||||||
|
//System.out.println(x1);
|
||||||
|
result.get(0).add(x1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Set<UnifyPair> s1 = new HashSet<>();
|
||||||
|
s1.add(pair);
|
||||||
|
Set<Set<UnifyPair>> s2 = new HashSet<>();
|
||||||
|
s2.add(s1);
|
||||||
|
result.get(0).add(s2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// Case 2: (a <.? ? ext Theta')
|
||||||
|
else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof ExtendsType)
|
||||||
|
if (first) { //writeLog(pair.toString()+"\n");
|
||||||
|
result.get(1).add(unifyCase2((PlaceholderType) pair.getLhsType(), (ExtendsType) pair.getRhsType(), (byte)0, fc));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Set<UnifyPair> s1 = new HashSet<>();
|
||||||
|
s1.add(pair);
|
||||||
|
Set<Set<UnifyPair>> s2 = new HashSet<>();
|
||||||
|
s2.add(s1);
|
||||||
|
result.get(1).add(s2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Case 3: (a <.? ? sup Theta')
|
||||||
|
else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType && rhsType instanceof SuperType)
|
||||||
|
if (first) { //writeLog(pair.toString()+"\n");
|
||||||
|
result.get(2).add(unifyCase3((PlaceholderType) lhsType, (SuperType) rhsType, (byte)0, fc));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Set<UnifyPair> s1 = new HashSet<>();
|
||||||
|
s1.add(pair);
|
||||||
|
Set<Set<UnifyPair>> s2 = new HashSet<>();
|
||||||
|
s2.add(s1);
|
||||||
|
result.get(2).add(s2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Case 4 was replaced by an inference rule
|
||||||
|
// Case 4: (a <.? Theta')
|
||||||
|
//else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof PlaceholderType)
|
||||||
|
// result.get(3).add(unifyCase4((PlaceholderType) lhsType, rhsType, fc));
|
||||||
|
|
||||||
|
// Case 5: (Theta <. a)
|
||||||
|
else if(pairOp == PairOperator.SMALLERDOT && rhsType instanceof PlaceholderType)
|
||||||
|
if (first) { //writeLog(pair.toString()+"\n");
|
||||||
|
if (rhsType.getName().equals("A"))
|
||||||
|
System.out.println();
|
||||||
|
result.get(4).add(unifyCase5(lhsType, (PlaceholderType) rhsType, (byte)-1, fc));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Set<UnifyPair> s1 = new HashSet<>();
|
||||||
|
s1.add(pair);
|
||||||
|
Set<Set<UnifyPair>> s2 = new HashSet<>();
|
||||||
|
s2.add(s1);
|
||||||
|
result.get(4).add(s2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Case 6 was replaced by an inference rule.
|
||||||
|
// Case 6: (? ext Theta <.? a)
|
||||||
|
//else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof ExtendsType && rhsType instanceof PlaceholderType)
|
||||||
|
// result.get(5).add(unifyCase6((ExtendsType) lhsType, (PlaceholderType) rhsType, fc));
|
||||||
|
|
||||||
|
// Case 7 was replaced by an inference rule
|
||||||
|
// Case 7: (? sup Theta <.? a)
|
||||||
|
//else if(pairOp == PairOperator.SMALLERDOTWC && lhsType instanceof SuperType && rhsType instanceof PlaceholderType)
|
||||||
|
// result.get(6).add(unifyCase7((SuperType) lhsType, (PlaceholderType) rhsType, fc));
|
||||||
|
|
||||||
|
// Case 8: (Theta <.? a)
|
||||||
|
else if(pairOp == PairOperator.SMALLERDOTWC && rhsType instanceof PlaceholderType)
|
||||||
|
if (first) { //writeLog(pair.toString()+"\n");
|
||||||
|
result.get(7).add(
|
||||||
|
unifyCase8(lhsType, (PlaceholderType) rhsType, (byte)0, fc));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Set<UnifyPair> s1 = new HashSet<>();
|
||||||
|
s1.add(pair);
|
||||||
|
Set<Set<UnifyPair>> s2 = new HashSet<>();
|
||||||
|
s2.add(s1);
|
||||||
|
result.get(7).add(s2);
|
||||||
|
}
|
||||||
|
// 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 {
|
||||||
|
// If a pair is not defined, the unificiation will fail, so the loop can be stopped here.
|
||||||
|
undefined.add(pair);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter empty sets or sets that only contain an empty set.
|
||||||
|
return result.stream().map(x -> x.stream().filter(y -> y.size() > 0).collect(Collectors.toCollection(HashSet::new)))
|
||||||
|
.filter(x -> x.size() > 0).collect(Collectors.toCollection(HashSet::new));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cartesian product Case 1: (a <. Theta')
|
||||||
|
*/
|
||||||
|
protected Set<Set<UnifyPair>> unifyCase1(PlaceholderType a, UnifyType thetaPrime, byte variance, IFiniteClosure fc) {
|
||||||
|
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||||
|
|
||||||
|
boolean allGen = thetaPrime.getTypeParams().size() > 0;
|
||||||
|
for(UnifyType t : thetaPrime.getTypeParams())
|
||||||
|
if(!(t instanceof PlaceholderType) || !((PlaceholderType) t).isGenerated()) {
|
||||||
|
allGen = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
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>???]
|
||||||
|
|
||||||
|
//PL 18-02-06 entfernt, kommt durch unify wieder rein
|
||||||
|
//cs.add(thetaPrime);
|
||||||
|
//PL 18-02-06 entfernt
|
||||||
|
|
||||||
|
for(UnifyType c : cs) {
|
||||||
|
//PL 18-02-05 getChildren durch smaller ersetzt in getChildren werden die Varianlen nicht ersetzt.
|
||||||
|
Set<UnifyType> thetaQs = fc.smaller(c).stream().collect(Collectors.toCollection(HashSet::new));
|
||||||
|
//Set<UnifyType> thetaQs = fc.getChildren(c).stream().collect(Collectors.toCollection(HashSet::new));
|
||||||
|
//thetaQs.add(thetaPrime); //PL 18-02-05 wieder geloescht
|
||||||
|
//PL 2017-10-03: War auskommentiert habe ich wieder einkommentiert,
|
||||||
|
//da children offensichtlich ein echtes kleiner und kein kleinergleich ist
|
||||||
|
|
||||||
|
//PL 18-02-06: eingefuegt, thetaQs der Form V<V<...>> <. V'<V<...>> werden entfernt
|
||||||
|
thetaQs = thetaQs.stream().filter(ut -> ut.getTypeParams().arePlaceholders()).collect(Collectors.toCollection(HashSet::new));
|
||||||
|
//PL 18-02-06: eingefuegt
|
||||||
|
|
||||||
|
Set<UnifyType> thetaQPrimes = new HashSet<>();
|
||||||
|
TypeParams cParams = c.getTypeParams();
|
||||||
|
if(cParams.size() == 0)
|
||||||
|
thetaQPrimes.add(c);
|
||||||
|
else {
|
||||||
|
ArrayList<Set<UnifyType>> candidateParams = new ArrayList<>();
|
||||||
|
|
||||||
|
for(UnifyType param : cParams)
|
||||||
|
candidateParams.add(fc.grArg(param));
|
||||||
|
|
||||||
|
for(TypeParams tp : permuteParams(candidateParams))
|
||||||
|
thetaQPrimes.add(c.setTypeParams(tp));
|
||||||
|
}
|
||||||
|
|
||||||
|
for(UnifyType tqp : thetaQPrimes) {
|
||||||
|
//System.out.println(tqp.toString());
|
||||||
|
//i++;
|
||||||
|
//System.out.println(i);
|
||||||
|
//if (i == 62)
|
||||||
|
// System.out.println(tqp.toString());
|
||||||
|
Optional<Unifier> opt = stdUnify.unify(tqp, thetaPrime);
|
||||||
|
if (!opt.isPresent())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Unifier unifier = opt.get();
|
||||||
|
unifier.swapPlaceholderSubstitutions(thetaPrime.getTypeParams());
|
||||||
|
Set<UnifyPair> substitutionSet = new HashSet<>();
|
||||||
|
for (Entry<PlaceholderType, UnifyType> sigma : unifier)
|
||||||
|
substitutionSet.add(new UnifyPair(sigma.getKey(), sigma.getValue(), PairOperator.EQUALSDOT));
|
||||||
|
|
||||||
|
//List<UnifyType> freshTphs = new ArrayList<>(); PL 18-02-06 in die For-Schleife verschoben
|
||||||
|
for (UnifyType tq : thetaQs) {
|
||||||
|
Set<UnifyType> smaller = fc.smaller(unifier.apply(tq));
|
||||||
|
for(UnifyType theta : smaller) {
|
||||||
|
List<UnifyType> freshTphs = new ArrayList<>();
|
||||||
|
Set<UnifyPair> resultPrime = new HashSet<>();
|
||||||
|
|
||||||
|
for(int i = 0; !allGen && i < theta.getTypeParams().size(); i++) {
|
||||||
|
if(freshTphs.size()-1 < i)
|
||||||
|
freshTphs.add(PlaceholderType.freshPlaceholder());
|
||||||
|
resultPrime.add(new UnifyPair(freshTphs.get(i), theta.getTypeParams().get(i), PairOperator.SMALLERDOTWC));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(allGen)
|
||||||
|
resultPrime.add(new UnifyPair(a, theta, PairOperator.EQUALSDOT));
|
||||||
|
else
|
||||||
|
resultPrime.add(new UnifyPair(a, theta.setTypeParams(new TypeParams(freshTphs.toArray(new UnifyType[0]))), PairOperator.EQUALSDOT));
|
||||||
|
resultPrime.addAll(substitutionSet);
|
||||||
|
//writeLog("Substitution: " + substitutionSet.toString());
|
||||||
|
resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new));
|
||||||
|
result.add(resultPrime);
|
||||||
|
//writeLog("Result: " + resultPrime.toString());
|
||||||
|
//writeLog("MAX: " + oup.max(resultPrime.iterator()).toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cartesian Product Case 2: (a <.? ? ext Theta')
|
||||||
|
*/
|
||||||
|
private Set<Set<UnifyPair>> unifyCase2(PlaceholderType a, ExtendsType extThetaPrime, byte variance, IFiniteClosure fc) {
|
||||||
|
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||||
|
|
||||||
|
UnifyType aPrime = PlaceholderType.freshPlaceholder();
|
||||||
|
UnifyType extAPrime = new ExtendsType(aPrime);
|
||||||
|
UnifyType thetaPrime = extThetaPrime.getExtendedType();
|
||||||
|
Set<UnifyPair> resultPrime = new HashSet<>();
|
||||||
|
resultPrime.add(new UnifyPair(a, thetaPrime, PairOperator.SMALLERDOT));
|
||||||
|
result.add(resultPrime);
|
||||||
|
|
||||||
|
resultPrime = new HashSet<>();
|
||||||
|
resultPrime.add(new UnifyPair(a, extAPrime, PairOperator.EQUALSDOT));
|
||||||
|
resultPrime.add(new UnifyPair(aPrime, thetaPrime, PairOperator.SMALLERDOT));
|
||||||
|
resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new));
|
||||||
|
result.add(resultPrime);
|
||||||
|
//writeLog("Result: " + resultPrime.toString());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cartesian Product Case 3: (a <.? ? sup Theta')
|
||||||
|
*/
|
||||||
|
private Set<Set<UnifyPair>> unifyCase3(PlaceholderType a, SuperType subThetaPrime, byte variance, IFiniteClosure fc) {
|
||||||
|
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||||
|
|
||||||
|
UnifyType aPrime = PlaceholderType.freshPlaceholder();
|
||||||
|
UnifyType supAPrime = new SuperType(aPrime);
|
||||||
|
UnifyType thetaPrime = subThetaPrime.getSuperedType();
|
||||||
|
Set<UnifyPair> resultPrime = new HashSet<>();
|
||||||
|
resultPrime.add(new UnifyPair(thetaPrime, a, PairOperator.SMALLERDOT));
|
||||||
|
result.add(resultPrime);
|
||||||
|
//writeLog(resultPrime.toString());
|
||||||
|
|
||||||
|
resultPrime = new HashSet<>();
|
||||||
|
resultPrime.add(new UnifyPair(a, supAPrime, PairOperator.EQUALSDOT));
|
||||||
|
resultPrime.add(new UnifyPair(thetaPrime, aPrime, PairOperator.SMALLERDOT));
|
||||||
|
resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new));
|
||||||
|
result.add(resultPrime);
|
||||||
|
//writeLog(resultPrime.toString());
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cartesian Product Case 5: (Theta <. a)
|
||||||
|
*/
|
||||||
|
private Set<Set<UnifyPair>> unifyCase5(UnifyType theta, PlaceholderType a, byte variance, IFiniteClosure fc) {
|
||||||
|
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||||
|
|
||||||
|
boolean allGen = theta.getTypeParams().size() > 0;
|
||||||
|
for(UnifyType t : theta.getTypeParams())
|
||||||
|
if(!(t instanceof PlaceholderType) || !((PlaceholderType) t).isGenerated()) {
|
||||||
|
allGen = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(UnifyType thetaS : fc.greater(theta)) {
|
||||||
|
Set<UnifyPair> resultPrime = new HashSet<>();
|
||||||
|
|
||||||
|
UnifyType[] freshTphs = new UnifyType[thetaS.getTypeParams().size()];
|
||||||
|
for(int i = 0; !allGen && i < freshTphs.length; i++) {
|
||||||
|
freshTphs[i] = PlaceholderType.freshPlaceholder();
|
||||||
|
resultPrime.add(new UnifyPair(thetaS.getTypeParams().get(i), freshTphs[i], PairOperator.SMALLERDOTWC));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(allGen)
|
||||||
|
resultPrime.add(new UnifyPair(a, thetaS, PairOperator.EQUALSDOT));
|
||||||
|
else
|
||||||
|
resultPrime.add(new UnifyPair(a, thetaS.setTypeParams(new TypeParams(freshTphs)), PairOperator.EQUALSDOT));
|
||||||
|
resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new));
|
||||||
|
result.add(resultPrime);
|
||||||
|
//writeLog(resultPrime.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cartesian Product Case 8: (Theta <.? a)
|
||||||
|
*/
|
||||||
|
private Set<Set<UnifyPair>> unifyCase8(UnifyType theta, PlaceholderType a, byte variance, IFiniteClosure fc) {
|
||||||
|
Set<Set<UnifyPair>> result = new HashSet<>();
|
||||||
|
//for(UnifyType thetaS : fc.grArg(theta)) {
|
||||||
|
Set<UnifyPair> resultPrime = new HashSet<>();
|
||||||
|
resultPrime.add(new UnifyPair(a, theta, PairOperator.EQUALSDOT));
|
||||||
|
result.add(resultPrime);
|
||||||
|
//writeLog(resultPrime.toString());
|
||||||
|
|
||||||
|
UnifyType freshTph = PlaceholderType.freshPlaceholder();
|
||||||
|
resultPrime = new HashSet<>();
|
||||||
|
resultPrime.add(new UnifyPair(a, new ExtendsType(freshTph), PairOperator.EQUALSDOT));
|
||||||
|
resultPrime.add(new UnifyPair(theta, freshTph, PairOperator.SMALLERDOT));
|
||||||
|
result.add(resultPrime);
|
||||||
|
//writeLog(resultPrime.toString());
|
||||||
|
|
||||||
|
resultPrime = new HashSet<>();
|
||||||
|
resultPrime.add(new UnifyPair(a, new SuperType(freshTph), PairOperator.EQUALSDOT));
|
||||||
|
resultPrime.add(new UnifyPair(freshTph, theta, PairOperator.SMALLERDOT));
|
||||||
|
resultPrime = resultPrime.stream().map(x -> { x.setVariance(variance); return x;}).collect(Collectors.toCollection(HashSet::new));
|
||||||
|
result.add(resultPrime);
|
||||||
|
//writeLog(resultPrime.toString());
|
||||||
|
//}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes a set of candidates for each position and computes all possible permutations.
|
||||||
|
* @param candidates The length of the list determines the number of type params. Each set
|
||||||
|
* contains the candidates for the corresponding position.
|
||||||
|
*/
|
||||||
|
protected Set<TypeParams> permuteParams(ArrayList<Set<UnifyType>> candidates) {
|
||||||
|
Set<TypeParams> result = new HashSet<>();
|
||||||
|
permuteParams(candidates, 0, result, new UnifyType[candidates.size()]);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Takes a set of candidates for each position and computes all possible permutations.
|
||||||
|
* @param candidates The length of the list determines the number of type params. Each set
|
||||||
|
* contains the candidates for the corresponding position.
|
||||||
|
* @param idx Idx for the current permutatiton.
|
||||||
|
* @param result Set of all permutations found so far
|
||||||
|
* @param current The permutation of type params that is currently explored
|
||||||
|
*/
|
||||||
|
private void permuteParams(ArrayList<Set<UnifyType>> candidates, int idx, Set<TypeParams> result, UnifyType[] current) {
|
||||||
|
if(candidates.size() == idx) {
|
||||||
|
result.add(new TypeParams(Arrays.copyOf(current, current.length)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<UnifyType> localCandidates = candidates.get(idx);
|
||||||
|
|
||||||
|
for(UnifyType t : localCandidates) {
|
||||||
|
current[idx] = t;
|
||||||
|
permuteParams(candidates, idx+1, result, current);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeLog(String str) {
|
||||||
|
try {
|
||||||
|
logFile.write(str+"\n");
|
||||||
|
logFile.flush();
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (IOException e) { }
|
||||||
|
}
|
||||||
|
}
|
117
src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java
Normal file
117
src/de/dhbwstuttgart/typeinference/unify/model/UnifyPair.java
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
package de.dhbwstuttgart.typeinference.unify.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A pair which contains two types and an operator, e.q. (Integer <. a).
|
||||||
|
* @author Florian Steurer
|
||||||
|
*/
|
||||||
|
public class UnifyPair {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type on the left hand side of the pair.
|
||||||
|
*/
|
||||||
|
private final UnifyType lhs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type on the right hand side of the pair.
|
||||||
|
*/
|
||||||
|
private final UnifyType rhs;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The operator that determines the relation between the left and right hand side type.
|
||||||
|
*/
|
||||||
|
private PairOperator pairOp;
|
||||||
|
|
||||||
|
private byte variance = 0;
|
||||||
|
|
||||||
|
private boolean undefinedPair = false;
|
||||||
|
|
||||||
|
private final int hashCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance of the pair.
|
||||||
|
* @param lhs The type on the left hand side of the pair.
|
||||||
|
* @param rhs The type on the right hand side of the pair.
|
||||||
|
* @param op The operator that determines the relation between the left and right hand side type.
|
||||||
|
*/
|
||||||
|
public UnifyPair(UnifyType lhs, UnifyType rhs, PairOperator op) {
|
||||||
|
this.lhs = lhs;
|
||||||
|
this.rhs = rhs;
|
||||||
|
pairOp = op;
|
||||||
|
|
||||||
|
// Caching hashcode
|
||||||
|
hashCode = 17 + 31 * lhs.hashCode() + 31 * rhs.hashCode() + 31 * pairOp.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the type on the left hand side of the pair.
|
||||||
|
*/
|
||||||
|
public UnifyType getLhsType() {
|
||||||
|
return lhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the type on the right hand side of the pair.
|
||||||
|
*/
|
||||||
|
public UnifyType getRhsType() {
|
||||||
|
return rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the operator that determines the relation between the left and right hand side type.
|
||||||
|
*/
|
||||||
|
public PairOperator getPairOp() {
|
||||||
|
return pairOp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte getVariance() {
|
||||||
|
return variance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVariance(byte v) {
|
||||||
|
variance = v;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUndefinedPair() {
|
||||||
|
return undefinedPair;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if(!(obj instanceof UnifyPair))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(obj.hashCode() != this.hashCode())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
UnifyPair other = (UnifyPair) obj;
|
||||||
|
|
||||||
|
return other.getPairOp() == pairOp
|
||||||
|
&& other.getLhsType().equals(lhs)
|
||||||
|
&& other.getRhsType().equals(rhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return hashCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "(" + lhs + " " + pairOp + " " + rhs + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
public List<? extends PlaceholderType> getInvolvedPlaceholderTypes() {
|
||||||
|
ArrayList<PlaceholderType> ret = new ArrayList<>();
|
||||||
|
ret.addAll(lhs.getInvolvedPlaceholderTypes());
|
||||||
|
ret.addAll(rhs.getInvolvedPlaceholderTypes());
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@@ -1,22 +1,25 @@
|
|||||||
package de.dhbwstuttgart.bytecode;
|
package de.dhbwstuttgart.bytecode;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||||
import org.objectweb.asm.ClassWriter;
|
import org.objectweb.asm.ClassWriter;
|
||||||
import org.objectweb.asm.FieldVisitor;
|
import org.objectweb.asm.FieldVisitor;
|
||||||
import org.objectweb.asm.MethodVisitor;
|
import org.objectweb.asm.MethodVisitor;
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
import org.objectweb.asm.Type;
|
import org.objectweb.asm.Type;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.Exception.BytecodeGeneratorError;
|
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
||||||
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
|
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
|
||||||
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
||||||
import de.dhbwstuttgart.bytecode.signature.Signature;
|
import de.dhbwstuttgart.bytecode.signature.Signature;
|
||||||
@@ -26,47 +29,9 @@ import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
|||||||
import de.dhbwstuttgart.bytecode.utilities.NormalConstructor;
|
import de.dhbwstuttgart.bytecode.utilities.NormalConstructor;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.NormalMethod;
|
import de.dhbwstuttgart.bytecode.utilities.NormalMethod;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.Simplify;
|
import de.dhbwstuttgart.bytecode.utilities.Simplify;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.SimplifyResult;
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
|
||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||||
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
import de.dhbwstuttgart.syntaxtree.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.Field;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.ArgumentList;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Assign;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.AssignToField;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.BinaryExpr;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Block;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.CastExpr;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.DoStmt;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.EmptyStmt;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.ExpressionReceiver;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.FieldVar;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.ForStmt;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.IfStmt;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.InstanceOf;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Literal;
|
import de.dhbwstuttgart.syntaxtree.statement.Literal;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.NewArray;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.NewClass;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Return;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.ReturnVoid;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.StaticClassName;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Super;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.SuperCall;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.This;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.UnaryExpr;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.WhileStmt;
|
|
||||||
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;
|
||||||
@@ -74,6 +39,8 @@ import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
|||||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResolvedType;
|
||||||
|
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
public class BytecodeGen implements ASTVisitor {
|
public class BytecodeGen implements ASTVisitor {
|
||||||
@@ -85,7 +52,7 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
public static RefTypeOrTPHOrWildcardOrGeneric THISTYPE = null;
|
public static RefTypeOrTPHOrWildcardOrGeneric THISTYPE = null;
|
||||||
String className;
|
String className;
|
||||||
private boolean isInterface;
|
private boolean isInterface;
|
||||||
private Collection<ResultSet> listOfResultSets;
|
private List<ResultSet> listOfResultSets;
|
||||||
private ResultSet resultSet;
|
private ResultSet resultSet;
|
||||||
private SourceFile sf;
|
private SourceFile sf;
|
||||||
private String path;
|
private String path;
|
||||||
@@ -96,10 +63,9 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
|
|
||||||
private String superClass;
|
private String superClass;
|
||||||
|
|
||||||
private ArrayList<String> tphsClass;
|
private ArrayList<TypePlaceholder> tphsClass;
|
||||||
|
|
||||||
// stores parameter, local vars and the next index on the local variable table,
|
// stores parameter, local vars and the next index on the local variable table, which use for aload_i, astore_i,...
|
||||||
// which use for aload_i, astore_i,...
|
|
||||||
HashMap<String, Integer> paramsAndLocals = new HashMap<>();
|
HashMap<String, Integer> paramsAndLocals = new HashMap<>();
|
||||||
// stores generics and their bounds of class
|
// stores generics and their bounds of class
|
||||||
HashMap<String, String> genericsAndBounds = new HashMap<>();
|
HashMap<String, String> genericsAndBounds = new HashMap<>();
|
||||||
@@ -113,24 +79,9 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
byte[] bytecode;
|
byte[] bytecode;
|
||||||
HashMap<String,byte[]> classFiles;
|
HashMap<String,byte[]> classFiles;
|
||||||
|
|
||||||
private final ArrayList<String> methodNameAndParamsT = new ArrayList<>();
|
ArrayList<String> methodNameAndParamsT = new ArrayList<>();
|
||||||
private final ArrayList<String> fieldNameAndParamsT = new ArrayList<>();
|
|
||||||
|
|
||||||
private HashMap<String, SimplifyResult> simplifyResults = new HashMap<>();
|
public BytecodeGen(HashMap<String,byte[]> classFiles, List<ResultSet> listOfResultSets,SourceFile sf ,String path) {
|
||||||
private List<HashMap<String, SimplifyResult>> simplifyResultsList = new ArrayList<>();
|
|
||||||
|
|
||||||
private final ArrayList<String> fieldNameSignature = new ArrayList<>();
|
|
||||||
|
|
||||||
public List<HashMap<String, SimplifyResult>> getSimplifyResultsList() {
|
|
||||||
return simplifyResultsList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSimplifyResultsList(List<HashMap<String, SimplifyResult>> simplifyResultsList) {
|
|
||||||
this.simplifyResultsList = simplifyResultsList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public BytecodeGen(HashMap<String, byte[]> classFiles, Collection<ResultSet> listOfResultSets, SourceFile sf,
|
|
||||||
String path) {
|
|
||||||
this.classFiles = classFiles;
|
this.classFiles = classFiles;
|
||||||
this.listOfResultSets = listOfResultSets;
|
this.listOfResultSets = listOfResultSets;
|
||||||
this.sf = sf;
|
this.sf = sf;
|
||||||
@@ -143,14 +94,13 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
System.out.println("in Class: " + cl.getClassName().toString());
|
System.out.println("in Class: " + cl.getClassName().toString());
|
||||||
BytecodeGen classGen = new BytecodeGen(classFiles, listOfResultSets, sf, path);
|
BytecodeGen classGen = new BytecodeGen(classFiles, listOfResultSets, sf, path);
|
||||||
cl.accept(classGen);
|
cl.accept(classGen);
|
||||||
simplifyResultsList.add(classGen.getSimplifyResults());
|
|
||||||
classGen.writeClass(cl.getClassName().toString());
|
classGen.writeClass(cl.getClassName().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Associates the bytecode of the class that was build with the classWriter
|
* Associates the bytecode of the class that was build with the classWriter {@link #cw}
|
||||||
* {@link #cw} with the class name in the map {@link #classFiles}
|
* with the class name in the map {@link #classFiles}
|
||||||
*
|
*
|
||||||
* @param name name of the class with which the the bytecode is to be associated
|
* @param name name of the class with which the the bytecode is to be associated
|
||||||
*/
|
*/
|
||||||
@@ -164,6 +114,7 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
return classFiles;
|
return classFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(ClassOrInterface classOrInterface) {
|
public void visit(ClassOrInterface classOrInterface) {
|
||||||
|
|
||||||
@@ -173,19 +124,16 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
|
|
||||||
isInterface = (classOrInterface.getModifiers()&512)==512;
|
isInterface = (classOrInterface.getModifiers()&512)==512;
|
||||||
|
|
||||||
int acc = isInterface ? classOrInterface.getModifiers() + Opcodes.ACC_ABSTRACT
|
int acc = isInterface?classOrInterface.getModifiers()+Opcodes.ACC_ABSTRACT:classOrInterface.getModifiers()+Opcodes.ACC_SUPER;
|
||||||
: classOrInterface.getModifiers() + Opcodes.ACC_SUPER;
|
|
||||||
|
|
||||||
fieldInitializations = classOrInterface.getfieldInitializations();
|
fieldInitializations = classOrInterface.getfieldInitializations();
|
||||||
|
|
||||||
// resultSet = listOfResultSets.get(0);
|
// resultSet = listOfResultSets.get(0);
|
||||||
boolean isConsWithNoParamsVisited = false;
|
boolean isConsWithNoParamsVisited = false;
|
||||||
boolean isVisited = false;
|
boolean isVisited = false;
|
||||||
List<ResultSet> listOfResultSetsList = new ArrayList<>(listOfResultSets);
|
for(ResultSet rs : listOfResultSets) {
|
||||||
for (int i = 0; i < listOfResultSetsList.size(); i++) {
|
|
||||||
//for (ResultSet rs : listOfResultSets) {
|
|
||||||
superClass = classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor());
|
superClass = classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor());
|
||||||
resultSet = listOfResultSetsList.get(i);
|
resultSet = rs;
|
||||||
tphExtractor.setResultSet(resultSet);
|
tphExtractor.setResultSet(resultSet);
|
||||||
|
|
||||||
// Nur einmal ausführen!!
|
// Nur einmal ausführen!!
|
||||||
@@ -195,62 +143,43 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
getCommonTPHS(tphExtractor);
|
getCommonTPHS(tphExtractor);
|
||||||
|
|
||||||
tphsClass = new ArrayList<>();
|
tphsClass = new ArrayList<>();
|
||||||
for (String t : tphExtractor.allTPHS.keySet()) {
|
for(TypePlaceholder t : tphExtractor.allTPHS.keySet()) {
|
||||||
if(!tphExtractor.allTPHS.get(t))
|
if(!tphExtractor.allTPHS.get(t))
|
||||||
tphsClass.add(t);
|
tphsClass.add(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
String sig = null;
|
String sig = null;
|
||||||
/*
|
/* if class has generics then creates signature
|
||||||
* if class has generics then creates signature Signature looks like:
|
* Signature looks like:
|
||||||
* <E:Ljava/...>Superclass
|
* <E:Ljava/...>Superclass
|
||||||
*/
|
*/
|
||||||
if (classOrInterface.getGenerics().iterator().hasNext() || !commonPairs.isEmpty()
|
if(classOrInterface.getGenerics().iterator().hasNext() || !commonPairs.isEmpty() ||
|
||||||
|| classOrInterface.getSuperClass().acceptTV(new TypeToSignature()).contains("<")
|
classOrInterface.getSuperClass().acceptTV(new TypeToSignature()).contains("<")
|
||||||
|| !tphsClass.isEmpty()) {
|
|| !tphsClass.isEmpty()) {
|
||||||
HashMap<TPHConstraint, HashSet<String>> constraints = Simplify
|
HashMap<TPHConstraint, HashSet<String>> constraints = Simplify.simplifyConstraintsClass(tphExtractor,tphsClass);
|
||||||
.simplifyConstraintsClass(tphExtractor, tphsClass);
|
|
||||||
ArrayList<TPHConstraint> consClass = new ArrayList<>();
|
ArrayList<TPHConstraint> consClass = new ArrayList<>();
|
||||||
for(TPHConstraint cons : constraints.keySet()) {
|
for(TPHConstraint cons : constraints.keySet()) {
|
||||||
String right = null;
|
TypePlaceholder right = null;
|
||||||
boolean isToAdd = false;
|
for(TypePlaceholder tph : tphsClass) {
|
||||||
for (String tph : tphsClass) {
|
if(cons.getLeft().equals(tph.getName())) {
|
||||||
if (cons.getLeft().equals(tph)) {
|
|
||||||
|
|
||||||
consClass.add(cons);
|
consClass.add(cons);
|
||||||
try {
|
|
||||||
right = getTPH(cons.getRight());
|
right = getTPH(cons.getRight());
|
||||||
isToAdd = true;
|
|
||||||
} catch (NoSuchElementException e) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (isToAdd) {
|
if(right != null) {
|
||||||
tphsClass.add(right);
|
tphsClass.add(right);
|
||||||
removeFromMethod(right);
|
removeFromMethod(right.getName());
|
||||||
right = null;
|
right = null;
|
||||||
isToAdd = false;
|
|
||||||
}
|
}
|
||||||
// if(right != null) {
|
|
||||||
// tphsClass.add(right);
|
|
||||||
// removeFromMethod(right);
|
|
||||||
// right = null;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
Signature signature = new Signature(classOrInterface, genericsAndBounds,commonPairs,tphsClass, consClass);
|
||||||
SimplifyResult sRes = new SimplifyResult(consClass, tphsClass, new HashMap<>());
|
|
||||||
simplifyResults.put(className, sRes);
|
|
||||||
|
|
||||||
Signature signature = new Signature(classOrInterface, genericsAndBounds, commonPairs, tphsClass,
|
|
||||||
consClass);
|
|
||||||
sig = signature.toString();
|
sig = signature.toString();
|
||||||
System.out.println("Signature: => " + sig);
|
System.out.println("Signature: => " + sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
cw.visit(Opcodes.V1_8, acc, classOrInterface.getClassName().toString(), sig,
|
cw.visit(Opcodes.V1_8, acc, classOrInterface.getClassName().toString()
|
||||||
classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor()), null);
|
, sig, classOrInterface.getSuperClass().acceptTV(new TypeToDescriptor()), null);
|
||||||
|
|
||||||
isVisited = true;
|
isVisited = true;
|
||||||
}
|
}
|
||||||
@@ -293,9 +222,9 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getTPH(String name) {
|
private TypePlaceholder getTPH(String name) {
|
||||||
for (String tph : tphExtractor.allTPHS.keySet()) {
|
for(TypePlaceholder tph: tphExtractor.allTPHS.keySet()) {
|
||||||
if (tph.equals(name))
|
if(tph.getName().equals(name))
|
||||||
return tph;
|
return tph;
|
||||||
}
|
}
|
||||||
throw new NoSuchElementException("TPH "+name +" does not exist");
|
throw new NoSuchElementException("TPH "+name +" does not exist");
|
||||||
@@ -303,9 +232,9 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
|
|
||||||
private void getCommonTPHS(TPHExtractor tphExtractor) {
|
private void getCommonTPHS(TPHExtractor tphExtractor) {
|
||||||
// Gemeinsame TPHs
|
// Gemeinsame TPHs
|
||||||
ArrayList<String> cTPHs = new ArrayList<>();
|
ArrayList<TypePlaceholder> cTPHs = new ArrayList<>();
|
||||||
// Alle TPHs der Felder speichern
|
// Alle TPHs der Felder speichern
|
||||||
for (String tph : tphExtractor.allTPHS.keySet()) {
|
for(TypePlaceholder tph : tphExtractor.allTPHS.keySet()) {
|
||||||
if(!tphExtractor.allTPHS.get(tph))
|
if(!tphExtractor.allTPHS.get(tph))
|
||||||
cTPHs.add(tph);
|
cTPHs.add(tph);
|
||||||
}
|
}
|
||||||
@@ -346,15 +275,15 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
for(String paramName : methodParamsAndTypes.keySet()) {
|
for(String paramName : methodParamsAndTypes.keySet()) {
|
||||||
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToSignature());
|
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToSignature());
|
||||||
System.out.println(typeOfParam);
|
System.out.println(typeOfParam);
|
||||||
if (genericsAndBounds.containsKey(typeOfParam) || typeOfParam.contains("$") || typeOfParam.contains("<")) {
|
if(genericsAndBounds.containsKey(typeOfParam) ||typeOfParam.contains("$")
|
||||||
|
|| typeOfParam.contains("<")) {
|
||||||
hasGen = true;
|
hasGen = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String sig = null;
|
String sig = null;
|
||||||
if(hasGen) {
|
if(hasGen) {
|
||||||
HashMap<TPHConstraint, HashSet<String>> constraints = Simplify.simplifyConstraints(field.name, tphExtractor,
|
HashMap<TPHConstraint, HashSet<String>> constraints = Simplify.simplifyConstraints(field.name, tphExtractor,tphsClass);
|
||||||
tphsClass);
|
|
||||||
Signature signature = new Signature(field, genericsAndBounds,methodParamsAndTypes,resultSet,constraints);
|
Signature signature = new Signature(field, genericsAndBounds,methodParamsAndTypes,resultSet,constraints);
|
||||||
sig = signature.toString();
|
sig = signature.toString();
|
||||||
}
|
}
|
||||||
@@ -373,8 +302,7 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
|
|
||||||
BytecodeGenMethod gen = new BytecodeGenMethod(className,superClass,resultSet,field, mv,paramsAndLocals,cw,
|
BytecodeGenMethod gen = new BytecodeGenMethod(className,superClass,resultSet,field, mv,paramsAndLocals,cw,
|
||||||
genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles, sf,path, block, constructorPos);
|
genericsAndBoundsMethod,genericsAndBounds,isInterface,classFiles, sf,path, block, constructorPos);
|
||||||
if (!field.getParameterList().iterator().hasNext()
|
if(!field.getParameterList().iterator().hasNext() && !(field.block.statements.get(field.block.statements.size()-1) instanceof ReturnVoid)) {
|
||||||
&& !(field.block.statements.get(field.block.statements.size() - 1) instanceof ReturnVoid)) {
|
|
||||||
mv.visitInsn(Opcodes.RETURN);
|
mv.visitInsn(Opcodes.RETURN);
|
||||||
}
|
}
|
||||||
mv.visitMaxs(0, 0);
|
mv.visitMaxs(0, 0);
|
||||||
@@ -383,8 +311,7 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(Method method) {
|
public void visit(Method method) {
|
||||||
// TODO: check if the method is static => if static then the first param will be
|
// TODO: check if the method is static => if static then the first param will be stored in pos 0
|
||||||
// stored in pos 0
|
|
||||||
// else it will be stored in pos 1 and this will be stored in pos 0
|
// else it will be stored in pos 1 and this will be stored in pos 0
|
||||||
String retType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String retType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
// String retType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature());
|
// String retType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature());
|
||||||
@@ -412,54 +339,37 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
System.out.println(acc);
|
System.out.println(acc);
|
||||||
|
|
||||||
/*Prüfe, ob die Rückgabe-Type der Methode eine Type-Variable ist*/
|
/*Prüfe, ob die Rückgabe-Type der Methode eine Type-Variable ist*/
|
||||||
boolean hasGenInParameterList = genericsAndBounds.containsKey(retType) || retType.contains("TPH ")
|
boolean hasGenInParameterList = genericsAndBounds.containsKey(retType) || retType.subSequence(0, 4).equals("TPH ") ||
|
||||||
|| resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature())
|
resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature()).contains("<");
|
||||||
.contains("<");
|
/*Wenn die Rückgabe-Type eine Typ-variable ist, erzeuge direkt die Signature, wenn nicht,
|
||||||
/*
|
* prüfe, ob einer der Parameter Typ-Variable als Typ hat*/
|
||||||
* Wenn die Rückgabe-Type eine Typ-variable ist, erzeuge direkt die Signature,
|
|
||||||
* wenn nicht, prüfe, ob einer der Parameter Typ-Variable als Typ hat
|
|
||||||
*/
|
|
||||||
if(!hasGenInParameterList) {
|
if(!hasGenInParameterList) {
|
||||||
for(String paramName : methodParamsAndTypes.keySet()) {
|
for(String paramName : methodParamsAndTypes.keySet()) {
|
||||||
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToDescriptor());
|
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToDescriptor());
|
||||||
String sigOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToSignature());
|
String sigOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToSignature());
|
||||||
if (genericsAndBounds.containsKey(typeOfParam) || typeOfParam.contains("TPH ")
|
if(genericsAndBounds.containsKey(typeOfParam)||typeOfParam.substring(0, 4).equals("TPH ")||sigOfParam.contains("<")) {
|
||||||
|| sigOfParam.contains("<")) {
|
|
||||||
hasGenInParameterList = true;
|
hasGenInParameterList = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: Test if the return-type or any of the parameter is a parameterized
|
//TODO: Test if the return-type or any of the parameter is a parameterized type. (VP)
|
||||||
// type. (VP)
|
|
||||||
//then create the descriptor with the new syntax.
|
//then create the descriptor with the new syntax.
|
||||||
|
|
||||||
String sig = null;
|
String sig = null;
|
||||||
/*
|
/* method.getGenerics: <....> RT method(..)
|
||||||
* method.getGenerics: <....> RT method(..)
|
* */
|
||||||
*/
|
|
||||||
boolean hasGen = method.getGenerics().iterator().hasNext() || hasGenInParameterList;
|
boolean hasGen = method.getGenerics().iterator().hasNext() || hasGenInParameterList;
|
||||||
/* if method has generics or return type is TPH, create signature */
|
/* if method has generics or return type is TPH, create signature */
|
||||||
// zwite operand muss weggelassen werden
|
// zwite operand muss weggelassen werden
|
||||||
if (hasGen || resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToString())
|
if(hasGen||resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToString()).equals("TPH")) {
|
||||||
.equals("TPH")) {
|
|
||||||
System.out.println("ALL CONST: " + tphExtractor.allCons.size());
|
System.out.println("ALL CONST: " + tphExtractor.allCons.size());
|
||||||
tphExtractor.allCons.forEach(c->System.out.println(c.toString()));
|
tphExtractor.allCons.forEach(c->System.out.println(c.toString()));
|
||||||
System.out.println("----------------");
|
System.out.println("----------------");
|
||||||
HashMap<TPHConstraint, HashSet<String>> constraints = Simplify.simplifyConstraints(method.name,
|
HashMap<TPHConstraint, HashSet<String>> constraints = Simplify.simplifyConstraints(method.name, tphExtractor, tphsClass);
|
||||||
tphExtractor, tphsClass);
|
|
||||||
// ArrayList<GenericInsertPair> pairs = simplifyPairs(method.name,tphExtractor.allPairs,tphExtractor.allCons);
|
// ArrayList<GenericInsertPair> pairs = simplifyPairs(method.name,tphExtractor.allPairs,tphExtractor.allCons);
|
||||||
Signature signature = new Signature(method, genericsAndBoundsMethod, genericsAndBounds,
|
Signature signature = new Signature(method, genericsAndBoundsMethod, genericsAndBounds,methodParamsAndTypes,resultSet,constraints);
|
||||||
methodParamsAndTypes, resultSet, constraints);
|
|
||||||
sig = signature.toString();
|
sig = signature.toString();
|
||||||
if (simplifyResults.containsKey(className)) {
|
|
||||||
simplifyResults.get(className).getMethodsConstraints().put(methParamTypes, constraints);
|
|
||||||
} else {
|
|
||||||
SimplifyResult sRes = new SimplifyResult(new ArrayList<>(), new ArrayList<>(), new HashMap<>());
|
|
||||||
sRes.getMethodsConstraints().put(methParamTypes, constraints);
|
|
||||||
simplifyResults.put(className, sRes);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
System.out.println(method.getName()+" ==> "+sig);
|
System.out.println(method.getName()+" ==> "+sig);
|
||||||
NormalMethod meth = new NormalMethod(method,genericsAndBounds,genericsAndBoundsMethod,hasGen);
|
NormalMethod meth = new NormalMethod(method,genericsAndBounds,genericsAndBoundsMethod,hasGen);
|
||||||
@@ -476,10 +386,6 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
mv.visitEnd();
|
mv.visitEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<String, SimplifyResult> getSimplifyResults() {
|
|
||||||
return simplifyResults;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(ParameterList formalParameters) {
|
public void visit(ParameterList formalParameters) {
|
||||||
paramsAndLocals = new HashMap<>();
|
paramsAndLocals = new HashMap<>();
|
||||||
@@ -534,8 +440,7 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
public void visit(FieldVar fieldVar) {
|
public void visit(FieldVar fieldVar) {
|
||||||
System.out.println("In FieldVar ---");
|
System.out.println("In FieldVar ---");
|
||||||
// cw.newField(fieldVar.receiver.toString(), fieldVar.fieldVarName.toString(), fieldVar.getType().toString());
|
// cw.newField(fieldVar.receiver.toString(), fieldVar.fieldVarName.toString(), fieldVar.getType().toString());
|
||||||
FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE, fieldVar.fieldVarName, "L" + fieldVar.getType() + ";",
|
FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE, fieldVar.fieldVarName, "L"+fieldVar.getType()+";", null, null);
|
||||||
null, null);
|
|
||||||
fv.visitEnd();
|
fv.visitEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -555,18 +460,9 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
if(sig.charAt(sig.length()-1) != (";").charAt(0)) {
|
if(sig.charAt(sig.length()-1) != (";").charAt(0)) {
|
||||||
sig +=";";
|
sig +=";";
|
||||||
}
|
}
|
||||||
String nameAndDesc = field.getName() + "%%" + des;
|
cw.visitField(field.modifier, field.getName(),
|
||||||
String nameAndSig = field.getName() + "%%" + sig;
|
des, sig,
|
||||||
if (fieldNameAndParamsT.contains(nameAndDesc)) {
|
null);
|
||||||
if (fieldNameSignature.contains(nameAndSig)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
throw new BytecodeGeneratorError("Bytecode generation aborted due to duplicate field name&signature");
|
|
||||||
}
|
|
||||||
fieldNameAndParamsT.add(nameAndDesc);
|
|
||||||
fieldNameSignature.add(nameAndSig);
|
|
||||||
|
|
||||||
cw.visitField(field.modifier, field.getName(), des, sig, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -747,4 +643,5 @@ public class BytecodeGen implements ASTVisitor {
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -33,14 +33,12 @@ import org.objectweb.asm.Type;
|
|||||||
import org.objectweb.asm.signature.SignatureVisitor;
|
import org.objectweb.asm.signature.SignatureVisitor;
|
||||||
import org.objectweb.asm.signature.SignatureWriter;
|
import org.objectweb.asm.signature.SignatureWriter;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.Exception.NotInCurrentPackageException;
|
|
||||||
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
|
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
|
||||||
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
||||||
import de.dhbwstuttgart.bytecode.signature.Signature;
|
import de.dhbwstuttgart.bytecode.signature.Signature;
|
||||||
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
|
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.KindOfLambda;
|
import de.dhbwstuttgart.bytecode.utilities.KindOfLambda;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.Lambda;
|
import de.dhbwstuttgart.bytecode.utilities.Lambda;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.MethodCallHelper;
|
|
||||||
import de.dhbwstuttgart.bytecode.utilities.MethodFromMethodCall;
|
import de.dhbwstuttgart.bytecode.utilities.MethodFromMethodCall;
|
||||||
import de.dhbwstuttgart.bytecode.utilities.SamMethod;
|
import de.dhbwstuttgart.bytecode.utilities.SamMethod;
|
||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.AssignToLocal;
|
||||||
@@ -54,7 +52,6 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
|
|||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
import javassist.NotFoundException;
|
|
||||||
|
|
||||||
public class BytecodeGenMethod implements StatementVisitor {
|
public class BytecodeGenMethod implements StatementVisitor {
|
||||||
|
|
||||||
@@ -143,8 +140,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public BytecodeGenMethod(LambdaExpression lambdaExpression, ArrayList<String> usedVars, ResultSet resultSet, MethodVisitor mv,
|
public BytecodeGenMethod(LambdaExpression lambdaExpression, ArrayList<String> usedVars, ResultSet resultSet, MethodVisitor mv,
|
||||||
int indexOfFirstParamLam, boolean isInterface, HashMap<String, byte[]> classFiles, String path, int lamCounter, SourceFile sf,HashMap<String, String> genericsAndBoundsMethod,
|
int indexOfFirstParamLam, boolean isInterface, HashMap<String, byte[]> classFiles, String path, int lamCounter, SourceFile sf) {
|
||||||
HashMap<String, String> genericsAndBounds) {
|
|
||||||
|
|
||||||
this.resultSet = resultSet;
|
this.resultSet = resultSet;
|
||||||
this.mv = mv;
|
this.mv = mv;
|
||||||
@@ -153,9 +149,6 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
this.path = path;
|
this.path = path;
|
||||||
this.lamCounter = lamCounter;
|
this.lamCounter = lamCounter;
|
||||||
this.sf = sf;
|
this.sf = sf;
|
||||||
this.genericsAndBoundsMethod = genericsAndBoundsMethod;
|
|
||||||
this.genericsAndBounds = genericsAndBounds;
|
|
||||||
|
|
||||||
Iterator<FormalParameter> itr = lambdaExpression.params.iterator();
|
Iterator<FormalParameter> itr = lambdaExpression.params.iterator();
|
||||||
int i = indexOfFirstParamLam;
|
int i = indexOfFirstParamLam;
|
||||||
|
|
||||||
@@ -651,8 +644,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
ArrayList<String> usedVars = kindOfLambda.getUsedVars();
|
ArrayList<String> usedVars = kindOfLambda.getUsedVars();
|
||||||
|
|
||||||
new BytecodeGenMethod(lambdaExpression, usedVars,this.resultSet, mvLambdaBody, indexOfFirstParamLam, isInterface,
|
new BytecodeGenMethod(lambdaExpression, usedVars,this.resultSet, mvLambdaBody, indexOfFirstParamLam, isInterface,
|
||||||
classFiles,this.path, lamCounter, sf, genericsAndBoundsMethod,
|
classFiles,this.path, lamCounter, sf);
|
||||||
genericsAndBounds);
|
|
||||||
|
|
||||||
mvLambdaBody.visitMaxs(0, 0);
|
mvLambdaBody.visitMaxs(0, 0);
|
||||||
mvLambdaBody.visitEnd();
|
mvLambdaBody.visitEnd();
|
||||||
@@ -678,7 +670,7 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
}
|
}
|
||||||
methSig.visitReturnType().visitTypeVariable("R");
|
methSig.visitReturnType().visitTypeVariable("R");
|
||||||
// ")"+lam.getReturn.getBounds
|
// ")"+lam.getReturn.getBounds
|
||||||
Signature sig = new Signature(numberOfParams);
|
Signature sig = new Signature(lambdaExpression, numberOfParams);
|
||||||
String name = "Fun" + numberOfParams + "$$";
|
String name = "Fun" + numberOfParams + "$$";
|
||||||
classWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC+Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT, name, sig.toString(),
|
classWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC+Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT, name, sig.toString(),
|
||||||
Type.getInternalName(Object.class), null);
|
Type.getInternalName(Object.class), null);
|
||||||
@@ -752,13 +744,6 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
statement = new IfStatement(ifStmt.expr, ifStmt.then_block, ifStmt.else_block);
|
statement = new IfStatement(ifStmt.expr, ifStmt.then_block, ifStmt.else_block);
|
||||||
isBinaryExp = statement.isExprBinary();
|
isBinaryExp = statement.isExprBinary();
|
||||||
ifStmt.expr.accept(this);
|
ifStmt.expr.accept(this);
|
||||||
if(!(ifStmt.expr instanceof BinaryExpr)) {
|
|
||||||
doUnboxing(getResolvedType(ifStmt.expr.getType()));
|
|
||||||
Label branchLabel = new Label();
|
|
||||||
Label endLabel = new Label();
|
|
||||||
mv.visitJumpInsn(Opcodes.IFEQ, branchLabel);
|
|
||||||
statement.genBCForRelOp(mv, branchLabel, endLabel, this);
|
|
||||||
}
|
|
||||||
statement = null;
|
statement = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -773,19 +758,11 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
System.out.println("In MethodCall = " + methodCall.name);
|
System.out.println("In MethodCall = " + methodCall.name);
|
||||||
String receiverName = getResolvedType(methodCall.receiver.getType());
|
String receiverName = getResolvedType(methodCall.receiver.getType());
|
||||||
System.out.println("Methods of " + receiverName + " ");
|
System.out.println("Methods of " + receiverName + " ");
|
||||||
java.lang.reflect.Method methodRefl = null;
|
|
||||||
String clazz = receiverName.replace("/", ".");
|
|
||||||
|
|
||||||
String mDesc = "";
|
|
||||||
|
|
||||||
MethodCallHelper helper = new MethodCallHelper(methodCall, sf, resultSet, path);
|
|
||||||
|
|
||||||
boolean toCreate = false;
|
|
||||||
|
|
||||||
ClassLoader cLoader = ClassLoader.getSystemClassLoader();
|
ClassLoader cLoader = ClassLoader.getSystemClassLoader();
|
||||||
// This will be used if the class is not standard class (not in API)
|
// This will be used if the class is not standard class (not in API)
|
||||||
ClassLoader cLoader2;
|
ClassLoader cLoader2;
|
||||||
|
java.lang.reflect.Method methodRefl = null;
|
||||||
|
String clazz = receiverName.replace("/", ".");
|
||||||
String methCallType = resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String methCallType = resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
String[] typesOfParams = getTypes(methodCall.arglist.getArguments());
|
String[] typesOfParams = getTypes(methodCall.arglist.getArguments());
|
||||||
try {
|
try {
|
||||||
@@ -798,10 +775,28 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
methodRefl = getMethod(methodCall.name,methodCall.arglist.getArguments().size(),methods);
|
methodRefl = getMethod(methodCall.name,methodCall.arglist.getArguments().size(),methods);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
// try {
|
||||||
|
// cLoader2 = new URLClassLoader(new URL[] {new URL("file://"+path)});
|
||||||
|
// java.lang.reflect.Method[] methods = cLoader2.loadClass(clazz).getMethods();
|
||||||
|
// System.out.println("Methods of " + receiverName + " ");
|
||||||
|
// for(int i = 0; i<methods.length; i++) {
|
||||||
|
// System.out.println(methods[i]);
|
||||||
|
// }
|
||||||
|
// methodRefl = getMethod(methodCall.name,methodCall.arglist.getArguments().size(),methCallType, typesOfParams,methods);
|
||||||
|
// }catch (Exception e2) {
|
||||||
String superClass = "";
|
String superClass = "";
|
||||||
|
// TODO: Test SubMatrix.jav
|
||||||
while(true) {
|
while(true) {
|
||||||
try {
|
for(ClassOrInterface cl : sf.getClasses()) {
|
||||||
superClass = helper.getSuperClass(receiverName);
|
if(receiverName.equals(cl.getClassName().toString())) {
|
||||||
|
superClass = cl.getSuperClass().getName().toString();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println(superClass);
|
||||||
|
|
||||||
|
if(superClass.equals(""))
|
||||||
|
break;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String superClazz = superClass.replace("/", ".");
|
String superClazz = superClass.replace("/", ".");
|
||||||
@@ -823,26 +818,12 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
receiverName = superClass;
|
receiverName = superClass;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} catch (NotInCurrentPackageException e2) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(methodRefl == null) {
|
if(methodRefl == null) {
|
||||||
toCreate = !receiverName.equals(className) && helper.isInCurrPkg(clazz);
|
|
||||||
if(toCreate) {
|
|
||||||
try {
|
|
||||||
mDesc = helper.getDesc(clazz);
|
|
||||||
} catch (NotInCurrentPackageException | NotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} else if(!helper.isInCurrPkg(clazz)){
|
|
||||||
if(clazz.contains("$$")) {
|
|
||||||
mDesc = helper.generateBCForFunN();
|
|
||||||
}else {
|
|
||||||
try {
|
try {
|
||||||
cLoader2 = new URLClassLoader(new URL[] {new URL("file://"+path)});
|
cLoader2 = new URLClassLoader(new URL[] {new URL("file://"+path)});
|
||||||
java.lang.reflect.Method[] methods = cLoader2.loadClass(clazz).getMethods();
|
java.lang.reflect.Method[] methods = cLoader2.loadClass(clazz).getMethods();
|
||||||
@@ -853,25 +834,22 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
methodRefl = getMethod(methodCall.name,methodCall.arglist.getArguments().size(),methCallType, typesOfParams,methods);
|
methodRefl = getMethod(methodCall.name,methodCall.arglist.getArguments().size(),methCallType, typesOfParams,methods);
|
||||||
}
|
}
|
||||||
catch (Exception e2) {
|
catch (Exception e2) {
|
||||||
e2.printStackTrace();
|
System.out.println("");
|
||||||
|
//do nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
methodCall.receiver.accept(this);
|
methodCall.receiver.accept(this);
|
||||||
|
|
||||||
System.out.println("Methodcall type : " + resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor()));
|
System.out.println("Methodcall type : " + resultSet.resolveType(methodCall.getType()).resolvedType.acceptTV(new TypeToDescriptor()));
|
||||||
|
String mDesc = "";
|
||||||
List<Boolean> argListMethCall = new LinkedList<>();
|
List<Boolean> argListMethCall = new LinkedList<>();
|
||||||
String receiverRefl="";
|
String receiverRefl="";
|
||||||
if(methodRefl == null && receiverName.equals(className)) {
|
if(methodRefl == null) {
|
||||||
MethodFromMethodCall method = new MethodFromMethodCall(methodCall.arglist, methodCall.getType(),
|
MethodFromMethodCall method = new MethodFromMethodCall(methodCall.arglist, methodCall.getType(),
|
||||||
receiverName, genericsAndBoundsMethod, genericsAndBounds);
|
receiverName, genericsAndBoundsMethod, genericsAndBounds);
|
||||||
mDesc = method.accept(new DescriptorToString(resultSet));
|
mDesc = method.accept(new DescriptorToString(resultSet));
|
||||||
methodCall.arglist.accept(this);
|
methodCall.arglist.accept(this);
|
||||||
} else if(methodRefl != null) {
|
} else {
|
||||||
System.out.println(methodCall.name + " -> Refl != null");
|
|
||||||
receiverRefl = methodRefl.getAnnotatedReceiverType().getType().toString();
|
receiverRefl = methodRefl.getAnnotatedReceiverType().getType().toString();
|
||||||
for(Parameter p:methodRefl.getParameters()) {
|
for(Parameter p:methodRefl.getParameters()) {
|
||||||
System.out.println(p.getName() + " und is Primitive = " + p.getType().isPrimitive());
|
System.out.println(p.getName() + " und is Primitive = " + p.getType().isPrimitive());
|
||||||
@@ -885,11 +863,9 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
al.accept(argV);
|
al.accept(argV);
|
||||||
statement = null;
|
statement = null;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
methodCall.arglist.accept(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Methodcall ("+ methodCall.name +") Desc : " + mDesc);
|
System.out.println("Methodcall Desc : " + mDesc);
|
||||||
|
|
||||||
|
|
||||||
// methodCall.arglist.accept(this);
|
// methodCall.arglist.accept(this);
|
||||||
@@ -924,19 +900,6 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getDescForMethInCurrPkg(String name) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isInCurrPkg(String superClass) {
|
|
||||||
for(ClassOrInterface cl : sf.KlassenVektor) {
|
|
||||||
if(superClass.equals(cl.getClassName().toString()))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String[] getTypes(List<Expression> arguments) {
|
private String[] getTypes(List<Expression> arguments) {
|
||||||
String[] types = new String[arguments.size()];
|
String[] types = new String[arguments.size()];
|
||||||
for(int i = 0; i<arguments.size(); ++i) {
|
for(int i = 0; i<arguments.size(); ++i) {
|
||||||
@@ -1234,7 +1197,6 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case "java/lang/Boolean":
|
case "java/lang/Boolean":
|
||||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z", false);
|
|
||||||
break;
|
break;
|
||||||
case "java/lang/Byte":
|
case "java/lang/Byte":
|
||||||
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Byte", "byteValue", "()B", false);
|
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Byte", "byteValue", "()B", false);
|
||||||
@@ -1272,16 +1234,10 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
visitBooleanLiteral((Boolean) value);
|
visitBooleanLiteral((Boolean) value);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Byte":
|
case "java/lang/Byte":
|
||||||
if(value instanceof Double)
|
|
||||||
visitByteLiteral(((Double) value).byteValue(), false);
|
visitByteLiteral(((Double) value).byteValue(), false);
|
||||||
if(value instanceof Integer)
|
|
||||||
visitByteLiteral(((Integer) value).byteValue(), false);
|
|
||||||
break;
|
break;
|
||||||
case "java/lang/Short":
|
case "java/lang/Short":
|
||||||
if(value instanceof Double)
|
|
||||||
visitShortLiteral(((Double) value).shortValue(), false);
|
visitShortLiteral(((Double) value).shortValue(), false);
|
||||||
if(value instanceof Integer)
|
|
||||||
visitShortLiteral(((Integer) value).shortValue(), false);
|
|
||||||
break;
|
break;
|
||||||
case "java/lang/Integer":
|
case "java/lang/Integer":
|
||||||
// zweite Argument isLong
|
// zweite Argument isLong
|
||||||
@@ -1292,16 +1248,10 @@ public class BytecodeGenMethod implements StatementVisitor {
|
|||||||
visitIntegerLiteral(((Integer) value).intValue(), false);
|
visitIntegerLiteral(((Integer) value).intValue(), false);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Long":
|
case "java/lang/Long":
|
||||||
if(value instanceof Double)
|
|
||||||
visitLongLiteral(((Double) value).longValue(), true);
|
|
||||||
if(value instanceof Integer)
|
|
||||||
visitLongLiteral(((Integer) value).longValue(), true);
|
visitLongLiteral(((Integer) value).longValue(), true);
|
||||||
break;
|
break;
|
||||||
case "java/lang/Float":
|
case "java/lang/Float":
|
||||||
if(value instanceof Double)
|
|
||||||
visitFloatLiteral(((Double) value).floatValue());
|
visitFloatLiteral(((Double) value).floatValue());
|
||||||
if(value instanceof Integer)
|
|
||||||
visitFloatLiteral(((Integer) value).floatValue());
|
|
||||||
break;
|
break;
|
||||||
case "java/lang/Double":
|
case "java/lang/Double":
|
||||||
if(value instanceof Double)
|
if(value instanceof Double)
|
||||||
|
@@ -1,19 +0,0 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package de.dhbwstuttgart.bytecode.Exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author fayez
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class BytecodeGeneratorError extends RuntimeException {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param message
|
|
||||||
*/
|
|
||||||
public BytecodeGeneratorError(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,25 +0,0 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package de.dhbwstuttgart.bytecode.Exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author fayez
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class NotFoundException extends Exception {
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param message
|
|
||||||
*/
|
|
||||||
public NotFoundException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@@ -1,26 +0,0 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package de.dhbwstuttgart.bytecode.Exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author fayez
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class NotInCurrentPackageException extends Exception {
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param message
|
|
||||||
*/
|
|
||||||
public NotInCurrentPackageException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@@ -5,11 +5,7 @@ package de.dhbwstuttgart.bytecode;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
import de.dhbwstuttgart.bytecode.constraint.ExtendsConstraint;
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
||||||
@@ -17,18 +13,13 @@ import de.dhbwstuttgart.bytecode.constraint.TPHConstraint.Relation;
|
|||||||
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
import de.dhbwstuttgart.bytecode.utilities.MethodAndTPH;
|
||||||
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
import de.dhbwstuttgart.syntaxtree.AbstractASTWalker;
|
||||||
import de.dhbwstuttgart.syntaxtree.Constructor;
|
import de.dhbwstuttgart.syntaxtree.Constructor;
|
||||||
import de.dhbwstuttgart.syntaxtree.Field;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
import de.dhbwstuttgart.syntaxtree.ParameterList;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
import de.dhbwstuttgart.syntaxtree.statement.LocalVar;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
|
import de.dhbwstuttgart.syntaxtree.statement.LocalVarDecl;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,14 +29,14 @@ import de.dhbwstuttgart.typeinference.result.ResultSet;
|
|||||||
public class TPHExtractor extends AbstractASTWalker {
|
public class TPHExtractor extends AbstractASTWalker {
|
||||||
// Alle TPHs der Felder werden iKopf der Klasse definiert
|
// Alle TPHs der Felder werden iKopf der Klasse definiert
|
||||||
// alle TPHs der Klasse: (TPH, is in Method?)
|
// alle TPHs der Klasse: (TPH, is in Method?)
|
||||||
final HashMap<String, Boolean> allTPHS = new HashMap<>();
|
final HashMap<TypePlaceholder, Boolean> allTPHS = new HashMap<>();
|
||||||
MethodAndTPH methodAndTph;
|
MethodAndTPH methodAndTph;
|
||||||
|
|
||||||
Boolean inMethod = false;
|
Boolean inMethod = false;
|
||||||
boolean inLocalOrParam = false;
|
boolean inLocalOrParam = false;
|
||||||
|
|
||||||
public final ArrayList<MethodAndTPH> ListOfMethodsAndTph = new ArrayList<>();
|
public final ArrayList<MethodAndTPH> ListOfMethodsAndTph = new ArrayList<>();
|
||||||
final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> allPairs = new ArrayList<>();
|
final ArrayList<GenericInsertPair> allPairs = new ArrayList<>();
|
||||||
public final ArrayList<TPHConstraint> allCons = new ArrayList<>();
|
public final ArrayList<TPHConstraint> allCons = new ArrayList<>();
|
||||||
private ResultSet resultSet;
|
private ResultSet resultSet;
|
||||||
|
|
||||||
@@ -67,80 +58,19 @@ public class TPHExtractor extends AbstractASTWalker {
|
|||||||
methodAndTph.getLocalTphs().add(resolvedTPH.getName());
|
methodAndTph.getLocalTphs().add(resolvedTPH.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
allTPHS.put(resolvedTPH.getName(), inMethod);
|
allTPHS.put(resolvedTPH, inMethod);
|
||||||
// final List<TPHConstraint> cons = new ArrayList<>();
|
resultSet.resolveType(tph).additionalGenerics.forEach(ag -> {
|
||||||
// resultSet.resolveType(tph).additionalGenerics.forEach(ag -> {
|
if (ag.contains(resolvedTPH) && ag.TA1.equals(resolvedTPH) && !contains(allPairs, ag)) {
|
||||||
// TPHConstraint con = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS);
|
|
||||||
// cons.add(con);
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// Map<TPHConstraint, Boolean> visitMap = new HashMap<>();
|
|
||||||
// for(TPHConstraint cc : cons) {
|
|
||||||
// visitMap.put(cc, false);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// String left = resolvedTPH.getName();
|
|
||||||
// for (TPHConstraint cc : visitMap.keySet()) {
|
|
||||||
//
|
|
||||||
// if(visitMap.get(cc))
|
|
||||||
// continue;
|
|
||||||
//
|
|
||||||
// if (cc.getLeft().equals(left)) {
|
|
||||||
// allCons.add(cc);
|
|
||||||
// List<TPHConstraint> toVisit = getToVisitCons(cons,cc.getRight(), visitMap);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
//resultSet.resolveType(tph).getAdditionalGenerics().forEach(ag -> {
|
|
||||||
resultSet.genIns.forEach(ag -> {
|
|
||||||
|
|
||||||
// if (ag.contains(resolvedTPH) /* && ag.TA1.equals(resolvedTPH) */ && !contains(allPairs, ag)) {
|
|
||||||
if (inMethod)
|
if (inMethod)
|
||||||
methodAndTph.getPairs().add(ag);
|
methodAndTph.getPairs().add(ag);
|
||||||
allPairs.add(ag);
|
allPairs.add(ag);
|
||||||
TPHConstraint con = new ExtendsConstraint(ag.getLeft().getName(), ag.getRight().getName(), Relation.EXTENDS);
|
TPHConstraint con = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS);
|
||||||
if(!containsConstraint(allCons,con))
|
|
||||||
allCons.add(con);
|
allCons.add(con);
|
||||||
// }
|
}
|
||||||
});
|
});
|
||||||
} else if (resultSet.resolveType(tph).resolvedType instanceof RefType) {
|
|
||||||
RefType rt = (RefType) resultSet.resolveType(tph).resolvedType;
|
|
||||||
rt.accept(this);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean containsConstraint(ArrayList<TPHConstraint> allCons, TPHConstraint c) {
|
|
||||||
for(TPHConstraint con:allCons) {
|
|
||||||
if(c.getLeft().equals(con.getLeft()) && c.getRight().equals(c.getRight())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<TPHConstraint> getToVisitCons(List<TPHConstraint> cons, String right, Map<TPHConstraint, Boolean> visitMap) {
|
|
||||||
List<TPHConstraint> res = new ArrayList<>();
|
|
||||||
for(TPHConstraint cc : cons) {
|
|
||||||
if(cc.getLeft().equals(right)) {
|
|
||||||
res.add(cc);
|
|
||||||
if(visitMap.get(cc))
|
|
||||||
visitMap.replace(cc, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visit(GenericRefType genericRefType) {
|
|
||||||
String name = genericRefType.getParsedName();
|
|
||||||
if (inMethod) {
|
|
||||||
methodAndTph.getLocalTphs().add(name);
|
|
||||||
if (inLocalOrParam)
|
|
||||||
methodAndTph.getLocalTphs().add(name);
|
|
||||||
}
|
|
||||||
allTPHS.put(name, inMethod);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean contains(ArrayList<GenericInsertPair> pairs, GenericInsertPair genPair) {
|
private boolean contains(ArrayList<GenericInsertPair> pairs, GenericInsertPair genPair) {
|
||||||
for (int i = 0; i < pairs.size(); ++i) {
|
for (int i = 0; i < pairs.size(); ++i) {
|
||||||
GenericInsertPair p = pairs.get(i);
|
GenericInsertPair p = pairs.get(i);
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
package de.dhbwstuttgart.bytecode.descriptor;
|
package de.dhbwstuttgart.bytecode.descriptor;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.objectweb.asm.Type;
|
import org.objectweb.asm.Type;
|
||||||
@@ -45,31 +44,20 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
if(method.hasGen()) {
|
if(method.hasGen()) {
|
||||||
String fpDesc = fp.getType().acceptTV(new TypeToDescriptor());
|
String fpDesc = fp.getType().acceptTV(new TypeToDescriptor());
|
||||||
if(method.getGenericsAndBoundsMethod().containsKey(fpDesc)) {
|
if(method.getGenericsAndBoundsMethod().containsKey(fpDesc)) {
|
||||||
String bound = getBound(fpDesc, method.getGenericsAndBoundsMethod());
|
desc += "L"+method.getGenericsAndBoundsMethod().get(fpDesc)+ ";";
|
||||||
desc += "L"+bound+ ";";
|
|
||||||
}else if(method.getGenericsAndBounds().containsKey(fpDesc)){
|
}else if(method.getGenericsAndBounds().containsKey(fpDesc)){
|
||||||
String bound = getBound(fpDesc, method.getGenericsAndBounds());
|
desc += "L"+method.getGenericsAndBounds().get(fpDesc)+ ";";
|
||||||
desc += "L"+bound+ ";";
|
|
||||||
}else {
|
}else {
|
||||||
// desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
// desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor())+ ";";
|
||||||
String resType = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String resType = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
if(resType.contains("TPH ")/*resType.subSequence(0, 4).equals("TPH ")*/) {
|
if(resType.subSequence(0, 4).equals("TPH ")) {
|
||||||
// Bound ist immer Object
|
// Bound ist immer Object
|
||||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||||
} else {
|
|
||||||
// TODO::
|
|
||||||
if(method.getGenericsAndBounds().containsKey(resType)) {
|
|
||||||
String bound = getBound(resType, method.getGenericsAndBounds());
|
|
||||||
desc += "L"+bound+ ";";
|
|
||||||
}else if(method.getGenericsAndBoundsMethod().containsKey(resType)) {
|
|
||||||
String bound = getBound(resType, method.getGenericsAndBoundsMethod());
|
|
||||||
desc += "L"+bound+ ";";
|
|
||||||
} else {
|
} else {
|
||||||
desc += "L"+resType+ ";";
|
desc += "L"+resType+ ";";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
//TODO: generate a class java%% ... %%
|
//TODO: generate a class java%% ... %%
|
||||||
else if(resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor()).contains("<")){
|
else if(resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor()).contains("<")){
|
||||||
desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.toString().replace(".", "$$").replace("<", "$$$").replace(">", "$$$")+ ";";
|
desc += "L"+resultSet.resolveType(fp.getType()).resolvedType.toString().replace(".", "$$").replace("<", "$$$").replace(">", "$$$")+ ";";
|
||||||
@@ -90,21 +78,11 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
desc += ")L"+method.getGenericsAndBounds().get(ret)+ ";";
|
desc += ")L"+method.getGenericsAndBounds().get(ret)+ ";";
|
||||||
}else {
|
}else {
|
||||||
String resType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String resType = resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
if(resType.contains("TPH ")/*resType.subSequence(0, 4).equals("TPH ")*/) {
|
if(resType.subSequence(0, 4).equals("TPH ")) {
|
||||||
// desc += ")" + "L"+method.getGenericsAndBoundsMethod().get(resType.substring(4)+"$")+ ";";
|
// desc += ")" + "L"+method.getGenericsAndBoundsMethod().get(resType.substring(4)+"$")+ ";";
|
||||||
desc += ")" + "L"+Type.getInternalName(Object.class)+ ";";
|
desc += ")" + "L"+Type.getInternalName(Object.class)+ ";";
|
||||||
} else {
|
} else {
|
||||||
// TODO::
|
desc += ")" + "L"+resType+ ";";
|
||||||
if(method.getGenericsAndBounds().containsKey(resType)) {
|
|
||||||
String bound = getBound(resType, method.getGenericsAndBounds());
|
|
||||||
desc += ")L"+bound+ ";";
|
|
||||||
}else if(method.getGenericsAndBoundsMethod().containsKey(resType)) {
|
|
||||||
String bound = getBound(resType, method.getGenericsAndBoundsMethod());
|
|
||||||
desc += ")L"+bound+ ";";
|
|
||||||
} else {
|
|
||||||
desc += ")L"+resType+ ";";
|
|
||||||
}
|
|
||||||
// desc += ")" + "L"+resType+ ";";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
@@ -115,15 +93,6 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
return desc;
|
return desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getBound(String fpDesc, HashMap<String, String> genericsAndBounds) {
|
|
||||||
String start = genericsAndBounds.get(fpDesc);
|
|
||||||
while(genericsAndBounds.containsKey(start)) {
|
|
||||||
start = genericsAndBounds.get(start);
|
|
||||||
}
|
|
||||||
|
|
||||||
return start;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String visit(NormalConstructor constructor) {
|
public String visit(NormalConstructor constructor) {
|
||||||
String desc = "(";
|
String desc = "(";
|
||||||
@@ -162,7 +131,7 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
while(itr.hasNext()) {
|
while(itr.hasNext()) {
|
||||||
FormalParameter fp = itr.next();
|
FormalParameter fp = itr.next();
|
||||||
String d = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String d = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
if(d.contains("TPH ") ||d.contains("<")) {
|
if(d.substring(0, 4).equals("TPH ") ||d.contains("<")) {
|
||||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||||
}else {
|
}else {
|
||||||
desc = desc + "L"+ d + ";";
|
desc = desc + "L"+ d + ";";
|
||||||
@@ -171,7 +140,7 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
|
|
||||||
String retType = resultSet.resolveType(lambdaExpression.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String retType = resultSet.resolveType(lambdaExpression.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
|
|
||||||
if(retType.contains("TPH ")|| retType.contains("<")){
|
if(retType.substring(0, 4).equals("TPH ")|| retType.contains("<")){
|
||||||
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
||||||
}else {
|
}else {
|
||||||
desc = desc + ")"+"L"+retType+";";
|
desc = desc + ")"+"L"+retType+";";
|
||||||
@@ -187,7 +156,7 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
RefTypeOrTPHOrWildcardOrGeneric rt = itr.next();
|
RefTypeOrTPHOrWildcardOrGeneric rt = itr.next();
|
||||||
String d = resultSet.resolveType(rt).resolvedType.acceptTV(new TypeToDescriptor());
|
String d = resultSet.resolveType(rt).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
|
|
||||||
if(d.contains("TPH ") ||d.contains("<")) {
|
if(d.substring(0, 4).equals("TPH ") ||d.contains("<")) {
|
||||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||||
}else {
|
}else {
|
||||||
desc += "L"+ d + ";";
|
desc += "L"+ d + ";";
|
||||||
@@ -196,7 +165,7 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
}
|
}
|
||||||
String retType = resultSet.resolveType(samMethod.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String retType = resultSet.resolveType(samMethod.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
|
|
||||||
if(retType.contains("TPH ")|| retType.contains("<")){
|
if(retType.substring(0, 4).equals("TPH ")|| retType.contains("<")){
|
||||||
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
||||||
}else {
|
}else {
|
||||||
desc = desc + ")"+"L"+retType+";";
|
desc = desc + ")"+"L"+retType+";";
|
||||||
@@ -210,7 +179,7 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
for(Expression e : methodFromMethodCall.getArgList().getArguments()) {
|
for(Expression e : methodFromMethodCall.getArgList().getArguments()) {
|
||||||
String d = resultSet.resolveType(e.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
String d = resultSet.resolveType(e.getType()).resolvedType.acceptTV(new TypeToDescriptor());
|
||||||
|
|
||||||
if(d.contains("TPH ") ||d.contains("<") || methodFromMethodCall.getReceiverName().contains("$$")) {
|
if(d.substring(0, 4).equals("TPH ") ||d.contains("<") || methodFromMethodCall.getReceiverName().contains("$$")) {
|
||||||
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
desc += "L"+Type.getInternalName(Object.class)+ ";";
|
||||||
}else {
|
}else {
|
||||||
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(d)) {
|
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(d)) {
|
||||||
@@ -227,7 +196,7 @@ public class DescriptorToString implements DescriptorVisitor{
|
|||||||
System.out.println("DescriptorToString retType = " + retType);
|
System.out.println("DescriptorToString retType = " + retType);
|
||||||
if(retType.equals("void")) {
|
if(retType.equals("void")) {
|
||||||
desc += ")V";
|
desc += ")V";
|
||||||
}else if(retType.contains("TPH ")|| retType.contains("<") || methodFromMethodCall.getReceiverName().contains("$$")){
|
}else if(retType.substring(0, 4).equals("TPH ")|| retType.contains("<") || methodFromMethodCall.getReceiverName().contains("$$")){
|
||||||
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
desc += ")L"+Type.getInternalName(Object.class)+ ";";
|
||||||
}else {
|
}else {
|
||||||
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(retType)) {
|
if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(retType)) {
|
||||||
|
@@ -41,11 +41,11 @@ public class Signature {
|
|||||||
private ResultSet resultSet;
|
private ResultSet resultSet;
|
||||||
private ArrayList<GenericInsertPair> commonPairs;
|
private ArrayList<GenericInsertPair> commonPairs;
|
||||||
private HashMap<TPHConstraint,HashSet<String>> methodConstraints;
|
private HashMap<TPHConstraint,HashSet<String>> methodConstraints;
|
||||||
private ArrayList<String> tphsClass;
|
private ArrayList<TypePlaceholder> tphsClass;
|
||||||
private ArrayList<TPHConstraint> consClass;
|
private ArrayList<TPHConstraint> consClass;
|
||||||
|
|
||||||
public Signature(ClassOrInterface classOrInterface, HashMap<String, String> genericsAndBounds,
|
public Signature(ClassOrInterface classOrInterface, HashMap<String, String> genericsAndBounds,
|
||||||
ArrayList<GenericInsertPair> commonPairs, ArrayList<String> tphsClass, ArrayList<TPHConstraint> consClass) {
|
ArrayList<GenericInsertPair> commonPairs, ArrayList<TypePlaceholder> tphsClass, ArrayList<TPHConstraint> consClass) {
|
||||||
this.classOrInterface = classOrInterface;
|
this.classOrInterface = classOrInterface;
|
||||||
this.genericsAndBounds = genericsAndBounds;
|
this.genericsAndBounds = genericsAndBounds;
|
||||||
this.commonPairs = commonPairs;
|
this.commonPairs = commonPairs;
|
||||||
@@ -80,12 +80,12 @@ public class Signature {
|
|||||||
createSignatureForConsOrMethod(this.method,false);
|
createSignatureForConsOrMethod(this.method,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Signature(int numberOfParams) {
|
public Signature(LambdaExpression lambdaExpression,int numberOfParams) {
|
||||||
sw = new SignatureWriter();
|
sw = new SignatureWriter();
|
||||||
createSignatureForFunN(numberOfParams);
|
createSignatureForFunN(lambdaExpression, numberOfParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createSignatureForFunN(int numberOfParams) {
|
private void createSignatureForFunN(LambdaExpression lambdaExpression, int numberOfParams) {
|
||||||
|
|
||||||
// sw.visitClassBound().visitEnd();
|
// sw.visitClassBound().visitEnd();
|
||||||
for(int i = 0;i<numberOfParams;i++) {
|
for(int i = 0;i<numberOfParams;i++) {
|
||||||
@@ -235,9 +235,8 @@ public class Signature {
|
|||||||
|
|
||||||
RefTypeOrTPHOrWildcardOrGeneric resolved = resType.resolvedType;
|
RefTypeOrTPHOrWildcardOrGeneric resolved = resType.resolvedType;
|
||||||
if(resolved instanceof TypePlaceholder) {
|
if(resolved instanceof TypePlaceholder) {
|
||||||
//resType.getAdditionalGenerics().forEach(ag ->{
|
resType.additionalGenerics.forEach(ag ->{
|
||||||
resultSet.genIns.forEach(ag ->{
|
TPHConstraint constr = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS);
|
||||||
TPHConstraint constr = new ExtendsConstraint(ag.getLeft().getName(), ag.getRight().getName(), Relation.EXTENDS);
|
|
||||||
if(!contains(res,constr)) {
|
if(!contains(res,constr)) {
|
||||||
res.add(constr);
|
res.add(constr);
|
||||||
}
|
}
|
||||||
@@ -247,9 +246,8 @@ public class Signature {
|
|||||||
WildcardType resWC = (WildcardType) resolved;
|
WildcardType resWC = (WildcardType) resolved;
|
||||||
ResolvedType resType2 = resultSet.resolveType(resWC.getInnerType());
|
ResolvedType resType2 = resultSet.resolveType(resWC.getInnerType());
|
||||||
if(resType2.resolvedType instanceof TypePlaceholder) {
|
if(resType2.resolvedType instanceof TypePlaceholder) {
|
||||||
//resType2.getAdditionalGenerics().forEach(ag ->{
|
resType2.additionalGenerics.forEach(ag ->{
|
||||||
resultSet.genIns.forEach(ag ->{
|
TPHConstraint constr = new ExtendsConstraint(ag.TA1.getName(), ag.TA2.getName(), Relation.EXTENDS);
|
||||||
TPHConstraint constr = new ExtendsConstraint(ag.getLeft().getName(), ag.getRight().getName(), Relation.EXTENDS);
|
|
||||||
if(!contains(res,constr)) {
|
if(!contains(res,constr)) {
|
||||||
res.add(constr);
|
res.add(constr);
|
||||||
}
|
}
|
||||||
@@ -292,8 +290,7 @@ public class Signature {
|
|||||||
break;
|
break;
|
||||||
case "GRT":
|
case "GRT":
|
||||||
GenericRefType g = (GenericRefType) t;
|
GenericRefType g = (GenericRefType) t;
|
||||||
// sv.visitTypeVariable(g.acceptTV(new TypeToSignature()).substring(1));
|
sv.visitTypeVariable(g.acceptTV(new TypeToSignature()).substring(1));
|
||||||
sv.visitTypeVariable(g.acceptTV(new TypeToSignature()));
|
|
||||||
break;
|
break;
|
||||||
case "TPH":
|
case "TPH":
|
||||||
RefTypeOrTPHOrWildcardOrGeneric r = resultSet.resolveType(t).resolvedType;
|
RefTypeOrTPHOrWildcardOrGeneric r = resultSet.resolveType(t).resolvedType;
|
||||||
@@ -304,27 +301,16 @@ public class Signature {
|
|||||||
// das braucht man nicht es reicht: sv.visitTypeVariable(r.acceptTV(new TypeToSignature())
|
// das braucht man nicht es reicht: sv.visitTypeVariable(r.acceptTV(new TypeToSignature())
|
||||||
//
|
//
|
||||||
String sig2 = r.acceptTV(new TypeToSignature());
|
String sig2 = r.acceptTV(new TypeToSignature());
|
||||||
if(r instanceof GenericRefType) {
|
String eqTPH = getEqualTPH(methodConstraints, sig2.substring(1, sig2.length()-1))+"$";
|
||||||
sv.visitTypeVariable(sig2);
|
if(!(r instanceof TypePlaceholder)) {
|
||||||
}else if(!(r instanceof TypePlaceholder)) {
|
|
||||||
if(sig2.contains("$$")) {
|
if(sig2.contains("$$")) {
|
||||||
System.out.println(" Signature FUN$$: "+r);
|
System.out.println(" Signature FUN$$: "+r);
|
||||||
sv.visitInterface().visitClassType(sig2.substring(1, sig2.length()));
|
sv.visitInterface().visitClassType(sig2.substring(1, sig2.length()));
|
||||||
} else {
|
} else {
|
||||||
// Kann zwischen GenericRefType und RefType nicht unterscheiden
|
sv.visitClassType(sig2.substring(1, sig2.length()));
|
||||||
// Deswegen wird immer geprüft, ob der Name in Generic Maps liegt
|
|
||||||
String n = sig2.substring(1, sig2.length()-1);
|
|
||||||
// if(genericsAndBoundsMethod.containsKey(n) || genericsAndBounds.containsKey(n)) {
|
|
||||||
// sv.visitTypeVariable(n);
|
|
||||||
// } else {
|
|
||||||
sv.visitClassType(n);
|
|
||||||
sv.visitEnd();
|
|
||||||
// }
|
|
||||||
// sv.visitClassType(n);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
String eqTPH = getEqualTPH(methodConstraints, sig2.substring(1, sig2.length()-1))+"$";
|
|
||||||
System.out.println(r.getClass()+" Signature TPH: "+r.acceptTV(new TypeToSignature()));
|
System.out.println(r.getClass()+" Signature TPH: "+r.acceptTV(new TypeToSignature()));
|
||||||
sv.visitTypeVariable(eqTPH);
|
sv.visitTypeVariable(eqTPH);
|
||||||
}
|
}
|
||||||
@@ -470,15 +456,10 @@ public class Signature {
|
|||||||
String boundDesc = b.acceptTV(new TypeToDescriptor());
|
String boundDesc = b.acceptTV(new TypeToDescriptor());
|
||||||
// System.out.println("GetBounds: " + boundDesc);
|
// System.out.println("GetBounds: " + boundDesc);
|
||||||
// Ensure that <...> extends java.lang.Object OR ...
|
// Ensure that <...> extends java.lang.Object OR ...
|
||||||
if(b instanceof GenericRefType) {
|
|
||||||
sw.visitClassBound().visitTypeVariable(boundDesc);
|
|
||||||
} else {
|
|
||||||
sw.visitClassBound().visitClassType(boundDesc);
|
sw.visitClassBound().visitClassType(boundDesc);
|
||||||
sw.visitClassBound().visitEnd();
|
|
||||||
}
|
|
||||||
genAndBounds.put(g.getName(), boundDesc);
|
genAndBounds.put(g.getName(), boundDesc);
|
||||||
}
|
}
|
||||||
// sw.visitClassBound().visitEnd();
|
sw.visitClassBound().visitEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@@ -2,17 +2,14 @@ package de.dhbwstuttgart.bytecode.utilities;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||||
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
import de.dhbwstuttgart.typeinference.result.GenericInsertPair;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
|
||||||
|
|
||||||
public class MethodAndTPH {
|
public class MethodAndTPH {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private final ArrayList<String> tphs = new ArrayList<>();
|
private final ArrayList<String> tphs = new ArrayList<>();
|
||||||
//private final ArrayList<GenericInsertPair> pairs = new ArrayList<>();
|
private final ArrayList<GenericInsertPair> pairs = new ArrayList<>();
|
||||||
private final ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> pairs = new ArrayList<>();
|
|
||||||
// tphs of local variables and parameters
|
// tphs of local variables and parameters
|
||||||
private final ArrayList<String> localTphs = new ArrayList<>();
|
private final ArrayList<String> localTphs = new ArrayList<>();
|
||||||
|
|
||||||
@@ -24,10 +21,7 @@ public class MethodAndTPH {
|
|||||||
return tphs;
|
return tphs;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public ArrayList<GenericInsertPair> getPairs(){
|
public ArrayList<GenericInsertPair> getPairs(){
|
||||||
// return pairs;
|
|
||||||
// }
|
|
||||||
public ArrayList<ResultPair<TypePlaceholder, TypePlaceholder>> getPairs(){
|
|
||||||
return pairs;
|
return pairs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,255 +0,0 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package de.dhbwstuttgart.bytecode.utilities;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
import org.objectweb.asm.ClassWriter;
|
|
||||||
import org.objectweb.asm.MethodVisitor;
|
|
||||||
import org.objectweb.asm.Opcodes;
|
|
||||||
import org.objectweb.asm.Type;
|
|
||||||
import org.objectweb.asm.signature.SignatureVisitor;
|
|
||||||
import org.objectweb.asm.signature.SignatureWriter;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.Exception.NotInCurrentPackageException;
|
|
||||||
import de.dhbwstuttgart.bytecode.descriptor.DescriptorToString;
|
|
||||||
import de.dhbwstuttgart.bytecode.descriptor.TypeToDescriptor;
|
|
||||||
import de.dhbwstuttgart.bytecode.signature.Signature;
|
|
||||||
import de.dhbwstuttgart.bytecode.signature.TypeToSignature;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.FormalParameter;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Expression;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.LambdaExpression;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.MethodCall;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
|
||||||
import javassist.NotFoundException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author fayez
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class MethodCallHelper {
|
|
||||||
private MethodCall methCall;
|
|
||||||
private SourceFile sourceFile;
|
|
||||||
private ResultSet resultSet;
|
|
||||||
private String path;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param methCall
|
|
||||||
* @param sourceFile
|
|
||||||
* @param resultSet
|
|
||||||
* @param path TODO
|
|
||||||
*/
|
|
||||||
public MethodCallHelper(MethodCall methCall, SourceFile sourceFile, ResultSet resultSet, String path) {
|
|
||||||
this.methCall = methCall;
|
|
||||||
this.sourceFile = sourceFile;
|
|
||||||
this.resultSet = resultSet;
|
|
||||||
this.path = path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getResolvedType(RefTypeOrTPHOrWildcardOrGeneric type) {
|
|
||||||
return resultSet.resolveType(type).resolvedType.acceptTV(new TypeToDescriptor());
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isInCurrPkg(String className) {
|
|
||||||
for (ClassOrInterface cl : sourceFile.KlassenVektor) {
|
|
||||||
if (className.equals(cl.getClassName().toString()))
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSuperClass(String className) throws NotInCurrentPackageException {
|
|
||||||
|
|
||||||
for (ClassOrInterface cl : sourceFile.getClasses()) {
|
|
||||||
if (className.equals(cl.getClassName().toString())) {
|
|
||||||
return cl.getSuperClass().getName().toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new NotInCurrentPackageException("Class " + className + " is not in the current package.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public ClassOrInterface getClassFromCurrPkg(String className) throws NotInCurrentPackageException {
|
|
||||||
for (ClassOrInterface cl : sourceFile.KlassenVektor) {
|
|
||||||
if (className.equals(cl.getClassName().toString()))
|
|
||||||
return cl;
|
|
||||||
}
|
|
||||||
throw new NotInCurrentPackageException("Class of " + className + " is not in the current package.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDesc(String className) throws NotInCurrentPackageException, NotFoundException {
|
|
||||||
String name = methCall.name;
|
|
||||||
ClassOrInterface clazz = getClassFromCurrPkg(className);
|
|
||||||
|
|
||||||
Map<String, String> genAndBoundsClass = getGenericsAndBounds(clazz.getGenerics());
|
|
||||||
modifyGenAndBounds(genAndBoundsClass);
|
|
||||||
for (Method m : clazz.getMethods()) {
|
|
||||||
if (name.equals(m.getName())) {
|
|
||||||
Map<String, String> genAndBoundsMethod = getGenericsAndBoundsMethod(m.getGenerics());
|
|
||||||
modifyGenAndBounds(genAndBoundsMethod);
|
|
||||||
boolean hasGen = hasGen(m, genAndBoundsClass);
|
|
||||||
NormalMethod nm = new NormalMethod(m, (HashMap<String, String>) genAndBoundsClass,
|
|
||||||
(HashMap<String, String>) genAndBoundsMethod, hasGen);
|
|
||||||
return nm.accept(new DescriptorToString(resultSet));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new NotFoundException("Method " + name + " is not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean hasGen(Method m, Map<String, String> genericsAndBounds) {
|
|
||||||
String retType = resultSet.resolveType(m.getReturnType()).resolvedType.acceptTV(new TypeToSignature());
|
|
||||||
/*Prüfe, ob die Rückgabe-Type der Methode eine Type-Variable ist*/
|
|
||||||
boolean hasGenInParameterList = genericsAndBounds.containsKey(retType) || retType.contains("TPH ") || retType.contains("<");
|
|
||||||
|
|
||||||
Map<String,RefTypeOrTPHOrWildcardOrGeneric> methodParamsAndTypes = new HashMap<>();
|
|
||||||
Iterator<FormalParameter> itr = m.getParameterList().iterator();
|
|
||||||
while(itr.hasNext()) {
|
|
||||||
FormalParameter fp = itr.next();
|
|
||||||
methodParamsAndTypes.put(fp.getName(), resultSet.resolveType(fp.getType()).resolvedType);
|
|
||||||
}
|
|
||||||
/*Wenn die Rückgabe-Type eine Typ-variable ist, erzeuge direkt die Signature, wenn nicht,
|
|
||||||
* prüfe, ob einer der Parameter Typ-Variable als Typ hat*/
|
|
||||||
if(!hasGenInParameterList) {
|
|
||||||
for(String paramName : methodParamsAndTypes.keySet()) {
|
|
||||||
String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToDescriptor());
|
|
||||||
String sigOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToSignature());
|
|
||||||
if(genericsAndBounds.containsKey(typeOfParam)||typeOfParam.contains("TPH ")||sigOfParam.contains("<")) {
|
|
||||||
hasGenInParameterList = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return m.getGenerics().iterator().hasNext() || hasGenInParameterList;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, String> getGenericsAndBoundsMethod(Iterable<? extends GenericTypeVar> generics) {
|
|
||||||
Map<String, String> genAndBounds = new HashMap<>();
|
|
||||||
Iterator<? extends GenericTypeVar> itr = generics.iterator();
|
|
||||||
while (itr.hasNext()) {
|
|
||||||
GenericTypeVar gtv = itr.next();
|
|
||||||
getBoundsOfTypeVar(gtv, genAndBounds);
|
|
||||||
}
|
|
||||||
return genAndBounds;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void modifyGenAndBounds(Map<String, String> genAndBoundsClass) {
|
|
||||||
List<String> visited = new ArrayList<>(genAndBoundsClass.size());
|
|
||||||
Map<String, String> toReplace = new HashMap<>();
|
|
||||||
for (String tv : genAndBoundsClass.keySet()) {
|
|
||||||
|
|
||||||
if (visited.contains(tv))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
List<String> types = new LinkedList<>();
|
|
||||||
String bound = genAndBoundsClass.get(tv);
|
|
||||||
types.add(tv);
|
|
||||||
visited.add(tv);
|
|
||||||
boolean doReplace = false;
|
|
||||||
while (genAndBoundsClass.keySet().contains(bound)) {
|
|
||||||
doReplace = true;
|
|
||||||
types.add(bound);
|
|
||||||
visited.add(bound);
|
|
||||||
bound = genAndBoundsClass.get(bound);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (doReplace) {
|
|
||||||
for (String tt : types) {
|
|
||||||
toReplace.put(tt, bound);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String key : toReplace.keySet()) {
|
|
||||||
genAndBoundsClass.replace(key, toReplace.get(key));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, String> getGenericsAndBounds(GenericDeclarationList generics) {
|
|
||||||
Map<String, String> genAndBounds = new HashMap<>();
|
|
||||||
Iterator<GenericTypeVar> itr = generics.iterator();
|
|
||||||
while (itr.hasNext()) {
|
|
||||||
GenericTypeVar gtv = itr.next();
|
|
||||||
getBoundsOfTypeVar(gtv, genAndBounds);
|
|
||||||
}
|
|
||||||
return genAndBounds;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getBoundsOfTypeVar(GenericTypeVar g, Map<String, String> genAndBounds) {
|
|
||||||
|
|
||||||
Iterator<? extends RefTypeOrTPHOrWildcardOrGeneric> bItr = g.getBounds().iterator();
|
|
||||||
while (bItr.hasNext()) {
|
|
||||||
RefTypeOrTPHOrWildcardOrGeneric b = bItr.next();
|
|
||||||
String boundDesc = b.acceptTV(new TypeToDescriptor());
|
|
||||||
genAndBounds.put(g.getName(), boundDesc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String generateBCForFunN() {
|
|
||||||
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
|
||||||
|
|
||||||
SignatureWriter methSig = new SignatureWriter();
|
|
||||||
|
|
||||||
int numberOfParams = 0;
|
|
||||||
SignatureVisitor paramVisitor = methSig.visitParameterType();
|
|
||||||
Iterator<Expression> itr1 = methCall.arglist.getArguments().iterator();
|
|
||||||
String methDesc = "(";
|
|
||||||
while(itr1.hasNext()) {
|
|
||||||
numberOfParams++;
|
|
||||||
// getBounds
|
|
||||||
paramVisitor.visitTypeVariable("T" + numberOfParams);
|
|
||||||
methDesc += "L" + Type.getInternalName(Object.class) + ";";
|
|
||||||
itr1.next();
|
|
||||||
}
|
|
||||||
methDesc += ")L" + Type.getInternalName(Object.class) + ";";
|
|
||||||
|
|
||||||
methSig.visitReturnType().visitTypeVariable("R");
|
|
||||||
// ")"+lam.getReturn.getBounds
|
|
||||||
Signature sig = new Signature(numberOfParams);
|
|
||||||
String name = "Fun" + numberOfParams + "$$";
|
|
||||||
classWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC+Opcodes.ACC_INTERFACE + Opcodes.ACC_ABSTRACT, name, sig.toString(),
|
|
||||||
Type.getInternalName(Object.class), null);
|
|
||||||
MethodVisitor mvApply = classWriter.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT, "apply", methDesc,
|
|
||||||
methSig.toString(), null);
|
|
||||||
mvApply.visitEnd();
|
|
||||||
writeClassFile(classWriter.toByteArray(), name);
|
|
||||||
return methDesc;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void writeClassFile(byte[] bytecode, String name) {
|
|
||||||
FileOutputStream output;
|
|
||||||
try {
|
|
||||||
System.out.println("generating " + name + ".class file...");
|
|
||||||
output = new FileOutputStream(
|
|
||||||
new File(path + name + ".class"));
|
|
||||||
output.write(bytecode);
|
|
||||||
output.close();
|
|
||||||
System.out.println(name + ".class file generated");
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -23,7 +23,6 @@ public class MethodFromMethodCall {
|
|||||||
this.genericsAndBounds = genericsAndBounds;
|
this.genericsAndBounds = genericsAndBounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ArgumentList getArgList() {
|
public ArgumentList getArgList() {
|
||||||
return argList;
|
return argList;
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,7 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
|||||||
public class Simplify {
|
public class Simplify {
|
||||||
|
|
||||||
public static HashMap<TPHConstraint, HashSet<String>> simplifyConstraints(String name, TPHExtractor tphExtractor,
|
public static HashMap<TPHConstraint, HashSet<String>> simplifyConstraints(String name, TPHExtractor tphExtractor,
|
||||||
ArrayList<String> tphsClass) {
|
ArrayList<TypePlaceholder> tphsClass) {
|
||||||
// 1. check if there are any simple cycles like L<R and R<L:
|
// 1. check if there are any simple cycles like L<R and R<L:
|
||||||
// a) yes => set L=R and:
|
// a) yes => set L=R and:
|
||||||
// * remove both constraints
|
// * remove both constraints
|
||||||
@@ -38,11 +38,9 @@ public class Simplify {
|
|||||||
ArrayList<TPHConstraint> allCons = new ArrayList<>();
|
ArrayList<TPHConstraint> allCons = new ArrayList<>();
|
||||||
|
|
||||||
for(TPHConstraint c : tphExtractor.allCons) {
|
for(TPHConstraint c : tphExtractor.allCons) {
|
||||||
if(!containsConstraint(allCons,c)) {
|
|
||||||
TPHConstraint nc = new TPHConstraint(c.getLeft(), c.getRight(), c.getRel());
|
TPHConstraint nc = new TPHConstraint(c.getLeft(), c.getRight(), c.getRel());
|
||||||
allCons.add(nc);
|
allCons.add(nc);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
ArrayList<TPHConstraint> consToRemove = new ArrayList<>();
|
ArrayList<TPHConstraint> consToRemove = new ArrayList<>();
|
||||||
|
|
||||||
// get all tph of the method
|
// get all tph of the method
|
||||||
@@ -384,7 +382,7 @@ public class Simplify {
|
|||||||
|
|
||||||
if (!containTPH(methodTphs, superTphRes)) {
|
if (!containTPH(methodTphs, superTphRes)) {
|
||||||
HashSet<String> equals = getEqualsTphsFromEqualCons(eqCons, superTphRes);
|
HashSet<String> equals = getEqualsTphsFromEqualCons(eqCons, superTphRes);
|
||||||
if (tphsClass.contains(superTphRes)/*classTPHSContainsTPH(tphsClass, superTphRes)*/) {
|
if (classTPHSContainsTPH(tphsClass, superTphRes)) {
|
||||||
result.put(new ExtendsConstraint(subTphRes, superTphRes, Relation.EXTENDS), equals);
|
result.put(new ExtendsConstraint(subTphRes, superTphRes, Relation.EXTENDS), equals);
|
||||||
} else {
|
} else {
|
||||||
result.put(new ExtendsConstraint(subTphRes, Type.getInternalName(Object.class), Relation.EXTENDS),
|
result.put(new ExtendsConstraint(subTphRes, Type.getInternalName(Object.class), Relation.EXTENDS),
|
||||||
@@ -452,15 +450,6 @@ public class Simplify {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean containsConstraint(ArrayList<TPHConstraint> allCons, TPHConstraint c) {
|
|
||||||
for(TPHConstraint con:allCons) {
|
|
||||||
if(c.getLeft().equals(con.getLeft()) && c.getRight().equals(c.getRight())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void updateEqualCons(Map<String, List<String>> replRes, ArrayList<TPHConstraint> eqCons) {
|
private static void updateEqualCons(Map<String, List<String>> replRes, ArrayList<TPHConstraint> eqCons) {
|
||||||
List<String> oldNames = replRes.values().iterator().next();
|
List<String> oldNames = replRes.values().iterator().next();
|
||||||
String newName = replRes.keySet().iterator().next();
|
String newName = replRes.keySet().iterator().next();
|
||||||
@@ -474,7 +463,7 @@ public class Simplify {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static HashMap<TPHConstraint, HashSet<String>> simplifyConstraintsClass(TPHExtractor tphExtractor,
|
public static HashMap<TPHConstraint, HashSet<String>> simplifyConstraintsClass(TPHExtractor tphExtractor,
|
||||||
ArrayList<String> tphsClass) {
|
ArrayList<TypePlaceholder> tphsClass) {
|
||||||
// all constraints that will be simplified
|
// all constraints that will be simplified
|
||||||
ArrayList<TPHConstraint> allCons = tphExtractor.allCons;
|
ArrayList<TPHConstraint> allCons = tphExtractor.allCons;
|
||||||
ArrayList<TPHConstraint> consToRemove = new ArrayList<>();
|
ArrayList<TPHConstraint> consToRemove = new ArrayList<>();
|
||||||
@@ -638,9 +627,7 @@ public class Simplify {
|
|||||||
if (isTPHInConstraint(result, sub))
|
if (isTPHInConstraint(result, sub))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// if (!classTPHSContainsTPH(tphsClass, sub))
|
if (!classTPHSContainsTPH(tphsClass, sub))
|
||||||
// continue;
|
|
||||||
if (!tphsClass.contains(sub))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (numOfVisitedPairs >= size)
|
if (numOfVisitedPairs >= size)
|
||||||
@@ -669,7 +656,7 @@ public class Simplify {
|
|||||||
// add X at the beginning of the list.
|
// add X at the beginning of the list.
|
||||||
while (subAndSuper.containsValue(subTphRes)) {
|
while (subAndSuper.containsValue(subTphRes)) {
|
||||||
for (String tph : subAndSuper.keySet()) {
|
for (String tph : subAndSuper.keySet()) {
|
||||||
if (/*classTPHSContainsTPH(tphsClass, tph)*/tphsClass.contains(tph) && subAndSuper.get(tph).equals(subTphRes)) {
|
if (classTPHSContainsTPH(tphsClass, tph) && subAndSuper.get(tph).equals(subTphRes)) {
|
||||||
subTphRes = tph;
|
subTphRes = tph;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -1,42 +0,0 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package de.dhbwstuttgart.bytecode.utilities;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.constraint.TPHConstraint;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author fayez
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class SimplifyResult {
|
|
||||||
private final ArrayList<TPHConstraint> classConstraints;
|
|
||||||
private final ArrayList<String> tphsClass;
|
|
||||||
private final HashMap<String, HashMap<TPHConstraint, HashSet<String>>> methodsConstraints;
|
|
||||||
|
|
||||||
public SimplifyResult(ArrayList<TPHConstraint> classConstraints, ArrayList<String> tphsClass,
|
|
||||||
HashMap<String, HashMap<TPHConstraint, HashSet<String>>> methodsConstraints) {
|
|
||||||
super();
|
|
||||||
this.classConstraints = classConstraints;
|
|
||||||
this.tphsClass = tphsClass;
|
|
||||||
this.methodsConstraints = methodsConstraints;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<TPHConstraint> getClassConstraints() {
|
|
||||||
return classConstraints;
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<String, HashMap<TPHConstraint, HashSet<String>>> getMethodsConstraints() {
|
|
||||||
return methodsConstraints;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<String> getTphsClass() {
|
|
||||||
return tphsClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -3,8 +3,6 @@ package de.dhbwstuttgart.core;
|
|||||||
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.BytecodeGen;
|
import de.dhbwstuttgart.bytecode.BytecodeGen;
|
||||||
import de.dhbwstuttgart.bytecode.Exception.BytecodeGeneratorError;
|
|
||||||
import de.dhbwstuttgart.bytecode.utilities.SimplifyResult;
|
|
||||||
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
||||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
@@ -39,7 +37,6 @@ 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;
|
||||||
@@ -53,23 +50,14 @@ import java.util.stream.Collectors;
|
|||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.antlr.v4.parse.ANTLRParser.throwsSpec_return;
|
import org.antlr.v4.parse.ANTLRParser.throwsSpec_return;
|
||||||
import org.apache.commons.io.output.NullOutputStream;
|
|
||||||
//import org.apache.commons.io.output.NullOutputStream;
|
//import org.apache.commons.io.output.NullOutputStream;
|
||||||
|
|
||||||
public class JavaTXCompiler {
|
public class JavaTXCompiler {
|
||||||
|
|
||||||
final CompilationEnvironment environment;
|
final CompilationEnvironment environment;
|
||||||
Boolean resultmodel = true;
|
Boolean resultmodel = false;
|
||||||
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();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Äußerste Liste der Source-Files.
|
|
||||||
* Danach Liste der Klassen in Source File.
|
|
||||||
* Danach Map Klassenname
|
|
||||||
*/
|
|
||||||
private List<List<HashMap<String, SimplifyResult>>> simplifyResultsSF = new ArrayList<>();
|
|
||||||
|
|
||||||
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
public JavaTXCompiler(File sourceFile) throws IOException, ClassNotFoundException {
|
||||||
this(Arrays.asList(sourceFile));
|
this(Arrays.asList(sourceFile));
|
||||||
@@ -419,7 +407,7 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}).collect(Collectors.toCollection(ArrayList::new));
|
}).collect(Collectors.toCollection(ArrayList::new));
|
||||||
unify.unifyAsync(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm, usedTasks);
|
unify.unifyAsync(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm);
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
System.err.println("kein LogFile");
|
System.err.println("kein LogFile");
|
||||||
@@ -440,7 +428,7 @@ public class JavaTXCompiler {
|
|||||||
Set<Set<UnifyPair>> results = new HashSet<>();
|
Set<Set<UnifyPair>> results = new HashSet<>();
|
||||||
try {
|
try {
|
||||||
Writer logFile = //new OutputStreamWriter(new NullOutputStream());
|
Writer logFile = //new OutputStreamWriter(new NullOutputStream());
|
||||||
new FileWriter(new File(System.getProperty("user.dir")+"/src/test/resources/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName()));
|
new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName()));
|
||||||
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile);
|
IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile);
|
||||||
System.out.println(finiteClosure);
|
System.out.println(finiteClosure);
|
||||||
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
ConstraintSet<UnifyPair> unifyCons = UnifyTypeFactory.convert(cons);
|
||||||
@@ -559,7 +547,7 @@ public class JavaTXCompiler {
|
|||||||
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, usedTasks);
|
unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm);
|
||||||
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();
|
||||||
@@ -567,8 +555,8 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
/* UnifyResultModel End */
|
/* UnifyResultModel End */
|
||||||
else {
|
else {
|
||||||
//Set<Set<UnifyPair>> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure));
|
Set<Set<UnifyPair>> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure));
|
||||||
Set<Set<UnifyPair>> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure), usedTasks);
|
//Set<Set<UnifyPair>> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, 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();
|
||||||
@@ -654,7 +642,7 @@ public class JavaTXCompiler {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
// um pfad erweitern
|
// um pfad erweitern
|
||||||
public void generateBytecode(String path) throws ClassNotFoundException, IOException, BytecodeGeneratorError {
|
public void generateBytecode(String path) throws ClassNotFoundException, IOException {
|
||||||
for(File f : sourceFiles.keySet()) {
|
for(File f : sourceFiles.keySet()) {
|
||||||
HashMap<String,byte[]> classFiles = new HashMap<>();
|
HashMap<String,byte[]> classFiles = new HashMap<>();
|
||||||
SourceFile sf = sourceFiles.get(f);
|
SourceFile sf = sourceFiles.get(f);
|
||||||
@@ -662,7 +650,6 @@ public class JavaTXCompiler {
|
|||||||
BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult,sf,path);
|
BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult,sf,path);
|
||||||
// BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult.get(0));
|
// BytecodeGen bytecodeGen = new BytecodeGen(classFiles,typeinferenceResult.get(0));
|
||||||
bytecodeGen.visit(sf);
|
bytecodeGen.visit(sf);
|
||||||
this.simplifyResultsSF.add(bytecodeGen.getSimplifyResultsList());
|
|
||||||
this.writeClassFile(bytecodeGen.getClassFiles(), path);
|
this.writeClassFile(bytecodeGen.getClassFiles(), path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -679,8 +666,4 @@ public class JavaTXCompiler {
|
|||||||
System.out.println(name+".class file generated");
|
System.out.println(name+".class file generated");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<List<HashMap<String, SimplifyResult>>> getSimplifyResults() {
|
|
||||||
return simplifyResultsSF;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -100,7 +100,7 @@ public class UnifyTypeFactory {
|
|||||||
}
|
}
|
||||||
ret = new ReferenceType(t.getName().toString(),new TypeParams(params));
|
ret = new ReferenceType(t.getName().toString(),new TypeParams(params));
|
||||||
}else{
|
}else{
|
||||||
ret = new ReferenceType(t.getName().toString(), false);
|
ret = new ReferenceType(t.getName().toString());
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -136,7 +136,7 @@ public class UnifyTypeFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static UnifyType convert(GenericRefType t, Boolean innerType){
|
public static UnifyType convert(GenericRefType t, Boolean innerType){
|
||||||
return new ReferenceType(t.getParsedName(), true);
|
return new ReferenceType(t.getParsedName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UnifyType convert(WildcardType t, Boolean innerType){
|
public static UnifyType convert(WildcardType t, Boolean innerType){
|
||||||
@@ -222,15 +222,12 @@ public class UnifyTypeFactory {
|
|||||||
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (RefType) tr);
|
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (RefType) tr);
|
||||||
}else if(tr instanceof WildcardType){
|
}else if(tr instanceof WildcardType){
|
||||||
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (WildcardType) tr);
|
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (WildcardType) tr);
|
||||||
}else if(tr instanceof GenericRefType){
|
|
||||||
return new PairTPHequalRefTypeOrWildcardType((TypePlaceholder)tl, (GenericRefType) tr);
|
|
||||||
}else throw new NotImplementedException();
|
}else throw new NotImplementedException();
|
||||||
}else throw new NotImplementedException();
|
}else throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RefTypeOrTPHOrWildcardOrGeneric convert(ReferenceType t, Map<String,TypePlaceholder> tphs) {
|
public static RefTypeOrTPHOrWildcardOrGeneric convert(ReferenceType t, Map<String,TypePlaceholder> tphs) {
|
||||||
if(JavaClassName.Void.equals(t.getName()))return new Void(new NullToken());
|
if(JavaClassName.Void.equals(t.getName()))return new Void(new NullToken());
|
||||||
if (t.isGenTypeVar()) return new GenericRefType(t.getName(),new NullToken());
|
|
||||||
RefType ret = new RefType(new JavaClassName(t.getName()),convert(t.getTypeParams(), tphs),new NullToken());
|
RefType ret = new RefType(new JavaClassName(t.getName()),convert(t.getTypeParams(), tphs),new NullToken());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@@ -1,23 +1,22 @@
|
|||||||
package de.dhbwstuttgart.typedeployment;
|
package de.dhbwstuttgart.typedeployment;
|
||||||
|
|
||||||
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultPair;
|
|
||||||
|
|
||||||
public class TypeInsert {
|
public class TypeInsert {
|
||||||
/**
|
/**
|
||||||
* point wird hauptsächlich zur Anzeige einer Annotation im Eclipse-plugin benutzt.
|
* point wird hauptsächlich zur Anzeige einer Annotation im Eclipse-plugin benutzt.
|
||||||
*/
|
*/
|
||||||
public final TypeInsertPoint point;
|
public final TypeInsertPoint point;
|
||||||
Set<TypeInsertPoint> inserts;
|
Set<TypeInsertPoint> inserts;
|
||||||
ResultPair<?, ?> resultPair;
|
|
||||||
|
|
||||||
public TypeInsert(TypeInsertPoint point, Set<TypeInsertPoint> additionalPoints, ResultPair<?, ?> resultPair){
|
public TypeInsert(TypeInsertPoint point, Set<TypeInsertPoint> additionalPoints){
|
||||||
this.point = point;
|
this.point = point;
|
||||||
inserts = additionalPoints;
|
inserts = additionalPoints;
|
||||||
this.resultPair = resultPair;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String insert(String intoSource){
|
public String insert(String intoSource){
|
||||||
@@ -35,10 +34,6 @@ public class TypeInsert {
|
|||||||
return point.getInsertString();
|
return point.getInsertString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResultPair<?, ?> getResultPair() {
|
|
||||||
return this.resultPair;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* PL 2018-06-18
|
/* PL 2018-06-18
|
||||||
* Zwei TypeInsert's sind gleich, wenn ihre point's und ihre inserts' gleich sind
|
* Zwei TypeInsert's sind gleich, wenn ihre point's und ihre inserts' gleich sind
|
||||||
* eingefuegt damit man TypeReplaceMarker vergleichen kann
|
* eingefuegt damit man TypeReplaceMarker vergleichen kann
|
||||||
|
@@ -32,7 +32,7 @@ public class TypeInsertFactory {
|
|||||||
ResolvedType resolvedType = resultSet.resolveType(type);
|
ResolvedType resolvedType = resultSet.resolveType(type);
|
||||||
TypeInsertPoint insertPoint = new TypeInsertPoint(offset,
|
TypeInsertPoint insertPoint = new TypeInsertPoint(offset,
|
||||||
new TypeToInsertString(resolvedType.resolvedType).insert);
|
new TypeToInsertString(resolvedType.resolvedType).insert);
|
||||||
return new TypeInsert(insertPoint, new HashSet<>(), resolvedType.getResultPair());
|
return new TypeInsert(insertPoint, new HashSet<>(Arrays.asList(createGenericInsert(resolvedType.additionalGenerics, cl, m))));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TypeInsertPoint createGenericInsert(Set<GenericInsertPair> toInsert, ClassOrInterface cl, Method m){
|
private static TypeInsertPoint createGenericInsert(Set<GenericInsertPair> toInsert, ClassOrInterface cl, Method m){
|
||||||
|
@@ -4,14 +4,12 @@ import org.antlr.v4.runtime.Token;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
|
import de.dhbwstuttgart.typeinference.unify.model.ReferenceType;
|
||||||
|
|
||||||
import java.time.OffsetDateTime;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class TypeInsertPoint {
|
public class TypeInsertPoint {
|
||||||
public Token point;
|
public final Token point;
|
||||||
private String insertString;
|
private String insertString;
|
||||||
private int extraOffset = 0;
|
|
||||||
|
|
||||||
public TypeInsertPoint(Token point, String toInsert){
|
public TypeInsertPoint(Token point, String toInsert){
|
||||||
this.point = point;
|
this.point = point;
|
||||||
@@ -23,21 +21,13 @@ public class TypeInsertPoint {
|
|||||||
//token.point.getLine() != point.getLine() && token.point.getCharPositionInLine() <= point.getCharPositionInLine()))
|
//token.point.getLine() != point.getLine() && token.point.getCharPositionInLine() <= point.getCharPositionInLine()))
|
||||||
token.point.getStartIndex() <= point.getStartIndex()))
|
token.point.getStartIndex() <= point.getStartIndex()))
|
||||||
.mapToInt((typeInsertPoint -> typeInsertPoint.insertString.length())).sum();
|
.mapToInt((typeInsertPoint -> typeInsertPoint.insertString.length())).sum();
|
||||||
return new StringBuilder(intoSource).insert(point.getStartIndex()+offset+extraOffset, insertString).toString();
|
return new StringBuilder(intoSource).insert(point.getStartIndex()+offset, insertString).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getInsertString() {
|
public String getInsertString() {
|
||||||
return insertString;
|
return insertString;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addExtraOffset(int toAdd) {
|
|
||||||
this.extraOffset += toAdd;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPositionInCode() {
|
|
||||||
return point.getStartIndex() + extraOffset;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* PL 2018-06-19
|
/* PL 2018-06-19
|
||||||
* Zwei TypeInsertPoint's sind gleich, wenn ihre point's gleich sind
|
* Zwei TypeInsertPoint's sind gleich, wenn ihre point's gleich sind
|
||||||
* eingefuegt damit man TypeReplaceMarker vergleichen kann
|
* eingefuegt damit man TypeReplaceMarker vergleichen kann
|
||||||
|
@@ -23,9 +23,4 @@ public class GenericInsertPair {
|
|||||||
if(TA2.equals(additionalTPH))return true;
|
if(TA2.equals(additionalTPH))return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "GenIns(" + TA1.toString() + " < " + TA2.toString() + ")";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -21,9 +21,4 @@ public class PairTPHequalRefTypeOrWildcardType extends ResultPair{
|
|||||||
public void accept(ResultPairVisitor visitor) {
|
public void accept(ResultPairVisitor visitor) {
|
||||||
visitor.visit(this);
|
visitor.visit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "(" + left.toString() + " = " + right.toString() + ")";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -20,9 +20,4 @@ public class PairTPHsmallerTPH extends ResultPair{
|
|||||||
public void accept(ResultPairVisitor visitor) {
|
public void accept(ResultPairVisitor visitor) {
|
||||||
visitor.visit(this);
|
visitor.visit(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "(" + left.toString() + " < " + right.toString() + ")";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -7,21 +7,11 @@ import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class ResolvedType{
|
public class ResolvedType{
|
||||||
private ResultPair<?, ?> resultPair;
|
|
||||||
|
|
||||||
public final RefTypeOrTPHOrWildcardOrGeneric resolvedType;
|
public final RefTypeOrTPHOrWildcardOrGeneric resolvedType;
|
||||||
//public final Set<GenericInsertPair> additionalGenerics;
|
public final Set<GenericInsertPair> additionalGenerics;
|
||||||
|
|
||||||
public ResolvedType(RefTypeOrTPHOrWildcardOrGeneric resolvedType, Set<GenericInsertPair> additionalGenerics){
|
public ResolvedType(RefTypeOrTPHOrWildcardOrGeneric resolvedType, Set<GenericInsertPair> additionalGenerics){
|
||||||
this.resolvedType = resolvedType;
|
this.resolvedType = resolvedType;
|
||||||
//this.additionalGenerics = additionalGenerics;
|
this.additionalGenerics = additionalGenerics;
|
||||||
}
|
|
||||||
|
|
||||||
public void setResultPair(ResultPair<?, ?> resultPair) {
|
|
||||||
this.resultPair = resultPair;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ResultPair<?, ?> getResultPair() {
|
|
||||||
return resultPair;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -27,36 +27,4 @@ public abstract class ResultPair<A extends RefTypeOrTPHOrWildcardOrGeneric,B ext
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return "(" + left.toString() + ", " + right.toString() + ")";
|
return "(" + left.toString() + ", " + right.toString() + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
final int prime = 31;
|
|
||||||
int result = 1;
|
|
||||||
result = prime * result + ((left == null) ? 0 : left.getOffset().hashCode());
|
|
||||||
result = prime * result + ((right == null) ? 0 : right.getOffset().hashCode());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj)
|
|
||||||
return true;
|
|
||||||
if (obj == null)
|
|
||||||
return false;
|
|
||||||
if (getClass() != obj.getClass())
|
|
||||||
return false;
|
|
||||||
ResultPair<?,?> other = (ResultPair<?,?>) obj;
|
|
||||||
if (left == null) {
|
|
||||||
if (other.left != null)
|
|
||||||
return false;
|
|
||||||
} else if (!left.getOffset().equals(other.left.getOffset()))
|
|
||||||
return false;
|
|
||||||
if (right == null) {
|
|
||||||
if (other.right != null)
|
|
||||||
return false;
|
|
||||||
} else if (!right.getOffset().equals(other.right.getOffset()))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,34 +1,16 @@
|
|||||||
package de.dhbwstuttgart.typeinference.result;
|
package de.dhbwstuttgart.typeinference.result;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.ExtendsWildcardType;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
public class ResultSet {
|
public class ResultSet {
|
||||||
|
|
||||||
public final Set<ResultPair> results;
|
public final Set<ResultPair> results;
|
||||||
public Set<ResultPair<TypePlaceholder, TypePlaceholder>> genIns;
|
public ResultSet(Set<ResultPair> results){
|
||||||
|
this.results = results;
|
||||||
public ResultSet(Set<ResultPair> set){
|
|
||||||
this.results = set;
|
|
||||||
this.genIns = new HashSet<>();
|
|
||||||
results.forEach(x -> { if (x instanceof PairTPHsmallerTPH) { this.genIns.add(x);}} );
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean contains(ResultPair toCheck) {
|
|
||||||
return this.results.contains(toCheck);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void remove(ResultPair toCheck) {
|
|
||||||
results.remove(toCheck);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResolvedType resolveType(RefTypeOrTPHOrWildcardOrGeneric type) {
|
public ResolvedType resolveType(RefTypeOrTPHOrWildcardOrGeneric type) {
|
||||||
@@ -45,24 +27,12 @@ public class ResultSet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO Beim Einsetzen eines Generics, müssen die new und Methodenaufrufe verändert werden
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return results.toString();
|
return results.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (o instanceof ResultSet) {
|
|
||||||
ResultSet other = (ResultSet)o;
|
|
||||||
return this.results.equals(other.results);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return results.hashCode();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Resolver implements ResultSetVisitor {
|
class Resolver implements ResultSetVisitor {
|
||||||
@@ -70,7 +40,6 @@ class Resolver implements ResultSetVisitor {
|
|||||||
private TypePlaceholder toResolve;
|
private TypePlaceholder toResolve;
|
||||||
private RefTypeOrTPHOrWildcardOrGeneric resolved;
|
private RefTypeOrTPHOrWildcardOrGeneric resolved;
|
||||||
private final Set<GenericInsertPair> additionalTPHs = new HashSet<>();
|
private final Set<GenericInsertPair> additionalTPHs = new HashSet<>();
|
||||||
private ResultPair<?,?> currentPair;
|
|
||||||
|
|
||||||
public Resolver(ResultSet resultPairs){
|
public Resolver(ResultSet resultPairs){
|
||||||
this.result = resultPairs;
|
this.result = resultPairs;
|
||||||
@@ -80,28 +49,23 @@ class Resolver implements ResultSetVisitor {
|
|||||||
toResolve = tph;
|
toResolve = tph;
|
||||||
resolved = null;
|
resolved = null;
|
||||||
System.out.println(tph.toString());
|
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)){
|
||||||
currentPair = resultPair;
|
|
||||||
return resolve(((PairTPHEqualTPH) resultPair).getRight());
|
return resolve(((PairTPHEqualTPH) resultPair).getRight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for(ResultPair<?,?> resultPair : result.results){
|
for(ResultPair resultPair : result.results){
|
||||||
currentPair = resultPair;
|
|
||||||
resultPair.accept(this);
|
resultPair.accept(this);
|
||||||
}
|
}
|
||||||
if(resolved==null){//TPH kommt nicht im Result vor:
|
if(resolved==null){//TPH kommt nicht im Result vor:
|
||||||
resolved = tph;
|
resolved = tph;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResolvedType result = new ResolvedType(resolved, additionalTPHs);//resolved;
|
return new ResolvedType(resolved, additionalTPHs);//resolved;
|
||||||
result.setResultPair(currentPair);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(PairTPHsmallerTPH p) {
|
public void visit(PairTPHsmallerTPH p) {
|
||||||
currentPair = p;
|
|
||||||
if(p.left.equals(toResolve)){
|
if(p.left.equals(toResolve)){
|
||||||
additionalTPHs.add(new GenericInsertPair(p.left, p.right));
|
additionalTPHs.add(new GenericInsertPair(p.left, p.right));
|
||||||
additionalTPHs.addAll(new RelatedTypeWalker(p.right, result).relatedTPHs);
|
additionalTPHs.addAll(new RelatedTypeWalker(p.right, result).relatedTPHs);
|
||||||
@@ -112,7 +76,6 @@ class Resolver implements ResultSetVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(PairTPHequalRefTypeOrWildcardType p) {
|
public void visit(PairTPHequalRefTypeOrWildcardType p) {
|
||||||
currentPair = p;
|
|
||||||
if(p.left.equals(toResolve)){
|
if(p.left.equals(toResolve)){
|
||||||
resolved = p.right;
|
resolved = p.right;
|
||||||
RelatedTypeWalker related = new RelatedTypeWalker(null, result);
|
RelatedTypeWalker related = new RelatedTypeWalker(null, result);
|
||||||
@@ -158,7 +121,6 @@ class Resolver implements ResultSetVisitor {
|
|||||||
/**
|
/**
|
||||||
* Sucht aus dem Result Set den Sub/supertyp für einen TPH
|
* Sucht aus dem Result Set den Sub/supertyp für einen TPH
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
class TPHResolver implements ResultSetVisitor {
|
class TPHResolver implements ResultSetVisitor {
|
||||||
|
|
||||||
private final TypePlaceholder tph;
|
private final TypePlaceholder tph;
|
||||||
@@ -227,7 +189,6 @@ class TPHResolver implements ResultSetVisitor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
class RelatedTypeWalker implements ResultSetVisitor {
|
class RelatedTypeWalker implements ResultSetVisitor {
|
||||||
|
|
||||||
final Set<GenericInsertPair> relatedTPHs = new HashSet<>();
|
final Set<GenericInsertPair> relatedTPHs = new HashSet<>();
|
||||||
|
@@ -312,9 +312,6 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
numericAdditionOrStringConcatenation.add(stringConcat);
|
numericAdditionOrStringConcatenation.add(stringConcat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(numericAdditionOrStringConcatenation.size()<1){
|
|
||||||
throw new TypeinferenceException("Kein Typ für " + binary.operation.toString() + " vorhanden", binary.getOffset());
|
|
||||||
}
|
|
||||||
constraintsSet.addOderConstraint(numericAdditionOrStringConcatenation);
|
constraintsSet.addOderConstraint(numericAdditionOrStringConcatenation);
|
||||||
}else if(binary.operation.equals(BinaryExpr.Operator.LESSEQUAL) ||
|
}else if(binary.operation.equals(BinaryExpr.Operator.LESSEQUAL) ||
|
||||||
binary.operation.equals(BinaryExpr.Operator.BIGGEREQUAL) ||
|
binary.operation.equals(BinaryExpr.Operator.BIGGEREQUAL) ||
|
||||||
@@ -358,7 +355,6 @@ public class TYPEStmt implements StatementVisitor{
|
|||||||
//***ACHTUNG: Moeglicherweise oder und und-Contraint falsch
|
//***ACHTUNG: Moeglicherweise oder und und-Contraint falsch
|
||||||
*/
|
*/
|
||||||
//Testeise eingefuegt PL 2018-05-24
|
//Testeise eingefuegt PL 2018-05-24
|
||||||
//Hier sollte evtl. noch importe angefragt werden PL 2019-05-07
|
|
||||||
constraintsSet.addUndConstraint(new Pair(binary.lexpr.getType(), number, PairOperator.SMALLERNEQDOT));
|
constraintsSet.addUndConstraint(new Pair(binary.lexpr.getType(), number, PairOperator.SMALLERNEQDOT));
|
||||||
constraintsSet.addUndConstraint(new Pair(binary.rexpr.getType(), number, PairOperator.SMALLERNEQDOT));
|
constraintsSet.addUndConstraint(new Pair(binary.rexpr.getType(), number, PairOperator.SMALLERNEQDOT));
|
||||||
//Rückgabetyp ist Boolean
|
//Rückgabetyp ist Boolean
|
||||||
|
@@ -3,12 +3,10 @@ package de.dhbwstuttgart.typeinference.unify;
|
|||||||
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.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ForkJoinPool;
|
import java.util.concurrent.ForkJoinPool;
|
||||||
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
import de.dhbwstuttgart.typeinference.constraints.Pair;
|
||||||
@@ -28,8 +26,8 @@ public class TypeUnify {
|
|||||||
* @param cons
|
* @param cons
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Set<Set<UnifyPair>> unify(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
public Set<Set<UnifyPair>> unify(Set<UnifyPair> undConstrains, List<Set<Set<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 +52,8 @@ public class TypeUnify {
|
|||||||
* @param ret
|
* @param ret
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public UnifyResultModel unifyAsync(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
public UnifyResultModel unifyAsync(Set<UnifyPair> undConstrains, List<Set<Set<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;
|
||||||
@@ -72,8 +70,8 @@ public class TypeUnify {
|
|||||||
* @param ret
|
* @param ret
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public UnifyResultModel unifyParallel(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
public UnifyResultModel unifyParallel(Set<UnifyPair> undConstrains, List<Set<Set<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();
|
||||||
@@ -105,8 +103,8 @@ public class TypeUnify {
|
|||||||
* @param cons
|
* @param cons
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public Set<Set<UnifyPair>> unifyOderConstraints(Set<UnifyPair> undConstrains, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
|
public Set<Set<UnifyPair>> unifyOderConstraints(Set<UnifyPair> undConstrains, List<Set<Set<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");
|
||||||
|
@@ -3,7 +3,6 @@ package de.dhbwstuttgart.typeinference.unify;
|
|||||||
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.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -18,8 +17,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<Set<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<Set<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;
|
||||||
}
|
}
|
||||||
@@ -39,17 +38,9 @@ public class TypeUnify2Task extends TypeUnifyTask {
|
|||||||
return new HashSet<>(); }
|
return new HashSet<>(); }
|
||||||
else
|
else
|
||||||
*/
|
*/
|
||||||
|
|
||||||
noOfThread--;
|
noOfThread--;
|
||||||
synchronized (usedTasks) {
|
|
||||||
if (this.myIsCancelled()) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void closeLogFile() {
|
public void closeLogFile() {
|
||||||
|
|
||||||
|
@@ -19,10 +19,6 @@ import java.util.function.BinaryOperator;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import org.apache.commons.io.output.NullOutputStream;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
import de.dhbwstuttgart.typeinference.constraints.Constraint;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
@@ -48,7 +44,6 @@ import de.dhbwstuttgart.typeinference.unify.model.Pair;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
|
||||||
import com.google.common.collect.Ordering;
|
import com.google.common.collect.Ordering;
|
||||||
@@ -122,10 +117,6 @@ 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();
|
||||||
}
|
}
|
||||||
@@ -145,7 +136,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
public TypeUnifyTask(Set<UnifyPair> eq, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) {
|
public TypeUnifyTask(Set<UnifyPair> eq, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm) {
|
||||||
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));
|
||||||
@@ -172,26 +163,14 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
thNo = totalnoOfThread;
|
thNo = totalnoOfThread;
|
||||||
writeLog("thNo2 " + thNo);
|
writeLog("thNo2 " + thNo);
|
||||||
try {
|
try {
|
||||||
this.logFile = //new OutputStreamWriter(new NullOutputStream());
|
this.logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"Thread_"+thNo));
|
||||||
new FileWriter(new File(System.getProperty("user.dir")+"/src/test/resources/logFiles/"+"Thread_"+thNo));
|
|
||||||
logFile.write("");
|
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
System.err.println("log-File nicht vorhanden");
|
System.err.println("log-File nicht vorhanden");
|
||||||
}
|
}
|
||||||
/*Abbruchtest
|
|
||||||
if (thNo > 10) {
|
|
||||||
System.out.println("cancel");
|
|
||||||
usedTasks.cancel();
|
|
||||||
writeLog(nOfUnify.toString() + "cancel");
|
|
||||||
System.out.println("cancel");
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,13 +206,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
void myCancel(Boolean b) {
|
|
||||||
myIsCanceled = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean myIsCancelled() {
|
|
||||||
return myIsCanceled;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Set<Set<UnifyPair>> compute() {
|
protected Set<Set<UnifyPair>> compute() {
|
||||||
if (one) {
|
if (one) {
|
||||||
@@ -256,19 +228,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
catch (IOException ioE) {
|
catch (IOException ioE) {
|
||||||
System.err.println("no log-File");
|
System.err.println("no log-File");
|
||||||
}
|
}
|
||||||
if (isUndefinedPairSetSet(res)) {
|
if (isUndefinedPairSetSet(res)) { return new HashSet<>(); }
|
||||||
throw new TypeinferenceException("Unresolved constraints: " + res.toString(), new NullToken()); //return new HashSet<>();
|
else return res;
|
||||||
}
|
|
||||||
else {
|
|
||||||
synchronized (usedTasks) {
|
|
||||||
if (this.myIsCancelled()) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@Override
|
@Override
|
||||||
@@ -302,7 +263,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
/*
|
/*
|
||||||
* Step 1: Repeated application of reduce, adapt, erase, swap
|
* Step 1: Repeated application of reduce, adapt, erase, swap
|
||||||
*/
|
*/
|
||||||
|
|
||||||
rekTiefe++;
|
rekTiefe++;
|
||||||
nOfUnify++;
|
nOfUnify++;
|
||||||
writeLog(nOfUnify.toString() + " Unifikation: " + eq.toString());
|
writeLog(nOfUnify.toString() + " Unifikation: " + eq.toString());
|
||||||
@@ -462,8 +422,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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Set<Set<UnifyPair>> eqPrimePrimeSet = new HashSet<>();
|
Set<Set<UnifyPair>> eqPrimePrimeSet = new HashSet<>();
|
||||||
|
|
||||||
Set<TypeUnifyTask> forks = new HashSet<>();
|
Set<TypeUnifyTask> forks = new HashSet<>();
|
||||||
@@ -520,16 +478,15 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
//PL 2018-05-18 beide Bedingungen muessen gelten, da eqPrime Veränderungen in allem ausser subst
|
//PL 2018-05-18 beide Bedingungen muessen gelten, da eqPrime Veränderungen in allem ausser subst
|
||||||
//eqPrimePrime Veraenderungen in subst repraesentieren.
|
//eqPrimePrime Veraenderungen in subst repraesentieren.
|
||||||
//try {
|
//try {
|
||||||
//if (isSolvedForm(eqPrime)) {
|
if (isSolvedForm(eqPrime)) {
|
||||||
// writeLog("eqPrime:" + eqPrime.toString()+"\n");
|
writeLog("eqPrime:" + eqPrime.toString()+"\n");
|
||||||
//}
|
}
|
||||||
//}
|
//}
|
||||||
//catch (IOException e) {
|
//catch (IOException e) {
|
||||||
// System.err.println("log-File nicht vorhanden");
|
// System.err.println("log-File nicht vorhanden");
|
||||||
//}
|
//}
|
||||||
eqPrimePrimeSet.add(eqPrime);
|
eqPrimePrimeSet.add(eqPrime);
|
||||||
if (finalresult && isSolvedForm(eqPrime)) {
|
if (finalresult) {
|
||||||
writeLog("eqPrime:" + eqPrime.toString()+"\n");
|
|
||||||
urm.notify(eqPrimePrimeSet);
|
urm.notify(eqPrimePrimeSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -573,7 +530,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
Set<Set<UnifyPair>> computeCartesianRecursive(Set<Set<UnifyPair>> fstElems, ArrayList<Set<Set<UnifyPair>>> topLevelSets, Set<UnifyPair> eq, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) {
|
Set<Set<UnifyPair>> computeCartesianRecursive(Set<Set<UnifyPair>> fstElems, ArrayList<Set<Set<UnifyPair>>> topLevelSets, Set<UnifyPair> eq, List<Set<Set<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe, Boolean finalresult) {
|
||||||
//ArrayList<Set<Set<UnifyPair>>> remainingSets = new ArrayList<>(topLevelSets);
|
//ArrayList<Set<Set<UnifyPair>>> remainingSets = new ArrayList<>(topLevelSets);
|
||||||
|
|
||||||
fstElems.addAll(topLevelSets.stream()
|
fstElems.addAll(topLevelSets.stream()
|
||||||
.filter(x -> x.size()==1)
|
.filter(x -> x.size()==1)
|
||||||
.map(y -> y.stream().findFirst().get())
|
.map(y -> y.stream().findFirst().get())
|
||||||
@@ -838,14 +794,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
newElemsOrig.add(a);
|
newElemsOrig.add(a);
|
||||||
|
|
||||||
/* 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);
|
||||||
//forks.add(forkOrig);
|
//forks.add(forkOrig);
|
||||||
synchronized(usedTasks) {
|
|
||||||
if (this.myIsCancelled()) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
forkOrig.fork();
|
forkOrig.fork();
|
||||||
}
|
|
||||||
/* FORK ENDE */
|
/* FORK ENDE */
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
@@ -890,15 +841,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
||||||
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||||
newElems.add(nSaL);
|
newElems.add(nSaL);
|
||||||
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm);
|
||||||
forks.add(fork);
|
forks.add(fork);
|
||||||
synchronized(usedTasks) {
|
|
||||||
if (this.myIsCancelled()) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
fork.fork();
|
fork.fork();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
//res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
|
//res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
|
||||||
|
|
||||||
/* FORK ANFANG */
|
/* FORK ANFANG */
|
||||||
@@ -941,14 +887,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
newElemsOrig.add(a);
|
newElemsOrig.add(a);
|
||||||
|
|
||||||
/* 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);
|
||||||
//forks.add(forkOrig);
|
//forks.add(forkOrig);
|
||||||
synchronized(usedTasks) {
|
|
||||||
if (this.myIsCancelled()) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
forkOrig.fork();
|
forkOrig.fork();
|
||||||
}
|
|
||||||
/* FORK ENDE */
|
/* FORK ENDE */
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
@@ -993,15 +934,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
||||||
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||||
newElems.add(nSaL);
|
newElems.add(nSaL);
|
||||||
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm);
|
||||||
forks.add(fork);
|
forks.add(fork);
|
||||||
synchronized(usedTasks) {
|
|
||||||
if (this.myIsCancelled()) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
fork.fork();
|
fork.fork();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
//res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
|
//res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
|
||||||
|
|
||||||
/* FORK ANFANG */
|
/* FORK ANFANG */
|
||||||
@@ -1045,14 +981,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
newElemsOrig.add(a);
|
newElemsOrig.add(a);
|
||||||
|
|
||||||
/* 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);
|
||||||
//forks.add(forkOrig);
|
//forks.add(forkOrig);
|
||||||
synchronized(usedTasks) {
|
|
||||||
if (this.myIsCancelled()) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
forkOrig.fork();
|
forkOrig.fork();
|
||||||
}
|
|
||||||
/* FORK ENDE */
|
/* FORK ENDE */
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
@@ -1066,15 +997,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
||||||
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||||
newElems.add(nSaL);
|
newElems.add(nSaL);
|
||||||
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks);
|
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm);
|
||||||
forks.add(fork);
|
forks.add(fork);
|
||||||
synchronized(usedTasks) {
|
|
||||||
if (this.myIsCancelled()) {
|
|
||||||
return new HashSet<>();
|
|
||||||
}
|
|
||||||
fork.fork();
|
fork.fork();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
//res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
|
//res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
|
||||||
|
|
||||||
/* FORK ANFANG */
|
/* FORK ANFANG */
|
||||||
@@ -1110,6 +1036,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) {
|
if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) {
|
||||||
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
|
//wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen
|
||||||
result = res;
|
result = res;
|
||||||
|
if (res.iterator().next() instanceof WildcardType) {
|
||||||
|
System.out.println("");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result))
|
if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result))
|
||||||
@@ -1137,9 +1066,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
|
|
||||||
//Alle Variablen bestimmen die nicht hinzugefügt wurden in a_last
|
//Alle Variablen bestimmen die nicht hinzugefügt wurden in a_last
|
||||||
//System.out.println(a_last);
|
//System.out.println(a_last);
|
||||||
|
a_last.forEach(x -> {writeLog("a_last_elem:" + x + " basepair: " + x.getBasePair());});
|
||||||
try {//PL eingefuegt 2019-03-06 da bei map mmer wieder Nullpointer kamen
|
try {//PL eingefuegt 2019-03-06 da bei map mmer wieder Nullpointer kamen
|
||||||
a_last.forEach(x -> {writeLog("a_last_elem:" + x + " basepair: " + x.getBasePair());});//PL 2019-05-13 ins try hinzugefuegt Nullpointer-Exception ist in der Zeile aufgetaucht.
|
|
||||||
List<PlaceholderType> varsLast_a =
|
List<PlaceholderType> varsLast_a =
|
||||||
a_last.stream().filter(x -> ((x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName())
|
a_last.stream().filter(x -> ((x.getLhsType().getName().equals(x.getBasePair().getLhsType().getName())
|
||||||
&& (x.getLhsType() instanceof PlaceholderType) && (x.getBasePair().getLhsType() instanceof PlaceholderType))
|
&& (x.getLhsType() instanceof PlaceholderType) && (x.getBasePair().getLhsType() instanceof PlaceholderType))
|
||||||
|
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -11,43 +11,26 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.UnifyTypeVisitor;
|
|||||||
* @author Florian Steurer
|
* @author Florian Steurer
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ReferenceType extends UnifyType {
|
public final class ReferenceType extends UnifyType {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The buffered hashCode
|
* The buffered hashCode
|
||||||
*/
|
*/
|
||||||
private final int hashCode;
|
private final int hashCode;
|
||||||
|
|
||||||
/**
|
|
||||||
* gibt an, ob der ReferenceType eine generische Typvariable ist
|
|
||||||
*/
|
|
||||||
private final boolean genericTypeVar;
|
|
||||||
|
|
||||||
|
|
||||||
public <T> UnifyType accept(UnifyTypeVisitor<T> visitor, T ht) {
|
public <T> UnifyType accept(UnifyTypeVisitor<T> visitor, T ht) {
|
||||||
return visitor.visit(this, ht);
|
return visitor.visit(this, ht);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReferenceType(String name, Boolean genericTypeVar) {
|
|
||||||
super(name, new TypeParams());
|
|
||||||
hashCode = 31 + 17 * typeName.hashCode() + 17 * typeParams.hashCode();
|
|
||||||
this.genericTypeVar = genericTypeVar;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ReferenceType(String name, UnifyType... params) {
|
public ReferenceType(String name, UnifyType... params) {
|
||||||
super(name, new TypeParams(params));
|
super(name, new TypeParams(params));
|
||||||
hashCode = 31 + 17 * typeName.hashCode() + 17 * typeParams.hashCode();
|
hashCode = 31 + 17 * typeName.hashCode() + 17 * typeParams.hashCode();
|
||||||
genericTypeVar = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReferenceType(String name, TypeParams params) {
|
public ReferenceType(String name, TypeParams params) {
|
||||||
super(name, params);
|
super(name, params);
|
||||||
hashCode = 31 + 17 * typeName.hashCode() + 17 * typeParams.hashCode();
|
hashCode = 31 + 17 * typeName.hashCode() + 17 * typeParams.hashCode();
|
||||||
genericTypeVar = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isGenTypeVar () {
|
|
||||||
return genericTypeVar;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -137,7 +137,7 @@ public class UnifyPair {
|
|||||||
undefinedPair = true;
|
undefinedPair = true;
|
||||||
}
|
}
|
||||||
public Set<UnifyPair> getSubstitution() {
|
public Set<UnifyPair> getSubstitution() {
|
||||||
return new HashSet<>(substitution);
|
return substitution;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UnifyPair getBasePair() {
|
public UnifyPair getBasePair() {
|
||||||
@@ -149,9 +149,9 @@ public class UnifyPair {
|
|||||||
|
|
||||||
public Set<UnifyPair> getAllSubstitutions () {
|
public Set<UnifyPair> getAllSubstitutions () {
|
||||||
Set<UnifyPair> ret = new HashSet<>();
|
Set<UnifyPair> ret = new HashSet<>();
|
||||||
ret.addAll(new ArrayList<>(getSubstitution()));
|
ret.addAll(getSubstitution());
|
||||||
if (basePair != null) {
|
if (basePair != null) {
|
||||||
ret.addAll(new ArrayList<>(basePair.getAllSubstitutions()));
|
ret.addAll(basePair.getAllSubstitutions());
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@@ -1,37 +0,0 @@
|
|||||||
package bytecode;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLClassLoader;
|
|
||||||
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
|
||||||
|
|
||||||
public class ClassGenLamTest {
|
|
||||||
|
|
||||||
private static String path;
|
|
||||||
private static File fileToTest;
|
|
||||||
private static JavaTXCompiler compiler;
|
|
||||||
private static ClassLoader loader;
|
|
||||||
private static Class<?> classToTest;
|
|
||||||
private static String pathToClassFile;
|
|
||||||
private static Object instanceOfClass;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void generateBC() throws Exception {
|
|
||||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/ClassGenLam.jav";
|
|
||||||
fileToTest = new File(path);
|
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
|
||||||
compiler.generateBytecode(pathToClassFile);
|
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
|
||||||
classToTest = loader.loadClass("ClassGenLam");
|
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -12,7 +12,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
|
|
||||||
public class OLFunTest {
|
public class FunOLTest {
|
||||||
private static String path;
|
private static String path;
|
||||||
private static File fileToTest;
|
private static File fileToTest;
|
||||||
private static JavaTXCompiler compiler;
|
private static JavaTXCompiler compiler;
|
||||||
@@ -23,13 +23,13 @@ public class OLFunTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void generateBC() throws Exception {
|
public void generateBC() throws Exception {
|
||||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/OLFun.jav";
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/FunOL.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass("OLFun");
|
classToTest = loader.loadClass("FunOL");
|
||||||
/*
|
/*
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||||
|
|
@@ -1,38 +0,0 @@
|
|||||||
package bytecode;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLClassLoader;
|
|
||||||
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
|
||||||
|
|
||||||
public class TypedIDTest {
|
|
||||||
|
|
||||||
private static String path;
|
|
||||||
private static File fileToTest;
|
|
||||||
private static JavaTXCompiler compiler;
|
|
||||||
private static ClassLoader loader;
|
|
||||||
private static Class<?> classToTest;
|
|
||||||
private static String pathToClassFile;
|
|
||||||
private static Object instanceOfClass;
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test() throws Exception {
|
|
||||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/TypedID.jav";
|
|
||||||
fileToTest = new File(path);
|
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
|
||||||
compiler.generateBytecode(System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/");
|
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
|
||||||
classToTest = loader.loadClass("TypedID");
|
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -1,45 +0,0 @@
|
|||||||
package bytecode;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLClassLoader;
|
|
||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
|
||||||
|
|
||||||
public class VectorSuperTest {
|
|
||||||
|
|
||||||
private static String path;
|
|
||||||
private static File fileToTest;
|
|
||||||
private static JavaTXCompiler compiler;
|
|
||||||
private static ClassLoader loader;
|
|
||||||
private static Class<?> classToTest;
|
|
||||||
private static String pathToClassFile;
|
|
||||||
private static Object instanceOfClass;
|
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void setUpBeforeClass() throws Exception {
|
|
||||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/VectorSuper.jav";
|
|
||||||
fileToTest = new File(path);
|
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
|
||||||
compiler.generateBytecode(pathToClassFile);
|
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
|
||||||
classToTest = loader.loadClass("VectorSuper");
|
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test1() throws Exception {
|
|
||||||
Method m = classToTest.getDeclaredMethod("m", Vector.class);
|
|
||||||
//Object result = m.invoke(instanceOfClass, 1);
|
|
||||||
|
|
||||||
//assertEquals(1,result);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
package bytecode;
|
package bytecode;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@@ -1,8 +0,0 @@
|
|||||||
import java.lang.Integer;
|
|
||||||
|
|
||||||
public class ClassGenLam {
|
|
||||||
lam = x-> x;
|
|
||||||
// public ClassGenLam() {
|
|
||||||
// lam = x->x;
|
|
||||||
// }
|
|
||||||
}
|
|
@@ -1,6 +1,4 @@
|
|||||||
import java.lang.Integer;
|
import java.lang.Integer;
|
||||||
import java.lang.Long;
|
|
||||||
import java.lang.Short;
|
|
||||||
|
|
||||||
public class Faculty {
|
public class Faculty {
|
||||||
public fact;
|
public fact;
|
||||||
@@ -19,7 +17,6 @@ public class Faculty {
|
|||||||
public getFact(x) {
|
public getFact(x) {
|
||||||
return fact.apply(x);
|
return fact.apply(x);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// m (x) {
|
// m (x) {
|
||||||
//
|
//
|
||||||
//// var fact = (x) -> {
|
//// var fact = (x) -> {
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
public class Id {
|
public class Id<FTU extends FTT,FTT> {
|
||||||
|
|
||||||
id(b){
|
id(FTU b){
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -8,4 +8,3 @@ public class Lambda {
|
|||||||
};
|
};
|
||||||
return lam1;
|
return lam1;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@@ -19,7 +19,7 @@ public class Matrix extends Vector<Vector<Integer>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mul(m) {
|
mul(java.util.Vector<? extends Vector<? extends java.lang.Integer>> m) {
|
||||||
var ret = new Matrix();
|
var ret = new Matrix();
|
||||||
var i = 0;
|
var i = 0;
|
||||||
while(i < size()) {
|
while(i < size()) {
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
import java.lang.Integer;
|
import java.lang.Integer;
|
||||||
//import java.lang.Byte;
|
import java.lang.Byte;
|
||||||
import java.lang.Boolean;
|
import java.lang.Boolean;
|
||||||
|
|
||||||
public class MatrixOP extends Vector<Vector<Integer>> {
|
public class MatrixOP extends Vector<Vector<Integer>> {
|
||||||
@@ -18,7 +18,7 @@ public class MatrixOP extends Vector<Vector<Integer>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public mul = (m1, m2) -> {
|
Fun2$$<java.util.Vector<? extends java.util.Vector<? extends java.lang.Byte>>, java.util.Vector<? extends java.util.Vector<? extends java.lang.Byte>>, MatrixOP> mul = (m1, m2) -> {
|
||||||
var ret = new MatrixOP();
|
var ret = new MatrixOP();
|
||||||
var i = 0;
|
var i = 0;
|
||||||
while(i < m1.size()) {
|
while(i < m1.size()) {
|
||||||
|
@@ -10,6 +10,8 @@ public class OL {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class OLMain {
|
public class OLMain {
|
||||||
|
|
||||||
main(x) {
|
main(x) {
|
||||||
|
@@ -1,17 +0,0 @@
|
|||||||
import java.lang.String;
|
|
||||||
import java.lang.Integer;
|
|
||||||
import java.lang.Double;
|
|
||||||
import java.util.Vector;
|
|
||||||
import java.lang.Boolean;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class OLFun {
|
|
||||||
|
|
||||||
//f = x -> {return x + x;};
|
|
||||||
|
|
||||||
m(f, x) {
|
|
||||||
x = f.apply(x+x);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,12 +0,0 @@
|
|||||||
public class TypedID/*<L extends K,K> */ {
|
|
||||||
|
|
||||||
lam = x-> x;
|
|
||||||
|
|
||||||
id(b){
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
|
|
||||||
m(){
|
|
||||||
return lam;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,11 +0,0 @@
|
|||||||
import java.util.Vector;
|
|
||||||
import java.lang.Integer;
|
|
||||||
|
|
||||||
public class VectorSuper {
|
|
||||||
|
|
||||||
m(x){
|
|
||||||
Integer y = 1;
|
|
||||||
x.addElement(y);
|
|
||||||
//return x;
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user