Search in sources :

Example 1 with ExpFunctionDef

use of org.abs_models.frontend.ast.ExpFunctionDef 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 2 with ExpFunctionDef

use of org.abs_models.frontend.ast.ExpFunctionDef 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 3 with ExpFunctionDef

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

Example 4 with ExpFunctionDef

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

the class TypingTest method functionTypeArgs2.

@Test
public void functionTypeArgs2() {
    Model m = assertParse(" def Maybe<A> f<A>(Maybe<A> o) = o ;");
    ParametricFunctionDecl d = getLastParametricFunctionDecl(m);
    assertEquals(d.getTypeUse().getType(), ((ExpFunctionDef) d.getFunctionDef()).getRhs().getType());
}
Also used : ParametricFunctionDecl(org.abs_models.frontend.ast.ParametricFunctionDecl) Model(org.abs_models.frontend.ast.Model) ExpFunctionDef(org.abs_models.frontend.ast.ExpFunctionDef) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Example 5 with ExpFunctionDef

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

the class TypingTest method functionTypeArgs5.

@Test
public void functionTypeArgs5() {
    Model m = assertParse("def B nth<B>(List<B> list, Int n) = nth(tail(list), n-1) ; ");
    ParametricFunctionDecl d = getLastParametricFunctionDecl(m);
    TypeParameterDecl typeParameter = d.getTypeParameter(0);
    TypeParameter type = (TypeParameter) ((ExpFunctionDef) d.getFunctionDef()).getRhs().getType();
    assertEquals(typeParameter.getName(), type.getDecl().getName());
}
Also used : TypeParameterDecl(org.abs_models.frontend.ast.TypeParameterDecl) ParametricFunctionDecl(org.abs_models.frontend.ast.ParametricFunctionDecl) TypeParameter(org.abs_models.frontend.typechecker.TypeParameter) Model(org.abs_models.frontend.ast.Model) ExpFunctionDef(org.abs_models.frontend.ast.ExpFunctionDef) FrontendTest(org.abs_models.frontend.FrontendTest) Test(org.junit.Test)

Aggregations

ExpFunctionDef (org.abs_models.frontend.ast.ExpFunctionDef)7 FrontendTest (org.abs_models.frontend.FrontendTest)6 Model (org.abs_models.frontend.ast.Model)6 Test (org.junit.Test)6 FunctionDecl (org.abs_models.frontend.ast.FunctionDecl)4 ParametricFunctionDecl (org.abs_models.frontend.ast.ParametricFunctionDecl)3 PureExp (org.abs_models.frontend.ast.PureExp)3 Decl (org.abs_models.frontend.ast.Decl)2 TypeParameterDecl (org.abs_models.frontend.ast.TypeParameterDecl)2 TypeParameter (org.abs_models.frontend.typechecker.TypeParameter)2 ArrayList (java.util.ArrayList)1 WrongProgramArgumentException (org.abs_models.common.WrongProgramArgumentException)1 SemanticConditionList (org.abs_models.frontend.analyser.SemanticConditionList)1 DataConstructor (org.abs_models.frontend.ast.DataConstructor)1 DataConstructorExp (org.abs_models.frontend.ast.DataConstructorExp)1 DataTypeDecl (org.abs_models.frontend.ast.DataTypeDecl)1 Feature (org.abs_models.frontend.ast.Feature)1 List (org.abs_models.frontend.ast.List)1 ModuleDecl (org.abs_models.frontend.ast.ModuleDecl)1 ProductDecl (org.abs_models.frontend.ast.ProductDecl)1