Created
December 2, 2015 15:19
-
-
Save wheaties/32adfd2df82468304d59 to your computer and use it in GitHub Desktop.
MkExportDefMacro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def mkExportDefMacro(tcTpe: Type, exportTc: Type, nme: TermName): Tree = { | |
| val tcRef = mkAttributedRef(tcTpe) | |
| val kind = tcTpe.typeParams.map(_.asType.typeParams.length) | |
| val suffix = | |
| if(kind.exists(_ > 1) || kind.size > 22) | |
| c.abort(c.enclosingPosition, s"$tcTpe has an unsupported kind") | |
| else kind.mkString("") | |
| val (f, fd) = { | |
| val t = TypeName(c.freshName) | |
| val (ns, nts) = (kind.map { k => | |
| val tn = TypeName(c.freshName) | |
| (tn, if(k == 0) q"type $tn" else q"type $tn[_]") | |
| }).unzip | |
| (t, q"""type $t[..$nts] >: $tcRef[..$ns]""") | |
| } | |
| val (ts: List[TypeName], tds: List[Tree]) = (kind.map { k => | |
| val t = TypeName(c.freshName) | |
| (t, if(k == 0) q"type $t" else q"type $t[_]") | |
| }).unzip | |
| val exportTpt = c.internal.gen.mkAttributedRef(exportTc.typeSymbol) | |
| val exportsImpl = TermName(s"exportsImpl$suffix") | |
| q""" | |
| implicit def $nme[$fd, ..$tds]: $exportTpt[$f[..$ts]] = | |
| macro _root_.export.ExportsImplExpr.$exportsImpl[$tcRef, ..$ts, $exportTpt] | |
| """ | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment