[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH libnbd v2 1/3] generator: Modify C.print_* with optional parens flag.



Controls whether or not we print the parentheses around the function
parameters.
---
 generator/C.ml  | 26 ++++++++++++++------------
 generator/C.mli |  5 +++--
 2 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/generator/C.ml b/generator/C.ml
index e79ac42..568e3f1 100644
--- a/generator/C.ml
+++ b/generator/C.ml
@@ -96,16 +96,17 @@ let rec name_of_arg = function
 | UInt32 n -> [n]
 | UInt64 n -> [n]
 
-let rec print_arg_list ?(wrap = false) ?maxcol ?handle ?types args optargs =
-  pr "(";
+let rec print_arg_list ?(wrap = false) ?maxcol ?handle ?types ?(parens = true)
+          args optargs =
+  if parens then pr "(";
   if wrap then
     pr_wrap ?maxcol ','
-      (fun () -> print_arg_list_no_parens ?handle ?types args optargs)
+      (fun () -> print_arg_list' ?handle ?types args optargs)
   else
-    print_arg_list_no_parens ?handle ?types args optargs;
-  pr ")"
+    print_arg_list' ?handle ?types args optargs;
+  if parens then pr ")"
 
-and print_arg_list_no_parens ?(handle = false) ?(types = true) args optargs =
+and print_arg_list' ?(handle = false) ?(types = true) args optargs =
   let comma = ref false in
   if handle then (
     comma := true;
@@ -191,16 +192,17 @@ let print_extern ?wrap name args optargs ret =
   print_call ?wrap name args optargs ret;
   pr ";\n"
 
-let rec print_cbarg_list ?(wrap = false) ?maxcol ?types cbargs =
-  pr "(";
+let rec print_cbarg_list ?(wrap = false) ?maxcol ?types ?(parens = true)
+          cbargs =
+  if parens then pr "(";
   if wrap then
     pr_wrap ?maxcol ','
-      (fun () -> print_cbarg_list_no_parens ?types cbargs)
+      (fun () -> print_cbarg_list' ?types cbargs)
   else
-    print_cbarg_list_no_parens ?types cbargs;
-  pr ")"
+    print_cbarg_list' ?types cbargs;
+  if parens then pr ")"
 
-and print_cbarg_list_no_parens ?(types = true) cbargs =
+and print_cbarg_list' ?(types = true) cbargs =
   if types then pr "void *";
   pr "user_data";
 
diff --git a/generator/C.mli b/generator/C.mli
index 7748bc7..c8268c1 100644
--- a/generator/C.mli
+++ b/generator/C.mli
@@ -25,9 +25,10 @@ val generate_docs_api_links_pod : unit -> unit
 val generate_docs_api_flag_links_pod : unit -> unit
 val generate_docs_nbd_pod : string -> API.call -> unit -> unit
 val print_arg_list : ?wrap:bool -> ?maxcol:int ->
-                     ?handle:bool -> ?types:bool ->
+                     ?handle:bool -> ?types:bool -> ?parens:bool ->
                      API.arg list -> API.optarg list -> unit
-val print_cbarg_list : ?wrap:bool -> ?maxcol:int -> ?types:bool ->
+val print_cbarg_list : ?wrap:bool -> ?maxcol:int ->
+                       ?types:bool -> ?parens:bool ->
                        API.cbarg list -> unit
 val errcode_of_ret : API.ret -> string option
 val type_of_ret : API.ret -> string
-- 
2.25.0


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]