let find_behaviors kf cfg ki bhv_names =
let spec = Kernel_function.get_spec kf in
let f_bhvs = spec.spec_behavior in
let s_bhvs, def_annot_bhv = internal_function_behaviors cfg in
let add_fct_bhv (def, acc) b =
let add () =
let def = if Cil.is_default_behavior b then true else def in
def, (FunBhv (Some b))::acc
in
if bhv_names = [] then add()
else match ki with
| None | Some Kglobal ->
if List.mem b.b_name bhv_names then add () else (def, acc)
| Some Kstmt _ -> def, acc
in
let add_stmt_bhv acc (n,s,b) =
if bhv_names = [] then (StmtBhv (n,s,b))::acc
else if List.mem b.b_name bhv_names then
let acc = match ki with
| None -> (StmtBhv (n, s, b))::acc
| Some (Kstmt stmt) when stmt.sid = s.sid ->
(StmtBhv (n, s, b))::acc
| _ -> acc
in acc
else acc
in
let f_bhvs = List.rev f_bhvs in
let def, bhvs = List.fold_left add_fct_bhv (false, []) f_bhvs in
let bhvs = List.fold_left add_stmt_bhv bhvs s_bhvs in
let bhvs =
if def then bhvs
else if bhv_names = [] then (FunBhv None)::bhvs
else match ki with
| None | Some Kglobal ->
if List.mem Cil.default_behavior_name bhv_names
then (FunBhv None)::bhvs
else bhvs
| Some Kstmt _ -> bhvs
in def_annot_bhv, bhvs