Skip to content

Commit

Permalink
Inhaling and ensuring the idle token for the default constructor of r…
Browse files Browse the repository at this point in the history
…unnable classes (fix #646).
  • Loading branch information
raulmonti committed Jul 7, 2021
2 parents 3993a9b + 34d711e commit 2c67111
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/main/java/vct/col/rewrite/AddZeroConstructor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import vct.col.ast.stmt.decl.{ASTClass, ASTSpecial, DeclarationStatement, Method
import vct.col.ast.util.{AbstractRewriter, ContractBuilder}
import vct.col.ast.stmt.decl.ASTSpecial

import scala.collection.convert.ImplicitConversions.`collection asJava`
import scala.jdk.CollectionConverters._

object AddZeroConstructor {
Expand All @@ -24,15 +25,17 @@ case class AddZeroConstructor(override val source: ProgramUnit) extends Abstract
val cb = new ContractBuilder
val body = create.block()

for(field <- cls.dynamicFields.asScala) {
for (field <- cls.dynamicFields.asScala) {
val init = field.`type`.zero
val fieldNode = create.dereference (create.diz(), field.name)
val fieldNode = create.dereference(create.diz(), field.name)
body.addStatement(create assignment(fieldNode, init))
cb.ensures(create.expression(StandardOperator.PointsTo, fieldNode, create.fullPermission(), init))
}

body.append(create.special(ASTSpecial.Kind.Inhale, create.invokation(create.diz, null, "idleToken")))
cb.ensures(create.invokation(create.diz, null, "idleToken"));
if(cls.methods().asScala.map(_.name).contains("run")) {
body.append(create.special(ASTSpecial.Kind.Inhale, create.invokation(create.diz, null, "idleToken")))
cb.ensures(create.invokation(create.diz, null, "idleToken"));
}

val res = create method_kind(
Method.Kind.Constructor,
Expand Down

0 comments on commit 2c67111

Please sign in to comment.