Search in sources :

Example 1 with IUnifier

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);
    }
}
Also used : ISourceRegion(org.metaborg.core.source.ISourceRegion) FileObject(org.apache.commons.vfs2.FileObject) TermOrigin(mb.nabl2.stratego.TermOrigin)

Example 2 with IUnifier

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;
}
Also used : ITerm(mb.nabl2.terms.ITerm)

Example 3 with IUnifier

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;
}
Also used : ITermVar(mb.nabl2.terms.ITermVar)

Example 4 with IUnifier

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;
}
Also used : ITermVar(mb.nabl2.terms.ITermVar)

Example 5 with IUnifier

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();
}
Also used : IUnifier(mb.nabl2.terms.unification.IUnifier) HashMultimap(com.google.common.collect.HashMultimap) HashMultiset(com.google.common.collect.HashMultiset) ITerm(mb.nabl2.terms.ITerm) Multiset(com.google.common.collect.Multiset) Collection(java.util.Collection) ITermVar(mb.nabl2.terms.ITermVar) Set(java.util.Set) Multimap(com.google.common.collect.Multimap) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) ITerm(mb.nabl2.terms.ITerm)

Aggregations

ITermVar (mb.nabl2.terms.ITermVar)8 ITerm (mb.nabl2.terms.ITerm)4 HashMultimap (com.google.common.collect.HashMultimap)1 HashMultiset (com.google.common.collect.HashMultiset)1 Multimap (com.google.common.collect.Multimap)1 Multiset (com.google.common.collect.Multiset)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 TermOrigin (mb.nabl2.stratego.TermOrigin)1 IUnifier (mb.nabl2.terms.unification.IUnifier)1 FileObject (org.apache.commons.vfs2.FileObject)1 ISourceRegion (org.metaborg.core.source.ISourceRegion)1