Commit 3a6380e3 authored by Arthur Bit-Monnot's avatar Arthur Bit-Monnot

[anml] Manual rewrite of anml actions instead of using landscaper.

While more practical and safer landscaper induces very high compile times
parent a70f61e9
......@@ -3,11 +3,9 @@ package copla.lang.model
import copla.lang.model
import copla.lang.model.common.operators.{BinaryOperator, UnaryOperator}
import scala.annotation.tailrec
package object common {
case class Id(scope: Scope, name: String) {
final case class Id(scope: Scope, name: String) {
override def toString: String = scope.toScopedString(name)
def toTPId = Timepoint(this)
......@@ -37,7 +35,7 @@ package object common {
def toScopedString(name: String): String = s"$this.$name"
}
case class Type(id: Id, parent: Option[Type]) {
final case class Type(id: Id, parent: Option[Type]) {
def isSubtypeOf(typ: Type): Boolean =
this == typ || parent.exists(t => t == typ || t.isSubtypeOf(typ))
......
......@@ -87,14 +87,6 @@ package object core {
require(e.typ.isSubtypeOf(Type.Boolean))
override def toString: String = s"assert($e)"
}
@deprecated
final case class StaticEqualAssertion(left: Term, right: Term) extends StaticAssertion {
override def toString: String = s"$left == $right"
}
@deprecated
final case class StaticDifferentAssertion(left: Term, right: Term) extends StaticAssertion {
override def toString: String = s"$left != $right"
}
final case class StaticAssignmentAssertion(left: BoundConstant, right: Cst)
extends StaticAssertion {
override def toString: String = s"$left := $right"
......
......@@ -2,40 +2,72 @@ package copla.lang.model.transforms
import copla.lang.model.common._
import copla.lang.model.core._
import landscaper.transformations._
object ActionInstantiation {
private[this] object implicits {
type Up[T] = Trans.Aux[Id, Id, T, T]
def instance[T](implicit ev: Up[T]): Up[T] = ev
// // landscaper has problem with the new ADT, provide some help
// implicit val x3 = instance[IntExpr]
// implicit val x4 = instance[TPRef]
// implicit val x5 = instance[TBefore] // ok
// implicit val x6 = instance[StaticAssertion] //ok
// implicit val x7 = instance[ArgDeclaration] //ok
// implicit val x8 = instance[TimedAssignmentAssertion] //ok
// implicit val x9 = instance[TimedEqualAssertion] //ok
// implicit val x10 = instance[TimedTransitionAssertion] //ok
// implicit val x11 = instance[TimedAssertion] //ok
// implicit val x12 = instance[LocalVarDeclaration] //ok
// implicit val x13 = instance[TimepointDeclaration] //ok
//
// // derivation of Trans[Id,Id,InActionBlock] never ends for an obscure reason, dispatch manually
// implicit val main: Up[InActionBlock] = new Trans[Id, Id, InActionBlock] {
// override type Result = InActionBlock
//
// override def rewrite(f: Id => Id, in: InActionBlock): Result = in match {
// case x: TimedAssertion => x11.rewrite(f, x)
// case x: StaticAssertion => x6.rewrite(f, x)
// case x: TBefore => x5.rewrite(f, x)
// case x: ArgDeclaration => x7.rewrite(f, x)
// case x: LocalVarDeclaration => x12.rewrite(f, x)
// case x: TimepointDeclaration => x13.rewrite(f, x)
// }
// }
trait IdRewrite[T] {
/** Transforms a type T, recursively replacing any id: Id in it with f(id) */
def map(a: T, f: Id => Id): T
}
// provides syntax for boilerplate
implicit class Rewrite[T](private val lhs: T) extends AnyVal {
def rw(f: Id => Id)(implicit rewrite: IdRewrite[T]): T = rewrite.map(lhs, f)
}
implicit object ofCst extends IdRewrite[Cst] {
override def map(a: Cst, f: Id => Id): Cst = a match {
case i: IntLiteral => i
case Instance(id, tpe) => Instance(f(id), tpe)
}
}
implicit object ofExpr extends IdRewrite[Expr] {
override def map(a: Expr, f: Id => Id): Expr = a match {
case x: Cst => x.rw(f)
case Arg(id, tpe) => Arg(f(id), tpe)
case LocalVar(id, tpe) => LocalVar(f(id), tpe)
case Op1(op, e) => Op1(op, map(e, f))
case Op2(op, lhs, rhs) => Op2(op, map(lhs, f), map(rhs, f))
}
}
implicit object ofConstantTemplate extends IdRewrite[ConstantTemplate] {
override def map(a: ConstantTemplate, f: Id => Id): ConstantTemplate = a match {
case ConstantTemplate(id, tpe, params) =>
ConstantTemplate(f(id), tpe, params.map { case Arg(id, tpe) => Arg(f(id), tpe)} )
}
}
implicit object ofFluentTemplate extends IdRewrite[FluentTemplate] {
override def map(a: FluentTemplate, f: Id => Id): FluentTemplate = a match {
case FluentTemplate(id, tpe, params) =>
FluentTemplate(f(id), tpe, params.map { case Arg(id, tpe) => Arg(f(id), tpe)} )
}
}
implicit object ofFluent extends IdRewrite[Fluent] {
override def map(a: Fluent, f: Id => Id): Fluent = a match {
case Fluent(template, params) => Fluent(template.rw(f), params.map(_.rw(f)))
}
}
implicit object ofBlock extends IdRewrite[InActionBlock] {
override def map(a: InActionBlock, f: Id => Id): InActionBlock = a match {
case StaticBooleanAssertion(e) => StaticBooleanAssertion(e.rw(f))
case ArgDeclaration(Arg(id, tpe)) => ArgDeclaration(Arg(f(id), tpe))
case LocalVarDeclaration(LocalVar(id, tpe)) => LocalVarDeclaration(LocalVar(f(id), tpe))
case StaticAssignmentAssertion(x: BoundConstant, cst) =>
StaticAssignmentAssertion(new BoundConstant(x.template, x.params.map(_.rw(f))), cst.rw(f))
case TimedAssignmentAssertion(st, ed, fl, value) =>
TimedAssignmentAssertion(st.rw(f), ed.rw(f), fl.rw(f), value.rw(f))
case TimedEqualAssertion(st, ed, fl, value) =>
TimedEqualAssertion(st.rw(f), ed.rw(f), fl.rw(f), value.rw(f))
case TimedTransitionAssertion(st, ed, fl, from, to) =>
TimedTransitionAssertion(st.rw(f), ed.rw(f), fl.rw(f), from.rw(f), to.rw(f))
case BindAssertion(Constant(template, params), LocalVar(id, tpe)) =>
BindAssertion(Constant(template.rw(f), params.map(_.rw(f))), LocalVar(f(id), tpe))
}
}
}
/** Builds a new action instance with the given name*/
......@@ -52,9 +84,7 @@ object ActionInstantiation {
x match { case Id(s, name) => Id(transScope(s), name) }
}
//
???
// val instanceContent = template.content.map(s => implicits.main.rewrite(trans, s))
// Action(instanceScope, instanceContent, template)
val instanceContent = template.content.map(s => implicits.ofBlock.map(s, trans))
Action(instanceScope, instanceContent, template)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment