All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
encrywm.frontend.semantics.Transformer.scala Maven / Gradle / Ivy
package encrywm.frontend.semantics
import encrywm.ast.Ast.EXPR
import encrywm.ast.{Ast, AstNodeScanner}
import encrywm.lib.Types.{ESList, ESOption}
import org.bitbucket.inkytonik.kiama.rewriting.Rewriter._
object Transformer extends AstNodeScanner {
override def scan(node: Ast.AST_NODE): Ast.AST_NODE = rewrite(manytd(strategy[Ast.AST_NODE]({
// Rule: Call(Attribute(coll, "exists"), Func) -> Exists(coll, Func)
case EXPR.Call(EXPR.Attribute(value, attr, _, _), args, _, _)
if value.tpeOpt.get.isCollection &&
attr.name == "exists" &&
args.size == 1 &&
args.head.tpeOpt.get.isFunc =>
Some(EXPR.Exists(value, args.head))
// Rule: Call(Attribute(coll, "map"), Func) -> Map(coll, Func)
case EXPR.Call(EXPR.Attribute(value, attr, _, _), args, _, Some(tpe))
if value.tpeOpt.get.isCollection &&
attr.name == "map" &&
args.size == 1 &&
args.head.tpeOpt.get.isFunc =>
Some(EXPR.Map(value, args.head, Some(tpe)))
// Rule: Attribute(coll, "size") -> SizeOf(coll)
case EXPR.Attribute(value, attr, _, _)
if value.tpeOpt.get.isCollection && attr.name == "size" =>
Some(EXPR.SizeOf(value))
// Rule: Attribute(coll, "sum") -> SizeOf(coll)
case EXPR.Attribute(value, attr, _, _)
if value.tpeOpt.get.isCollection && attr.name == "sum" =>
value.tpeOpt match {
case Some(ESList(valT)) =>
Some(EXPR.Sum(value, Some(valT)))
case _ => None
}
// Rule: Attribute(option, "isDefined") -> IsDefined(option)
case EXPR.Attribute(value, attr, _, _)
if value.tpeOpt.get.isOption && attr.name == "isDefined" =>
Some(EXPR.IsDefined(value))
// Rule: Attribute(option, "get") -> Get(option)
case EXPR.Attribute(value, attr, _, _) if attr.name == "get" =>
value.tpeOpt.get match {
case ESOption(inT) => Some(EXPR.Get(value, Some(inT)))
case _ => None
}
case _ => None
})))(node)
}