From 9930b559fe657d517abeb3e4e4ffb3a2a6e00ee0 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 3 Oct 2012 23:24:03 +0200 Subject: turns on documentation of scala.reflect.runtime We definitely need to document scala.reflect.runtime.universe, therefore adding scala.reflect.runtime to skipPackages was a mistake. But then we need to make a bunch of internal classes private to reflect or to scala. Not very pretty, but it works. --- src/reflect/scala/reflect/runtime/JavaMirrors.scala | 6 +++--- src/reflect/scala/reflect/runtime/ReflectionUtils.scala | 2 +- src/reflect/scala/reflect/runtime/Settings.scala | 2 +- src/reflect/scala/reflect/runtime/SymbolLoaders.scala | 2 +- src/reflect/scala/reflect/runtime/SymbolTable.scala | 2 +- src/reflect/scala/reflect/runtime/SynchronizedOps.scala | 2 +- src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala | 2 +- src/reflect/scala/reflect/runtime/SynchronizedTypes.scala | 2 +- src/reflect/scala/reflect/runtime/package.scala | 2 +- 9 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/reflect/scala/reflect/runtime/JavaMirrors.scala b/src/reflect/scala/reflect/runtime/JavaMirrors.scala index b6b2537dc4..b917eac779 100644 --- a/src/reflect/scala/reflect/runtime/JavaMirrors.scala +++ b/src/reflect/scala/reflect/runtime/JavaMirrors.scala @@ -24,7 +24,7 @@ import scala.language.existentials import scala.runtime.{ScalaRunTime, BoxesRunTime} import scala.reflect.internal.util.Collections._ -trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { thisUniverse: SymbolTable => +private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { thisUniverse: SymbolTable => private lazy val mirrors = new WeakHashMap[ClassLoader, WeakReference[JavaMirror]]() @@ -1279,6 +1279,6 @@ trait JavaMirrors extends internal.SymbolTable with api.JavaUniverse { thisUnive } } -class ReflectError(msg: String) extends java.lang.Error(msg) +private[reflect] class ReflectError(msg: String) extends java.lang.Error(msg) -class HasJavaClass[J](val getClazz: J => java.lang.Class[_]) +private[reflect] class HasJavaClass[J](val getClazz: J => java.lang.Class[_]) diff --git a/src/reflect/scala/reflect/runtime/ReflectionUtils.scala b/src/reflect/scala/reflect/runtime/ReflectionUtils.scala index 44d9d94a46..73425bae55 100644 --- a/src/reflect/scala/reflect/runtime/ReflectionUtils.scala +++ b/src/reflect/scala/reflect/runtime/ReflectionUtils.scala @@ -10,7 +10,7 @@ import java.lang.reflect.{ Method, InvocationTargetException, UndeclaredThrowabl /** A few java-reflection oriented utility functions useful during reflection bootstrapping. */ -object ReflectionUtils { +private[scala] object ReflectionUtils { // Unwraps some chained exceptions which arise during reflective calls. def unwrapThrowable(x: Throwable): Throwable = x match { case _: InvocationTargetException | // thrown by reflectively invoked method or constructor diff --git a/src/reflect/scala/reflect/runtime/Settings.scala b/src/reflect/scala/reflect/runtime/Settings.scala index da4f4fbda1..0e0cf3fc40 100644 --- a/src/reflect/scala/reflect/runtime/Settings.scala +++ b/src/reflect/scala/reflect/runtime/Settings.scala @@ -7,7 +7,7 @@ import scala.reflect.internal.settings.MutableSettings * This should be refined, so that settings are settable via command * line options or properties. */ -class Settings extends MutableSettings { +private[reflect] class Settings extends MutableSettings { trait Setting extends SettingValue { } diff --git a/src/reflect/scala/reflect/runtime/SymbolLoaders.scala b/src/reflect/scala/reflect/runtime/SymbolLoaders.scala index d1be73bed3..61663f6181 100644 --- a/src/reflect/scala/reflect/runtime/SymbolLoaders.scala +++ b/src/reflect/scala/reflect/runtime/SymbolLoaders.scala @@ -5,7 +5,7 @@ import internal.Flags import java.lang.{Class => jClass, Package => jPackage} import scala.collection.mutable -trait SymbolLoaders { self: SymbolTable => +private[reflect] trait SymbolLoaders { self: SymbolTable => /** The standard completer for top-level classes * @param clazz The top-level class diff --git a/src/reflect/scala/reflect/runtime/SymbolTable.scala b/src/reflect/scala/reflect/runtime/SymbolTable.scala index 73632be965..5c08e9a508 100644 --- a/src/reflect/scala/reflect/runtime/SymbolTable.scala +++ b/src/reflect/scala/reflect/runtime/SymbolTable.scala @@ -8,7 +8,7 @@ import scala.reflect.internal.Flags._ * It can be used either from a reflexive universe (class scala.reflect.runtime.JavaUniverse), or else from * a runtime compiler that uses reflection to get a class information (class scala.tools.reflect.ReflectGlobal) */ -trait SymbolTable extends internal.SymbolTable with JavaMirrors with SymbolLoaders with SynchronizedOps { +private[scala] trait SymbolTable extends internal.SymbolTable with JavaMirrors with SymbolLoaders with SynchronizedOps { def info(msg: => String) = if (settings.verbose.value) println("[reflect-compiler] "+msg) diff --git a/src/reflect/scala/reflect/runtime/SynchronizedOps.scala b/src/reflect/scala/reflect/runtime/SynchronizedOps.scala index 1a17dd12d2..7b280e59b9 100644 --- a/src/reflect/scala/reflect/runtime/SynchronizedOps.scala +++ b/src/reflect/scala/reflect/runtime/SynchronizedOps.scala @@ -2,7 +2,7 @@ package scala.reflect package runtime // SI-6240: test thread-safety, make trees synchronized as well -trait SynchronizedOps extends internal.SymbolTable +private[reflect] trait SynchronizedOps extends internal.SymbolTable with SynchronizedSymbols with SynchronizedTypes { self: SymbolTable => diff --git a/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala b/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala index 3c2885a9f4..950718267a 100644 --- a/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala +++ b/src/reflect/scala/reflect/runtime/SynchronizedSymbols.scala @@ -3,7 +3,7 @@ package runtime import scala.reflect.io.AbstractFile -trait SynchronizedSymbols extends internal.Symbols { self: SymbolTable => +private[reflect] trait SynchronizedSymbols extends internal.Symbols { self: SymbolTable => override protected def nextId() = synchronized { super.nextId() } diff --git a/src/reflect/scala/reflect/runtime/SynchronizedTypes.scala b/src/reflect/scala/reflect/runtime/SynchronizedTypes.scala index 9b4d8d1d48..a3e7c28ca4 100644 --- a/src/reflect/scala/reflect/runtime/SynchronizedTypes.scala +++ b/src/reflect/scala/reflect/runtime/SynchronizedTypes.scala @@ -7,7 +7,7 @@ import java.lang.ref.WeakReference /** This trait overrides methods in reflect.internal, bracketing * them in synchronized { ... } to make them thread-safe */ -trait SynchronizedTypes extends internal.Types { self: SymbolTable => +private[reflect] trait SynchronizedTypes extends internal.Types { self: SymbolTable => // No sharing of map objects: override protected def commonOwnerMap = new CommonOwnerMap diff --git a/src/reflect/scala/reflect/runtime/package.scala b/src/reflect/scala/reflect/runtime/package.scala index 7b9f69e657..278629adb6 100644 --- a/src/reflect/scala/reflect/runtime/package.scala +++ b/src/reflect/scala/reflect/runtime/package.scala @@ -11,7 +11,7 @@ package object runtime { } package runtime { - object Macros { + private[scala] object Macros { def currentMirror(c: scala.reflect.macros.Context): c.Expr[universe.Mirror] = { import c.universe._ val runtimeClass = c.reifyEnclosingRuntimeClass -- cgit v1.2.3 From 1b2415865984071036c5f61e82a4a7048d4d18ee Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 3 Oct 2012 23:06:12 +0200 Subject: renames macros.ParseError to ParseException Because it's not a fatal error. Neither it should subclass Throwable. --- src/compiler/scala/reflect/macros/runtime/Parsers.scala | 2 +- src/reflect/scala/reflect/macros/Parsers.scala | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/reflect/macros/runtime/Parsers.scala b/src/compiler/scala/reflect/macros/runtime/Parsers.scala index ab9b94ec9f..566bcde73d 100644 --- a/src/compiler/scala/reflect/macros/runtime/Parsers.scala +++ b/src/compiler/scala/reflect/macros/runtime/Parsers.scala @@ -19,6 +19,6 @@ trait Parsers { } catch { case ToolBoxError(msg, cause) => // todo. provide a position - throw new ParseError(universe.NoPosition, msg) + throw new ParseException(universe.NoPosition, msg) } } diff --git a/src/reflect/scala/reflect/macros/Parsers.scala b/src/reflect/scala/reflect/macros/Parsers.scala index c2d4d8a3ab..d3aabcff0d 100644 --- a/src/reflect/scala/reflect/macros/Parsers.scala +++ b/src/reflect/scala/reflect/macros/Parsers.scala @@ -10,5 +10,6 @@ trait Parsers { def parse(code: String): Tree } -// should be path-dependent, otherwise exception handling becomes a mess -case class ParseError(val pos: scala.reflect.api.Position, val msg: String) extends Throwable(msg) +/** Indicates an error during [[scala.reflect.macros.Parsers#Parse]]. + */ +case class ParseException(val pos: scala.reflect.api.Position, val msg: String) extends Exception(msg) -- cgit v1.2.3 From 992d255e2fc1ca487a60e38196ec4aa952617b92 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 3 Oct 2012 23:09:42 +0200 Subject: renames macros.TypeError to TypecheckException Again, this is not a fatal error, so it should end with an Error, and it should subclass not Throwable, but Exception. Also moved the exception outside the cake to simplify error handling, along the same lines of what've been done for parsing and reification exceptions. --- .../scala/reflect/macros/runtime/Typers.scala | 10 ++------- src/compiler/scala/reflect/reify/Taggers.scala | 6 ++--- src/reflect/scala/reflect/macros/Typers.scala | 26 ++++++++++++---------- .../run/macro-typecheck-implicitsdisabled.check | 2 +- 4 files changed, 20 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/reflect/macros/runtime/Typers.scala b/src/compiler/scala/reflect/macros/runtime/Typers.scala index 9fa8567ada..be70181126 100644 --- a/src/compiler/scala/reflect/macros/runtime/Typers.scala +++ b/src/compiler/scala/reflect/macros/runtime/Typers.scala @@ -25,7 +25,7 @@ trait Typers { result case error @ universe.analyzer.SilentTypeError(_) => macroLogVerbose(error.err.errMsg) - if (!silent) throw new universe.TypeError(error.err.errPos, error.err.errMsg) + if (!silent) throw new TypecheckException(error.err.errPos, error.err.errMsg) universe.EmptyTree }) } @@ -49,19 +49,13 @@ trait Typers { wrapper(universe.analyzer.inferImplicit(tree, pt, reportAmbiguous = true, isView = isView, context = context, saveAmbiguousDivergent = !silent, pos = pos)) match { case failure if failure.tree.isEmpty => macroLogVerbose("implicit search has failed. to find out the reason, turn on -Xlog-implicits") - if (context.hasErrors) throw new universe.TypeError(context.errBuffer.head.errPos, context.errBuffer.head.errMsg) + if (context.hasErrors) throw new TypecheckException(context.errBuffer.head.errPos, context.errBuffer.head.errMsg) universe.EmptyTree case success => success.tree } } - type TypeError = universe.TypeError - - object TypeError extends TypeErrorExtractor { - def unapply(error: TypeError): Option[(Position, String)] = Some((error.pos, error.msg)) - } - def resetAllAttrs(tree: Tree): Tree = universe.resetAllAttrs(tree) def resetLocalAttrs(tree: Tree): Tree = universe.resetLocalAttrs(tree) diff --git a/src/compiler/scala/reflect/reify/Taggers.scala b/src/compiler/scala/reflect/reify/Taggers.scala index 7db6394734..513ce020cc 100644 --- a/src/compiler/scala/reflect/reify/Taggers.scala +++ b/src/compiler/scala/reflect/reify/Taggers.scala @@ -1,6 +1,6 @@ package scala.reflect.reify -import scala.reflect.macros.{ReificationError, UnexpectedReificationError} +import scala.reflect.macros.{ReificationError, UnexpectedReificationError, TypecheckException} import scala.reflect.macros.runtime.Context abstract class Taggers { @@ -65,13 +65,13 @@ abstract class Taggers { translatingReificationErrors(materializer) } try c.typeCheck(result) - catch { case terr @ c.TypeError(pos, msg) => failTag(result, terr) } + catch { case terr @ TypecheckException(pos, msg) => failTag(result, terr) } } def materializeExpr(universe: Tree, mirror: Tree, expr: Tree): Tree = { val result = translatingReificationErrors(c.reifyTree(universe, mirror, expr)) try c.typeCheck(result) - catch { case terr @ c.TypeError(pos, msg) => failExpr(result, terr) } + catch { case terr @ TypecheckException(pos, msg) => failExpr(result, terr) } } private def translatingReificationErrors(materializer: => Tree): Tree = { diff --git a/src/reflect/scala/reflect/macros/Typers.scala b/src/reflect/scala/reflect/macros/Typers.scala index eef6507418..9c4854f89f 100644 --- a/src/reflect/scala/reflect/macros/Typers.scala +++ b/src/reflect/scala/reflect/macros/Typers.scala @@ -24,11 +24,11 @@ trait Typers { * Unlike `enclosingImplicits`, this is a def, which means that it gets recalculated on every invocation, * so it might change depending on what is going on during macro expansion. */ - def openImplicits: List[(Type, Tree)] + def openImplicits: List[(Type, Tree)] /** Typechecks the provided tree against the expected type `pt` in the macro callsite context. * - * If `silent` is false, `TypeError` will be thrown in case of a typecheck error. + * If `silent` is false, `TypecheckException` will be thrown in case of a typecheck error. * If `silent` is true, the typecheck is silent and will return `EmptyTree` if an error occurs. * Such errors don't vanish and can be inspected by turning on -Ymacro-debug-verbose. * Unlike in `inferImplicitValue` and `inferImplicitView`, `silent` is false by default. @@ -36,26 +36,32 @@ trait Typers { * Typechecking can be steered with the following optional parameters: * `withImplicitViewsDisabled` recursively prohibits implicit views (though, implicit vals will still be looked up and filled in), default value is false * `withMacrosDisabled` recursively prohibits macro expansions and macro-based implicits, default value is false + * + * @throws [[scala.reflect.macros.TypecheckException]] */ def typeCheck(tree: Tree, pt: Type = WildcardType, silent: Boolean = false, withImplicitViewsDisabled: Boolean = false, withMacrosDisabled: Boolean = false): Tree /** Infers an implicit value of the expected type `pt` in the macro callsite context. * Optional `pos` parameter provides a position that will be associated with the implicit search. * - * If `silent` is false, `TypeError` will be thrown in case of an inference error. + * If `silent` is false, `TypecheckException` will be thrown in case of an inference error. * If `silent` is true, the typecheck is silent and will return `EmptyTree` if an error occurs. * Such errors don't vanish and can be inspected by turning on -Xlog-implicits. * Unlike in `typeCheck`, `silent` is true by default. + * + * @throws [[scala.reflect.macros.TypecheckException]] */ def inferImplicitValue(pt: Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: Position = enclosingPosition): Tree /** Infers an implicit view from the provided tree `tree` of the type `from` to the type `to` in the macro callsite context. * Optional `pos` parameter provides a position that will be associated with the implicit search. * - * If `silent` is false, `TypeError` will be thrown in case of an inference error. + * If `silent` is false, `TypecheckException` will be thrown in case of an inference error. * If `silent` is true, the typecheck is silent and will return `EmptyTree` if an error occurs. * Such errors don't vanish and can be inspected by turning on -Xlog-implicits. * Unlike in `typeCheck`, `silent` is true by default. + * + * @throws [[scala.reflect.macros.TypecheckException]] */ def inferImplicitView(tree: Tree, from: Type, to: Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: Position = enclosingPosition): Tree @@ -72,12 +78,8 @@ trait Typers { * For more info, read up https://issues.scala-lang.org/browse/SI-5464. */ def resetLocalAttrs(tree: Tree): Tree +} - /** Represents an error during typechecking - */ - type TypeError <: Throwable - val TypeError: TypeErrorExtractor - abstract class TypeErrorExtractor { - def unapply(error: TypeError): Option[(Position, String)] - } -} \ No newline at end of file +/** Indicates an error during one of the methods in [[scala.reflect.macros.Typers]]. + */ +case class TypecheckException(val pos: scala.reflect.api.Position, val msg: String) extends Exception(msg) diff --git a/test/files/run/macro-typecheck-implicitsdisabled.check b/test/files/run/macro-typecheck-implicitsdisabled.check index 6cf25076a7..c4fa2c5c28 100644 --- a/test/files/run/macro-typecheck-implicitsdisabled.check +++ b/test/files/run/macro-typecheck-implicitsdisabled.check @@ -1,2 +1,2 @@ scala.this.Predef.any2ArrowAssoc[Int](1).->[Int](2) -scala.reflect.internal.Types$TypeError: value -> is not a member of Int +scala.reflect.macros.TypecheckException: value -> is not a member of Int -- cgit v1.2.3 From fb515bca0549cbc84a40b23889d1f038bcb0ef3a Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 3 Oct 2012 23:13:04 +0200 Subject: renames macros.ReificationError to ReificationException And again, this is not a fatal error, so it should end with an Error, and it should subclass not Throwable, but Exception. --- src/compiler/scala/reflect/reify/Errors.scala | 22 +++++++++++----------- src/compiler/scala/reflect/reify/Reifier.scala | 10 +++++----- src/compiler/scala/reflect/reify/Taggers.scala | 6 +++--- src/compiler/scala/reflect/reify/package.scala | 4 ++-- .../scala/tools/reflect/MacroImplementations.scala | 2 +- src/compiler/scala/tools/util/PathResolver.scala | 2 +- src/reflect/scala/reflect/macros/Reifiers.scala | 12 ++++++++++-- 7 files changed, 33 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/reflect/reify/Errors.scala b/src/compiler/scala/reflect/reify/Errors.scala index 73c13901b6..c25112941c 100644 --- a/src/compiler/scala/reflect/reify/Errors.scala +++ b/src/compiler/scala/reflect/reify/Errors.scala @@ -1,7 +1,7 @@ package scala.reflect.reify -import scala.reflect.macros.ReificationError -import scala.reflect.macros.UnexpectedReificationError +import scala.reflect.macros.ReificationException +import scala.reflect.macros.UnexpectedReificationException trait Errors { self: Reifier => @@ -19,17 +19,17 @@ trait Errors { def CannotReifyType(tpe: Type) = { val msg = "implementation restriction: cannot reify type %s (%s)".format(tpe, tpe.kind) - throw new ReificationError(defaultErrorPosition, msg) + throw new ReificationException(defaultErrorPosition, msg) } def CannotReifySymbol(sym: Symbol) = { val msg = "implementation restriction: cannot reify symbol %s (%s)".format(sym, sym.accurateKindString) - throw new ReificationError(defaultErrorPosition, msg) + throw new ReificationException(defaultErrorPosition, msg) } def CannotReifyWeakType(details: Any) = { val msg = "cannot create a TypeTag" + details - throw new ReificationError(defaultErrorPosition, msg) + throw new ReificationException(defaultErrorPosition, msg) } def CannotConvertManifestToTagWithoutScalaReflect(tpe: Type, manifestInScope: Tree) = { @@ -37,7 +37,7 @@ trait Errors { |to create a type tag here, it is necessary to interoperate with the manifest `$manifestInScope` in scope. |however manifest -> typetag conversion requires Scala reflection, which is not present on the classpath. |to proceed put scala-reflect.jar on your compilation classpath and recompile.""".trim.stripMargin - throw new ReificationError(defaultErrorPosition, msg) + throw new ReificationException(defaultErrorPosition, msg) } def CannotReifyRuntimeSplice(tree: Tree) = { @@ -46,7 +46,7 @@ trait Errors { |cross-stage evaluations need to be invoked explicitly, so we're showing you this error. |if you're sure this is not an oversight, add scala-compiler.jar to the classpath, |import `scala.tools.reflect.Eval` and call `.eval` instead.""".trim.stripMargin - throw new ReificationError(tree.pos, msg) + throw new ReificationException(tree.pos, msg) } // unexpected errors: these can never happen under normal conditions unless there's a bug in the compiler (or in a compiler plugin or in a macro) @@ -54,21 +54,21 @@ trait Errors { def CannotReifyUntypedPrefix(prefix: Tree) = { val msg = "internal error: untyped prefixes are not supported, consider typechecking the prefix before passing it to the reifier" - throw new UnexpectedReificationError(defaultErrorPosition, msg) + throw new UnexpectedReificationException(defaultErrorPosition, msg) } def CannotReifyUntypedReifee(reifee: Any) = { val msg = "internal error: untyped trees are not supported, consider typechecking the reifee before passing it to the reifier" - throw new UnexpectedReificationError(defaultErrorPosition, msg) + throw new UnexpectedReificationException(defaultErrorPosition, msg) } def CannotReifyErroneousPrefix(prefix: Tree) = { val msg = "internal error: erroneous prefixes are not supported, make sure that your prefix has typechecked successfully before passing it to the reifier" - throw new UnexpectedReificationError(defaultErrorPosition, msg) + throw new UnexpectedReificationException(defaultErrorPosition, msg) } def CannotReifyErroneousReifee(reifee: Any) = { val msg = "internal error: erroneous reifees are not supported, make sure that your reifee has typechecked successfully before passing it to the reifier" - throw new UnexpectedReificationError(defaultErrorPosition, msg) + throw new UnexpectedReificationException(defaultErrorPosition, msg) } } diff --git a/src/compiler/scala/reflect/reify/Reifier.scala b/src/compiler/scala/reflect/reify/Reifier.scala index f48fcd8ada..47669f57b0 100644 --- a/src/compiler/scala/reflect/reify/Reifier.scala +++ b/src/compiler/scala/reflect/reify/Reifier.scala @@ -1,8 +1,8 @@ package scala.reflect.reify import scala.tools.nsc.Global -import scala.reflect.macros.ReificationError -import scala.reflect.macros.UnexpectedReificationError +import scala.reflect.macros.ReificationException +import scala.reflect.macros.UnexpectedReificationException import scala.reflect.reify.utils.Utils /** Given a tree or a type, generate a tree that when executed at runtime produces the original tree or type. @@ -132,12 +132,12 @@ abstract class Reifier extends States untyped } catch { - case ex: ReificationError => + case ex: ReificationException => throw ex - case ex: UnexpectedReificationError => + case ex: UnexpectedReificationException => throw ex case ex: Throwable => - throw new UnexpectedReificationError(defaultErrorPosition, "reification crashed", ex) + throw new UnexpectedReificationException(defaultErrorPosition, "reification crashed", ex) } } } \ No newline at end of file diff --git a/src/compiler/scala/reflect/reify/Taggers.scala b/src/compiler/scala/reflect/reify/Taggers.scala index 513ce020cc..cbaee41890 100644 --- a/src/compiler/scala/reflect/reify/Taggers.scala +++ b/src/compiler/scala/reflect/reify/Taggers.scala @@ -1,6 +1,6 @@ package scala.reflect.reify -import scala.reflect.macros.{ReificationError, UnexpectedReificationError, TypecheckException} +import scala.reflect.macros.{ReificationException, UnexpectedReificationException, TypecheckException} import scala.reflect.macros.runtime.Context abstract class Taggers { @@ -77,10 +77,10 @@ abstract class Taggers { private def translatingReificationErrors(materializer: => Tree): Tree = { try materializer catch { - case ReificationError(pos, msg) => + case ReificationException(pos, msg) => c.error(pos.asInstanceOf[c.Position], msg) // this cast is a very small price for the sanity of exception handling EmptyTree - case UnexpectedReificationError(pos, err, cause) if cause != null => + case UnexpectedReificationException(pos, err, cause) if cause != null => throw cause } } diff --git a/src/compiler/scala/reflect/reify/package.scala b/src/compiler/scala/reflect/reify/package.scala index 5a23ab7214..55f8684df2 100644 --- a/src/compiler/scala/reflect/reify/package.scala +++ b/src/compiler/scala/reflect/reify/package.scala @@ -1,7 +1,7 @@ package scala.reflect import scala.language.implicitConversions -import scala.reflect.macros.{Context, ReificationError, UnexpectedReificationError} +import scala.reflect.macros.{Context, ReificationException, UnexpectedReificationException} import scala.tools.nsc.Global package object reify { @@ -53,7 +53,7 @@ package object reify { if (tpe.isSpliceable) { val classTagInScope = typer0.resolveClassTag(enclosingMacroPosition, tpe, allowMaterialization = false) if (!classTagInScope.isEmpty) return Select(classTagInScope, nme.runtimeClass) - if (concrete) throw new ReificationError(enclosingMacroPosition, "tpe %s is an unresolved spliceable type".format(tpe)) + if (concrete) throw new ReificationException(enclosingMacroPosition, "tpe %s is an unresolved spliceable type".format(tpe)) } tpe.normalize match { diff --git a/src/compiler/scala/tools/reflect/MacroImplementations.scala b/src/compiler/scala/tools/reflect/MacroImplementations.scala index 48a4811744..86cd845c54 100644 --- a/src/compiler/scala/tools/reflect/MacroImplementations.scala +++ b/src/compiler/scala/tools/reflect/MacroImplementations.scala @@ -1,6 +1,6 @@ package scala.tools.reflect -import scala.reflect.macros.{ReificationError, UnexpectedReificationError} +import scala.reflect.macros.{ReificationException, UnexpectedReificationException} import scala.reflect.macros.runtime.Context import scala.collection.mutable.ListBuffer import scala.collection.mutable.Stack diff --git a/src/compiler/scala/tools/util/PathResolver.scala b/src/compiler/scala/tools/util/PathResolver.scala index f6dc92f96e..7cf3586d3d 100644 --- a/src/compiler/scala/tools/util/PathResolver.scala +++ b/src/compiler/scala/tools/util/PathResolver.scala @@ -195,7 +195,7 @@ class PathResolver(settings: Settings, context: JavaContext) { def scalaExtDirs = cmdLineOrElse("extdirs", Defaults.scalaExtDirs) /** Scaladoc doesn't need any bootstrapping, otherwise will create errors such as: * [scaladoc] ../scala-trunk/src/reflect/scala/reflect/macros/Reifiers.scala:89: error: object api is not a member of package reflect - * [scaladoc] case class ReificationError(val pos: reflect.api.PositionApi, val msg: String) extends Throwable(msg) + * [scaladoc] case class ReificationException(val pos: reflect.api.PositionApi, val msg: String) extends Throwable(msg) * [scaladoc] ^ * because the bootstrapping will look at the sourcepath and create package "reflect" in "" * and then when typing relative names, instead of picking .scala.relect, typedIdentifier will pick up the diff --git a/src/reflect/scala/reflect/macros/Reifiers.scala b/src/reflect/scala/reflect/macros/Reifiers.scala index ed31663c68..0022a488b9 100644 --- a/src/reflect/scala/reflect/macros/Reifiers.scala +++ b/src/reflect/scala/reflect/macros/Reifiers.scala @@ -76,6 +76,14 @@ trait Reifiers { // made these guys non path-dependent, otherwise exception handling quickly becomes a mess -case class ReificationError(val pos: scala.reflect.api.Position, val msg: String) extends Throwable(msg) +/** Indicates an expected error during one of the `reifyXXX` methods in [[scala.reflect.macros.Reifiers]]. + * Such errors represent one of the standard ways for reification to go wrong, e.g. + * an attempt to create a `TypeTag` from a weak type. + */ +case class ReificationException(val pos: scala.reflect.api.Position, val msg: String) extends Exception(msg) -case class UnexpectedReificationError(val pos: scala.reflect.api.Position, val msg: String, val cause: Throwable = null) extends Throwable(msg, cause) +/** Indicates an unexpected expected error during one of the `reifyXXX` methods in [[scala.reflect.macros.Reifiers]]. + * Such errors wrap random crashes in reification logic and are distinguished from expected [[scala.reflect.macros.ReificationException]]s + * so that the latter can be reported as compilation errors, while the former manifest themselves as compiler crashes. + */ +case class UnexpectedReificationException(val pos: scala.reflect.api.Position, val msg: String, val cause: Throwable = null) extends Exception(msg, cause) -- cgit v1.2.3 From d6bbf9bb9c8d0bd74abe47a1c2f4be66e0c19c03 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 3 Oct 2012 23:15:24 +0200 Subject: removes EmptyTermName and EmptyTypeName We have nme.EMPTY and tpnme.EMPTY for that. --- src/compiler/scala/reflect/reify/utils/SymbolTables.scala | 2 +- src/reflect/scala/reflect/api/Names.scala | 8 -------- src/reflect/scala/reflect/api/Trees.scala | 4 ++-- .../files/run/macro-reflective-mamd-normal-mi/Macros_Test_2.scala | 2 +- 4 files changed, 4 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/reflect/reify/utils/SymbolTables.scala b/src/compiler/scala/reflect/reify/utils/SymbolTables.scala index 3ec43c863d..dbb0836e0a 100644 --- a/src/compiler/scala/reflect/reify/utils/SymbolTables.scala +++ b/src/compiler/scala/reflect/reify/utils/SymbolTables.scala @@ -28,7 +28,7 @@ trait SymbolTables { symtab.get(sym) match { case Some(FreeDef(_, name, _, _, _)) => name case Some(SymDef(_, name, _, _)) => name - case None => EmptyTermName + case None => nme.EMPTY } def symAliases(sym: Symbol): List[TermName] = diff --git a/src/reflect/scala/reflect/api/Names.scala b/src/reflect/scala/reflect/api/Names.scala index e8665ca736..6cb226c32f 100644 --- a/src/reflect/scala/reflect/api/Names.scala +++ b/src/reflect/scala/reflect/api/Names.scala @@ -75,12 +75,4 @@ trait Names { /** Creates a new type name. */ def newTypeName(s: String): TypeName - - /** Wraps the empty string. Can be used as the null object for term name. - */ - def EmptyTermName: TermName = newTermName("") - - /** Wraps the empty string. Can be used as the null object for type name. - */ - def EmptyTypeName: TypeName = EmptyTermName.toTypeName } diff --git a/src/reflect/scala/reflect/api/Trees.scala b/src/reflect/scala/reflect/api/Trees.scala index 1f15ee6070..63a06ab2e8 100644 --- a/src/reflect/scala/reflect/api/Trees.scala +++ b/src/reflect/scala/reflect/api/Trees.scala @@ -1967,12 +1967,12 @@ trait Trees { self: Universe => val Modifiers: ModifiersCreator abstract class ModifiersCreator { - def apply(): Modifiers = Modifiers(NoFlags, EmptyTypeName, List()) + def apply(): Modifiers = Modifiers(NoFlags, tpnme.EMPTY, List()) def apply(flags: FlagSet, privateWithin: Name, annotations: List[Tree]): Modifiers } def Modifiers(flags: FlagSet, privateWithin: Name): Modifiers = Modifiers(flags, privateWithin, List()) - def Modifiers(flags: FlagSet): Modifiers = Modifiers(flags, EmptyTypeName) + def Modifiers(flags: FlagSet): Modifiers = Modifiers(flags, tpnme.EMPTY) /** ... */ lazy val NoMods = Modifiers() diff --git a/test/files/run/macro-reflective-mamd-normal-mi/Macros_Test_2.scala b/test/files/run/macro-reflective-mamd-normal-mi/Macros_Test_2.scala index 089f30f389..adecfcff17 100644 --- a/test/files/run/macro-reflective-mamd-normal-mi/Macros_Test_2.scala +++ b/test/files/run/macro-reflective-mamd-normal-mi/Macros_Test_2.scala @@ -11,7 +11,7 @@ object Test extends App { val macrobody = Select(Ident(newTermName("Impls")), newTermName("foo")) val macroparam = ValDef(NoMods, newTermName("x"), TypeTree(definitions.IntClass.toType), EmptyTree) val macrodef = DefDef(Modifiers(MACRO), newTermName("foo"), Nil, List(List(macroparam)), TypeTree(), macrobody) - val modulector = DefDef(NoMods, nme.CONSTRUCTOR, Nil, List(List()), TypeTree(), Block(Apply(Select(Super(This(EmptyTypeName), EmptyTypeName), nme.CONSTRUCTOR), List()))) + val modulector = DefDef(NoMods, nme.CONSTRUCTOR, Nil, List(List()), TypeTree(), Block(Apply(Select(Super(This(tpnme.EMPTY), tpnme.EMPTY), nme.CONSTRUCTOR), List()))) val module = ModuleDef(NoMods, newTermName("Macros"), Template(Nil, emptyValDef, List(modulector, macrodef))) val macroapp = Apply(Select(Ident("Macros"), newTermName("foo")), List(Literal(Constant(42)))) val tree = Block(macrodef, module, macroapp) -- cgit v1.2.3 From b25f6514b77b1a93ea5a4a57041c9419e0efbe10 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 3 Oct 2012 23:18:46 +0200 Subject: removes extraneous methods from api.Constants The next round of scaladoc-driven cleanup kicks in. --- src/reflect/scala/reflect/api/Constants.scala | 3 --- 1 file changed, 3 deletions(-) (limited to 'src') diff --git a/src/reflect/scala/reflect/api/Constants.scala b/src/reflect/scala/reflect/api/Constants.scala index f2d8ef2eb9..0bb64b3b12 100644 --- a/src/reflect/scala/reflect/api/Constants.scala +++ b/src/reflect/scala/reflect/api/Constants.scala @@ -37,7 +37,6 @@ trait Constants { abstract class ConstantApi { val value: Any def tpe: Type - def isNaN: Boolean def booleanValue: Boolean def byteValue: Byte @@ -50,7 +49,5 @@ trait Constants { def stringValue: String def typeValue: Type def symbolValue: Symbol - - def convertTo(pt: Type): Constant } } -- cgit v1.2.3 From 7ee5bc9e549f07b8e73babce456e72539d7413d3 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 3 Oct 2012 23:19:45 +0200 Subject: removes extraneous indirection from FlagValues We don't really need that abstract type. --- src/reflect/scala/reflect/api/FlagSets.scala | 4 +--- src/reflect/scala/reflect/internal/FlagSets.scala | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) (limited to 'src') diff --git a/src/reflect/scala/reflect/api/FlagSets.scala b/src/reflect/scala/reflect/api/FlagSets.scala index 599c4ca426..3eda54b28a 100644 --- a/src/reflect/scala/reflect/api/FlagSets.scala +++ b/src/reflect/scala/reflect/api/FlagSets.scala @@ -21,14 +21,12 @@ trait FlagSets { self: Universe => val Flag: FlagValues - type FlagValues >: Null <: FlagValuesApi - // Q: I have a pretty flag. Can I put it here? // A: Only if there's a tree that cannot be built without it. // If you want to put a flag here so that it can be tested against, // introduce an `isXXX` method in one of the `api.Symbols` classes instead. - trait FlagValuesApi { + trait FlagValues { /** Flag indicating that tree represents a trait */ val TRAIT: FlagSet diff --git a/src/reflect/scala/reflect/internal/FlagSets.scala b/src/reflect/scala/reflect/internal/FlagSets.scala index 6270416d4f..6a3b6870a0 100644 --- a/src/reflect/scala/reflect/internal/FlagSets.scala +++ b/src/reflect/scala/reflect/internal/FlagSets.scala @@ -17,8 +17,6 @@ trait FlagSets extends api.FlagSets { self: SymbolTable => val NoFlags: FlagSet = 0L - trait FlagValues extends FlagValuesApi - object Flag extends FlagValues { val TRAIT : FlagSet = Flags.TRAIT val INTERFACE : FlagSet = Flags.INTERFACE -- cgit v1.2.3 From f4521c7f4fd77bc42d4b3d9e6f8f8309a00fa922 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 3 Oct 2012 23:20:53 +0200 Subject: removes extraneous methods from api.Scopes It's been more than a year, and I never used these methods. --- src/reflect/scala/reflect/api/Scopes.scala | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/reflect/scala/reflect/api/Scopes.scala b/src/reflect/scala/reflect/api/Scopes.scala index d30da07ad5..770349c5b5 100644 --- a/src/reflect/scala/reflect/api/Scopes.scala +++ b/src/reflect/scala/reflect/api/Scopes.scala @@ -21,6 +21,9 @@ trait Scopes { self: Universe => */ implicit val ScopeTag: ClassTag[Scope] + /** Create a new scope with the given initial elements. */ + def newScopeWith(elems: Symbol*): Scope + /** The type of member scopes, as in class definitions, for example. */ type MemberScope >: Null <: Scope with MemberScopeApi @@ -28,7 +31,7 @@ trait Scopes { self: Universe => trait MemberScopeApi extends ScopeApi { /** Sorts the symbols included in this scope so that: * 1) Symbols appear in the linearization order of their owners. - * 2) Symbols with the same owner appear in reverse order of their declarations. + * 2) Symbols with the same owner appear in same order of their declarations. * 3) Synthetic members (e.g. getters/setters for vals/vars) might appear in arbitrary order. */ def sorted: List[Symbol] @@ -38,13 +41,4 @@ trait Scopes { self: Universe => * Can be used for pattern matching, instance tests, serialization and likes. */ implicit val MemberScopeTag: ClassTag[MemberScope] - - /** Create a new scope. */ - def newScope: Scope - - /** Create a new scope nested in another one with which it shares its elements. */ - def newNestedScope(outer: Scope): Scope - - /** Create a new scope with the given initial elements. */ - def newScopeWith(elems: Symbol*): Scope } \ No newline at end of file -- cgit v1.2.3 From be493483b55548f06b5bebff689b99208272a4a9 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 3 Oct 2012 23:22:53 +0200 Subject: removes extraneous methods from api.Mirrors We decided to give up on providing symbol table traversal facilities in the current incarnation of mirrors. Let's be consistent with ourselves. --- src/reflect/scala/reflect/api/Mirrors.scala | 31 ---------------------- .../scala/reflect/runtime/JavaMirrors.scala | 11 +------- 2 files changed, 1 insertion(+), 41 deletions(-) (limited to 'src') diff --git a/src/reflect/scala/reflect/api/Mirrors.scala b/src/reflect/scala/reflect/api/Mirrors.scala index bff899daa4..bfd60dfba0 100644 --- a/src/reflect/scala/reflect/api/Mirrors.scala +++ b/src/reflect/scala/reflect/api/Mirrors.scala @@ -166,9 +166,6 @@ trait Mirrors { self: Universe => /** A mirror that reflects the instance or static parts of a runtime class */ trait TemplateMirror { - /** The runtime class reflected by this mirror */ - def runtimeClass: RuntimeClass - /** True if the mirror represents the static part * of a runtime class or the companion object of a Scala class. * One has: @@ -180,18 +177,6 @@ trait Mirrors { self: Universe => /** The Scala symbol corresponding to the reflected runtime class or object */ def symbol: Symbol - - /** Optionally, the mirror of the companion reflected by this mirror. - * If this mirror reflects a Scala object, the mirror for the companion class, or None - * if the mirror represents a Scala object that comes without a class. - * Otherwise, if the mirror represents the static part of a runtime class, the - * mirror representing the instance part of the same class. - * Otherwise, if the mirror represents a Scala instance class, the mirror for the companion - * object of that class, or None if no such object exists. - * Otherwise, if the mirror represents a runtime instance class, a mirror representing the static - * part of the same class. - */ - def companion: Option[TemplateMirror] } /** A mirror that reflects a Scala object definition or the static parts of a runtime class */ @@ -205,14 +190,6 @@ trait Mirrors { self: Universe => * If this mirror reflects the static part of a runtime class, returns `null`. */ def instance: Any - - /** Optionally, the mirror of the companion class if the object reflected by this mirror. - * If this mirror reflects a Scala object, the mirror for the companion class, or None - * if the mirror represents a Scala object that comes without a class. - * Otherwise, if the mirror represents the static part of a runtime class, the - * mirror representing the instance part of the same class. - */ - override def companion: Option[ClassMirror] } /** A mirror that reflects the instance parts of a runtime class */ @@ -232,14 +209,6 @@ trait Mirrors { self: Universe => * It must be a member (declared or inherited) of the class underlying this mirror. */ def reflectConstructor(constructor: MethodSymbol): MethodMirror - - /** Optionally, the mirror of the companion object of the class reflected by this mirror. - * If this mirror represents a Scala instance class, the mirror for the companion - * object of that class, or None if no such object exists. - * Otherwise, if the mirror represents a runtime instance class, a mirror representing the static - * part of the same class. - */ - override def companion: Option[ModuleMirror] } /** A mirror that reflects instances and static classes */ diff --git a/src/reflect/scala/reflect/runtime/JavaMirrors.scala b/src/reflect/scala/reflect/runtime/JavaMirrors.scala index b917eac779..e5ff9d62f2 100644 --- a/src/reflect/scala/reflect/runtime/JavaMirrors.scala +++ b/src/reflect/scala/reflect/runtime/JavaMirrors.scala @@ -446,8 +446,7 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni extends TemplateMirror { def outer: AnyRef def erasure: ClassSymbol - lazy val runtimeClass = classToJava(erasure) - lazy val signature = typeToScala(runtimeClass) + lazy val signature = typeToScala(classToJava(erasure)) } private class JavaClassMirror(val outer: AnyRef, val symbol: ClassSymbol) @@ -458,10 +457,6 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni checkConstructorOf(constructor, symbol) new JavaConstructorMirror(outer, constructor) } - def companion: Option[ModuleMirror] = symbol.companionModule match { - case module: ModuleSymbol => Some(new JavaModuleMirror(outer, module)) - case _ => None - } override def toString = s"class mirror for ${symbol.fullName} (bound to $outer)" } @@ -476,10 +471,6 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni if (outer == null) staticSingletonInstance(classToJava(symbol.moduleClass.asClass)) else innerSingletonInstance(outer, symbol.name) } - def companion: Option[ClassMirror] = symbol.companionClass match { - case cls: ClassSymbol => Some(new JavaClassMirror(outer, cls)) - case _ => None - } override def toString = s"module mirror for ${symbol.fullName} (bound to $outer)" } -- cgit v1.2.3 From 27003cc53e10528b55a9604f60a5f73ac8d0f702 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 3 Oct 2012 23:29:03 +0200 Subject: hides internal methods of api.Printers --- src/reflect/scala/reflect/api/Printers.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/reflect/scala/reflect/api/Printers.scala b/src/reflect/scala/reflect/api/Printers.scala index 65ff2ed9fa..72a9bf8f3d 100644 --- a/src/reflect/scala/reflect/api/Printers.scala +++ b/src/reflect/scala/reflect/api/Printers.scala @@ -5,7 +5,7 @@ import java.io.{ PrintWriter, StringWriter } trait Printers { self: Universe => - trait TreePrinter { + protected trait TreePrinter { def print(args: Any*) protected var printTypes = false protected var printIds = false @@ -52,7 +52,7 @@ trait Printers { self: Universe => /** Hook to define what `show(...)` means. */ - def newTreePrinter(out: PrintWriter): TreePrinter + protected def newTreePrinter(out: PrintWriter): TreePrinter /** Renders internal structure of a reflection artifact. */ @@ -61,7 +61,7 @@ trait Printers { self: Universe => /** Hook to define what `showRaw(...)` means. */ - def newRawTreePrinter(out: PrintWriter): TreePrinter + protected def newRawTreePrinter(out: PrintWriter): TreePrinter /** Renders a prettified representation of a name. */ -- cgit v1.2.3 From 9262c42db144cd3b9491fa087faa819d3c75247d Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 3 Oct 2012 23:30:07 +0200 Subject: removes extraneous methods from api.Trees Tree.hasSymbol is really too much to document for its merit. --- src/reflect/scala/reflect/api/Trees.scala | 3 --- 1 file changed, 3 deletions(-) (limited to 'src') diff --git a/src/reflect/scala/reflect/api/Trees.scala b/src/reflect/scala/reflect/api/Trees.scala index 63a06ab2e8..5a87d1a90e 100644 --- a/src/reflect/scala/reflect/api/Trees.scala +++ b/src/reflect/scala/reflect/api/Trees.scala @@ -99,9 +99,6 @@ trait Trees { self: Universe => */ def symbol: Symbol - /** ... */ - def hasSymbol: Boolean - /** Provides an alternate if tree is empty * @param alt The alternate tree * @return If this tree is non empty, this tree, otherwise `alt`. -- cgit v1.2.3 From 8ff35b0dc4a41c1061a23da77ab5da668b27f17f Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Thu, 4 Oct 2012 07:30:41 +0200 Subject: removes extraneous methods from api.StandardDefinitions Never got to use these guys, so let's better remove them. --- src/reflect/scala/reflect/api/StandardDefinitions.scala | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'src') diff --git a/src/reflect/scala/reflect/api/StandardDefinitions.scala b/src/reflect/scala/reflect/api/StandardDefinitions.scala index 03f2a6b0aa..7197542370 100644 --- a/src/reflect/scala/reflect/api/StandardDefinitions.scala +++ b/src/reflect/scala/reflect/api/StandardDefinitions.scala @@ -67,12 +67,7 @@ trait StandardDefinitions { def Array_length: TermSymbol // todo. fix the bug in Definitions.getMemberMethod def Array_update: TermSymbol // todo. fix the bug in Definitions.getMemberMethod def ByNameParamClass: ClassSymbol - def ConsClass: ClassSymbol def FunctionClass : Array[ClassSymbol] - def IterableClass: ClassSymbol - def IteratorClass: ClassSymbol - def IteratorModule: ModuleSymbol - def Iterator_apply: TermSymbol // todo. fix the bug in Definitions.getMemberMethod def JavaRepeatedParamClass: ClassSymbol def ListModule: ModuleSymbol def List_apply: TermSymbol // todo. fix the bug in Definitions.getMemberMethod @@ -81,13 +76,7 @@ trait StandardDefinitions { def OptionClass: ClassSymbol def ProductClass : Array[ClassSymbol] def RepeatedParamClass: ClassSymbol - def SeqClass: ClassSymbol - def SeqModule: ModuleSymbol - def SomeClass: ClassSymbol def SomeModule: ModuleSymbol - def StringBuilderClass: ClassSymbol - def SymbolClass : ClassSymbol - def TraversableClass: ClassSymbol def TupleClass: Array[Symbol] // cannot make it Array[ClassSymbol], because TupleClass(0) is supposed to be NoSymbol. weird def ScalaPrimitiveValueClasses: List[ClassSymbol] def ScalaNumericValueClasses: List[ClassSymbol] -- cgit v1.2.3 From ca611e38e2ca9f10927f207b98ee0c0f7b8aca06 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Thu, 4 Oct 2012 07:32:50 +0200 Subject: removes extraneous methods from api.StandardNames nme.ROOT doesn't have much use in the public API (unlike nme.ROOTPKG). tpnme.EMPTY duplicates a method inherited from the base class. --- src/reflect/scala/reflect/api/StandardNames.scala | 2 -- 1 file changed, 2 deletions(-) (limited to 'src') diff --git a/src/reflect/scala/reflect/api/StandardNames.scala b/src/reflect/scala/reflect/api/StandardNames.scala index 354a9f9328..36ba840c84 100644 --- a/src/reflect/scala/reflect/api/StandardNames.scala +++ b/src/reflect/scala/reflect/api/StandardNames.scala @@ -23,7 +23,6 @@ trait StandardNames { trait NamesApi { type NameType >: Null <: Name val WILDCARD: NameType - val ROOT: NameType val EMPTY: NameType val ERROR: NameType val PACKAGE: NameType @@ -38,7 +37,6 @@ trait StandardNames { trait TypeNamesApi extends NamesApi { type NameType = TypeName - val EMPTY: NameType val WILDCARD_STAR: NameType } } -- cgit v1.2.3 From 02b9c23d1ab9d12eb31526d3edbc76d8ee43abf2 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 3 Oct 2012 23:34:50 +0200 Subject: introduces macros.package.scala For the sole reason of putting docs on it in a separate pull request, which is being prepared elsewhere --- src/reflect/scala/reflect/macros/package.scala | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 src/reflect/scala/reflect/macros/package.scala (limited to 'src') diff --git a/src/reflect/scala/reflect/macros/package.scala b/src/reflect/scala/reflect/macros/package.scala new file mode 100644 index 0000000000..6a69872367 --- /dev/null +++ b/src/reflect/scala/reflect/macros/package.scala @@ -0,0 +1,4 @@ +package scala.reflect + +package object macros { +} \ No newline at end of file -- cgit v1.2.3 From c868038423b5c28234e66788158e379754ed47b3 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 3 Oct 2012 23:17:31 +0200 Subject: moves Attachments from api to macros Because they are only available in macros.Universe, not in api.Universe, therefore I'd argue that the confusion factor is stronger than the weirdness of scala.reflect.api.Position extending scala.reflect.macros.Attachments. --- src/reflect/scala/reflect/api/Attachments.scala | 50 ------------------- src/reflect/scala/reflect/api/Position.scala | 2 + .../scala/reflect/internal/StdAttachments.scala | 2 +- .../scala/reflect/internal/util/Position.scala | 2 +- src/reflect/scala/reflect/macros/Attachments.scala | 57 ++++++++++++++++++++++ src/reflect/scala/reflect/macros/Universe.scala | 2 +- 6 files changed, 62 insertions(+), 53 deletions(-) delete mode 100644 src/reflect/scala/reflect/api/Attachments.scala create mode 100644 src/reflect/scala/reflect/macros/Attachments.scala (limited to 'src') diff --git a/src/reflect/scala/reflect/api/Attachments.scala b/src/reflect/scala/reflect/api/Attachments.scala deleted file mode 100644 index edbb0131ca..0000000000 --- a/src/reflect/scala/reflect/api/Attachments.scala +++ /dev/null @@ -1,50 +0,0 @@ -package scala.reflect -package api - -/** Attachments is a generalization of Position. Typically it stores a Position of a tree, but this can be extended to - * encompass arbitrary payloads. Payloads are stored in type-indexed slots, which can be read with `get[T]` and written - * with `update[T]` and `remove[T]`. - * - * Attachments always carry positions because we don't want to introduce an additional field for attachments in `Tree` - * imposing an unnecessary memory tax because of something that will not be used in most cases. - */ -abstract class Attachments { self => - - /** The position type of this attachment */ - type Pos >: Null - - /** The underlying position */ - def pos: Pos - - /** Creates a copy of this attachment with the position replaced by `newPos` */ - def withPos(newPos: Pos): Attachments { type Pos = self.Pos } - - /** The underlying payload with the guarantee that no two elements have the same type. */ - def all: Set[Any] = Set.empty - - private def matchesTag[T: ClassTag](datum: Any) = - classTag[T].runtimeClass == datum.getClass - - /** An underlying payload of the given class type `T`. */ - def get[T: ClassTag]: Option[T] = - (all filter matchesTag[T]).headOption.asInstanceOf[Option[T]] - - /** Creates a copy of this attachment with the payload slot of T added/updated with the provided value. - * - * Replaces an existing payload of the same type, if exists. - */ - def update[T: ClassTag](attachment: T): Attachments { type Pos = self.Pos } = - new NonemptyAttachments(this.pos, remove[T].all + attachment) - - /** Creates a copy of this attachment with the payload of the given class type `T` removed. */ - def remove[T: ClassTag]: Attachments { type Pos = self.Pos } = { - val newAll = all filterNot matchesTag[T] - if (newAll.isEmpty) pos.asInstanceOf[Attachments { type Pos = self.Pos }] - else new NonemptyAttachments(this.pos, newAll) - } - - private class NonemptyAttachments(override val pos: Pos, override val all: Set[Any]) extends Attachments { - type Pos = self.Pos - def withPos(newPos: Pos) = new NonemptyAttachments(newPos, all) - } -} diff --git a/src/reflect/scala/reflect/api/Position.scala b/src/reflect/scala/reflect/api/Position.scala index 9c63e4becf..d3dc9c884f 100644 --- a/src/reflect/scala/reflect/api/Position.scala +++ b/src/reflect/scala/reflect/api/Position.scala @@ -1,6 +1,8 @@ package scala.reflect package api +import scala.reflect.macros.Attachments + /** The Position class and its subclasses represent positions of ASTs and symbols. * Except for NoPosition and FakePos, every position refers to a SourceFile * and to an offset in the sourcefile (its `point`). For batch compilation, diff --git a/src/reflect/scala/reflect/internal/StdAttachments.scala b/src/reflect/scala/reflect/internal/StdAttachments.scala index 5c4d1f7e28..9fe443bf50 100644 --- a/src/reflect/scala/reflect/internal/StdAttachments.scala +++ b/src/reflect/scala/reflect/internal/StdAttachments.scala @@ -8,7 +8,7 @@ trait StdAttachments { * Common code between reflect-internal Symbol and Tree related to Attachments. */ trait Attachable { - protected var rawatt: scala.reflect.api.Attachments { type Pos = Position } = NoPosition + protected var rawatt: scala.reflect.macros.Attachments { type Pos = Position } = NoPosition def attachments = rawatt def updateAttachment[T: ClassTag](attachment: T): this.type = { rawatt = rawatt.update(attachment); this } def removeAttachment[T: ClassTag]: this.type = { rawatt = rawatt.remove[T]; this } diff --git a/src/reflect/scala/reflect/internal/util/Position.scala b/src/reflect/scala/reflect/internal/util/Position.scala index 151a64daff..d4225bcff5 100644 --- a/src/reflect/scala/reflect/internal/util/Position.scala +++ b/src/reflect/scala/reflect/internal/util/Position.scala @@ -7,7 +7,7 @@ package scala.reflect.internal.util import scala.reflect.ClassTag -import scala.reflect.api.Attachments +import scala.reflect.macros.Attachments object Position { val tabInc = 8 diff --git a/src/reflect/scala/reflect/macros/Attachments.scala b/src/reflect/scala/reflect/macros/Attachments.scala new file mode 100644 index 0000000000..ba5ccf88f1 --- /dev/null +++ b/src/reflect/scala/reflect/macros/Attachments.scala @@ -0,0 +1,57 @@ +package scala.reflect +package macros + +/** Attachments provide a way to associate custom metadata with symbols and trees. + * + * Along with `symbol` and `tpe`, which represent core metadata of trees, each tree + * carries the `attachments` field that can store other metadata: compiler-defined (e.g. positions) or user-defined. + * Same story is true for symbols, which also have extensible metadata by the virtue + * of the same `attachments` field. + * + * Typically attachments just store a [[scala.reflect.api.Position]], but they can be extended to + * encompass arbitrary payloads. Payloads are stored in type-indexed slots, which can be read with `get[T]` and written + * with `update[T]` and `remove[T]`. + * + * This API doesn't have much use in the runtime reflection API (the [[scala.reflect.api]] package), but it might be of help + * for macro writers, providing a way to coordinate multiple macros operating on the same code. Therefore the `attachments` + * field is only declared in trees and symbols belonging to [[scala.reflect.macros.Universe]]. + */ +abstract class Attachments { self => + + /** The position type of this attachment */ + type Pos >: Null + + /** The underlying position */ + def pos: Pos + + /** Creates a copy of this attachment with the position replaced by `newPos` */ + def withPos(newPos: Pos): Attachments { type Pos = self.Pos } + + /** The underlying payload with the guarantee that no two elements have the same type. */ + def all: Set[Any] = Set.empty + + private def matchesTag[T: ClassTag](datum: Any) = + classTag[T].runtimeClass == datum.getClass + + /** An underlying payload of the given class type `T`. */ + def get[T: ClassTag]: Option[T] = + (all filter matchesTag[T]).headOption.asInstanceOf[Option[T]] + + /** Creates a copy of this attachment with the payload slot of T added/updated with the provided value. + * Replaces an existing payload of the same type, if exists. + */ + def update[T: ClassTag](attachment: T): Attachments { type Pos = self.Pos } = + new NonemptyAttachments(this.pos, remove[T].all + attachment) + + /** Creates a copy of this attachment with the payload of the given class type `T` removed. */ + def remove[T: ClassTag]: Attachments { type Pos = self.Pos } = { + val newAll = all filterNot matchesTag[T] + if (newAll.isEmpty) pos.asInstanceOf[Attachments { type Pos = self.Pos }] + else new NonemptyAttachments(this.pos, newAll) + } + + private class NonemptyAttachments(override val pos: Pos, override val all: Set[Any]) extends Attachments { + type Pos = self.Pos + def withPos(newPos: Pos) = new NonemptyAttachments(newPos, all) + } +} diff --git a/src/reflect/scala/reflect/macros/Universe.scala b/src/reflect/scala/reflect/macros/Universe.scala index 97d0a8d98a..3e38691d85 100644 --- a/src/reflect/scala/reflect/macros/Universe.scala +++ b/src/reflect/scala/reflect/macros/Universe.scala @@ -7,7 +7,7 @@ abstract class Universe extends scala.reflect.api.Universe { trait AttachableApi { /** ... */ - def attachments: scala.reflect.api.Attachments { type Pos = Position } + def attachments: Attachments { type Pos = Position } /** ... */ def updateAttachment[T: ClassTag](attachment: T): AttachableApi.this.type -- cgit v1.2.3 From cfae88959153996c25ba1a93f2456e3e4912194c Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 3 Oct 2012 23:28:16 +0200 Subject: introduces api.JavaMirrors This trait carries mirror-related changes of the API that happen when api.Universe transforms into api.JavaUniverse. From a coding standpoint this is a mere rehashing of the code, but from a documentation standpoint this provides additional insights into what's going on in reflection. --- src/reflect/scala/reflect/api/JavaMirrors.scala | 16 ++++++++++++++++ src/reflect/scala/reflect/api/JavaUniverse.scala | 13 +------------ 2 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 src/reflect/scala/reflect/api/JavaMirrors.scala (limited to 'src') diff --git a/src/reflect/scala/reflect/api/JavaMirrors.scala b/src/reflect/scala/reflect/api/JavaMirrors.scala new file mode 100644 index 0000000000..cb0fa0f650 --- /dev/null +++ b/src/reflect/scala/reflect/api/JavaMirrors.scala @@ -0,0 +1,16 @@ +package scala.reflect +package api + +trait JavaMirrors { self: JavaUniverse => + + type RuntimeClass = java.lang.Class[_] + + override type Mirror >: Null <: JavaMirror + + trait JavaMirror extends scala.reflect.api.Mirror[self.type] with RuntimeMirror { + val classLoader: ClassLoader + override def toString = s"JavaMirror with ${runtime.ReflectionUtils.show(classLoader)}" + } + + def runtimeMirror(cl: ClassLoader): Mirror +} diff --git a/src/reflect/scala/reflect/api/JavaUniverse.scala b/src/reflect/scala/reflect/api/JavaUniverse.scala index cc703e833d..1a8a02776b 100644 --- a/src/reflect/scala/reflect/api/JavaUniverse.scala +++ b/src/reflect/scala/reflect/api/JavaUniverse.scala @@ -1,18 +1,7 @@ package scala.reflect package api -trait JavaUniverse extends Universe with Mirrors { self => - - type RuntimeClass = java.lang.Class[_] - - override type Mirror >: Null <: JavaMirror - - trait JavaMirror extends scala.reflect.api.Mirror[self.type] with RuntimeMirror { - val classLoader: ClassLoader - override def toString = s"JavaMirror with ${runtime.ReflectionUtils.show(classLoader)}" - } - - def runtimeMirror(cl: ClassLoader): Mirror +trait JavaUniverse extends Universe with JavaMirrors { self => override def typeTagToManifest[T: ClassTag](mirror0: Any, tag: Universe # TypeTag[T]): Manifest[T] = { // SI-6239: make this conversion more precise -- cgit v1.2.3 From 112e922acdce5d2b1a102be95c211abcb5c0b59d Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Wed, 3 Oct 2012 23:31:28 +0200 Subject: upgrades showRaw Fixes the stuff that was irritating, when I was preparing examples for reflection documentation. Has zero impact at stability of scalac, because showRaw isn't used anywhere in the compiler unless invoked explicitly. --- src/reflect/scala/reflect/internal/Printers.scala | 47 ++++++++++++++--------- 1 file changed, 29 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/reflect/scala/reflect/internal/Printers.scala b/src/reflect/scala/reflect/internal/Printers.scala index fb165ab50f..fd5a7cf88b 100644 --- a/src/reflect/scala/reflect/internal/Printers.scala +++ b/src/reflect/scala/reflect/internal/Printers.scala @@ -534,17 +534,16 @@ trait Printers extends api.Printers { self: SymbolTable => depth += 1 args foreach { + case expr: Expr[_] => + print("Expr") + if (printTypes) print(expr.staticType) + print("(") + print(expr.tree) + print(")") case EmptyTree => print("EmptyTree") case emptyValDef: AnyRef if emptyValDef eq self.emptyValDef => print("emptyValDef") - case Literal(Constant(value)) => - def print(s: String) = this.print("Literal(Constant(" + s + "))") - value match { - case s: String => print("\"" + s + "\"") - case null => print(null) - case _ => print(value.toString) - } case tree: Tree => val hasSymbol = tree.hasSymbol && tree.symbol != NoSymbol val isError = hasSymbol && tree.symbol.name.toString == nme.ERROR.toString @@ -568,6 +567,12 @@ trait Printers extends api.Printers { self: SymbolTable => } else { print(name) } + case Constant(s: String) => + print("Constant(\"" + s + "\")") + case Constant(null) => + print("Constant(null)") + case Constant(value) => + print("Constant(" + value + ")") case arg => print(arg) }, @@ -582,14 +587,18 @@ trait Printers extends api.Printers { self: SymbolTable => if (printIds) print("#", sym.id) if (printKinds) print("#", sym.abbreviatedKindString) if (printMirrors) print("%M", footnotes.put[scala.reflect.api.Mirror[_]](mirrorThatLoaded(sym))) - case NoType => - print("NoType") - case NoPrefix => - print("NoPrefix") + case tag: TypeTag[_] => + print("TypeTag(", tag.tpe, ")") + case tag: WeakTypeTag[_] => + print("WeakTypeTag(", tag.tpe, ")") case tpe: Type => val defer = printTypesInFootnotes && !printingFootnotes if (defer) print("[", footnotes.put(tpe), "]") - else printProduct(tpe.asInstanceOf[Product]) + else tpe match { + case NoType => print("NoType") + case NoPrefix => print("NoPrefix") + case _ => printProduct(tpe.asInstanceOf[Product]) + } case mods: Modifiers => print("Modifiers(") if (mods.flags != NoFlags || mods.privateWithin != tpnme.EMPTY || mods.annotations.nonEmpty) print(show(mods.flags)) @@ -598,6 +607,9 @@ trait Printers extends api.Printers { self: SymbolTable => print(")") case name: Name => print(show(name)) + case scope: Scope => + print("Scope") + printIterable(scope.toList) case list: List[_] => print("List") printIterable(list) @@ -645,16 +657,15 @@ trait Printers extends api.Printers { self: SymbolTable => } def show(name: Name): String = name match { + case tpnme.WILDCARD => "tpnme.WILDCARD" case tpnme.EMPTY => "tpnme.EMPTY" - case tpnme.ROOT => "tpnme.ROOT" + case tpnme.ERROR => "tpnme.ERROR" case tpnme.PACKAGE => "tpnme.PACKAGE" - case tpnme.EMPTY_PACKAGE_NAME => "tpnme.EMPTY_PACKAGE_NAME" - case tpnme.WILDCARD => "tpnme.WILDCARD" + case tpnme.WILDCARD_STAR => "tpnme.WILDCARD_STAR" + case nme.WILDCARD => "nme.WILDCARD" case nme.EMPTY => "nme.EMPTY" - case nme.ROOT => "nme.ROOT" + case nme.ERROR => "tpnme.ERROR" case nme.PACKAGE => "nme.PACKAGE" - case nme.EMPTY_PACKAGE_NAME => "nme.EMPTY_PACKAGE_NAME" - case nme.WILDCARD => "nme.WILDCARD" case nme.CONSTRUCTOR => "nme.CONSTRUCTOR" case nme.ROOTPKG => "nme.ROOTPKG" case _ => -- cgit v1.2.3 From 49dcb8ff33483949cecce671a2d87676cefa457f Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Mon, 8 Oct 2012 16:10:34 +0200 Subject: removes strongly-typed Constant.value wrappers These are surely not necessary. Thanks Vlad! --- src/reflect/scala/reflect/api/Constants.scala | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'src') diff --git a/src/reflect/scala/reflect/api/Constants.scala b/src/reflect/scala/reflect/api/Constants.scala index 0bb64b3b12..2f201d033d 100644 --- a/src/reflect/scala/reflect/api/Constants.scala +++ b/src/reflect/scala/reflect/api/Constants.scala @@ -37,17 +37,5 @@ trait Constants { abstract class ConstantApi { val value: Any def tpe: Type - - def booleanValue: Boolean - def byteValue: Byte - def shortValue: Short - def charValue: Char - def intValue: Int - def longValue: Long - def floatValue: Float - def doubleValue: Double - def stringValue: String - def typeValue: Type - def symbolValue: Symbol } } -- cgit v1.2.3