aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/transform/SymUtils.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-09-21 14:48:10 +0200
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2014-10-11 08:24:36 +0200
commitd32ff05d101f860dc1b290330d34caa9aea6e1df (patch)
tree23aad3d7ee22a375f99f772e37dc0b09ce5397c1 /src/dotty/tools/dotc/transform/SymUtils.scala
parentd288981f42cd8fde42340264a73d30e037bffec5 (diff)
downloaddotty-d32ff05d101f860dc1b290330d34caa9aea6e1df.tar.gz
dotty-d32ff05d101f860dc1b290330d34caa9aea6e1df.tar.bz2
dotty-d32ff05d101f860dc1b290330d34caa9aea6e1df.zip
New utility methods in SymUtils
Diffstat (limited to 'src/dotty/tools/dotc/transform/SymUtils.scala')
-rw-r--r--src/dotty/tools/dotc/transform/SymUtils.scala24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/transform/SymUtils.scala b/src/dotty/tools/dotc/transform/SymUtils.scala
index df0ac59ae..5ae9aba63 100644
--- a/src/dotty/tools/dotc/transform/SymUtils.scala
+++ b/src/dotty/tools/dotc/transform/SymUtils.scala
@@ -7,6 +7,8 @@ import Contexts._
import Symbols._
import Decorators._
import Names._
+import StdNames._
+import Flags._
import language.implicitConversions
object SymUtils {
@@ -17,9 +19,31 @@ object SymUtils {
* that are needed in the transformer pipeline.
*/
class SymUtils(val self: Symbol) extends AnyVal {
+ import SymUtils._
def isTypeTestOrCast(implicit ctx: Context): Boolean =
self == defn.Any_asInstanceOf || self == defn.Any_isInstanceOf
def isVolatile(implicit ctx: Context) = self.hasAnnotation(defn.VolatileAnnot)
+
+ /** If this is a constructor, its owner: otherwise this. */
+ final def skipConstructor(implicit ctx: Context): Symbol =
+ if (self.isConstructor) self.owner else self
+
+ final def isAnonymousFunction(implicit ctx: Context): Boolean =
+ self.is(Method) && (self.denot.initial.asSymDenotation.name startsWith nme.ANON_FUN)
+
+ /** The logically enclosing method or class for this symbol.
+ * Instead of constructors one always picks the enclosing class.
+ */
+ final def enclosure(implicit ctx: Context) = self.owner.enclosingMethod.skipConstructor
+
+ /** Apply symbol/symbol substitution to this symbol */
+ def subst(from: List[Symbol], to: List[Symbol]): Symbol = {
+ def loop(from: List[Symbol], to: List[Symbol]): Symbol =
+ if (from.isEmpty) self
+ else if (self eq from.head) to.head
+ else loop(from.tail, to.tail)
+ loop(from, to)
+ }
}