use of mb.nabl2.terms.unification.IUnifier in project spoofax by metaborg.
the class AbstractConstraintAnalyzer method message.
private IMessage message(ITerm originatingTerm, IMessageInfo messageInfo, MessageSeverity severity, IUnifier unifier, C context, FileObject defaultLocation) {
Optional<TermOrigin> maybeOrigin = TermOrigin.get(originatingTerm);
if (maybeOrigin.isPresent()) {
TermOrigin origin = maybeOrigin.get();
ISourceRegion region = JSGLRSourceRegionFactory.fromTokens(origin.getLeftToken(), origin.getRightToken());
FileObject resource = resourceService.resolve(context.location(), origin.getResource());
String message = messageInfo.getContent().apply(unifier::findRecursive).toString(prettyprint(context, resource(resource, context)));
return MessageFactory.newAnalysisMessage(resource, region, message, severity, null);
} else {
String message = messageInfo.getContent().apply(unifier::findRecursive).toString(prettyprint(context, null));
return MessageFactory.newAnalysisMessageAtTop(defaultLocation, message, severity, null);
}
}
use of mb.nabl2.terms.unification.IUnifier in project nabl by metaborg.
the class UnificationPerformanceTest method testUnify.
private static IUnifier testUnify(int n) {
final IUnifier.Transient unifier = PersistentUnifier.Transient.of();
final ITerm left = TermBuild.B.newTuple(Iterables.concat(createVars(A, n), createTuples(B, n), Iterables2.singleton(createVar(A, n))));
final ITerm right = TermBuild.B.newTuple(Iterables.concat(createTuples(A, n), createVars(B, n), Iterables2.singleton(createVar(B, n))));
try {
unifier.unify(left, right);
} catch (UnificationException e) {
System.err.println("Unification failed");
e.printStackTrace(System.err);
}
System.out.println("ground = " + unifier.isGround(left));
System.out.println("cyclic = " + unifier.isCyclic(left));
System.out.println("size = " + unifier.size(left));
System.out.println("vars = " + unifier.getVars(left));
System.out.println("equal = " + unifier.areEqual(left, right));
System.out.println("unequal = " + unifier.areUnequal(left, right));
return unifier;
}
use of mb.nabl2.terms.unification.IUnifier in project nabl by metaborg.
the class VarMultimap method remove.
public boolean remove(ITermVar key, T value, IUnifier unifier) {
final Set<ITermVar> reps = unifier.getVars(key);
boolean change = false;
for (ITermVar rep : reps) {
change |= map.remove(rep, value);
}
return change;
}
use of mb.nabl2.terms.unification.IUnifier in project nabl by metaborg.
the class VarMultimap method put.
public boolean put(ITermVar key, T value, IUnifier unifier) {
final Set<ITermVar> reps = unifier.getVars(key);
boolean change = false;
for (ITermVar rep : reps) {
change |= map.put(rep, value);
}
return change;
}
use of mb.nabl2.terms.unification.IUnifier in project nabl by metaborg.
the class TermMultiset method update.
public boolean update(Collection<ITermVar> vars, IUnifier unifier) {
final Set<ITerm> updatedTerms = vars.stream().flatMap(var -> varTerms.removeAll(var).stream()).collect(Collectors.toSet());
for (ITerm term : updatedTerms) {
final int n = terms.remove(term, terms.count(term));
varTerms.values().remove(term);
add(term, n, unifier);
}
return !updatedTerms.isEmpty();
}
Aggregations