From: Jim Meyering Date: Mon, 17 Aug 2009 18:28:34 +0000 (+0200) Subject: generator.ml: do not emit unused print_*_list functions X-Git-Tag: 1.0.68~26 X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=commitdiff_plain;h=8966b137660fff6619905e842ef793c4c9ed4f6e generator.ml: do not emit unused print_*_list functions * src/generator.ml (emit_print_list_function): New function. Emit a function definition only if it will be used. --- diff --git a/src/generator.ml b/src/generator.ml index 189b1fd..4824438 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -6063,6 +6063,21 @@ and generate_fish_cmds () = pr "}\n"; pr "\n"; + let emit_print_list_function typ = + pr "static void print_%s_list (struct guestfs_%s_list *%ss)\n" + typ typ typ; + pr "{\n"; + pr " int i;\n"; + pr "\n"; + pr " for (i = 0; i < %ss->len; ++i) {\n" typ; + pr " printf (\"[%%d] = {\\n\", i);\n"; + pr " print_%s_indent (&%ss->val[i], \" \");\n" typ typ; + pr " printf (\"}\\n\");\n"; + pr " }\n"; + pr "}\n"; + pr "\n"; + in + (* print_* functions *) List.iter ( fun (typ, cols) -> @@ -6119,20 +6134,17 @@ and generate_fish_cmds () = pr " print_%s_indent (%s, \"\");\n" typ typ; pr "}\n"; pr "\n"; - pr "static void print_%s_list (struct guestfs_%s_list *%ss)\n" - typ typ typ; - pr "{\n"; - pr " int i;\n"; - pr "\n"; - pr " for (i = 0; i < %ss->len; ++i) {\n" typ; - pr " printf (\"[%%d] = {\\n\", i);\n"; - pr " print_%s_indent (&%ss->val[i], \" \");\n" typ typ; - pr " printf (\"}\\n\");\n"; - pr " }\n"; - pr "}\n"; - pr "\n"; ) structs; + (* Emit a print_TYPE_list function definition only if that function is used. *) + List.iter ( + function + | typ, (RStructListOnly | RStructAndList) -> + (* generate the function for typ *) + emit_print_list_function typ + | typ, _ -> () (* empty *) + ) rstructs_used; + (* run_ actions *) List.iter ( fun (name, style, _, flags, _, _, _) ->