summaryrefslogtreecommitdiff
path: root/src/reflect/scala/reflect/internal/Definitions.scala
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2014-01-12 00:17:25 +0100
committerEugene Burmako <xeno.by@gmail.com>2014-01-12 18:03:51 +0100
commit3a689f5c426436aea716567625fd6167e57bef92 (patch)
tree46871d70acc7d3cd83e7433f217e362a796e8f30 /src/reflect/scala/reflect/internal/Definitions.scala
parent5cc8f83c681ded7367dc5112f6f9042e9526facf (diff)
downloadscala-3a689f5c426436aea716567625fd6167e57bef92.tar.gz
scala-3a689f5c426436aea716567625fd6167e57bef92.tar.bz2
scala-3a689f5c426436aea716567625fd6167e57bef92.zip
changes bundles to be classes, not traits extending Macro
Adjusts bundle notation to read `class Bundle(val c: Context)` instead of `class Bundle extends Macro`. This avoids calling compileLate in the macro compiler and associated tooling problems.
Diffstat (limited to 'src/reflect/scala/reflect/internal/Definitions.scala')
-rw-r--r--src/reflect/scala/reflect/internal/Definitions.scala44
1 files changed, 19 insertions, 25 deletions
diff --git a/src/reflect/scala/reflect/internal/Definitions.scala b/src/reflect/scala/reflect/internal/Definitions.scala
index 133442bdb5..03826a3011 100644
--- a/src/reflect/scala/reflect/internal/Definitions.scala
+++ b/src/reflect/scala/reflect/internal/Definitions.scala
@@ -482,10 +482,6 @@ trait Definitions extends api.StandardDefinitions {
lazy val TypeCreatorClass = getClassIfDefined("scala.reflect.api.TypeCreator") // defined in scala-reflect.jar, so we need to be careful
lazy val TreeCreatorClass = getClassIfDefined("scala.reflect.api.TreeCreator") // defined in scala-reflect.jar, so we need to be careful
- lazy val BlackboxMacroClass = getClassIfDefined("scala.reflect.macros.blackbox.Macro") // defined in scala-reflect.jar, so we need to be careful
- def BlackboxMacroContextValue = BlackboxMacroClass.map(sym => getMemberValue(sym, nme.c))
- lazy val WhiteboxMacroClass = getClassIfDefined("scala.reflect.macros.whitebox.Macro") // defined in scala-reflect.jar, so we need to be careful
- def WhiteboxMacroContextValue = WhiteboxMacroClass.map(sym => getMemberValue(sym, nme.c))
lazy val BlackboxContextClass = getClassIfDefined("scala.reflect.macros.blackbox.Context") // defined in scala-reflect.jar, so we need to be careful
lazy val WhiteboxContextClass = getClassIfDefined("scala.reflect.macros.whitebox.Context") // defined in scala-reflect.jar, so we need to be careful
def MacroContextPrefix = BlackboxContextClass.map(sym => getMemberMethod(sym, nme.prefix))
@@ -603,32 +599,30 @@ trait Definitions extends api.StandardDefinitions {
def isWhiteboxContextType(tp: Type) =
isMacroContextType(tp) && (tp <:< WhiteboxContextClass.tpe)
- def mightBeMacroBundleType(tp: Type) =
- tp.baseClasses.contains(WhiteboxMacroClass) ||
- tp.baseClasses.contains(BlackboxMacroClass)
-
- def isMacroBundleType(tp: Type) = tp.baseClasses match {
- case _ :: proto :: _ if isMacroBundleProtoType(proto.tpe) => true
- case _ => false
+ private def macroBundleParamInfo(tp: Type) = {
+ val ctor = tp.erasure.typeSymbol.primaryConstructor
+ ctor.paramss match {
+ case List(List(c)) =>
+ val sym = c.info.typeSymbol
+ val isContextCompatible = sym.isNonBottomSubClass(BlackboxContextClass) || sym.isNonBottomSubClass(WhiteboxContextClass)
+ if (isContextCompatible) c.info else NoType
+ case _ =>
+ NoType
+ }
}
- def isBlackboxMacroBundleType(tp: Type) =
- isMacroBundleType(tp) && (tp <:< BlackboxMacroClass.tpe) && !(tp <:< WhiteboxMacroClass.tpe)
+ def looksLikeMacroBundleType(tp: Type) =
+ macroBundleParamInfo(tp) != NoType
- def isMacroBundleProtoType(tp: Type) = {
- val sym = tp.typeSymbol
- val isNonTrivial = tp != ErrorType && tp != NothingTpe && tp != NullTpe
- def subclasses(sym: Symbol) = sym != NoSymbol && tp.baseClasses.contains(sym)
- val isMacroCompatible = subclasses(BlackboxMacroClass) ^ subclasses(WhiteboxMacroClass)
- val isBundlePrototype = sym != BlackboxMacroClass && sym != WhiteboxMacroClass && sym.isTrait && {
- val c = sym.info.member(nme.c)
- def overrides(sym: Symbol) = c.overrideChain.contains(sym)
- val cIsOk = (overrides(BlackboxMacroContextValue) || overrides(WhiteboxMacroContextValue)) && c.isDeferred
- cIsOk && sym.isMonomorphicType
- }
- isNonTrivial && isMacroCompatible && isBundlePrototype
+ def isMacroBundleType(tp: Type) = {
+ val isContextCompatible = macroBundleParamInfo(tp) != NoType
+ val nonAbstract = !tp.erasure.typeSymbol.isAbstractClass
+ isContextCompatible && nonAbstract
}
+ def isBlackboxMacroBundleType(tp: Type) =
+ isMacroBundleType(tp) && (macroBundleParamInfo(tp) <:< BlackboxContextClass.tpe)
+
def isIterableType(tp: Type) = tp <:< classExistentialType(IterableClass)
// These "direct" calls perform no dealiasing. They are most needed when