forked from i21017/JavaCompilerCore
Compare commits
1 Commits
feat/unify
...
c10acc020e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c10acc020e |
@@ -26,7 +26,7 @@ public class UnifyResultModel {
|
|||||||
this.fc = fc;
|
this.fc = fc;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<UnifyResultListener> listeners = new ArrayList<>();
|
private final List<UnifyResultListener> listeners = new ArrayList<>();
|
||||||
|
|
||||||
public void addUnifyResultListener(UnifyResultListener listenerToAdd) {
|
public void addUnifyResultListener(UnifyResultListener listenerToAdd) {
|
||||||
listeners.add(listenerToAdd);
|
listeners.add(listenerToAdd);
|
||||||
@@ -35,25 +35,31 @@ public class UnifyResultModel {
|
|||||||
public void removeUnifyResultListener(UnifyResultListener listenerToRemove) {
|
public void removeUnifyResultListener(UnifyResultListener listenerToRemove) {
|
||||||
listeners.remove(listenerToRemove);
|
listeners.remove(listenerToRemove);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void notify(Set<Set<UnifyPair>> eqPrimePrimeSet, UnifyContext context) {
|
private synchronized void announceResult(UnifyResultEvent event) {
|
||||||
Set<Set<UnifyPair>> eqPrimePrimeSetRet = eqPrimePrimeSet.stream().map(x -> {
|
|
||||||
Optional<Set<UnifyPair>> res = new RuleSet(context.placeholderRegistry()).subst(x.stream().map(y -> {
|
|
||||||
if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT);
|
|
||||||
return y; //alle Paare a <.? b erden durch a =. b ersetzt
|
|
||||||
}).collect(Collectors.toCollection(HashSet::new)));
|
|
||||||
if (res.isPresent()) {//wenn subst ein Erg liefert wurde was veraendert
|
|
||||||
return new TypeUnifyTask(context).applyTypeUnificationRules(res.get(), fc);
|
|
||||||
}
|
|
||||||
else return x; //wenn nichts veraendert wurde wird x zurueckgegeben
|
|
||||||
}).collect(Collectors.toCollection(HashSet::new));
|
|
||||||
List<ResultSet> newResult = eqPrimePrimeSetRet.stream().map(unifyPairs ->
|
|
||||||
new ResultSet(UnifyTypeFactory.convert(unifyPairs, de.dhbwstuttgart.typeinference.constraints.Pair.generateTPHMap(cons), context.placeholderRegistry())))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
UnifyResultEvent evt = new UnifyResultEvent(newResult);
|
|
||||||
|
|
||||||
for (UnifyResultListener listener : listeners) {
|
for (UnifyResultListener listener : listeners) {
|
||||||
listener.onNewTypeResultFound(evt);
|
listener.onNewTypeResultFound(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void notify(Set<Set<UnifyPair>> eqPrimePrimeSet, UnifyContext context) {
|
||||||
|
context.executor().execute(() -> {
|
||||||
|
Set<Set<UnifyPair>> eqPrimePrimeSetRet = eqPrimePrimeSet.stream().map(x -> {
|
||||||
|
Optional<Set<UnifyPair>> res = new RuleSet(context.placeholderRegistry()).subst(x.stream().map(y -> {
|
||||||
|
if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT);
|
||||||
|
return y; //alle Paare a <.? b erden durch a =. b ersetzt
|
||||||
|
}).collect(Collectors.toCollection(HashSet::new)));
|
||||||
|
if (res.isPresent()) {//wenn subst ein Erg liefert wurde was veraendert
|
||||||
|
return new TypeUnifyTask(context).applyTypeUnificationRules(res.get(), fc);
|
||||||
|
}
|
||||||
|
else return x; //wenn nichts veraendert wurde wird x zurueckgegeben
|
||||||
|
}).collect(Collectors.toCollection(HashSet::new));
|
||||||
|
List<ResultSet> newResult = eqPrimePrimeSetRet.stream().map(unifyPairs ->
|
||||||
|
new ResultSet(UnifyTypeFactory.convert(unifyPairs, de.dhbwstuttgart.typeinference.constraints.Pair.generateTPHMap(cons), context.placeholderRegistry())))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
UnifyResultEvent evt = new UnifyResultEvent(newResult);
|
||||||
|
|
||||||
|
this.announceResult(evt);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user