Search in sources :

Example 1 with DefaultABSFormatter

use of org.abs_models.backend.prettyprint.DefaultABSFormatter in project abstools by abstools.

the class PartialFunctionTest method prettyPrintImplemented.

@Test
public void prettyPrintImplemented() throws NotImplementedYetException, IOException {
    Model model = expand(parse("apply(inc)(0);", applyFunction(), incFunction()));
    PartialFunctionDecl func = getPartialFunction(model, "apply");
    assertNotNull(func);
    String printed;
    try (StringWriter writer = new StringWriter();
        PrintWriter pw = new PrintWriter(writer)) {
        func.doPrettyPrint(pw, new DefaultABSFormatter(pw));
        printed = writer.toString();
    }
    assertFalse(printed.isEmpty());
}
Also used : DefaultABSFormatter(org.abs_models.backend.prettyprint.DefaultABSFormatter) StringWriter(java.io.StringWriter) Model(org.abs_models.frontend.ast.Model) PartialFunctionDecl(org.abs_models.frontend.ast.PartialFunctionDecl) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 2 with DefaultABSFormatter

use of org.abs_models.backend.prettyprint.DefaultABSFormatter in project abstools by abstools.

the class PardefTest method expand.

protected final Model expand(Model model) {
    try {
        model.flattenTraitOnly();
        model.expandPartialFunctions();
        SemanticConditionList e = model.typeCheck();
        assertFalse("Type check errors! First: " + e.getFirstError(), e.containsErrors());
        return model;
    } catch (Throwable e) {
        if (e instanceof PardefModellingException) {
            // prettyprint could fail if expansion left the AST in an invalid state
            throw e;
        }
        PrintWriter pw = new PrintWriter(System.out);
        model.lookupModule("UnitTest").doPrettyPrint(pw, new DefaultABSFormatter(pw));
        pw.flush();
        throw e;
    }
}
Also used : DefaultABSFormatter(org.abs_models.backend.prettyprint.DefaultABSFormatter) SemanticConditionList(org.abs_models.frontend.analyser.SemanticConditionList) PrintWriter(java.io.PrintWriter)

Example 3 with DefaultABSFormatter

use of org.abs_models.backend.prettyprint.DefaultABSFormatter in project abstools by abstools.

the class OtherAnalysisTests method prettyPrint.

public static String prettyPrint(Model m2) {
    StringWriter writer = new StringWriter();
    PrintWriter w = new PrintWriter(writer);
    ABSFormatter f = new DefaultABSFormatter(w);
    m2.doPrettyPrint(w, f);
    return writer.toString();
}
Also used : DefaultABSFormatter(org.abs_models.backend.prettyprint.DefaultABSFormatter) StringWriter(java.io.StringWriter) ABSFormatter(org.abs_models.backend.prettyprint.ABSFormatter) DefaultABSFormatter(org.abs_models.backend.prettyprint.DefaultABSFormatter) PrintWriter(java.io.PrintWriter)

Example 4 with DefaultABSFormatter

use of org.abs_models.backend.prettyprint.DefaultABSFormatter in project abstools by abstools.

the class ASTBasedABSTestRunnerGenerator method generateTestRunner.

@Override
public void generateTestRunner(PrintStream stream) {
    // In order to safely call module.doPrettyPrint() we need a complete AST
    Model model = new Model();
    CompilationUnit compilationunit = new CompilationUnit();
    ModuleDecl module = new ModuleDecl();
    model.addCompilationUnitNoTransform(compilationunit);
    compilationunit.addModuleDeclNoTransform(module);
    module.setName(RUNNER_MAIN);
    module.setImportList(generateImportsAST());
    module.setBlock(generateMainBlockAST(module.getImportList()));
    PrintWriter writer = new PrintWriter(stream, true);
    ABSFormatter formatter = new DefaultABSFormatter(writer);
    module.doPrettyPrint(writer, formatter);
}
Also used : CompilationUnit(org.abs_models.frontend.ast.CompilationUnit) DefaultABSFormatter(org.abs_models.backend.prettyprint.DefaultABSFormatter) ABSFormatter(org.abs_models.backend.prettyprint.ABSFormatter) DefaultABSFormatter(org.abs_models.backend.prettyprint.DefaultABSFormatter) Model(org.abs_models.frontend.ast.Model) ModuleDecl(org.abs_models.frontend.ast.ModuleDecl) PrintWriter(java.io.PrintWriter)

Aggregations

PrintWriter (java.io.PrintWriter)4 DefaultABSFormatter (org.abs_models.backend.prettyprint.DefaultABSFormatter)4 StringWriter (java.io.StringWriter)2 ABSFormatter (org.abs_models.backend.prettyprint.ABSFormatter)2 Model (org.abs_models.frontend.ast.Model)2 SemanticConditionList (org.abs_models.frontend.analyser.SemanticConditionList)1 CompilationUnit (org.abs_models.frontend.ast.CompilationUnit)1 ModuleDecl (org.abs_models.frontend.ast.ModuleDecl)1 PartialFunctionDecl (org.abs_models.frontend.ast.PartialFunctionDecl)1 Test (org.junit.Test)1