@@ -10,7 +10,7 @@ import viper.silicon.common.collections.immutable.InsertionOrderedSet
1010import viper .silicon .Stack
1111import viper .silicon .state .terms ._
1212import viper .silicon .utils .Counter
13-
13+ import viper . silver . ast
1414/*
1515 * Interfaces
1616 */
@@ -22,6 +22,7 @@ import viper.silicon.utils.Counter
2222
2323trait RecordedPathConditions {
2424 def branchConditions : Stack [Term ]
25+ def branchConditionExps : Stack [Option [ast.Exp ]]
2526 def assumptions : InsertionOrderedSet [Term ]
2627 def declarations : InsertionOrderedSet [Decl ]
2728
@@ -39,7 +40,7 @@ trait RecordedPathConditions {
3940}
4041
4142trait PathConditionStack extends RecordedPathConditions {
42- def setCurrentBranchCondition (condition : Term ): Unit
43+ def setCurrentBranchCondition (condition : Term , conditionExp : Option [ast. Exp ] ): Unit
4344 def add (assumption : Term ): Unit
4445 def add (declaration : Decl ): Unit
4546 def pushScope (): Unit
@@ -59,11 +60,13 @@ private class PathConditionStackLayer
5960 extends Cloneable {
6061
6162 private var _branchCondition : Option [Term ] = None
63+ private var _branchConditionExp : Option [Option [ast.Exp ]] = None
6264 private var _globalAssumptions : InsertionOrderedSet [Term ] = InsertionOrderedSet .empty
6365 private var _nonGlobalAssumptions : InsertionOrderedSet [Term ] = InsertionOrderedSet .empty
6466 private var _declarations : InsertionOrderedSet [Decl ] = InsertionOrderedSet .empty
6567
6668 def branchCondition : Option [Term ] = _branchCondition
69+ def branchConditionExp : Option [Option [ast.Exp ]] = _branchConditionExp
6770 def globalAssumptions : InsertionOrderedSet [Term ] = _globalAssumptions
6871 def nonGlobalAssumptions : InsertionOrderedSet [Term ] = _nonGlobalAssumptions
6972 def declarations : InsertionOrderedSet [Decl ] = _declarations
@@ -79,6 +82,14 @@ private class PathConditionStackLayer
7982 _branchCondition = Some (condition)
8083 }
8184
85+ def branchConditionExp_= (condition : Option [ast.Exp ]): Unit = {
86+ assert(_branchConditionExp.isEmpty,
87+ s " Branch condition is already set (to ${_branchConditionExp.get}), "
88+ + s " won't override (with $condition). " )
89+
90+ _branchConditionExp = Some (condition)
91+ }
92+
8293 def add (assumption : Term ): Unit = {
8394 assert(
8495 ! assumption.isInstanceOf [And ],
@@ -116,6 +127,9 @@ private trait LayeredPathConditionStackLike {
116127 protected def branchConditions (layers : Stack [PathConditionStackLayer ]): Stack [Term ] =
117128 layers.flatMap(_.branchCondition)
118129
130+ protected def branchConditionExps (layers : Stack [PathConditionStackLayer ]): Stack [Option [ast.Exp ]] =
131+ layers.flatMap(_.branchConditionExp)
132+
119133 protected def assumptions (layers : Stack [PathConditionStackLayer ]): InsertionOrderedSet [Term ] =
120134 InsertionOrderedSet (layers.flatMap(_.assumptions)) // Note: Performance?
121135
@@ -175,6 +189,7 @@ private class DefaultRecordedPathConditions(from: Stack[PathConditionStackLayer]
175189 with RecordedPathConditions {
176190
177191 val branchConditions : Stack [Term ] = branchConditions(from)
192+ val branchConditionExps : Stack [Option [ast.Exp ]] = branchConditionExps(from)
178193 val assumptions : InsertionOrderedSet [Term ] = assumptions(from)
179194 val declarations : InsertionOrderedSet [Decl ] = declarations(from)
180195
@@ -209,10 +224,11 @@ private[decider] class LayeredPathConditionStack
209224
210225 pushScope() /* Create an initial layer on the stack */
211226
212- def setCurrentBranchCondition (condition : Term ): Unit = {
227+ def setCurrentBranchCondition (condition : Term , conditionExp : Option [ast. Exp ] ): Unit = {
213228 /* TODO: Split condition into top-level conjuncts as well? */
214229
215230 layers.head.branchCondition = condition
231+ layers.head.branchConditionExp = conditionExp
216232 }
217233
218234 def add (assumption : Term ): Unit = {
@@ -275,6 +291,8 @@ private[decider] class LayeredPathConditionStack
275291
276292 def branchConditions : Stack [Term ] = layers.flatMap(_.branchCondition)
277293
294+ override def branchConditionExps : Stack [Option [ast.Exp ]] = layers.flatMap(_.branchConditionExp)
295+
278296 def assumptions : InsertionOrderedSet [Term ] = allAssumptions
279297
280298 def declarations : InsertionOrderedSet [Decl ] =
0 commit comments