aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Pretty <jon.pretty@propensive.com>2017-06-11 09:32:01 +0200
committerJon Pretty <jon.pretty@propensive.com>2017-06-11 09:32:01 +0200
commitcb45584555405a1239c55f9f053a4a2fdd7dc33f (patch)
treee692e58d57dc986e925326f48f364b0e78cb6ea9
parent57159b663961a5931de5a0a058c7ade39c0c2a80 (diff)
downloadmagnolia-cb45584555405a1239c55f9f053a4a2fdd7dc33f.tar.gz
magnolia-cb45584555405a1239c55f9f053a4a2fdd7dc33f.tar.bz2
magnolia-cb45584555405a1239c55f9f053a4a2fdd7dc33f.zip
Use List instead of ListMap in compiler state
-rw-r--r--core/src/main/scala/magnolia.scala (renamed from core/src/main/scala/generic.scala)18
1 files changed, 8 insertions, 10 deletions
diff --git a/core/src/main/scala/generic.scala b/core/src/main/scala/magnolia.scala
index 67cc93e..815b613 100644
--- a/core/src/main/scala/generic.scala
+++ b/core/src/main/scala/magnolia.scala
@@ -5,8 +5,6 @@ import macrocompat.bundle
import scala.util.Try
import language.existentials
-import scala.collection.immutable.ListMap
-
abstract class Transformation[C <: whitebox.Context](val c: C) {
def typeclassBody(genericType: c.Type, implementation: c.Tree): c.Tree
def coproductReduction(left: c.Tree, right: c.Tree): c.Tree
@@ -21,14 +19,14 @@ abstract class MagnoliaMacro(val c: whitebox.Context) {
protected def transformation(c: whitebox.Context): Transformation[c.type]
private def findType(key: c.universe.Type): Option[c.universe.TermName] =
- recursionStack(c.enclosingPosition).get(key).map(_.asInstanceOf[c.universe.TermName])
+ recursionStack(c.enclosingPosition).find(_._1 == key).map(_._2.asInstanceOf[c.universe.TermName])
private def recurse[T](key: c.universe.Type, value: c.universe.TermName)(fn: => T): Option[T] = {
recursionStack = recursionStack.updated(
c.enclosingPosition,
recursionStack.get(c.enclosingPosition).map { m =>
- m.updated(key, value)
- }.getOrElse(ListMap(key -> value))
+ m ::: List((key, value))
+ }.getOrElse(List(key -> value))
)
try Some(fn) catch { case e: Exception => None } finally {
@@ -39,9 +37,10 @@ abstract class MagnoliaMacro(val c: whitebox.Context) {
private val transformer = new Transformer {
override def transform(tree: Tree): Tree = tree match {
- case q"_root_.magnolia.Lazy[$returnType](${Literal(Constant(method: String))})" =>
+ case q"magnolia.Lazy.apply[$returnType](${Literal(Constant(method: String))})" =>
q"${TermName(method)}"
- case _ => super.transform(tree)
+ case _ =>
+ super.transform(tree)
}
}
@@ -184,9 +183,8 @@ private[magnolia] object Lazy { def apply[T](method: String): T = ??? }
private[magnolia] object CompileTimeState {
- private[magnolia] var recursionStack: Map[api.Position, ListMap[
- c.universe.Type forSome { val c: whitebox.Context },
- c.universe.TermName forSome { val c: whitebox.Context }
+ private[magnolia] var recursionStack: Map[api.Position, List[
+ (c.universe.Type, c.universe.TermName) forSome { val c: whitebox.Context }
]] = Map()
private[magnolia] var lastSearchType: Option[Universe#Type] = None