Wrappi_accumulator.add_enum en
>>
+let add_struct _loc name fields =
+ let loc = expr_of_loc _loc _loc in
+
+ let fields = List.map (
+ fun (name, t) -> <:expr< ($str:name$, $t$) >>
+ ) fields in
+ let fields = expr_of_list _loc fields in
+
+ <:str_item<
+ let sd = { Wrappi_types.sd_loc = $loc$;
+ sd_name = $str:name$;
+ sd_fields = Array.of_list $fields$ } in
+ Wrappi_accumulator.add_struct sd
+ >>
+
let () =
(* Quotation expander for C code. *)
let c_quotation_expander _loc _ code =
(* A single function parameter. XXX Preconditions. *)
parameter: [[ t = ptype; name = LIDENT -> (name, t) ]];
+ (* A single struct field. XXX Preconditions. *)
+ struct_field: [[ t = ptype; name = LIDENT -> (name, t) ]];
+
str_item: LEVEL "top" [
[ "entry_point";
local = OPT "local";
add_enum _loc name identifiers
]
+ | [ "struct"; name = LIDENT; "{";
+ fields = LIST0 struct_field SEP ";";
+ "}" ->
+ add_struct _loc name fields
+ ]
+
| [ "typedef"; t = ptype; name = LIDENT ->
add_typedef _loc name t
]