Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/main/scala/viper/carbon/modules/impls/DefaultLoopModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,11 @@ class DefaultLoopModule(val verifier: Verifier) extends LoopModule with StmtComp
}

private def handleWhile(w: sil.While): Stmt = {
val guard = translateExp(w.cond)
val (invs, writtenVars) = getWhileInformation(w)
val guard = translateExp(w.cond)
val (invs, writtenVars) = getWhileInformation(w)

If(
guard,
beforeLoopHead(invs, w.info.getUniqueInfo[LoopInfo].map(loopInfo => loopInfo.head.get)) ++
MaybeCommentBlock("Havoc loop written variables (except locals)",
Havoc((writtenVars map translateExp).asInstanceOf[Seq[Var]]) ++
Expand All @@ -448,10 +450,13 @@ class DefaultLoopModule(val verifier: Verifier) extends LoopModule with StmtComp
stmts
}
)) ++
MaybeCommentBlock("Inhale loop invariant after loop, and assume guard",
Assume(guard.not) ++ stateModule.assumeGoodState ++
inhale(invs map (x => (x, errors.WhileFailed(x)))) ++ executeUnfoldings(invs, (inv => errors.Internal(inv)))
)
MaybeCommentBlock("Unroll last loop iteration; inhale loop invariant and assume guard, execute body and lastly assume !guard",
stateModule.assumeGoodState ++
inhale(invs map (x => (x, errors.WhileFailed(x)))) ++ executeUnfoldings(invs, (inv => errors.Internal(inv))) ++
Assume(guard) ++ MaybeCommentBlock("Translate loop body", stmtModule.translateStmt(w.body)) ++ Assume(guard.not)
),
Statements.EmptyStmt
)
}

override def handleStmt(s: sil.Stmt, statesStackOfPackageStmt: List[Any] = null, allStateAssms: Exp = TrueLit(), insidePackageStmt: Boolean = false): (Seqn => Seqn) = {
Expand Down