Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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.
  • Loading branch information...
commit 3ef5837be595034949ea083fe0062dc22cb69fa5 1 parent dbe7a36
@xeno-by xeno-by authored
View
30 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)
+ }
+ }
+}
View
40 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")
+ }
}
View
14 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.
View
1  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.
View
14 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"
View
3  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
Please sign in to comment.
Something went wrong with that request. Please try again.