Search in sources :

Example 1 with AddAddExp

use of org.abs_models.frontend.ast.AddAddExp 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();
}
Also used : AddAddExp(org.abs_models.frontend.ast.AddAddExp) FnApp(org.abs_models.frontend.ast.FnApp) StringLiteral(org.abs_models.frontend.ast.StringLiteral) ArrayList(java.util.ArrayList) List(org.abs_models.frontend.ast.List) LinkedList(java.util.LinkedList) MainBlock(org.abs_models.frontend.ast.MainBlock) VarUse(org.abs_models.frontend.ast.VarUse) ExpressionStmt(org.abs_models.frontend.ast.ExpressionStmt)

Aggregations

ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 AddAddExp (org.abs_models.frontend.ast.AddAddExp)1 ExpressionStmt (org.abs_models.frontend.ast.ExpressionStmt)1 FnApp (org.abs_models.frontend.ast.FnApp)1 List (org.abs_models.frontend.ast.List)1 MainBlock (org.abs_models.frontend.ast.MainBlock)1 StringLiteral (org.abs_models.frontend.ast.StringLiteral)1 VarUse (org.abs_models.frontend.ast.VarUse)1