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));
}
}
}
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));
}
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));
}
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));
}
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));
}
Aggregations