Skip to content
Snippets Groups Projects
Commit 87d5bd38 authored by Loïc Correnson's avatar Loïc Correnson
Browse files

[wp] use funbehavior in modes

parent 7e00d91d
No related branches found
No related tags found
No related merge requests found
...@@ -40,48 +40,38 @@ type assigns = WpPropId.assigns_full_info ...@@ -40,48 +40,38 @@ type assigns = WpPropId.assigns_full_info
(* -------------------------------------------------------------------------- *) (* -------------------------------------------------------------------------- *)
type mode = { type mode = {
bhv : string option ; (* Selected behavior (None is default) *) bhv : funbehavior ; (* Selected behavior (None is default) *)
stmt : stmt option ; (* Stmt contract under proof *) stmt : stmt option ; (* Stmt contract under proof *)
} }
let default_mode = { bhv = None ; stmt = None }
let get_modes kf = let get_modes kf =
default_mode :: Annotations.fold_behaviors
begin (fun _emitter bhv ms -> { bhv ; stmt = None } :: ms)
Annotations.fold_behaviors kf @@
(fun _emitter b ms -> { bhv = Some b.b_name ; stmt = None } :: ms) List.fold_right
kf @@ (fun stmt ms ->
List.fold_right Annotations.fold_code_annot (fun _emitter ca ms ->
(fun stmt ms -> match ca.annot_content with
Annotations.fold_code_annot (fun _emitter ca ms -> | AStmtSpec(_, { spec_behavior = bs } ) ->
match ca.annot_content with List.fold_right (fun bhv ms -> {
| AStmtSpec(_, { spec_behavior = bs } ) -> bhv ;
{ bhv = None ; stmt = Some stmt } :: stmt = Some stmt ;
List.fold_right (fun b ms -> { }::ms) bs ms
bhv = Some b.b_name ; | _ -> ms
stmt = Some stmt ; ) stmt ms
}::ms) bs ms ) (Kernel_function.get_definition kf).sallstmts []
| _ -> ms
) stmt ms
) (Kernel_function.get_definition kf).sallstmts []
end
(* -------------------------------------------------------------------------- *) (* -------------------------------------------------------------------------- *)
(* --- Property Selection by Mode --- *) (* --- Property Selection by Mode --- *)
(* -------------------------------------------------------------------------- *) (* -------------------------------------------------------------------------- *)
let is_default (m: mode) = m.bhv = None let is_default_bhv (m: mode) = Cil.is_default_behavior m.bhv
let is_selected_bhv (m: mode) (bhv: funbehavior) = let is_selected_bhv (m: mode) (bhv: funbehavior) =
match m.bhv with m.bhv.b_name = bhv.b_name
| None -> Cil.is_default_behavior bhv
| Some b -> b = bhv.b_name
let is_selected_for (m: mode) (fors: string list) = let is_selected_for (m: mode) (fors: string list) =
match m.bhv with List.mem m.bhv.b_name fors
| None -> fors = []
| Some b0 -> List.mem b0 fors
let is_selected_ca ~goal (m: mode) (ca: code_annotation) = let is_selected_ca ~goal (m: mode) (ca: code_annotation) =
match ca.annot_content with match ca.annot_content with
...@@ -90,7 +80,7 @@ let is_selected_ca ~goal (m: mode) (ca: code_annotation) = ...@@ -90,7 +80,7 @@ let is_selected_ca ~goal (m: mode) (ca: code_annotation) =
| AAssert(forb,_) | AAssert(forb,_)
| AInvariant(forb,_,_) | AInvariant(forb,_,_)
-> not goal || is_selected_for m forb -> not goal || is_selected_for m forb
| AVariant _ -> m.bhv = None | AVariant _ -> is_default_bhv m
| AExtended _ | AStmtSpec _ | APragma _ -> | AExtended _ | AStmtSpec _ | APragma _ ->
assert false (* n/a *) assert false (* n/a *)
...@@ -103,14 +93,14 @@ let is_selected_property ~goal (m: mode) (p: Property.t) = ...@@ -103,14 +93,14 @@ let is_selected_property ~goal (m: mode) (p: Property.t) =
| PKRequires bhv | PKAssumes bhv -> | PKRequires bhv | PKAssumes bhv ->
Cil.is_default_behavior bhv || is_selected_bhv m bhv Cil.is_default_behavior bhv || is_selected_bhv m bhv
| PKEnsures(bhv,_) -> is_selected_bhv m bhv | PKEnsures(bhv,_) -> is_selected_bhv m bhv
| PKTerminates -> is_default m | PKTerminates -> is_default_bhv m
end end
| IPAllocation { ial_bhv = bhv } | IPAssigns { ias_bhv = bhv } -> | IPAllocation { ial_bhv = bhv } | IPAssigns { ias_bhv = bhv } ->
begin match bhv with begin match bhv with
| Id_loop ca -> is_selected_ca ~goal m ca | Id_loop ca -> is_selected_ca ~goal m ca
| Id_contract(_,bhv) -> is_selected_bhv m bhv | Id_contract(_,bhv) -> is_selected_bhv m bhv
end end
| IPDecrease { id_ca = None } -> is_default m | IPDecrease { id_ca = None } -> is_default_bhv m
| IPDecrease { id_ca = Some ca } -> is_selected_ca ~goal m ca | IPDecrease { id_ca = Some ca } -> is_selected_ca ~goal m ca
| IPComplete _ | IPDisjoint _ | IPFrom _ | IPComplete _ | IPDisjoint _ | IPFrom _
| IPGlobalInvariant _ | IPTypeInvariant _ -> | IPGlobalInvariant _ | IPTypeInvariant _ ->
......
...@@ -27,7 +27,7 @@ open Cil_types ...@@ -27,7 +27,7 @@ open Cil_types
(* -------------------------------------------------------------------------- *) (* -------------------------------------------------------------------------- *)
type mode = { type mode = {
bhv : string option ; (* Selected behavior (None is default) *) bhv : funbehavior ; (* Selected behavior (None is default) *)
stmt : stmt option ; (* Stmt contract under proof *) stmt : stmt option ; (* Stmt contract under proof *)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment