Skip to content

Commit

Permalink
Cleaner implementation of fix for issue #740
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoeilers committed Oct 18, 2023
1 parent 09956be commit a48b4a0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package viper.silver.ast.utility

import java.util.concurrent.atomic.AtomicInteger
import reflect.ClassTag
import viper.silver.ast

object GenericTriggerGenerator {
case class TriggerSet[E](exps: Seq[E])
Expand Down Expand Up @@ -195,10 +196,19 @@ abstract class GenericTriggerGenerator[Node <: AnyRef,
else
results.flatten

case e if modifyPossibleTriggers.isDefinedAt(e) => modifyPossibleTriggers.apply(e)(results)

case _ => results.flatten
})
}

/*
* Hook for clients to add more cases to getFunctionAppsContaining to modify the found possible triggers.
* Used e.g. to wrap trigger expressions inferred from inside old-expression into old()
*/
def modifyPossibleTriggers: PartialFunction[Node, Seq[Seq[(PossibleTrigger, Seq[Var], Seq[Var])]] =>
Seq[(PossibleTrigger, Seq[Var], Seq[Var])]] = PartialFunction.empty

/* Precondition: if vars is non-empty then every (f,vs) pair in functs
* satisfies the property that vars and vs are not disjoint.
*
Expand Down
13 changes: 13 additions & 0 deletions src/main/scala/viper/silver/ast/utility/Triggers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ object Triggers {
case LabelledOld(pt: PossibleTrigger, _) => pt.getArgs
case _ => sys.error(s"Unexpected expression $e")
}

override def modifyPossibleTriggers = {
case ast.Old(_) => results =>
results.flatten.map(t => {
val exp = t._1
(ast.Old(exp)(exp.pos, exp.info, exp.errT), t._2, t._3)
})
case ast.LabelledOld(_, l) => results =>
results.flatten.map(t => {
val exp = t._1
(ast.LabelledOld(exp, l)(exp.pos, exp.info, exp.errT), t._2, t._3)
})
}
}

/**
Expand Down

0 comments on commit a48b4a0

Please sign in to comment.