summaryrefslogtreecommitdiff
path: root/src/compiler/scala/reflect/internal/Definitions.scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2011-12-27 15:54:32 -0800
committerPaul Phillips <paulp@improving.org>2011-12-28 08:43:13 -0800
commitd05881e42e661986286ac15c2a8c32f651b0101e (patch)
treee09f124ca83106f542682d51bc10e430c35bdd72 /src/compiler/scala/reflect/internal/Definitions.scala
parent33ab1a574af0d5f736ab73c5a18cc6a4cb36cbb0 (diff)
downloadscala-d05881e42e661986286ac15c2a8c32f651b0101e.tar.gz
scala-d05881e42e661986286ac15c2a8c32f651b0101e.tar.bz2
scala-d05881e42e661986286ac15c2a8c32f651b0101e.zip
repl power mode improvements.
Implemented great suggestion from moors. More imports in power mode, including the contents of treedsl. Also, another swing at overcoming the mismatched global singletons problem, this time taking advantage of dependent method types. Amazingly, it seems to work. Continuing in the quest to create a useful compiler hacking environment, there is now an implicit from Symbol which allows you to pretend a Symbol takes type parameters, and the result is the applied type based on the manifests of the type arguments and the type constructor of the symbol. Examples: // magic with manifests scala> val tp = ArrayClass[scala.util.Random] tp: $r.global.Type = Array[scala.util.Random] // evidence scala> tp.memberType(Array_apply) res0: $r.global.Type = (i: Int)scala.util.Random // treedsl scala> val m = LIT(10) MATCH (CASE(LIT(5)) ==> FALSE, DEFAULT ==> TRUE) m: $r.treedsl.global.Match = 10 match { case 5 => false case _ => true } // typed is in scope scala> typed(m).tpe res1: $r.treedsl.global.Type = Boolean
Diffstat (limited to 'src/compiler/scala/reflect/internal/Definitions.scala')
-rw-r--r--src/compiler/scala/reflect/internal/Definitions.scala24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/compiler/scala/reflect/internal/Definitions.scala b/src/compiler/scala/reflect/internal/Definitions.scala
index 15f89e1382..fe20613c22 100644
--- a/src/compiler/scala/reflect/internal/Definitions.scala
+++ b/src/compiler/scala/reflect/internal/Definitions.scala
@@ -386,6 +386,30 @@ trait Definitions extends reflect.api.StandardDefinitions {
lazy val NoneModule: Symbol = getModule("scala.None")
lazy val SomeModule: Symbol = getModule("scala.Some")
+ /** Note: don't use this manifest/type function for anything important,
+ * as it is incomplete. Would love to have things like existential types
+ * working, but very unfortunately the manifests just stuff the relevant
+ * information into the toString method.
+ */
+ def manifestToType(m: OptManifest[_]): Type = m match {
+ case x: AnyValManifest[_] =>
+ getClassIfDefined("scala." + x).tpe
+ case m: ClassManifest[_] =>
+ val name = m.erasure.getName
+ if (name endsWith nme.MODULE_SUFFIX_STRING)
+ getModuleIfDefined(name stripSuffix nme.MODULE_SUFFIX_STRING).tpe
+ else {
+ val sym = getClassIfDefined(name)
+ val args = m.typeArguments
+
+ if (sym eq NoSymbol) NoType
+ else if (args.isEmpty) sym.tpe
+ else appliedType(sym.typeConstructor, args map manifestToType)
+ }
+ case _ =>
+ NoType
+ }
+
// The given symbol represents either String.+ or StringAdd.+
def isStringAddition(sym: Symbol) = sym == String_+ || sym == StringAdd_+
def isArrowAssoc(sym: Symbol) = ArrowAssocClass.tpe.decls.toList contains sym