-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
169 additions
and
83 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
34 changes: 34 additions & 0 deletions
34
quill-core/src/main/scala/io/getquill/quotation/Rebind.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.getquill.quotation | ||
|
||
import scala.reflect.macros.whitebox.Context | ||
import io.getquill.ast._ | ||
import io.getquill.norm.BetaReduction | ||
|
||
object Rebind { | ||
|
||
def apply(c: Context)(tree: c.Tree, ast: Ast, astParser: c.Tree => Ast) = { | ||
import c.universe.{ Ident => _, _ } | ||
|
||
def toIdent(s: Symbol) = | ||
Ident(s.name.decodedName.toString) | ||
|
||
def origRebind(conv: Tree, orig: Tree, astParser: Tree => Ast) = { | ||
val paramSymbol = conv.symbol.asMethod.paramLists.flatten.head | ||
(toIdent(paramSymbol) -> astParser(orig)) | ||
} | ||
|
||
tree match { | ||
case q"$conv($orig).$method" => | ||
BetaReduction(ast, origRebind(conv, orig, astParser)) | ||
case q"$conv($orig).$m(...$params)" => | ||
val method = | ||
conv.symbol.asMethod.returnType.member(m) | ||
val paramsIdents = | ||
method.asMethod.paramLists.flatten.map(toIdent) | ||
val paramsRebind = | ||
paramsIdents.zip(params.flatten.map(astParser)) | ||
BetaReduction(ast, (origRebind(conv, orig, astParser) +: paramsRebind): _*) | ||
case other => ast | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.