diff --git a/src/funcheck/CodeExtraction.scala b/src/funcheck/CodeExtraction.scala index c8c887a13fbbb04b8489bb0dce531f355616343b..83fa2d6083cecfe76b9d999029ba9eea87887357 100644 --- a/src/funcheck/CodeExtraction.scala +++ b/src/funcheck/CodeExtraction.scala @@ -366,6 +366,26 @@ trait CodeExtraction extends Extractors { val underlying = scalaType2PureScala(unit, silent)(tt.tpe) 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) => { val rl = rec(t1) val rr = rec(t2) diff --git a/src/funcheck/Extractors.scala b/src/funcheck/Extractors.scala index da04302b6845bc2e7341cf85d0ab4b051caf633f..1081ec2a54557e16294a410b8ab8abdf99e28304 100644 --- a/src/funcheck/Extractors.scala +++ b/src/funcheck/Extractors.scala @@ -304,6 +304,24 @@ trait Extractors { 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 { def unapply(tree: TypeApply): Option[Tree] = tree match { case TypeApply( diff --git a/src/purescala/Definitions.scala b/src/purescala/Definitions.scala index 42e2807c543a02ce93228ce7c4d1367f3087dc50..9178793628043498e6ca754df06e951abe461a2d 100644 --- a/src/purescala/Definitions.scala +++ b/src/purescala/Definitions.scala @@ -20,7 +20,20 @@ object Definitions { /** 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. */ - 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 * val's. */ @@ -86,5 +99,9 @@ object Definitions { var body: Option[Expr] = None var precondition: Option[Expr] = None var postcondition: Option[Expr] = None + + def hasImplementation : Boolean = body.isDefined + def hasPrecondition : Boolean = precondition.isDefined + def hasPostcondition : Boolean = postcondition.isDefined } } diff --git a/src/purescala/PrettyPrinter.scala b/src/purescala/PrettyPrinter.scala index 4e312210afb5ce79e84d684e094cb54df27f76e1..f273e877f896dfaa2c69210406d2561ab96f9872 100644 --- a/src/purescala/PrettyPrinter.scala +++ b/src/purescala/PrettyPrinter.scala @@ -103,6 +103,8 @@ object PrettyPrinter { case GreaterEquals(l,r) => ppBinary(sb, l, r, " \u2265 ", lvl) // \geq case FiniteSet(rs) => ppNary(sb, rs, "{", ", ", "}", lvl) 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 SetDifference(l,r) => ppBinary(sb, l, r, " \\ ", lvl) case SetIntersection(l,r) => ppBinary(sb, l, r, " \u2229 ", lvl) // \cap