Search in sources :

Example 11 with FunctionDecl

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

the class TreeUtilsTest method closestParent.

@Test
public void closestParent() {
    Model model = assertParseOkStdLib("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(abs.frontend.ast.Model) FunctionDecl(abs.frontend.ast.FunctionDecl) Decl(abs.frontend.ast.Decl) PureExp(abs.frontend.ast.PureExp) FunctionDecl(abs.frontend.ast.FunctionDecl) ExpFunctionDef(abs.frontend.ast.ExpFunctionDef) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 12 with FunctionDecl

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

the class TreeUtilsTest method findChildrenListLazy.

@Test
public void findChildrenListLazy() {
    Model model = assertParseOkStdLib("def Int test(Int i) = test(1);");
    FunctionDecl functionDecl = getLastFunctionDecl(model);
    assertEquals("test", functionDecl.getName());
    List<PureExp> children = functionDecl.getFunctionDef().findChildren(PureExp.class, true);
    assertEquals(1, children.size());
    assertTrue(children.get(0) instanceof FnApp);
}
Also used : FnApp(abs.frontend.ast.FnApp) Model(abs.frontend.ast.Model) PureExp(abs.frontend.ast.PureExp) FunctionDecl(abs.frontend.ast.FunctionDecl) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 13 with FunctionDecl

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

the class TreeUtilsTest method findChildrenIncludeSelf.

@Test
public void findChildrenIncludeSelf() {
    Model model = assertParseOkStdLib("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(abs.frontend.ast.Model) PureExp(abs.frontend.ast.PureExp) FunctionDecl(abs.frontend.ast.FunctionDecl) ExpFunctionDef(abs.frontend.ast.ExpFunctionDef) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 14 with FunctionDecl

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

the class TreeUtilsTest method closestParentNotFound.

@Test
public void closestParentNotFound() {
    Model model = assertParseOkStdLib("def Int test() = 1;");
    FunctionDecl functionDecl = getLastFunctionDecl(model);
    assertNull(functionDecl.closestParent(FunctionDecl.class));
}
Also used : Model(abs.frontend.ast.Model) FunctionDecl(abs.frontend.ast.FunctionDecl) Test(org.junit.Test) FrontendTest(abs.frontend.FrontendTest)

Example 15 with FunctionDecl

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

the class PardefTest method getFunctions.

protected final String getFunctions(Model model) {
    List<FunctionDecl> functions = model.findChildren(FunctionDecl.class);
    // The desired function is probably at the end, so we reverse the list
    LinkedList<String> reversedNames = new LinkedList<>();
    for (FunctionDecl fun : functions) {
        reversedNames.addFirst(fun.getName());
    }
    return '[' + Joiner.on(", ").join(reversedNames) + ']';
}
Also used : LinkedList(java.util.LinkedList) FunctionDecl(abs.frontend.ast.FunctionDecl)

Aggregations

FunctionDecl (abs.frontend.ast.FunctionDecl)18 Model (abs.frontend.ast.Model)12 Test (org.junit.Test)12 FrontendTest (abs.frontend.FrontendTest)10 PureExp (abs.frontend.ast.PureExp)8 ExpFunctionDef (abs.frontend.ast.ExpFunctionDef)6 Decl (abs.frontend.ast.Decl)3 FnApp (abs.frontend.ast.FnApp)3 FunctionDef (abs.frontend.ast.FunctionDef)3 IntLiteral (abs.frontend.ast.IntLiteral)2 Stmt (abs.frontend.ast.Stmt)2 ABSBuiltInFunctions (abs.backend.java.lib.runtime.ABSBuiltInFunctions)1 AbsASTBuilderUtil.findMethodImpl (abs.backend.tests.AbsASTBuilderUtil.findMethodImpl)1 NotImplementedYetException (abs.common.NotImplementedYetException)1 TypeError (abs.frontend.analyser.TypeError)1 ASTNode (abs.frontend.ast.ASTNode)1 Access (abs.frontend.ast.Access)1 AddExp (abs.frontend.ast.AddExp)1 ClassDecl (abs.frontend.ast.ClassDecl)1 DeltaAccess (abs.frontend.ast.DeltaAccess)1