Search in sources :

Example 86 with Model

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

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

Example 88 with Model

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

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

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

Aggregations

Model (org.abs_models.frontend.ast.Model)268 Test (org.junit.Test)227 FrontendTest (org.abs_models.frontend.FrontendTest)101 ClassDecl (org.abs_models.frontend.ast.ClassDecl)72 DeltaDecl (org.abs_models.frontend.ast.DeltaDecl)34 SemanticConditionList (org.abs_models.frontend.analyser.SemanticConditionList)29 ABSTest (org.abs_models.ABSTest)22 ProductDecl (org.abs_models.frontend.ast.ProductDecl)17 FunctionDecl (org.abs_models.frontend.ast.FunctionDecl)15 HashSet (java.util.HashSet)13 ModifyClassModifier (org.abs_models.frontend.ast.ModifyClassModifier)13 PrintStream (java.io.PrintStream)12 Product (org.abs_models.frontend.ast.Product)11 SkipStmt (org.abs_models.frontend.ast.SkipStmt)11 VarUse (org.abs_models.frontend.ast.VarUse)11 Feature (org.abs_models.frontend.ast.Feature)10 File (java.io.File)9 ExpFunctionDef (org.abs_models.frontend.ast.ExpFunctionDef)9 ReturnStmt (org.abs_models.frontend.ast.ReturnStmt)9 KindedName (org.abs_models.frontend.typechecker.KindedName)9