let field_offset field = (* TODO : use foffset_in_bits ? *)
(* TODO find a better place for this auxiliary function
* (the OCaml List module perhaps ?) *)
let rec take_while p = function
[] -> []
| hd::tl -> if p hd then hd::(take_while p tl) else []
in
let add_offset current_offset field =
Why_ops.cil_binop PlusA Linteger current_offset (fol_ctype_sizeof field.ftype)
in
let fields_before = take_while
(function x -> x.fname = field.fname) field.fcomp.cfields in
List.fold_left add_offset Why_ops.int_zero fields_before