aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/transform/ResolveSuper.scala
diff options
context:
space:
mode:
authorDmitry Petrashko <dmitry.petrashko@gmail.com>2015-12-20 11:47:09 +0100
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2015-12-20 15:53:55 +0100
commitfacb334f64b4221b56200852e9bab5c80c7266f9 (patch)
treec7b094147fccaee1d5b052f306a3b21619901e9a /src/dotty/tools/dotc/transform/ResolveSuper.scala
parentc864e118e7bd04dcbd0503ab9af6729fda94ff3f (diff)
downloaddotty-facb334f64b4221b56200852e9bab5c80c7266f9.tar.gz
dotty-facb334f64b4221b56200852e9bab5c80c7266f9.tar.bz2
dotty-facb334f64b4221b56200852e9bab5c80c7266f9.zip
LinkerSpecific: make functionality of ResolveSuper accessible.
Linker needs to resolve super calls before they are rewritten in the tree.
Diffstat (limited to 'src/dotty/tools/dotc/transform/ResolveSuper.scala')
-rw-r--r--src/dotty/tools/dotc/transform/ResolveSuper.scala57
1 files changed, 30 insertions, 27 deletions
diff --git a/src/dotty/tools/dotc/transform/ResolveSuper.scala b/src/dotty/tools/dotc/transform/ResolveSuper.scala
index 26128cf33..e718a7e60 100644
--- a/src/dotty/tools/dotc/transform/ResolveSuper.scala
+++ b/src/dotty/tools/dotc/transform/ResolveSuper.scala
@@ -17,6 +17,7 @@ import ast.Trees._
import util.Positions._
import Names._
import collection.mutable
+import ResolveSuper._
/** This phase adds super accessors and method overrides where
* linearization differs from Java's rule for default methods in interfaces.
@@ -51,33 +52,6 @@ class ResolveSuper extends MiniPhaseTransform with IdentityDenotTransformer { th
override def runsAfter = Set(classOf[ElimByName], // verified empirically, need to figure out what the reason is.
classOf[AugmentScala2Traits])
- /** Returns the symbol that is accessed by a super-accessor in a mixin composition.
- *
- * @param base The class in which everything is mixed together
- * @param member The symbol statically referred to by the superaccessor in the trait
- */
- private def rebindSuper(base: Symbol, acc: Symbol)(implicit ctx: Context): Symbol = {
- var bcs = base.info.baseClasses.dropWhile(acc.owner != _).tail
- var sym: Symbol = NoSymbol
- val unexpandedAccName =
- if (acc.is(ExpandedName)) // Cannot use unexpandedName because of #765. t2183.scala would fail if we did.
- acc.name
- .drop(acc.name.indexOfSlice(nme.EXPAND_SEPARATOR ++ nme.SUPER_PREFIX))
- .drop(nme.EXPAND_SEPARATOR.length)
- else acc.name
- val SuperAccessorName(memberName) = unexpandedAccName: Name // dotty deviation: ": Name" needed otherwise pattern type is neither a subtype nor a supertype of selector type
- ctx.debuglog(i"starting rebindsuper from $base of ${acc.showLocated}: ${acc.info} in $bcs, name = $memberName")
- while (bcs.nonEmpty && sym == NoSymbol) {
- val other = bcs.head.info.nonPrivateDecl(memberName)
- if (ctx.settings.debug.value)
- ctx.log(i"rebindsuper ${bcs.head} $other deferred = ${other.symbol.is(Deferred)}")
- sym = other.matchingDenotation(base.thisType, base.thisType.memberInfo(acc)).symbol
- bcs = bcs.tail
- }
- assert(sym.exists)
- sym
- }
-
override def transformTemplate(impl: Template)(implicit ctx: Context, info: TransformerInfo) = {
val cls = impl.symbol.owner.asClass
val ops = new MixinOps(cls, thisTransform)
@@ -110,3 +84,32 @@ class ResolveSuper extends MiniPhaseTransform with IdentityDenotTransformer { th
private val PrivateOrAccessorOrDeferred = Private | Accessor | Deferred
}
+
+object ResolveSuper{
+ /** Returns the symbol that is accessed by a super-accessor in a mixin composition.
+ *
+ * @param base The class in which everything is mixed together
+ * @param acc The symbol statically referred to by the superaccessor in the trait
+ */
+ def rebindSuper(base: Symbol, acc: Symbol)(implicit ctx: Context): Symbol = {
+ var bcs = base.info.baseClasses.dropWhile(acc.owner != _).tail
+ var sym: Symbol = NoSymbol
+ val unexpandedAccName =
+ if (acc.is(ExpandedName)) // Cannot use unexpandedName because of #765. t2183.scala would fail if we did.
+ acc.name
+ .drop(acc.name.indexOfSlice(nme.EXPAND_SEPARATOR ++ nme.SUPER_PREFIX))
+ .drop(nme.EXPAND_SEPARATOR.length)
+ else acc.name
+ val SuperAccessorName(memberName) = unexpandedAccName: Name // dotty deviation: ": Name" needed otherwise pattern type is neither a subtype nor a supertype of selector type
+ ctx.debuglog(i"starting rebindsuper from $base of ${acc.showLocated}: ${acc.info} in $bcs, name = $memberName")
+ while (bcs.nonEmpty && sym == NoSymbol) {
+ val other = bcs.head.info.nonPrivateDecl(memberName)
+ if (ctx.settings.debug.value)
+ ctx.log(i"rebindsuper ${bcs.head} $other deferred = ${other.symbol.is(Deferred)}")
+ sym = other.matchingDenotation(base.thisType, base.thisType.memberInfo(acc)).symbol
+ bcs = bcs.tail
+ }
+ assert(sym.exists)
+ sym
+ }
+}