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