diff options
author | Paul Phillips <paulp@improving.org> | 2009-07-14 18:15:14 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2009-07-14 18:15:14 +0000 |
commit | d9418567e6a467f3ac47b70552476e2647be8784 (patch) | |
tree | e9aa82f3d309608c59a723a8b8ad894b651d4290 /src | |
parent | 0be42af7a28a92739712636289009f3996370388 (diff) | |
download | scala-d9418567e6a467f3ac47b70552476e2647be8784.tar.gz scala-d9418567e6a467f3ac47b70552476e2647be8784.tar.bz2 scala-d9418567e6a467f3ac47b70552476e2647be8784.zip |
Enhanced repl based debugger to use manifests a...
Enhanced repl based debugger to use manifests and try to get a usable
type out of it. It works for at least a useful subset of the types which
one might want to inspect.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/Interpreter.scala | 37 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/matching/ParallelMatching.scala | 3 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/SymbolTable.scala | 6 |
3 files changed, 39 insertions, 7 deletions
diff --git a/src/compiler/scala/tools/nsc/Interpreter.scala b/src/compiler/scala/tools/nsc/Interpreter.scala index 470dadc7b1..b41f577f84 100644 --- a/src/compiler/scala/tools/nsc/Interpreter.scala +++ b/src/compiler/scala/tools/nsc/Interpreter.scala @@ -903,11 +903,37 @@ class Interpreter(val settings: Settings, out: PrintWriter) /** Utility methods for the Interpreter. */ object Interpreter { - def breakIf(assertion: => Boolean, args: Any*): Unit = + object DebugParam { + implicit def tuple2debugparam[T](x: (String, T))(implicit m: scala.reflect.Manifest[T]): DebugParam[T] = + DebugParam(x._1, x._2) + + implicit def any2debugparam[T](x: T)(implicit m: scala.reflect.Manifest[T]): DebugParam[T] = + DebugParam("p" + getCount(), x) + + private var counter = 0 + def getCount() = { counter += 1; counter } + } + case class DebugParam[T](name: String, param: T)(implicit m: scala.reflect.Manifest[T]) { + val manifest = m + val typeStr = { + val str = manifest.toString + // I'm sure there are more to be discovered... + val regexp1 = """(.*?)\[(.*)\]""".r + val regexp2str = """.*\.type#""" + val regexp2 = (regexp2str + """(.*)""").r + + (str.replaceAll("""\n""", "")) match { + case regexp1(clazz, typeArgs) => "%s[%s]".format(clazz, typeArgs.replaceAll(regexp2str, "")) + case regexp2(clazz) => clazz + case _ => str + } + } + } + def breakIf(assertion: => Boolean, args: DebugParam[_]*): Unit = if (assertion) break(args.toList) - // start a repl binding supplied args to p1, p2, etc. - def break(args: List[Any]): Unit = { + // start a repl, binding supplied args + def break(args: List[DebugParam[_]]): Unit = { val intLoop = new InterpreterLoop intLoop.settings = new Settings(Console.println) intLoop.createInterpreter @@ -916,7 +942,10 @@ object Interpreter { // rebind exit so people don't accidentally call System.exit by way of predef intLoop.interpreter.beQuietDuring { intLoop.interpreter.interpret("""def exit = println("Type :quit to resume program execution.")""") - println(intLoop.inject(args)) + for (p <- args) { + intLoop.interpreter.bind(p.name, p.typeStr, p.param) + println("%s: %s".format(p.name, p.typeStr)) + } } intLoop.repl() intLoop.closeInterpreter diff --git a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala index ecf3dddfea..22df6d1bda 100644 --- a/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala +++ b/src/compiler/scala/tools/nsc/matching/ParallelMatching.scala @@ -566,6 +566,9 @@ trait ParallelMatching extends ast.TreeDSL { } final def tree(): Tree = { + // Just a demo of breakIf + // Interpreter.breakIf(true, "lits" -> literals, "mixlit" -> this, literalMap) + def bindVars(Tag: Int, orig: Bindings): Bindings = { def myBindVars(rest: List[(Int, List[Symbol])], bnd: Bindings): Bindings = rest match { case Nil => bnd diff --git a/src/compiler/scala/tools/nsc/symtab/SymbolTable.scala b/src/compiler/scala/tools/nsc/symtab/SymbolTable.scala index 50cccd0f05..9b5872aba5 100644 --- a/src/compiler/scala/tools/nsc/symtab/SymbolTable.scala +++ b/src/compiler/scala/tools/nsc/symtab/SymbolTable.scala @@ -106,9 +106,9 @@ abstract class SymbolTable extends Names } /** Break into repl debugger if assertion is true */ - def breakIf(assertion: => Boolean, args: Any*): Unit = - if (assertion) - Interpreter.break(args.toList) + // def breakIf(assertion: => Boolean, args: Any*): Unit = + // if (assertion) + // Interpreter.break(args.toList) /** The set of all installed infotransformers */ var infoTransformers = new InfoTransformer { |