summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2013-04-17 15:16:53 +0200
committerJason Zaugg <jzaugg@gmail.com>2013-04-21 19:04:09 +0200
commitc598e764b91307587388ab2a3f5188e64f42af44 (patch)
tree4e62dbe8c432be718e696b3868bb09777df8289e /src/compiler/scala/tools/nsc/typechecker/Contexts.scala
parent85af192fffd3801692b91c2d8f806cd55d559ffd (diff)
downloadscala-c598e764b91307587388ab2a3f5188e64f42af44.tar.gz
scala-c598e764b91307587388ab2a3f5188e64f42af44.tar.bz2
scala-c598e764b91307587388ab2a3f5188e64f42af44.zip
SI-7345 Improved Context.toString
ticket/7345-2 ~/code/scala qbin/scala Welcome to Scala version 2.11.0-20130416-231609-7829011884 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_37). Type in expressions to have them evaluated. Type :help for more information. scala> import language.experimental._import language.experimental._ scala> import reflect.macros.Contextimport reflect.macros.Context scala> def showContextImpl(c: Context) = {println(c.asInstanceOf[reflect.macros.runtime.Context].callsiteTyper.context.enclosingContextChain.mkString("\n\n")); c.literalUnit} showContextImpl: (c: scala.reflect.macros.Context)c.Expr[Unit] scala> def showContext = macro showContextImpldefined term macro showContext: Unit scala> object Foo { def foo(a: Any) { {class C { println("") }; showContext } } }Context(<console>) { owner = method foo tree = Block:{ class C extends scala.AnyRef { def <init>(): C = { super.<init>(); ( scope = 1 decls contextMode = AmbiguousErrors ImplicitsEnabled MacrosEnabled ReportErrors outer.owner = method foo } Context(<console>) { owner = method foo tree = DefDef:def foo(a: Any): Unit = { class C extends scala.AnyRef { def <init>(): scope = 1 decls contextMode = AmbiguousErrors ImplicitsEnabled MacrosEnabled ReportErrors outer.owner = object Foo } Context(<console>) { owner = object Foo tree = Template(scala.AnyRef, _, 2 stats) scope = 0 decls contextMode = AmbiguousErrors ImplicitsEnabled MacrosEnabled ReportErrors outer.owner = object Foo } Context(<console>) { owner = object Foo tree = ModuleDef:object Foo extends scala.AnyRef { def <init>(): Foo.type = { super.<in scope = 0 decls contextMode = AmbiguousErrors ImplicitsEnabled MacrosEnabled ReportErrors outer.owner = object $iw } Context(<console>) { owner = object $iw tree = Template(scala.AnyRef, _, 2 stats) scope = 0 decls contextMode = AmbiguousErrors ImplicitsEnabled MacrosEnabled ReportErrors outer.owner = object $iw } Context(<console>) { owner = object $iw tree = ModuleDef:object $iw extends scala.AnyRef { def <init>(): type = { super.<init>( scope = 0 decls contextMode = AmbiguousErrors ImplicitsEnabled MacrosEnabled ReportErrors outer.owner = object $iw } ImportContext { import $line18.$read.$iw.$iw.$iw.$iw.showContext; outer.owner = object $iw } ImportContext { import $line17.$read.$iw.$iw.$iw.$iw.showContextImpl; outer.owner = object $iw } ImportContext { import reflect.macros.Context; outer.owner = object $iw } Context(<console>) { owner = object $iw tree = Template(scala.AnyRef, _, 5 stats) scope = 0 decls contextMode = AmbiguousErrors ImplicitsEnabled MacrosEnabled ReportErrors outer.owner = object $iw } Context(<console>) { owner = object $iw tree = ModuleDef:object $iw extends scala.AnyRef { def <init>(): type = { super.<init>( scope = 0 decls contextMode = AmbiguousErrors ImplicitsEnabled MacrosEnabled ReportErrors outer.owner = object $iw } ImportContext { import language.experimental._; outer.owner = object $iw } Context(<console>) { owner = object $iw tree = Template(scala.AnyRef, _, 3 stats) scope = 0 decls contextMode = AmbiguousErrors ImplicitsEnabled MacrosEnabled ReportErrors outer.owner = object $iw } Context(<console>) { owner = object $iw tree = ModuleDef:object $iw extends scala.AnyRef { def <init>(): type = { super.<init>( scope = 0 decls contextMode = AmbiguousErrors ImplicitsEnabled MacrosEnabled ReportErrors outer.owner = object $iw } Context(<console>) { owner = object $iw tree = Template(scala.AnyRef, _, 2 stats) scope = 0 decls contextMode = AmbiguousErrors ImplicitsEnabled MacrosEnabled ReportErrors outer.owner = object $iw } Context(<console>) { owner = object $iw tree = ModuleDef:object $iw extends scala.AnyRef { def <init>(): type = { super.<init>( scope = 0 decls contextMode = AmbiguousErrors ImplicitsEnabled MacrosEnabled ReportErrors outer.owner = object $read } Context(<console>) { owner = object $read tree = Template(scala.AnyRef, _, 2 stats) scope = 0 decls contextMode = AmbiguousErrors ImplicitsEnabled MacrosEnabled ReportErrors outer.owner = object $read } Context(<console>) { owner = object $read tree = ModuleDef:object $read extends scala.AnyRef { def <init>(): $line19.$read.type = scope = 1 decls contextMode = AmbiguousErrors ImplicitsEnabled MacrosEnabled ReportErrors outer.owner = package $line19 } Context(<console>) { owner = package $line19 tree = PackageDef:package $line19 { object $read extends scala.AnyRef { def <init>(): $l scope = 1 decls contextMode = AmbiguousErrors ImplicitsEnabled MacrosEnabled ReportErrors outer.owner = package <root> } Context(<console>) { owner = package <root> tree = EmptyTree:<empty> scope = 50 decls contextMode = AmbiguousErrors ImplicitsEnabled MacrosEnabled ReportErrors outer.owner = package <root> } ImportContext { import scala.this.Predef._; outer.owner = package <root> } ImportContext { import scala._; outer.owner = package <root> } ImportContext { import java.this.lang._; outer.owner = package <root> } Context(NoCompilationUnit) { owner = package <root> tree = Template(Nil, _, 0 stats) scope = 50 decls contextMode = MacrosEnabled outer.owner = <none> } defined object Foo
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Contexts.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Contexts.scala24
1 files changed, 20 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
index 4343845e80..bcc6f8eed6 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Contexts.scala
@@ -557,9 +557,25 @@ trait Contexts { self: Analyzer =>
def enclosingContextChain: List[Context] = this :: outer.enclosingContextChain
- override def toString = "Context(%s@%s unit=%s scope=%s errors=%b, reportErrors=%b, throwErrors=%b)".format(
- owner.fullName, tree.shortClass, unit, scope.##, hasErrors, reportErrors, throwErrors
- )
+ private def treeTruncated = tree.toString.replaceAll("\\s+", " ").lines.mkString("\\n").take(70)
+ private def treeIdString = if (settings.uniqid.value) "#" + System.identityHashCode(tree).toString.takeRight(3) else ""
+ private def treeString = tree match {
+ case x: Import => "" + x
+ case Template(parents, `emptyValDef`, body) =>
+ val pstr = if ((parents eq null) || parents.isEmpty) "Nil" else parents mkString " "
+ val bstr = if (body eq null) "" else body.length + " stats"
+ s"""Template($pstr, _, $bstr)"""
+ case x => s"${tree.shortClass}${treeIdString}:${treeTruncated}"
+ }
+
+ override def toString =
+ sm"""|Context($unit) {
+ | owner = $owner
+ | tree = $treeString
+ | scope = ${scope.size} decls
+ | contextMode = $contextMode
+ | outer.owner = ${outer.owner}
+ |}"""
//
// Accessibility checking
@@ -1133,7 +1149,7 @@ trait Contexts { self: Analyzer =>
override final def imports = impInfo :: super.imports
override final def firstImport = Some(impInfo)
override final def isRootImport = impInfo.isRootImport
- override final def toString = "<import>"
+ override final def toString = s"ImportContext { $impInfo; outer.owner = ${outer.owner} }"
}
/** A buffer for warnings and errors that are accumulated during speculative type checking. */