diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2012-06-06 14:29:05 +0200 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2012-06-08 15:31:58 +0200 |
commit | ce67870e64afabf75363679bcee597812ad223e9 (patch) | |
tree | ce84ef7673977b0dde4ed13ca1276e25517d6b9c /src/compiler/scala/reflect/makro/runtime/Typers.scala | |
parent | bdff66e2730518f449634375b1f3d19689d72b1e (diff) | |
download | scala-ce67870e64afabf75363679bcee597812ad223e9.tar.gz scala-ce67870e64afabf75363679bcee597812ad223e9.tar.bz2 scala-ce67870e64afabf75363679bcee597812ad223e9.zip |
brings macros up to speed
Before reflection refactoring, macro contexts only exposed a mirror.
Now it's time to expose both a universe (the compiler instance) and
a mirror (a macro-specific symbol resolver).
By the way, speaking of mirrors. Macro contexts have their own mirror,
which is different from compiler's rootMirror. This is done because
macros need to be able to resolve stuff from empty package.
Reflection refactoring brought major changes to runtime evaluation,
which got dropped from universes and now requires scala-compiler.jar.
However there are macro users, who would like to do eval inside macros.
To help them we expose `libraryClassLoader` to manually build toolboxes,
and also a simple-to-use `c.eval` method.
I've also sneakily introduced `c.parse`, because it's something that
has also been frequently requested. Moreover, it might help Scaladoc.
So I decided that it might be worth it to add this new functionality.
Diffstat (limited to 'src/compiler/scala/reflect/makro/runtime/Typers.scala')
-rw-r--r-- | src/compiler/scala/reflect/makro/runtime/Typers.scala | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/compiler/scala/reflect/makro/runtime/Typers.scala b/src/compiler/scala/reflect/makro/runtime/Typers.scala index 704d3d7ac2..18c1714d15 100644 --- a/src/compiler/scala/reflect/makro/runtime/Typers.scala +++ b/src/compiler/scala/reflect/makro/runtime/Typers.scala @@ -4,11 +4,11 @@ package runtime trait Typers { self: Context => - def openMacros: List[Context] = this :: mirror.analyzer.openMacros + def openMacros: List[Context] = this :: universe.analyzer.openMacros def openImplicits: List[(Type, Tree)] = callsiteTyper.context.openImplicits - def typeCheck(tree: Tree, pt: Type = mirror.WildcardType, silent: Boolean = false, withImplicitViewsDisabled: Boolean = false, withMacrosDisabled: Boolean = false): Tree = { + def typeCheck(tree: Tree, pt: Type = universe.WildcardType, silent: Boolean = false, withImplicitViewsDisabled: Boolean = false, withMacrosDisabled: Boolean = false): Tree = { macroLogVerbose("typechecking %s with expected type %s, implicit views = %s, macros = %s".format(tree, pt, !withImplicitViewsDisabled, !withMacrosDisabled)) val wrapper1 = if (!withImplicitViewsDisabled) (callsiteTyper.context.withImplicitsEnabled[Tree] _) else (callsiteTyper.context.withImplicitsDisabled[Tree] _) val wrapper2 = if (!withMacrosDisabled) (callsiteTyper.context.withMacrosEnabled[Tree] _) else (callsiteTyper.context.withMacrosDisabled[Tree] _) @@ -18,28 +18,28 @@ trait Typers { // typechecking uses silent anyways (e.g. in typedSelect), so you'll only waste your time // I'd advise fixing the root cause: finding why the context is not set to report errors // (also see reflect.runtime.ToolBoxes.typeCheckExpr for a workaround that might work for you) - wrapper(callsiteTyper.silent(_.typed(tree, mirror.analyzer.EXPRmode, pt)) match { - case mirror.analyzer.SilentResultValue(result) => + wrapper(callsiteTyper.silent(_.typed(tree, universe.analyzer.EXPRmode, pt)) match { + case universe.analyzer.SilentResultValue(result) => macroLogVerbose(result) result - case error @ mirror.analyzer.SilentTypeError(_) => + case error @ universe.analyzer.SilentTypeError(_) => macroLogVerbose(error.err.errMsg) - if (!silent) throw new mirror.TypeError(error.err.errPos, error.err.errMsg) - mirror.EmptyTree + if (!silent) throw new universe.TypeError(error.err.errPos, error.err.errMsg) + universe.EmptyTree }) } def inferImplicitValue(pt: Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: Position = enclosingPosition): Tree = { macroLogVerbose("inferring implicit value of type %s, macros = %s".format(pt, !withMacrosDisabled)) - import mirror.analyzer.SearchResult + import universe.analyzer.SearchResult val context = callsiteTyper.context val wrapper1 = if (!withMacrosDisabled) (context.withMacrosEnabled[SearchResult] _) else (context.withMacrosDisabled[SearchResult] _) def wrapper (inference: => SearchResult) = wrapper1(inference) - wrapper(mirror.analyzer.inferImplicit(mirror.EmptyTree, pt, true, false, context, !silent, pos)) match { + wrapper(universe.analyzer.inferImplicit(universe.EmptyTree, pt, true, false, context, !silent, 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 mirror.TypeError(context.errBuffer.head.errPos, context.errBuffer.head.errMsg) - mirror.EmptyTree + if (context.hasErrors) throw new universe.TypeError(context.errBuffer.head.errPos, context.errBuffer.head.errMsg) + universe.EmptyTree case success => success.tree } @@ -47,29 +47,29 @@ trait Typers { def inferImplicitView(tree: Tree, from: Type, to: Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, reportAmbiguous: Boolean = true, pos: Position = enclosingPosition): Tree = { macroLogVerbose("inferring implicit view from %s to %s for %s, macros = %s, reportAmbiguous = %s".format(from, to, tree, !withMacrosDisabled, reportAmbiguous)) - import mirror.analyzer.SearchResult + import universe.analyzer.SearchResult val context = callsiteTyper.context val wrapper1 = if (!withMacrosDisabled) (context.withMacrosEnabled[SearchResult] _) else (context.withMacrosDisabled[SearchResult] _) def wrapper (inference: => SearchResult) = wrapper1(inference) - val fun1 = mirror.definitions.FunctionClass(1) - val viewTpe = mirror.TypeRef(fun1.typeConstructor.prefix, fun1, List(from, to)) - wrapper(mirror.analyzer.inferImplicit(tree, viewTpe, reportAmbiguous, true, context, !silent, pos)) match { + val fun1 = universe.definitions.FunctionClass(1) + val viewTpe = universe.TypeRef(fun1.typeConstructor.prefix, fun1, List(from, to)) + wrapper(universe.analyzer.inferImplicit(tree, viewTpe, reportAmbiguous, true, context, !silent, 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 mirror.TypeError(context.errBuffer.head.errPos, context.errBuffer.head.errMsg) - mirror.EmptyTree + if (context.hasErrors) throw new universe.TypeError(context.errBuffer.head.errPos, context.errBuffer.head.errMsg) + universe.EmptyTree case success => success.tree } } - type TypeError = mirror.TypeError + 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 = mirror.resetAllAttrs(tree) + def resetAllAttrs(tree: Tree): Tree = universe.resetAllAttrs(tree) - def resetLocalAttrs(tree: Tree): Tree = mirror.resetLocalAttrs(tree) + def resetLocalAttrs(tree: Tree): Tree = universe.resetLocalAttrs(tree) }
\ No newline at end of file |