Skip to content
Snippets Groups Projects
Commit 9b8f0149 authored by Philippe Suter's avatar Philippe Suter
Browse files

laptop changes

parent 106df9ab
No related branches found
No related tags found
No related merge requests found
......@@ -160,12 +160,19 @@ trait CodeExtraction extends Extractors {
case None => Variable(id)
}
case ExAnd(l, r) => And(rec(l), rec(r))
case ExOr(l, r) => Or(rec(l), rec(r))
case ExNot(e) => Not(rec(e))
case ExUMinus(e) => UMinus(rec(e))
case ExPlus(l, r) => Plus(rec(l), rec(r))
case ExMinus(l, r) => Minus(rec(l), rec(r))
case ExTimes(l, r) => Times(rec(l), rec(r))
case ExDiv(l, r) => Division(rec(l), rec(r))
case ExEquals(l, r) => Equals(rec(l), rec(r))
case ExGreaterThan(l, r) => GreaterThan(rec(l), rec(r))
case ExGreaterEqThan(l, r) => GreaterEquals(rec(l), rec(r))
case ExLessThan(l, r) => LessThan(rec(l), rec(r))
case ExLessEqThan(l, r) => LessEquals(rec(l), rec(r))
case ExIfThenElse(t1,t2,t3) => IfExpr(rec(t1), rec(t2), rec(t3))
// default behaviour is to complain :)
case _ => {
......@@ -184,10 +191,13 @@ trait CodeExtraction extends Extractors {
tree match {
case tt: TypeTree if tt.tpe == IntClass.tpe => Int32Type
case tt: TypeTree if tt.tpe == BooleanClass.tpe => BooleanType
case tt: TypeTree => tt.tpe match {
case TypeRef(_,sym,_) if sym == setTraitSym => XXXXXX
}
case _ => {
case tt => {
if(!silent) {
unit.error(tree.pos, "Could not extract type as PureScala.")
unit.error(tree.pos, "Could not extract type as PureScala. [" + tt + "]")
}
throw ImpureCodeEncounteredException(tree)
}
......
......@@ -105,6 +105,13 @@ trait Extractors {
}
object ExpressionExtractors {
object ExIfThenElse {
def unapply(tree: Tree): Option[(Tree,Tree,Tree)] = tree match {
case If(t1,t2,t3) => Some((t1,t2,t3))
case _ => None
}
}
object ExBooleanLiteral {
def unapply(tree: Tree): Option[Boolean] = tree match {
case Literal(Constant(true)) => Some(true)
......@@ -199,12 +206,40 @@ trait Extractors {
}
}
object ExUMinus {
def unapply(tree: Tree): Option[Tree] = tree match {
case Select(t, n) if (n == nme.UNARY_-) => Some(t)
case _ => None
}
}
object ExPlus {
def unapply(tree: Tree): Option[(Tree,Tree)] = tree match {
case Apply(Select(lhs, n), List(rhs)) if (n == nme.ADD) => Some((lhs,rhs))
case _ => None
}
}
object ExMinus {
def unapply(tree: Tree): Option[(Tree,Tree)] = tree match {
case Apply(Select(lhs, n), List(rhs)) if (n == nme.SUB) => Some((lhs,rhs))
case _ => None
}
}
object ExTimes {
def unapply(tree: Tree): Option[(Tree,Tree)] = tree match {
case Apply(Select(lhs, n), List(rhs)) if (n == nme.MUL) => Some((lhs,rhs))
case _ => None
}
}
object ExDiv {
def unapply(tree: Tree): Option[(Tree,Tree)] = tree match {
case Apply(Select(lhs, n), List(rhs)) if (n == nme.DIV) => Some((lhs,rhs))
case _ => None
}
}
}
object TypeExtractors {
......
......@@ -67,6 +67,7 @@ object PrettyPrinter {
case Or(exprs) => ppNary(sb, exprs, " \u2228 ") // \lor
case Not(Equals(l, r)) => ppBinary(sb, l, r, " \u2260 ") // \neq
case Not(expr) => ppUnary(sb, expr, "\u00AC") // \neg
case UMinus(expr) => ppUnary(sb, expr, "-")
case Equals(l,r) => ppBinary(sb, l, r, " == ")
case IntLiteral(v) => sb.append(v)
case BooleanLiteral(v) => sb.append(v)
......
......@@ -43,6 +43,15 @@ object Trees {
}
}
case object Or {
def apply(l: Expr, r: Expr): Expr = (l,r) match {
case (Or(exs1), Or(exs2)) => Or(exs1 ++ exs2)
case (Or(exs1), ex2) => Or(exs1 :+ ex2)
case (ex1, Or(exs2)) => Or(exs2 :+ ex1)
case (ex1, ex2) => Or(List(ex1, ex2))
}
}
case class And(exprs: Seq[Expr]) extends Expr
case class Or(exprs: Seq[Expr]) extends Expr
case class Not(expr: Expr) extends Expr
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment