aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core/Signature.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-11-27 14:17:12 +0100
committerMartin Odersky <odersky@gmail.com>2013-11-27 14:17:12 +0100
commitf8c9dc95929655a198066652cd12109329836198 (patch)
tree32f8c29e89ad426b7c0d6947cdda44878dc414fe /src/dotty/tools/dotc/core/Signature.scala
parentf0b4fc58e0c5e5372c23bd817954ed3aa82b2102 (diff)
downloaddotty-f8c9dc95929655a198066652cd12109329836198.tar.gz
dotty-f8c9dc95929655a198066652cd12109329836198.tar.bz2
dotty-f8c9dc95929655a198066652cd12109329836198.zip
Changed Signatures
Signatures have a different meaning before and after erasure. After erasure, the result type counts also whereas before it doesn't. The new definitions refelect this behavior.
Diffstat (limited to 'src/dotty/tools/dotc/core/Signature.scala')
-rw-r--r--src/dotty/tools/dotc/core/Signature.scala56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/core/Signature.scala b/src/dotty/tools/dotc/core/Signature.scala
new file mode 100644
index 000000000..50c42e96d
--- /dev/null
+++ b/src/dotty/tools/dotc/core/Signature.scala
@@ -0,0 +1,56 @@
+package dotty.tools.dotc
+package core
+
+import Names._, Types._, Contexts._
+import transform.Erasure.sigName
+
+/** The signature of a denotation.
+ * Overloaded denotations with the same name are distinguished by
+ * their signatures. A signature of a method (of type PolyType,MethodType, or ExprType) is
+ * composed of a list of signature names, one for each parameter type, plus a signature for
+ * the result type. Methods are uncurried before taking their signatures.
+ * The signature name of a type is the fully qualified name of the type symbol of the type's erasure.
+ *
+ * For instance a definition
+ *
+ * def f(x: Int)(y: List[String]): String
+ *
+ * would have signature
+ *
+ * Signature(
+ * List("scala.Int".toTypeName, "scala.collection.immutable.List".toTypeName),
+ * "scala.String".toTypeName)
+ *
+ * The signatures of non-method types are always `NotAMethod`.
+ */
+case class Signature private (paramsSig: List[TypeName], resSig: TypeName) {
+
+ /** Does this signature conincide with that signature on their parameter parts? */
+ final def sameParams(that: Signature): Boolean = this.paramsSig == that.paramsSig
+
+ /** The meaning of `matches` depends on the phase. If types are not erased,
+ * it means `sameParams`. Once types are erased, it means `==`, comparing parameter as
+ * well as result type parts.
+ */
+ final def matches(that: Signature)(implicit ctx: Context) =
+ if (ctx.erasedTypes) equals(that) else sameParams(that)
+
+ /** Construct a signature by prepending the signature names of the given `params`
+ * to the parameter part of this signature.
+ */
+ def ++:(params: List[Type])(implicit ctx: Context) =
+ Signature((params map sigName) ++ paramsSig, resSig)
+
+}
+
+object Signature {
+
+ /** The signature of everything that's not a method, i.e. that has
+ * a type different from PolyType, MethodType, or ExprType.
+ */
+ val NotAMethod = Signature(List(EmptyTypeName), EmptyTypeName)
+
+ /** The signature of a method with no parameters and result type `resultType`. */
+ def apply(resultType: Type)(implicit ctx: Context): Signature =
+ apply(Nil, sigName(resultType))
+} \ No newline at end of file