Search in sources :

Example 1 with FunctionDecl

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

the class AbstractPartialFunctionTest method assertHasFunction.

protected FunctionDecl assertHasFunction(Model model, String regex) {
    FunctionDecl result = getFunction(model, Pattern.compile(regex));
    String errorMessage = "No expanded function with name " + regex + " created" + " (functions: " + getFunctions(model) + ")";
    assertNotNull(errorMessage, result);
    Decl decl = model.lookup(new KindedName(KindedName.Kind.FUN, result.getName()));
    assertFalse("Could not lookup function " + result.getName(), decl.isUnknown());
    return result;
}
Also used : FunctionDecl(org.abs_models.frontend.ast.FunctionDecl) PartialFunctionDecl(org.abs_models.frontend.ast.PartialFunctionDecl) Decl(org.abs_models.frontend.ast.Decl) KindedName(org.abs_models.frontend.typechecker.KindedName) FunctionDecl(org.abs_models.frontend.ast.FunctionDecl) PartialFunctionDecl(org.abs_models.frontend.ast.PartialFunctionDecl)

Example 2 with FunctionDecl

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

the class ParFnAppTest method sameAnonTwiceTwoClosureParams.

@Test
public void sameAnonTwiceTwoClosureParams() {
    Model m = testExpand(parse("Int x = 1; test(() => x, () => x)();", "def Int test(f, g)() = f() + g();"), "test_%s_Anon\\d+__");
    FunctionDecl function = getFunction(m, Pattern.compile(expandedName("test_%s_Anon\\d+__")));
    assertNotNull(function);
    assertEquals(2, function.getNumParam());
    assertEquals("x__0__", function.getParam(0).getName());
    assertEquals("x__1__", function.getParam(1).getName());
}
Also used : Model(org.abs_models.frontend.ast.Model) FunctionDecl(org.abs_models.frontend.ast.FunctionDecl) Test(org.junit.Test)

Example 3 with FunctionDecl

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

the class TreeUtilsTest method findChildrenListLazy.

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

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

the class TreeUtilsTest method closestParentIgnoresSelf.

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

Example 5 with FunctionDecl

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

the class TreeUtilsTest method findChildrenList.

@Test
public void findChildrenList() {
    Model model = assertParse("def Int test(Int i) = test(1);");
    FunctionDecl functionDecl = getLastFunctionDecl(model);
    assertEquals("test", functionDecl.getName());
    List<PureExp> children = functionDecl.getFunctionDef().findChildren(PureExp.class);
    assertEquals(2, children.size());
}
Also used : Model(org.abs_models.frontend.ast.Model) PureExp(org.abs_models.frontend.ast.PureExp) FunctionDecl(org.abs_models.frontend.ast.FunctionDecl) 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