Search in sources :

Example 1 with ABSFormatter

use of abs.frontend.tests.ABSFormatter in project abstools by abstools.

the class PrettyPrinterBackEnd method compile.

/**
 * @param args
 * @throws Exception
 */
public int compile(String[] args) throws Exception {
    final Model model = parseFiles(parseArgs(args).toArray(new String[0]));
    if (keepsugar) {
        model.doAACrewrite = false;
        model.doForEachRewrite = false;
    }
    analyzeFlattenAndRewriteModel(model);
    if (!force && (model.hasParserErrors() || model.hasErrors() || model.hasTypeErrors())) {
        printErrorMessage();
        return 1;
    }
    final PrintStream stream;
    final String loc;
    if (outputfile != null) {
        stream = new PrintStream(outputfile);
        loc = outputfile.getAbsolutePath();
    } else {
        stream = System.out;
        loc = "Standard Output Stream";
    }
    if (verbose) {
        System.out.println("Output ABS model source code to " + loc + "...");
    }
    PrintWriter writer = new PrintWriter(stream, true);
    ABSFormatter formatter = new DefaultABSFormatter(writer);
    model.doPrettyPrint(writer, formatter);
    return 0;
}
Also used : PrintStream(java.io.PrintStream) ABSFormatter(abs.frontend.tests.ABSFormatter) Model(abs.frontend.ast.Model) PrintWriter(java.io.PrintWriter)

Example 2 with ABSFormatter

use of abs.frontend.tests.ABSFormatter 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 EmptyFormatter();
    m2.doPrettyPrint(w, f);
    return writer.toString();
}
Also used : EmptyFormatter(abs.frontend.tests.EmptyFormatter) StringWriter(java.io.StringWriter) ABSFormatter(abs.frontend.tests.ABSFormatter) PrintWriter(java.io.PrintWriter)

Example 3 with ABSFormatter

use of abs.frontend.tests.ABSFormatter in project abstools by abstools.

the class PrettyPrinterTests method prettyPrint.

private String prettyPrint(ASTNode<?> d) {
    StringWriter writer = new StringWriter();
    PrintWriter w = new PrintWriter(writer);
    ABSFormatter f = new EmptyFormatter();
    d.doPrettyPrint(w, f);
    return writer.toString();
}
Also used : EmptyFormatter(abs.frontend.tests.EmptyFormatter) StringWriter(java.io.StringWriter) ABSFormatter(abs.frontend.tests.ABSFormatter) PrintWriter(java.io.PrintWriter)

Example 4 with ABSFormatter

use of abs.frontend.tests.ABSFormatter in project abstools by abstools.

the class ABSUnitTestCaseTranslator method printToFile.

@SuppressWarnings("rawtypes")
private void printToFile(List<ASTNode<ASTNode>> nodes, File file) {
    try {
        PrintStream stream = new PrintStream(file);
        PrintWriter writer = new PrintWriter(stream, true);
        ABSFormatter formatter = new DefaultABSFormatter(writer);
        for (ASTNode<ASTNode> n : nodes) {
            n.doPrettyPrint(writer, formatter);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace(new PrintStream(ConsoleHandler.getDefault().newMessageStream()));
    }
}
Also used : PrintStream(java.io.PrintStream) DefaultABSFormatter(abs.backend.prettyprint.DefaultABSFormatter) DefaultABSFormatter(abs.backend.prettyprint.DefaultABSFormatter) ABSFormatter(abs.frontend.tests.ABSFormatter) ASTNode(abs.frontend.ast.ASTNode) FileNotFoundException(java.io.FileNotFoundException) PrintWriter(java.io.PrintWriter)

Example 5 with ABSFormatter

use of abs.frontend.tests.ABSFormatter in project abstools by abstools.

the class ASTBasedABSTestRunnerGenerator method generateTestRunner.

@Override
public void generateTestRunner(PrintStream stream) {
    ModuleDecl module = new ModuleDecl();
    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 : DefaultABSFormatter(abs.backend.prettyprint.DefaultABSFormatter) DefaultABSFormatter(abs.backend.prettyprint.DefaultABSFormatter) ABSFormatter(abs.frontend.tests.ABSFormatter) ModuleDecl(abs.frontend.ast.ModuleDecl) PrintWriter(java.io.PrintWriter)

Aggregations

ABSFormatter (abs.frontend.tests.ABSFormatter)5 PrintWriter (java.io.PrintWriter)5 DefaultABSFormatter (abs.backend.prettyprint.DefaultABSFormatter)2 EmptyFormatter (abs.frontend.tests.EmptyFormatter)2 PrintStream (java.io.PrintStream)2 StringWriter (java.io.StringWriter)2 ASTNode (abs.frontend.ast.ASTNode)1 Model (abs.frontend.ast.Model)1 ModuleDecl (abs.frontend.ast.ModuleDecl)1 FileNotFoundException (java.io.FileNotFoundException)1