Search in sources :

Example 1 with AddExp

use of abs.frontend.ast.AddExp in project abstools by abstools.

the class TreeUtilsTest method recurseForSome.

@Test
public void recurseForSome() {
    Model model = assertParseOkStdLib("def Int test(Int i) = 1 + test(2);");
    FunctionDecl functionDecl = getLastFunctionDecl(model);
    assertEquals("test", functionDecl.getName());
    FunctionDef def = functionDecl.getFunctionDef();
    Stream<PureExp> children = def.findChildren(cast(PureExp.class), AddExp.class::isInstance);
    assertNotNull(children);
    List<PureExp> result = children.distinct().collect(Collectors.toList());
    // expecting AddExp, IntLiteral(1), FnApp, NOT IntLiteral(2)
    assertEquals(3, result.size());
    for (PureExp exp : result) {
        assertFalse(exp instanceof IntLiteral && ((IntLiteral) exp).getContent().equals("2"));
    }
}
Also used : AddExp(abs.frontend.ast.AddExp) Model(abs.frontend.ast.Model) FunctionDef(abs.frontend.ast.FunctionDef) ExpFunctionDef(abs.frontend.ast.ExpFunctionDef) IntLiteral(abs.frontend.ast.IntLiteral) PureExp(abs.frontend.ast.PureExp) FunctionDecl(abs.frontend.ast.FunctionDecl) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Aggregations

FrontendTest (abs.frontend.FrontendTest)1 AddExp (abs.frontend.ast.AddExp)1 ExpFunctionDef (abs.frontend.ast.ExpFunctionDef)1 FunctionDecl (abs.frontend.ast.FunctionDecl)1 FunctionDef (abs.frontend.ast.FunctionDef)1 IntLiteral (abs.frontend.ast.IntLiteral)1 Model (abs.frontend.ast.Model)1 PureExp (abs.frontend.ast.PureExp)1 Test (org.junit.Test)1