Commits

Anonymous committed dbce0db

+ offsets of fields in structures

  • Participants
  • Parent commits 76e56f9

Comments (0)

Files changed (2)

   - val sizeof : int -- get size of structure in octets
   - val get_a : t -> <typeof a> -- get field "a"
   - val set_a : t -> <typeof a> -> unit -- set field "a"
+  - val a_ofs : int -- offset of field "a" in the structure
   - val of_bigarray : bigarray -> t -- create Mystruct.t on top of bigarray
   - val bigarray_of : t -> bigarray -- get bigarray of Mystruct.t
   - val create : unit -> t -- create uninitialized Mystruct.t

lib/cstruct_codegen.ml

   ; sig_ "(* getters and setters: *)"
   ; str_ ""
 
-  ; let for_field { fname = fname ; ftype = ftype_gen } =
+  ; let for_field { fname = fname_orig ; ftype = ftype_gen } =
+      let fname = fname_orig in
       let gen_get_set ~ftype ~fname =
         let getter = "get_" ^ fname
         and setter = "set_" ^ fname in
         ; sig_
             "val %s : t -> %s -> unit"
             setter ftype.ocamltype
+        ; sig_
+            "val %s_ofs : int"
+            fname_orig
         ; str_
             "let %s t = %s t %i"
             getter ftype.getter cur_ofs.val
         ; str_
             "let %s t v = %s t %i v"
             setter ftype.setter cur_ofs.val
+        ; str_
+            "let %s_ofs = %i"
+            fname_orig cur_ofs.val
+
         ; cur_ofs.val := cur_ofs.val + ftype.sz
         )
       in