diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2012-09-19 15:04:50 +0200 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2012-09-19 22:47:10 +0200 |
commit | 3fa900ca0ea244ac54df75dc2fd6d711739eface (patch) | |
tree | bd37a549da114d7030a7cbce14ecc527058dd1ad /src/library | |
parent | eadf1d2080e0ce763e4c1920a26b80c8b8609ca0 (diff) | |
download | scala-3fa900ca0ea244ac54df75dc2fd6d711739eface.tar.gz scala-3fa900ca0ea244ac54df75dc2fd6d711739eface.tar.bz2 scala-3fa900ca0ea244ac54df75dc2fd6d711739eface.zip |
SI-6363 removes scala.reflect.base
As the experience has shown, there's no need for a separate layer of reflection
in scala-library.jar. Therefore I'm putting an end to it.
Diffstat (limited to 'src/library')
26 files changed, 29 insertions, 4371 deletions
diff --git a/src/library/scala/reflect/ClassTag.scala b/src/library/scala/reflect/ClassTag.scala index 1a574836c0..5c2067a548 100644 --- a/src/library/scala/reflect/ClassTag.scala +++ b/src/library/scala/reflect/ClassTag.scala @@ -11,13 +11,13 @@ import scala.runtime.ScalaRunTime.{ arrayClass, arrayElementClass } * The runtime class (i.e. the erasure, a java.lang.Class on the JVM) of T can be accessed * via the `runtimeClass` field. References to type parameters or abstract type members are * replaced by the concrete types if ClassTags are available for them. - * + * * Besides accessing the erasure, a ClassTag knows how to instantiate single- and multi- * dimensional `Arrays` where the element type is unknown at compile time. * * [[scala.reflect.ClassTag]] corresponds to a previous concept of [[scala.reflect.ClassManifest]]. * - * @see [[scala.reflect.base.TypeTags]] + * @see [[scala.reflect.api.TypeTags]] */ @scala.annotation.implicitNotFound(msg = "No ClassTag available for ${T}") trait ClassTag[T] extends ClassManifestDeprecatedApis[T] with Equals with Serializable { diff --git a/src/library/scala/reflect/base/Annotations.scala b/src/library/scala/reflect/base/Annotations.scala deleted file mode 100644 index 107443f09b..0000000000 --- a/src/library/scala/reflect/base/Annotations.scala +++ /dev/null @@ -1,106 +0,0 @@ -package scala.reflect -package base - -import scala.collection.immutable.ListMap - -/** - * Defines the type hierarchy for annotations. - */ -trait Annotations { self: Universe => - - /** Typed information about an annotation. It can be attached to either a symbol or an annotated type. - * - * Annotations are either ''Scala annotations'', which conform to [[scala.annotation.StaticAnnotation]] - * or ''Java annotations'', which conform to [[scala.annotation.ClassfileAnnotation]]. - * Trait `ClassfileAnnotation` is automatically added to every Java annotation by the scalac classfile parser. - */ - type Annotation >: Null <: AnyRef - - /** A tag that preserves the identity of the `Annotation` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val AnnotationTag: ClassTag[Annotation] - - /** The constructor/deconstructor for `Annotation` instances. */ - val Annotation: AnnotationExtractor - - /** An extractor class to create and pattern match with syntax `Annotation(atp, scalaArgs, javaArgs)`. - * Here, `atp` is the annotation type, `scalaArgs` the arguments, and `javaArgs` the annotation's key-value - * pairs. - * - * Annotations are pickled, i.e. written to scala symtab attribute in the classfile. - * Annotations are written to the classfile as Java annotations if `atp` conforms to `ClassfileAnnotation`. - * - * For Scala annotations, arguments are stored in `scalaArgs` and `javaArgs` is empty. Arguments in - * `scalaArgs` are represented as typed trees. Note that these trees are not transformed by any phases - * following the type-checker. For Java annotations, `scalaArgs` is empty and arguments are stored in - * `javaArgs`. - */ - abstract class AnnotationExtractor { - def apply(tpe: Type, scalaArgs: List[Tree], javaArgs: ListMap[Name, JavaArgument]): Annotation - def unapply(ann: Annotation): Option[(Type, List[Tree], ListMap[Name, JavaArgument])] - } - - /** A Java annotation argument */ - type JavaArgument >: Null <: AnyRef - implicit val JavaArgumentTag: ClassTag[JavaArgument] - - /** A literal argument to a Java annotation as `"Use X instead"` in `@Deprecated("Use X instead")`*/ - type LiteralArgument >: Null <: AnyRef with JavaArgument - - /** A tag that preserves the identity of the `LiteralArgument` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val LiteralArgumentTag: ClassTag[LiteralArgument] - - /** The constructor/deconstructor for `LiteralArgument` instances. */ - val LiteralArgument: LiteralArgumentExtractor - - /** An extractor class to create and pattern match with syntax `LiteralArgument(value)` - * where `value` is the constant argument. - */ - abstract class LiteralArgumentExtractor { - def apply(value: Constant): LiteralArgument - def unapply(arg: LiteralArgument): Option[Constant] - } - - /** An array argument to a Java annotation as in `@Target(value={TYPE,FIELD,METHOD,PARAMETER})` - */ - type ArrayArgument >: Null <: AnyRef with JavaArgument - - /** A tag that preserves the identity of the `ArrayArgument` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val ArrayArgumentTag: ClassTag[ArrayArgument] - - /** The constructor/deconstructor for `ArrayArgument` instances. */ - val ArrayArgument: ArrayArgumentExtractor - - /** An extractor class to create and pattern match with syntax `ArrayArgument(args)` - * where `args` is the argument array. - */ - abstract class ArrayArgumentExtractor { - def apply(args: Array[JavaArgument]): ArrayArgument - def unapply(arg: ArrayArgument): Option[Array[JavaArgument]] - } - - /** A nested annotation argument to a Java annotation as `@Nested` in `@Outer(@Nested)`. - */ - type NestedArgument >: Null <: AnyRef with JavaArgument - - /** A tag that preserves the identity of the `NestedArgument` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val NestedArgumentTag: ClassTag[NestedArgument] - - /** The constructor/deconstructor for `NestedArgument` instances. */ - val NestedArgument: NestedArgumentExtractor - - /** An extractor class to create and pattern match with syntax `NestedArgument(annotation)` - * where `annotation` is the nested annotation. - */ - abstract class NestedArgumentExtractor { - def apply(annotation: Annotation): NestedArgument - def unapply(arg: NestedArgument): Option[Annotation] - } -}
\ No newline at end of file diff --git a/src/library/scala/reflect/base/Attachments.scala b/src/library/scala/reflect/base/Attachments.scala deleted file mode 100644 index 479ab9a857..0000000000 --- a/src/library/scala/reflect/base/Attachments.scala +++ /dev/null @@ -1,52 +0,0 @@ -package scala.reflect -package base - -/** Attachments is a generalization of Position. Typically it stores a Position of a tree, but this can be extended to - * encompass arbitrary payloads. Payloads are stored in type-indexed slots, which can be read with `get[T]` and written - * with `update[T]` and `remove[T]`. - * - * Attachments always carry positions because we don't want to introduce an additional field for attachments in `Tree` - * imposing an unnecessary memory tax because of something that will not be used in most cases. - */ -abstract class Attachments { self => - - /** The position type of this attachment */ - type Pos >: Null - - /** The underlying position */ - def pos: Pos - - /** Creates a copy of this attachment with the position replaced by `newPos` */ - def withPos(newPos: Pos): Attachments { type Pos = self.Pos } - - /** The underlying payload with the guarantee that no two elements have the same type. */ - def all: Set[Any] = Set.empty - - private def matchesTag[T: ClassTag](datum: Any) = - classTag[T].runtimeClass == datum.getClass - - /** An underlying payload of the given class type `T`. */ - def get[T: ClassTag]: Option[T] = - (all filter matchesTag[T]).headOption.asInstanceOf[Option[T]] - - /** Creates a copy of this attachment with the payload slot of T added/updated with the provided value. - * - * Replaces an existing payload of the same type, if exists. - */ - def update[T: ClassTag](attachment: T): Attachments { type Pos = self.Pos } = - new NonemptyAttachments(this.pos, remove[T].all + attachment) - - /** Creates a copy of this attachment with the payload of the given class type `T` removed. */ - def remove[T: ClassTag]: Attachments { type Pos = self.Pos } = { - val newAll = all filterNot matchesTag[T] - if (newAll.isEmpty) pos.asInstanceOf[Attachments { type Pos = self.Pos }] - else new NonemptyAttachments(this.pos, newAll) - } - - private class NonemptyAttachments(override val pos: Pos, override val all: Set[Any]) extends Attachments { - type Pos = self.Pos - def withPos(newPos: Pos) = new NonemptyAttachments(newPos, all) - } -} - - diff --git a/src/library/scala/reflect/base/Base.scala b/src/library/scala/reflect/base/Base.scala deleted file mode 100644 index 5136f41df4..0000000000 --- a/src/library/scala/reflect/base/Base.scala +++ /dev/null @@ -1,765 +0,0 @@ -package scala.reflect -package base - -import java.io.PrintWriter -import scala.annotation.switch -import scala.ref.WeakReference -import scala.collection.mutable -import scala.collection.immutable.ListMap - -/** - * This is an internal implementation class. - */ -class Base extends Universe { self => - - private var nextId = 0 - - abstract class Symbol(val name: Name, val flags: FlagSet) extends SymbolBase { - val id = { nextId += 1; nextId } - def owner: Symbol - def fullName: String = - if (isEffectiveRoot || owner.isEffectiveRoot) name.toString else owner.fullName + "." + name - private def isEffectiveRoot = - this == NoSymbol || this == rootMirror.RootClass || this == rootMirror.EmptyPackageClass - - def newTermSymbol(name: TermName, pos: Position = NoPosition, flags: FlagSet = NoFlags): TermSymbol = - new TermSymbol(this, name, flags) - - def newModuleAndClassSymbol(name: Name, pos: Position = NoPosition, flags: FlagSet = NoFlags): (ModuleSymbol, ClassSymbol) = { - val c = new ModuleClassSymbol(this, name.toTypeName, flags) - val m = new ModuleSymbol(this, name.toTermName, flags, c) - (m, c) - } - - def newMethodSymbol(name: TermName, pos: Position = NoPosition, flags: FlagSet = NoFlags): MethodSymbol - = new MethodSymbol(this, name, flags) - - def newTypeSymbol(name: TypeName, pos: Position = NoPosition, flags: FlagSet = NoFlags): TypeSymbol = - new TypeSymbol(this, name, flags) - - def newClassSymbol(name: TypeName, pos: Position = NoPosition, flags: FlagSet = NoFlags): ClassSymbol = - new ClassSymbol(this, name, flags) - - def newFreeTermSymbol(name: TermName, value: => Any, flags: FlagSet = NoFlags, origin: String = null) = - new FreeTermSymbol(this, name, flags) - - def newFreeTypeSymbol(name: TypeName, flags: FlagSet = NoFlags, origin: String = null) = - new FreeTypeSymbol(this, name, flags) - - private def kindString: String = - if (isModule) "module" - else if (isClass) "class" - else if (isFreeType) "free type" - else if (isType) "type" - else if (isMethod) "method" - else if (isFreeTerm) "free term" - else if (isTerm) "value" - else "symbol" - override def toString() = s"$kindString $name" - } - implicit val SymbolTag = ClassTag[Symbol](classOf[Symbol]) - - class TermSymbol(val owner: Symbol, override val name: TermName, flags: FlagSet) - extends Symbol(name, flags) with TermSymbolBase - implicit val TermSymbolTag = ClassTag[TermSymbol](classOf[TermSymbol]) - - class TypeSymbol(val owner: Symbol, override val name: TypeName, flags: FlagSet) - extends Symbol(name, flags) with TypeSymbolBase { - override def toTypeConstructor = TypeRef(ThisType(owner), this, Nil) - override def toType = TypeRef(ThisType(owner), this, Nil) - override def toTypeIn(site: Type) = TypeRef(ThisType(owner), this, Nil) - } - implicit val TypeSymbolTag = ClassTag[TypeSymbol](classOf[TypeSymbol]) - - class MethodSymbol(owner: Symbol, name: TermName, flags: FlagSet) - extends TermSymbol(owner, name, flags) with MethodSymbolBase - implicit val MethodSymbolTag = ClassTag[MethodSymbol](classOf[MethodSymbol]) - - class ModuleSymbol(owner: Symbol, name: TermName, flags: FlagSet, override val moduleClass: Symbol) - extends TermSymbol(owner, name, flags) with ModuleSymbolBase - implicit val ModuleSymbolTag = ClassTag[ModuleSymbol](classOf[ModuleSymbol]) - - class ClassSymbol(owner: Symbol, name: TypeName, flags: FlagSet) - extends TypeSymbol(owner, name, flags) with ClassSymbolBase - class ModuleClassSymbol(owner: Symbol, name: TypeName, flags: FlagSet) - extends ClassSymbol(owner, name, flags) { override def isModuleClass = true } - implicit val ClassSymbolTag = ClassTag[ClassSymbol](classOf[ClassSymbol]) - - class FreeTermSymbol(owner: Symbol, name: TermName, flags: FlagSet) - extends TermSymbol(owner, name, flags) with FreeTermSymbolBase - implicit val FreeTermSymbolTag = ClassTag[FreeTermSymbol](classOf[FreeTermSymbol]) - - class FreeTypeSymbol(owner: Symbol, name: TypeName, flags: FlagSet) - extends TypeSymbol(owner, name, flags) with FreeTypeSymbolBase - implicit val FreeTypeSymbolTag = ClassTag[FreeTypeSymbol](classOf[FreeTypeSymbol]) - - - object NoSymbol extends Symbol(nme.NO_NAME, NoFlags) { - override def owner = throw new UnsupportedOperationException("NoSymbol.owner") - } - - // todo. write a decent toString that doesn't crash on recursive types - class Type extends TypeBase { - def termSymbol: Symbol = NoSymbol - def typeSymbol: Symbol = NoSymbol - } - implicit val TypeTagg = ClassTag[Type](classOf[Type]) - - val NoType = new Type { override def toString = "NoType" } - val NoPrefix = new Type { override def toString = "NoPrefix" } - - class SingletonType extends Type - implicit val SingletonTypeTag = ClassTag[SingletonType](classOf[SingletonType]) - - case class ThisType(sym: Symbol) extends SingletonType { override val typeSymbol = sym } - object ThisType extends ThisTypeExtractor - implicit val ThisTypeTag = ClassTag[ThisType](classOf[ThisType]) - - case class SingleType(pre: Type, sym: Symbol) extends SingletonType { override val termSymbol = sym } - object SingleType extends SingleTypeExtractor - implicit val SingleTypeTag = ClassTag[SingleType](classOf[SingleType]) - - case class SuperType(thistpe: Type, supertpe: Type) extends SingletonType - object SuperType extends SuperTypeExtractor - implicit val SuperTypeTag = ClassTag[SuperType](classOf[SuperType]) - - case class ConstantType(value: Constant) extends SingletonType - object ConstantType extends ConstantTypeExtractor - implicit val ConstantTypeTag = ClassTag[ConstantType](classOf[ConstantType]) - - case class TypeRef(pre: Type, sym: Symbol, args: List[Type]) extends Type { override val typeSymbol = sym } - object TypeRef extends TypeRefExtractor - implicit val TypeRefTag = ClassTag[TypeRef](classOf[TypeRef]) - - abstract class CompoundType extends Type - implicit val CompoundTypeTag = ClassTag[CompoundType](classOf[CompoundType]) - - case class RefinedType(parents: List[Type], decls: Scope) extends CompoundType - object RefinedType extends RefinedTypeExtractor { - def apply(parents: List[Type], decls: Scope, clazz: Symbol): RefinedType = - RefinedType(parents, decls) - } - implicit val RefinedTypeTag = ClassTag[RefinedType](classOf[RefinedType]) - - case class ClassInfoType(parents: List[Type], decls: Scope, override val typeSymbol: Symbol) extends CompoundType - object ClassInfoType extends ClassInfoTypeExtractor - implicit val ClassInfoTypeTag = ClassTag[ClassInfoType](classOf[ClassInfoType]) - - case class MethodType(params: List[Symbol], resultType: Type) extends Type - object MethodType extends MethodTypeExtractor - implicit val MethodTypeTag = ClassTag[MethodType](classOf[MethodType]) - - case class NullaryMethodType(resultType: Type) extends Type - object NullaryMethodType extends NullaryMethodTypeExtractor - implicit val NullaryMethodTypeTag = ClassTag[NullaryMethodType](classOf[NullaryMethodType]) - - case class PolyType(typeParams: List[Symbol], resultType: Type) extends Type - object PolyType extends PolyTypeExtractor - implicit val PolyTypeTag = ClassTag[PolyType](classOf[PolyType]) - - case class ExistentialType(quantified: List[Symbol], underlying: Type) extends Type { override def typeSymbol = underlying.typeSymbol } - object ExistentialType extends ExistentialTypeExtractor - implicit val ExistentialTypeTag = ClassTag[ExistentialType](classOf[ExistentialType]) - - case class AnnotatedType(annotations: List[Annotation], underlying: Type, selfsym: Symbol) extends Type { override def typeSymbol = underlying.typeSymbol } - object AnnotatedType extends AnnotatedTypeExtractor - implicit val AnnotatedTypeTag = ClassTag[AnnotatedType](classOf[AnnotatedType]) - - case class TypeBounds(lo: Type, hi: Type) extends Type - object TypeBounds extends TypeBoundsExtractor - implicit val TypeBoundsTag = ClassTag[TypeBounds](classOf[TypeBounds]) - - val WildcardType = new Type - - case class BoundedWildcardType(bounds: TypeBounds) extends Type - object BoundedWildcardType extends BoundedWildcardTypeExtractor - implicit val BoundedWildcardTypeTag = ClassTag[BoundedWildcardType](classOf[BoundedWildcardType]) - - class Scope(elems: Iterable[Symbol]) extends ScopeBase with MemberScopeBase { - def iterator = elems.iterator - def sorted = elems.toList - } - type MemberScope = Scope - implicit val ScopeTag = ClassTag[Scope](classOf[Scope]) - implicit val MemberScopeTag = ClassTag[MemberScope](classOf[MemberScope]) - - def newScope: Scope = newScopeWith() - def newNestedScope(outer: Scope): Scope = newScope - def newScopeWith(elems: Symbol*): Scope = new Scope(elems) - - abstract class Name(str: String) extends NameBase { - override def toString = str - } - implicit val NameTag = ClassTag[Name](classOf[Name]) - - class TermName(str: String) extends Name(str) { - def isTermName = true - def isTypeName = false - def toTermName = this - def toTypeName = new TypeName(str) - } - implicit val TermNameTag = ClassTag[TermName](classOf[TermName]) - - class TypeName(str: String) extends Name(str) { - def isTermName = false - def isTypeName = true - def toTermName = new TermName(str) - def toTypeName = this - } - implicit val TypeNameTag = ClassTag[TypeName](classOf[TypeName]) - - def newTermName(str: String) = new TermName(str) - def newTypeName(str: String) = new TypeName(str) - - object nme extends TermNamesBase { - val WILDCARD = newTermName("_") - val CONSTRUCTOR = newTermName("<init>") - val ROOTPKG = newTermName("_root_") - val EMPTY = newTermName("") - val EMPTY_PACKAGE_NAME = newTermName("<empty>") - val ROOT = newTermName("<root>") - val NO_NAME = newTermName("<none>") - } - - object tpnme extends TypeNamesBase { - val WILDCARD = nme.WILDCARD.toTypeName - val EMPTY = nme.EMPTY.toTypeName - val WILDCARD_STAR = newTypeName("_*") - val EMPTY_PACKAGE_NAME = nme.EMPTY_PACKAGE_NAME.toTypeName - val ROOT = nme.ROOT.toTypeName - } - - type FlagSet = Long - val NoFlags = 0L - implicit val FlagSetTag = ClassTag[FlagSet](classOf[FlagSet]) - - class Modifiers(override val flags: FlagSet, - override val privateWithin: Name, - override val annotations: List[Tree]) extends ModifiersBase { - def hasFlag(flags: FlagSet) = (this.flags & flags) != 0 - } - - implicit val ModifiersTag = ClassTag[Modifiers](classOf[Modifiers]) - - object Modifiers extends ModifiersCreator { - def apply(flags: Long, - privateWithin: Name, - annotations: List[Tree]) = new Modifiers(flags, privateWithin, annotations) - } - - case class Constant(value: Any) - object Constant extends ConstantExtractor - implicit val ConstantTag = ClassTag[Constant](classOf[Constant]) - - case class Annotation(tpe: Type, scalaArgs: List[Tree], javaArgs: ListMap[Name, JavaArgument]) - object Annotation extends AnnotationExtractor - implicit val AnnotationTag = ClassTag[Annotation](classOf[Annotation]) - - abstract class JavaArgument - implicit val JavaArgumentTag = ClassTag[JavaArgument](classOf[JavaArgument]) - - case class LiteralArgument(value: Constant) extends JavaArgument - object LiteralArgument extends LiteralArgumentExtractor - implicit val LiteralArgumentTag = ClassTag[LiteralArgument](classOf[LiteralArgument]) - - case class ArrayArgument(args: Array[JavaArgument]) extends JavaArgument - object ArrayArgument extends ArrayArgumentExtractor - implicit val ArrayArgumentTag = ClassTag[ArrayArgument](classOf[ArrayArgument]) - - case class NestedArgument(annotation: Annotation) extends JavaArgument - object NestedArgument extends NestedArgumentExtractor - implicit val NestedArgumentTag = ClassTag[NestedArgument](classOf[NestedArgument]) - - class Position extends Attachments { - override type Pos = Position - def pos = this - def withPos(newPos: Position) = newPos - def isRange = false - def focus = this - } - implicit val PositionTag = ClassTag[Position](classOf[Position]) - - val NoPosition = new Position - - private val generated = new mutable.HashMap[String, WeakReference[Symbol]] - - private def cached(name: String)(symExpr: => Symbol): Symbol = - generated get name match { - case Some(WeakReference(sym)) => - sym - case _ => - val sym = symExpr - generated(name) = WeakReference(sym) - sym - } - - object build extends BuildBase { - def selectType(owner: Symbol, name: String): TypeSymbol = { - val clazz = new ClassSymbol(owner, newTypeName(name), NoFlags) - cached(clazz.fullName)(clazz).asType - } - - def selectTerm(owner: Symbol, name: String): TermSymbol = { - val valu = new MethodSymbol(owner, newTermName(name), NoFlags) - cached(valu.fullName)(valu).asTerm - } - - def selectOverloadedMethod(owner: Symbol, name: String, index: Int): MethodSymbol = - selectTerm(owner, name).asMethod - - def newNestedSymbol(owner: Symbol, name: Name, pos: Position, flags: Long, isClass: Boolean): Symbol = - if (name.isTypeName) - if (isClass) new ClassSymbol(owner, name.toTypeName, flags) - else new TypeSymbol(owner, name.toTypeName, flags) - else new TermSymbol(owner, name.toTermName, flags) - - def newFreeTerm(name: String, value: => Any, flags: Long = 0L, origin: String = null): FreeTermSymbol = - new FreeTermSymbol(rootMirror.RootClass, newTermName(name), flags) - - def newFreeType(name: String, flags: Long = 0L, origin: String = null): FreeTypeSymbol = - new FreeTypeSymbol(rootMirror.RootClass, newTypeName(name), flags) - - def setTypeSignature[S <: Symbol](sym: S, tpe: Type): S = sym - - def setAnnotations[S <: Symbol](sym: S, annots: List[Annotation]): S = sym - - def flagsFromBits(bits: Long): FlagSet = bits - - object emptyValDef extends ValDef(NoMods, nme.WILDCARD, TypeTree(NoType), EmptyTree) { - override def isEmpty = true - } - - def This(sym: Symbol): Tree = self.This(sym.name.toTypeName) - - def Select(qualifier: Tree, sym: Symbol): Select = self.Select(qualifier, sym.name) - - def Ident(sym: Symbol): Ident = self.Ident(sym.name) - - def TypeTree(tp: Type): TypeTree = self.TypeTree() - - def thisPrefix(sym: Symbol): Type = SingleType(NoPrefix, sym) - - def setType[T <: Tree](tree: T, tpe: Type): T = tree - - def setSymbol[T <: Tree](tree: T, sym: Symbol): T = tree - } - - import build._ - - class Mirror extends MirrorOf[self.type] { - val universe: self.type = self - - lazy val RootClass = new ClassSymbol(NoSymbol, tpnme.ROOT, NoFlags) { override def isModuleClass = true } - lazy val RootPackage = new ModuleSymbol(NoSymbol, nme.ROOT, NoFlags, RootClass) - lazy val EmptyPackageClass = new ClassSymbol(RootClass, tpnme.EMPTY_PACKAGE_NAME, NoFlags) { override def isModuleClass = true } - lazy val EmptyPackage = new ModuleSymbol(RootClass, nme.EMPTY_PACKAGE_NAME, NoFlags, EmptyPackageClass) - - def staticClass(fullName: String): ClassSymbol = - mkStatic[ClassSymbol](fullName) - - def staticModule(fullName: String): ModuleSymbol = - mkStatic[ModuleSymbol](fullName) - - def staticPackage(fullName: String): ModuleSymbol = - staticModule(fullName) // this toy universe doesn't care about the distinction between packages and modules - - private def mkStatic[S <: Symbol : ClassTag](fullName: String): S = - cached(fullName) { - val point = fullName lastIndexOf '.' - val owner = - if (point > 0) staticModule(fullName take point).moduleClass - else rootMirror.RootClass - val name = fullName drop point + 1 - val symtag = implicitly[ClassTag[S]] - if (symtag == ClassSymbolTag) new ClassSymbol(owner, newTypeName(name), NoFlags) - else owner.newModuleAndClassSymbol(newTermName(name))._1 - }.asInstanceOf[S] - } - - lazy val rootMirror = new Mirror - - import rootMirror._ - - object definitions extends DefinitionsBase { - lazy val ScalaPackage = staticModule("scala") - lazy val ScalaPackageClass = ScalaPackage.moduleClass.asClass - - lazy val AnyClass = staticClass("scala.Any") - lazy val AnyValClass = staticClass("scala.Any") - lazy val ObjectClass = staticClass("java.lang.Object") - lazy val AnyRefClass = ObjectClass - - lazy val NullClass = staticClass("scala.Null") - lazy val NothingClass = staticClass("scala.Nothing") - - lazy val UnitClass = staticClass("scala.Unit") - lazy val ByteClass = staticClass("scala.Byte") - lazy val ShortClass = staticClass("scala.Short") - lazy val CharClass = staticClass("scala.Char") - lazy val IntClass = staticClass("scala.Int") - lazy val LongClass = staticClass("scala.Long") - lazy val FloatClass = staticClass("scala.Float") - lazy val DoubleClass = staticClass("scala.Double") - lazy val BooleanClass = staticClass("scala.Boolean") - - lazy val StringClass = staticClass("java.lang.String") - lazy val ClassClass = staticClass("java.lang.Class") - lazy val ArrayClass = staticClass("scala.Array") - lazy val ListClass = staticClass("scala.List") - - lazy val PredefModule = staticModule("scala.Predef") - - lazy val ByteTpe = TypeRef(ScalaPrefix, ByteClass, Nil) - lazy val ShortTpe = TypeRef(ScalaPrefix, ShortClass, Nil) - lazy val CharTpe = TypeRef(ScalaPrefix, CharClass, Nil) - lazy val IntTpe = TypeRef(ScalaPrefix, IntClass, Nil) - lazy val LongTpe = TypeRef(ScalaPrefix, LongClass, Nil) - lazy val FloatTpe = TypeRef(ScalaPrefix, FloatClass, Nil) - lazy val DoubleTpe = TypeRef(ScalaPrefix, DoubleClass, Nil) - lazy val BooleanTpe = TypeRef(ScalaPrefix, BooleanClass, Nil) - lazy val UnitTpe = TypeRef(ScalaPrefix, UnitClass, Nil) - lazy val AnyTpe = TypeRef(ScalaPrefix, AnyClass, Nil) - lazy val AnyValTpe = TypeRef(ScalaPrefix, AnyValClass, Nil) - lazy val NothingTpe = TypeRef(ScalaPrefix, NothingClass, Nil) - lazy val NullTpe = TypeRef(ScalaPrefix, NullClass, Nil) - lazy val ObjectTpe = TypeRef(JavaLangPrefix, ObjectClass, Nil) - lazy val AnyRefTpe = ObjectTpe - } - - import definitions._ - - private def thisModuleType(fullName: String): Type = ThisType(staticModule(fullName).moduleClass) - private lazy val ScalaPrefix = thisModuleType("scala") - private lazy val JavaLangPrefix = thisModuleType("java.lang") - - private var nodeCount = 0 // not synchronized - - abstract class Tree extends TreeBase with Product { - def isDef: Boolean = false - def isEmpty: Boolean = false - - /** The canonical way to test if a Tree represents a term. - */ - def isTerm: Boolean = this match { - case _: TermTree => true - case Bind(name, _) => name.isTermName - case Select(_, name) => name.isTermName - case Ident(name) => name.isTermName - case Annotated(_, arg) => arg.isTerm - case _ => false - } - - /** The canonical way to test if a Tree represents a type. - */ - def isType: Boolean = this match { - case _: TypTree => true - case Bind(name, _) => name.isTypeName - case Select(_, name) => name.isTypeName - case Ident(name) => name.isTypeName - case Annotated(_, arg) => arg.isType - case _ => false - } - } - - def treeToString(tree: Tree) = s"<tree ${tree.getClass}>" - - def treeType(tree: Tree) = NoType - - trait TermTree extends Tree - - trait TypTree extends Tree - - trait SymTree extends Tree - - trait NameTree extends Tree { - def name: Name - } - - trait RefTree extends SymTree with NameTree { - def qualifier: Tree // empty for Idents - def name: Name - } - - abstract class DefTree extends SymTree with NameTree { - def name: Name - override def isDef = true - } - - case object EmptyTree extends TermTree { - val asList = List(this) - override def isEmpty = true - } - - abstract class MemberDef extends DefTree { - def mods: Modifiers - } - - case class PackageDef(pid: RefTree, stats: List[Tree]) - extends MemberDef { - def name = pid.name - def mods = NoMods - } - object PackageDef extends PackageDefExtractor - - abstract class ImplDef extends MemberDef { - def impl: Template - } - - case class ClassDef(mods: Modifiers, name: TypeName, tparams: List[TypeDef], impl: Template) - extends ImplDef - object ClassDef extends ClassDefExtractor - - case class ModuleDef(mods: Modifiers, name: TermName, impl: Template) - extends ImplDef - object ModuleDef extends ModuleDefExtractor - - abstract class ValOrDefDef extends MemberDef { - val name: Name - val tpt: Tree - val rhs: Tree - } - - case class ValDef(mods: Modifiers, name: TermName, tpt: Tree, rhs: Tree) extends ValOrDefDef - object ValDef extends ValDefExtractor - - case class DefDef(mods: Modifiers, name: Name, tparams: List[TypeDef], - vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree) extends ValOrDefDef - object DefDef extends DefDefExtractor - - case class TypeDef(mods: Modifiers, name: TypeName, tparams: List[TypeDef], rhs: Tree) - extends MemberDef - object TypeDef extends TypeDefExtractor - - case class LabelDef(name: TermName, params: List[Ident], rhs: Tree) - extends DefTree with TermTree - object LabelDef extends LabelDefExtractor - - case class ImportSelector(name: Name, namePos: Int, rename: Name, renamePos: Int) - object ImportSelector extends ImportSelectorExtractor - - case class Import(expr: Tree, selectors: List[ImportSelector]) - extends SymTree - object Import extends ImportExtractor - - case class Template(parents: List[Tree], self: ValDef, body: List[Tree]) - extends SymTree - object Template extends TemplateExtractor - - case class Block(stats: List[Tree], expr: Tree) - extends TermTree - object Block extends BlockExtractor - - case class CaseDef(pat: Tree, guard: Tree, body: Tree) - extends Tree - object CaseDef extends CaseDefExtractor - - case class Alternative(trees: List[Tree]) - extends TermTree - object Alternative extends AlternativeExtractor - - case class Star(elem: Tree) - extends TermTree - object Star extends StarExtractor - - case class Bind(name: Name, body: Tree) - extends DefTree - object Bind extends BindExtractor - - case class UnApply(fun: Tree, args: List[Tree]) - extends TermTree - object UnApply extends UnApplyExtractor - - case class Function(vparams: List[ValDef], body: Tree) - extends TermTree with SymTree - object Function extends FunctionExtractor - - case class Assign(lhs: Tree, rhs: Tree) - extends TermTree - object Assign extends AssignExtractor - - case class AssignOrNamedArg(lhs: Tree, rhs: Tree) - extends TermTree - object AssignOrNamedArg extends AssignOrNamedArgExtractor - - case class If(cond: Tree, thenp: Tree, elsep: Tree) - extends TermTree - object If extends IfExtractor - - case class Match(selector: Tree, cases: List[CaseDef]) - extends TermTree - object Match extends MatchExtractor - - case class Return(expr: Tree) - extends TermTree with SymTree - object Return extends ReturnExtractor - - case class Try(block: Tree, catches: List[CaseDef], finalizer: Tree) - extends TermTree - object Try extends TryExtractor - - case class Throw(expr: Tree) - extends TermTree - object Throw extends ThrowExtractor - - case class New(tpt: Tree) extends TermTree - object New extends NewExtractor - - case class Typed(expr: Tree, tpt: Tree) - extends TermTree - object Typed extends TypedExtractor - - abstract class GenericApply extends TermTree { - val fun: Tree - val args: List[Tree] - } - - case class TypeApply(fun: Tree, args: List[Tree]) - extends GenericApply - object TypeApply extends TypeApplyExtractor - - case class Apply(fun: Tree, args: List[Tree]) - extends GenericApply - object Apply extends ApplyExtractor - - case class Super(qual: Tree, mix: TypeName) extends TermTree - object Super extends SuperExtractor - - case class This(qual: TypeName) - extends TermTree with SymTree - object This extends ThisExtractor - - case class Select(qualifier: Tree, name: Name) - extends RefTree - object Select extends SelectExtractor - - case class Ident(name: Name) extends RefTree { - def qualifier: Tree = EmptyTree - } - object Ident extends IdentExtractor - - case class ReferenceToBoxed(ident: Ident) extends TermTree - object ReferenceToBoxed extends ReferenceToBoxedExtractor - - case class Literal(value: Constant) - extends TermTree { - assert(value ne null) - } - object Literal extends LiteralExtractor - - case class Annotated(annot: Tree, arg: Tree) extends Tree - object Annotated extends AnnotatedExtractor - - case class SingletonTypeTree(ref: Tree) - extends TypTree - object SingletonTypeTree extends SingletonTypeTreeExtractor - - case class SelectFromTypeTree(qualifier: Tree, name: TypeName) - extends TypTree with RefTree - object SelectFromTypeTree extends SelectFromTypeTreeExtractor - - case class CompoundTypeTree(templ: Template) - extends TypTree - object CompoundTypeTree extends CompoundTypeTreeExtractor - - case class AppliedTypeTree(tpt: Tree, args: List[Tree]) - extends TypTree - object AppliedTypeTree extends AppliedTypeTreeExtractor - - case class TypeBoundsTree(lo: Tree, hi: Tree) - extends TypTree - object TypeBoundsTree extends TypeBoundsTreeExtractor - - case class ExistentialTypeTree(tpt: Tree, whereClauses: List[Tree]) - extends TypTree - object ExistentialTypeTree extends ExistentialTypeTreeExtractor - - case class TypeTree() extends TypTree { - val original: Tree = null - override def isEmpty = true - } - object TypeTree extends TypeTreeExtractor - - implicit val TreeTag = ClassTag[Tree](classOf[Tree]) - implicit val TermTreeTag = ClassTag[TermTree](classOf[TermTree]) - implicit val TypTreeTag = ClassTag[TypTree](classOf[TypTree]) - implicit val SymTreeTag = ClassTag[SymTree](classOf[SymTree]) - implicit val NameTreeTag = ClassTag[NameTree](classOf[NameTree]) - implicit val RefTreeTag = ClassTag[RefTree](classOf[RefTree]) - implicit val DefTreeTag = ClassTag[DefTree](classOf[DefTree]) - implicit val MemberDefTag = ClassTag[MemberDef](classOf[MemberDef]) - implicit val PackageDefTag = ClassTag[PackageDef](classOf[PackageDef]) - implicit val ImplDefTag = ClassTag[ImplDef](classOf[ImplDef]) - implicit val ClassDefTag = ClassTag[ClassDef](classOf[ClassDef]) - implicit val ModuleDefTag = ClassTag[ModuleDef](classOf[ModuleDef]) - implicit val ValOrDefDefTag = ClassTag[ValOrDefDef](classOf[ValOrDefDef]) - implicit val ValDefTag = ClassTag[ValDef](classOf[ValDef]) - implicit val DefDefTag = ClassTag[DefDef](classOf[DefDef]) - implicit val TypeDefTag = ClassTag[TypeDef](classOf[TypeDef]) - implicit val LabelDefTag = ClassTag[LabelDef](classOf[LabelDef]) - implicit val ImportSelectorTag = ClassTag[ImportSelector](classOf[ImportSelector]) - implicit val ImportTag = ClassTag[Import](classOf[Import]) - implicit val TemplateTag = ClassTag[Template](classOf[Template]) - implicit val BlockTag = ClassTag[Block](classOf[Block]) - implicit val CaseDefTag = ClassTag[CaseDef](classOf[CaseDef]) - implicit val AlternativeTag = ClassTag[Alternative](classOf[Alternative]) - implicit val StarTag = ClassTag[Star](classOf[Star]) - implicit val BindTag = ClassTag[Bind](classOf[Bind]) - implicit val UnApplyTag = ClassTag[UnApply](classOf[UnApply]) - implicit val FunctionTag = ClassTag[Function](classOf[Function]) - implicit val AssignTag = ClassTag[Assign](classOf[Assign]) - implicit val AssignOrNamedArgTag = ClassTag[AssignOrNamedArg](classOf[AssignOrNamedArg]) - implicit val IfTag = ClassTag[If](classOf[If]) - implicit val MatchTag = ClassTag[Match](classOf[Match]) - implicit val ReturnTag = ClassTag[Return](classOf[Return]) - implicit val TryTag = ClassTag[Try](classOf[Try]) - implicit val ThrowTag = ClassTag[Throw](classOf[Throw]) - implicit val NewTag = ClassTag[New](classOf[New]) - implicit val TypedTag = ClassTag[Typed](classOf[Typed]) - implicit val GenericApplyTag = ClassTag[GenericApply](classOf[GenericApply]) - implicit val TypeApplyTag = ClassTag[TypeApply](classOf[TypeApply]) - implicit val ApplyTag = ClassTag[Apply](classOf[Apply]) - implicit val SuperTag = ClassTag[Super](classOf[Super]) - implicit val ThisTag = ClassTag[This](classOf[This]) - implicit val SelectTag = ClassTag[Select](classOf[Select]) - implicit val IdentTag = ClassTag[Ident](classOf[Ident]) - implicit val ReferenceToBoxedTag = ClassTag[ReferenceToBoxed](classOf[ReferenceToBoxed]) - implicit val LiteralTag = ClassTag[Literal](classOf[Literal]) - implicit val AnnotatedTag = ClassTag[Annotated](classOf[Annotated]) - implicit val SingletonTypeTreeTag = ClassTag[SingletonTypeTree](classOf[SingletonTypeTree]) - implicit val SelectFromTypeTreeTag = ClassTag[SelectFromTypeTree](classOf[SelectFromTypeTree]) - implicit val CompoundTypeTreeTag = ClassTag[CompoundTypeTree](classOf[CompoundTypeTree]) - implicit val AppliedTypeTreeTag = ClassTag[AppliedTypeTree](classOf[AppliedTypeTree]) - implicit val TypeBoundsTreeTag = ClassTag[TypeBoundsTree](classOf[TypeBoundsTree]) - implicit val ExistentialTypeTreeTag = ClassTag[ExistentialTypeTree](classOf[ExistentialTypeTree]) - implicit val TypeTreeTag = ClassTag[TypeTree](classOf[TypeTree]) - - def ClassDef(sym: Symbol, impl: Template): ClassDef = ??? - def ModuleDef(sym: Symbol, impl: Template): ModuleDef = ??? - def ValDef(sym: Symbol, rhs: Tree): ValDef = ??? - def ValDef(sym: Symbol): ValDef = ??? - def DefDef(sym: Symbol, mods: Modifiers, vparamss: List[List[ValDef]], rhs: Tree): DefDef = ??? - def DefDef(sym: Symbol, vparamss: List[List[ValDef]], rhs: Tree): DefDef = ??? - def DefDef(sym: Symbol, mods: Modifiers, rhs: Tree): DefDef = ??? - def DefDef(sym: Symbol, rhs: Tree): DefDef = ??? - def DefDef(sym: Symbol, rhs: List[List[Symbol]] => Tree): DefDef = ??? - def TypeDef(sym: Symbol, rhs: Tree): TypeDef = ??? - def TypeDef(sym: Symbol): TypeDef = ??? - def LabelDef(sym: Symbol, params: List[Symbol], rhs: Tree): LabelDef = ??? - def CaseDef(pat: Tree, body: Tree): CaseDef = ??? - def Bind(sym: Symbol, body: Tree): Bind = ??? - def Try(body: Tree, cases: (Tree, Tree)*): Try = ??? - def Throw(tpe: Type, args: Tree*): Throw = ??? - def Apply(sym: Symbol, args: Tree*): Tree = ??? - def New(tpt: Tree, argss: List[List[Tree]]): Tree = ??? - def New(tpe: Type, args: Tree*): Tree = ??? - def New(sym: Symbol, args: Tree*): Tree = ??? - def ApplyConstructor(tpt: Tree, args: List[Tree]): Tree = ??? - def Super(sym: Symbol, mix: TypeName): Tree = ??? - def This(sym: Symbol): Tree = ??? - def Select(qualifier: Tree, name: String): Select = ??? - def Select(qualifier: Tree, sym: Symbol): Select = ??? - def Ident(name: String): Ident = ??? - def Ident(sym: Symbol): Ident = ??? - def Block(stats: Tree*): Block = ??? - def TypeTree(tp: Type): TypeTree = ??? -} diff --git a/src/library/scala/reflect/base/BuildUtils.scala b/src/library/scala/reflect/base/BuildUtils.scala deleted file mode 100644 index 5982329aef..0000000000 --- a/src/library/scala/reflect/base/BuildUtils.scala +++ /dev/null @@ -1,75 +0,0 @@ -package scala.reflect -package base - -/** - * This is an internal implementation class. - */ -trait BuildUtils { self: Universe => - - val build: BuildBase - - // this API abstracts away the functionality necessary for reification - // it's too gimmicky and unstructured to be exposed directly in the universe - // but we need it in a publicly available place for reification to work - - abstract class BuildBase { - /** Selects type symbol with given simple name `name` from the defined members of `owner`. - */ - def selectType(owner: Symbol, name: String): TypeSymbol - - /** Selects term symbol with given name and type from the defined members of prefix type - */ - def selectTerm(owner: Symbol, name: String): TermSymbol - - /** Selects overloaded method symbol with given name and index - */ - def selectOverloadedMethod(owner: Symbol, name: String, index: Int): MethodSymbol - - /** A fresh symbol with given name `name`, position `pos` and flags `flags` that has - * the current symbol as its owner. - */ - def newNestedSymbol(owner: Symbol, name: Name, pos: Position, flags: FlagSet, isClass: Boolean): Symbol - - /** Create a fresh free term symbol. - * @param name the name of the free variable - * @param value the value of the free variable at runtime - * @param flags (optional) flags of the free variable - * @param origin debug information that tells where this symbol comes from - */ - def newFreeTerm(name: String, value: => Any, flags: FlagSet = NoFlags, origin: String = null): FreeTermSymbol - - /** Create a fresh free type symbol. - * @param name the name of the free variable - * @param flags (optional) flags of the free variable - * @param origin debug information that tells where this symbol comes from - */ - def newFreeType(name: String, flags: FlagSet = NoFlags, origin: String = null): FreeTypeSymbol - - /** Set symbol's type signature to given type. - * @return the symbol itself - */ - def setTypeSignature[S <: Symbol](sym: S, tpe: Type): S - - /** Set symbol's annotations to given annotations `annots`. - */ - def setAnnotations[S <: Symbol](sym: S, annots: List[Annotation]): S - - def flagsFromBits(bits: Long): FlagSet - - def emptyValDef: ValDef - - def This(sym: Symbol): Tree - - def Select(qualifier: Tree, sym: Symbol): Select - - def Ident(sym: Symbol): Ident - - def TypeTree(tp: Type): TypeTree - - def thisPrefix(sym: Symbol): Type - - def setType[T <: Tree](tree: T, tpe: Type): T - - def setSymbol[T <: Tree](tree: T, sym: Symbol): T - } -} diff --git a/src/library/scala/reflect/base/Constants.scala b/src/library/scala/reflect/base/Constants.scala deleted file mode 100644 index 240434362d..0000000000 --- a/src/library/scala/reflect/base/Constants.scala +++ /dev/null @@ -1,36 +0,0 @@ -/* NSC -- new Scala compiler - * Copyright 2005-2012 LAMP/EPFL - * @author Martin Odersky - */ - -package scala.reflect -package base - -/** - * Defines the type hierachy for compile-time constants. - * - * @see [[scala.reflect]] for a description on how the class hierarchy is encoded here. - */ -trait Constants { - self: Universe => - - /** The type of compile-time constants. - */ - type Constant >: Null <: AnyRef - - /** A tag that preserves the identity of the `Constant` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val ConstantTag: ClassTag[Constant] - - /** The constructor/deconstructor for `Constant` instances. */ - val Constant: ConstantExtractor - - /** An extractor class to create and pattern match with syntax `Constant(value)` - * where `value` is the Scala value of the constant. - */ - abstract class ConstantExtractor { - def apply(value: Any): Constant - def unapply(arg: Constant): Option[Any] - } -} diff --git a/src/library/scala/reflect/base/Exprs.scala b/src/library/scala/reflect/base/Exprs.scala deleted file mode 100644 index bd15c65711..0000000000 --- a/src/library/scala/reflect/base/Exprs.scala +++ /dev/null @@ -1,137 +0,0 @@ -/* NSC -- new Scala compiler - * Copyright 2005-2012 LAMP/EPFL - * @author Martin Odersky - */ - -package scala.reflect -package base - -trait Exprs { self: Universe => - - /** Expr wraps an expression tree and tags it with its type. */ - trait Expr[+T] extends Equals with Serializable { - val mirror: Mirror - /** - * Migrates the expression into another mirror, jumping into a different universe if necessary. - * - * This means that all symbolic references to classes/objects/packages in the expression - * will be re-resolved within the new mirror (typically using that mirror's classloader). - */ - def in[U <: Universe with Singleton](otherMirror: MirrorOf[U]): U # Expr[T] - - /** - * The Scala syntax tree representing the wrapped expression. - */ - def tree: Tree - - /** - * Representation of the type of the wrapped expression tree as found via type tags. - */ - def staticType: Type - /** - * Representation of the type of the wrapped expression tree as found in the tree. - */ - def actualType: Type - - /** - * A dummy method to mark expression splicing in reification. - * - * It should only be used within a `reify` call, which eliminates the `splice` call and embeds - * the wrapped tree into the reified surrounding expression. - * If used alone `splice` throws an exception when called at runtime. - * - * If you want to use an Expr in reification of some Scala code, you need to splice it in. - * For an expr of type `Expr[T]`, where `T` has a method `foo`, the following code - * {{{ - * reify{ expr.splice.foo } - * }}} - * uses splice to turn an expr of type Expr[T] into a value of type T in the context of `reify`. - * - * It is equivalent to - * {{{ - * Select( expr.tree, newTermName("foo") ) - * }}} - * - * The following example code however does not compile - * {{{ - * reify{ expr.foo } - * }}} - * because expr of type Expr[T] itself does not have a method foo. - */ - def splice: T - /** - * A dummy value to denote cross-stage path-dependent type dependencies. - * - * For example for the following macro definition: - * {{{ - * class X { type T } - * object Macros { def foo(x: X): x.T = macro Impls.foo_impl } - * }}} - * - * The corresponding macro implementation should have the following signature (note how the return type denotes path-dependency on x): - * {{{ - * object Impls { def foo_impl(c: Context)(x: c.Expr[X]): c.Expr[x.value.T] = ... } - * }}} - */ - val value: T - - /** case class accessories */ - override def canEqual(x: Any) = x.isInstanceOf[Expr[_]] - override def equals(x: Any) = x.isInstanceOf[Expr[_]] && this.mirror == x.asInstanceOf[Expr[_]].mirror && this.tree == x.asInstanceOf[Expr[_]].tree - override def hashCode = mirror.hashCode * 31 + tree.hashCode - override def toString = "Expr["+staticType+"]("+tree+")" - } - - /** - * Constructor/Extractor for Expr. - * - * Can be useful, when having a tree and wanting to splice it in reify call, - * in which case the tree first needs to be wrapped in an expr. - */ - object Expr { - def apply[T: WeakTypeTag](mirror: MirrorOf[self.type], treec: TreeCreator): Expr[T] = new ExprImpl[T](mirror.asInstanceOf[Mirror], treec) - def unapply[T](expr: Expr[T]): Option[Tree] = Some(expr.tree) - } - - private class ExprImpl[+T: WeakTypeTag](val mirror: Mirror, val treec: TreeCreator) extends Expr[T] { - def in[U <: Universe with Singleton](otherMirror: MirrorOf[U]): U # Expr[T] = { - val otherMirror1 = otherMirror.asInstanceOf[MirrorOf[otherMirror.universe.type]] - val tag1 = (implicitly[WeakTypeTag[T]] in otherMirror).asInstanceOf[otherMirror.universe.WeakTypeTag[T]] - otherMirror.universe.Expr[T](otherMirror1, treec)(tag1) - } - - lazy val tree: Tree = treec(mirror) - lazy val staticType: Type = implicitly[WeakTypeTag[T]].tpe - def actualType: Type = treeType(tree) - - def splice: T = throw new UnsupportedOperationException(""" - |the function you're calling has not been spliced by the compiler. - |this means there is a cross-stage evaluation involved, and it needs to be invoked explicitly. - |if you're sure this is not an oversight, add scala-compiler.jar to the classpath, - |import `scala.tools.reflect.Eval` and call `<your expr>.eval` instead.""".trim.stripMargin) - lazy val value: T = throw new UnsupportedOperationException(""" - |the value you're calling is only meant to be used in cross-stage path-dependent types. - |if you want to splice the underlying expression, use `<your expr>.splice`. - |if you want to get a value of the underlying expression, add scala-compiler.jar to the classpath, - |import `scala.tools.reflect.Eval` and call `<your expr>.eval` instead.""".trim.stripMargin) - - private def writeReplace(): AnyRef = new SerializedExpr(treec, implicitly[WeakTypeTag[T]].in(scala.reflect.basis.rootMirror)) - } -} - -private[scala] class SerializedExpr(var treec: TreeCreator, var tag: scala.reflect.basis.WeakTypeTag[_]) extends Serializable { - private def writeObject(out: java.io.ObjectOutputStream): Unit = { - out.writeObject(treec) - out.writeObject(tag) - } - - private def readObject(in: java.io.ObjectInputStream): Unit = { - treec = in.readObject().asInstanceOf[TreeCreator] - tag = in.readObject().asInstanceOf[scala.reflect.basis.WeakTypeTag[_]] - } - - private def readResolve(): AnyRef = { - import scala.reflect.basis._ - Expr(rootMirror, treec)(tag) - } -}
\ No newline at end of file diff --git a/src/library/scala/reflect/base/FlagSets.scala b/src/library/scala/reflect/base/FlagSets.scala deleted file mode 100644 index 0ce7613eb3..0000000000 --- a/src/library/scala/reflect/base/FlagSets.scala +++ /dev/null @@ -1,16 +0,0 @@ -package scala.reflect -package base - -trait FlagSets { self: Universe => - - /** An abstract type representing sets of flags (like private, final, etc.) that apply to definition trees and symbols */ - type FlagSet - - /** A tag that preserves the identity of the `FlagSet` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val FlagSetTag: ClassTag[FlagSet] - - /** The empty set of flags */ - val NoFlags: FlagSet -} diff --git a/src/library/scala/reflect/base/MirrorOf.scala b/src/library/scala/reflect/base/MirrorOf.scala deleted file mode 100644 index 4e54a2fae7..0000000000 --- a/src/library/scala/reflect/base/MirrorOf.scala +++ /dev/null @@ -1,107 +0,0 @@ -package scala.reflect -package base - -/** - * The base interface for all mirrors. - * - * @tparam U the type of the universe this mirror belongs to. - * - * This is defined outside the reflection universe cake pattern implementation - * so that it can be referenced from outside. For example TypeCreator and TreeCreator - * reference MirrorOf and also need to be defined outside the cake as they are - * used by type tags, which can be migrated between different universes and consequently - * cannot be bound to a fixed one. - * - * @see [[Mirrors]] - */ -abstract class MirrorOf[U <: base.Universe with Singleton] { - /** The universe this mirror belongs to. */ - val universe: U - - /** The class symbol of the `_root_` package */ - def RootClass: U#ClassSymbol - - /** The module symbol of the `_root_` package */ - def RootPackage: U#ModuleSymbol - - /** The module class symbol of the default (unnamed) package */ - def EmptyPackageClass: U#ClassSymbol - - /** The module symbol of the default (unnamed) package */ - def EmptyPackage: U#ModuleSymbol - - /** The symbol corresponding to the globally accessible class with the - * given fully qualified name `fullName`. - * - * If the name points to a type alias, it's recursively dealiased and its target is returned. - * If you need a symbol that corresponds to the type alias itself, load it directly from the package class: - * - * scala> cm.staticClass("scala.List") - * res0: reflect.runtime.universe.ClassSymbol = class List - * - * scala> res0.fullName - * res1: String = scala.collection.immutable.List - * - * scala> cm.staticPackage("scala") - * res2: reflect.runtime.universe.ModuleSymbol = package scala - * - * scala> res2.moduleClass.typeSignature member newTypeName("List") - * res3: reflect.runtime.universe.Symbol = type List - * - * scala> res3.fullName - * res4: String = scala.List - * - * To be consistent with Scala name resolution rules, in case of ambiguity between - * a package and an object, the object is never been considered. - * - * For example for the following code: - * - * package foo { - * class B - * } - * - * object foo { - * class A - * class B - * } - * - * staticClass("foo.B") will resolve to the symbol corresponding to the class B declared in the package foo, and - * staticClass("foo.A") will throw a MissingRequirementException (which is exactly what scalac would do if this - * fully qualified class name is written inside any package in a Scala program). - * - * In the example above, to load a symbol that corresponds to the class B declared in the object foo, - * use staticModule("foo") to load the module symbol and then navigate typeSignature.members of its moduleClass. - */ - def staticClass(fullName: String): U#ClassSymbol - - /** The symbol corresponding to the globally accessible object with the - * given fully qualified name `fullName`. - * - * To be consistent with Scala name resolution rules, in case of ambiguity between - * a package and an object, the object is never been considered. - * - * For example for the following code: - * - * package foo { - * object B - * } - * - * object foo { - * object A - * object B - * } - * - * staticModule("foo.B") will resolve to the symbol corresponding to the object B declared in the package foo, and - * staticModule("foo.A") will throw a MissingRequirementException (which is exactly what scalac would do if this - * fully qualified class name is written inside any package in a Scala program). - * - * In the example above, to load a symbol that corresponds to the object B declared in the object foo, - * use staticModule("foo") to load the module symbol and then navigate typeSignature.members of its moduleClass. - */ - def staticModule(fullName: String): U#ModuleSymbol - - /** The symbol corresponding to a package with the - * given fully qualified name `fullName`. - */ - def staticPackage(fullName: String): U#ModuleSymbol -} diff --git a/src/library/scala/reflect/base/Mirrors.scala b/src/library/scala/reflect/base/Mirrors.scala deleted file mode 100644 index e38a3d1cdd..0000000000 --- a/src/library/scala/reflect/base/Mirrors.scala +++ /dev/null @@ -1,22 +0,0 @@ -package scala.reflect -package base - -/** - * Defines a type hierarchy for mirrors. - * - * Every universe has one or more mirrors. A mirror defines a hierarchy of symbols starting with the root package `_root_` - * and provides methods to locate and define classes and singleton objects in that hierarchy. - * - * On the JVM, there is a one to one correspondance between class loaders and mirrors. - */ -trait Mirrors { - self: Universe => - - /** The base type of all mirrors of this universe */ - type Mirror >: Null <: MirrorOf[self.type] - - /** The root mirror of this universe. This mirror contains standard Scala classes and types such as `Any`, `AnyRef`, `AnyVal`, - * `Nothing`, `Null`, and all classes loaded from scala-library, which are shared across all mirrors within the enclosing universe. - */ - val rootMirror: Mirror -} diff --git a/src/library/scala/reflect/base/Names.scala b/src/library/scala/reflect/base/Names.scala deleted file mode 100644 index b02038a920..0000000000 --- a/src/library/scala/reflect/base/Names.scala +++ /dev/null @@ -1,68 +0,0 @@ -package scala.reflect -package base - -import scala.language.implicitConversions - -/** A trait that manages names. - * - * @see TermName - * @see TypeName - */ -trait Names { - // Intentionally no implicit from String => Name. - implicit def stringToTermName(s: String): TermName = newTermName(s) - implicit def stringToTypeName(s: String): TypeName = newTypeName(s) - - /** - * The abstract type of names - * - * A Name wraps a string as the name for either a type ([[TypeName]]) of a term ([[TermName]]). - * Two names are equal, if the wrapped string are equal and they are either both `TypeName` or both `TermName`. - * The same string can co-exist as a `TypeName` and a `TermName`, but they would not be equal. - * Names are interned. That is, for two names `name11 and `name2`, - * `name1 == name2` implies `name1 eq name2`. - * - * One of the reasons for the existence of names rather than plain strings is being more explicit about what is a name and if it represents a type or a term. - */ - type Name >: Null <: NameBase - implicit val NameTag: ClassTag[Name] - - /** The abstract type of names representing terms */ - type TypeName >: Null <: Name - implicit val TypeNameTag: ClassTag[TypeName] - - /** The abstract type of names representing types */ - type TermName >: Null <: Name - implicit val TermNameTag: ClassTag[TermName] - - /** The base API that all names support */ - abstract class NameBase { - /** Checks wether the name is a a term name */ - def isTermName: Boolean - - /** Checks wether the name is a a type name */ - def isTypeName: Boolean - - /** Returns a term name that wraps the same string as `this` */ - def toTermName: TermName - - /** Returns a type name that wraps the same string as `this` */ - def toTypeName: TypeName - } - - /** Create a new term name. - */ - def newTermName(s: String): TermName - - /** Creates a new type name. - */ - def newTypeName(s: String): TypeName - - /** Wraps the empty string. Can be used as the null object for term name. - */ - def EmptyTermName: TermName = newTermName("") - - /** Wraps the empty string. Can be used as the null object for term name. - */ - def EmptyTypeName: TypeName = EmptyTermName.toTypeName -} diff --git a/src/library/scala/reflect/base/Positions.scala b/src/library/scala/reflect/base/Positions.scala deleted file mode 100644 index 70412a2f4b..0000000000 --- a/src/library/scala/reflect/base/Positions.scala +++ /dev/null @@ -1,22 +0,0 @@ -package scala.reflect -package base - -/** - * Defines the type hierachy for positions. - * - * @see [[scala.reflect]] for a description on how the class hierarchy is encoded here. - */ -trait Positions { - self: Universe => - - /** The base type for all positions of tree nodes in source files. */ - type Position >: Null <: Attachments { type Pos = Position } - - /** A tag that preserves the identity of the `Position` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val PositionTag: ClassTag[Position] - - /** A special "missing" position. */ - val NoPosition: Position -} diff --git a/src/library/scala/reflect/base/Scopes.scala b/src/library/scala/reflect/base/Scopes.scala deleted file mode 100644 index a8c498b814..0000000000 --- a/src/library/scala/reflect/base/Scopes.scala +++ /dev/null @@ -1,50 +0,0 @@ -package scala.reflect -package base - -/** - * Defines the type hierachy for scopes. - * - * @see [[scala.reflect]] for a description on how the class hierarchy is encoded here. - */ -trait Scopes { self: Universe => - - /** The base type of all scopes. A scope object generally maps names to symbols available in the current lexical scope. - * Scopes can be nested. This base type, however, only exposes a minimal interface, representing a scope as an iterable of symbols. - */ - type Scope >: Null <: ScopeBase - - /** The base API that all scopes support */ - trait ScopeBase extends Iterable[Symbol] - - /** A tag that preserves the identity of the `Scope` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val ScopeTag: ClassTag[Scope] - - /** The base type of member scopes, as in class definitions, for example. */ - type MemberScope >: Null <: Scope with MemberScopeBase - - /** The base API that all member scopes support */ - trait MemberScopeBase extends ScopeBase { - /** Sorts the symbols included in this scope so that: - * 1) Symbols appear in the linearization order of their owners. - * 2) Symbols with the same owner appear in reverse order of their declarations. - * 3) Synthetic members (e.g. getters/setters for vals/vars) might appear in arbitrary order. - */ - def sorted: List[Symbol] - } - - /** A tag that preserves the identity of the `MemberScope` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val MemberScopeTag: ClassTag[MemberScope] - - /** Create a new scope. */ - def newScope: Scope - - /** Create a new scope nested in another one with which it shares its elements. */ - def newNestedScope(outer: Scope): Scope - - /** Create a new scope with the given initial elements. */ - def newScopeWith(elems: Symbol*): Scope -}
\ No newline at end of file diff --git a/src/library/scala/reflect/base/StandardDefinitions.scala b/src/library/scala/reflect/base/StandardDefinitions.scala deleted file mode 100644 index 4df8501b3d..0000000000 --- a/src/library/scala/reflect/base/StandardDefinitions.scala +++ /dev/null @@ -1,110 +0,0 @@ -/* NSC -- new Scala compiler - * Copyright 2005-2012 LAMP/EPFL - * @author Martin Odersky - */ - -package scala.reflect -package base - -/** - * Defines standard symbols and types. - */ -trait StandardDefinitions { - self: Universe => - - /** A value containing all standard defnitions. */ - val definitions: DefinitionsBase - - /** Defines standard symbols (and types via its base class). */ - trait DefinitionsBase extends StandardTypes { - /** The class symbol of package `scala`. */ - def ScalaPackageClass: ClassSymbol - - /** The module class symbol of package `scala`. */ - def ScalaPackage: ModuleSymbol - - // top types - def AnyClass : ClassSymbol - def AnyValClass: ClassSymbol - def ObjectClass: ClassSymbol - def AnyRefClass: TypeSymbol - - // bottom types - def NullClass : ClassSymbol - def NothingClass: ClassSymbol - - // the scala value classes - def UnitClass : ClassSymbol - def ByteClass : ClassSymbol - def ShortClass : ClassSymbol - def CharClass : ClassSymbol - def IntClass : ClassSymbol - def LongClass : ClassSymbol - def FloatClass : ClassSymbol - def DoubleClass : ClassSymbol - def BooleanClass: ClassSymbol - - /** The class symbol of class `String`. */ - def StringClass : ClassSymbol - - /** The class symbol of class `Class`. */ - def ClassClass : ClassSymbol - - /** The class symbol of class `Array`. */ - def ArrayClass : ClassSymbol - - /** The class symbol of class `List`. */ - def ListClass : ClassSymbol - - /** The module symbol of `scala.Predef`. */ - def PredefModule: ModuleSymbol - } - - /** Defines standard types. */ - trait StandardTypes { - /** The `Type` of type `Unit`. */ - val UnitTpe: Type - - /** The `Type` of primitive type `Byte`. */ - val ByteTpe: Type - - /** The `Type` of primitive type `Short`. */ - val ShortTpe: Type - - /** The `Type` of primitive type `Char`. */ - val CharTpe: Type - - /** The `Type` of primitive type `Int`. */ - val IntTpe: Type - - /** The `Type` of primitive type `Long`. */ - val LongTpe: Type - - /** The `Type` of primitive type `Float`. */ - val FloatTpe: Type - - /** The `Type` of primitive type `Double`. */ - val DoubleTpe: Type - - /** The `Type` of primitive type `Boolean`. */ - val BooleanTpe: Type - - /** The `Type` of type `Any`. */ - val AnyTpe: Type - - /** The `Type` of type `AnyVal`. */ - val AnyValTpe: Type - - /** The `Type` of type `AnyRef`. */ - val AnyRefTpe: Type - - /** The `Type` of type `Object`. */ - val ObjectTpe: Type - - /** The `Type` of type `Nothing`. */ - val NothingTpe: Type - - /** The `Type` of type `Null`. */ - val NullTpe: Type - } -} diff --git a/src/library/scala/reflect/base/StandardNames.scala b/src/library/scala/reflect/base/StandardNames.scala deleted file mode 100644 index fc1d247512..0000000000 --- a/src/library/scala/reflect/base/StandardNames.scala +++ /dev/null @@ -1,40 +0,0 @@ -/* NSC -- new Scala compiler -* Copyright 2005-2012 LAMP/EPFL -* @author Martin Odersky -*/ - -package scala.reflect -package base - -// Q: I have a pretty name. Where do I put it - into base.StandardNames or into api.StandardNames? -// A: Is it necessary to construct trees (like EMPTY or WILDCARD_STAR)? If yes, then it goes to base.StandardNames. -// Is it necessary to perform reflection (like ERROR or LOCAL_SUFFIX_STRING)? If yes, then it goes to api.StandardNames. -// Otherwise it goes nowhere - reflection API should stay minimalistic. - -// TODO: document better -/** - * Names necessary to create Scala trees. - */ -trait StandardNames { - self: Universe => - - val nme: TermNamesBase - val tpnme: TypeNamesBase - - trait NamesBase { - type NameType >: Null <: Name - val WILDCARD: NameType - } - - trait TermNamesBase extends NamesBase { - type NameType = TermName - val CONSTRUCTOR: NameType - val ROOTPKG: NameType - } - - trait TypeNamesBase extends NamesBase { - type NameType = TypeName - val EMPTY: NameType - val WILDCARD_STAR: NameType - } -} diff --git a/src/library/scala/reflect/base/Symbols.scala b/src/library/scala/reflect/base/Symbols.scala deleted file mode 100644 index 4a1eef014c..0000000000 --- a/src/library/scala/reflect/base/Symbols.scala +++ /dev/null @@ -1,294 +0,0 @@ -package scala.reflect -package base - -/** - * Defines the type hierachy for symbols - * - * @see [[scala.reflect]] for a description on how the class hierarchy is encoded here. - */ -trait Symbols { self: Universe => - - /** The type of symbols representing declarations */ - type Symbol >: Null <: SymbolBase - - /** A tag that preserves the identity of the `Symbol` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val SymbolTag: ClassTag[Symbol] - - /** The type of type symbols representing type, class, and trait declarations, - * as well as type parameters - */ - type TypeSymbol >: Null <: Symbol with TypeSymbolBase - - /** A tag that preserves the identity of the `TypeSymbol` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val TypeSymbolTag: ClassTag[TypeSymbol] - - /** The type of term symbols representing val, var, def, and object declarations as - * well as packages and value parameters. - */ - type TermSymbol >: Null <: Symbol with TermSymbolBase - - /** A tag that preserves the identity of the `TermSymbol` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val TermSymbolTag: ClassTag[TermSymbol] - - /** The type of method symbols representing def declarations */ - type MethodSymbol >: Null <: TermSymbol with MethodSymbolBase - - /** A tag that preserves the identity of the `MethodSymbol` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val MethodSymbolTag: ClassTag[MethodSymbol] - - /** The type of module symbols representing object declarations */ - type ModuleSymbol >: Null <: TermSymbol with ModuleSymbolBase - - /** A tag that preserves the identity of the `ModuleSymbol` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val ModuleSymbolTag: ClassTag[ModuleSymbol] - - /** The type of class symbols representing class and trait definitions */ - type ClassSymbol >: Null <: TypeSymbol with ClassSymbolBase - - /** A tag that preserves the identity of the `ClassSymbol` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val ClassSymbolTag: ClassTag[ClassSymbol] - - /** The type of free terms introduced by reification */ - type FreeTermSymbol >: Null <: TermSymbol with FreeTermSymbolBase - - /** A tag that preserves the identity of the `FreeTermSymbol` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val FreeTermSymbolTag: ClassTag[FreeTermSymbol] - - /** The type of free types introduced by reification */ - type FreeTypeSymbol >: Null <: TypeSymbol with FreeTypeSymbolBase - - /** A tag that preserves the identity of the `FreeTypeSymbol` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val FreeTypeSymbolTag: ClassTag[FreeTypeSymbol] - - /** A special "missing" symbol */ - val NoSymbol: Symbol - - /** The base API that all symbols support */ - trait SymbolBase { this: Symbol => - - /** The owner of this symbol. This is the symbol - * that directly contains the current symbol's definition. - * The `NoSymbol` symbol does not have an owner, and calling this method - * on one causes an internal error. - * The owner of the Scala root class [[scala.reflect.base.MirrorOf.RootClass]] - * and the Scala root object [[scala.reflect.base.MirrorOf.RootPackage]] is `NoSymbol`. - * Every other symbol has a chain of owners that ends in - * [[scala.reflect.base.MirrorOf.RootClass]]. - */ - def owner: Symbol - - /** The type of the symbol name. - * Can be either `TermName` or `TypeName` depending on whether this is a `TermSymbol` or a `TypeSymbol`. - * - * Type name namespaces do not intersect with term name namespaces. - * This fact is reflected in different types for names of `TermSymbol` and `TypeSymbol`. - */ - type NameType >: Null <: Name - - /** The name of the symbol as a member of the `Name` type. - */ - def name: Name - - /** The encoded full path name of this symbol, where outer names and inner names - * are separated by periods. - */ - def fullName: String - - /** Does this symbol represent the definition of a type? - * Note that every symbol is either a term or a type. - * So for every symbol `sym` (except for `NoSymbol`), - * either `sym.isTerm` is true or `sym.isType` is true. - */ - def isType: Boolean = false - - /** This symbol cast to a TypeSymbol. - * @throws ScalaReflectionException if `isType` is false. - */ - def asType: TypeSymbol = throw new ScalaReflectionException(s"$this is not a type") - - /** Does this symbol represent the definition of a term? - * Note that every symbol is either a term or a type. - * So for every symbol `sym` (except for `NoSymbol`), - * either `sym.isTerm` is true or `sym.isTerm` is true. - */ - def isTerm: Boolean = false - - /** This symbol cast to a TermSymbol. - * @throws ScalaReflectionException if `isTerm` is false. - */ - def asTerm: TermSymbol = throw new ScalaReflectionException(s"$this is not a term") - - /** Does this symbol represent the definition of a method? - * If yes, `isTerm` is also guaranteed to be true. - */ - def isMethod: Boolean = false - - /** This symbol cast to a MethodSymbol. - * @throws ScalaReflectionException if `isMethod` is false. - */ - def asMethod: MethodSymbol = { - def overloadedMsg = - "encapsulates multiple overloaded alternatives and cannot be treated as a method. "+ - "Consider invoking `<offending symbol>.asTerm.alternatives` and manually picking the required method" - def vanillaMsg = "is not a method" - val msg = if (isOverloadedMethod) overloadedMsg else vanillaMsg - throw new ScalaReflectionException(s"$this $msg") - } - - /** Used to provide a better error message for `asMethod` */ - protected def isOverloadedMethod = false - - /** Does this symbol represent the definition of a module (i.e. it - * results from an object definition?). - * If yes, `isTerm` is also guaranteed to be true. - */ - def isModule: Boolean = false - - /** This symbol cast to a ModuleSymbol defined by an object definition. - * @throws ScalaReflectionException if `isModule` is false. - */ - def asModule: ModuleSymbol = throw new ScalaReflectionException(s"$this is not a module") - - /** Does this symbol represent the definition of a class or trait? - * If yes, `isType` is also guaranteed to be true. - */ - def isClass: Boolean = false - - /** Does this symbol represent the definition of a class implicitly associated - * with an object definition (module class in scala compiler parlance). - * If yes, `isType` is also guaranteed to be true. - */ - def isModuleClass: Boolean = false - - /** This symbol cast to a ClassSymbol representing a class or trait. - * @throws ScalaReflectionException if `isClass` is false. - */ - def asClass: ClassSymbol = throw new ScalaReflectionException(s"$this is not a class") - - /** Does this symbol represent a free term captured by reification? - * If yes, `isTerm` is also guaranteed to be true. - */ - def isFreeTerm: Boolean = false - - /** This symbol cast to a free term symbol. - * @throws ScalaReflectionException if `isFreeTerm` is false. - */ - def asFreeTerm: FreeTermSymbol = throw new ScalaReflectionException(s"$this is not a free term") - - /** Does this symbol represent a free type captured by reification? - * If yes, `isType` is also guaranteed to be true. - */ - def isFreeType: Boolean = false - - /** This symbol cast to a free type symbol. - * @throws ScalaReflectionException if `isFreeType` is false. - */ - def asFreeType: FreeTypeSymbol = throw new ScalaReflectionException(s"$this is not a free type") - - def newTermSymbol(name: TermName, pos: Position = NoPosition, flags: FlagSet = NoFlags): TermSymbol - def newModuleAndClassSymbol(name: Name, pos: Position = NoPosition, flags: FlagSet = NoFlags): (ModuleSymbol, ClassSymbol) - def newMethodSymbol(name: TermName, pos: Position = NoPosition, flags: FlagSet = NoFlags): MethodSymbol - def newTypeSymbol(name: TypeName, pos: Position = NoPosition, flags: FlagSet = NoFlags): TypeSymbol - def newClassSymbol(name: TypeName, pos: Position = NoPosition, flags: FlagSet = NoFlags): ClassSymbol - } - - /** The base API that all type symbols support */ - trait TypeSymbolBase extends SymbolBase { this: TypeSymbol => - /** Type symbols have their names of type `TypeName`. - */ - final type NameType = TypeName - - /** The type constructor corresponding to this type symbol. - * This is different from `toType` in that type parameters - * are part of results of `toType`, but not of `toTypeConstructor`. - * - * Example: Given a class declaration `class C[T] { ... } `, that generates a symbol - * `C`. Then `C.toType` is the type `C[T]`, but `C.toTypeConstructor` is `C`. - */ - def toTypeConstructor: Type - - /** A type reference that refers to this type symbol seen - * as a member of given type `site`. - */ - def toTypeIn(site: Type): Type - - /** A type reference that refers to this type symbol - * Note if symbol is a member of a class, one almost always is interested - * in `asTypeIn` with a site type instead. - * - * Example: Given a class declaration `class C[T] { ... } `, that generates a symbol - * `C`. Then `C.toType` is the type `C[T]`. - * - * By contrast, `C.typeSignature` would be a type signature of form - * `PolyType(ClassInfoType(...))` that describes type parameters, value - * parameters, parent types, and members of `C`. - */ - def toType: Type - - final override def isType = true - final override def asType = this - } - - /** The base API that all term symbols support */ - trait TermSymbolBase extends SymbolBase { this: TermSymbol => - /** Term symbols have their names of type `TermName`. - */ - final type NameType = TermName - - final override def isTerm = true - final override def asTerm = this - } - - /** The base API that all method symbols support */ - trait MethodSymbolBase extends TermSymbolBase { this: MethodSymbol => - final override def isMethod = true - final override def asMethod = this - } - - /** The base API that all module symbols support */ - trait ModuleSymbolBase extends TermSymbolBase { this: ModuleSymbol => - /** The class implicitly associated with the object definition. - * One can go back from a module class to the associated module symbol - * by inspecting its `selfType.termSymbol`. - */ - def moduleClass: Symbol // needed for tree traversals - // when this becomes `moduleClass: ClassSymbol`, it will be the happiest day in my life - - final override def isModule = true - final override def asModule = this - } - - /** The base API that all class symbols support */ - trait ClassSymbolBase extends TypeSymbolBase { this: ClassSymbol => - final override def isClass = true - final override def asClass = this - } - - /** The base API that all free type symbols support */ - trait FreeTypeSymbolBase extends TypeSymbolBase { this: FreeTypeSymbol => - final override def isFreeType = true - final override def asFreeType = this - } - - /** The base API that all free term symbols support */ - trait FreeTermSymbolBase extends TermSymbolBase { this: FreeTermSymbol => - final override def isFreeTerm = true - final override def asFreeTerm = this - } -} diff --git a/src/library/scala/reflect/base/TagInterop.scala b/src/library/scala/reflect/base/TagInterop.scala deleted file mode 100644 index e989631abf..0000000000 --- a/src/library/scala/reflect/base/TagInterop.scala +++ /dev/null @@ -1,29 +0,0 @@ -package scala.reflect -package base - -import scala.runtime.ScalaRunTime._ - -trait TagInterop { self: Universe => - // TODO `mirror` parameters are now of type `Any`, because I can't make these path-dependent types work - // if you're brave enough, replace `Any` with `Mirror`, recompile and run interop_typetags_are_manifests.scala - - /** - * Convert a typetag to a pre `Scala-2.10` manifest. - * For example - * {{{ - * typeTagToManifest( scala.reflect.runtime.currentMirror, implicitly[TypeTag[String]] ) - * }}} - */ - def typeTagToManifest[T: ClassTag](mirror: Any, tag: base.Universe # TypeTag[T]): Manifest[T] = - throw new UnsupportedOperationException("This universe does not support tag -> manifest conversions. Use scala.reflect.runtime.universe from scala-reflect.jar.") - - /** - * Convert a pre `Scala-2.10` manifest to a typetag. - * For example - * {{{ - * manifestToTypeTag( scala.reflect.runtime.currentMirror, implicitly[Manifest[String]] ) - * }}} - */ - def manifestToTypeTag[T](mirror: Any, manifest: Manifest[T]): base.Universe # TypeTag[T] = - throw new UnsupportedOperationException("This universe does not support manifest -> tag conversions. Use scala.reflect.runtime.universe from scala-reflect.jar.") -} diff --git a/src/library/scala/reflect/base/TreeCreator.scala b/src/library/scala/reflect/base/TreeCreator.scala deleted file mode 100644 index 5de0094f1f..0000000000 --- a/src/library/scala/reflect/base/TreeCreator.scala +++ /dev/null @@ -1,26 +0,0 @@ -package scala.reflect -package base - -/** A mirror-aware factory for trees. - * - * In the reflection API, artifacts are specific to universes and - * symbolic references used in artifacts (e.g. `scala.Int`) are resolved by mirrors. - * - * Therefore to build a tree one needs to know a universe that the tree is going to be bound to - * and a mirror that is going to resolve symbolic references (e.g. to determine that `scala.Int` - * points to a core class `Int` from scala-library.jar). - * - * `TreeCreator` implements this notion by providing a standalone tree factory. - * - * This is immediately useful for reification. When the compiler reifies an expression, - * the end result needs to make sense in any mirror. That's because the compiler knows - * the universe it's reifying an expression into (specified by the target of the `reify` call), - * but it cannot know in advance the mirror to instantiate the result in (e.g. on JVM - * it doesn't know what classloader use to resolve symbolic names in the reifee). - * - * Due to a typechecker restriction (no eta-expansion for dependent method types), - * `TreeCreator` can't have a functional type, so it's implemented as class with an apply method. - */ -abstract class TreeCreator { - def apply[U <: Universe with Singleton](m: MirrorOf[U]): U # Tree -} diff --git a/src/library/scala/reflect/base/Trees.scala b/src/library/scala/reflect/base/Trees.scala deleted file mode 100644 index 6931d23173..0000000000 --- a/src/library/scala/reflect/base/Trees.scala +++ /dev/null @@ -1,1427 +0,0 @@ -/* NSC -- new Scala compiler - * Copyright 2005-2012 LAMP/EPFL - * @author Martin Odersky - */ -package scala.reflect -package base - -trait Trees { self: Universe => - - /** The base API that all trees support */ - abstract class TreeBase extends Product { this: Tree => - // TODO - /** ... */ - def isDef: Boolean - - // TODO - /** ... */ - def isEmpty: Boolean - - /** The canonical way to test if a Tree represents a term. - */ - def isTerm: Boolean - - /** The canonical way to test if a Tree represents a type. - */ - def isType: Boolean - - /** Obtains string representation of a tree */ - override def toString: String = treeToString(this) - } - - /** Obtains string representation of a tree */ - protected def treeToString(tree: Tree): String - - /** Obtains the type of the tree (we intentionally don't expose `tree.tpe` in base) */ - protected def treeType(tree: Tree): Type - - /** Tree is the basis for scala's abstract syntax. The nodes are - * implemented as case classes, and the parameters which initialize - * a given tree are immutable: however Trees have several mutable - * fields which are manipulated in the course of typechecking, - * including pos, symbol, and tpe. - * - * Newly instantiated trees have tpe set to null (though it - * may be set immediately thereafter depending on how it is - * constructed.) When a tree is passed to the typer, typically via - * `typer.typed(tree)`, under normal circumstances the tpe must be - * null or the typer will ignore it. Furthermore, the typer is not - * required to return the same tree it was passed. - * - * Trees can be easily traversed with e.g. foreach on the root node; - * for a more nuanced traversal, subclass Traverser. Transformations - * can be considerably trickier: see the numerous subclasses of - * Transformer found around the compiler. - * - * Copying Trees should be done with care depending on whether - * it needs be done lazily or strictly (see LazyTreeCopier and - * StrictTreeCopier) and on whether the contents of the mutable - * fields should be copied. The tree copiers will copy the mutable - * attributes to the new tree; calling Tree#duplicate will copy - * symbol and tpe, but all the positions will be focused. - * - * Trees can be coarsely divided into four mutually exclusive categories: - * - * - TermTrees, representing terms - * - TypTrees, representing types. Note that is `TypTree`, not `TypeTree`. - * - SymTrees, which may represent types or terms. - * - Other Trees, which have none of those as parents. - * - * SymTrees include important nodes Ident and Select, which are - * used as both terms and types; they are distinguishable based on - * whether the Name is a TermName or TypeName. The correct way - * to test any Tree for a type or a term are the `isTerm`/`isType` - * methods on Tree. - * - * "Others" are mostly syntactic or short-lived constructs. Examples - * include CaseDef, which wraps individual match cases: they are - * neither terms nor types, nor do they carry a symbol. Another - * example is Parens, which is eliminated during parsing. - */ - type Tree >: Null <: TreeBase - - /** A tag that preserves the identity of the `Tree` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val TreeTag: ClassTag[Tree] - - /** The empty tree */ - val EmptyTree: Tree - - /** A tree for a term. Not all trees representing terms are TermTrees; use isTerm - * to reliably identify terms. - */ - type TermTree >: Null <: AnyRef with Tree - - /** A tag that preserves the identity of the `TermTree` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val TermTreeTag: ClassTag[TermTree] - - /** A tree for a type. Not all trees representing types are TypTrees; use isType - * to reliably identify types. - */ - type TypTree >: Null <: AnyRef with Tree - - /** A tag that preserves the identity of the `TypTree` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val TypTreeTag: ClassTag[TypTree] - - /** A tree with a mutable symbol field, initialized to NoSymbol. - */ - type SymTree >: Null <: AnyRef with Tree - - /** A tag that preserves the identity of the `SymTree` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val SymTreeTag: ClassTag[SymTree] - - /** A tree with a name - effectively, a DefTree or RefTree. - */ - type NameTree >: Null <: AnyRef with Tree - - /** A tag that preserves the identity of the `NameTree` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val NameTreeTag: ClassTag[NameTree] - - /** A tree which references a symbol-carrying entity. - * References one, as opposed to defining one; definitions - * are in DefTrees. - */ - type RefTree >: Null <: SymTree with NameTree - - /** A tag that preserves the identity of the `RefTree` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val RefTreeTag: ClassTag[RefTree] - - /** A tree which defines a symbol-carrying entity. - */ - type DefTree >: Null <: SymTree with NameTree - - /** A tag that preserves the identity of the `DefTree` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val DefTreeTag: ClassTag[DefTree] - - /** Common base class for all member definitions: types, classes, - * objects, packages, vals and vars, defs. - */ - type MemberDef >: Null <: DefTree - - /** A tag that preserves the identity of the `MemberDef` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val MemberDefTag: ClassTag[MemberDef] - - /** A packaging, such as `package pid { stats }` - */ - type PackageDef >: Null <: MemberDef - - /** A tag that preserves the identity of the `PackageDef` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val PackageDefTag: ClassTag[PackageDef] - - /** The constructor/deconstructor for `PackageDef` instances. */ - val PackageDef: PackageDefExtractor - - /** An extractor class to create and pattern match with syntax `PackageDef(pid, stats)`. - * This AST node corresponds to the following Scala code: - * - * `package` pid { stats } - */ - abstract class PackageDefExtractor { - def apply(pid: RefTree, stats: List[Tree]): PackageDef - def unapply(packageDef: PackageDef): Option[(RefTree, List[Tree])] - } - - /** A common base class for class and object definitions. - */ - type ImplDef >: Null <: MemberDef - - /** A tag that preserves the identity of the `ImplDef` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val ImplDefTag: ClassTag[ImplDef] - - /** A class definition. - */ - type ClassDef >: Null <: ImplDef - - /** A tag that preserves the identity of the `ClassDef` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val ClassDefTag: ClassTag[ClassDef] - - /** The constructor/deconstructor for `ClassDef` instances. */ - val ClassDef: ClassDefExtractor - - /** An extractor class to create and pattern match with syntax `ClassDef(mods, name, tparams, impl)`. - * This AST node corresponds to the following Scala code: - * - * mods `class` name [tparams] impl - * - * Where impl stands for: - * - * `extends` parents { defs } - */ - abstract class ClassDefExtractor { - def apply(mods: Modifiers, name: TypeName, tparams: List[TypeDef], impl: Template): ClassDef - def unapply(classDef: ClassDef): Option[(Modifiers, TypeName, List[TypeDef], Template)] - } - - /** An object definition, e.g. `object Foo`. Internally, objects are - * quite frequently called modules to reduce ambiguity. - * Eliminated by compiler phase refcheck. - */ - type ModuleDef >: Null <: ImplDef - - /** A tag that preserves the identity of the `ModuleDef` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val ModuleDefTag: ClassTag[ModuleDef] - - /** The constructor/deconstructor for `ModuleDef` instances. */ - val ModuleDef: ModuleDefExtractor - - /** An extractor class to create and pattern match with syntax `ModuleDef(mods, name, impl)`. - * This AST node corresponds to the following Scala code: - * - * mods `object` name impl - * - * Where impl stands for: - * - * `extends` parents { defs } - */ - abstract class ModuleDefExtractor { - def apply(mods: Modifiers, name: TermName, impl: Template): ModuleDef - def unapply(moduleDef: ModuleDef): Option[(Modifiers, TermName, Template)] - } - - /** A common base class for ValDefs and DefDefs. - */ - type ValOrDefDef >: Null <: MemberDef - - /** A tag that preserves the identity of the `ValOrDefDef` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val ValOrDefDefTag: ClassTag[ValOrDefDef] - - /** Broadly speaking, a value definition. All these are encoded as ValDefs: - * - * - immutable values, e.g. "val x" - * - mutable values, e.g. "var x" - the MUTABLE flag set in mods - * - lazy values, e.g. "lazy val x" - the LAZY flag set in mods - * - method parameters, see vparamss in [[scala.reflect.base.Trees#DefDef]] - the PARAM flag is set in mods - * - explicit self-types, e.g. class A { self: Bar => } - */ - type ValDef >: Null <: ValOrDefDef - - /** A tag that preserves the identity of the `ValDef` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val ValDefTag: ClassTag[ValDef] - - /** The constructor/deconstructor for `ValDef` instances. */ - val ValDef: ValDefExtractor - - /** An extractor class to create and pattern match with syntax `ValDef(mods, name, tpt, rhs)`. - * This AST node corresponds to any of the following Scala code: - * - * mods `val` name: tpt = rhs - * - * mods `var` name: tpt = rhs - * - * mods name: tpt = rhs // in signatures of function and method definitions - * - * self: Bar => // self-types - * - * If the type of a value is not specified explicitly (i.e. is meant to be inferred), - * this is expressed by having `tpt` set to `TypeTree()` (but not to an `EmptyTree`!). - */ - abstract class ValDefExtractor { - def apply(mods: Modifiers, name: TermName, tpt: Tree, rhs: Tree): ValDef - def unapply(valDef: ValDef): Option[(Modifiers, TermName, Tree, Tree)] - } - - /** A method or macro definition. - * @param name The name of the method or macro. Can be a type name in case this is a type macro - */ - type DefDef >: Null <: ValOrDefDef - - /** A tag that preserves the identity of the `DefDef` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val DefDefTag: ClassTag[DefDef] - - /** The constructor/deconstructor for `DefDef` instances. */ - val DefDef: DefDefExtractor - - /** An extractor class to create and pattern match with syntax `DefDef(mods, name, tparams, vparamss, tpt, rhs)`. - * This AST node corresponds to the following Scala code: - * - * mods `def` name[tparams](vparams_1)...(vparams_n): tpt = rhs - * - * If the return type is not specified explicitly (i.e. is meant to be inferred), - * this is expressed by having `tpt` set to `TypeTree()` (but not to an `EmptyTree`!). - */ - abstract class DefDefExtractor { - def apply(mods: Modifiers, name: Name, tparams: List[TypeDef], vparamss: List[List[ValDef]], tpt: Tree, rhs: Tree): DefDef - def unapply(defDef: DefDef): Option[(Modifiers, Name, List[TypeDef], List[List[ValDef]], Tree, Tree)] - } - - /** An abstract type, a type parameter, or a type alias. - * Eliminated by erasure. - */ - type TypeDef >: Null <: MemberDef - - /** A tag that preserves the identity of the `TypeDef` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val TypeDefTag: ClassTag[TypeDef] - - /** The constructor/deconstructor for `TypeDef` instances. */ - val TypeDef: TypeDefExtractor - - /** An extractor class to create and pattern match with syntax `TypeDef(mods, name, tparams, rhs)`. - * This AST node corresponds to the following Scala code: - * - * mods `type` name[tparams] = rhs - * - * mods `type` name[tparams] >: lo <: hi - * - * First usage illustrates `TypeDefs` representing type aliases and type parameters. - * Second usage illustrates `TypeDefs` representing abstract types, - * where lo and hi are both `TypeBoundsTrees` and `Modifier.deferred` is set in mods. - */ - abstract class TypeDefExtractor { - def apply(mods: Modifiers, name: TypeName, tparams: List[TypeDef], rhs: Tree): TypeDef - def unapply(typeDef: TypeDef): Option[(Modifiers, TypeName, List[TypeDef], Tree)] - } - - /** A labelled expression. Not expressible in language syntax, but - * generated by the compiler to simulate while/do-while loops, and - * also by the pattern matcher. - * - * The label acts much like a nested function, where `params` represents - * the incoming parameters. The symbol given to the LabelDef should have - * a MethodType, as if it were a nested function. - * - * Jumps are apply nodes attributed with a label's symbol. The - * arguments from the apply node will be passed to the label and - * assigned to the Idents. - * - * Forward jumps within a block are allowed. - */ - type LabelDef >: Null <: DefTree with TermTree - - /** A tag that preserves the identity of the `LabelDef` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val LabelDefTag: ClassTag[LabelDef] - - /** The constructor/deconstructor for `LabelDef` instances. */ - val LabelDef: LabelDefExtractor - - /** An extractor class to create and pattern match with syntax `LabelDef(name, params, rhs)`. - * - * This AST node does not have direct correspondence to Scala code. - * It is used for tailcalls and like. - * For example, while/do are desugared to label defs as follows: - * {{{ - * while (cond) body ==> LabelDef($L, List(), if (cond) { body; L$() } else ()) - * }}} - * {{{ - * do body while (cond) ==> LabelDef($L, List(), body; if (cond) L$() else ()) - * }}} - */ - abstract class LabelDefExtractor { - def apply(name: TermName, params: List[Ident], rhs: Tree): LabelDef - def unapply(labelDef: LabelDef): Option[(TermName, List[Ident], Tree)] - } - - /** Import selector - * - * Representation of an imported name its optional rename and their optional positions - * - * Eliminated by typecheck. - * - * @param name the imported name - * @param namePos its position or -1 if undefined - * @param rename the name the import is renamed to (== name if no renaming) - * @param renamePos the position of the rename or -1 if undefined - */ - type ImportSelector >: Null <: AnyRef - - /** A tag that preserves the identity of the `ImportSelector` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val ImportSelectorTag: ClassTag[ImportSelector] - - /** The constructor/deconstructor for `ImportSelector` instances. */ - val ImportSelector: ImportSelectorExtractor - - /** An extractor class to create and pattern match with syntax `ImportSelector(name:, namePos, rename, renamePos)`. - * This is not an AST node, it is used as a part of the `Import` node. - */ - abstract class ImportSelectorExtractor { - def apply(name: Name, namePos: Int, rename: Name, renamePos: Int): ImportSelector - def unapply(importSelector: ImportSelector): Option[(Name, Int, Name, Int)] - } - - /** Import clause - * - * @param expr - * @param selectors - */ - type Import >: Null <: SymTree - - /** A tag that preserves the identity of the `Import` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val ImportTag: ClassTag[Import] - - /** The constructor/deconstructor for `Import` instances. */ - val Import: ImportExtractor - - /** An extractor class to create and pattern match with syntax `Import(expr, selectors)`. - * This AST node corresponds to the following Scala code: - * - * import expr.{selectors} - * - * Selectors are a list of ImportSelectors, which conceptually are pairs of names (from, to). - * The last (and maybe only name) may be a nme.WILDCARD. For instance: - * - * import qual.{x, y => z, _} - * - * Would be represented as: - * - * Import(qual, List(("x", "x"), ("y", "z"), (WILDCARD, null))) - * - * The symbol of an `Import` is an import symbol @see Symbol.newImport. - * It's used primarily as a marker to check that the import has been typechecked. - */ - abstract class ImportExtractor { - def apply(expr: Tree, selectors: List[ImportSelector]): Import - def unapply(import_ : Import): Option[(Tree, List[ImportSelector])] - } - - /** Instantiation template of a class or trait - * - * @param parents - * @param body - */ - type Template >: Null <: SymTree - - /** A tag that preserves the identity of the `Template` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val TemplateTag: ClassTag[Template] - - /** The constructor/deconstructor for `Template` instances. */ - val Template: TemplateExtractor - - /** An extractor class to create and pattern match with syntax `Template(parents, self, body)`. - * This AST node corresponds to the following Scala code: - * - * `extends` parents { self => body } - * - * In case when the self-type annotation is missing, it is represented as - * an empty value definition with nme.WILDCARD as name and NoType as type. - * - * The symbol of a template is a local dummy. @see Symbol.newLocalDummy - * The owner of the local dummy is the enclosing trait or class. - * The local dummy is itself the owner of any local blocks. For example: - * - * class C { - * def foo { // owner is C - * def bar // owner is local dummy - * } - * } - */ - abstract class TemplateExtractor { - def apply(parents: List[Tree], self: ValDef, body: List[Tree]): Template - def unapply(template: Template): Option[(List[Tree], ValDef, List[Tree])] - } - - /** Block of expressions (semicolon separated expressions) */ - type Block >: Null <: TermTree - - /** A tag that preserves the identity of the `Block` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val BlockTag: ClassTag[Block] - - /** The constructor/deconstructor for `Block` instances. */ - val Block: BlockExtractor - - /** An extractor class to create and pattern match with syntax `Block(stats, expr)`. - * This AST node corresponds to the following Scala code: - * - * { stats; expr } - * - * If the block is empty, the `expr` is set to `Literal(Constant(()))`. - */ - abstract class BlockExtractor { - def apply(stats: List[Tree], expr: Tree): Block - def unapply(block: Block): Option[(List[Tree], Tree)] - } - - /** Case clause in a pattern match. - * (except for occurrences in switch statements). - * Eliminated by compiler phases patmat (in the new pattern matcher of 2.10) or explicitouter (in the old pre-2.10 pattern matcher) - */ - type CaseDef >: Null <: AnyRef with Tree - - /** A tag that preserves the identity of the `CaseDef` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val CaseDefTag: ClassTag[CaseDef] - - /** The constructor/deconstructor for `CaseDef` instances. */ - val CaseDef: CaseDefExtractor - - /** An extractor class to create and pattern match with syntax `CaseDef(pat, guard, body)`. - * This AST node corresponds to the following Scala code: - * - * `case` pat `if` guard => body - * - * If the guard is not present, the `guard` is set to `EmptyTree`. - * If the body is not specified, the `body` is set to `Literal(Constant())` - */ - abstract class CaseDefExtractor { - def apply(pat: Tree, guard: Tree, body: Tree): CaseDef - def unapply(caseDef: CaseDef): Option[(Tree, Tree, Tree)] - } - - /** Alternatives of patterns. - * - * Eliminated by compiler phases Eliminated by compiler phases patmat (in the new pattern matcher of 2.10) or explicitouter (in the old pre-2.10 pattern matcher), - * except for - * occurrences in encoded Switch stmt (i.e. remaining Match(CaseDef(...))) - */ - type Alternative >: Null <: TermTree - - /** A tag that preserves the identity of the `Alternative` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val AlternativeTag: ClassTag[Alternative] - - /** The constructor/deconstructor for `Alternative` instances. */ - val Alternative: AlternativeExtractor - - /** An extractor class to create and pattern match with syntax `Alternative(trees)`. - * This AST node corresponds to the following Scala code: - * - * pat1 | ... | patn - */ - abstract class AlternativeExtractor { - def apply(trees: List[Tree]): Alternative - def unapply(alternative: Alternative): Option[List[Tree]] - } - - /** Repetition of pattern. - * - * Eliminated by compiler phases patmat (in the new pattern matcher of 2.10) or explicitouter (in the old pre-2.10 pattern matcher). - */ - type Star >: Null <: TermTree - - /** A tag that preserves the identity of the `Star` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val StarTag: ClassTag[Star] - - /** The constructor/deconstructor for `Star` instances. */ - val Star: StarExtractor - - /** An extractor class to create and pattern match with syntax `Star(elem)`. - * This AST node corresponds to the following Scala code: - * - * pat* - */ - abstract class StarExtractor { - def apply(elem: Tree): Star - def unapply(star: Star): Option[Tree] - } - - /** Bind a variable to a rhs pattern. - * - * Eliminated by compiler phases patmat (in the new pattern matcher of 2.10) or explicitouter (in the old pre-2.10 pattern matcher). - * - * @param name - * @param body - */ - type Bind >: Null <: DefTree - - /** A tag that preserves the identity of the `Bind` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val BindTag: ClassTag[Bind] - - /** The constructor/deconstructor for `Bind` instances. */ - val Bind: BindExtractor - - /** An extractor class to create and pattern match with syntax `Bind(name, body)`. - * This AST node corresponds to the following Scala code: - * - * pat* - */ - abstract class BindExtractor { - def apply(name: Name, body: Tree): Bind - def unapply(bind: Bind): Option[(Name, Tree)] - } - - /** - * Used to represent `unapply` methods in pattern matching. - * - * For example: - * {{{ - * 2 match { case Foo(x) => x } - * }}} - * - * Is represented as: - * {{{ - * Match( - * Literal(Constant(2)), - * List( - * CaseDef( - * UnApply( - * // a dummy node that carries the type of unapplication to patmat - * // the <unapply-selector> here doesn't have an underlying symbol - * // it only has a type assigned, therefore after `resetAllAttrs` this tree is no longer typeable - * Apply(Select(Ident(Foo), newTermName("unapply")), List(Ident(newTermName("<unapply-selector>")))), - * // arguments of the unapply => nothing synthetic here - * List(Bind(newTermName("x"), Ident(nme.WILDCARD)))), - * EmptyTree, - * Ident(newTermName("x"))))) - * }}} - * - * Introduced by typer. Eliminated by compiler phases patmat (in the new pattern matcher of 2.10) or explicitouter (in the old pre-2.10 pattern matcher). - */ - type UnApply >: Null <: TermTree - - /** A tag that preserves the identity of the `UnApply` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val UnApplyTag: ClassTag[UnApply] - - /** The constructor/deconstructor for `UnApply` instances. */ - val UnApply: UnApplyExtractor - - /** An extractor class to create and pattern match with syntax `UnApply(fun, args)`. - * This AST node does not have direct correspondence to Scala code, - * and is introduced when typechecking pattern matches and `try` blocks. - */ - abstract class UnApplyExtractor { - def apply(fun: Tree, args: List[Tree]): UnApply - def unapply(unApply: UnApply): Option[(Tree, List[Tree])] - } - - /** Anonymous function, eliminated by compiler phase lambdalift */ - type Function >: Null <: TermTree with SymTree - - /** A tag that preserves the identity of the `Function` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val FunctionTag: ClassTag[Function] - - /** The constructor/deconstructor for `Function` instances. */ - val Function: FunctionExtractor - - /** An extractor class to create and pattern match with syntax `Function(vparams, body)`. - * This AST node corresponds to the following Scala code: - * - * vparams => body - * - * The symbol of a Function is a synthetic TermSymbol. - * It is the owner of the function's parameters. - */ - abstract class FunctionExtractor { - def apply(vparams: List[ValDef], body: Tree): Function - def unapply(function: Function): Option[(List[ValDef], Tree)] - } - - /** Assignment */ - type Assign >: Null <: TermTree - - /** A tag that preserves the identity of the `Assign` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val AssignTag: ClassTag[Assign] - - /** The constructor/deconstructor for `Assign` instances. */ - val Assign: AssignExtractor - - /** An extractor class to create and pattern match with syntax `Assign(lhs, rhs)`. - * This AST node corresponds to the following Scala code: - * - * lhs = rhs - */ - abstract class AssignExtractor { - def apply(lhs: Tree, rhs: Tree): Assign - def unapply(assign: Assign): Option[(Tree, Tree)] - } - - /** Either an assignment or a named argument. Only appears in argument lists, - * eliminated by compiler phase typecheck (doTypedApply), resurrected by reifier. - */ - type AssignOrNamedArg >: Null <: TermTree - - /** A tag that preserves the identity of the `AssignOrNamedArg` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val AssignOrNamedArgTag: ClassTag[AssignOrNamedArg] - - /** The constructor/deconstructor for `AssignOrNamedArg` instances. */ - val AssignOrNamedArg: AssignOrNamedArgExtractor - - /** An extractor class to create and pattern match with syntax `AssignOrNamedArg(lhs, rhs)`. - * This AST node corresponds to the following Scala code: - * - * {{{ - * m.f(lhs = rhs) - * }}} - * {{{ - * @annotation(lhs = rhs) - * }}} - * - */ - abstract class AssignOrNamedArgExtractor { - def apply(lhs: Tree, rhs: Tree): AssignOrNamedArg - def unapply(assignOrNamedArg: AssignOrNamedArg): Option[(Tree, Tree)] - } - - /** Conditional expression */ - type If >: Null <: TermTree - - /** A tag that preserves the identity of the `If` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val IfTag: ClassTag[If] - - /** The constructor/deconstructor for `If` instances. */ - val If: IfExtractor - - /** An extractor class to create and pattern match with syntax `If(cond, thenp, elsep)`. - * This AST node corresponds to the following Scala code: - * - * `if` (cond) thenp `else` elsep - * - * If the alternative is not present, the `elsep` is set to `Literal(Constant(()))`. - */ - abstract class IfExtractor { - def apply(cond: Tree, thenp: Tree, elsep: Tree): If - def unapply(if_ : If): Option[(Tree, Tree, Tree)] - } - - /** - Pattern matching expression (before compiler phase explicitouter before 2.10 / patmat from 2.10) - * - Switch statements (after compiler phase explicitouter before 2.10 / patmat from 2.10) - * - * After compiler phase explicitouter before 2.10 / patmat from 2.10, cases will satisfy the following constraints: - * - * - all guards are `EmptyTree`, - * - all patterns will be either `Literal(Constant(x:Int))` - * or `Alternative(lit|...|lit)` - * - except for an "otherwise" branch, which has pattern - * `Ident(nme.WILDCARD)` - */ - type Match >: Null <: TermTree - - /** A tag that preserves the identity of the `Match` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val MatchTag: ClassTag[Match] - - /** The constructor/deconstructor for `Match` instances. */ - val Match: MatchExtractor - - /** An extractor class to create and pattern match with syntax `Match(selector, cases)`. - * This AST node corresponds to the following Scala code: - * - * selector `match` { cases } - * - * `Match` is also used in pattern matching assignments like `val (foo, bar) = baz`. - */ - abstract class MatchExtractor { - def apply(selector: Tree, cases: List[CaseDef]): Match - def unapply(match_ : Match): Option[(Tree, List[CaseDef])] - } - - /** Return expression */ - type Return >: Null <: TermTree with SymTree - - /** A tag that preserves the identity of the `Return` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val ReturnTag: ClassTag[Return] - - /** The constructor/deconstructor for `Return` instances. */ - val Return: ReturnExtractor - - /** An extractor class to create and pattern match with syntax `Return(expr)`. - * This AST node corresponds to the following Scala code: - * - * `return` expr - * - * The symbol of a Return node is the enclosing method. - */ - abstract class ReturnExtractor { - def apply(expr: Tree): Return - def unapply(return_ : Return): Option[Tree] - } - - /** [Eugene++] comment me! */ - type Try >: Null <: TermTree - - /** A tag that preserves the identity of the `Try` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val TryTag: ClassTag[Try] - - /** The constructor/deconstructor for `Try` instances. */ - val Try: TryExtractor - - /** An extractor class to create and pattern match with syntax `Try(block, catches, finalizer)`. - * This AST node corresponds to the following Scala code: - * - * `try` block `catch` { catches } `finally` finalizer - * - * If the finalizer is not present, the `finalizer` is set to `EmptyTree`. - */ - abstract class TryExtractor { - def apply(block: Tree, catches: List[CaseDef], finalizer: Tree): Try - def unapply(try_ : Try): Option[(Tree, List[CaseDef], Tree)] - } - - /** Throw expression */ - type Throw >: Null <: TermTree - - /** A tag that preserves the identity of the `Throw` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val ThrowTag: ClassTag[Throw] - - /** The constructor/deconstructor for `Throw` instances. */ - val Throw: ThrowExtractor - - /** An extractor class to create and pattern match with syntax `Throw(expr)`. - * This AST node corresponds to the following Scala code: - * - * `throw` expr - */ - abstract class ThrowExtractor { - def apply(expr: Tree): Throw - def unapply(throw_ : Throw): Option[Tree] - } - - /** Object instantiation - */ - type New >: Null <: TermTree - - /** A tag that preserves the identity of the `New` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val NewTag: ClassTag[New] - - /** The constructor/deconstructor for `New` instances. - */ - val New: NewExtractor - - /** An extractor class to create and pattern match with syntax `New(tpt)`. - * This AST node corresponds to the following Scala code: - * - * `new` T - * - * This node always occurs in the following context: - * - * (`new` tpt).<init>[targs](args) - */ - abstract class NewExtractor { - /** A user level `new`. - * One should always use this factory method to build a user level `new`. - * - * @param tpt a class type - */ - def apply(tpt: Tree): New - def unapply(new_ : New): Option[Tree] - } - - /** Type annotation, eliminated by compiler phase cleanup */ - type Typed >: Null <: TermTree - - /** A tag that preserves the identity of the `Typed` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val TypedTag: ClassTag[Typed] - - /** The constructor/deconstructor for `Typed` instances. */ - val Typed: TypedExtractor - - /** An extractor class to create and pattern match with syntax `Typed(expr, tpt)`. - * This AST node corresponds to the following Scala code: - * - * expr: tpt - */ - abstract class TypedExtractor { - def apply(expr: Tree, tpt: Tree): Typed - def unapply(typed: Typed): Option[(Tree, Tree)] - } - - /** Common base class for Apply and TypeApply. - */ - type GenericApply >: Null <: TermTree - - /** A tag that preserves the identity of the `GenericApply` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val GenericApplyTag: ClassTag[GenericApply] - - /* @PP: All signs point toward it being a requirement that args.nonEmpty, - * but I can't find that explicitly stated anywhere. Unless your last name - * is odersky, you should probably treat it as true. - */ - /** Explicit type application. */ - type TypeApply >: Null <: GenericApply - - /** A tag that preserves the identity of the `TypeApply` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val TypeApplyTag: ClassTag[TypeApply] - - /** The constructor/deconstructor for `TypeApply` instances. */ - val TypeApply: TypeApplyExtractor - - /** An extractor class to create and pattern match with syntax `TypeApply(fun, args)`. - * This AST node corresponds to the following Scala code: - * - * fun[args] - */ - abstract class TypeApplyExtractor { - def apply(fun: Tree, args: List[Tree]): TypeApply - def unapply(typeApply: TypeApply): Option[(Tree, List[Tree])] - } - - /** Value application */ - type Apply >: Null <: GenericApply - - /** A tag that preserves the identity of the `Apply` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val ApplyTag: ClassTag[Apply] - - /** The constructor/deconstructor for `Apply` instances. */ - val Apply: ApplyExtractor - - /** An extractor class to create and pattern match with syntax `Apply(fun, args)`. - * This AST node corresponds to the following Scala code: - * - * fun(args) - * - * For instance: - * - * fun[targs](args) - * - * Is expressed as: - * - * Apply(TypeApply(fun, targs), args) - */ - abstract class ApplyExtractor { - def apply(fun: Tree, args: List[Tree]): Apply - def unapply(apply: Apply): Option[(Tree, List[Tree])] - } - - /** Super reference, where `qual` is the corresponding `this` reference. - * A super reference `C.super[M]` is represented as `Super(This(C), M)`. - */ - type Super >: Null <: TermTree - - /** A tag that preserves the identity of the `Super` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val SuperTag: ClassTag[Super] - - /** The constructor/deconstructor for `Super` instances. */ - val Super: SuperExtractor - - /** An extractor class to create and pattern match with syntax `Super(qual, mix)`. - * This AST node corresponds to the following Scala code: - * - * C.super[M] - * - * Which is represented as: - * - * Super(This(C), M) - * - * If `mix` is empty, it is tpnme.EMPTY. - * - * The symbol of a Super is the class _from_ which the super reference is made. - * For instance in C.super(...), it would be C. - */ - abstract class SuperExtractor { - def apply(qual: Tree, mix: TypeName): Super - def unapply(super_ : Super): Option[(Tree, TypeName)] - } - - /** Self reference */ - type This >: Null <: TermTree with SymTree - - /** A tag that preserves the identity of the `This` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val ThisTag: ClassTag[This] - - /** The constructor/deconstructor for `This` instances. */ - val This: ThisExtractor - - /** An extractor class to create and pattern match with syntax `This(qual)`. - * This AST node corresponds to the following Scala code: - * - * qual.this - * - * The symbol of a This is the class to which the this refers. - * For instance in C.this, it would be C. - * - * If `mix` is empty, then ??? - */ - abstract class ThisExtractor { - def apply(qual: TypeName): This - def unapply(this_ : This): Option[TypeName] - } - - /** Designator <qualifier> . <name> */ - type Select >: Null <: RefTree - - /** A tag that preserves the identity of the `Select` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val SelectTag: ClassTag[Select] - - /** The constructor/deconstructor for `Select` instances. */ - val Select: SelectExtractor - - /** An extractor class to create and pattern match with syntax `Select(qual, name)`. - * This AST node corresponds to the following Scala code: - * - * qualifier.selector - */ - abstract class SelectExtractor { - def apply(qualifier: Tree, name: Name): Select - def unapply(select: Select): Option[(Tree, Name)] - } - - /** Identifier <name> */ - type Ident >: Null <: RefTree - - /** A tag that preserves the identity of the `Ident` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val IdentTag: ClassTag[Ident] - - /** The constructor/deconstructor for `Ident` instances. */ - val Ident: IdentExtractor - - /** An extractor class to create and pattern match with syntax `Ident(qual, name)`. - * This AST node corresponds to the following Scala code: - * - * name - * - * Type checker converts idents that refer to enclosing fields or methods to selects. - * For example, name ==> this.name - */ - abstract class IdentExtractor { - def apply(name: Name): Ident - def unapply(ident: Ident): Option[Name] - } - - /** Marks underlying reference to id as boxed. - * @pre id must refer to a captured variable - * A reference such marked will refer to the boxed entity, no dereferencing - * with `.elem` is done on it. - * This tree node can be emitted by macros such as reify that call referenceCapturedVariable. - * It is eliminated in LambdaLift, where the boxing conversion takes place. - */ - type ReferenceToBoxed >: Null <: TermTree - - /** A tag that preserves the identity of the `ReferenceToBoxed` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val ReferenceToBoxedTag: ClassTag[ReferenceToBoxed] - - /** The constructor/deconstructor for `ReferenceToBoxed` instances. */ - val ReferenceToBoxed: ReferenceToBoxedExtractor - - /** An extractor class to create and pattern match with syntax `ReferenceToBoxed(ident)`. - * This AST node does not have direct correspondence to Scala code, - * and is emitted by macros to reference capture vars directly without going through `elem`. - * - * For example: - * - * var x = ... - * fun { x } - * - * Will emit: - * - * Ident(x) - * - * Which gets transformed to: - * - * Select(Ident(x), "elem") - * - * If `ReferenceToBoxed` were used instead of Ident, no transformation would be performed. - */ - abstract class ReferenceToBoxedExtractor { - def apply(ident: Ident): ReferenceToBoxed - def unapply(referenceToBoxed: ReferenceToBoxed): Option[Ident] - } - - /** Literal */ - type Literal >: Null <: TermTree - - /** A tag that preserves the identity of the `Literal` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val LiteralTag: ClassTag[Literal] - - /** The constructor/deconstructor for `Literal` instances. */ - val Literal: LiteralExtractor - - /** An extractor class to create and pattern match with syntax `Literal(value)`. - * This AST node corresponds to the following Scala code: - * - * value - */ - abstract class LiteralExtractor { - def apply(value: Constant): Literal - def unapply(literal: Literal): Option[Constant] - } - - /** A tree that has an annotation attached to it. Only used for annotated types and - * annotation ascriptions, annotations on definitions are stored in the Modifiers. - * Eliminated by typechecker (typedAnnotated), the annotations are then stored in - * an AnnotatedType. - */ - type Annotated >: Null <: AnyRef with Tree - - /** A tag that preserves the identity of the `Annotated` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val AnnotatedTag: ClassTag[Annotated] - - /** The constructor/deconstructor for `Annotated` instances. */ - val Annotated: AnnotatedExtractor - - /** An extractor class to create and pattern match with syntax `Annotated(annot, arg)`. - * This AST node corresponds to the following Scala code: - * - * arg @annot // for types - * arg: @annot // for exprs - */ - abstract class AnnotatedExtractor { - def apply(annot: Tree, arg: Tree): Annotated - def unapply(annotated: Annotated): Option[(Tree, Tree)] - } - - /** Singleton type, eliminated by RefCheck */ - type SingletonTypeTree >: Null <: TypTree - - /** A tag that preserves the identity of the `SingletonTypeTree` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val SingletonTypeTreeTag: ClassTag[SingletonTypeTree] - - /** The constructor/deconstructor for `SingletonTypeTree` instances. */ - val SingletonTypeTree: SingletonTypeTreeExtractor - - /** An extractor class to create and pattern match with syntax `SingletonTypeTree(ref)`. - * This AST node corresponds to the following Scala code: - * - * ref.type - */ - abstract class SingletonTypeTreeExtractor { - def apply(ref: Tree): SingletonTypeTree - def unapply(singletonTypeTree: SingletonTypeTree): Option[Tree] - } - - /** Type selection <qualifier> # <name>, eliminated by RefCheck */ - // [Eugene++] don't see why we need it, when we have Select - type SelectFromTypeTree >: Null <: TypTree with RefTree - - /** A tag that preserves the identity of the `SelectFromTypeTree` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val SelectFromTypeTreeTag: ClassTag[SelectFromTypeTree] - - /** The constructor/deconstructor for `SelectFromTypeTree` instances. */ - val SelectFromTypeTree: SelectFromTypeTreeExtractor - - /** An extractor class to create and pattern match with syntax `SelectFromTypeTree(qualifier, name)`. - * This AST node corresponds to the following Scala code: - * - * qualifier # selector - * - * Note: a path-dependent type p.T is expressed as p.type # T - */ - abstract class SelectFromTypeTreeExtractor { - def apply(qualifier: Tree, name: TypeName): SelectFromTypeTree - def unapply(selectFromTypeTree: SelectFromTypeTree): Option[(Tree, TypeName)] - } - - /** Intersection type <parent1> with ... with <parentN> { <decls> }, eliminated by RefCheck */ - type CompoundTypeTree >: Null <: TypTree - - /** A tag that preserves the identity of the `CompoundTypeTree` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val CompoundTypeTreeTag: ClassTag[CompoundTypeTree] - - /** The constructor/deconstructor for `CompoundTypeTree` instances. */ - val CompoundTypeTree: CompoundTypeTreeExtractor - - /** An extractor class to create and pattern match with syntax `CompoundTypeTree(templ)`. - * This AST node corresponds to the following Scala code: - * - * parent1 with ... with parentN { refinement } - */ - abstract class CompoundTypeTreeExtractor { - def apply(templ: Template): CompoundTypeTree - def unapply(compoundTypeTree: CompoundTypeTree): Option[Template] - } - - /** Applied type <tpt> [ <args> ], eliminated by RefCheck */ - type AppliedTypeTree >: Null <: TypTree - - /** A tag that preserves the identity of the `AppliedTypeTree` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val AppliedTypeTreeTag: ClassTag[AppliedTypeTree] - - /** The constructor/deconstructor for `AppliedTypeTree` instances. */ - val AppliedTypeTree: AppliedTypeTreeExtractor - - /** An extractor class to create and pattern match with syntax `AppliedTypeTree(tpt, args)`. - * This AST node corresponds to the following Scala code: - * - * tpt[args] - */ - abstract class AppliedTypeTreeExtractor { - def apply(tpt: Tree, args: List[Tree]): AppliedTypeTree - def unapply(appliedTypeTree: AppliedTypeTree): Option[(Tree, List[Tree])] - } - - /** Document me! */ - type TypeBoundsTree >: Null <: TypTree - - /** A tag that preserves the identity of the `TypeBoundsTree` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val TypeBoundsTreeTag: ClassTag[TypeBoundsTree] - - /** The constructor/deconstructor for `TypeBoundsTree` instances. */ - val TypeBoundsTree: TypeBoundsTreeExtractor - - /** An extractor class to create and pattern match with syntax `TypeBoundsTree(lo, hi)`. - * This AST node corresponds to the following Scala code: - * - * >: lo <: hi - */ - abstract class TypeBoundsTreeExtractor { - def apply(lo: Tree, hi: Tree): TypeBoundsTree - def unapply(typeBoundsTree: TypeBoundsTree): Option[(Tree, Tree)] - } - - /** Document me! */ - type ExistentialTypeTree >: Null <: TypTree - - /** A tag that preserves the identity of the `ExistentialTypeTree` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val ExistentialTypeTreeTag: ClassTag[ExistentialTypeTree] - - /** The constructor/deconstructor for `ExistentialTypeTree` instances. */ - val ExistentialTypeTree: ExistentialTypeTreeExtractor - - /** An extractor class to create and pattern match with syntax `ExistentialTypeTree(tpt, whereClauses)`. - * This AST node corresponds to the following Scala code: - * - * tpt forSome { whereClauses } - */ - abstract class ExistentialTypeTreeExtractor { - def apply(tpt: Tree, whereClauses: List[Tree]): ExistentialTypeTree - def unapply(existentialTypeTree: ExistentialTypeTree): Option[(Tree, List[Tree])] - } - - /** A synthetic tree holding an arbitrary type. Not to be confused with - * with TypTree, the trait for trees that are only used for type trees. - * TypeTree's are inserted in several places, but most notably in - * `RefCheck`, where the arbitrary type trees are all replaced by - * TypeTree's. */ - type TypeTree >: Null <: TypTree - - /** A tag that preserves the identity of the `TypeTree` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val TypeTreeTag: ClassTag[TypeTree] - - /** The constructor/deconstructor for `TypeTree` instances. */ - val TypeTree: TypeTreeExtractor - - /** An extractor class to create and pattern match with syntax `TypeTree()`. - * This AST node does not have direct correspondence to Scala code, - * and is emitted by everywhere when we want to wrap a `Type` in a `Tree`. - */ - abstract class TypeTreeExtractor { - def apply(): TypeTree - def unapply(typeTree: TypeTree): Boolean - } - - /** ... */ - type Modifiers >: Null <: ModifiersBase - - /** A tag that preserves the identity of the `Modifiers` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val ModifiersTag: ClassTag[Modifiers] - - /** ... */ - abstract class ModifiersBase { - def flags: FlagSet // default: NoFlags - def hasFlag(flag: FlagSet): Boolean - def privateWithin: Name // default: EmptyTypeName - def annotations: List[Tree] // default: List() - def mapAnnotations(f: List[Tree] => List[Tree]): Modifiers = - Modifiers(flags, privateWithin, f(annotations)) - } - - val Modifiers: ModifiersCreator - - abstract class ModifiersCreator { - def apply(): Modifiers = Modifiers(NoFlags, EmptyTypeName, List()) - def apply(flags: FlagSet, privateWithin: Name, annotations: List[Tree]): Modifiers - } - - def Modifiers(flags: FlagSet, privateWithin: Name): Modifiers = Modifiers(flags, privateWithin, List()) - def Modifiers(flags: FlagSet): Modifiers = Modifiers(flags, EmptyTypeName) - - /** ... */ - lazy val NoMods = Modifiers() - -// ---------------------- factories ---------------------------------------------- - - /** @param sym the class symbol - * @param impl the implementation template - */ - def ClassDef(sym: Symbol, impl: Template): ClassDef - - /** - * @param sym the class symbol - * @param impl the implementation template - */ - def ModuleDef(sym: Symbol, impl: Template): ModuleDef - - def ValDef(sym: Symbol, rhs: Tree): ValDef - - def ValDef(sym: Symbol): ValDef - - def DefDef(sym: Symbol, mods: Modifiers, vparamss: List[List[ValDef]], rhs: Tree): DefDef - - def DefDef(sym: Symbol, vparamss: List[List[ValDef]], rhs: Tree): DefDef - - def DefDef(sym: Symbol, mods: Modifiers, rhs: Tree): DefDef - - def DefDef(sym: Symbol, rhs: Tree): DefDef - - def DefDef(sym: Symbol, rhs: List[List[Symbol]] => Tree): DefDef - - /** A TypeDef node which defines given `sym` with given tight hand side `rhs`. */ - def TypeDef(sym: Symbol, rhs: Tree): TypeDef - - /** A TypeDef node which defines abstract type or type parameter for given `sym` */ - def TypeDef(sym: Symbol): TypeDef - - def LabelDef(sym: Symbol, params: List[Symbol], rhs: Tree): LabelDef - - /** Block factory that flattens directly nested blocks. - */ - def Block(stats: Tree*): Block - - /** casedef shorthand */ - def CaseDef(pat: Tree, body: Tree): CaseDef - - def Bind(sym: Symbol, body: Tree): Bind - - def Try(body: Tree, cases: (Tree, Tree)*): Try - - def Throw(tpe: Type, args: Tree*): Throw - - /** Factory method for object creation `new tpt(args_1)...(args_n)` - * A `New(t, as)` is expanded to: `(new t).<init>(as)` - */ - def New(tpt: Tree, argss: List[List[Tree]]): Tree - - /** 0-1 argument list new, based on a type. - */ - def New(tpe: Type, args: Tree*): Tree - - def New(sym: Symbol, args: Tree*): Tree - - def Apply(sym: Symbol, args: Tree*): Tree - - def ApplyConstructor(tpt: Tree, args: List[Tree]): Tree - - def Super(sym: Symbol, mix: TypeName): Tree - - def This(sym: Symbol): Tree - - def Select(qualifier: Tree, name: String): Select - - def Select(qualifier: Tree, sym: Symbol): Select - - def Ident(name: String): Ident - - def Ident(sym: Symbol): Ident - - def TypeTree(tp: Type): TypeTree -}
\ No newline at end of file diff --git a/src/library/scala/reflect/base/TypeCreator.scala b/src/library/scala/reflect/base/TypeCreator.scala deleted file mode 100644 index 0260fe1410..0000000000 --- a/src/library/scala/reflect/base/TypeCreator.scala +++ /dev/null @@ -1,26 +0,0 @@ -package scala.reflect -package base - -/** A mirror-aware factory for types. - * - * In the reflection API, artifacts are specific to universes and - * symbolic references used in artifacts (e.g. `scala.Int`) are resolved by mirrors. - * - * Therefore to build a type one needs to know a universe that the type is going to be bound to - * and a mirror that is going to resolve symbolic references (e.g. to determine that `scala.Int` - * points to a core class `Int` from scala-library.jar). - * - * `TypeCreator` implements this notion by providing a standalone type factory. - * - * This is immediately useful for type tags. When the compiler creates a type tag, - * the end result needs to make sense in any mirror. That's because the compiler knows - * the universe it's creating a type tag for (since `TypeTag` is path-dependent on a universe), - * but it cannot know in advance the mirror to instantiate the result in (e.g. on JVM - * it doesn't know what classloader use to resolve symbolic names in the type tag). - * - * Due to a typechecker restriction (no eta-expansion for dependent method types), - * `TypeCreator` can't have a functional type, so it's implemented as class with an apply method. - */ -abstract class TypeCreator { - def apply[U <: Universe with Singleton](m: MirrorOf[U]): U # Type -} diff --git a/src/library/scala/reflect/base/TypeTags.scala b/src/library/scala/reflect/base/TypeTags.scala deleted file mode 100644 index db9fa95553..0000000000 --- a/src/library/scala/reflect/base/TypeTags.scala +++ /dev/null @@ -1,355 +0,0 @@ -/* NSC -- new Scala compiler - * Copyright 2005-2012 LAMP/EPFL - * @author Martin Odersky - */ - -package scala -package reflect -package base - -import java.lang.{ Class => jClass } -import scala.language.implicitConversions - -/* - * TODO - * add @see to docs about universes - * [Eugene++] also mention sensitivity to prefixes, i.e. that rb.TypeTag is different from ru.TypeTag - * [Chris++] tag.in(some mirror) or expr.in(some mirror) (does not work for tag and exprs in macros) - * Backwards compat item1: [Eugene++] it might be useful, though, to guard against abstractness of the incoming type. - */ -/** - * A type tag encapsulates a representation of type T. - * - * Type tags replace the pre-2.10 concept of a [[scala.reflect.Manifest]] and are integrated with reflection. - * - * === Overview and examples === - * - * Type tags are organized in a hierarchy of three classes: - * [[scala.reflect.ClassTag]], [[scala.reflect.base.Universe#TypeTag]] and [[scala.reflect.base.Universe#WeakTypeTag]]. - * - * @see [[scala.reflect.ClassTag]], [[scala.reflect.base.Universe#TypeTag]], [[scala.reflect.base.Universe#WeakTypeTag]] - * - * Examples: - * {{{ - * scala> class Person - * scala> class Container[T] - * scala> import scala.reflect.ClassTag - * scala> import scala.reflect.runtime.universe.TypeTag - * scala> import scala.reflect.runtime.universe.WeakTypeTag - * scala> def firstTypeArg( tag: WeakTypeTag[_] ) = (tag.tpe match {case TypeRef(_,_,typeArgs) => typeArgs})(0) - * }}} - * TypeTag contains concrete type arguments: - * {{{ - * scala> firstTypeArg( implicitly[TypeTag[Container[Person]]] ) - * res0: reflect.runtime.universe.Type = Person - * }}} - * TypeTag guarantees concrete type arguments (fails for references to unbound type arguments): - * {{{ - * scala> def foo1[T] = implicitly[TypeTag[Container[T]]] - * <console>:11: error: No TypeTag available for Container[T] - * def foo1[T] = implicitly[TypeTag[Container[T]]] - * }}} - * WeakTypeTag allows references to unbound type arguments: - * {{{ - * scala> def foo2[T] = firstTypeArg( implicitly[WeakTypeTag[Container[T]]] ) - * foo2: [T]=> reflect.runtime.universe.Type - * scala> foo2[Person] - * res1: reflect.runtime.universe.Type = T - * }}} - * TypeTag allows unbound type arguments for which type tags are available: - * {{{ - * scala> def foo3[T:TypeTag] = firstTypeArg( implicitly[TypeTag[Container[T]]] ) - * foo3: [T](implicit evidence$1: reflect.runtime.universe.TypeTag[T])reflect.runtime.universe.Type - * scala> foo3[Person] - * res1: reflect.runtime.universe.Type = Person - * }}} - * WeakTypeTag contains concrete type arguments if available via existing tags: - * {{{ - * scala> def foo4[T:WeakTypeTag] = firstTypeArg( implicitly[WeakTypeTag[Container[T]]] ) - * foo4: [T](implicit evidence$1: reflect.runtime.universe.WeakTypeTag[T])reflect.runtime.universe.Type - * scala> foo4[Person] - * res1: reflect.runtime.universe.Type = Person - * }}} - * - * - * [[scala.reflect.base.Universe#TypeTag]] and [[scala.reflect.base.Universe#WeakTypeTag]] are path dependent on their universe. - * - * The default universe is [[scala.reflect.runtime.universe]] - * - * Type tags can be migrated to another universe given the corresponding mirror using - * - * {{{ - * tag.in( other_mirror ) - * }}} - * - * See [[scala.reflect.base.TypeTags#WeakTypeTag.in]] - * - * === WeakTypeTag vs TypeTag === - * - * Be careful with WeakTypeTag, because it will reify types even if these types are abstract. - * This makes it easy to forget to tag one of the methods in the call chain and discover it much later in the runtime - * by getting cryptic errors far away from their source. For example, consider the following snippet: - * - * {{{ - * def bind[T: WeakTypeTag](name: String, value: T): IR.Result = bind((name, value)) - * def bind(p: NamedParam): IR.Result = bind(p.name, p.tpe, p.value) - * object NamedParam { - * implicit def namedValue[T: WeakTypeTag](name: String, x: T): NamedParam = apply(name, x) - * def apply[T: WeakTypeTag](name: String, x: T): NamedParam = new Typed[T](name, x) - * } - * }}} - * - * This fragment of the Scala REPL implementation defines a `bind` function that carries a named value along with its type - * into the heart of the REPL. Using a [[scala.reflect.base.Universe#WeakTypeTag]] here is reasonable, because it is desirable - * to work with all types, even if they are type parameters or abstract type members. - * - * However if any of the three `WeakTypeTag` context bounds is omitted, the resulting code will be incorrect, - * because the missing `WeakTypeTag` will be transparently generated by the compiler, carrying meaningless information. - * Most likely, this problem will manifest itself elsewhere, making debugging complicated. - * If `WeakTypeTag` context bounds were replaced with `TypeTag`, then such errors would be reported statically. - * But in that case we wouldn't be able to use `bind` in arbitrary contexts. - * - * === Backward compatibility with Manifests === - * - * Type tags correspond loosely to manifests. - * - * More precisely: - * The previous notion of a [[scala.reflect.ClassManifest]] corresponds to a scala.reflect.ClassTag, - * The previous notion of a [[scala.reflect.Manifest]] corresponds to scala.reflect.runtime.universe.TypeTag, - * - * In Scala 2.10, manifests are deprecated, so it's advisable to migrate them to tags, - * because manifests will probably be removed in the next major release. - * - * In most cases it will be enough to replace ClassManifest with ClassTag and Manifest with TypeTag. - * There are however a few caveats: - * - * 1) The notion of OptManifest is no longer supported. Tags can reify arbitrary types, so they are always available. - * - * 2) There's no equivalent for AnyValManifest. Consider comparing your tag with one of the base tags - * (defined in the corresponding companion objects) to find out whether it represents a primitive value class. - * You can also use `<tag>.tpe.typeSymbol.isPrimitiveValueClass` for that purpose (requires scala-reflect.jar). - * - * 3) There's no replacement for factory methods defined in `ClassManifest` and `Manifest` companion objects. - * Consider assembling corresponding types using the reflection APIs provided by Java (for classes) and Scala (for types). - * - * 4) Certain manifest functions (such as `<:<`, `>:>` and `typeArguments`) weren't included in the tag API. - * Consider using the reflection APIs provided by Java (for classes) and Scala (for types) instead. - */ -trait TypeTags { self: Universe => - - import definitions._ - - /** - * If an implicit value of type WeakTypeTag[T] is required, the compiler will create one. - * A reflective representation of T can be accessed via the tpe field. - * Components of T can be references to type parameters or abstract types. WeakTypeTag makes an effort to - * be as concrete as possible, i.e. if type tags are available for the referenced type arguments or abstract types, - * they are used to embed the concrete types into the WeakTypeTag. Otherwise the WeakTypeTag will contain a reference - * to an abstract type. This behavior can be useful, when one expects T to be possibly partially abstract, but - * requires special care to handle this case. If however T is expected to be fully known, use - * [[scala.reflect.base.Universe#TypeTag]] instead, which statically guarantees this property. - * - * @see [[scala.reflect.base.TypeTags]] - */ - @annotation.implicitNotFound(msg = "No WeakTypeTag available for ${T}") - trait WeakTypeTag[T] extends Equals with Serializable { - /** - * Mirror corresponding to the universe of this WeakTypeTag. - */ - val mirror: Mirror - /** - * Migrates type tag to another universe. - * - * Type tags are path dependent on their universe. This methods allows migration - * given the mirror corresponding to the target universe. - * - * Migration means that all symbolic references to classes/objects/packages in the expression - * will be re-resolved within the new mirror (typically using that mirror's classloader). - */ - def in[U <: Universe with Singleton](otherMirror: MirrorOf[U]): U # WeakTypeTag[T] - - /** - * Reflective representation of type T. - */ - def tpe: Type - - // case class accessories - override def canEqual(x: Any) = x.isInstanceOf[WeakTypeTag[_]] - override def equals(x: Any) = x.isInstanceOf[WeakTypeTag[_]] && this.mirror == x.asInstanceOf[WeakTypeTag[_]].mirror && this.tpe == x.asInstanceOf[WeakTypeTag[_]].tpe - override def hashCode = mirror.hashCode * 31 + tpe.hashCode - override def toString = "WeakTypeTag[" + tpe + "]" - } - - /** - * Type tags corresponding to primitive types and constructor/extractor for WeakTypeTags. - */ - object WeakTypeTag { - val Byte : WeakTypeTag[scala.Byte] = TypeTag.Byte - val Short : WeakTypeTag[scala.Short] = TypeTag.Short - val Char : WeakTypeTag[scala.Char] = TypeTag.Char - val Int : WeakTypeTag[scala.Int] = TypeTag.Int - val Long : WeakTypeTag[scala.Long] = TypeTag.Long - val Float : WeakTypeTag[scala.Float] = TypeTag.Float - val Double : WeakTypeTag[scala.Double] = TypeTag.Double - val Boolean : WeakTypeTag[scala.Boolean] = TypeTag.Boolean - val Unit : WeakTypeTag[scala.Unit] = TypeTag.Unit - val Any : WeakTypeTag[scala.Any] = TypeTag.Any - val AnyVal : WeakTypeTag[scala.AnyVal] = TypeTag.AnyVal - val AnyRef : WeakTypeTag[scala.AnyRef] = TypeTag.AnyRef - val Object : WeakTypeTag[java.lang.Object] = TypeTag.Object - val Nothing : WeakTypeTag[scala.Nothing] = TypeTag.Nothing - val Null : WeakTypeTag[scala.Null] = TypeTag.Null - - - def apply[T](mirror1: MirrorOf[self.type], tpec1: TypeCreator): WeakTypeTag[T] = - tpec1(mirror1) match { - case ByteTpe => WeakTypeTag.Byte.asInstanceOf[WeakTypeTag[T]] - case ShortTpe => WeakTypeTag.Short.asInstanceOf[WeakTypeTag[T]] - case CharTpe => WeakTypeTag.Char.asInstanceOf[WeakTypeTag[T]] - case IntTpe => WeakTypeTag.Int.asInstanceOf[WeakTypeTag[T]] - case LongTpe => WeakTypeTag.Long.asInstanceOf[WeakTypeTag[T]] - case FloatTpe => WeakTypeTag.Float.asInstanceOf[WeakTypeTag[T]] - case DoubleTpe => WeakTypeTag.Double.asInstanceOf[WeakTypeTag[T]] - case BooleanTpe => WeakTypeTag.Boolean.asInstanceOf[WeakTypeTag[T]] - case UnitTpe => WeakTypeTag.Unit.asInstanceOf[WeakTypeTag[T]] - case AnyTpe => WeakTypeTag.Any.asInstanceOf[WeakTypeTag[T]] - case AnyValTpe => WeakTypeTag.AnyVal.asInstanceOf[WeakTypeTag[T]] - case AnyRefTpe => WeakTypeTag.AnyRef.asInstanceOf[WeakTypeTag[T]] - case ObjectTpe => WeakTypeTag.Object.asInstanceOf[WeakTypeTag[T]] - case NothingTpe => WeakTypeTag.Nothing.asInstanceOf[WeakTypeTag[T]] - case NullTpe => WeakTypeTag.Null.asInstanceOf[WeakTypeTag[T]] - case _ => new WeakTypeTagImpl[T](mirror1.asInstanceOf[Mirror], tpec1) - } - - def unapply[T](ttag: WeakTypeTag[T]): Option[Type] = Some(ttag.tpe) - } - - private class WeakTypeTagImpl[T](val mirror: Mirror, val tpec: TypeCreator) extends WeakTypeTag[T] { - lazy val tpe: Type = tpec(mirror) - def in[U <: Universe with Singleton](otherMirror: MirrorOf[U]): U # WeakTypeTag[T] = { - val otherMirror1 = otherMirror.asInstanceOf[MirrorOf[otherMirror.universe.type]] - otherMirror.universe.WeakTypeTag[T](otherMirror1, tpec) - } - private def writeReplace(): AnyRef = new SerializedTypeTag(tpec, concrete = false) - } - - /** - * A `TypeTag` is a [[scala.reflect.base.Universe#WeakTypeTag]] with the additional - * static guarantee that all type references are concrete, i.e. it does <b>not</b> contain any references to - * unresolved type parameters or abstract types. - * - * @see [[scala.reflect.base.TypeTags]] - */ - @annotation.implicitNotFound(msg = "No TypeTag available for ${T}") - trait TypeTag[T] extends WeakTypeTag[T] with Equals with Serializable { - /** - * @inheritdoc - */ - override def in[U <: Universe with Singleton](otherMirror: MirrorOf[U]): U # TypeTag[T] - - // case class accessories - override def canEqual(x: Any) = x.isInstanceOf[TypeTag[_]] - override def equals(x: Any) = x.isInstanceOf[TypeTag[_]] && this.mirror == x.asInstanceOf[TypeTag[_]].mirror && this.tpe == x.asInstanceOf[TypeTag[_]].tpe - override def hashCode = mirror.hashCode * 31 + tpe.hashCode - override def toString = "TypeTag[" + tpe + "]" - } - - object TypeTag { - val Byte: TypeTag[scala.Byte] = new PredefTypeTag[scala.Byte] (ByteTpe, _.TypeTag.Byte) - val Short: TypeTag[scala.Short] = new PredefTypeTag[scala.Short] (ShortTpe, _.TypeTag.Short) - val Char: TypeTag[scala.Char] = new PredefTypeTag[scala.Char] (CharTpe, _.TypeTag.Char) - val Int: TypeTag[scala.Int] = new PredefTypeTag[scala.Int] (IntTpe, _.TypeTag.Int) - val Long: TypeTag[scala.Long] = new PredefTypeTag[scala.Long] (LongTpe, _.TypeTag.Long) - val Float: TypeTag[scala.Float] = new PredefTypeTag[scala.Float] (FloatTpe, _.TypeTag.Float) - val Double: TypeTag[scala.Double] = new PredefTypeTag[scala.Double] (DoubleTpe, _.TypeTag.Double) - val Boolean: TypeTag[scala.Boolean] = new PredefTypeTag[scala.Boolean] (BooleanTpe, _.TypeTag.Boolean) - val Unit: TypeTag[scala.Unit] = new PredefTypeTag[scala.Unit] (UnitTpe, _.TypeTag.Unit) - val Any: TypeTag[scala.Any] = new PredefTypeTag[scala.Any] (AnyTpe, _.TypeTag.Any) - val AnyVal: TypeTag[scala.AnyVal] = new PredefTypeTag[scala.AnyVal] (AnyValTpe, _.TypeTag.AnyVal) - val AnyRef: TypeTag[scala.AnyRef] = new PredefTypeTag[scala.AnyRef] (AnyRefTpe, _.TypeTag.AnyRef) - val Object: TypeTag[java.lang.Object] = new PredefTypeTag[java.lang.Object] (ObjectTpe, _.TypeTag.Object) - val Nothing: TypeTag[scala.Nothing] = new PredefTypeTag[scala.Nothing] (NothingTpe, _.TypeTag.Nothing) - val Null: TypeTag[scala.Null] = new PredefTypeTag[scala.Null] (NullTpe, _.TypeTag.Null) - - def apply[T](mirror1: MirrorOf[self.type], tpec1: TypeCreator): TypeTag[T] = - tpec1(mirror1) match { - case ByteTpe => TypeTag.Byte.asInstanceOf[TypeTag[T]] - case ShortTpe => TypeTag.Short.asInstanceOf[TypeTag[T]] - case CharTpe => TypeTag.Char.asInstanceOf[TypeTag[T]] - case IntTpe => TypeTag.Int.asInstanceOf[TypeTag[T]] - case LongTpe => TypeTag.Long.asInstanceOf[TypeTag[T]] - case FloatTpe => TypeTag.Float.asInstanceOf[TypeTag[T]] - case DoubleTpe => TypeTag.Double.asInstanceOf[TypeTag[T]] - case BooleanTpe => TypeTag.Boolean.asInstanceOf[TypeTag[T]] - case UnitTpe => TypeTag.Unit.asInstanceOf[TypeTag[T]] - case AnyTpe => TypeTag.Any.asInstanceOf[TypeTag[T]] - case AnyValTpe => TypeTag.AnyVal.asInstanceOf[TypeTag[T]] - case AnyRefTpe => TypeTag.AnyRef.asInstanceOf[TypeTag[T]] - case ObjectTpe => TypeTag.Object.asInstanceOf[TypeTag[T]] - case NothingTpe => TypeTag.Nothing.asInstanceOf[TypeTag[T]] - case NullTpe => TypeTag.Null.asInstanceOf[TypeTag[T]] - case _ => new TypeTagImpl[T](mirror1.asInstanceOf[Mirror], tpec1) - } - - def unapply[T](ttag: TypeTag[T]): Option[Type] = Some(ttag.tpe) - } - - private class TypeTagImpl[T](mirror: Mirror, tpec: TypeCreator) extends WeakTypeTagImpl[T](mirror, tpec) with TypeTag[T] { - override def in[U <: Universe with Singleton](otherMirror: MirrorOf[U]): U # TypeTag[T] = { - val otherMirror1 = otherMirror.asInstanceOf[MirrorOf[otherMirror.universe.type]] - otherMirror.universe.TypeTag[T](otherMirror1, tpec) - } - private def writeReplace(): AnyRef = new SerializedTypeTag(tpec, concrete = true) - } - - private class PredefTypeCreator[T](copyIn: Universe => Universe#TypeTag[T]) extends TypeCreator { - def apply[U <: Universe with Singleton](m: MirrorOf[U]): U # Type = { - copyIn(m.universe).asInstanceOf[U # TypeTag[T]].tpe - } - } - - private class PredefTypeTag[T](_tpe: Type, copyIn: Universe => Universe#TypeTag[T]) extends TypeTagImpl[T](rootMirror, new PredefTypeCreator(copyIn)) { - override lazy val tpe: Type = _tpe - private def writeReplace(): AnyRef = new SerializedTypeTag(tpec, concrete = true) - } - - /** - * Shortcut for `implicitly[WeakTypeTag[T]]` - */ - def weakTypeTag[T](implicit attag: WeakTypeTag[T]) = attag - - /** - * Shortcut for `implicitly[TypeTag[T]]` - */ - def typeTag[T](implicit ttag: TypeTag[T]) = ttag - - // big thanks to Viktor Klang for this brilliant idea! - /** - * Shortcut for `implicitly[WeakTypeTag[T]].tpe` - */ - def weakTypeOf[T](implicit attag: WeakTypeTag[T]): Type = attag.tpe - - /** - * Shortcut for `implicitly[TypeTag[T]].tpe` - */ - def typeOf[T](implicit ttag: TypeTag[T]): Type = ttag.tpe -} - -private[scala] class SerializedTypeTag(var tpec: TypeCreator, var concrete: Boolean) extends Serializable { - private def writeObject(out: java.io.ObjectOutputStream): Unit = { - out.writeObject(tpec) - out.writeBoolean(concrete) - } - - private def readObject(in: java.io.ObjectInputStream): Unit = { - tpec = in.readObject().asInstanceOf[TypeCreator] - concrete = in.readBoolean() - } - - private def readResolve(): AnyRef = { - import scala.reflect.basis._ - if (concrete) TypeTag(rootMirror, tpec) - else WeakTypeTag(rootMirror, tpec) - } -} -
\ No newline at end of file diff --git a/src/library/scala/reflect/base/Types.scala b/src/library/scala/reflect/base/Types.scala deleted file mode 100644 index b2ee3bc4d3..0000000000 --- a/src/library/scala/reflect/base/Types.scala +++ /dev/null @@ -1,441 +0,0 @@ -package scala.reflect -package base - -/** - * Defines the type hierachy for types. - * - * Note: Because of implementation details, some type factories have return type `Type` - * instead of a more precise type. - * - * @see [[scala.reflect]] for a description on how the class hierarchy is encoded here. - */ -trait Types { self: Universe => - - /** The type of Scala types, and also Scala type signatures. - * (No difference is internally made between the two). - */ - type Type >: Null <: TypeBase - - /** The base API that all types support */ - abstract class TypeBase - - /** A tag that preserves the identity of the `Type` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val TypeTagg: ClassTag[Type] - - /** This constant is used as a special value that indicates that no meaningful type exists. - */ - val NoType: Type - - /** This constant is used as a special value denoting the empty prefix in a path dependent type. - * For instance `x.type` is represented as `SingleType(NoPrefix, <x>)`, where `<x>` stands for - * the symbol for `x`. - */ - val NoPrefix: Type - - /** The type of Scala singleton types, i.e., types that are inhabited - * by only one nun-null value. These include types of the forms - * {{{ - * C.this.type - * C.super.type - * x.type - * }}} - * as well as [[ConstantType constant types]]. - */ - type SingletonType >: Null <: Type - - /** A tag that preserves the identity of the `SingletonType` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val SingletonTypeTag: ClassTag[SingletonType] - - /** A singleton type that describes types of the form on the left with the - * corresponding `ThisType` representation to the right: - * {{{ - * C.this.type ThisType(C) - * }}} - */ - type ThisType >: Null <: AnyRef with SingletonType - - /** A tag that preserves the identity of the `ThisType` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val ThisTypeTag: ClassTag[ThisType] - - /** The constructor/deconstructor for `ThisType` instances. */ - val ThisType: ThisTypeExtractor - - /** An extractor class to create and pattern match with syntax `ThisType(sym)` - * where `sym` is the class prefix of the this type. - */ - abstract class ThisTypeExtractor { - /** - * Creates a ThisType from the given class symbol. - */ - def apply(sym: Symbol): Type - def unapply(tpe: ThisType): Option[Symbol] - } - - /** The `SingleType` type describes types of any of the forms on the left, - * with their TypeRef representations to the right. - * {{{ - * (T # x).type SingleType(T, x) - * p.x.type SingleType(p.type, x) - * x.type SingleType(NoPrefix, x) - * }}} - */ - type SingleType >: Null <: AnyRef with SingletonType - - /** A tag that preserves the identity of the `SingleType` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val SingleTypeTag: ClassTag[SingleType] - - /** The constructor/deconstructor for `SingleType` instances. */ - val SingleType: SingleTypeExtractor - - /** An extractor class to create and pattern match with syntax `SingleType(pre, sym)` - * Here, `pre` is the prefix of the single-type, and `sym` is the stable value symbol - * referred to by the single-type. - */ - abstract class SingleTypeExtractor { - def apply(pre: Type, sym: Symbol): Type // not SingleTypebecause of implementation details - def unapply(tpe: SingleType): Option[(Type, Symbol)] - } - - /** The `SuperType` type is not directly written, but arises when `C.super` is used - * as a prefix in a `TypeRef` or `SingleType`. It's internal presentation is - * {{{ - * SuperType(thistpe, supertpe) - * }}} - * Here, `thistpe` is the type of the corresponding this-type. For instance, - * in the type arising from C.super, the `thistpe` part would be `ThisType(C)`. - * `supertpe` is the type of the super class referred to by the `super`. - */ - type SuperType >: Null <: AnyRef with SingletonType - - /** A tag that preserves the identity of the `SuperType` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val SuperTypeTag: ClassTag[SuperType] - - /** The constructor/deconstructor for `SuperType` instances. */ - val SuperType: SuperTypeExtractor - - /** An extractor class to create and pattern match with syntax `SingleType(thistpe, supertpe)` - */ - abstract class SuperTypeExtractor { - def apply(thistpe: Type, supertpe: Type): Type // not SuperTypebecause of implementation details - def unapply(tpe: SuperType): Option[(Type, Type)] - } - - /** The `ConstantType` type is not directly written in user programs, but arises as the type of a constant. - * The REPL expresses constant types like `Int(11)`. Here are some constants with their types: - * {{{ - * 1 ConstantType(Constant(1)) - * "abc" ConstantType(Constant("abc")) - * }}} - */ - type ConstantType >: Null <: AnyRef with SingletonType - - /** A tag that preserves the identity of the `ConstantType` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val ConstantTypeTag: ClassTag[ConstantType] - - /** The constructor/deconstructor for `ConstantType` instances. */ - val ConstantType: ConstantTypeExtractor - - /** An extractor class to create and pattern match with syntax `ConstantType(constant)` - * Here, `constant` is the constant value represented by the type. - */ - abstract class ConstantTypeExtractor { - def apply(value: Constant): ConstantType - def unapply(tpe: ConstantType): Option[Constant] - } - - /** The `TypeRef` type describes types of any of the forms on the left, - * with their TypeRef representations to the right. - * {{{ - * T # C[T_1, ..., T_n] TypeRef(T, C, List(T_1, ..., T_n)) - * p.C[T_1, ..., T_n] TypeRef(p.type, C, List(T_1, ..., T_n)) - * C[T_1, ..., T_n] TypeRef(NoPrefix, C, List(T_1, ..., T_n)) - * T # C TypeRef(T, C, Nil) - * p.C TypeRef(p.type, C, Nil) - * C TypeRef(NoPrefix, C, Nil) - * }}} - */ - type TypeRef >: Null <: AnyRef with Type - - /** A tag that preserves the identity of the `TypeRef` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val TypeRefTag: ClassTag[TypeRef] - - /** The constructor/deconstructor for `TypeRef` instances. */ - val TypeRef: TypeRefExtractor - - /** An extractor class to create and pattern match with syntax `TypeRef(pre, sym, args)` - * Here, `pre` is the prefix of the type reference, `sym` is the symbol - * referred to by the type reference, and `args` is a possible empty list of - * type argumenrts. - */ - abstract class TypeRefExtractor { - def apply(pre: Type, sym: Symbol, args: List[Type]): Type // not TypeRefbecause of implementation details - def unapply(tpe: TypeRef): Option[(Type, Symbol, List[Type])] - } - - /** A subtype of Type representing refined types as well as `ClassInfo` signatures. - */ - type CompoundType >: Null <: AnyRef with Type - - /** A tag that preserves the identity of the `CompoundType` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val CompoundTypeTag: ClassTag[CompoundType] - - /** The `RefinedType` type defines types of any of the forms on the left, - * with their RefinedType representations to the right. - * {{{ - * P_1 with ... with P_m { D_1; ...; D_n} RefinedType(List(P_1, ..., P_m), Scope(D_1, ..., D_n)) - * P_1 with ... with P_m RefinedType(List(P_1, ..., P_m), Scope()) - * { D_1; ...; D_n} RefinedType(List(AnyRef), Scope(D_1, ..., D_n)) - * }}} - */ - type RefinedType >: Null <: AnyRef with CompoundType - - /** A tag that preserves the identity of the `RefinedType` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val RefinedTypeTag: ClassTag[RefinedType] - - /** The constructor/deconstructor for `RefinedType` instances. */ - val RefinedType: RefinedTypeExtractor - - /** An extractor class to create and pattern match with syntax `RefinedType(parents, decls)` - * Here, `parents` is the list of parent types of the class, and `decls` is the scope - * containing all declarations in the class. - */ - abstract class RefinedTypeExtractor { - def apply(parents: List[Type], decls: Scope): RefinedType - - /** An alternative constructor that passes in the synthetic classs symbol - * that backs the refined type. (Normally, a fresh class symbol is created automatically). - */ - def apply(parents: List[Type], decls: Scope, clazz: Symbol): RefinedType - def unapply(tpe: RefinedType): Option[(List[Type], Scope)] - } - - /** The `ClassInfo` type signature is used to define parents and declarations - * of classes, traits, and objects. If a class, trait, or object C is declared like this - * {{{ - * C extends P_1 with ... with P_m { D_1; ...; D_n} - * }}} - * its `ClassInfo` type has the following form: - * {{{ - * ClassInfo(List(P_1, ..., P_m), Scope(D_1, ..., D_n), C) - * }}} - */ - type ClassInfoType >: Null <: AnyRef with CompoundType - - /** A tag that preserves the identity of the `ClassInfoType` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val ClassInfoTypeTag: ClassTag[ClassInfoType] - - /** The constructor/deconstructor for `ClassInfoType` instances. */ - val ClassInfoType: ClassInfoTypeExtractor - - /** An extractor class to create and pattern match with syntax `ClassInfo(parents, decls, clazz)` - * Here, `parents` is the list of parent types of the class, `decls` is the scope - * containing all declarations in the class, and `clazz` is the symbol of the class - * itself. - */ - abstract class ClassInfoTypeExtractor { - def apply(parents: List[Type], decls: Scope, typeSymbol: Symbol): ClassInfoType - def unapply(tpe: ClassInfoType): Option[(List[Type], Scope, Symbol)] - } - - /** The `MethodType` type signature is used to indicate parameters and result type of a method - */ - type MethodType >: Null <: AnyRef with Type - - /** A tag that preserves the identity of the `MethodType` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val MethodTypeTag: ClassTag[MethodType] - - /** The constructor/deconstructor for `MethodType` instances. */ - val MethodType: MethodTypeExtractor - - /** An extractor class to create and pattern match with syntax `MethodType(params, respte)` - * Here, `params` is a potentially empty list of parameter symbols of the method, - * and `restpe` is the result type of the method. If the method is curried, `restpe` would - * be another `MethodType`. - * Note: `MethodType(Nil, Int)` would be the type of a method defined with an empty parameter list. - * {{{ - * def f(): Int - * }}} - * If the method is completely parameterless, as in - * {{{ - * def f: Int - * }}} - * its type is a `NullaryMethodType`. - */ - abstract class MethodTypeExtractor { - def apply(params: List[Symbol], resultType: Type): MethodType - def unapply(tpe: MethodType): Option[(List[Symbol], Type)] - } - - /** The `NullaryMethodType` type signature is used for parameterless methods - * with declarations of the form `def foo: T` - */ - type NullaryMethodType >: Null <: AnyRef with Type - - /** A tag that preserves the identity of the `NullaryMethodType` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val NullaryMethodTypeTag: ClassTag[NullaryMethodType] - - /** The constructor/deconstructor for `NullaryMethodType` instances. */ - val NullaryMethodType: NullaryMethodTypeExtractor - - /** An extractor class to create and pattern match with syntax `NullaryMethodType(resultType)`. - * Here, `resultType` is the result type of the parameterless method. - */ - abstract class NullaryMethodTypeExtractor { - def apply(resultType: Type): NullaryMethodType - def unapply(tpe: NullaryMethodType): Option[(Type)] - } - - /** The `PolyType` type signature is used for polymorphic methods - * that have at least one type parameter. - */ - type PolyType >: Null <: AnyRef with Type - - /** A tag that preserves the identity of the `PolyType` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val PolyTypeTag: ClassTag[PolyType] - - /** The constructor/deconstructor for `PolyType` instances. */ - val PolyType: PolyTypeExtractor - - /** An extractor class to create and pattern match with syntax `PolyType(typeParams, resultType)`. - * Here, `typeParams` are the type parameters of the method and `resultType` - * is the type signature following the type parameters. - */ - abstract class PolyTypeExtractor { - def apply(typeParams: List[Symbol], resultType: Type): PolyType - def unapply(tpe: PolyType): Option[(List[Symbol], Type)] - } - - /** The `ExistentialType` type signature is used for existential types and - * wildcard types. - */ - type ExistentialType >: Null <: AnyRef with Type - - /** A tag that preserves the identity of the `ExistentialType` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val ExistentialTypeTag: ClassTag[ExistentialType] - - /** The constructor/deconstructor for `ExistentialType` instances. */ - val ExistentialType: ExistentialTypeExtractor - - /** An extractor class to create and pattern match with syntax - * `ExistentialType(quantified, underlying)`. - * Here, `quantified` are the type variables bound by the existential type and `underlying` - * is the type that's existentially quantified. - */ - abstract class ExistentialTypeExtractor { - def apply(quantified: List[Symbol], underlying: Type): ExistentialType - def unapply(tpe: ExistentialType): Option[(List[Symbol], Type)] - } - - /** The `AnnotatedType` type signature is used for annotated types of the - * for `<type> @<annotation>`. - */ - type AnnotatedType >: Null <: AnyRef with Type - - /** A tag that preserves the identity of the `AnnotatedType` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val AnnotatedTypeTag: ClassTag[AnnotatedType] - - /** The constructor/deconstructor for `AnnotatedType` instances. */ - val AnnotatedType: AnnotatedTypeExtractor - - /** An extractor class to create and pattern match with syntax - * `AnnotatedType(annotations, underlying, selfsym)`. - * Here, `annotations` are the annotations decorating the underlying type `underlying`. - * `selfSym` is a symbol representing the annotated type itself. - */ - abstract class AnnotatedTypeExtractor { - def apply(annotations: List[Annotation], underlying: Type, selfsym: Symbol): AnnotatedType - def unapply(tpe: AnnotatedType): Option[(List[Annotation], Type, Symbol)] - } - - /** The `TypeBounds` type signature is used to indicate lower and upper type bounds - * of type parameters and abstract types. It is not a first-class type. - * If an abstract type or type parameter is declared with any of the forms - * on the left, its type signature is the TypeBounds type on the right. - * {{{ - * T >: L <: U TypeBounds(L, U) - * T >: L TypeBounds(L, Any) - * T <: U TypeBounds(Nothing, U) - * }}} - */ - type TypeBounds >: Null <: AnyRef with Type - - /** A tag that preserves the identity of the `TypeBounds` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val TypeBoundsTag: ClassTag[TypeBounds] - - /** The constructor/deconstructor for `TypeBounds` instances. */ - val TypeBounds: TypeBoundsExtractor - - /** An extractor class to create and pattern match with syntax `TypeBound(lower, upper)` - * Here, `lower` is the lower bound of the `TypeBounds` pair, and `upper` is - * the upper bound. - */ - abstract class TypeBoundsExtractor { - def apply(lo: Type, hi: Type): TypeBounds - def unapply(tpe: TypeBounds): Option[(Type, Type)] - } - - /** An object representing an unknown type, used during type inference. - * If you see WildcardType outside of inference it is almost certainly a bug. - */ - val WildcardType: Type - - /** BoundedWildcardTypes, used only during type inference, are created in - * two places: - * - * 1. If the expected type of an expression is an existential type, - * its hidden symbols are replaced with bounded wildcards. - * 2. When an implicit conversion is being sought based in part on - * the name of a method in the converted type, a HasMethodMatching - * type is created: a MethodType with parameters typed as - * BoundedWildcardTypes. - */ - type BoundedWildcardType >: Null <: AnyRef with Type - - /** A tag that preserves the identity of the `BoundedWildcardType` abstract type from erasure. - * Can be used for pattern matching, instance tests, serialization and likes. - */ - implicit val BoundedWildcardTypeTag: ClassTag[BoundedWildcardType] - - /** The constructor/deconstructor for `BoundedWildcardType` instances. */ - val BoundedWildcardType: BoundedWildcardTypeExtractor - - /** An extractor class to create and pattern match with syntax `BoundedWildcardTypeExtractor(bounds)` - * with `bounds` denoting the type bounds. - */ - abstract class BoundedWildcardTypeExtractor { - def apply(bounds: TypeBounds): BoundedWildcardType - def unapply(tpe: BoundedWildcardType): Option[TypeBounds] - } -} diff --git a/src/library/scala/reflect/base/Universe.scala b/src/library/scala/reflect/base/Universe.scala deleted file mode 100644 index 0b5d5ed685..0000000000 --- a/src/library/scala/reflect/base/Universe.scala +++ /dev/null @@ -1,80 +0,0 @@ -package scala.reflect -package base - -abstract class Universe extends Symbols - with Types - with FlagSets - with Scopes - with Names - with Trees - with Constants - with Annotations - with Positions - with Exprs - with TypeTags - with TagInterop - with StandardDefinitions - with StandardNames - with BuildUtils - with Mirrors -{ - /** Produce the abstract syntax tree representing the given Scala expression. - * - * For example - * - * {{{ - * val five = reify{ 5 } // Literal(Constant(5)) - * reify{ 2 + 4 } // Apply( Select( Literal(Constant(2)), newTermName("$plus")), List( Literal(Constant(4)) ) ) - * reify{ five.splice + 4 } // Apply( Select( Literal(Constant(5)), newTermName("$plus")), List( Literal(Constant(4)) ) ) - * }}} - * - * The produced tree is path dependent on the Universe `reify` was called from. - * - * Use [[scala.reflect.base.Exprs#Expr.splice]] to embed an existing expression into a reify call. Use [[Expr]] to turn a [[Tree]] into an expression that can be spliced. - * - * == Further info and implementation details == - * - * `reify` is implemented as a macro, which given an expression, generates a tree that when compiled and executed produces the original tree. - * - * For instance in `reify{ x + 1 }` the macro `reify` receives the abstract syntax tree of `x + 1` as its argument, which is - * - * {{{ - * Apply(Select(Ident("x"), "+"), List(Literal(Constant(1)))) - * }}} - * - * and returns a tree, which produces the tree above, when compiled and executed. So in other terms, the refiy call expands to something like - * - * {{{ - * val $u: u.type = u // where u is a reference to the Universe that calls the reify - * $u.Expr[Int]($u.Apply($u.Select($u.Ident($u.newFreeVar("x", <Int>, x), "+"), List($u.Literal($u.Constant(1)))))) - * }}} - * - * ------ - * - * Reification performs expression splicing (when processing Expr.splice) - * and type splicing (for every type T that has a TypeTag[T] implicit in scope): - * - * {{{ - * val two = mirror.reify(2) // Literal(Constant(2)) - * val four = mirror.reify(two.splice + two.splice) // Apply(Select(two.tree, newTermName("$plus")), List(two.tree)) - * - * def macroImpl[T](c: Context) = { - * ... - * // T here is just a type parameter, so the tree produced by reify won't be of much use in a macro expansion - * // however, if T were annotated with c.WeakTypeTag (which would declare an implicit parameter for macroImpl) - * // then reification would substitute T with the TypeTree that was used in a TypeApply of this particular macro invocation - * val factory = c.reify{ new Queryable[T] } - * ... - * } - * }}} - * - * The transformation looks mostly straightforward, but it has its tricky parts: - * - Reifier retains symbols and types defined outside the reified tree, however - * locally defined entities get erased and replaced with their original trees - * - Free variables are detected and wrapped in symbols of the type `FreeTermSymbol` or `FreeTypeSymbol` - * - Mutable variables that are accessed from a local function are wrapped in refs - */ - // implementation is hardwired to `scala.reflect.reify.Taggers` - // using the mechanism implemented in `scala.tools.reflect.FastTrack` - def reify[T](expr: T): Expr[T] = ??? // macro -}
\ No newline at end of file diff --git a/src/library/scala/reflect/base/compat.scala b/src/library/scala/reflect/base/compat.scala new file mode 100644 index 0000000000..0f7bec49f2 --- /dev/null +++ b/src/library/scala/reflect/base/compat.scala @@ -0,0 +1,16 @@ +package scala.reflect.base + +// should be removed once I re-deploy the starr +trait Exprs { + case class Expr +} +trait TypeTags { + case class TypeTag + case class WeakTypeTag +} +trait Universe { + def reify: Nothing = ??? +} +trait MirrorOf +trait TypeCreator +trait TreeCreator
\ No newline at end of file diff --git a/src/library/scala/reflect/macros/internal/package.scala b/src/library/scala/reflect/macros/internal/package.scala index 8457285752..61efc58e04 100644 --- a/src/library/scala/reflect/macros/internal/package.scala +++ b/src/library/scala/reflect/macros/internal/package.scala @@ -3,12 +3,9 @@ package scala.reflect.macros import scala.reflect.base.{Universe => BaseUniverse} import scala.reflect.ClassTag -// anchors for materialization macros emitted during tag materialization in Implicits.scala -// implementation is hardwired into `scala.reflect.reify.Taggers` -// using the mechanism implemented in `scala.tools.reflect.FastTrack` -// todo. once we have implicit macros for tag generation, we can remove these anchors package object internal { - private[scala] def materializeClassTag[T](u: BaseUniverse): ClassTag[T] = ??? // macro - private[scala] def materializeWeakTypeTag[T](u: BaseUniverse): u.WeakTypeTag[T] = ??? // macro - private[scala] def materializeTypeTag[T](u: BaseUniverse): u.TypeTag[T] = ??? // macro + // should all be removed once I re-deploy the starr + def materializeClassTag[T](u: BaseUniverse): ClassTag[T] = ??? + def materializeWeakTypeTag: Nothing = ??? + def materializeTypeTag: Nothing = ??? } diff --git a/src/library/scala/reflect/package.scala b/src/library/scala/reflect/package.scala index 8b411d0dca..f9ad743ab3 100644 --- a/src/library/scala/reflect/package.scala +++ b/src/library/scala/reflect/package.scala @@ -1,77 +1,9 @@ package scala -/** - * The base package of Scala's reflection library. - * - * The reflection library is structured according to the 'cake pattern'. The base layer - * resides in package [[scala.reflect.base]] and defines an interface to the following main types: - * - * - [[scala.reflect.base.Types#Type Types]] represent types - * - [[scala.reflect.base.Symbols#Symbol Symbols]] represent definitions - * - [[scala.reflect.base.Trees#Tree Trees]] represent abstract syntax trees - * - [[scala.reflect.base.Names#Name Names]] represent term and type names - * - [[scala.reflect.base.Annotations#Annotation Annotations]] represent annotations - * - [[scala.reflect.base.Positions#Position Positions]] represent source positions of tree nodes - * - [[scala.reflect.base.FlagSets#FlagSet FlagSet]] represent sets of flags that apply to symbols and - * definition trees - * - [[scala.reflect.base.Constants#Constant Constants]] represent compile-time constants. - * - * Each of these types are defined in their own enclosing traits, which are ultimately all inherited by class - * [[scala.reflect.base.Universe Universe]]. The base universe defines a minimal interface to the above types. - * Universes that provide additional functionality such as deeper introspection or runtime code generation, - * are defined in packages [[scala.reflect.api]] and `scala.tools.reflect`. - * - * The cake pattern employed here requires to write certain Scala idioms with more indirections that usual. - * What follows is a description of these indirections, which will help to navigate the Scaladocs easily. - * - * For instance, consider the base type of all abstract syntax trees: [[scala.reflect.base.Trees#Tree]]. - * This type is not a class but is abstract and has an upper bound of [[scala.reflect.base.Trees#TreeBase]], - * which is a class defining the minimal base interface for all trees. - * - * For a more interesting tree type, consider [[scala.reflect.base.Trees#If]] representing if-expressions. - * It does not come with a class `IfBase`, since it does not add anything to the interface of its upper - * bound `TermTree`. However, it is defined next to a value `If` of type [[scala.reflect.base.Trees#IfExtractor]]. - * This value serves as the companion object defining a factory method `apply` and a corresponding `unapply` - * for pattern matching. - * - * {{{ - * import scala.reflect.runtime.universe._ - * val cond = reify{ condition }.tree // <- just some tree representing a condition - * val body = Literal(Constant(1)) - * val other = Literal(Constant(2)) - * val iftree = If(cond,body,other) - * }}} - * - * is equivalent to - * - * {{{ - * import scala.reflect.runtime.universe._ - * val iftree = reify{ if( condition ) 1 else 2 }.tree - * }}} - * - * and can be pattern matched as - * - * {{{ - * iftree match { case If(cond,body,other) => ... } - * }}} - * - * Moreover, there is an implicit value [[scala.reflect.base.Trees#IfTag]] of type - * `ClassTag[If]` that is used by the Scala compiler so that we can indeed pattern match on `If`: - * {{{ - * iftree match { case _:If => ... } - * }}} - * Without the given implicit value, this pattern match would raise an "unchecked" warning at compile time - * since `If` is an abstract type that gets erased at runtime. See [[scala.reflect.ClassTag]] for details. - * - * To summarize: each tree type `X` (and similarly for other types such as `Type` or `Symbol`) is represented - * by an abstract type `X`, optionally together with a class `XBase` that defines `X`'s' interface. - * `X`'s companion object, if it exists, is represented by a value `X` that is of type `XExtractor`. - * Moreover, for each type `X`, there is a value `XTag` of type `ClassTag[X]` that allows to pattern match - * on `X`. - */ package object reflect { - lazy val basis: base.Universe = new base.Base + // should be removed once I re-deploy the starr + val basis: scala.reflect.base.Universe = null // in the new scheme of things ClassManifests are aliased to ClassTags // this is done because we want `toArray` in collections work with ClassTags @@ -111,15 +43,12 @@ package object reflect { val Manifest = ManifestFactory def classTag[T](implicit ctag: ClassTag[T]) = ctag - // typeTag incantation is defined inside scala.reflect.basis and scala.reflect.runtime.universe - private[scala] def materializeClassTag[T](u: base.Universe): ClassTag[T] = ??? // macro - - // ClassTag class is defined in ClassTag.scala - type TypeTag[T] = scala.reflect.basis.TypeTag[T] - - // ClassTag object is defined in ClassTag.scala - lazy val TypeTag = scala.reflect.basis.TypeTag + // anchor for the class tag materialization macro emitted during tag materialization in Implicits.scala + // implementation is hardwired into `scala.reflect.reify.Taggers` + // using the mechanism implemented in `scala.tools.reflect.FastTrack` + // todo. once we have implicit macros for tag generation, we can remove this anchor + private[scala] def materializeClassTag[T](): ClassTag[T] = ??? // macro @deprecated("Use `@scala.beans.BeanDescription` instead", "2.10.0") type BeanDescription = scala.beans.BeanDescription |