changeset 21469:286aef83a9a7

Replacing PrintStream with PrintWriter in the simple language
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Fri, 22 May 2015 18:12:01 +0200
parents 99942eac9c6d
children 1bbef57f9a38
files graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTestRunner.java graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/instrument/SLInstrumentTestRunner.java graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/SLPrintlnBuiltin.java graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/factory/SLContextFactory.java graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLContext.java
diffstat 7 files changed, 22 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java	Fri May 22 13:41:10 2015 +0200
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/NodeUtil.java	Fri May 22 18:12:01 2015 +0200
@@ -561,6 +561,10 @@
         printSourceAttributionTree(new PrintWriter(out), null, node, 1);
     }
 
+    public static void printSourceAttributionTree(PrintWriter out, Node node) {
+        printSourceAttributionTree(out, null, node, 1);
+    }
+
     private static void printSourceAttributionTree(PrintWriter p, Node parent, Node node, int level) {
         if (node == null) {
             return;
--- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTestRunner.java	Fri May 22 13:41:10 2015 +0200
+++ b/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTestRunner.java	Fri May 22 18:12:01 2015 +0200
@@ -165,7 +165,7 @@
         notifier.fireTestStarted(testCase.name);
 
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        PrintStream printer = new PrintStream(out);
+        PrintWriter printer = new PrintWriter(out);
         try {
             SLContext context = SLContextFactory.create(new BufferedReader(new StringReader(repeat(testCase.testInput, repeats))), printer);
             for (NodeFactory<? extends SLBuiltinNode> builtin : builtins) {
@@ -178,6 +178,7 @@
             final Source source = Source.fromText(readAllLines(testCase.path), testCase.sourceName);
             SLMain.run(context, source, null, repeats);
 
+            printer.flush();
             String actualOutput = new String(out.toByteArray());
             Assert.assertEquals(repeat(testCase.expectedOutput, repeats), actualOutput);
         } catch (Throwable ex) {
--- a/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/instrument/SLInstrumentTestRunner.java	Fri May 22 13:41:10 2015 +0200
+++ b/graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/instrument/SLInstrumentTestRunner.java	Fri May 22 18:12:01 2015 +0200
@@ -202,7 +202,7 @@
         notifier.fireTestStarted(testCase.name);
 
         ByteArrayOutputStream out = new ByteArrayOutputStream();
-        PrintStream printer = new PrintStream(out);
+        PrintWriter printer = new PrintWriter(out);
         final ASTProber prober = new SLStandardASTProber();
         Probe.registerASTProber(prober);
         try {
@@ -226,6 +226,7 @@
                 notifier.fireTestFailure(new Failure(testCase.name, new UnsupportedOperationException("No instrumentation found.")));
             }
 
+            printer.flush();
             String actualOutput = new String(out.toByteArray());
             Assert.assertEquals(testCase.expectedOutput, actualOutput);
         } catch (Throwable ex) {
@@ -270,15 +271,15 @@
 
     /**
      * This sample listener provides prints the value of an assignment (after the assignment is
-     * complete) to the {@link PrintStream} specified in the constructor. This listener can only be
+     * complete) to the {@link PrintWriter} specified in the constructor. This listener can only be
      * attached at {@link SLWriteLocalVariableNode}, but provides no guards to protect it from being
      * attached elsewhere.
      */
     public final class SLPrintAssigmentValueListener extends DefaultSimpleInstrumentListener {
 
-        private PrintStream output;
+        private PrintWriter output;
 
-        public SLPrintAssigmentValueListener(PrintStream output) {
+        public SLPrintAssigmentValueListener(PrintWriter output) {
             this.output = output;
         }
 
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java	Fri May 22 13:41:10 2015 +0200
+++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/SLMain.java	Fri May 22 18:12:01 2015 +0200
@@ -135,7 +135,7 @@
     private final SLContext context;
 
     public SLMain() {
-        this.context = SLContextFactory.create(new BufferedReader(new InputStreamReader(System.in)), System.out);
+        this.context = SLContextFactory.create(new BufferedReader(new InputStreamReader(System.in)), new PrintWriter(System.out));
     }
 
     /* Demonstrate per-type tabulation of node execution counts */
@@ -170,7 +170,7 @@
      * Parse and run the specified SL source. Factored out in a separate method so that it can also
      * be used by the unit test harness.
      */
-    public static long run(SLContext context, Source source, PrintStream logOutput, int repeats) {
+    public static long run(SLContext context, Source source, PrintWriter logOutput, int repeats) {
         if (logOutput != null) {
             logOutput.println("== running on " + Truffle.getRuntime().getName());
             // logOutput.println("Source = " + source.getCode());
@@ -260,7 +260,7 @@
      * <p>
      * When printASTToLog is true: prints the ASTs to the console.
      */
-    private static void printScript(String groupName, SLContext context, PrintStream logOutput, boolean printASTToLog, boolean printSourceAttributionToLog, boolean dumpASTToIGV) {
+    private static void printScript(String groupName, SLContext context, PrintWriter logOutput, boolean printASTToLog, boolean printSourceAttributionToLog, boolean dumpASTToIGV) {
         if (dumpASTToIGV) {
             GraphPrintVisitor graphPrinter = new GraphPrintVisitor();
             graphPrinter.beginGroup(groupName);
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/SLPrintlnBuiltin.java	Fri May 22 13:41:10 2015 +0200
+++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/builtins/SLPrintlnBuiltin.java	Fri May 22 18:12:01 2015 +0200
@@ -53,7 +53,7 @@
     }
 
     @TruffleBoundary
-    private static void doPrint(PrintStream out, long value) {
+    private static void doPrint(PrintWriter out, long value) {
         out.println(value);
     }
 
@@ -64,7 +64,7 @@
     }
 
     @TruffleBoundary
-    private static void doPrint(PrintStream out, boolean value) {
+    private static void doPrint(PrintWriter out, boolean value) {
         out.println(value);
     }
 
@@ -75,7 +75,7 @@
     }
 
     @TruffleBoundary
-    private static void doPrint(PrintStream out, String value) {
+    private static void doPrint(PrintWriter out, String value) {
         out.println(value);
     }
 
@@ -86,7 +86,7 @@
     }
 
     @TruffleBoundary
-    private static void doPrint(PrintStream out, Object value) {
+    private static void doPrint(PrintWriter out, Object value) {
         out.println(value);
     }
 }
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/factory/SLContextFactory.java	Fri May 22 13:41:10 2015 +0200
+++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/factory/SLContextFactory.java	Fri May 22 18:12:01 2015 +0200
@@ -32,11 +32,7 @@
     private SLContextFactory() {
     }
 
-    public static SLContext create() {
-        return create(new BufferedReader(new InputStreamReader(System.in)), System.out);
-    }
-
-    public static SLContext create(BufferedReader input, PrintStream output) {
+    public static SLContext create(BufferedReader input, PrintWriter output) {
         final SLContext slContext = new SLContext(input, output);
         slContext.setVisualizer(new SLDefaultVisualizer());
         return slContext;
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLContext.java	Fri May 22 13:41:10 2015 +0200
+++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/runtime/SLContext.java	Fri May 22 18:12:01 2015 +0200
@@ -50,11 +50,11 @@
     private static final Layout LAYOUT = Layout.createLayout();
 
     private final BufferedReader input;
-    private final PrintStream output;
+    private final PrintWriter output;
     private final SLFunctionRegistry functionRegistry;
     private final Shape emptyShape;
 
-    public SLContext(BufferedReader input, PrintStream output) {
+    public SLContext(BufferedReader input, PrintWriter output) {
         this.input = input;
         this.output = output;
         this.functionRegistry = new SLFunctionRegistry();
@@ -80,7 +80,7 @@
      * The default default, i.e., the output for the {@link SLPrintlnBuiltin}. To allow unit
      * testing, we do not use {@link System#out} directly.
      */
-    public PrintStream getOutput() {
+    public PrintWriter getOutput() {
         return output;
     }