@@ -165,6 +165,15 @@ abstract class GenericTriggerGenerator[Node <: AnyRef,
165165 val nestedBoundVars : Seq [Var ] =
166166 deepCollect(toSearch){ case qe : Quantification => Quantification_vars (qe)}.flatten
167167
168+ val additionalRelevantVars : Seq [Var ] = {
169+ val additionalVarFinder = additionalRelevantVariables(vs, nestedBoundVars)
170+ deepCollect(toSearch){
171+ case n if additionalVarFinder.isDefinedAt(n) => additionalVarFinder(n)
172+ }.flatten
173+ }
174+ val allRelevantVars = (vs ++ additionalRelevantVars).distinct
175+ val modifyTriggers = modifyPossibleTriggers(allRelevantVars)
176+
168177 /* Get all function applications */
169178 reduceTree(toSearch)((node : Node , results : Seq [Seq [(PossibleTrigger , Seq [Var ], Seq [Var ])]]) => node match {
170179 case possibleTrigger : PossibleTrigger if isPossibleTrigger(possibleTrigger) =>
@@ -187,15 +196,15 @@ abstract class GenericTriggerGenerator[Node <: AnyRef,
187196 processedArgs foreach (arg => visit(arg) {
188197 case v : Var =>
189198 if (nestedBoundVars.contains(v)) containsNestedBoundVars = true
190- if (vs .contains(v)) containedVars +:= v
199+ if (allRelevantVars .contains(v)) containedVars +:= v
191200 })
192201
193202 if (! containsNestedBoundVars && containedVars.nonEmpty)
194203 results.flatten ++ Seq ((withArgs(possibleTrigger, processedArgs), containedVars, extraVars))
195204 else
196205 results.flatten
197206
198- case e if modifyPossibleTriggers .isDefinedAt(e) => modifyPossibleTriggers .apply(e)(results)
207+ case e if modifyTriggers .isDefinedAt(e) => modifyTriggers .apply(e)(results)
199208
200209 case _ => results.flatten
201210 })
@@ -205,9 +214,14 @@ abstract class GenericTriggerGenerator[Node <: AnyRef,
205214 * Hook for clients to add more cases to getFunctionAppsContaining to modify the found possible triggers.
206215 * Used e.g. to wrap trigger expressions inferred from inside old-expression into old()
207216 */
208- def modifyPossibleTriggers : PartialFunction [Node , Seq [Seq [(PossibleTrigger , Seq [Var ], Seq [Var ])]] =>
217+ def modifyPossibleTriggers ( relevantVars : Seq [ Var ]) : PartialFunction [Node , Seq [Seq [(PossibleTrigger , Seq [Var ], Seq [Var ])]] =>
209218 Seq [(PossibleTrigger , Seq [Var ], Seq [Var ])]] = PartialFunction .empty
210219
220+ /*
221+ * Hook for clients to identify additional variables which can be covered by triggers.
222+ */
223+ def additionalRelevantVariables (relevantVars : Seq [Var ], varsToAvoid : Seq [Var ]): PartialFunction [Node , Seq [Var ]] = PartialFunction .empty
224+
211225 /* Precondition: if vars is non-empty then every (f,vs) pair in functs
212226 * satisfies the property that vars and vs are not disjoint.
213227 *
0 commit comments