Search in sources :

Example 6 with FunctionDecl

use of org.abs_models.frontend.ast.FunctionDecl in project abstools by abstools.

the class TreeUtilsTest method findChildrenIncludeSelf.

@Test
public void findChildrenIncludeSelf() {
    Model model = assertParse("def Int test(Int i) = test(1);");
    FunctionDecl functionDecl = getLastFunctionDecl(model);
    assertEquals("test", functionDecl.getName());
    ExpFunctionDef def = (ExpFunctionDef) functionDecl.getFunctionDef();
    PureExp exp = def.getRhs();
    Stream<PureExp> children = def.findChildren(cast(PureExp.class), n -> true);
    assertNotNull(children);
    List<PureExp> result = children.distinct().collect(Collectors.toList());
    assertEquals(2, result.size());
    assertTrue(result.contains(exp));
}
Also used : Model(org.abs_models.frontend.ast.Model) PureExp(org.abs_models.frontend.ast.PureExp) FunctionDecl(org.abs_models.frontend.ast.FunctionDecl) ExpFunctionDef(org.abs_models.frontend.ast.ExpFunctionDef) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 7 with FunctionDecl

use of org.abs_models.frontend.ast.FunctionDecl in project abstools by abstools.

the class TreeUtilsTest method findChildrenListNotNull.

@Test
public void findChildrenListNotNull() {
    Model model = assertParse("def Int test(Int i) = test(1);");
    FunctionDecl functionDecl = getLastFunctionDecl(model);
    assertEquals("test", functionDecl.getName());
    List<Stmt> children = functionDecl.getFunctionDef().findChildren(Stmt.class);
    assertNotNull(children);
    assertTrue(children.isEmpty());
}
Also used : Model(org.abs_models.frontend.ast.Model) FunctionDecl(org.abs_models.frontend.ast.FunctionDecl) Stmt(org.abs_models.frontend.ast.Stmt) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 8 with FunctionDecl

use of org.abs_models.frontend.ast.FunctionDecl in project abstools by abstools.

the class TreeUtilsTest method findChildrenMultipleTypes.

@Test
public void findChildrenMultipleTypes() {
    Model model = assertParse("def Int test(Int i) = test(1);");
    FunctionDecl functionDecl = getLastFunctionDecl(model);
    assertEquals("test", functionDecl.getName());
    FunctionDef def = functionDecl.getFunctionDef();
    Stream<PureExp> children = def.findChildren(cast(ImmutableList.of(FnApp.class, IntLiteral.class)), n -> true);
    assertNotNull(children);
    List<PureExp> result = children.distinct().collect(Collectors.toList());
    assertEquals(2, result.size());
    for (PureExp exp : result) {
        assertTrue(exp instanceof FnApp || exp instanceof IntLiteral);
    }
}
Also used : FnApp(org.abs_models.frontend.ast.FnApp) Model(org.abs_models.frontend.ast.Model) ExpFunctionDef(org.abs_models.frontend.ast.ExpFunctionDef) FunctionDef(org.abs_models.frontend.ast.FunctionDef) IntLiteral(org.abs_models.frontend.ast.IntLiteral) PureExp(org.abs_models.frontend.ast.PureExp) FunctionDecl(org.abs_models.frontend.ast.FunctionDecl) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 9 with FunctionDecl

use of org.abs_models.frontend.ast.FunctionDecl in project abstools by abstools.

the class TreeUtilsTest method closestParent.

@Test
public void closestParent() {
    Model model = assertParse("def Int test() = 1;");
    FunctionDecl functionDecl = getLastFunctionDecl(model);
    assertEquals("test", functionDecl.getName());
    PureExp exp = ((ExpFunctionDef) functionDecl.getFunctionDef()).getRhs();
    assertSame(functionDecl, exp.closestParent(Decl.class));
    assertSame(functionDecl, exp.closestParent(FunctionDecl.class));
}
Also used : Model(org.abs_models.frontend.ast.Model) FunctionDecl(org.abs_models.frontend.ast.FunctionDecl) Decl(org.abs_models.frontend.ast.Decl) PureExp(org.abs_models.frontend.ast.PureExp) FunctionDecl(org.abs_models.frontend.ast.FunctionDecl) ExpFunctionDef(org.abs_models.frontend.ast.ExpFunctionDef) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 10 with FunctionDecl

use of org.abs_models.frontend.ast.FunctionDecl in project abstools by abstools.

the class TreeUtilsTest method findChildrenIncludeOnlySelf.

@Test
public void findChildrenIncludeOnlySelf() {
    Model model = assertParse("def Int test(Int i) = test(1);");
    FunctionDecl functionDecl = getLastFunctionDecl(model);
    assertEquals("test", functionDecl.getName());
    ExpFunctionDef def = (ExpFunctionDef) functionDecl.getFunctionDef();
    PureExp exp = def.getRhs();
    Stream<PureExp> children = def.findChildren(cast(PureExp.class), n -> false);
    assertNotNull(children);
    List<PureExp> result = children.distinct().collect(Collectors.toList());
    assertEquals(1, result.size());
    assertTrue(result.contains(exp));
}
Also used : Model(org.abs_models.frontend.ast.Model) PureExp(org.abs_models.frontend.ast.PureExp) FunctionDecl(org.abs_models.frontend.ast.FunctionDecl) ExpFunctionDef(org.abs_models.frontend.ast.ExpFunctionDef) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Aggregations

FunctionDecl (org.abs_models.frontend.ast.FunctionDecl)18 Model (org.abs_models.frontend.ast.Model)12 Test (org.junit.Test)12 FrontendTest (org.abs_models.frontend.FrontendTest)10 PureExp (org.abs_models.frontend.ast.PureExp)8 ExpFunctionDef (org.abs_models.frontend.ast.ExpFunctionDef)7 Decl (org.abs_models.frontend.ast.Decl)4 FnApp (org.abs_models.frontend.ast.FnApp)3 FunctionDef (org.abs_models.frontend.ast.FunctionDef)3 IntLiteral (org.abs_models.frontend.ast.IntLiteral)2 ModuleDecl (org.abs_models.frontend.ast.ModuleDecl)2 Stmt (org.abs_models.frontend.ast.Stmt)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 NotImplementedYetException (org.abs_models.common.NotImplementedYetException)1 WrongProgramArgumentException (org.abs_models.common.WrongProgramArgumentException)1 SemanticConditionList (org.abs_models.frontend.analyser.SemanticConditionList)1 TypeError (org.abs_models.frontend.analyser.TypeError)1 ASTNode (org.abs_models.frontend.ast.ASTNode)1 AddExp (org.abs_models.frontend.ast.AddExp)1