Search in sources :

Example 16 with FunctionDecl

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

the class TreeUtilsTest method recurseForSome.

@Test
public void recurseForSome() {
    Model model = assertParse("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(org.abs_models.frontend.ast.AddExp) 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 17 with FunctionDecl

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

the class ParFnAppTest method sameAnonTwiceTwoExpansions.

@Test
public void sameAnonTwiceTwoExpansions() {
    Model m = testExpand(parse("apply((Int i) => i)(1);" + "apply((Int i) => i)(1);", applyFunction()));
    ModuleDecl module = m.lookupModule("UnitTest");
    int foundExpansions = 0;
    for (Decl decl : module.getDecls()) {
        if (decl instanceof FunctionDecl) {
            FunctionDecl fun = (FunctionDecl) decl;
            if (fun.getName().startsWith("apply_")) {
                ++foundExpansions;
            }
        }
    }
    assertEquals(2, foundExpansions);
}
Also used : Model(org.abs_models.frontend.ast.Model) ModuleDecl(org.abs_models.frontend.ast.ModuleDecl) ModuleDecl(org.abs_models.frontend.ast.ModuleDecl) FunctionDecl(org.abs_models.frontend.ast.FunctionDecl) Decl(org.abs_models.frontend.ast.Decl) FunctionDecl(org.abs_models.frontend.ast.FunctionDecl) Test(org.junit.Test)

Example 18 with FunctionDecl

use of org.abs_models.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(org.abs_models.frontend.ast.FunctionDecl)

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