]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Only emit declaration of *_register_type if needed
authorRico Tzschichholz <ricotz@ubuntu.com>
Sat, 23 Feb 2019 19:19:31 +0000 (20:19 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 23 Feb 2019 19:19:31 +0000 (20:19 +0100)
This allows to add a test case for ModuleInit with -Werror=redundant-decls

codegen/valaccodemethodmodule.vala

index 4adf1f4b30c818abb4803d932f1160e54e95768c..bc7a3b2a1d8f0669836689df131b05b7394c9a7c 100644 (file)
@@ -289,10 +289,13 @@ public abstract class Vala.CCodeMethodModule : CCodeStructModule {
                }
 
                // Add function prototypes for required register-type-calls which are likely external
-               var register_func = new CCodeFunction ("%s_register_type".printf (get_ccode_lower_case_name (type_symbol, null)), "GType");
-               register_func.add_parameter (new CCodeParameter ("module", "GTypeModule *"));
-               register_func.is_declaration = true;
-               cfile.add_function_declaration (register_func);
+               if (type_symbol.source_reference.file != cfile.file) {
+                       // TODO Duplicated source with TypeRegisterFunction.init_from_type()
+                       var register_func = new CCodeFunction ("%s_register_type".printf (get_ccode_lower_case_name (type_symbol, null)), "GType");
+                       register_func.add_parameter (new CCodeParameter ("module", "GTypeModule *"));
+                       register_func.is_declaration = true;
+                       cfile.add_function_declaration (register_func);
+               }
 
                var register_call = new CCodeFunctionCall (new CCodeIdentifier ("%s_register_type".printf (get_ccode_lower_case_name (type_symbol, null))));
                register_call.add_argument (new CCodeIdentifier (module_init_param_name));