Skip to content

Commit d6008c5

Browse files
authored
Merge pull request #389 from viperproject/ast-loops
Add support for loops formed via gotos
2 parents dbed9ab + 5ba5f53 commit d6008c5

12 files changed

Lines changed: 930 additions & 130 deletions

src/main/scala/viper/carbon/CarbonVerifier.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ case class CarbonVerifier(override val reporter: Reporter,
6161
val setModule = new DefaultSetModule(this)
6262
val mapModule = new DefaultMapModule(this)
6363
val wandModule = new DefaultWandModule(this)
64+
val loopModule = new DefaultLoopModule(this)
6465

6566
// initialize all modules
6667
allModules foreach (m => {

src/main/scala/viper/carbon/modules/HeapModule.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ import viper.silver.ast.{LocationAccess, MagicWand}
1717
*/
1818
trait HeapModule extends Module with CarbonStateComponent {
1919

20+
/**
21+
* The type used for heaps
22+
*/
23+
def heapType: Type
24+
2025
/**
2126
* The type used for references.
2227
*/
@@ -172,4 +177,8 @@ trait HeapModule extends Module with CarbonStateComponent {
172177

173178
// adds permission to field e to the secondary mask of the wand
174179
def addPermissionToWMask(wMask: Exp, e: sil.Exp): Stmt
180+
181+
// If expression evaluates to true then resultHeap is the sum of of heap1, where mask1 is defined,
182+
// and heap2, where mask2 is defined.
183+
def sumHeap(resultHeap: Exp, heap1: Exp, mask1: Exp, heap2: Exp, mask2: Exp): Exp
175184
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package viper.carbon.modules
2+
3+
import viper.silver.{ast => sil}
4+
5+
trait LoopModule extends Module {
6+
7+
/* Returns method annotated with loop information and initializes loop module accordingly.
8+
* This must be called before starting the method translation and the returned method should be used for the
9+
* translation.
10+
*/
11+
def initializeMethod(m: sil.Method): sil.Method
12+
13+
// Return true iff the statement is solely used for the loop module itself and is irrelevant otherwise.
14+
def isLoopDummyStmt(s: sil.Stmt) : Boolean
15+
16+
// Return true iff the axioms to sum states is required.
17+
def sumOfStatesAxiomRequired : Boolean
18+
}

src/main/scala/viper/carbon/modules/PermModule.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ trait PermModule extends Module with CarbonStateComponent {
8383
*/
8484
def wandMaskField(wand: Exp): Exp
8585

86+
/**
87+
* The type used for masks.
88+
*/
89+
def maskType: Type
90+
8691
/**
8792
* The type used to for predicate masks.
8893
*/
@@ -114,8 +119,24 @@ trait PermModule extends Module with CarbonStateComponent {
114119
def sumMask(assmsToSmt: Exp => Stmt):Stmt
115120
*/
116121

122+
/**
123+
*
124+
* @param summandMask1
125+
* @param summandMask2
126+
* @return expression for which its validity implies that the current mask is the sum of the two input masks
127+
*/
117128
def sumMask(summandMask1: Seq[Exp], summandMask2: Seq[Exp]): Exp
118129

130+
/**
131+
*
132+
* @param resultMask
133+
* @param summandMask1
134+
* @param summandMask2
135+
* @return expression for which its validity implies that @{code resultMask} is the sum of the other two input
136+
* masks
137+
*/
138+
def sumMask(resultMask: Seq[Exp], summandMask1: Seq[Exp], summandMask2: Seq[Exp]) : Exp
139+
119140
/** returns a mask and the returned statement ensures that the mask has non-zero permission at rcv.loc and zero
120141
* permission at all other location
121142
* this should only be used temporarily, i.e. if there are two calls to this then the previous tempMask returned

src/main/scala/viper/carbon/modules/StmtModule.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package viper.carbon.modules
88

99
import viper.carbon.modules.components.{ComponentRegistry, StmtComponent}
1010
import viper.silver.{ast => sil}
11-
import viper.carbon.boogie.{Exp, Stmt, TrueLit}
11+
import viper.carbon.boogie.{Exp, Namespace, Stmt, TrueLit}
1212

1313
/**
1414
* A module for translating Viper statements.
@@ -33,5 +33,5 @@ trait StmtModule extends Module with ComponentRegistry[StmtComponent] {
3333

3434
def translateStmt(stmt: sil.Stmt, statesStackForPackageStmt: List[Any] = null, allStateAssms: Exp = TrueLit(), insidePackageStmt: Boolean = false): Stmt
3535

36-
36+
def labelNamespace: Namespace
3737
}

src/main/scala/viper/carbon/modules/impls/DefaultHeapModule.scala

Lines changed: 199 additions & 74 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)