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));
}
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);
}
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));
}
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));
}
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) + ']';
}
Aggregations