use of org.abs_models.frontend.ast.FnApp in project abstools by abstools.
the class ParFnAppTest method recursionWithClosure.
@Test
public void recursionWithClosure() {
Model m = expand(parse("Int x = 0; Int y = 1; rec((Int i) => x, (Int j) => y)();", "def Int rec(f, g)() = rec();"));
FnApp call = assertHasCall(m, expandedName("rec_%s_Anon\\d+__"));
assertEquals(2, call.getNumParam());
}
use of org.abs_models.frontend.ast.FnApp 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);
}
use of org.abs_models.frontend.ast.FnApp 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);
}
}
use of org.abs_models.frontend.ast.FnApp in project abstools by abstools.
the class TimeoutThread method genCode.
/**
* Generates Erlang code in target directory, adding a last statement that
* prints the value of the `testresult' variable.
*
* @return a Module Name containing a Main Block
* @throws InternalBackendException
*/
public String genCode(Model model, File targetDir, boolean appendResultprinter) throws IOException, InterruptedException, InternalBackendException {
if (model.hasErrors()) {
Assert.fail(model.getErrors().getFirstError().getHelpMessage());
}
if (model.hasTypeErrors()) {
Assert.fail(model.getTypeErrors().getFirstError().getHelpMessage());
}
MainBlock mb = model.getMainBlock();
if (mb != null && appendResultprinter) {
// We search for this output in the `run' method below
mb.addStmt(new ExpressionStmt(new List<>(), new FnApp("ABS.StdLib.println", new List<>(new AddAddExp(new StringLiteral("RES="), new FnApp("ABS.StdLib.toString", new List<>(new VarUse("testresult"))))))));
}
new ErlangBackend().compile(model, targetDir, // use the following argument for silent compiler:
EnumSet.noneOf(ErlangBackend.CompileOptions.class));
if (mb == null)
return null;
else
return mb.getModuleDecl().getName();
}
use of org.abs_models.frontend.ast.FnApp in project abstools by abstools.
the class AnnotationUtil method addToAnnotations.
/**
* Add an ExpansionCall annotation, or an argument to an existing
* annotation. Creates or adds to [ExpansionCall : list[expansionId]]
* annotation.
*
* @param annotations The list to mutate
* @param annotationType Currently always EXPANSION_CALL
* @param expansionId An integer to add to the list.
*/
private static void addToAnnotations(List<Annotation> annotations, TypeIdUse annotationType, int expansionId) {
IntLiteral indexLiteral = new IntLiteral(Integer.toString(expansionId));
Annotation toAdd = getAnnotation(annotations, annotationType);
if (toAdd == null) {
List<PureExp> llist = new List<>(new ListLiteral(new List<PureExp>(indexLiteral)));
toAdd = new TypedAnnotation(new FnApp("list", llist), annotationType);
annotations.add(toAdd);
} else {
PureExp value = toAdd.getValue();
if (!(value instanceof FnApp)) {
throw new IllegalArgumentException("Annotation list contains invalid expansion annotation");
}
FnApp fvalue = (FnApp) value;
if (!fvalue.getName().equals("list")) {
throw new IllegalArgumentException("Annotation list contains invalid expansion annotation");
}
ListLiteral list = (ListLiteral) fvalue.getParam(0);
for (PureExp exp : list.getPureExps()) {
if (exp instanceof IntLiteral) {
IntLiteral intLiteral = (IntLiteral) exp;
if (intLiteral.getContent().equals(indexLiteral.getContent())) {
return;
}
}
}
list.addPureExp(indexLiteral);
}
}
Aggregations