diff options
Diffstat (limited to 'src/compiler/scala/tools/nsc/symtab/TypeDebugging.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/TypeDebugging.scala | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/TypeDebugging.scala b/src/compiler/scala/tools/nsc/symtab/TypeDebugging.scala index 62e812704b..f7cb430d7f 100644 --- a/src/compiler/scala/tools/nsc/symtab/TypeDebugging.scala +++ b/src/compiler/scala/tools/nsc/symtab/TypeDebugging.scala @@ -12,7 +12,33 @@ trait TypeDebugging { import definitions._ // @M toString that is safe during debugging (does not normalize, ...) - object TypeDebugStrings { + object typeDebug { + private def to_s(x: Any): String = x match { + // otherwise case classes are caught looking like products + case _: Tree | _: Type => "" + x + case x: TraversableOnce[_] => x mkString ", " + case x: Product => x.productIterator mkString ("(", ", ", ")") + case _ => "" + x + } + def ptIndent(x: Any) = ("" + x).replaceAll("\\n", " ") + def ptBlock(label: String, pairs: (String, Any)*): String = { + val width = pairs map (_._1.length) max + val fmt = "%-" + (width + 1) + "s %s" + val strs = pairs map { case (k, v) => fmt.format(k, to_s(v)) } + + strs.mkString(label + " {\n ", "\n ", "\n}") + } + def ptLine(label: String, pairs: (String, Any)*): String = { + val strs = pairs map { case (k, v) => k + "=" + to_s(v) } + strs.mkString(label + ": ", ", ", "") + } + def ptTree(t: Tree) = t match { + case PackageDef(pid, _) => "package " + pid + case ModuleDef(_, name, _) => "object " + name + case ClassDef(_, name, tparams, _) => "class " + name + str.brackets(tparams) + case _ => to_s(t) + } + object str { def parentheses(xs: List[_]): String = xs.mkString("(", ", ", ")") def brackets(xs: List[_]): String = if (xs.isEmpty) "" else xs.mkString("[", ", ", "]") @@ -58,15 +84,12 @@ trait TypeDebugging { case TypeBounds(lo, hi) => ">: "+ debug(lo) +" <: "+ debug(hi) case tv @ TypeVar(_, _) => tv.toString case ExistentialType(tparams, qtpe) => "forSome "+ str.brackets(tparams) + " " + debug(qtpe) - case _ => tp.toString + case _ => "?"+tp.getClass.getName+"?"//tp.toString might produce cyclic error... } def debugString(tp: Type) = debug(tp) } - private def TDS = TypeDebugStrings - - def paramString(tp: Type) = TDS.str parentheses (tp.params map (_.defString)) - def typeParamsString(tp: Type) = TDS.str brackets (tp.typeParams map (_.defString)) - def typeArgsString(tp: Type) = TDS.str brackets (tp.typeArgs map (_.safeToString)) - def debugString(tp: Type) = TDS debugString tp + def paramString(tp: Type) = typeDebug.str parentheses (tp.params map (_.defString)) + def typeParamsString(tp: Type) = typeDebug.str brackets (tp.typeParams map (_.defString)) + def typeArgsString(tp: Type) = typeDebug.str brackets (tp.typeArgs map (_.safeToString)) + def debugString(tp: Type) = typeDebug debugString tp } - |