Made scratchpad use replToString.

git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@25250 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
odersky 2011-07-07 15:16:44 +00:00
parent 991882f53e
commit cebc25823e
2 changed files with 8 additions and 2 deletions

View File

@ -51,6 +51,9 @@ trait ScratchPadMaker { self: Global =>
private def addSandbox(expr: Tree) = {}
// patches += (Patch(expr.pos.start, "sandbox("), Patch(expr.pos.end, ")"))
private def resultString(prefix: String, expr: String) =
literal(prefix + " = ") + " + $show(" + expr + ")"
private def traverseStat(stat: Tree) =
if (stat.pos.isInstanceOf[RangePosition]) {
stat match {
@ -60,7 +63,7 @@ trait ScratchPadMaker { self: Global =>
toPrint += literal(nameType(stat.symbol) + " = <lazy>")
else if (!stat.symbol.isSynthetic) {
addSandbox(rhs)
toPrint += literal(nameType(stat.symbol) + " = ") + " + " + stat.symbol.name
toPrint += resultString(nameType(stat.symbol), stat.symbol.name.toString)
}
case DefDef(_, _, _, _, _, _) =>
addSkip(stat)
@ -79,7 +82,7 @@ trait ScratchPadMaker { self: Global =>
val dispResName = resName filter ('$' !=)
patches += Patch(stat.pos.start, "val " + resName + " = ")
addSandbox(stat)
toPrint += literal(nameType(dispResName, stat.tpe) + " = ") + " + " + resName
toPrint += resultString(nameType(dispResName, stat.tpe), resName)
}
}
}

View File

@ -1,6 +1,7 @@
package scala.tools.nsc.scratchpad
import java.io.{PrintStream, OutputStreamWriter, Writer}
import scala.runtime.ScalaRunTime.replStringOf
import java.lang.reflect.InvocationTargetException
object Executor {
@ -55,6 +56,8 @@ object Executor {
def $skip(n: Int) = currentWriter.skip(n)
def $stop() = throw new StopException
def $show(x: Any): String = replStringOf(x, scala.Int.MaxValue)
}
class StopException extends Exception