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

No commit message

No commit message
parent 1ec8524a
Branches
Tags
No related merge requests found
...@@ -366,6 +366,26 @@ trait CodeExtraction extends Extractors { ...@@ -366,6 +366,26 @@ trait CodeExtraction extends Extractors {
val underlying = scalaType2PureScala(unit, silent)(tt.tpe) val underlying = scalaType2PureScala(unit, silent)(tt.tpe)
EmptySet(underlying).setType(SetType(underlying)) EmptySet(underlying).setType(SetType(underlying))
} }
case ExSetMin(t) => {
val set = rec(t)
if(!set.getType.isInstanceOf[SetType]) {
if(!silent) {
unit.error(t.pos, "Min should be computed on a set.")
}
throw ImpureCodeEncounteredException(tree)
}
SetMin(set).setType(set.getType.asInstanceOf[SetType].base)
}
case ExSetMax(t) => {
val set = rec(t)
if(!set.getType.isInstanceOf[SetType]) {
if(!silent) {
unit.error(t.pos, "Max should be computed on a set.")
}
throw ImpureCodeEncounteredException(tree)
}
SetMax(set).setType(set.getType.asInstanceOf[SetType].base)
}
case ExUnion(t1,t2) => { case ExUnion(t1,t2) => {
val rl = rec(t1) val rl = rec(t1)
val rr = rec(t2) val rr = rec(t2)
......
...@@ -304,6 +304,24 @@ trait Extractors { ...@@ -304,6 +304,24 @@ trait Extractors {
if(tree != null) Some((tree.selector, tree.cases)) else None if(tree != null) Some((tree.selector, tree.cases)) else None
} }
object ExSetMin {
def unapply(tree: Apply) : Option[Tree] = tree match {
case Apply(
TypeApply(Select(setTree, minName), typeTree :: Nil),
ordering :: Nil) if minName.toString == "min" && typeTree.tpe == IntClass.tpe => Some(setTree)
case _ => None
}
}
object ExSetMax {
def unapply(tree: Apply) : Option[Tree] = tree match {
case Apply(
TypeApply(Select(setTree, maxName), typeTree :: Nil),
ordering :: Nil) if maxName.toString == "max" && typeTree.tpe == IntClass.tpe => Some(setTree)
case _ => None
}
}
object ExEmptySet { object ExEmptySet {
def unapply(tree: TypeApply): Option[Tree] = tree match { def unapply(tree: TypeApply): Option[Tree] = tree match {
case TypeApply( case TypeApply(
......
...@@ -20,7 +20,20 @@ object Definitions { ...@@ -20,7 +20,20 @@ object Definitions {
/** A wrapper for a program. For now a program is simply a single object. The /** A wrapper for a program. For now a program is simply a single object. The
* name is meaningless and we just use the package name as id. */ * name is meaningless and we just use the package name as id. */
case class Program(id: Identifier, mainObject: ObjectDef) extends Definition case class Program(id: Identifier, mainObject: ObjectDef) extends Definition {
lazy val callGraph: Map[FunDef,Seq[FunDef]] = computeCallGraph
def computeCallGraph: Map[FunDef,Seq[FunDef]] = Map.empty
// checks whether f2 can be called from f1
def calls(f1: FunDef, f2: FunDef) : Boolean = {
false
}
def transitivelyCalls(f1: FunDef, f2: FunDef) : Boolean = {
false
}
}
/** Objects work as containers for class definitions, functions (def's) and /** Objects work as containers for class definitions, functions (def's) and
* val's. */ * val's. */
...@@ -86,5 +99,9 @@ object Definitions { ...@@ -86,5 +99,9 @@ object Definitions {
var body: Option[Expr] = None var body: Option[Expr] = None
var precondition: Option[Expr] = None var precondition: Option[Expr] = None
var postcondition: Option[Expr] = None var postcondition: Option[Expr] = None
def hasImplementation : Boolean = body.isDefined
def hasPrecondition : Boolean = precondition.isDefined
def hasPostcondition : Boolean = postcondition.isDefined
} }
} }
...@@ -103,6 +103,8 @@ object PrettyPrinter { ...@@ -103,6 +103,8 @@ object PrettyPrinter {
case GreaterEquals(l,r) => ppBinary(sb, l, r, " \u2265 ", lvl) // \geq case GreaterEquals(l,r) => ppBinary(sb, l, r, " \u2265 ", lvl) // \geq
case FiniteSet(rs) => ppNary(sb, rs, "{", ", ", "}", lvl) case FiniteSet(rs) => ppNary(sb, rs, "{", ", ", "}", lvl)
case EmptySet(_) => sb.append("\u2205") // Ø case EmptySet(_) => sb.append("\u2205") // Ø
case SetMin(s) => pp(s, sb, lvl).append(".min")
case SetMax(s) => pp(s, sb, lvl).append(".max")
case SetUnion(l,r) => ppBinary(sb, l, r, " \u222A ", lvl) // \cup case SetUnion(l,r) => ppBinary(sb, l, r, " \u222A ", lvl) // \cup
case SetDifference(l,r) => ppBinary(sb, l, r, " \\ ", lvl) case SetDifference(l,r) => ppBinary(sb, l, r, " \\ ", lvl)
case SetIntersection(l,r) => ppBinary(sb, l, r, " \u2229 ", lvl) // \cap case SetIntersection(l,r) => ppBinary(sb, l, r, " \u2229 ", lvl) // \cap
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment