Search in sources :

Example 71 with ITerm

use of mb.nabl2.terms.ITerm in project nabl by metaborg.

the class PersistentUnifier method getVars.

private void getVars(final ITermVar var, final LinkedList<ITermVar> stack, final Set<ITermVar> visited, Set<ITermVar> vars) {
    final ITermVar rep = findRep(var);
    if (!visited.contains(rep)) {
        visited.add(rep);
        stack.push(rep);
        final ITerm term = terms().get(rep);
        if (term != null) {
            getVars(term.getVars().elementSet(), stack, visited, vars);
        } else {
            vars.add(rep);
        }
        stack.pop();
    } else {
        // linear
        final int index = stack.indexOf(rep);
        if (index >= 0) {
            vars.addAll(stack.subList(0, index + 1));
        }
    }
}
Also used : ITermVar(mb.nabl2.terms.ITermVar) ITerm(mb.nabl2.terms.ITerm)

Example 72 with ITerm

use of mb.nabl2.terms.ITerm in project nabl by metaborg.

the class HashcodeAndEqualsTest method testSpecializedEqual.

@Test
public void testSpecializedEqual() {
    ITerm t1 = ImmutableSpecializedAppl.of("Hello, world!", 42);
    ITerm t2 = ImmutableSpecializedAppl.of("Hello, world!", 42);
    assertEquals(t1.hashCode(), t2.hashCode());
    assertTrue(t1.equals(t2));
}
Also used : ITerm(mb.nabl2.terms.ITerm) Test(org.junit.Test)

Example 73 with ITerm

use of mb.nabl2.terms.ITerm in project nabl by metaborg.

the class HashcodeAndEqualsTest method testGenericApplEqualsSepcializedAfterSerialization.

@Test
public void testGenericApplEqualsSepcializedAfterSerialization() throws Exception {
    ITerm t1 = deserialize(serialize(B.newAppl(SpecializedAppl.OP, B.newString("Hello, world!"), B.newInt(42))));
    ITerm t2 = ImmutableSpecializedAppl.of("Hello, world!", 42);
    assertEquals(t1.hashCode(), t2.hashCode());
    assertTrue(t1.equals(t2));
}
Also used : ITerm(mb.nabl2.terms.ITerm) Test(org.junit.Test)

Example 74 with ITerm

use of mb.nabl2.terms.ITerm in project nabl by metaborg.

the class HashcodeAndEqualsTest method testSpecializedAndGenericEqual.

@Test
public void testSpecializedAndGenericEqual() {
    ITerm t1 = ImmutableSpecializedAppl.of("Hello, world!", 42);
    ITerm t2 = B.newAppl(SpecializedAppl.OP, B.newString("Hello, world!"), B.newInt(42));
    assertEquals(t1.hashCode(), t2.hashCode());
    assertTrue(t1.equals(t2));
}
Also used : ITerm(mb.nabl2.terms.ITerm) Test(org.junit.Test)

Example 75 with ITerm

use of mb.nabl2.terms.ITerm in project nabl by metaborg.

the class HashcodeAndEqualsTest method testSameApplNullaryCtors.

@Test
public void testSameApplNullaryCtors() {
    ITerm t1 = B.newAppl("Ctor");
    ITerm t2 = B.newAppl("Ctor");
    assertEquals(t1.hashCode(), t2.hashCode());
    assertTrue(t1.equals(t2));
}
Also used : ITerm(mb.nabl2.terms.ITerm) Test(org.junit.Test)

Aggregations

ITerm (mb.nabl2.terms.ITerm)79 Test (org.junit.Test)24 Occurrence (mb.nabl2.scopegraph.terms.Occurrence)19 Scope (mb.nabl2.scopegraph.terms.Scope)18 SolveResult (mb.nabl2.solver.ISolver.SolveResult)16 Optional (java.util.Optional)15 IMessageInfo (mb.nabl2.constraints.messages.IMessageInfo)15 ITermVar (mb.nabl2.terms.ITermVar)15 Label (mb.nabl2.scopegraph.terms.Label)14 Map (java.util.Map)12 Set (java.util.Set)10 MessageContent (mb.nabl2.constraints.messages.MessageContent)10 SolverCore (mb.nabl2.solver.SolverCore)9 IUnifier (mb.nabl2.terms.unification.IUnifier)9 Function1 (org.metaborg.util.functions.Function1)9 Lists (com.google.common.collect.Lists)8 ISolution (mb.nabl2.solver.ISolution)8 HashMultimap (com.google.common.collect.HashMultimap)7 Multimap (com.google.common.collect.Multimap)7 IConstraint (mb.nabl2.constraints.IConstraint)7