summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2013-12-16 21:50:11 +0100
committerEugene Burmako <xeno.by@gmail.com>2013-12-19 23:38:00 +0100
commit3ef5837be595034949ea083fe0062dc22cb69fa5 (patch)
treea9f449db0704cc9bd488da1c224821b067177469
parentdbe7a366c994fe359edc368bfcd8a6a35a00e0da (diff)
downloadscala-3ef5837be595034949ea083fe0062dc22cb69fa5.tar.gz
scala-3ef5837be595034949ea083fe0062dc22cb69fa5.tar.bz2
scala-3ef5837be595034949ea083fe0062dc22cb69fa5.zip
cosmetic changes to liftables
Namely: 1) Moved definitions of Liftable and Unliftable into a separate file. 2) Inlined internal names that were only used in StandardLiftables.
-rw-r--r--src/reflect/scala/reflect/api/Liftables.scala30
-rw-r--r--src/reflect/scala/reflect/api/StandardLiftables.scala40
-rw-r--r--src/reflect/scala/reflect/api/StandardNames.scala14
-rw-r--r--src/reflect/scala/reflect/api/Universe.scala1
-rw-r--r--src/reflect/scala/reflect/internal/StdNames.scala14
-rw-r--r--src/reflect/scala/reflect/runtime/JavaUniverseForce.scala3
6 files changed, 58 insertions, 44 deletions
diff --git a/src/reflect/scala/reflect/api/Liftables.scala b/src/reflect/scala/reflect/api/Liftables.scala
new file mode 100644
index 0000000000..6ac5557caa
--- /dev/null
+++ b/src/reflect/scala/reflect/api/Liftables.scala
@@ -0,0 +1,30 @@
+package scala
+package reflect
+package api
+
+// TODO: needs a Scaladoc
+trait Liftables { self: Universe =>
+
+ // TODO: needs a Scaladoc
+ trait Liftable[T] {
+ def apply(value: T): Tree
+ }
+
+ // TODO: needs a Scaladoc
+ object Liftable extends StandardLiftableInstances {
+ def apply[T](f: T => Tree): Liftable[T] =
+ new Liftable[T] { def apply(value: T): Tree = f(value) }
+ }
+
+ // TODO: needs a Scaladoc
+ trait Unliftable[T] {
+ def unapply(tree: Tree): Option[T]
+ }
+
+ // TODO: needs a Scaladoc
+ object Unliftable extends StandardUnliftableInstances {
+ def apply[T](pf: PartialFunction[Tree, T]): Unliftable[T] = new Unliftable[T] {
+ def unapply(value: Tree): Option[T] = pf.lift(value)
+ }
+ }
+}
diff --git a/src/reflect/scala/reflect/api/StandardLiftables.scala b/src/reflect/scala/reflect/api/StandardLiftables.scala
index 57464459be..6756d5e114 100644
--- a/src/reflect/scala/reflect/api/StandardLiftables.scala
+++ b/src/reflect/scala/reflect/api/StandardLiftables.scala
@@ -4,14 +4,7 @@ package api
trait StandardLiftables { self: Universe =>
import build.{SyntacticTuple, ScalaDot}
- trait Liftable[T] {
- def apply(value: T): Tree
- }
-
- object Liftable {
- def apply[T](f: T => Tree): Liftable[T] =
- new Liftable[T] { def apply(value: T): Tree = f(value) }
-
+ trait StandardLiftableInstances {
private def lift[T: Liftable](value: T): Tree = implicitly[Liftable[T]].apply(value)
private def selectScala(names: Name*) = names.tail.foldLeft(ScalaDot(names.head)) { Select(_, _) }
private def callScala(names: Name*)(args: List[Tree]) = Apply(selectScala(names: _*), args)
@@ -122,15 +115,7 @@ trait StandardLiftables { self: Universe =>
}
}
- trait Unliftable[T] {
- def unapply(tree: Tree): Option[T]
- }
-
- object Unliftable {
- def apply[T](pf: PartialFunction[Tree, T]): Unliftable[T] = new Unliftable[T] {
- def unapply(value: Tree): Option[T] = pf.lift(value)
- }
-
+ trait StandardUnliftableInstances {
private def unliftPrimitive[Unboxed: ClassTag, Boxed: ClassTag] = Unliftable[Unboxed] {
case Literal(Constant(value))
if value.getClass == implicitly[ClassTag[Boxed]].runtimeClass
@@ -149,7 +134,7 @@ trait StandardLiftables { self: Universe =>
implicit def unliftString: Unliftable[String] = Unliftable { case Literal(Constant(s: String)) => s }
implicit def unliftScalaSymbol: Unliftable[scala.Symbol] = Unliftable {
- case Apply(ScalaDot(nme.Symbol), List(Literal(Constant(name: String)))) => scala.Symbol(name)
+ case Apply(ScalaDot(symbol), List(Literal(Constant(name: String)))) if symbol == nme.Symbol => scala.Symbol(name)
}
implicit def unliftName[T <: Name : ClassTag]: Unliftable[T] = Unliftable[T] { case Ident(name: T) => name; case Bind(name: T, Ident(nme.WILDCARD)) => name}
@@ -223,4 +208,23 @@ trait StandardLiftables { self: Universe =>
case SyntacticTuple(UnliftT1(v1) :: UnliftT2(v2) :: UnliftT3(v3) :: UnliftT4(v4) :: UnliftT5(v5) :: UnliftT6(v6) :: UnliftT7(v7) :: UnliftT8(v8) :: UnliftT9(v9) :: UnliftT10(v10) :: UnliftT11(v11) :: UnliftT12(v12) :: UnliftT13(v13) :: UnliftT14(v14) :: UnliftT15(v15) :: UnliftT16(v16) :: UnliftT17(v17) :: UnliftT18(v18) :: UnliftT19(v19) :: UnliftT20(v20) :: UnliftT21(v21) :: UnliftT22(v22) :: Nil) => Tuple22(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22)
}
}
+
+ // names used internally by implementations of standard liftables and unliftables
+ import scala.language.implicitConversions
+ private implicit def cachedNames(nme: self.nme.type): CachedNames.type = CachedNames
+ private object CachedNames {
+ val Array = TermName("Array")
+ val collection = TermName("collection")
+ val immutable = TermName("immutable")
+ val Left = TermName("Left")
+ val List = TermName("List")
+ val Map = TermName("Map")
+ val None = TermName("None")
+ val Right = TermName("Right")
+ val Set = TermName("Set")
+ val Some = TermName("Some")
+ val Symbol = TermName("Symbol")
+ val Vector = TermName("Vector")
+ val util = TermName("util")
+ }
}
diff --git a/src/reflect/scala/reflect/api/StandardNames.scala b/src/reflect/scala/reflect/api/StandardNames.scala
index 4ea6ddc7f8..aec5f19fa0 100644
--- a/src/reflect/scala/reflect/api/StandardNames.scala
+++ b/src/reflect/scala/reflect/api/StandardNames.scala
@@ -96,20 +96,6 @@ trait StandardNames {
* of non-private vals and vars are renamed using `LOCAL_SUFFIX_STRING`.
*/
val LOCAL_SUFFIX_STRING: String
-
- protected[reflect] val Array: NameType
- protected[reflect] val collection: NameType
- protected[reflect] val immutable: NameType
- protected[reflect] val Left: NameType
- protected[reflect] val List: NameType
- protected[reflect] val Map: NameType
- protected[reflect] val None: NameType
- protected[reflect] val Right: NameType
- protected[reflect] val Set: NameType
- protected[reflect] val Some: NameType
- protected[reflect] val Symbol: NameType
- protected[reflect] val util: NameType
- protected[reflect] val Vector: NameType
}
/** Defines standard type names that can be accessed via the [[tpnme]] member.
diff --git a/src/reflect/scala/reflect/api/Universe.scala b/src/reflect/scala/reflect/api/Universe.scala
index 534f69a23e..1da2c24306 100644
--- a/src/reflect/scala/reflect/api/Universe.scala
+++ b/src/reflect/scala/reflect/api/Universe.scala
@@ -78,6 +78,7 @@ abstract class Universe extends Symbols
with Mirrors
with Printers
with Importers
+ with Liftables
with Quasiquotes
{
/** Use `refiy` to produce the abstract syntax tree representing a given Scala expression.
diff --git a/src/reflect/scala/reflect/internal/StdNames.scala b/src/reflect/scala/reflect/internal/StdNames.scala
index 5ad2b15e8c..111adc1c28 100644
--- a/src/reflect/scala/reflect/internal/StdNames.scala
+++ b/src/reflect/scala/reflect/internal/StdNames.scala
@@ -124,15 +124,8 @@ trait StdNames {
final val AnyRef: NameType = "AnyRef"
final val Array: NameType = "Array"
final val List: NameType = "List"
- final val Left: NameType = "Left"
- final val Right: NameType = "Right"
- final val Vector: NameType = "Vector"
final val Seq: NameType = "Seq"
- final val Set: NameType = "Set"
- final val Some: NameType = "Some"
final val Symbol: NameType = "Symbol"
- final val Map: NameType = "Map"
- final val None: NameType = "None"
final val WeakTypeTag: NameType = "WeakTypeTag"
final val TypeTag : NameType = "TypeTag"
final val Expr: NameType = "Expr"
@@ -763,7 +756,6 @@ trait StdNames {
val typedProductIterator: NameType = "typedProductIterator"
val TypeName: NameType = "TypeName"
val typeTagToManifest: NameType = "typeTagToManifest"
- val util: NameType = "util"
val unapply: NameType = "unapply"
val unapplySeq: NameType = "unapplySeq"
val unbox: NameType = "unbox"
@@ -799,7 +791,7 @@ trait StdNames {
final val STAR : NameType = "*"
final val TILDE: NameType = "~"
- final val isUnary: Set[Name] = scala.collection.immutable.Set(MINUS, PLUS, TILDE, BANG)
+ final val isUnary: Set[Name] = Set(MINUS, PLUS, TILDE, BANG)
}
// value-conversion methods
@@ -852,8 +844,8 @@ trait StdNames {
val UNARY_! = encode("unary_!")
// Grouped here so Cleanup knows what tests to perform.
- val CommonOpNames = scala.collection.immutable.Set[Name](OR, XOR, AND, EQ, NE)
- val BooleanOpNames = scala.collection.immutable.Set[Name](ZOR, ZAND, UNARY_!) ++ CommonOpNames
+ val CommonOpNames = Set[Name](OR, XOR, AND, EQ, NE)
+ val BooleanOpNames = Set[Name](ZOR, ZAND, UNARY_!) ++ CommonOpNames
val add: NameType = "add"
val complement: NameType = "complement"
diff --git a/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala b/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala
index 0f41506382..9c4a3a5fe1 100644
--- a/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala
+++ b/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala
@@ -204,9 +204,10 @@ trait JavaUniverseForce { self: runtime.JavaUniverse =>
// inaccessible: this.TypeHistory
this.TermName
this.TypeName
- this.BooleanFlag
this.Liftable
this.Unliftable
+ this.BooleanFlag
+ // inaccessible: this.CachedNames
this.WeakTypeTag
this.TypeTag
this.Expr