summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2013-08-28 15:46:04 +0200
committerJason Zaugg <jzaugg@gmail.com>2013-09-11 23:22:07 +0200
commitc2dc34640c9fd06abda91266ca21160bb423bf41 (patch)
treeafd02a3a4bfb9d36a584f7038abf34599f3dc4b6
parent97255e7c4e31614b52f0584a75206fd621198ed4 (diff)
downloadscala-c2dc34640c9fd06abda91266ca21160bb423bf41.tar.gz
scala-c2dc34640c9fd06abda91266ca21160bb423bf41.tar.bz2
scala-c2dc34640c9fd06abda91266ca21160bb423bf41.zip
SI-3832 Extract tracking of under-construction classes to a mixin
In order to reduce the noise in OuterPathTransformer.
-rw-r--r--src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala17
-rw-r--r--src/reflect/scala/reflect/internal/Trees.scala19
2 files changed, 21 insertions, 15 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
index d6a6e027cb..8af95afdec 100644
--- a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
+++ b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala
@@ -216,7 +216,7 @@ abstract class ExplicitOuter extends InfoTransform
* values for outer parameters of constructors.
* The class provides methods for referencing via outer.
*/
- abstract class OuterPathTransformer(unit: CompilationUnit) extends TypingTransformer(unit) {
+ abstract class OuterPathTransformer(unit: CompilationUnit) extends TypingTransformer(unit) with UnderConstructionTransformer {
/** The directly enclosing outer parameter, if we are in a constructor */
protected var outerParam: Symbol = NoSymbol
@@ -276,16 +276,6 @@ abstract class ExplicitOuter extends InfoTransform
}
- /** The stack of class symbols in which a call to this() or to the super
- * constructor, or early definition is active
- */
- protected def isUnderConstruction(clazz: Symbol) = selfOrSuperCalls contains clazz
- protected val selfOrSuperCalls = mutable.Stack[Symbol]()
- @inline protected def inSelfOrSuperCall[A](sym: Symbol)(a: => A) = {
- selfOrSuperCalls push sym
- try a finally selfOrSuperCalls.pop()
- }
-
override def transform(tree: Tree): Tree = {
val savedOuterParam = outerParam
try {
@@ -299,10 +289,7 @@ abstract class ExplicitOuter extends InfoTransform
}
case _ =>
}
- if ((treeInfo isSelfOrSuperConstrCall tree) || (treeInfo isEarlyDef tree))
- inSelfOrSuperCall(currentOwner.owner)(super.transform(tree))
- else
- super.transform(tree)
+ super.transform(tree)
}
finally outerParam = savedOuterParam
}
diff --git a/src/reflect/scala/reflect/internal/Trees.scala b/src/reflect/scala/reflect/internal/Trees.scala
index 84818a6f42..e784d704d6 100644
--- a/src/reflect/scala/reflect/internal/Trees.scala
+++ b/src/reflect/scala/reflect/internal/Trees.scala
@@ -1617,6 +1617,25 @@ trait Trees extends api.Trees { self: SymbolTable =>
}
}
+ /** Tracks the classes currently under construction during a transform */
+ trait UnderConstructionTransformer extends Transformer {
+ import collection.mutable
+
+ protected def isUnderConstruction(clazz: Symbol) = selfOrSuperCalls contains clazz
+
+ /** The stack of class symbols in which a call to this() or to the super
+ * constructor, or early definition is active */
+ private val selfOrSuperCalls = mutable.Stack[Symbol]()
+
+ abstract override def transform(tree: Tree) = {
+ if ((treeInfo isSelfOrSuperConstrCall tree) || (treeInfo isEarlyDef tree)) {
+ selfOrSuperCalls push currentOwner.owner
+ try super.transform(tree)
+ finally selfOrSuperCalls.pop()
+ } else super.transform(tree)
+ }
+ }
+
def duplicateAndKeepPositions(tree: Tree) = new Duplicator(focusPositions = false) transform tree
// ------ copiers -------------------------------------------