summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/io/Replay.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2011-01-06 16:20:51 +0000
committerMartin Odersky <odersky@gmail.com>2011-01-06 16:20:51 +0000
commit715262fcfcefbb75788f287444c4791180e7eb67 (patch)
treeb9cca75f3a75423f843ada9e38656d88bfda6068 /src/compiler/scala/tools/nsc/io/Replay.scala
parent0b5c9ca6535b38dbfc958d92cfce691aa6de205f (diff)
downloadscala-715262fcfcefbb75788f287444c4791180e7eb67.tar.gz
scala-715262fcfcefbb75788f287444c4791180e7eb67.tar.bz2
scala-715262fcfcefbb75788f287444c4791180e7eb67.zip
Replay now enabled for presentation compiler.
Diffstat (limited to 'src/compiler/scala/tools/nsc/io/Replay.scala')
-rw-r--r--src/compiler/scala/tools/nsc/io/Replay.scala74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/io/Replay.scala b/src/compiler/scala/tools/nsc/io/Replay.scala
new file mode 100644
index 0000000000..5cb61b6cb1
--- /dev/null
+++ b/src/compiler/scala/tools/nsc/io/Replay.scala
@@ -0,0 +1,74 @@
+package scala.tools.nsc.io
+
+import java.io.{Reader, Writer}
+
+import Pickler._
+import Lexer.{Token, EOF}
+
+abstract class LogReplay {
+ def logreplay(event: String, x: => Boolean): Boolean
+ def logreplay[T: Pickler](event: String, x: => Option[T]): Option[T]
+ def close()
+ def flush()
+}
+
+class Logger(wr0: Writer) extends LogReplay {
+ val wr = new PrettyWriter(wr0)
+ private var first = true
+ private def insertComma() = if (first) first = false else wr.write(",")
+
+ def logreplay(event: String, x: => Boolean) = {
+ val xx = x
+ if (xx) { insertComma(); pkl[Unit].labelled(event).pickle(wr, ()) }
+ xx
+ }
+ def logreplay[T: Pickler](event: String, x: => Option[T]) = {
+ val xx = x
+ xx match {
+ case Some(y) => insertComma(); pkl[T].labelled(event).pickle(wr, y)
+ case None =>
+ }
+ xx
+ }
+ def close() { wr.close() }
+ def flush() { wr.flush() }
+}
+
+object NullLogger extends LogReplay {
+ def logreplay(event: String, x: => Boolean) = x
+ def logreplay[T: Pickler](event: String, x: => Option[T]) = x
+ def close() {}
+ def flush() {}
+}
+
+class Replayer(raw: Reader) extends LogReplay {
+ private val rd = new Lexer(raw)
+ private var nextComma = false
+
+ private def eatComma() =
+ if (nextComma) { rd.accept(','); nextComma = false }
+
+ def logreplay(event: String, x: => Boolean) =
+ if (rd.token == EOF) NullLogger.logreplay(event, x)
+ else {
+ eatComma()
+ pkl[Unit].labelled(event).unpickle(rd) match {
+ case UnpickleSuccess(_) => nextComma = true; true
+ case _ => false
+ }
+ }
+
+ def logreplay[T: Pickler](event: String, x: => Option[T]) =
+ if (rd.token == EOF) NullLogger.logreplay(event, x)
+ else {
+ eatComma()
+ pkl[T].labelled(event).unpickle(rd) match {
+ case UnpickleSuccess(y) => nextComma = true; Some(y)
+ case _ => None
+ }
+ }
+
+ def close() { raw.close() }
+ def flush() {}
+}
+