From 8966b137660fff6619905e842ef793c4c9ed4f6e Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Mon, 17 Aug 2009 20:28:34 +0200 Subject: [PATCH] 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. --- src/generator.ml | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) 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, _, _, _) -> -- 1.8.3.1