Skip to content

Commit 79da7d4

Browse files
authored
Merge pull request #572 from viperproject/perm_multiplication
Added support for perm-perm-multiplication
2 parents 15c2047 + 729e85b commit 79da7d4

4 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/main/scala/viper/silver/ast/Expression.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,13 @@ case class PermDiv(left: Exp, right: Exp)(val pos: Position = NoPosition, val in
330330
(if(left.typ != Perm) Seq(ConsistencyError(s"First parameter of permission division expression must be Perm, but found ${left.typ}", left.pos)) else Seq()) ++
331331
(if(right.typ != Int) Seq(ConsistencyError(s"Second parameter of permission division expression must be Int, but found ${right.typ}", right.pos)) else Seq())
332332
}
333+
334+
case class PermPermDiv(left: Exp, right: Exp)(val pos: Position = NoPosition, val info: Info = NoInfo, val errT: ErrorTrafo = NoTrafos) extends DomainBinExp(PermDivOp) with PermExp with ForbiddenInTrigger
335+
{
336+
override lazy val check : Seq[ConsistencyError] =
337+
(if(left.typ != Perm) Seq(ConsistencyError(s"First parameter of permission division expression must be Perm, but found ${left.typ}", left.pos)) else Seq()) ++
338+
(if(right.typ != Perm) Seq(ConsistencyError(s"Second parameter of permission-permission division expression must be Perm, but found ${right.typ}", right.pos)) else Seq())
339+
}
333340
/** The permission currently held for a given resource. */
334341
case class CurrentPerm(res: ResourceAccess)(val pos: Position = NoPosition, val info: Info = NoInfo, val errT: ErrorTrafo = NoTrafos) extends PermExp
335342

src/main/scala/viper/silver/parser/ParseAst.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ class PBinExp(val left: PExp, val opName: String, val right: PExp)(val pos: (Pos
549549
case "/" => List(
550550
Map(POpApp.pArgS(0) -> Int, POpApp.pArgS(1) -> Int, POpApp.pResS -> Perm),
551551
Map(POpApp.pArgS(0) -> Perm, POpApp.pArgS(1) -> Int, POpApp.pResS -> Perm),
552+
Map(POpApp.pArgS(0) -> Perm, POpApp.pArgS(1) -> Perm, POpApp.pResS -> Perm),
552553
Map(POpApp.pArgS(0) -> Int, POpApp.pArgS(1) -> Int, POpApp.pResS -> Int)
553554
)
554555
case "\\" | "%" => List(

src/main/scala/viper/silver/parser/Translator.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,11 @@ case class Translator(program: PProgram) {
290290
case _ => sys.error("should not occur in type-checked program")
291291
}
292292
case "/" =>
293-
assert(r.typ==Int)
294293
l.typ match {
295-
case Perm => PermDiv(l, r)(pos)
294+
case Perm => r.typ match {
295+
case Int => PermDiv(l, r)(pos)
296+
case Perm => PermPermDiv(l, r)(pos)
297+
}
296298
case Int =>
297299
assert (r.typ==Int)
298300
if (ttyp(pbe.typ) == Int)

src/test/resources/all/basic/arithmetic.vpr

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,17 @@ method t6() {
4545
//:: ExpectedOutput(assert.failed:assertion.false)
4646
assert 2/3 == 3/4 // / is interpreted as Perm-typed division
4747
}
48+
49+
method t6(p: Perm)
50+
{
51+
var r1 : Perm
52+
var r2: Perm
53+
var one: Perm
54+
one := 1/1
55+
r1 := p * one
56+
r2 := p * (2/1)
57+
assert r1 == p
58+
assert r2 - r1 == p
59+
//:: ExpectedOutput(assert.failed:assertion.false)
60+
assert r2 == p
61+
}

0 commit comments

Comments
 (0)