aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/transform/ValueClasses.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-07-07 11:52:38 +0200
committerMartin Odersky <odersky@gmail.com>2014-07-17 11:02:00 +0200
commit3eabbb77c8f8bd3e08b39e5335e8a67e2d68e659 (patch)
tree3443ff1c5613c5e1fd3a6659571c1454c8d18695 /src/dotty/tools/dotc/transform/ValueClasses.scala
parentab8d873430c22337c6fc6332cad5708514fd5fa0 (diff)
downloaddotty-3eabbb77c8f8bd3e08b39e5335e8a67e2d68e659.tar.gz
dotty-3eabbb77c8f8bd3e08b39e5335e8a67e2d68e659.tar.bz2
dotty-3eabbb77c8f8bd3e08b39e5335e8a67e2d68e659.zip
Move valueclass functionality into its own ValueClass module.
Diffstat (limited to 'src/dotty/tools/dotc/transform/ValueClasses.scala')
-rw-r--r--src/dotty/tools/dotc/transform/ValueClasses.scala36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/transform/ValueClasses.scala b/src/dotty/tools/dotc/transform/ValueClasses.scala
new file mode 100644
index 000000000..c5cf44552
--- /dev/null
+++ b/src/dotty/tools/dotc/transform/ValueClasses.scala
@@ -0,0 +1,36 @@
+package dotty.tools.dotc
+package transform
+
+import core._
+import Types._
+import Symbols._
+import SymDenotations._
+import Contexts._
+import Flags._
+
+/** Methods that apply to user-defined value classes */
+object ValueClasses {
+
+ def isDerivedValueClass(d: SymDenotation)(implicit ctx: Context) =
+ d.isClass && d.derivesFrom(defn.AnyValClass) && !d.isPrimitiveValueClass
+
+ def isMethodWithExtension(d: SymDenotation)(implicit ctx: Context) =
+ d.isSourceMethod &&
+ isDerivedValueClass(d.owner) &&
+ !d.isConstructor &&
+ !d.is(SuperAccessor) &&
+ !d.is(Macro)
+
+ /** The member that of a derived value class that unboxes it. */
+ def valueClassUnbox(d: ClassDenotation)(implicit ctx: Context): Symbol =
+ // (info.decl(nme.unbox)).orElse(...) uncomment once we accept unbox methods
+ d.classInfo.decls
+ .find(d => d.isTerm && d.symbol.is(ParamAccessor))
+ .map(_.symbol)
+ .getOrElse(NoSymbol)
+
+ /** The unboxed type that underlies a derived value class */
+ def underlyingOfValueClass(d: ClassDenotation)(implicit ctx: Context): Type =
+ valueClassUnbox(d).info.resultType
+
+}