summaryrefslogtreecommitdiff
path: root/src/reflect
diff options
context:
space:
mode:
Diffstat (limited to 'src/reflect')
-rw-r--r--src/reflect/scala/reflect/api/BuildUtils.scala300
-rw-r--r--src/reflect/scala/reflect/api/ImplicitTags.scala3
-rw-r--r--src/reflect/scala/reflect/api/Importers.scala104
-rw-r--r--src/reflect/scala/reflect/api/Internals.scala859
-rw-r--r--src/reflect/scala/reflect/api/JavaMirrors.scala58
-rw-r--r--src/reflect/scala/reflect/api/JavaUniverse.scala70
-rw-r--r--src/reflect/scala/reflect/api/Mirrors.scala2
-rw-r--r--src/reflect/scala/reflect/api/Scopes.scala5
-rw-r--r--src/reflect/scala/reflect/api/StandardLiftables.scala3
-rw-r--r--src/reflect/scala/reflect/api/Symbols.scala114
-rw-r--r--src/reflect/scala/reflect/api/TagInterop.scala44
-rw-r--r--src/reflect/scala/reflect/api/Trees.scala148
-rw-r--r--src/reflect/scala/reflect/api/Types.scala91
-rw-r--r--src/reflect/scala/reflect/api/Universe.scala4
-rw-r--r--src/reflect/scala/reflect/internal/Definitions.scala3
-rw-r--r--src/reflect/scala/reflect/internal/Importers.scala12
-rw-r--r--src/reflect/scala/reflect/internal/Internals.scala125
-rw-r--r--src/reflect/scala/reflect/internal/ReificationSupport.scala (renamed from src/reflect/scala/reflect/internal/BuildUtils.scala)38
-rw-r--r--src/reflect/scala/reflect/internal/StdAttachments.scala10
-rw-r--r--src/reflect/scala/reflect/internal/StdNames.scala14
-rw-r--r--src/reflect/scala/reflect/internal/SymbolTable.scala7
-rw-r--r--src/reflect/scala/reflect/internal/Symbols.scala15
-rw-r--r--src/reflect/scala/reflect/internal/TreeGen.scala2
-rw-r--r--src/reflect/scala/reflect/internal/Trees.scala20
-rw-r--r--src/reflect/scala/reflect/macros/Reifiers.scala2
-rw-r--r--src/reflect/scala/reflect/macros/TreeBuilder.scala97
-rw-r--r--src/reflect/scala/reflect/macros/Universe.scala235
-rw-r--r--src/reflect/scala/reflect/runtime/JavaUniverse.scala42
-rw-r--r--src/reflect/scala/reflect/runtime/JavaUniverseForce.scala4
29 files changed, 1282 insertions, 1149 deletions
diff --git a/src/reflect/scala/reflect/api/BuildUtils.scala b/src/reflect/scala/reflect/api/BuildUtils.scala
deleted file mode 100644
index ec20a89a10..0000000000
--- a/src/reflect/scala/reflect/api/BuildUtils.scala
+++ /dev/null
@@ -1,300 +0,0 @@
-package scala
-package reflect
-package api
-
-/**
- * This is an internal implementation class.
- * @groupname TreeBuilders Tree Building
- */
-private[reflect] trait BuildUtils { self: Universe =>
-
- /** @group TreeBuilders */
- val build: BuildApi
-
- // 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
-
- /** @group TreeBuilders */
- abstract class BuildApi {
- /** 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 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
-
- def toStats(tree: Tree): List[Tree]
-
- def mkAnnotation(tree: Tree): Tree
-
- def mkAnnotation(trees: List[Tree]): List[Tree]
-
- def mkRefineStat(stat: Tree): Tree
-
- def mkRefineStat(stats: List[Tree]): List[Tree]
-
- def mkPackageStat(stat: Tree): Tree
-
- def mkPackageStat(stats: List[Tree]): List[Tree]
-
- def mkEarlyDef(defn: Tree): Tree
-
- def mkEarlyDef(defns: List[Tree]): List[Tree]
-
- def RefTree(qual: Tree, sym: Symbol): Tree
-
- def freshTermName(prefix: String): TermName
-
- def freshTypeName(prefix: String): TypeName
-
- val ImplicitParams: ImplicitParamsExtractor
-
- trait ImplicitParamsExtractor {
- def apply(paramss: List[List[ValDef]], implparams: List[ValDef]): List[List[ValDef]]
- def unapply(vparamss: List[List[ValDef]]): Some[(List[List[ValDef]], List[ValDef])]
- }
-
- val ScalaDot: ScalaDotExtractor
-
- trait ScalaDotExtractor {
- def apply(name: Name): Tree
- def unapply(tree: Tree): Option[Name]
- }
-
- val FlagsRepr: FlagsReprExtractor
-
- trait FlagsReprExtractor {
- def apply(value: Long): FlagSet
- def unapply(flags: Long): Some[Long]
- }
-
- val SyntacticTypeApplied: SyntacticTypeAppliedExtractor
-
- trait SyntacticTypeAppliedExtractor {
- def apply(tree: Tree, targs: List[Tree]): Tree
- def unapply(tree: Tree): Some[(Tree, List[Tree])]
- }
-
- val SyntacticApplied: SyntacticAppliedExtractor
-
- trait SyntacticAppliedExtractor {
- def apply(tree: Tree, argss: List[List[Tree]]): Tree
- def unapply(tree: Tree): Some[(Tree, List[List[Tree]])]
- }
-
- val SyntacticClassDef: SyntacticClassDefExtractor
-
- trait SyntacticClassDefExtractor {
- def apply(mods: Modifiers, name: TypeName, tparams: List[Tree],
- constrMods: Modifiers, vparamss: List[List[Tree]],
- earlyDefs: List[Tree], parents: List[Tree], selfType: Tree, body: List[Tree]): ClassDef
- def unapply(tree: Tree): Option[(Modifiers, TypeName, List[TypeDef], Modifiers, List[List[ValDef]],
- List[Tree], List[Tree], ValDef, List[Tree])]
- }
-
- val SyntacticTraitDef: SyntacticTraitDefExtractor
-
- trait SyntacticTraitDefExtractor {
- def apply(mods: Modifiers, name: TypeName, tparams: List[Tree],
- earlyDefs: List[Tree], parents: List[Tree], selfType: Tree, body: List[Tree]): ClassDef
- def unapply(tree: Tree): Option[(Modifiers, TypeName, List[TypeDef],
- List[Tree], List[Tree], ValDef, List[Tree])]
- }
-
- val SyntacticObjectDef: SyntacticObjectDefExtractor
-
- trait SyntacticObjectDefExtractor {
- def apply(mods: Modifiers, name: TermName, earlyDefs: List[Tree],
- parents: List[Tree], selfType: Tree, body: List[Tree]): ModuleDef
- def unapply(tree: Tree): Option[(Modifiers, TermName, List[Tree], List[Tree], ValDef, List[Tree])]
- }
-
- val SyntacticPackageObjectDef: SyntacticPackageObjectDefExtractor
-
- trait SyntacticPackageObjectDefExtractor {
- def apply(name: TermName, earlyDefs: List[Tree],
- parents: List[Tree], selfType: Tree, body: List[Tree]): PackageDef
- def unapply(tree: Tree): Option[(TermName, List[Tree], List[Tree], ValDef, List[Tree])]
- }
-
- val SyntacticTuple: SyntacticTupleExtractor
- val SyntacticTupleType: SyntacticTupleExtractor
-
- trait SyntacticTupleExtractor {
- def apply(args: List[Tree]): Tree
- def unapply(tree: Tree): Option[List[Tree]]
- }
-
- val SyntacticBlock: SyntacticBlockExtractor
-
- trait SyntacticBlockExtractor {
- def apply(stats: List[Tree]): Tree
- def unapply(tree: Tree): Option[List[Tree]]
- }
-
- val SyntacticNew: SyntacticNewExtractor
-
- trait SyntacticNewExtractor {
- def apply(earlyDefs: List[Tree], parents: List[Tree], selfType: Tree, body: List[Tree]): Tree
- def unapply(tree: Tree): Option[(List[Tree], List[Tree], ValDef, List[Tree])]
- }
-
- val SyntacticFunctionType: SyntacticFunctionTypeExtractor
-
- trait SyntacticFunctionTypeExtractor {
- def apply(argtpes: List[Tree], restpe: Tree): Tree
- def unapply(tree: Tree): Option[(List[Tree], Tree)]
- }
-
- val SyntacticFunction: SyntacticFunctionExtractor
-
- trait SyntacticFunctionExtractor {
- def apply(params: List[Tree], body: Tree): Function
-
- def unapply(tree: Function): Option[(List[ValDef], Tree)]
- }
-
- val SyntacticDefDef: SyntacticDefDefExtractor
-
- trait SyntacticDefDefExtractor {
- def apply(mods: Modifiers, name: TermName, tparams: List[Tree],
- vparamss: List[List[Tree]], tpt: Tree, rhs: Tree): DefDef
-
- def unapply(tree: Tree): Option[(Modifiers, TermName, List[TypeDef], List[List[ValDef]], Tree, Tree)]
- }
-
- val SyntacticValDef: SyntacticValDefExtractor
- val SyntacticVarDef: SyntacticValDefExtractor
-
- trait SyntacticValDefExtractor {
- def apply(mods: Modifiers, name: TermName, tpt: Tree, rhs: Tree): ValDef
- def unapply(tree: Tree): Option[(Modifiers, TermName, Tree, Tree)]
- }
-
- val SyntacticAssign: SyntacticAssignExtractor
-
- trait SyntacticAssignExtractor {
- def apply(lhs: Tree, rhs: Tree): Tree
- def unapply(tree: Tree): Option[(Tree, Tree)]
- }
-
- val SyntacticValFrom: SyntacticValFromExtractor
-
- trait SyntacticValFromExtractor {
- def apply(pat: Tree, rhs: Tree): Tree
- def unapply(tree: Tree): Option[(Tree, Tree)]
- }
-
- val SyntacticValEq: SyntacticValEqExtractor
-
- trait SyntacticValEqExtractor {
- def apply(pat: Tree, rhs: Tree): Tree
- def unapply(tree: Tree): Option[(Tree, Tree)]
- }
-
- val SyntacticFilter: SyntacticFilterExtractor
-
- trait SyntacticFilterExtractor {
- def apply(test: Tree): Tree
- def unapply(tree: Tree): Option[(Tree)]
- }
-
- val SyntacticEmptyTypeTree: SyntacticEmptyTypeTreeExtractor
-
- trait SyntacticEmptyTypeTreeExtractor {
- def apply(): TypeTree
- def unapply(tt: TypeTree): Boolean
- }
-
- val SyntacticFor: SyntacticForExtractor
- val SyntacticForYield: SyntacticForExtractor
-
- trait SyntacticForExtractor {
- def apply(enums: List[Tree], body: Tree): Tree
- def unapply(tree: Tree): Option[(List[Tree], Tree)]
- }
-
- def UnliftListElementwise[T](unliftable: Unliftable[T]): UnliftListElementwise[T]
- trait UnliftListElementwise[T] {
- def unapply(lst: List[Tree]): Option[List[T]]
- }
-
- def UnliftListOfListsElementwise[T](unliftable: Unliftable[T]): UnliftListOfListsElementwise[T]
- trait UnliftListOfListsElementwise[T] {
- def unapply(lst: List[List[Tree]]): Option[List[List[T]]]
- }
-
- val SyntacticMatch: SyntacticMatchExtractor
- trait SyntacticMatchExtractor {
- def apply(selector: Tree, cases: List[Tree]): Match
- def unapply(tree: Match): Option[(Tree, List[CaseDef])]
- }
-
- val SyntacticTry: SyntacticTryExtractor
- trait SyntacticTryExtractor {
- def apply(block: Tree, catches: List[Tree], finalizer: Tree): Try
- def unapply(tree: Try): Option[(Tree, List[CaseDef], Tree)]
- }
-
- val SyntacticIdent: SyntacticIdentExtractor
- trait SyntacticIdentExtractor {
- def apply(name: Name, isBackquoted: Boolean = false): Ident
- def unapply(tree: Ident): Option[(Name, Boolean)]
- }
-
- val SyntacticImport: SyntacticImportExtractor
- trait SyntacticImportExtractor {
- def apply(expr: Tree, selectors: List[Tree]): Import
- def unapply(imp: Import): Some[(Tree, List[Tree])]
- }
- }
-}
diff --git a/src/reflect/scala/reflect/api/ImplicitTags.scala b/src/reflect/scala/reflect/api/ImplicitTags.scala
index 4fd7709089..aca0692d0d 100644
--- a/src/reflect/scala/reflect/api/ImplicitTags.scala
+++ b/src/reflect/scala/reflect/api/ImplicitTags.scala
@@ -51,8 +51,6 @@ trait ImplicitTags {
implicit val TypeSymbolTag: ClassTag[TypeSymbol]
implicit val ModuleSymbolTag: ClassTag[ModuleSymbol]
implicit val ClassSymbolTag: ClassTag[ClassSymbol]
- implicit val FreeTermSymbolTag: ClassTag[FreeTermSymbol]
- implicit val FreeTypeSymbolTag: ClassTag[FreeTypeSymbol]
// Tags for misc Tree relatives.
implicit val PositionTag: ClassTag[Position]
@@ -91,7 +89,6 @@ trait ImplicitTags {
implicit val NewTag: ClassTag[New]
implicit val PackageDefTag: ClassTag[PackageDef]
implicit val RefTreeTag: ClassTag[RefTree]
- implicit val ReferenceToBoxedTag: ClassTag[ReferenceToBoxed]
implicit val ReturnTag: ClassTag[Return]
implicit val SelectFromTypeTreeTag: ClassTag[SelectFromTypeTree]
implicit val SelectTag: ClassTag[Select]
diff --git a/src/reflect/scala/reflect/api/Importers.scala b/src/reflect/scala/reflect/api/Importers.scala
deleted file mode 100644
index 6539137cee..0000000000
--- a/src/reflect/scala/reflect/api/Importers.scala
+++ /dev/null
@@ -1,104 +0,0 @@
-package scala
-package reflect
-package api
-
-/**
- * <span class="badge badge-red" style="float: right;">EXPERIMENTAL</span>
- *
- * This trait provides support for importers, a facility to migrate reflection artifacts between universes.
- * ''Note: this trait should typically be used only rarely.''
- *
- * Reflection artifacts, such as [[scala.reflect.api.Symbols Symbols]] and [[scala.reflect.api.Types Types]],
- * are contained in [[scala.reflect.api.Universe Universe]]s. Typically all processing happens
- * within a single `Universe` (e.g. a compile-time macro `Universe` or a runtime reflection `Universe`), but sometimes
- * there is a need to migrate artifacts from one `Universe` to another. For example, runtime compilation works by
- * importing runtime reflection trees into a runtime compiler universe, compiling the importees and exporting the
- * result back.
- *
- * Reflection artifacts are firmly grounded in their `Universe`s, which is reflected by the fact that types of artifacts
- * from different universes are not compatible. By using `Importer`s, however, they be imported from one universe
- * into another. For example, to import `foo.bar.Baz` from the source `Universe` to the target `Universe`,
- * an importer will first check whether the entire owner chain exists in the target `Universe`.
- * If it does, then nothing else will be done. Otherwise, the importer will recreate the entire owner chain
- * and will import the corresponding type signatures into the target `Universe`.
- *
- * Since importers match `Symbol` tables of the source and the target `Universe`s using plain string names,
- * it is programmer's responsibility to make sure that imports don't distort semantics, e.g., that
- * `foo.bar.Baz` in the source `Universe` means the same that `foo.bar.Baz` does in the target `Universe`.
- *
- * === Example ===
- *
- * Here's how one might implement a macro that performs compile-time evaluation of its argument
- * by using a runtime compiler to compile and evaluate a tree that belongs to a compile-time compiler:
- *
- * {{{
- * def staticEval[T](x: T) = macro staticEval[T]
- *
- * def staticEval[T](c: scala.reflect.macros.blackbox.Context)(x: c.Expr[T]) = {
- * // creates a runtime reflection universe to host runtime compilation
- * import scala.reflect.runtime.{universe => ru}
- * val mirror = ru.runtimeMirror(c.libraryClassLoader)
- * import scala.tools.reflect.ToolBox
- * val toolBox = mirror.mkToolBox()
- *
- * // runtime reflection universe and compile-time macro universe are different
- * // therefore an importer is needed to bridge them
- * // currently mkImporter requires a cast to correctly assign the path-dependent types
- * val importer0 = ru.mkImporter(c.universe)
- * val importer = importer0.asInstanceOf[ru.Importer { val from: c.universe.type }]
- *
- * // the created importer is used to turn a compiler tree into a runtime compiler tree
- * // both compilers use the same classpath, so semantics remains intact
- * val imported = importer.importTree(tree)
- *
- * // after the tree is imported, it can be evaluated as usual
- * val tree = toolBox.untypecheck(imported.duplicate)
- * val valueOfX = toolBox.eval(imported).asInstanceOf[T]
- * ...
- * }
- * }}}
- *
- * @group ReflectionAPI
- */
-trait Importers { self: Universe =>
-
- /** Creates an importer that moves reflection artifacts between universes.
- * @group Importers
- */
- def mkImporter(from0: Universe): Importer { val from: from0.type }
-
- /** The API of importers.
- * The main source of information about importers is the [[scala.reflect.api.Importers]] page.
- * @group Importers
- */
- trait Importer {
- /** The source universe of reflection artifacts that will be processed.
- * The target universe is universe that created this importer with `mkImporter`.
- */
- val from: Universe
-
- /** An importer that works in reverse direction, namely:
- * imports reflection artifacts from the current universe to the universe specified in `from`.
- */
- val reverse: from.Importer { val from: self.type }
-
- /** In the current universe, locates or creates a symbol that corresponds to the provided symbol in the source universe.
- * If necessary imports the owner chain, companions, type signature, annotations and attachments.
- */
- def importSymbol(sym: from.Symbol): Symbol
-
- /** In the current universe, locates or creates a type that corresponds to the provided type in the source universe.
- * If necessary imports the underlying symbols, annotations, scopes and trees.
- */
- def importType(tpe: from.Type): Type
-
- /** In the current universe, creates a tree that corresponds to the provided tree in the source universe.
- * If necessary imports the underlying symbols, types and attachments.
- */
- def importTree(tree: from.Tree): Tree
-
- /** In the current universe, creates a position that corresponds to the provided position in the source universe.
- */
- def importPosition(pos: from.Position): Position
- }
-}
diff --git a/src/reflect/scala/reflect/api/Internals.scala b/src/reflect/scala/reflect/api/Internals.scala
new file mode 100644
index 0000000000..93796ad29e
--- /dev/null
+++ b/src/reflect/scala/reflect/api/Internals.scala
@@ -0,0 +1,859 @@
+package scala
+package reflect
+package api
+
+import scala.language.implicitConversions
+
+/**
+ * <span class="badge badge-red" style="float: right;">EXPERIMENTAL</span>
+ *
+ * This trait assembles APIs occasionally necessary for performing low-level operations on reflection artifacts.
+ * See [[Internals#InternalApi]] for more information about nature, usefulness and compatibility guarantees of these APIs.
+ *
+ * @group ReflectionAPI
+ */
+trait Internals { self: Universe =>
+
+ /** @see [[InternalApi]]
+ * @group Internal
+ */
+ val internal: Internal
+
+ /** @see [[InternalApi]]
+ * @group Internal
+ */
+ type Internal <: InternalApi
+
+ /** Reflection API exhibits a tension inherent to experimental things:
+ * on the one hand we want it to grow into a beautiful and robust API,
+ * but on the other hand we have to deal with immaturity of underlying mechanisms
+ * by providing not very pretty solutions to enable important use cases.
+ *
+ * In Scala 2.10, which was our first stab at reflection API, we didn't have a systematic
+ * approach to dealing with this tension, sometimes exposing too much of internals (e.g. Symbol.deSkolemize)
+ * and sometimes exposing too little (e.g. there's still no facility to change owners, to do typing
+ * transformations, etc). This resulted in certain confusion with some internal APIs
+ * living among public ones, scaring the newcomers, and some internal APIs only available via casting,
+ * which requires intimate knowledge of the compiler and breaks compatibility guarantees.
+ *
+ * This led to creation of the `internal` API module for the reflection API, which
+ * provides advanced APIs necessary for macros that push boundaries of the state of the art,
+ * clearly demarcating them from the more or less straightforward rest and
+ * providing compatibility guarantees on par with the rest of the reflection API
+ * (full compatibility within minor releases, best effort towards backward compatibility within major releases,
+ * clear replacement path in case of rare incompatible changes in major releases).
+ *
+ * The `internal` module itself (the value that implements [[InternalApi]]) isn't defined here,
+ * in [[scala.reflect.api.Universe]], but is provided on per-implementation basis. Runtime API endpoint
+ * ([[scala.reflect.runtime.universe]]) provides `universe.compat: InternalApi`, whereas compile-time API endpoints
+ * (instances of [[scala.reflect.macros.Context]]) provide `c.compat: ContextInternalApi`, which extends `InternalApi`
+ * with additional universe-specific and context-specific functionality.
+ *
+ * @group Internal
+ */
+ trait InternalApi {
+ /** This is an internal implementation module.
+ */
+ val reificationSupport: ReificationSupportApi
+
+ /** Creates an importer that moves reflection artifacts between universes.
+ * @see [[Importer]]
+ */
+ // SI-6241: move importers to a mirror
+ def createImporter(from0: Universe): Importer { val from: from0.type }
+
+ /**
+ * Convert a [[scala.reflect.api.TypeTags#TypeTag]] to a [[scala.reflect.Manifest]].
+ *
+ * Compiler usually generates these conversions automatically, when a type tag for a type `T` is in scope,
+ * and an implicit of type `Manifest[T]` is requested, but this method can also be called manually.
+ * For example:
+ * {{{
+ * typeTagToManifest(scala.reflect.runtime.currentMirror, implicitly[TypeTag[String]])
+ * }}}
+ * @group TagInterop
+ */
+ def typeTagToManifest[T: ClassTag](mirror: Any, tag: Universe#TypeTag[T]): Manifest[T] =
+ throw new UnsupportedOperationException("This universe does not support tag -> manifest conversions. Use a JavaUniverse, e.g. the scala.reflect.runtime.universe.")
+
+ /**
+ * Convert a [[scala.reflect.Manifest]] to a [[scala.reflect.api.TypeTags#TypeTag]].
+ *
+ * Compiler usually generates these conversions automatically, when a manifest for a type `T` is in scope,
+ * and an implicit of type `TypeTag[T]` is requested, but this method can also be called manually.
+ * For example:
+ * {{{
+ * manifestToTypeTag(scala.reflect.runtime.currentMirror, implicitly[Manifest[String]])
+ * }}}
+ * @group TagInterop
+ */
+ def manifestToTypeTag[T](mirror: Any, manifest: Manifest[T]): Universe#TypeTag[T] =
+ throw new UnsupportedOperationException("This universe does not support manifest -> tag conversions. Use a JavaUniverse, e.g. the scala.reflect.runtime.universe.")
+
+ /** Create a new scope with the given initial elements.
+ * @group Scopes
+ */
+ def newScopeWith(elems: Symbol*): Scope
+
+ /** Extracts free term symbols from a tree that is reified or contains reified subtrees.
+ */
+ def freeTerms(tree: Tree): List[FreeTermSymbol]
+
+ /** Extracts free type symbols from a tree that is reified or contains reified subtrees.
+ */
+ def freeTypes(tree: Tree): List[FreeTypeSymbol]
+
+ /** Substitute symbols in `to` for corresponding occurrences of references to
+ * symbols `from` in this type.
+ */
+ def substituteSymbols(tree: Tree, from: List[Symbol], to: List[Symbol]): Tree
+
+ /** Substitute types in `to` for corresponding occurrences of references to
+ * symbols `from` in this tree.
+ */
+ def substituteTypes(tree: Tree, from: List[Symbol], to: List[Type]): Tree
+
+ /** Substitute given tree `to` for occurrences of nodes that represent
+ * `C.this`, where `C` referes to the given class `clazz`.
+ */
+ def substituteThis(tree: Tree, clazz: Symbol, to: Tree): Tree
+
+ /** A factory method for `ClassDef` nodes.
+ */
+ def classDef(sym: Symbol, impl: Template): ClassDef
+
+ /** A factory method for `ModuleDef` nodes.
+ */
+ def moduleDef(sym: Symbol, impl: Template): ModuleDef
+
+ /** A factory method for `ValDef` nodes.
+ */
+ def valDef(sym: Symbol, rhs: Tree): ValDef
+
+ /** A factory method for `ValDef` nodes.
+ */
+ def valDef(sym: Symbol): ValDef
+
+ /** A factory method for `DefDef` nodes.
+ */
+ def defDef(sym: Symbol, mods: Modifiers, vparamss: List[List[ValDef]], rhs: Tree): DefDef
+
+ /** A factory method for `DefDef` nodes.
+ */
+ def defDef(sym: Symbol, vparamss: List[List[ValDef]], rhs: Tree): DefDef
+
+ /** A factory method for `DefDef` nodes.
+ */
+ def defDef(sym: Symbol, mods: Modifiers, rhs: Tree): DefDef
+
+ /** A factory method for `DefDef` nodes.
+ */
+ def defDef(sym: Symbol, rhs: Tree): DefDef
+
+ /** A factory method for `DefDef` nodes.
+ */
+ def defDef(sym: Symbol, rhs: List[List[Symbol]] => Tree): DefDef
+
+ /** A factory method for `TypeDef` nodes.
+ */
+ def typeDef(sym: Symbol, rhs: Tree): TypeDef
+
+ /** A factory method for `TypeDef` nodes.
+ */
+ def typeDef(sym: Symbol): TypeDef
+
+ /** A factory method for `LabelDef` nodes.
+ */
+ def labelDef(sym: Symbol, params: List[Symbol], rhs: Tree): LabelDef
+
+ /** Does this symbol represent a free term captured by reification?
+ * If yes, `isTerm` is also guaranteed to be true.
+ */
+ def isFreeTerm(symbol: Symbol): Boolean
+
+ /** This symbol cast to a free term symbol.
+ * @throws ScalaReflectionException if `isFreeTerm` is false.
+ */
+ def asFreeTerm(symbol: Symbol): FreeTermSymbol
+
+ /** Does this symbol represent a free type captured by reification?
+ * If yes, `isType` is also guaranteed to be true.
+ */
+ def isFreeType(symbol: Symbol): Boolean
+
+ /** This symbol cast to a free type symbol.
+ * @throws ScalaReflectionException if `isFreeType` is false.
+ */
+ def asFreeType(symbol: Symbol): FreeTypeSymbol
+
+ def newTermSymbol(owner: Symbol, name: TermName, pos: Position = NoPosition, flags: FlagSet = NoFlags): TermSymbol
+
+ def newModuleAndClassSymbol(owner: Symbol, name: Name, pos: Position = NoPosition, flags: FlagSet = NoFlags): (ModuleSymbol, ClassSymbol)
+
+ def newMethodSymbol(owner: Symbol, name: TermName, pos: Position = NoPosition, flags: FlagSet = NoFlags): MethodSymbol
+
+ def newTypeSymbol(owner: Symbol, name: TypeName, pos: Position = NoPosition, flags: FlagSet = NoFlags): TypeSymbol
+
+ def newClassSymbol(owner: Symbol, name: TypeName, pos: Position = NoPosition, flags: FlagSet = NoFlags): ClassSymbol
+
+ def newFreeTerm(name: String, value: => Any, flags: FlagSet = NoFlags, origin: String = null): FreeTermSymbol
+
+ def newFreeType(name: String, flags: FlagSet = NoFlags, origin: String = null): FreeTypeSymbol
+
+ /** Does this symbol or its underlying type represent a typechecking error?
+ */
+ def isErroneous(symbol: Symbol): Boolean
+
+ /** Does this symbol represent the definition of a skolem?
+ * Skolems are used during typechecking to represent type parameters viewed from inside their scopes.
+ */
+ def isSkolem(symbol: Symbol): Boolean
+
+ /** If this symbol is a skolem, its corresponding type parameter, otherwise the symbol itself.
+ *
+ * [[https://groups.google.com/forum/#!msg/scala-internals/0j8laVNTQsI/kRXMF_c8bGsJ To quote Martin Odersky]],
+ * skolems are synthetic type "constants" that are copies of existentially bound or universally
+ * bound type variables. E.g. if one is inside the right-hand side of a method:
+ *
+ * {{{
+ * def foo[T](x: T) = ... foo[List[T]]....
+ * }}}
+ *
+ * the skolem named `T` refers to the unknown type instance of `T` when `foo` is called. It needs to be different
+ * from the type parameter because in a recursive call as in the `foo[List[T]]` above the type parameter gets
+ * substituted with `List[T]`, but the ''type skolem'' stays what it is.
+ *
+ * The other form of skolem is an ''existential skolem''. Say one has a function
+ *
+ * {{{
+ * def bar(xs: List[T] forSome { type T }) = xs.head
+ * }}}
+ *
+ * then each occurrence of `xs` on the right will have type `List[T']` where `T'` is a fresh copy of `T`.
+ */
+ def deSkolemize(symbol: Symbol): Symbol
+
+ /** A creator for `ThisType` types.
+ */
+ def thisType(sym: Symbol): Type
+
+ /** A creator for `SingleType` types.
+ */
+ def singleType(pre: Type, sym: Symbol): Type
+
+ /** A creator for `SuperType` types.
+ */
+ def superType(thistpe: Type, supertpe: Type): Type
+
+ /** A creator for `ConstantType` types.
+ */
+ def constantType(value: Constant): ConstantType
+
+ /** A creator for `TypeRef` types.
+ */
+ def typeRef(pre: Type, sym: Symbol, args: List[Type]): Type
+
+ /** A creator for `RefinedType` types.
+ */
+ def refinedType(parents: List[Type], decls: Scope): RefinedType
+
+ /** A creator for `RefinedType` types.
+ */
+ def refinedType(parents: List[Type], owner: Symbol): Type
+
+ /** A creator for `RefinedType` types.
+ */
+ def refinedType(parents: List[Type], owner: Symbol, decls: Scope): Type
+
+ /** A creator for `RefinedType` types.
+ */
+ def refinedType(parents: List[Type], owner: Symbol, decls: Scope, pos: Position): Type
+
+ /** A creator for intersection type where intersections of a single type are
+ * replaced by the type itself.
+ */
+ def intersectionType(tps: List[Type]): Type
+
+ /** A creator for intersection type where intersections of a single type are
+ * replaced by the type itself, and repeated parent classes are merged.
+ *
+ * !!! Repeated parent classes are not merged - is this a bug in the
+ * comment or in the code?
+ */
+ def intersectionType(tps: List[Type], owner: Symbol): Type
+
+ /** A creator for `ClassInfoType` types.
+ */
+ def classInfoType(parents: List[Type], decls: Scope, typeSymbol: Symbol): ClassInfoType
+
+ /** A creator for `MethodType` types.
+ */
+ def methodType(params: List[Symbol], resultType: Type): MethodType
+
+ /** A creator for `NullaryMethodType` types.
+ */
+ def nullaryMethodType(resultType: Type): NullaryMethodType
+
+ /** A creator for type parameterizations that strips empty type parameter lists.
+ * Use this factory method to indicate the type has kind * (it's a polymorphic value)
+ * until we start tracking explicit kinds equivalent to typeFun (except that the latter requires tparams nonEmpty).
+ */
+ def polyType(tparams: List[Symbol], tpe: Type): PolyType
+
+ /** A creator for `ExistentialType` types.
+ */
+ def existentialType(quantified: List[Symbol], underlying: Type): ExistentialType
+
+ /** A creator for existential types. This generates:
+ *
+ * {{{
+ * tpe1 where { tparams }
+ * }}}
+ *
+ * where `tpe1` is the result of extrapolating `tpe` with regard to `tparams`.
+ * Extrapolating means that type variables in `tparams` occurring
+ * in covariant positions are replaced by upper bounds, (minus any
+ * SingletonClass markers), type variables in `tparams` occurring in
+ * contravariant positions are replaced by upper bounds, provided the
+ * resulting type is legal with regard to stability, and does not contain
+ * any type variable in `tparams`.
+ *
+ * The abstraction drops all type parameters that are not directly or
+ * indirectly referenced by type `tpe1`. If there are no remaining type
+ * parameters, simply returns result type `tpe`.
+ * @group TypeCreators
+ */
+ def existentialAbstraction(tparams: List[Symbol], tpe0: Type): Type
+
+ /** A creator for `AnnotatedType` types.
+ */
+ def annotatedType(annotations: List[Annotation], underlying: Type): AnnotatedType
+
+ /** A creator for `TypeBounds` types.
+ */
+ def typeBounds(lo: Type, hi: Type): TypeBounds
+
+ /** A creator for `BoundedWildcardType` types.
+ */
+ def boundedWildcardType(bounds: TypeBounds): BoundedWildcardType
+ }
+
+ /** This is an internal implementation class.
+ * @group Internal
+ */
+ // this API abstracts away the functionality necessary for reification and quasiquotes
+ // 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
+ trait ReificationSupportApi {
+ /** 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
+
+ def newScopeWith(elems: Symbol*): Scope
+
+ /** 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 This(sym: Symbol): Tree
+
+ def Select(qualifier: Tree, sym: Symbol): Select
+
+ def Ident(sym: Symbol): Ident
+
+ def TypeTree(tp: Type): TypeTree
+
+ def ThisType(sym: Symbol): Type
+
+ def SingleType(pre: Type, sym: Symbol): Type
+
+ def SuperType(thistpe: Type, supertpe: Type): Type
+
+ def ConstantType(value: Constant): ConstantType
+
+ def TypeRef(pre: Type, sym: Symbol, args: List[Type]): Type
+
+ def RefinedType(parents: List[Type], decls: Scope, typeSymbol: Symbol): RefinedType
+
+ def ClassInfoType(parents: List[Type], decls: Scope, typeSymbol: Symbol): ClassInfoType
+
+ def MethodType(params: List[Symbol], resultType: Type): MethodType
+
+ def NullaryMethodType(resultType: Type): NullaryMethodType
+
+ def PolyType(typeParams: List[Symbol], resultType: Type): PolyType
+
+ def ExistentialType(quantified: List[Symbol], underlying: Type): ExistentialType
+
+ def AnnotatedType(annotations: List[Annotation], underlying: Type): AnnotatedType
+
+ def TypeBounds(lo: Type, hi: Type): TypeBounds
+
+ def BoundedWildcardType(bounds: TypeBounds): BoundedWildcardType
+
+ def thisPrefix(sym: Symbol): Type
+
+ def setType[T <: Tree](tree: T, tpe: Type): T
+
+ def setSymbol[T <: Tree](tree: T, sym: Symbol): T
+
+ def toStats(tree: Tree): List[Tree]
+
+ def mkAnnotation(tree: Tree): Tree
+
+ def mkAnnotation(trees: List[Tree]): List[Tree]
+
+ def mkRefineStat(stat: Tree): Tree
+
+ def mkRefineStat(stats: List[Tree]): List[Tree]
+
+ def mkPackageStat(stat: Tree): Tree
+
+ def mkPackageStat(stats: List[Tree]): List[Tree]
+
+ def mkEarlyDef(defn: Tree): Tree
+
+ def mkEarlyDef(defns: List[Tree]): List[Tree]
+
+ def RefTree(qual: Tree, sym: Symbol): Tree
+
+ def freshTermName(prefix: String): TermName
+
+ def freshTypeName(prefix: String): TypeName
+
+ val ImplicitParams: ImplicitParamsExtractor
+
+ trait ImplicitParamsExtractor {
+ def apply(paramss: List[List[ValDef]], implparams: List[ValDef]): List[List[ValDef]]
+ def unapply(vparamss: List[List[ValDef]]): Some[(List[List[ValDef]], List[ValDef])]
+ }
+
+ val ScalaDot: ScalaDotExtractor
+
+ trait ScalaDotExtractor {
+ def apply(name: Name): Tree
+ def unapply(tree: Tree): Option[Name]
+ }
+
+ val FlagsRepr: FlagsReprExtractor
+
+ trait FlagsReprExtractor {
+ def apply(value: Long): FlagSet
+ def unapply(flags: Long): Some[Long]
+ }
+
+ val SyntacticTypeApplied: SyntacticTypeAppliedExtractor
+
+ trait SyntacticTypeAppliedExtractor {
+ def apply(tree: Tree, targs: List[Tree]): Tree
+ def unapply(tree: Tree): Some[(Tree, List[Tree])]
+ }
+
+ val SyntacticApplied: SyntacticAppliedExtractor
+
+ trait SyntacticAppliedExtractor {
+ def apply(tree: Tree, argss: List[List[Tree]]): Tree
+ def unapply(tree: Tree): Some[(Tree, List[List[Tree]])]
+ }
+
+ val SyntacticClassDef: SyntacticClassDefExtractor
+
+ trait SyntacticClassDefExtractor {
+ def apply(mods: Modifiers, name: TypeName, tparams: List[Tree],
+ constrMods: Modifiers, vparamss: List[List[Tree]],
+ earlyDefs: List[Tree], parents: List[Tree], selfType: Tree, body: List[Tree]): ClassDef
+ def unapply(tree: Tree): Option[(Modifiers, TypeName, List[TypeDef], Modifiers, List[List[ValDef]],
+ List[Tree], List[Tree], ValDef, List[Tree])]
+ }
+
+ val SyntacticTraitDef: SyntacticTraitDefExtractor
+
+ trait SyntacticTraitDefExtractor {
+ def apply(mods: Modifiers, name: TypeName, tparams: List[Tree],
+ earlyDefs: List[Tree], parents: List[Tree], selfType: Tree, body: List[Tree]): ClassDef
+ def unapply(tree: Tree): Option[(Modifiers, TypeName, List[TypeDef],
+ List[Tree], List[Tree], ValDef, List[Tree])]
+ }
+
+ val SyntacticObjectDef: SyntacticObjectDefExtractor
+
+ trait SyntacticObjectDefExtractor {
+ def apply(mods: Modifiers, name: TermName, earlyDefs: List[Tree],
+ parents: List[Tree], selfType: Tree, body: List[Tree]): ModuleDef
+ def unapply(tree: Tree): Option[(Modifiers, TermName, List[Tree], List[Tree], ValDef, List[Tree])]
+ }
+
+ val SyntacticPackageObjectDef: SyntacticPackageObjectDefExtractor
+
+ trait SyntacticPackageObjectDefExtractor {
+ def apply(name: TermName, earlyDefs: List[Tree],
+ parents: List[Tree], selfType: Tree, body: List[Tree]): PackageDef
+ def unapply(tree: Tree): Option[(TermName, List[Tree], List[Tree], ValDef, List[Tree])]
+ }
+
+ val SyntacticTuple: SyntacticTupleExtractor
+ val SyntacticTupleType: SyntacticTupleExtractor
+
+ trait SyntacticTupleExtractor {
+ def apply(args: List[Tree]): Tree
+ def unapply(tree: Tree): Option[List[Tree]]
+ }
+
+ val SyntacticBlock: SyntacticBlockExtractor
+
+ trait SyntacticBlockExtractor {
+ def apply(stats: List[Tree]): Tree
+ def unapply(tree: Tree): Option[List[Tree]]
+ }
+
+ val SyntacticNew: SyntacticNewExtractor
+
+ trait SyntacticNewExtractor {
+ def apply(earlyDefs: List[Tree], parents: List[Tree], selfType: Tree, body: List[Tree]): Tree
+ def unapply(tree: Tree): Option[(List[Tree], List[Tree], ValDef, List[Tree])]
+ }
+
+ val SyntacticFunctionType: SyntacticFunctionTypeExtractor
+
+ trait SyntacticFunctionTypeExtractor {
+ def apply(argtpes: List[Tree], restpe: Tree): Tree
+ def unapply(tree: Tree): Option[(List[Tree], Tree)]
+ }
+
+ val SyntacticFunction: SyntacticFunctionExtractor
+
+ trait SyntacticFunctionExtractor {
+ def apply(params: List[Tree], body: Tree): Function
+
+ def unapply(tree: Function): Option[(List[ValDef], Tree)]
+ }
+
+ val SyntacticDefDef: SyntacticDefDefExtractor
+
+ trait SyntacticDefDefExtractor {
+ def apply(mods: Modifiers, name: TermName, tparams: List[Tree],
+ vparamss: List[List[Tree]], tpt: Tree, rhs: Tree): DefDef
+
+ def unapply(tree: Tree): Option[(Modifiers, TermName, List[TypeDef], List[List[ValDef]], Tree, Tree)]
+ }
+
+ val SyntacticValDef: SyntacticValDefExtractor
+ val SyntacticVarDef: SyntacticValDefExtractor
+
+ trait SyntacticValDefExtractor {
+ def apply(mods: Modifiers, name: TermName, tpt: Tree, rhs: Tree): ValDef
+ def unapply(tree: Tree): Option[(Modifiers, TermName, Tree, Tree)]
+ }
+
+ val SyntacticAssign: SyntacticAssignExtractor
+
+ trait SyntacticAssignExtractor {
+ def apply(lhs: Tree, rhs: Tree): Tree
+ def unapply(tree: Tree): Option[(Tree, Tree)]
+ }
+
+ val SyntacticValFrom: SyntacticValFromExtractor
+
+ trait SyntacticValFromExtractor {
+ def apply(pat: Tree, rhs: Tree): Tree
+ def unapply(tree: Tree): Option[(Tree, Tree)]
+ }
+
+ val SyntacticValEq: SyntacticValEqExtractor
+
+ trait SyntacticValEqExtractor {
+ def apply(pat: Tree, rhs: Tree): Tree
+ def unapply(tree: Tree): Option[(Tree, Tree)]
+ }
+
+ val SyntacticFilter: SyntacticFilterExtractor
+
+ trait SyntacticFilterExtractor {
+ def apply(test: Tree): Tree
+ def unapply(tree: Tree): Option[(Tree)]
+ }
+
+ val SyntacticEmptyTypeTree: SyntacticEmptyTypeTreeExtractor
+
+ trait SyntacticEmptyTypeTreeExtractor {
+ def apply(): TypeTree
+ def unapply(tt: TypeTree): Boolean
+ }
+
+ val SyntacticFor: SyntacticForExtractor
+ val SyntacticForYield: SyntacticForExtractor
+
+ trait SyntacticForExtractor {
+ def apply(enums: List[Tree], body: Tree): Tree
+ def unapply(tree: Tree): Option[(List[Tree], Tree)]
+ }
+
+ def UnliftListElementwise[T](unliftable: Unliftable[T]): UnliftListElementwise[T]
+ trait UnliftListElementwise[T] {
+ def unapply(lst: List[Tree]): Option[List[T]]
+ }
+
+ def UnliftListOfListsElementwise[T](unliftable: Unliftable[T]): UnliftListOfListsElementwise[T]
+ trait UnliftListOfListsElementwise[T] {
+ def unapply(lst: List[List[Tree]]): Option[List[List[T]]]
+ }
+
+ val SyntacticMatch: SyntacticMatchExtractor
+ trait SyntacticMatchExtractor {
+ def apply(selector: Tree, cases: List[Tree]): Match
+ def unapply(tree: Match): Option[(Tree, List[CaseDef])]
+ }
+
+ val SyntacticTry: SyntacticTryExtractor
+ trait SyntacticTryExtractor {
+ def apply(block: Tree, catches: List[Tree], finalizer: Tree): Try
+ def unapply(tree: Try): Option[(Tree, List[CaseDef], Tree)]
+ }
+
+ val SyntacticIdent: SyntacticIdentExtractor
+ trait SyntacticIdentExtractor {
+ def apply(name: Name, isBackquoted: Boolean = false): Ident
+ def unapply(tree: Ident): Option[(Name, Boolean)]
+ }
+
+ val SyntacticImport: SyntacticImportExtractor
+ trait SyntacticImportExtractor {
+ def apply(expr: Tree, selectors: List[Tree]): Import
+ def unapply(imp: Import): Some[(Tree, List[Tree])]
+ }
+ }
+
+ /** This trait provides support for importers, a facility to migrate reflection artifacts between universes.
+ * ''Note: this trait should typically be used only rarely.''
+ *
+ * Reflection artifacts, such as [[scala.reflect.api.Symbols Symbols]] and [[scala.reflect.api.Types Types]],
+ * are contained in [[scala.reflect.api.Universe Universe]]s. Typically all processing happens
+ * within a single `Universe` (e.g. a compile-time macro `Universe` or a runtime reflection `Universe`), but sometimes
+ * there is a need to migrate artifacts from one `Universe` to another. For example, runtime compilation works by
+ * importing runtime reflection trees into a runtime compiler universe, compiling the importees and exporting the
+ * result back.
+ *
+ * Reflection artifacts are firmly grounded in their `Universe`s, which is reflected by the fact that types of artifacts
+ * from different universes are not compatible. By using `Importer`s, however, they be imported from one universe
+ * into another. For example, to import `foo.bar.Baz` from the source `Universe` to the target `Universe`,
+ * an importer will first check whether the entire owner chain exists in the target `Universe`.
+ * If it does, then nothing else will be done. Otherwise, the importer will recreate the entire owner chain
+ * and will import the corresponding type signatures into the target `Universe`.
+ *
+ * Since importers match `Symbol` tables of the source and the target `Universe`s using plain string names,
+ * it is programmer's responsibility to make sure that imports don't distort semantics, e.g., that
+ * `foo.bar.Baz` in the source `Universe` means the same that `foo.bar.Baz` does in the target `Universe`.
+ *
+ * === Example ===
+ *
+ * Here's how one might implement a macro that performs compile-time evaluation of its argument
+ * by using a runtime compiler to compile and evaluate a tree that belongs to a compile-time compiler:
+ *
+ * {{{
+ * def staticEval[T](x: T) = macro staticEval[T]
+ *
+ * def staticEval[T](c: scala.reflect.macros.blackbox.Context)(x: c.Expr[T]) = {
+ * // creates a runtime reflection universe to host runtime compilation
+ * import scala.reflect.runtime.{universe => ru}
+ * val mirror = ru.runtimeMirror(c.libraryClassLoader)
+ * import scala.tools.reflect.ToolBox
+ * val toolBox = mirror.mkToolBox()
+ *
+ * // runtime reflection universe and compile-time macro universe are different
+ * // therefore an importer is needed to bridge them
+ * // currently mkImporter requires a cast to correctly assign the path-dependent types
+ * val importer0 = ru.internal.mkImporter(c.universe)
+ * val importer = importer0.asInstanceOf[ru.internal.Importer { val from: c.universe.type }]
+ *
+ * // the created importer is used to turn a compiler tree into a runtime compiler tree
+ * // both compilers use the same classpath, so semantics remains intact
+ * val imported = importer.importTree(tree)
+ *
+ * // after the tree is imported, it can be evaluated as usual
+ * val tree = toolBox.untypecheck(imported.duplicate)
+ * val valueOfX = toolBox.eval(imported).asInstanceOf[T]
+ * ...
+ * }
+ * }}}
+ *
+ * @group Internal
+ */
+ // SI-6241: move importers to a mirror
+ trait Importer {
+ /** The source universe of reflection artifacts that will be processed.
+ * The target universe is universe that created this importer with `mkImporter`.
+ */
+ val from: Universe
+
+ /** An importer that works in reverse direction, namely:
+ * imports reflection artifacts from the current universe to the universe specified in `from`.
+ */
+ val reverse: from.Importer { val from: self.type }
+
+ /** In the current universe, locates or creates a symbol that corresponds to the provided symbol in the source universe.
+ * If necessary imports the owner chain, companions, type signature, annotations and attachments.
+ */
+ def importSymbol(sym: from.Symbol): Symbol
+
+ /** In the current universe, locates or creates a type that corresponds to the provided type in the source universe.
+ * If necessary imports the underlying symbols, annotations, scopes and trees.
+ */
+ def importType(tpe: from.Type): Type
+
+ /** In the current universe, creates a tree that corresponds to the provided tree in the source universe.
+ * If necessary imports the underlying symbols, types and attachments.
+ */
+ def importTree(tree: from.Tree): Tree
+
+ /** In the current universe, creates a position that corresponds to the provided position in the source universe.
+ */
+ def importPosition(pos: from.Position): Position
+ }
+
+ /** Marks underlying reference to id as boxed.
+ *
+ * <b>Precondition:<\b> 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.
+ * @group Internal
+ * @template
+ */
+ type ReferenceToBoxed >: Null <: ReferenceToBoxedApi with TermTree
+
+ /** The constructor/extractor for `ReferenceToBoxed` instances.
+ * @group Internal
+ */
+ 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.
+ * @group Internal
+ */
+ abstract class ReferenceToBoxedExtractor {
+ def apply(ident: Ident): ReferenceToBoxed
+ def unapply(referenceToBoxed: ReferenceToBoxed): Option[Ident]
+ }
+
+ /** The API that all references support
+ * @group Internal
+ */
+ trait ReferenceToBoxedApi extends TermTreeApi { this: ReferenceToBoxed =>
+ /** The underlying reference. */
+ def ident: Tree
+ }
+
+ /** Tag that preserves the identity of `ReferenceToBoxed` in the face of erasure.
+ * Can be used for pattern matching, instance tests, serialization and the like.
+ * @group Internal
+ */
+ implicit val ReferenceToBoxedTag: ClassTag[ReferenceToBoxed]
+
+ /** The type of free terms introduced by reification.
+ * @group Internal
+ * @template
+ */
+ type FreeTermSymbol >: Null <: FreeTermSymbolApi with TermSymbol
+
+ /** The API of free term symbols.
+ * The main source of information about symbols is the [[Symbols]] page.
+ *
+ * $SYMACCESSORS
+ * @group Internal
+ */
+ trait FreeTermSymbolApi extends TermSymbolApi { this: FreeTermSymbol =>
+ /** The place where this symbol has been spawned
+ *
+ * @group FreeTerm
+ */
+ def origin: String
+
+ /** The valus this symbol refers to
+ *
+ * @group FreeTerm
+ */
+ def value: Any
+ }
+
+ /** Tag that preserves the identity of `FreeTermSymbol` in the face of erasure.
+ * Can be used for pattern matching, instance tests, serialization and the like.
+ * @group Internal
+ */
+ implicit val FreeTermSymbolTag: ClassTag[FreeTermSymbol]
+
+ /** The type of free types introduced by reification.
+ * @group Internal
+ * @template
+ */
+ type FreeTypeSymbol >: Null <: FreeTypeSymbolApi with TypeSymbol
+
+ /** The API of free type symbols.
+ * The main source of information about symbols is the [[Symbols]] page.
+ *
+ * $SYMACCESSORS
+ * @group Internal
+ */
+ trait FreeTypeSymbolApi extends TypeSymbolApi { this: FreeTypeSymbol =>
+ /** The place where this symbol has been spawned
+ *
+ * @group FreeType
+ */
+ def origin: String
+ }
+
+ /** Tag that preserves the identity of `FreeTermSymbol` in the face of erasure.
+ * Can be used for pattern matching, instance tests, serialization and the like.
+ * @group Internal
+ */
+ implicit val FreeTypeSymbolTag: ClassTag[FreeTypeSymbol]
+}
diff --git a/src/reflect/scala/reflect/api/JavaMirrors.scala b/src/reflect/scala/reflect/api/JavaMirrors.scala
deleted file mode 100644
index 05a4a61d2e..0000000000
--- a/src/reflect/scala/reflect/api/JavaMirrors.scala
+++ /dev/null
@@ -1,58 +0,0 @@
-package scala
-package reflect
-package api
-
-/**
- * <span class="badge badge-red" style="float: right;">EXPERIMENTAL</span>
- *
- * A refinement of [[scala.reflect.api.Mirror]] for runtime reflection using JVM classloaders.
- *
- * This refinement equips mirrors with reflection capabilities for the JVM. `JavaMirror` can
- * convert Scala reflection artifacts (symbols and types) into Java reflection artifacts (classes)
- * and vice versa. It can also perform reflective invocations (getting/setting field values,
- * calling methods, etc).
- *
- * For more information about `Mirrors`s, see [[scala.reflect.api.Mirrors]] or the
- * [[http://docs.scala-lang.org/overviews/reflection/environment-universes-mirrors.html Reflection Guide: Mirrors]]
- *
- * @groupname JavaMirrors Java Mirrors
- * @group ReflectionAPI
- */
-trait JavaMirrors { self: JavaUniverse =>
-
- /** In runtime reflection universes, runtime representation of a class is `java.lang.Class`.
- * @group JavaMirrors
- */
- type RuntimeClass = java.lang.Class[_]
- implicit val RuntimeClassTag: ClassTag[RuntimeClass] = ClassTag[RuntimeClass](classOf[RuntimeClass])
-
- /** In runtime reflection universes, mirrors are `JavaMirrors`.
- * @group JavaMirrors
- */
- override type Mirror >: Null <: JavaMirror
-
- /** A refinement of [[scala.reflect.api.Mirror]] for runtime reflection using JVM classloaders.
- *
- * With this upgrade, mirrors become capable of converting Scala reflection artifacts (symbols and types)
- * into Java reflection artifacts (classes) and vice versa. Consequently, refined mirrors
- * become capable of performing reflective invocations (getting/setting field values, calling methods, etc).
- *
- * For more information about `Mirrors`s, see [[scala.reflect.api.Mirrors]] or the
- * [[http://docs.scala-lang.org/overviews/reflection/environment-universes-mirrors.html Reflection Guide: Mirrors]]
- *
- * @group JavaMirrors
- */
- trait JavaMirror extends scala.reflect.api.Mirror[self.type] with RuntimeMirror {
- val classLoader: ClassLoader
- override def toString = s"JavaMirror with ${runtime.ReflectionUtils.show(classLoader)}"
- }
-
- /** Creates a runtime reflection mirror from a JVM classloader.
- *
- * For more information about `Mirrors`s, see [[scala.reflect.api.Mirrors]] or the
- * [[http://docs.scala-lang.org/overviews/reflection/environment-universes-mirrors.html Reflection Guide: Mirrors]]
- *
- * @group JavaMirrors
- */
- def runtimeMirror(cl: ClassLoader): Mirror
-}
diff --git a/src/reflect/scala/reflect/api/JavaUniverse.scala b/src/reflect/scala/reflect/api/JavaUniverse.scala
index df5e0699a5..88107ea117 100644
--- a/src/reflect/scala/reflect/api/JavaUniverse.scala
+++ b/src/reflect/scala/reflect/api/JavaUniverse.scala
@@ -3,12 +3,14 @@ package reflect
package api
/**
- * <span class="badge badge-red" style="float: right;">EXPERIMENTAL</span>
+ * <span class="badge badge-red" style="float: right;">EXPERIMENTAL</span>
*
- * A refinement of [[scala.reflect.api.Universe]] for runtime reflection using JVM classloaders.
+ * A refinement of [[scala.reflect.api.Universe]] for runtime reflection using JVM classloaders.
*
- * The refinement consists of an upgrade to the mirror API, which gets extended from [[scala.reflect.api.Mirror]]
- * to [[scala.reflect.api.JavaMirrors#JavaMirror]].
+ * This refinement equips mirrors with reflection capabilities for the JVM. `JavaMirror` can
+ * convert Scala reflection artifacts (symbols and types) into Java reflection artifacts (classes)
+ * and vice versa. It can also perform reflective invocations (getting/setting field values,
+ * calling methods, etc).
*
* See the [[http://docs.scala-lang.org/overviews/reflection/overview.html Reflection Guide]] for details on how to use runtime reflection.
*
@@ -17,31 +19,41 @@ package api
*
* @contentDiagram hideNodes "*Api"
*/
-trait JavaUniverse extends Universe with JavaMirrors { self =>
+trait JavaUniverse extends Universe { self =>
- /* @group JavaUniverse */
- override def typeTagToManifest[T: ClassTag](mirror0: Any, tag: Universe # TypeTag[T]): Manifest[T] = {
- // SI-6239: make this conversion more precise
- val mirror = mirror0.asInstanceOf[Mirror]
- val runtimeClass = mirror.runtimeClass(tag.in(mirror).tpe)
- Manifest.classType(runtimeClass).asInstanceOf[Manifest[T]]
+ /** In runtime reflection universes, runtime representation of a class is `java.lang.Class`.
+ * @group JavaMirrors
+ */
+ type RuntimeClass = java.lang.Class[_]
+ implicit val RuntimeClassTag: ClassTag[RuntimeClass] = ClassTag[RuntimeClass](classOf[RuntimeClass])
+
+ /** In runtime reflection universes, mirrors are `JavaMirrors`.
+ * @group JavaMirrors
+ */
+ override type Mirror >: Null <: JavaMirror
+
+ /** A refinement of [[scala.reflect.api.Mirror]] for runtime reflection using JVM classloaders.
+ *
+ * With this upgrade, mirrors become capable of converting Scala reflection artifacts (symbols and types)
+ * into Java reflection artifacts (classes) and vice versa. Consequently, refined mirrors
+ * become capable of performing reflective invocations (getting/setting field values, calling methods, etc).
+ *
+ * For more information about `Mirrors`s, see [[scala.reflect.api.Mirrors]] or the
+ * [[http://docs.scala-lang.org/overviews/reflection/environment-universes-mirrors.html Reflection Guide: Mirrors]]
+ *
+ * @group JavaMirrors
+ */
+ trait JavaMirror extends scala.reflect.api.Mirror[self.type] with RuntimeMirror {
+ val classLoader: ClassLoader
+ override def toString = s"JavaMirror with ${runtime.ReflectionUtils.show(classLoader)}"
}
- /* @group JavaUniverse */
- override def manifestToTypeTag[T](mirror0: Any, manifest: Manifest[T]): Universe # TypeTag[T] =
- TypeTag(mirror0.asInstanceOf[Mirror], new TypeCreator {
- def apply[U <: Universe with Singleton](mirror: scala.reflect.api.Mirror[U]): U # Type = {
- mirror.universe match {
- case ju: JavaUniverse =>
- val jm = mirror.asInstanceOf[ju.Mirror]
- val sym = jm.classSymbol(manifest.runtimeClass)
- val tpe =
- if (manifest.typeArguments.isEmpty) sym.toType
- else ju.appliedType(sym.toTypeConstructor, manifest.typeArguments map (targ => ju.manifestToTypeTag(jm, targ)) map (_.in(jm).tpe))
- tpe.asInstanceOf[U # Type]
- case u =>
- u.manifestToTypeTag(mirror.asInstanceOf[u.Mirror], manifest).in(mirror).tpe
- }
- }
- })
-}
+ /** Creates a runtime reflection mirror from a JVM classloader.
+ *
+ * For more information about `Mirrors`s, see [[scala.reflect.api.Mirrors]] or the
+ * [[http://docs.scala-lang.org/overviews/reflection/environment-universes-mirrors.html Reflection Guide: Mirrors]]
+ *
+ * @group JavaMirrors
+ */
+ def runtimeMirror(cl: ClassLoader): Mirror
+} \ No newline at end of file
diff --git a/src/reflect/scala/reflect/api/Mirrors.scala b/src/reflect/scala/reflect/api/Mirrors.scala
index 0d39f628ce..f688001f95 100644
--- a/src/reflect/scala/reflect/api/Mirrors.scala
+++ b/src/reflect/scala/reflect/api/Mirrors.scala
@@ -62,7 +62,7 @@ package api
* The entry point to `Mirror`s for use at runtime is via `ru.runtimeMirror(<classloader>)`, where
* `ru` is [[scala.reflect.runtime.universe]].
*
- * The result of a [[scala.reflect.api.JavaMirrors#runtimeMirror]] call is a classloader mirror,
+ * The result of a [[scala.reflect.api.JavaUniverse#runtimeMirror]] call is a classloader mirror,
* of type [[scala.reflect.api.Mirrors#ReflectiveMirror]], which can load symbols by names as
* discussed above (in the “Compile-time” section).
*
diff --git a/src/reflect/scala/reflect/api/Scopes.scala b/src/reflect/scala/reflect/api/Scopes.scala
index 9327fb9762..3f926d68f2 100644
--- a/src/reflect/scala/reflect/api/Scopes.scala
+++ b/src/reflect/scala/reflect/api/Scopes.scala
@@ -34,11 +34,6 @@ trait Scopes { self: Universe =>
*/
trait ScopeApi extends Iterable[Symbol]
- /** Create a new scope with the given initial elements.
- * @group Scopes
- */
- def newScopeWith(elems: Symbol*): Scope
-
/** The type of member scopes, as in class definitions, for example.
* @template
* @group Scopes
diff --git a/src/reflect/scala/reflect/api/StandardLiftables.scala b/src/reflect/scala/reflect/api/StandardLiftables.scala
index 104215bb93..6fc00de3e5 100644
--- a/src/reflect/scala/reflect/api/StandardLiftables.scala
+++ b/src/reflect/scala/reflect/api/StandardLiftables.scala
@@ -2,7 +2,8 @@ package scala.reflect
package api
trait StandardLiftables { self: Universe =>
- import build.{SyntacticTuple, ScalaDot}
+ import internal._
+ import reificationSupport.{SyntacticTuple, ScalaDot}
trait StandardLiftableInstances {
private def lift[T: Liftable](value: T): Tree = implicitly[Liftable[T]].apply(value)
diff --git a/src/reflect/scala/reflect/api/Symbols.scala b/src/reflect/scala/reflect/api/Symbols.scala
index 9831420749..b30c6de01d 100644
--- a/src/reflect/scala/reflect/api/Symbols.scala
+++ b/src/reflect/scala/reflect/api/Symbols.scala
@@ -94,18 +94,6 @@ trait Symbols { self: Universe =>
*/
type ClassSymbol >: Null <: ClassSymbolApi with TypeSymbol
- /** The type of free terms introduced by reification.
- * @group Symbols
- * @template
- */
- type FreeTermSymbol >: Null <: FreeTermSymbolApi with TermSymbol
-
- /** The type of free types introduced by reification.
- * @group Symbols
- * @template
- */
- type FreeTypeSymbol >: Null <: FreeTypeSymbolApi with TypeSymbol
-
/** A special "missing" symbol. Commonly used in the API to denote a default or empty value.
* @group Symbols
* @template
@@ -131,12 +119,8 @@ trait Symbols { self: Universe =>
* @groupdesc Helpers These methods enable collections-like operations on symbols.
* @groupname Type TypeSymbol Members
* @groupprio Type -1
- * @groupname FreeType FreeType Symbol Members
- * @groupprio FreeType -2
* @groupname Term TermSymbol Members
* @groupprio Term -1
- * @groupname FreeTerm FreeTerm Symbol Members
- * @groupprio FreeTerm -2
* @groupname Class Class Symbol Members
* @groupprio Class -2
* @groupname Method Method Symbol Members
@@ -275,45 +259,6 @@ trait Symbols { self: Universe =>
*/
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.
- *
- * @group Tests
- */
- def isFreeTerm: Boolean = false
-
- /** This symbol cast to a free term symbol.
- * @throws ScalaReflectionException if `isFreeTerm` is false.
- *
- * @group Conversions
- */
- 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.
- *
- * @group Tests
- */
- def isFreeType: Boolean = false
-
- /** This symbol cast to a free type symbol.
- * @throws ScalaReflectionException if `isFreeType` is false.
- *
- * @group Conversions
- */
- def asFreeType: FreeTypeSymbol = throw new ScalaReflectionException(s"$this is not a free type")
-
- /** @group Constructors */
- def newTermSymbol(name: TermName, pos: Position = NoPosition, flags: FlagSet = NoFlags): TermSymbol
- /** @group Constructors */
- def newModuleAndClassSymbol(name: Name, pos: Position = NoPosition, flags: FlagSet = NoFlags): (ModuleSymbol, ClassSymbol)
- /** @group Constructors */
- def newMethodSymbol(name: TermName, pos: Position = NoPosition, flags: FlagSet = NoFlags): MethodSymbol
- /** @group Constructors */
- def newTypeSymbol(name: TypeName, pos: Position = NoPosition, flags: FlagSet = NoFlags): TypeSymbol
- /** @group Constructors */
- def newClassSymbol(name: TypeName, pos: Position = NoPosition, flags: FlagSet = NoFlags): ClassSymbol
-
/** Source file if this symbol is created during this compilation run,
* or a class file if this symbol is loaded from a *.class or *.jar.
*
@@ -470,12 +415,6 @@ trait Symbols { self: Universe =>
*/
def isPackageClass: Boolean
- /** Does this symbol or its underlying type represent a typechecking error?
- *
- * @group Tests
- */
- def isErroneous : Boolean
-
/** Is this symbol static (i.e. with no outer instance)?
* Q: When exactly is a sym marked as STATIC?
* A: If it's a member of a toplevel object, or of an object contained in a toplevel object, or any number of levels deep.
@@ -743,13 +682,6 @@ trait Symbols { self: Universe =>
*/
def isCovariant : Boolean
- /** Does this symbol represent the definition of a skolem?
- * Skolems are used during typechecking to represent type parameters viewed from inside their scopes.
- *
- * @group Type
- */
- def isSkolem : Boolean
-
/** Does this symbol represent the definition of a type alias?
*
* @group Type
@@ -952,6 +884,12 @@ trait Symbols { self: Universe =>
*/
def thisPrefix: Type
+ /** The type `C.super[M]`, where `C` is the current class and `M` is supertpe.
+ *
+ * @group Class
+ */
+ def superPrefix(supertpe: Type): Type
+
/** For a polymorphic class/trait, its type parameters, the empty list for all other classes/trait
*
* @group Class
@@ -971,44 +909,4 @@ trait Symbols { self: Universe =>
// as at the moment we don't have time or risk tolerance for that
def primaryConstructor: Symbol
}
-
- /** The API of free term symbols.
- * The main source of information about symbols is the [[Symbols]] page.
- *
- * $SYMACCESSORS
- * @group API
- */
- trait FreeTermSymbolApi extends TermSymbolApi { this: FreeTermSymbol =>
- final override def isFreeTerm = true
- final override def asFreeTerm = this
-
- /** The place where this symbol has been spawned
- *
- * @group FreeTerm
- */
- def origin: String
-
- /** The valus this symbol refers to
- *
- * @group FreeTerm
- */
- def value: Any
- }
-
- /** The API of free type symbols.
- * The main source of information about symbols is the [[Symbols]] page.
- *
- * $SYMACCESSORS
- * @group API
- */
- trait FreeTypeSymbolApi extends TypeSymbolApi { this: FreeTypeSymbol =>
- final override def isFreeType = true
- final override def asFreeType = this
-
- /** The place where this symbol has been spawned
- *
- * @group FreeType
- */
- def origin: String
- }
}
diff --git a/src/reflect/scala/reflect/api/TagInterop.scala b/src/reflect/scala/reflect/api/TagInterop.scala
deleted file mode 100644
index 51b7c519c5..0000000000
--- a/src/reflect/scala/reflect/api/TagInterop.scala
+++ /dev/null
@@ -1,44 +0,0 @@
-package scala
-package reflect
-package api
-
-/**
- * <span class="badge badge-red" style="float: right;">EXPERIMENTAL</span>
- *
- * This trait provides type tag <-> manifest interoperability.
- * @group ReflectionAPI
- *
- * @groupname TagInterop TypeTag and Manifest Interoperability
- */
-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 [[scala.reflect.api.TypeTags#TypeTag]] to a [[scala.reflect.Manifest]].
- *
- * Compiler usually generates these conversions automatically, when a type tag for a type `T` is in scope,
- * and an implicit of type `Manifest[T]` is requested, but this method can also be called manually.
- * For example:
- * {{{
- * typeTagToManifest(scala.reflect.runtime.currentMirror, implicitly[TypeTag[String]])
- * }}}
- * @group TagInterop
- */
- def typeTagToManifest[T: ClassTag](mirror: Any, tag: Universe#TypeTag[T]): Manifest[T] =
- throw new UnsupportedOperationException("This universe does not support tag -> manifest conversions. Use a JavaUniverse, e.g. the scala.reflect.runtime.universe.")
-
- /**
- * Convert a [[scala.reflect.Manifest]] to a [[scala.reflect.api.TypeTags#TypeTag]].
- *
- * Compiler usually generates these conversions automatically, when a manifest for a type `T` is in scope,
- * and an implicit of type `TypeTag[T]` is requested, but this method can also be called manually.
- * For example:
- * {{{
- * manifestToTypeTag(scala.reflect.runtime.currentMirror, implicitly[Manifest[String]])
- * }}}
- * @group TagInterop
- */
- def manifestToTypeTag[T](mirror: Any, manifest: Manifest[T]): Universe#TypeTag[T] =
- throw new UnsupportedOperationException("This universe does not support manifest -> tag conversions. Use a JavaUniverse, e.g. the scala.reflect.runtime.universe.")
-}
diff --git a/src/reflect/scala/reflect/api/Trees.scala b/src/reflect/scala/reflect/api/Trees.scala
index 45d28e3e5a..a42f6ab728 100644
--- a/src/reflect/scala/reflect/api/Trees.scala
+++ b/src/reflect/scala/reflect/api/Trees.scala
@@ -168,29 +168,6 @@ trait Trees { self: Universe =>
*/
def children: List[Tree]
- /** Extracts free term symbols from a tree that is reified or contains reified subtrees.
- */
- def freeTerms: List[FreeTermSymbol]
-
- /** Extracts free type symbols from a tree that is reified or contains reified subtrees.
- */
- def freeTypes: List[FreeTypeSymbol]
-
- /** Substitute symbols in `to` for corresponding occurrences of references to
- * symbols `from` in this type.
- */
- def substituteSymbols(from: List[Symbol], to: List[Symbol]): Tree
-
- /** Substitute types in `to` for corresponding occurrences of references to
- * symbols `from` in this tree.
- */
- def substituteTypes(from: List[Symbol], to: List[Type]): Tree
-
- /** Substitute given tree `to` for occurrences of nodes that represent
- * `C.this`, where `C` referes to the given class `clazz`.
- */
- def substituteThis(clazz: Symbol, to: Tree): Tree
-
/** Make a copy of this tree, keeping all attributes,
* except that all positions are focused (so nothing
* in this tree will be found when searching by position).
@@ -1745,60 +1722,13 @@ trait Trees { self: Universe =>
* @group API
*/
trait IdentApi extends RefTreeApi { this: Ident =>
+ /** Was this ident created from a backquoted identifier? */
+ def isBackquoted: Boolean
+
/** @inheritdoc */
def name: Name
}
- /** Marks underlying reference to id as boxed.
- *
- * <b>Precondition:<\b> 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.
- * @group Trees
- * @template
- */
- type ReferenceToBoxed >: Null <: ReferenceToBoxedApi with TermTree
-
- /** The constructor/extractor for `ReferenceToBoxed` instances.
- * @group Extractors
- */
- 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.
- * @group Extractors
- */
- abstract class ReferenceToBoxedExtractor {
- def apply(ident: Ident): ReferenceToBoxed
- def unapply(referenceToBoxed: ReferenceToBoxed): Option[Ident]
- }
-
- /** The API that all references support
- * @group API
- */
- trait ReferenceToBoxedApi extends TermTreeApi { this: ReferenceToBoxed =>
- /** The underlying reference. */
- def ident: Tree
- }
-
/** Literal
* @group Trees
* @template
@@ -2140,78 +2070,6 @@ trait Trees { self: Universe =>
// ---------------------- factories ----------------------------------------------
- /** A factory method for `ClassDef` nodes.
- * @group Factories
- */
- @deprecated("Use the canonical ClassDef constructor to create a class and then initialize its position and symbol manually", "2.10.1")
- def ClassDef(sym: Symbol, impl: Template): ClassDef
-
- /** A factory method for `ModuleDef` nodes.
- * @group Factories
- */
- @deprecated("Use the canonical ModuleDef constructor to create an object and then initialize its position and symbol manually", "2.10.1")
- def ModuleDef(sym: Symbol, impl: Template): ModuleDef
-
- /** A factory method for `ValDef` nodes.
- * @group Factories
- */
- @deprecated("Use the canonical ValDef constructor to create a val and then initialize its position and symbol manually", "2.10.1")
- def ValDef(sym: Symbol, rhs: Tree): ValDef
-
- /** A factory method for `ValDef` nodes.
- * @group Factories
- */
- @deprecated("Use the canonical ValDef constructor to create a val with an empty right-hand side and then initialize its position and symbol manually", "2.10.1")
- def ValDef(sym: Symbol): ValDef
-
- /** A factory method for `ValDef` nodes.
- * @group Factories
- */
- @deprecated("Use the canonical DefDef constructor to create a method and then initialize its position and symbol manually", "2.10.1")
- def DefDef(sym: Symbol, mods: Modifiers, vparamss: List[List[ValDef]], rhs: Tree): DefDef
-
- /** A factory method for `ValDef` nodes.
- * @group Factories
- */
- @deprecated("Use the canonical DefDef constructor to create a method and then initialize its position and symbol manually", "2.10.1")
- def DefDef(sym: Symbol, vparamss: List[List[ValDef]], rhs: Tree): DefDef
-
- /** A factory method for `ValDef` nodes.
- * @group Factories
- */
- @deprecated("Use the canonical DefDef constructor to create a method and then initialize its position and symbol manually", "2.10.1")
- def DefDef(sym: Symbol, mods: Modifiers, rhs: Tree): DefDef
-
- /** A factory method for `ValDef` nodes.
- * @group Factories
- */
- @deprecated("Use the canonical DefDef constructor to create a method and then initialize its position and symbol manually", "2.10.1")
- def DefDef(sym: Symbol, rhs: Tree): DefDef
-
- /** A factory method for `ValDef` nodes.
- * @group Factories
- */
- @deprecated("Use the canonical DefDef constructor to create a method and then initialize its position and symbol manually", "2.10.1")
- def DefDef(sym: Symbol, rhs: List[List[Symbol]] => Tree): DefDef
-
- /** A factory method for `TypeDef` nodes.
- * @group Factories
- */
- @deprecated("Use the canonical TypeDef constructor to create a type alias and then initialize its position and symbol manually", "2.10.1")
- def TypeDef(sym: Symbol, rhs: Tree): TypeDef
-
- /** A factory method for `TypeDef` nodes.
- * @group Factories
- */
- @deprecated("Use the canonical TypeDef constructor to create an abstract type or type parameter and then initialize its position and symbol manually", "2.10.1")
- def TypeDef(sym: Symbol): TypeDef
-
- /** A factory method for `LabelDef` nodes.
- * @group Factories
- */
- @deprecated("Use the canonical LabelDef constructor to create a label and then initialize its position and symbol manually", "2.10.1")
- def LabelDef(sym: Symbol, params: List[Symbol], rhs: Tree): LabelDef
-
/** A factory method for `Block` nodes.
* Flattens directly nested blocks.
* @group Factories
diff --git a/src/reflect/scala/reflect/api/Types.scala b/src/reflect/scala/reflect/api/Types.scala
index 2900b7ab3d..dd63211c32 100644
--- a/src/reflect/scala/reflect/api/Types.scala
+++ b/src/reflect/scala/reflect/api/Types.scala
@@ -393,10 +393,6 @@ trait Types {
* @group Extractors
*/
abstract class ThisTypeExtractor {
- /**
- * Creates a ThisType from the given class symbol.
- */
- def apply(sym: Symbol): Type
def unapply(tpe: ThisType): Option[Symbol]
}
@@ -432,7 +428,6 @@ trait Types {
* @group Extractors
*/
abstract class SingleTypeExtractor {
- def apply(pre: Type, sym: Symbol): Type // not SingleTypebecause of implementation details
def unapply(tpe: SingleType): Option[(Type, Symbol)]
}
@@ -469,7 +464,6 @@ trait Types {
* @group Extractors
*/
abstract class SuperTypeExtractor {
- def apply(thistpe: Type, supertpe: Type): Type // not SuperTypebecause of implementation details
def unapply(tpe: SuperType): Option[(Type, Type)]
}
@@ -509,7 +503,6 @@ trait Types {
* @group Extractors
*/
abstract class ConstantTypeExtractor {
- def apply(value: Constant): ConstantType
def unapply(tpe: ConstantType): Option[Constant]
}
@@ -549,7 +542,6 @@ trait Types {
* @group Extractors
*/
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])]
}
@@ -606,12 +598,6 @@ trait Types {
* @group Extractors
*/
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)]
}
@@ -653,7 +639,6 @@ trait Types {
* @group Extractors
*/
abstract class ClassInfoTypeExtractor {
- def apply(parents: List[Type], decls: Scope, typeSymbol: Symbol): ClassInfoType
def unapply(tpe: ClassInfoType): Option[(List[Type], Scope, Symbol)]
}
@@ -699,7 +684,6 @@ trait Types {
* @group Extractors
*/
abstract class MethodTypeExtractor {
- def apply(params: List[Symbol], resultType: Type): MethodType
def unapply(tpe: MethodType): Option[(List[Symbol], Type)]
}
@@ -732,7 +716,6 @@ trait Types {
* @group Extractors
*/
abstract class NullaryMethodTypeExtractor {
- def apply(resultType: Type): NullaryMethodType
def unapply(tpe: NullaryMethodType): Option[(Type)]
}
@@ -763,7 +746,6 @@ trait Types {
* @group Extractors
*/
abstract class PolyTypeExtractor {
- def apply(typeParams: List[Symbol], resultType: Type): PolyType
def unapply(tpe: PolyType): Option[(List[Symbol], Type)]
}
@@ -798,7 +780,6 @@ trait Types {
* @group Extractors
*/
abstract class ExistentialTypeExtractor {
- def apply(quantified: List[Symbol], underlying: Type): ExistentialType
def unapply(tpe: ExistentialType): Option[(List[Symbol], Type)]
}
@@ -833,7 +814,6 @@ trait Types {
* @group Extractors
*/
abstract class AnnotatedTypeExtractor {
- def apply(annotations: List[Annotation], underlying: Type): AnnotatedType
def unapply(tpe: AnnotatedType): Option[(List[Annotation], Type)]
}
@@ -874,7 +854,6 @@ trait Types {
* @group Extractors
*/
abstract class TypeBoundsExtractor {
- def apply(lo: Type, hi: Type): TypeBounds
def unapply(tpe: TypeBounds): Option[(Type, Type)]
}
@@ -924,7 +903,6 @@ trait Types {
* @group Extractors
*/
abstract class BoundedWildcardTypeExtractor {
- def apply(bounds: TypeBounds): BoundedWildcardType
def unapply(tpe: BoundedWildcardType): Option[TypeBounds]
}
@@ -947,74 +925,9 @@ trait Types {
*/
def glb(ts: List[Type]): Type
- // Creators ---------------------------------------------------------------
- // too useful and too non-trivial to be left out of public API
-
- /** The canonical creator for single-types
- * @group TypeCreators
- */
- def singleType(pre: Type, sym: Symbol): Type
-
- /** the canonical creator for a refined type with a given scope
- * @group TypeCreators
- */
- def refinedType(parents: List[Type], owner: Symbol, decls: Scope, pos: Position): Type
-
- /** The canonical creator for a refined type with an initially empty scope.
- * @group TypeCreators
- */
- def refinedType(parents: List[Type], owner: Symbol): Type
-
- /** The canonical creator for typerefs
- * @group TypeCreators
- */
- def typeRef(pre: Type, sym: Symbol, args: List[Type]): Type
-
- /** A creator for intersection type where intersections of a single type are
- * replaced by the type itself.
- * @group TypeCreators
- */
- def intersectionType(tps: List[Type]): Type
-
- /** A creator for intersection type where intersections of a single type are
- * replaced by the type itself, and repeated parent classes are merged.
- *
- * !!! Repeated parent classes are not merged - is this a bug in the
- * comment or in the code?
- * @group TypeCreators
- */
- def intersectionType(tps: List[Type], owner: Symbol): Type
-
/** A creator for type applications
- * @group Types
+ * @group TypeOps
*/
+ // TODO: needs a more convenient type signature, because applying types right now is quite boilerplatey
def appliedType(tycon: Type, args: List[Type]): Type
-
- /** A creator for type parameterizations that strips empty type parameter lists.
- * Use this factory method to indicate the type has kind * (it's a polymorphic value)
- * until we start tracking explicit kinds equivalent to typeFun (except that the latter requires tparams nonEmpty).
- * @group Types
- */
- def polyType(tparams: List[Symbol], tpe: Type): Type
-
- /** A creator for existential types. This generates:
- *
- * {{{
- * tpe1 where { tparams }
- * }}}
- *
- * where `tpe1` is the result of extrapolating `tpe` with regard to `tparams`.
- * Extrapolating means that type variables in `tparams` occurring
- * in covariant positions are replaced by upper bounds, (minus any
- * SingletonClass markers), type variables in `tparams` occurring in
- * contravariant positions are replaced by upper bounds, provided the
- * resulting type is legal with regard to stability, and does not contain
- * any type variable in `tparams`.
- *
- * The abstraction drops all type parameters that are not directly or
- * indirectly referenced by type `tpe1`. If there are no remaining type
- * parameters, simply returns result type `tpe`.
- * @group TypeCreators
- */
- def existentialAbstraction(tparams: List[Symbol], tpe0: Type): Type
}
diff --git a/src/reflect/scala/reflect/api/Universe.scala b/src/reflect/scala/reflect/api/Universe.scala
index 85a8ee0185..a3d1d291eb 100644
--- a/src/reflect/scala/reflect/api/Universe.scala
+++ b/src/reflect/scala/reflect/api/Universe.scala
@@ -69,17 +69,15 @@ abstract class Universe extends Symbols
with Positions
with Exprs
with TypeTags
- with TagInterop
with ImplicitTags
with StandardDefinitions
with StandardNames
with StandardLiftables
- with BuildUtils
with Mirrors
with Printers
- with Importers
with Liftables
with Quasiquotes
+ with Internals
{
/** Use `reify` to produce the abstract syntax tree representing a given Scala expression.
*
diff --git a/src/reflect/scala/reflect/internal/Definitions.scala b/src/reflect/scala/reflect/internal/Definitions.scala
index 645d6aa4ff..2567abe51d 100644
--- a/src/reflect/scala/reflect/internal/Definitions.scala
+++ b/src/reflect/scala/reflect/internal/Definitions.scala
@@ -461,6 +461,9 @@ trait Definitions extends api.StandardDefinitions {
def ReflectRuntimeUniverse = ReflectRuntimePackage.map(sym => getMemberValue(sym, nme.universe))
def ReflectRuntimeCurrentMirror = ReflectRuntimePackage.map(sym => getMemberMethod(sym, nme.currentMirror))
+ lazy val UniverseClass = getClassIfDefined("scala.reflect.api.Universe") // defined in scala-reflect.jar, so we need to be careful
+ def UniverseInternal = getMemberValue(UniverseClass, nme.internal)
+
lazy val PartialManifestModule = requiredModule[scala.reflect.ClassManifestFactory.type]
lazy val FullManifestClass = requiredClass[scala.reflect.Manifest[_]]
lazy val FullManifestModule = requiredModule[scala.reflect.ManifestFactory.type]
diff --git a/src/reflect/scala/reflect/internal/Importers.scala b/src/reflect/scala/reflect/internal/Importers.scala
index ff91b08ea1..4e205a9a90 100644
--- a/src/reflect/scala/reflect/internal/Importers.scala
+++ b/src/reflect/scala/reflect/internal/Importers.scala
@@ -7,17 +7,7 @@ import scala.ref.WeakReference
import scala.reflect.internal.Flags._
// SI-6241: move importers to a mirror
-trait Importers extends api.Importers { to: SymbolTable =>
-
- /** Attachment that knows how to import itself into another universe. */
- trait ImportableAttachment {
- def importAttachment(importer: Importer): this.type
- }
-
- /** Attachment that doesn't contain any reflection artificats and can be imported as-is. */
- trait PlainAttachment extends ImportableAttachment {
- def importAttachment(importer: Importer): this.type = this
- }
+trait Importers { to: SymbolTable =>
def mkImporter(from0: api.Universe): Importer { val from: from0.type } = (
if (to eq from0) {
diff --git a/src/reflect/scala/reflect/internal/Internals.scala b/src/reflect/scala/reflect/internal/Internals.scala
new file mode 100644
index 0000000000..3c0d5ac263
--- /dev/null
+++ b/src/reflect/scala/reflect/internal/Internals.scala
@@ -0,0 +1,125 @@
+package scala
+package reflect
+package internal
+
+import scala.language.implicitConversions
+import scala.collection.mutable.WeakHashMap
+import scala.ref.WeakReference
+import scala.reflect.api.Universe
+import scala.reflect.macros.Attachments
+import scala.reflect.internal.util.FreshNameCreator
+import scala.reflect.internal.Flags._
+import scala.reflect.internal.util.ListOfNil
+
+trait Internals extends api.Internals {
+ self: SymbolTable =>
+
+ type Internal = MacroInternalApi
+ lazy val internal: Internal = new SymbolTableInternal {}
+
+ trait SymbolTableInternal extends MacroInternalApi {
+ lazy val reificationSupport: ReificationSupportApi = self.build
+
+ def createImporter(from0: Universe): Importer { val from: from0.type } = self.mkImporter(from0)
+
+ def newScopeWith(elems: Symbol*): Scope = self.newScopeWith(elems: _*)
+
+ def freeTerms(tree: Tree): List[FreeTermSymbol] = tree.freeTerms
+ def freeTypes(tree: Tree): List[FreeTypeSymbol] = tree.freeTypes
+ def substituteSymbols(tree: Tree, from: List[Symbol], to: List[Symbol]): Tree = tree.substituteSymbols(from, to)
+ def substituteTypes(tree: Tree, from: List[Symbol], to: List[Type]): Tree = tree.substituteTypes(from, to)
+ def substituteThis(tree: Tree, clazz: Symbol, to: Tree): Tree = tree.substituteThis(clazz, to)
+ def attachments(tree: Tree): Attachments { type Pos = Position } = tree.attachments
+ def updateAttachment[T: ClassTag](tree: Tree, attachment: T): tree.type = tree.updateAttachment(attachment)
+ def removeAttachment[T: ClassTag](tree: Tree): tree.type = tree.removeAttachment[T]
+ def setPos(tree: Tree, newpos: Position): tree.type = tree.setPos(newpos)
+ def setType(tree: Tree, tp: Type): tree.type = tree.setType(tp)
+ def defineType(tree: Tree, tp: Type): tree.type = tree.defineType(tp)
+ def setSymbol(tree: Tree, sym: Symbol): tree.type = tree.setSymbol(sym)
+ def setOriginal(tt: TypeTree, tree: Tree): TypeTree = tt.setOriginal(tree)
+
+ def captureVariable(vble: Symbol): Unit = self.captureVariable(vble)
+ def referenceCapturedVariable(vble: Symbol): Tree = self.referenceCapturedVariable(vble)
+ def capturedVariableType(vble: Symbol): Type = self.capturedVariableType(vble)
+
+ def classDef(sym: Symbol, impl: Template): ClassDef = self.ClassDef(sym, impl)
+ def moduleDef(sym: Symbol, impl: Template): ModuleDef = self.ModuleDef(sym, impl)
+ def valDef(sym: Symbol, rhs: Tree): ValDef = self.ValDef(sym, rhs)
+ def valDef(sym: Symbol): ValDef = self.ValDef(sym)
+ def defDef(sym: Symbol, mods: Modifiers, vparamss: List[List[ValDef]], rhs: Tree): DefDef = self.DefDef(sym, mods, vparamss, rhs)
+ def defDef(sym: Symbol, vparamss: List[List[ValDef]], rhs: Tree): DefDef = self.DefDef(sym, vparamss, rhs)
+ def defDef(sym: Symbol, mods: Modifiers, rhs: Tree): DefDef = self.DefDef(sym, mods, rhs)
+ def defDef(sym: Symbol, rhs: Tree): DefDef = self.DefDef(sym, rhs)
+ def defDef(sym: Symbol, rhs: List[List[Symbol]] => Tree): DefDef = self.DefDef(sym, rhs)
+ def typeDef(sym: Symbol, rhs: Tree): TypeDef = self.TypeDef(sym, rhs)
+ def typeDef(sym: Symbol): TypeDef = self.TypeDef(sym)
+ def labelDef(sym: Symbol, params: List[Symbol], rhs: Tree): LabelDef = self.LabelDef(sym, params, rhs)
+
+ lazy val gen = self.treeBuild
+
+ def isFreeTerm(symbol: Symbol): Boolean = symbol.isFreeTerm
+ def asFreeTerm(symbol: Symbol): FreeTermSymbol = symbol.asFreeTerm
+ def isFreeType(symbol: Symbol): Boolean = symbol.isFreeType
+ def asFreeType(symbol: Symbol): FreeTypeSymbol = symbol.asFreeType
+ def newTermSymbol(symbol: Symbol, name: TermName, pos: Position = NoPosition, flags: FlagSet = NoFlags): TermSymbol = symbol.newTermSymbol(name, pos, flags)
+ def newModuleAndClassSymbol(symbol: Symbol, name: Name, pos: Position = NoPosition, flags: FlagSet = NoFlags): (ModuleSymbol, ClassSymbol) = symbol.newModuleAndClassSymbol(name, pos, flags)
+ def newMethodSymbol(symbol: Symbol, name: TermName, pos: Position = NoPosition, flags: FlagSet = NoFlags): MethodSymbol = symbol.newMethodSymbol(name, pos, flags)
+ def newTypeSymbol(symbol: Symbol, name: TypeName, pos: Position = NoPosition, flags: FlagSet = NoFlags): TypeSymbol = symbol.newTypeSymbol(name, pos, flags)
+ def newClassSymbol(symbol: Symbol, name: TypeName, pos: Position = NoPosition, flags: FlagSet = NoFlags): ClassSymbol = symbol.newClassSymbol(name, pos, flags)
+ def newFreeTerm(name: String, value: => Any, flags: FlagSet = NoFlags, origin: String = null): FreeTermSymbol = reificationSupport.newFreeTerm(name, value, flags, origin)
+ def newFreeType(name: String, flags: FlagSet = NoFlags, origin: String = null): FreeTypeSymbol = reificationSupport.newFreeType(name, flags, origin)
+ def isErroneous(symbol: Symbol): Boolean = symbol.isErroneous
+ def isSkolem(symbol: Symbol): Boolean = symbol.isSkolem
+ def deSkolemize(symbol: Symbol): Symbol = symbol.deSkolemize
+ def attachments(symbol: Symbol): Attachments { type Pos = Position } = symbol.attachments
+ def updateAttachment[T: ClassTag](symbol: Symbol, attachment: T): symbol.type = symbol.updateAttachment(attachment)
+ def removeAttachment[T: ClassTag](symbol: Symbol): symbol.type = symbol.removeAttachment[T]
+ def pos(symbol: Symbol): Position = symbol.pos
+ def setTypeSignature(symbol: Symbol, tpe: Type): symbol.type = symbol.setTypeSignature(tpe)
+ def setAnnotations(symbol: Symbol, annots: Annotation*): symbol.type = symbol.setAnnotations(annots: _*)
+ def setName(symbol: Symbol, name: Name): symbol.type = symbol.setName(name)
+ def setPrivateWithin(symbol: Symbol, sym: Symbol): symbol.type = symbol.setPrivateWithin(sym)
+
+ def thisType(sym: Symbol): Type = self.ThisType(sym)
+ def singleType(pre: Type, sym: Symbol): Type = self.SingleType(pre, sym)
+ def superType(thistpe: Type, supertpe: Type): Type = self.SuperType(thistpe, supertpe)
+ def constantType(value: Constant): ConstantType = self.ConstantType(value)
+ def typeRef(pre: Type, sym: Symbol, args: List[Type]): Type = self.TypeRef(pre, sym, args)
+ def refinedType(parents: List[Type], decls: Scope): RefinedType = self.RefinedType(parents, decls)
+ def refinedType(parents: List[Type], owner: Symbol): Type = self.refinedType(parents, owner)
+ def refinedType(parents: List[Type], owner: Symbol, decls: Scope): Type = self.RefinedType(parents, decls, owner)
+ def refinedType(parents: List[Type], owner: Symbol, decls: Scope, pos: Position): Type = self.refinedType(parents, owner, decls, pos)
+ def intersectionType(tps: List[Type]): Type = self.intersectionType(tps)
+ def intersectionType(tps: List[Type], owner: Symbol): Type = self.intersectionType(tps, owner)
+ def classInfoType(parents: List[Type], decls: Scope, typeSymbol: Symbol): ClassInfoType = self.ClassInfoType(parents, decls, typeSymbol)
+ def methodType(params: List[Symbol], resultType: Type): MethodType = self.MethodType(params, resultType)
+ def nullaryMethodType(resultType: Type): NullaryMethodType = self.NullaryMethodType(resultType)
+ def polyType(typeParams: List[Symbol], resultType: Type): PolyType = self.PolyType(typeParams, resultType)
+ def existentialType(quantified: List[Symbol], underlying: Type): ExistentialType = self.ExistentialType(quantified, underlying)
+ def existentialAbstraction(tparams: List[Symbol], tpe0: Type): Type = self.existentialAbstraction(tparams, tpe0)
+ def annotatedType(annotations: List[Annotation], underlying: Type): AnnotatedType = self.AnnotatedType(annotations, underlying)
+ def typeBounds(lo: Type, hi: Type): TypeBounds = self.TypeBounds(lo, hi)
+ def boundedWildcardType(bounds: TypeBounds): BoundedWildcardType = self.BoundedWildcardType(bounds)
+ }
+
+ lazy val treeBuild = new self.TreeGen {
+ def mkAttributedQualifier(tpe: Type): Tree = self.gen.mkAttributedQualifier(tpe)
+ def mkAttributedQualifier(tpe: Type, termSym: Symbol): Tree = self.gen.mkAttributedQualifier(tpe, termSym)
+ def mkAttributedRef(pre: Type, sym: Symbol): RefTree = self.gen.mkAttributedRef(pre, sym)
+ def mkAttributedRef(sym: Symbol): RefTree = self.gen.mkAttributedRef(sym)
+ def mkUnattributedRef(sym: Symbol): RefTree = self.gen.mkUnattributedRef(sym)
+ def mkUnattributedRef(fullName: Name): RefTree = self.gen.mkUnattributedRef(fullName)
+ def mkAttributedThis(sym: Symbol): This = self.gen.mkAttributedThis(sym)
+ def mkAttributedIdent(sym: Symbol): RefTree = self.gen.mkAttributedIdent(sym)
+ def mkAttributedSelect(qual: Tree, sym: Symbol): RefTree = self.gen.mkAttributedSelect(qual, sym)
+ def mkMethodCall(receiver: Symbol, methodName: Name, targs: List[Type], args: List[Tree]): Tree = self.gen.mkMethodCall(receiver, methodName, targs, args)
+ def mkMethodCall(method: Symbol, targs: List[Type], args: List[Tree]): Tree = self.gen.mkMethodCall(method, targs, args)
+ def mkMethodCall(method: Symbol, args: List[Tree]): Tree = self.gen.mkMethodCall(method, args)
+ def mkMethodCall(target: Tree, args: List[Tree]): Tree = self.gen.mkMethodCall(target, args)
+ def mkMethodCall(receiver: Symbol, methodName: Name, args: List[Tree]): Tree = self.gen.mkMethodCall(receiver, methodName, args)
+ def mkMethodCall(receiver: Tree, method: Symbol, targs: List[Type], args: List[Tree]): Tree = self.gen.mkMethodCall(receiver, method, targs, args)
+ def mkMethodCall(target: Tree, targs: List[Type], args: List[Tree]): Tree = self.gen.mkMethodCall(target, targs, args)
+ def mkNullaryCall(method: Symbol, targs: List[Type]): Tree = self.gen.mkNullaryCall(method, targs)
+ def mkRuntimeUniverseRef: Tree = self.gen.mkRuntimeUniverseRef
+ }
+} \ No newline at end of file
diff --git a/src/reflect/scala/reflect/internal/BuildUtils.scala b/src/reflect/scala/reflect/internal/ReificationSupport.scala
index c5581601de..00ed9fb963 100644
--- a/src/reflect/scala/reflect/internal/BuildUtils.scala
+++ b/src/reflect/scala/reflect/internal/ReificationSupport.scala
@@ -5,10 +5,11 @@ package internal
import Flags._
import util._
-trait BuildUtils { self: SymbolTable =>
+trait ReificationSupport { self: SymbolTable =>
import definitions.{TupleClass, FunctionClass, ScalaPackage, UnitClass}
+ import internal._
- class BuildImpl extends BuildApi {
+ class ReificationSupportImpl extends ReificationSupportApi {
def selectType(owner: Symbol, name: String): TypeSymbol =
select(owner, newTypeName(name)).asType
@@ -41,6 +42,9 @@ trait BuildUtils { self: SymbolTable =>
def newNestedSymbol(owner: Symbol, name: Name, pos: Position, flags: Long, isClass: Boolean): Symbol =
owner.newNestedSymbol(name, pos, flags, isClass).markFlagsCompleted(mask = AllFlags)
+ def newScopeWith(elems: Symbol*): Scope =
+ self.newScopeWith(elems: _*)
+
def setAnnotations[S <: Symbol](sym: S, annots: List[AnnotationInfo]): S =
sym.setAnnotations(annots)
@@ -55,6 +59,34 @@ trait BuildUtils { self: SymbolTable =>
def TypeTree(tp: Type): TypeTree = self.TypeTree(tp)
+ def ThisType(sym: Symbol): Type = self.ThisType(sym)
+
+ def SingleType(pre: Type, sym: Symbol): Type = self.SingleType(pre, sym)
+
+ def SuperType(thistpe: Type, supertpe: Type): Type = self.SuperType(thistpe, supertpe)
+
+ def ConstantType(value: Constant): ConstantType = self.ConstantType(value)
+
+ def TypeRef(pre: Type, sym: Symbol, args: List[Type]): Type = self.TypeRef(pre, sym, args)
+
+ def RefinedType(parents: List[Type], decls: Scope, typeSymbol: Symbol): RefinedType = self.RefinedType(parents, decls, typeSymbol)
+
+ def ClassInfoType(parents: List[Type], decls: Scope, typeSymbol: Symbol): ClassInfoType = self.ClassInfoType(parents, decls, typeSymbol)
+
+ def MethodType(params: List[Symbol], resultType: Type): MethodType = self.MethodType(params, resultType)
+
+ def NullaryMethodType(resultType: Type): NullaryMethodType = self.NullaryMethodType(resultType)
+
+ def PolyType(typeParams: List[Symbol], resultType: Type): PolyType = self.PolyType(typeParams, resultType)
+
+ def ExistentialType(quantified: List[Symbol], underlying: Type): ExistentialType = self.ExistentialType(quantified, underlying)
+
+ def AnnotatedType(annotations: List[Annotation], underlying: Type): AnnotatedType = self.AnnotatedType(annotations, underlying)
+
+ def TypeBounds(lo: Type, hi: Type): TypeBounds = self.TypeBounds(lo, hi)
+
+ def BoundedWildcardType(bounds: TypeBounds): BoundedWildcardType = self.BoundedWildcardType(bounds)
+
def thisPrefix(sym: Symbol): Type = sym.thisPrefix
def setType[T <: Tree](tree: T, tpe: Type): T = { tree.setType(tpe); tree }
@@ -911,5 +943,5 @@ trait BuildUtils { self: SymbolTable =>
}
}
- val build: BuildImpl = new BuildImpl
+ val build = new ReificationSupportImpl
}
diff --git a/src/reflect/scala/reflect/internal/StdAttachments.scala b/src/reflect/scala/reflect/internal/StdAttachments.scala
index 139a79ffe1..614e71b597 100644
--- a/src/reflect/scala/reflect/internal/StdAttachments.scala
+++ b/src/reflect/scala/reflect/internal/StdAttachments.scala
@@ -22,6 +22,16 @@ trait StdAttachments {
def setPos(newpos: Position): this.type = { pos = newpos; this }
}
+ /** Attachment that knows how to import itself into another universe. */
+ trait ImportableAttachment {
+ def importAttachment(importer: Importer): this.type
+ }
+
+ /** Attachment that doesn't contain any reflection artificats and can be imported as-is. */
+ trait PlainAttachment extends ImportableAttachment {
+ def importAttachment(importer: Importer): this.type = this
+ }
+
/** Stores the trees that give rise to a refined type to be used in reification.
* Unfortunately typed `CompoundTypeTree` is lacking essential info, and the reifier cannot use `CompoundTypeTree.tpe`.
* Therefore we need this hack (see `Reshape.toPreTyperTypeTree` for a detailed explanation).
diff --git a/src/reflect/scala/reflect/internal/StdNames.scala b/src/reflect/scala/reflect/internal/StdNames.scala
index 01df1d6003..192735805d 100644
--- a/src/reflect/scala/reflect/internal/StdNames.scala
+++ b/src/reflect/scala/reflect/internal/StdNames.scala
@@ -321,7 +321,7 @@ trait StdNames {
val FAKE_LOCAL_THIS: NameType = "this$"
val LAZY_LOCAL: NameType = "$lzy"
val LAZY_SLOW_SUFFIX: NameType = "$lzycompute"
- val UNIVERSE_BUILD_PREFIX: NameType = "$u.build."
+ val UNIVERSE_BUILD_PREFIX: NameType = "$u.internal.reificationSupport."
val UNIVERSE_PREFIX: NameType = "$u."
val UNIVERSE_SHORT: NameType = "$u"
val MIRROR_PREFIX: NameType = "$m."
@@ -577,9 +577,11 @@ trait StdNames {
val AnyVal: NameType = "AnyVal"
val Apply: NameType = "Apply"
val ArrayAnnotArg: NameType = "ArrayAnnotArg"
+ val ClassInfoType: NameType = "ClassInfoType"
val ConstantType: NameType = "ConstantType"
val EmptyPackage: NameType = "EmptyPackage"
val EmptyPackageClass: NameType = "EmptyPackageClass"
+ val ExistentialType: NameType = "ExistentialType"
val Flag : NameType = "Flag"
val FlagsRepr: NameType = "FlagsRepr"
val Ident: NameType = "Ident"
@@ -587,6 +589,7 @@ trait StdNames {
val Import: NameType = "Import"
val Literal: NameType = "Literal"
val LiteralAnnotArg: NameType = "LiteralAnnotArg"
+ val MethodType: NameType = "MethodType"
val Modifiers: NameType = "Modifiers"
val NestedAnnotArg: NameType = "NestedAnnotArg"
val New: NameType = "New"
@@ -595,11 +598,16 @@ trait StdNames {
val NoMods: NameType = "NoMods"
val Nothing: NameType = "Nothing"
val Null: NameType = "Null"
+ val NullaryMethodType: NameType = "NullaryMethodType"
val Object: NameType = "Object"
+ val PolyType: NameType = "PolyType"
+ val RefinedType: NameType = "RefinedType"
val RootPackage: NameType = "RootPackage"
val RootClass: NameType = "RootClass"
val Select: NameType = "Select"
val SelectFromTypeTree: NameType = "SelectFromTypeTree"
+ val SingleType: NameType = "SingleType"
+ val SuperType: NameType = "SuperType"
val SyntacticApplied: NameType = "SyntacticApplied"
val SyntacticAssign: NameType = "SyntacticAssign"
val SyntacticBlock: NameType = "SyntacticBlock"
@@ -630,6 +638,7 @@ trait StdNames {
val ThisType: NameType = "ThisType"
val Tuple2: NameType = "Tuple2"
val TYPE_ : NameType = "TYPE"
+ val TypeBounds: NameType = "TypeBounds"
val TypeRef: NameType = "TypeRef"
val TypeTree: NameType = "TypeTree"
val UNIT : NameType = "UNIT"
@@ -653,7 +662,6 @@ trait StdNames {
val asInstanceOf_ : NameType = "asInstanceOf"
val asInstanceOf_Ob : NameType = "$asInstanceOf"
val box: NameType = "box"
- val build : NameType = "build"
val bytes: NameType = "bytes"
val c: NameType = "c"
val canEqual_ : NameType = "canEqual"
@@ -695,6 +703,7 @@ trait StdNames {
val immutable: NameType = "immutable"
val implicitly: NameType = "implicitly"
val in: NameType = "in"
+ val internal: NameType = "internal"
val inlinedEquals: NameType = "inlinedEquals"
val isArray: NameType = "isArray"
val isDefinedAt: NameType = "isDefinedAt"
@@ -735,6 +744,7 @@ trait StdNames {
val productPrefix: NameType = "productPrefix"
val readResolve: NameType = "readResolve"
val reify : NameType = "reify"
+ val reificationSupport : NameType = "reificationSupport"
val rootMirror : NameType = "rootMirror"
val runtime: NameType = "runtime"
val runtimeClass: NameType = "runtimeClass"
diff --git a/src/reflect/scala/reflect/internal/SymbolTable.scala b/src/reflect/scala/reflect/internal/SymbolTable.scala
index 802bd18a4e..e50c65c9ca 100644
--- a/src/reflect/scala/reflect/internal/SymbolTable.scala
+++ b/src/reflect/scala/reflect/internal/SymbolTable.scala
@@ -11,6 +11,7 @@ import scala.annotation.elidable
import scala.collection.{ mutable, immutable }
import util._
import java.util.concurrent.TimeUnit
+import scala.reflect.internal.{TreeGen => InternalTreeGen}
abstract class SymbolTable extends macros.Universe
with Collections
@@ -40,14 +41,14 @@ abstract class SymbolTable extends macros.Universe
with CapturedVariables
with StdAttachments
with StdCreators
- with BuildUtils
+ with ReificationSupport
with PrivateWithin
with pickling.Translations
with FreshNames
+ with Internals
{
- val gen = new TreeGen { val global: SymbolTable.this.type = SymbolTable.this }
- lazy val treeBuild = gen
+ val gen = new InternalTreeGen { val global: SymbolTable.this.type = SymbolTable.this }
def log(msg: => AnyRef): Unit
def warning(msg: String): Unit = Console.err.println(msg)
diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala
index 63a69e2797..c4fc450a78 100644
--- a/src/reflect/scala/reflect/internal/Symbols.scala
+++ b/src/reflect/scala/reflect/internal/Symbols.scala
@@ -79,9 +79,14 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
def symbolOf[T: WeakTypeTag]: TypeSymbol = weakTypeOf[T].typeSymbolDirect.asType
- abstract class SymbolContextApiImpl extends SymbolContextApi {
+ abstract class SymbolContextApiImpl extends SymbolApi {
this: Symbol =>
+ def isFreeTerm: Boolean = false
+ def asFreeTerm: FreeTermSymbol = throw new ScalaReflectionException(s"$this is not a free term")
+ def isFreeType: Boolean = false
+ def asFreeType: FreeTypeSymbol = throw new ScalaReflectionException(s"$this is not a free type")
+
def isExistential: Boolean = this.isExistentiallyBound
def isParamWithDefault: Boolean = this.hasDefault
// `isByNameParam` is only true for a call-by-name parameter of a *method*,
@@ -115,6 +120,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
def baseClasses = info.baseClasses
def module = sourceModule
def thisPrefix: Type = thisType
+ def superPrefix(supertpe: Type): Type = SuperType(thisType, supertpe)
// automatic full initialization on access to info from reflection API is a double-edged sword
// on the one hand, it's convenient so that the users don't have to deal with initialization themselves before printing out stuff
@@ -3366,11 +3372,16 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
def origin: String
}
class FreeTermSymbol(name0: TermName, value0: => Any, val origin: String) extends TermSymbol(NoSymbol, NoPosition, name0) with FreeSymbol with FreeTermSymbolApi {
+ final override def isFreeTerm = true
+ final override def asFreeTerm = this
def value = value0
}
implicit val FreeTermSymbolTag = ClassTag[FreeTermSymbol](classOf[FreeTermSymbol])
- class FreeTypeSymbol(name0: TypeName, val origin: String) extends TypeSkolem(NoSymbol, NoPosition, name0, NoSymbol) with FreeSymbol with FreeTypeSymbolApi
+ class FreeTypeSymbol(name0: TypeName, val origin: String) extends TypeSkolem(NoSymbol, NoPosition, name0, NoSymbol) with FreeSymbol with FreeTypeSymbolApi {
+ final override def isFreeType = true
+ final override def asFreeType = this
+ }
implicit val FreeTypeSymbolTag = ClassTag[FreeTypeSymbol](classOf[FreeTypeSymbol])
/** An object representing a missing symbol */
diff --git a/src/reflect/scala/reflect/internal/TreeGen.scala b/src/reflect/scala/reflect/internal/TreeGen.scala
index 9de5c1a7ea..e8e57f9eb3 100644
--- a/src/reflect/scala/reflect/internal/TreeGen.scala
+++ b/src/reflect/scala/reflect/internal/TreeGen.scala
@@ -6,7 +6,7 @@ import Flags._
import util._
import scala.collection.mutable.ListBuffer
-abstract class TreeGen extends macros.TreeBuilder {
+abstract class TreeGen {
val global: SymbolTable
import global._
diff --git a/src/reflect/scala/reflect/internal/Trees.scala b/src/reflect/scala/reflect/internal/Trees.scala
index 3b84ef6aeb..42952e5d80 100644
--- a/src/reflect/scala/reflect/internal/Trees.scala
+++ b/src/reflect/scala/reflect/internal/Trees.scala
@@ -99,7 +99,7 @@ trait Trees extends api.Trees {
(duplicator transform this).asInstanceOf[this.type]
}
- abstract class TreeContextApiImpl extends TreeContextApi { this: Tree =>
+ abstract class TreeContextApiImpl extends TreeApi { this: Tree =>
override def orElse(alt: => Tree) = if (!isEmpty) this else alt
@@ -158,8 +158,8 @@ trait Trees extends api.Trees {
productIterator.toList flatMap subtrees
}
- override def freeTerms: List[FreeTermSymbol] = freeSyms[FreeTermSymbol](_.isFreeTerm, _.termSymbol)
- override def freeTypes: List[FreeTypeSymbol] = freeSyms[FreeTypeSymbol](_.isFreeType, _.typeSymbol)
+ def freeTerms: List[FreeTermSymbol] = freeSyms[FreeTermSymbol](_.isFreeTerm, _.termSymbol)
+ def freeTypes: List[FreeTypeSymbol] = freeSyms[FreeTypeSymbol](_.isFreeType, _.typeSymbol)
private def freeSyms[S <: Symbol](isFree: Symbol => Boolean, symOfType: Type => Symbol): List[S] = {
val s = mutable.LinkedHashSet[S]()
@@ -175,13 +175,13 @@ trait Trees extends api.Trees {
s.toList
}
- override def substituteSymbols(from: List[Symbol], to: List[Symbol]): Tree =
+ def substituteSymbols(from: List[Symbol], to: List[Symbol]): Tree =
new TreeSymSubstituter(from, to)(this)
- override def substituteTypes(from: List[Symbol], to: List[Type]): Tree =
+ def substituteTypes(from: List[Symbol], to: List[Type]): Tree =
new TreeTypeSubstituter(from, to)(this)
- override def substituteThis(clazz: Symbol, to: Tree): Tree =
+ def substituteThis(clazz: Symbol, to: Tree): Tree =
new ThisSubstituter(clazz, to) transform this
def hasExistingSymbol = (symbol ne null) && (symbol ne NoSymbol)
@@ -235,7 +235,7 @@ trait Trees extends api.Trees {
trait TypTree extends Tree with TypTreeApi
- abstract class SymTree extends Tree with SymTreeContextApi {
+ abstract class SymTree extends Tree with SymTreeApi {
override def hasSymbolField = true
override var symbol: Symbol = NoSymbol
}
@@ -488,7 +488,7 @@ trait Trees extends api.Trees {
}
object Select extends SelectExtractor
- case class Ident(name: Name) extends RefTree with IdentContextApi {
+ case class Ident(name: Name) extends RefTree with IdentApi {
def qualifier: Tree = EmptyTree
def isBackquoted = this.hasAttachment[BackquotedIdentifierAttachment.type]
}
@@ -545,7 +545,7 @@ trait Trees extends api.Trees {
extends TypTree with ExistentialTypeTreeApi
object ExistentialTypeTree extends ExistentialTypeTreeExtractor
- case class TypeTree() extends TypTree with TypeTreeContextApi {
+ case class TypeTree() extends TypTree with TypeTreeApi {
private var orig: Tree = null
/** Was this type tree originally empty? That is, does it now contain
* an inferred type that must be forgotten in `resetAttrs` to
@@ -1849,8 +1849,8 @@ trait Trees extends api.Trees {
implicit val NameTreeTag = ClassTag[NameTree](classOf[NameTree])
implicit val NewTag = ClassTag[New](classOf[New])
implicit val PackageDefTag = ClassTag[PackageDef](classOf[PackageDef])
- implicit val RefTreeTag = ClassTag[RefTree](classOf[RefTree])
implicit val ReferenceToBoxedTag = ClassTag[ReferenceToBoxed](classOf[ReferenceToBoxed])
+ implicit val RefTreeTag = ClassTag[RefTree](classOf[RefTree])
implicit val ReturnTag = ClassTag[Return](classOf[Return])
implicit val SelectFromTypeTreeTag = ClassTag[SelectFromTypeTree](classOf[SelectFromTypeTree])
implicit val SelectTag = ClassTag[Select](classOf[Select])
diff --git a/src/reflect/scala/reflect/macros/Reifiers.scala b/src/reflect/scala/reflect/macros/Reifiers.scala
index ff1f7a3b28..e35a5c8622 100644
--- a/src/reflect/scala/reflect/macros/Reifiers.scala
+++ b/src/reflect/scala/reflect/macros/Reifiers.scala
@@ -15,7 +15,7 @@ trait Reifiers {
* For more information and examples see the documentation for `Universe.reify`.
*
* The produced tree will be bound to the specified `universe` and `mirror`.
- * Possible values for `universe` include `universe.treeBuild.mkRuntimeUniverseRef`.
+ * Possible values for `universe` include `universe.internal.gen.mkRuntimeUniverseRef`.
* Possible values for `mirror` include `EmptyTree` (in that case the reifier will automatically pick an appropriate mirror).
*
* This function is deeply connected to `Universe.reify`, a macro that reifies arbitrary expressions into runtime trees.
diff --git a/src/reflect/scala/reflect/macros/TreeBuilder.scala b/src/reflect/scala/reflect/macros/TreeBuilder.scala
deleted file mode 100644
index 7f57274347..0000000000
--- a/src/reflect/scala/reflect/macros/TreeBuilder.scala
+++ /dev/null
@@ -1,97 +0,0 @@
-package scala
-package reflect
-package macros
-
-/**
- * <span class="badge badge-red" style="float: right;">EXPERIMENTAL</span>
- *
- * A helper available in [[scala.reflect.macros.Universe]] that defines shorthands for the
- * most common tree-creating functions.
- */
-@deprecated("Use quasiquotes instead", "2.11.0")
-abstract class TreeBuilder {
- val global: Universe
-
- import global._
-
- /** Builds a reference to value whose type is given stable prefix.
- * The type must be suitable for this. For example, it
- * must not be a TypeRef pointing to an abstract type variable.
- */
- @deprecated("Use quasiquotes instead", "2.11.0")
- def mkAttributedQualifier(tpe: Type): Tree
-
- /** Builds a reference to value whose type is given stable prefix.
- * If the type is unsuitable, e.g. it is a TypeRef for an
- * abstract type variable, then an Ident will be made using
- * termSym as the Ident's symbol. In that case, termSym must
- * not be NoSymbol.
- */
- @deprecated("Use quasiquotes instead", "2.11.0")
- def mkAttributedQualifier(tpe: Type, termSym: Symbol): Tree
-
- /** Builds a typed reference to given symbol with given stable prefix. */
- @deprecated("Use quasiquotes instead", "2.11.0")
- def mkAttributedRef(pre: Type, sym: Symbol): RefTree
-
- /** Builds a typed reference to given symbol. */
- @deprecated("Use quasiquotes instead", "2.11.0")
- def mkAttributedRef(sym: Symbol): RefTree
-
- /** Builds an untyped reference to given symbol. Requires the symbol to be static. */
- @deprecated("Use quasiquotes instead", "2.11.0")
- def mkUnattributedRef(sym: Symbol): RefTree
-
- /** Builds an untyped reference to symbol with given name. Requires the symbol to be static. */
- @deprecated("Use quasiquotes instead", "2.11.0")
- def mkUnattributedRef(fullName: Name): RefTree
-
- /** Builds a typed This reference to given symbol. */
- @deprecated("Use quasiquotes instead", "2.11.0")
- def mkAttributedThis(sym: Symbol): This
-
- /** Builds a typed Ident with an underlying symbol. */
- @deprecated("Use quasiquotes instead", "2.11.0")
- def mkAttributedIdent(sym: Symbol): RefTree
-
- /** Builds a typed Select with an underlying symbol. */
- @deprecated("Use quasiquotes instead", "2.11.0")
- def mkAttributedSelect(qual: Tree, sym: Symbol): RefTree
-
- /** A creator for method calls, e.g. fn[T1, T2, ...](v1, v2, ...)
- * There are a number of variations.
- *
- * @param receiver symbol of the method receiver
- * @param methodName name of the method to call
- * @param targs type arguments (if Nil, no TypeApply node will be generated)
- * @param args value arguments
- * @return the newly created trees.
- */
- @deprecated("Use quasiquotes instead", "2.11.0")
- def mkMethodCall(receiver: Symbol, methodName: Name, targs: List[Type], args: List[Tree]): Tree
-
- @deprecated("Use quasiquotes instead", "2.11.0")
- def mkMethodCall(method: Symbol, targs: List[Type], args: List[Tree]): Tree
-
- @deprecated("Use quasiquotes instead", "2.11.0")
- def mkMethodCall(method: Symbol, args: List[Tree]): Tree
-
- @deprecated("Use quasiquotes instead", "2.11.0")
- def mkMethodCall(target: Tree, args: List[Tree]): Tree
-
- @deprecated("Use quasiquotes instead", "2.11.0")
- def mkMethodCall(receiver: Symbol, methodName: Name, args: List[Tree]): Tree
-
- @deprecated("Use quasiquotes instead", "2.11.0")
- def mkMethodCall(receiver: Tree, method: Symbol, targs: List[Type], args: List[Tree]): Tree
-
- @deprecated("Use quasiquotes instead", "2.11.0")
- def mkMethodCall(target: Tree, targs: List[Type], args: List[Tree]): Tree
-
- @deprecated("Use quasiquotes instead", "2.11.0")
- def mkNullaryCall(method: Symbol, targs: List[Type]): Tree
-
- /** A tree that refers to the runtime reflexive universe, `scala.reflect.runtime.universe`. */
- @deprecated("Use quasiquotes instead", "2.11.0")
- def mkRuntimeUniverseRef: Tree
-}
diff --git a/src/reflect/scala/reflect/macros/Universe.scala b/src/reflect/scala/reflect/macros/Universe.scala
index bc5c8b2840..17eb17cee3 100644
--- a/src/reflect/scala/reflect/macros/Universe.scala
+++ b/src/reflect/scala/reflect/macros/Universe.scala
@@ -2,6 +2,8 @@ package scala
package reflect
package macros
+import scala.language.implicitConversions
+
/**
* <span class="badge badge-red" style="float: right;">EXPERIMENTAL</span>
*
@@ -17,109 +19,63 @@ package macros
*/
abstract class Universe extends scala.reflect.api.Universe {
- /** A factory that encapsulates common tree-building functions.
- * @group Macros
- */
- @deprecated("Use quasiquotes instead", "2.11.0")
- val treeBuild: TreeBuilder { val global: Universe.this.type }
+ /** @inheritdoc */
+ override type Internal <: MacroInternalApi
- /** The API of reflection artifacts that support [[scala.reflect.macros.Attachments]].
- * These artifacts are trees and symbols.
- * @group Macros
- */
- trait AttachableApi {
- /** The attachment of the reflection artifact. */
- def attachments: Attachments { type Pos = Position }
+ /** @inheritdoc */
+ trait MacroInternalApi extends InternalApi {
+
+ /** Advanced tree factories */
+ val gen: TreeGen
+
+ /** The attachment of the symbol. */
+ def attachments(symbol: Symbol): Attachments { type Pos = Position }
/** Updates the attachment with the payload slot of T added/updated with the provided value.
* Replaces an existing payload of the same type, if exists.
- * Returns the reflection artifact itself.
+ * Returns the symbol itself.
*/
- def updateAttachment[T: ClassTag](attachment: T): AttachableApi.this.type
+ def updateAttachment[T: ClassTag](symbol: Symbol, attachment: T): symbol.type
/** Update the attachment with the payload of the given class type `T` removed.
- * Returns the reflection artifact itself.
- */
- def removeAttachment[T: ClassTag]: AttachableApi.this.type
- }
-
- // Symbol extensions ---------------------------------------------------------------
-
- /** The `Symbol` API is extended for macros: See [[SymbolContextApi]] for details.
- *
- * @group Macros
- */
- override type Symbol >: Null <: SymbolContextApi
-
- /** The extended API of symbols that's supported in macro context universes
- * @group API
- */
- trait SymbolContextApi extends SymbolApi with AttachableApi { self: Symbol =>
-
- /** If this symbol is a skolem, its corresponding type parameter, otherwise the symbol itself.
- *
- * [[https://groups.google.com/forum/#!msg/scala-internals/0j8laVNTQsI/kRXMF_c8bGsJ To quote Martin Odersky]],
- * skolems are synthetic type "constants" that are copies of existentially bound or universally
- * bound type variables. E.g. if one is inside the right-hand side of a method:
- *
- * {{{
- * def foo[T](x: T) = ... foo[List[T]]....
- * }}}
- *
- * the skolem named `T` refers to the unknown type instance of `T` when `foo` is called. It needs to be different
- * from the type parameter because in a recursive call as in the `foo[List[T]]` above the type parameter gets
- * substituted with `List[T]`, but the ''type skolem'' stays what it is.
- *
- * The other form of skolem is an ''existential skolem''. Say one has a function
- *
- * {{{
- * def bar(xs: List[T] forSome { type T }) = xs.head
- * }}}
- *
- * then each occurrence of `xs` on the right will have type `List[T']` where `T'` is a fresh copy of `T`.
+ * Returns the symbol itself.
*/
- def deSkolemize: Symbol
+ def removeAttachment[T: ClassTag](symbol: Symbol): symbol.type
/** The position of this symbol. */
- def pos: Position
+ def pos(symbol: Symbol): Position
/** Sets the `typeSignature` of the symbol. */
- def setTypeSignature(tpe: Type): Symbol
+ def setTypeSignature(symbol: Symbol, tpe: Type): symbol.type
/** Sets the `annotations` of the symbol. */
- def setAnnotations(annots: Annotation*): Symbol
+ def setAnnotations(symbol: Symbol, annots: Annotation*): symbol.type
/** Sets the `name` of the symbol. */
- def setName(name: Name): Symbol
+ def setName(symbol: Symbol, name: Name): symbol.type
/** Sets the `privateWithin` of the symbol. */
- def setPrivateWithin(sym: Symbol): Symbol
- }
+ def setPrivateWithin(symbol: Symbol, sym: Symbol): symbol.type
- // Tree extensions ---------------------------------------------------------------
+ /** The attachment of the tree. */
+ def attachments(tree: Tree): Attachments { type Pos = Position }
- /** The `Tree` API is extended for macros: See [[TreeContextApi]] for details.
- *
- * @group Macros
- */
- override type Tree >: Null <: TreeContextApi
-
- /** The extended API of trees that's supported in macro context universes
- * @group API
- */
- trait TreeContextApi extends TreeApi with AttachableApi { self: Tree =>
+ /** Updates the attachment with the payload slot of T added/updated with the provided value.
+ * Replaces an existing payload of the same type, if exists.
+ * Returns the tree itself.
+ */
+ def updateAttachment[T: ClassTag](tree: Tree, attachment: T): tree.type
- /** Sets the `pos` of the tree. Returns `Unit`. */
- def pos_=(pos: Position): Unit
+ /** Update the attachment with the payload of the given class type `T` removed.
+ * Returns the tree itself.
+ */
+ def removeAttachment[T: ClassTag](tree: Tree): tree.type
/** Sets the `pos` of the tree. Returns the tree itself. */
- def setPos(newpos: Position): Tree
-
- /** Sets the `tpe` of the tree. Returns `Unit`. */
- @deprecated("Use setType", "2.11.0") def tpe_=(t: Type): Unit
+ def setPos(tree: Tree, newpos: Position): tree.type
/** Sets the `tpe` of the tree. Returns the tree itself. */
- def setType(tp: Type): Tree
+ def setType(tree: Tree, tp: Type): tree.type
/** Like `setType`, but if this is a previously empty TypeTree that
* fact is remembered so that `untypecheck` will snap back.
@@ -139,63 +95,96 @@ abstract class Universe extends scala.reflect.api.Universe {
* and therefore should be abandoned if the current line of type
* inquiry doesn't work out.
*/
- def defineType(tp: Type): Tree
-
- /** Sets the `symbol` of the tree. Returns `Unit`. */
- def symbol_=(sym: Symbol): Unit
+ def defineType(tree: Tree, tp: Type): tree.type
/** Sets the `symbol` of the tree. Returns the tree itself. */
- def setSymbol(sym: Symbol): Tree
- }
+ def setSymbol(tree: Tree, sym: Symbol): tree.type
- /** @inheritdoc */
- override type SymTree >: Null <: Tree with SymTreeContextApi
+ /** Sets the `original` field of the type tree. */
+ def setOriginal(tt: TypeTree, original: Tree): TypeTree
- /** The extended API of sym trees that's supported in macro context universes
- * @group API
- */
- trait SymTreeContextApi extends SymTreeApi { this: SymTree =>
- /** Sets the `symbol` field of the sym tree. */
- var symbol: Symbol
- }
+ /** Mark a variable as captured; i.e. force boxing in a *Ref type.
+ * @group Macros
+ */
+ def captureVariable(vble: Symbol): Unit
- /** @inheritdoc */
- override type TypeTree >: Null <: TypTree with TypeTreeContextApi
+ /** Mark given identifier as a reference to a captured variable itself
+ * suppressing dereferencing with the `elem` field.
+ * @group Macros
+ */
+ def referenceCapturedVariable(vble: Symbol): Tree
- /** The extended API of sym trees that's supported in macro context universes
- * @group API
- */
- trait TypeTreeContextApi extends TypeTreeApi { this: TypeTree =>
- /** Sets the `original` field of the type tree. */
- def setOriginal(tree: Tree): this.type
+ /** Convert type of a captured variable to *Ref type.
+ * @group Macros
+ */
+ def capturedVariableType(vble: Symbol): Type
}
- /** @inheritdoc */
- override type Ident >: Null <: RefTree with IdentContextApi
+ /** @group Internal */
+ trait TreeGen {
+ /** Builds a reference to value whose type is given stable prefix.
+ * The type must be suitable for this. For example, it
+ * must not be a TypeRef pointing to an abstract type variable.
+ */
+ def mkAttributedQualifier(tpe: Type): Tree
- /** The extended API of idents that's supported in macro context universes
- * @group API
- */
- trait IdentContextApi extends IdentApi { this: Ident =>
- /** Was this ident created from a backquoted identifier? */
- def isBackquoted: Boolean
- }
+ /** Builds a reference to value whose type is given stable prefix.
+ * If the type is unsuitable, e.g. it is a TypeRef for an
+ * abstract type variable, then an Ident will be made using
+ * termSym as the Ident's symbol. In that case, termSym must
+ * not be NoSymbol.
+ */
+ def mkAttributedQualifier(tpe: Type, termSym: Symbol): Tree
- /** Mark a variable as captured; i.e. force boxing in a *Ref type.
- * @group Macros
- */
- def captureVariable(vble: Symbol): Unit
+ /** Builds a typed reference to given symbol with given stable prefix. */
+ def mkAttributedRef(pre: Type, sym: Symbol): RefTree
- /** Mark given identifier as a reference to a captured variable itself
- * suppressing dereferencing with the `elem` field.
- * @group Macros
- */
- def referenceCapturedVariable(vble: Symbol): Tree
+ /** Builds a typed reference to given symbol. */
+ def mkAttributedRef(sym: Symbol): RefTree
- /** Convert type of a captured variable to *Ref type.
- * @group Macros
- */
- def capturedVariableType(vble: Symbol): Type
+ /** Builds an untyped reference to given symbol. Requires the symbol to be static. */
+ def mkUnattributedRef(sym: Symbol): RefTree
+
+ /** Builds an untyped reference to symbol with given name. Requires the symbol to be static. */
+ def mkUnattributedRef(fullName: Name): RefTree
+
+ /** Builds a typed This reference to given symbol. */
+ def mkAttributedThis(sym: Symbol): This
+
+ /** Builds a typed Ident with an underlying symbol. */
+ def mkAttributedIdent(sym: Symbol): RefTree
+
+ /** Builds a typed Select with an underlying symbol. */
+ def mkAttributedSelect(qual: Tree, sym: Symbol): RefTree
+
+ /** A creator for method calls, e.g. fn[T1, T2, ...](v1, v2, ...)
+ * There are a number of variations.
+ *
+ * @param receiver symbol of the method receiver
+ * @param methodName name of the method to call
+ * @param targs type arguments (if Nil, no TypeApply node will be generated)
+ * @param args value arguments
+ * @return the newly created trees.
+ */
+ def mkMethodCall(receiver: Symbol, methodName: Name, targs: List[Type], args: List[Tree]): Tree
+
+ def mkMethodCall(method: Symbol, targs: List[Type], args: List[Tree]): Tree
+
+ def mkMethodCall(method: Symbol, args: List[Tree]): Tree
+
+ def mkMethodCall(target: Tree, args: List[Tree]): Tree
+
+ def mkMethodCall(receiver: Symbol, methodName: Name, args: List[Tree]): Tree
+
+ def mkMethodCall(receiver: Tree, method: Symbol, targs: List[Type], args: List[Tree]): Tree
+
+ def mkMethodCall(target: Tree, targs: List[Type], args: List[Tree]): Tree
+
+ def mkNullaryCall(method: Symbol, targs: List[Type]): Tree
+
+ /** A tree that refers to the runtime reflexive universe, `scala.reflect.runtime.universe`. */
+ def mkRuntimeUniverseRef: Tree
+ }
/** The type of compilation runs.
* @see [[scala.reflect.macros.Enclosures]]
diff --git a/src/reflect/scala/reflect/runtime/JavaUniverse.scala b/src/reflect/scala/reflect/runtime/JavaUniverse.scala
index 85c56bc4bb..b5446694ed 100644
--- a/src/reflect/scala/reflect/runtime/JavaUniverse.scala
+++ b/src/reflect/scala/reflect/runtime/JavaUniverse.scala
@@ -2,18 +2,22 @@ package scala
package reflect
package runtime
+import scala.reflect.internal.{TreeInfo, SomePhase}
+import scala.reflect.internal.{SymbolTable => InternalSymbolTable}
+import scala.reflect.runtime.{SymbolTable => RuntimeSymbolTable}
+import scala.reflect.api.{TreeCreator, TypeCreator, Universe}
+
/** An implementation of [[scala.reflect.api.Universe]] for runtime reflection using JVM classloaders.
*
* Should not be instantiated directly, use [[scala.reflect.runtime.universe]] instead.
*
* @contentDiagram hideNodes "*Api" "*Extractor"
*/
-class JavaUniverse extends internal.SymbolTable with JavaUniverseForce with ReflectSetup with runtime.SymbolTable { self =>
+class JavaUniverse extends InternalSymbolTable with JavaUniverseForce with ReflectSetup with RuntimeSymbolTable { self =>
override def inform(msg: String): Unit = log(msg)
- def picklerPhase = internal.SomePhase
- def erasurePhase = internal.SomePhase
-
+ def picklerPhase = SomePhase
+ def erasurePhase = SomePhase
lazy val settings = new Settings
private val isLogging = sys.props contains "scala.debug.reflect"
@@ -26,10 +30,38 @@ class JavaUniverse extends internal.SymbolTable with JavaUniverseForce with Refl
def currentFreshNameCreator = globalFreshNameCreator
+ override lazy val internal: Internal = new SymbolTableInternal {
+ override def typeTagToManifest[T: ClassTag](mirror0: Any, tag: Universe # TypeTag[T]): Manifest[T] = {
+ // SI-6239: make this conversion more precise
+ val mirror = mirror0.asInstanceOf[Mirror]
+ val runtimeClass = mirror.runtimeClass(tag.in(mirror).tpe)
+ Manifest.classType(runtimeClass).asInstanceOf[Manifest[T]]
+ }
+ override def manifestToTypeTag[T](mirror0: Any, manifest: Manifest[T]): Universe # TypeTag[T] =
+ TypeTag(mirror0.asInstanceOf[Mirror], new TypeCreator {
+ def apply[U <: Universe with Singleton](mirror: scala.reflect.api.Mirror[U]): U # Type = {
+ mirror.universe match {
+ case ju: JavaUniverse =>
+ val jm = mirror.asInstanceOf[ju.Mirror]
+ val sym = jm.classSymbol(manifest.runtimeClass)
+ val tpe =
+ if (manifest.typeArguments.isEmpty) sym.toType
+ else {
+ val tags = manifest.typeArguments map (targ => ju.internal.manifestToTypeTag(jm, targ))
+ ju.appliedType(sym.toTypeConstructor, tags map (_.in(jm).tpe))
+ }
+ tpe.asInstanceOf[U # Type]
+ case u =>
+ u.internal.manifestToTypeTag(mirror.asInstanceOf[u.Mirror], manifest).in(mirror).tpe
+ }
+ }
+ })
+ }
+
// can't put this in runtime.Trees since that's mixed with Global in ReflectGlobal, which has the definition from internal.Trees
object treeInfo extends {
val global: JavaUniverse.this.type = JavaUniverse.this
- } with internal.TreeInfo
+ } with TreeInfo
init()
diff --git a/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala b/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala
index 0fcf215580..be8a2865d3 100644
--- a/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala
+++ b/src/reflect/scala/reflect/runtime/JavaUniverseForce.scala
@@ -26,11 +26,12 @@ trait JavaUniverseForce { self: runtime.JavaUniverse =>
TypeTag.Null.tpe
this.settings
+ this.internal
this.treeInfo
this.rootMirror
- this.treeBuild
this.traceSymbols
this.perRunCaches
+ this.treeBuild
this.FreshNameExtractor
this.FixedMirrorTreeCreator
this.FixedMirrorTypeCreator
@@ -279,6 +280,7 @@ trait JavaUniverseForce { self: runtime.JavaUniverse =>
definitions.ReflectPackage
definitions.ReflectApiPackage
definitions.ReflectRuntimePackage
+ definitions.UniverseClass
definitions.PartialManifestModule
definitions.FullManifestClass
definitions.FullManifestModule