Skip to content
Snippets Groups Projects
Commit e00949f0 authored by Mikaël Mayer's avatar Mikaël Mayer Committed by Ravi
Browse files

Added ExprOps.explainTyping to explain the typing of an expression.

parent a2280006
No related branches found
No related tags found
No related merge requests found
...@@ -2187,4 +2187,16 @@ object ExprOps extends GenTreeOps[Expr] { ...@@ -2187,4 +2187,16 @@ object ExprOps extends GenTreeOps[Expr] {
/** Returns true if expr is a value. Stronger than isGround */ /** Returns true if expr is a value. Stronger than isGround */
val isValue = (e: Expr) => isValueOfType(e, e.getType) val isValue = (e: Expr) => isValueOfType(e, e.getType)
/** Returns a nested string explaining why this expression is typed the way it is.*/
def explainTyping(e: Expr): String = {
leon.purescala.ExprOps.fold[String]{ (e, se) =>
e match {
case FunctionInvocation(tfd, args) =>
s"$e is of type ${e.getType}" + se.map(child => "\n " + "\n".r.replaceAllIn(child, "\n ")).mkString + s" because ${tfd.fd.id.name} was instantiated with ${tfd.fd.tparams.zip(args).map(k => k._1 +":="+k._2).mkString(",")} with type ${tfd.fd.params.map(_.getType).mkString(",")} => ${tfd.fd.returnType}"
case e =>
s"$e is of type ${e.getType}" + se.map(child => "\n " + "\n".r.replaceAllIn(child, "\n ")).mkString
}
}(e)
}
} }
...@@ -224,11 +224,7 @@ class TemplateGenerator[T](val theories: TheoryEncoder, ...@@ -224,11 +224,7 @@ class TemplateGenerator[T](val theories: TheoryEncoder,
// id => expr && ... && expr // id => expr && ... && expr
var guardedExprs = Map[Identifier, Seq[Expr]]() var guardedExprs = Map[Identifier, Seq[Expr]]()
def storeGuarded(guardVar: Identifier, expr: Expr) : Unit = { def storeGuarded(guardVar: Identifier, expr: Expr) : Unit = {
assert(expr.getType == BooleanType, expr.asString(Program.empty)(LeonContext.empty) + " is not of type Boolean. " + ( assert(expr.getType == BooleanType, expr.asString(Program.empty)(LeonContext.empty) + " is not of type Boolean. " + purescala.ExprOps.explainTyping(expr))
purescala.ExprOps.fold[String]{ (e, se) =>
s"$e is of type ${e.getType}" + se.map(child => "\n " + "\n".r.replaceAllIn(child, "\n ")).mkString
}(expr)
))
val prev = guardedExprs.getOrElse(guardVar, Nil) val prev = guardedExprs.getOrElse(guardVar, Nil)
guardedExprs += guardVar -> (expr +: prev) guardedExprs += guardVar -> (expr +: prev)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment