[vala/staging] codegen: Add function-prototypes for all register-type calls



commit 6f750884caf851baea27a0bc8e801bedbe94c51c
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Thu Dec 1 18:09:48 2016 +0100

    codegen: Add function-prototypes for all register-type calls
    
    Make sure to match the list of called register-type calls and include
    implemented classes and interfaces.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=775446

 codegen/valaccodemethodmodule.vala    |    6 ++++++
 codegen/valatyperegisterfunction.vala |    8 ++++----
 2 files changed, 10 insertions(+), 4 deletions(-)
---
diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index 991b57a..3a89c7e 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -297,6 +297,12 @@ 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);
+
                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));
                ccode.add_expression (register_call);
diff --git a/codegen/valatyperegisterfunction.vala b/codegen/valatyperegisterfunction.vala
index 9617f82..5f8d2be 100644
--- a/codegen/valatyperegisterfunction.vala
+++ b/codegen/valatyperegisterfunction.vala
@@ -78,6 +78,10 @@ public abstract class Vala.TypeRegisterFunction {
                                // avoid C warning as this function is not always used
                                fun.modifiers |= CCodeModifiers.INTERNAL | CCodeModifiers.UNUSED;
                        }
+
+                       fun.is_declaration = true;
+                       declaration_fragment.append (fun.copy ());
+                       fun.is_declaration = false;
                } else {
                        fun = new CCodeFunction ("%s_register_type".printf 
(CCodeBaseModule.get_ccode_lower_case_name (get_type_declaration ())), "GType");
                        fun.add_parameter (new CCodeParameter ("module", "GTypeModule *"));
@@ -250,10 +254,6 @@ public abstract class Vala.TypeRegisterFunction {
                        type_block.add_statement (new CCodeReturnStatement (new CCodeIdentifier 
(type_id_name)));
                }
 
-               fun.is_declaration = true;
-               declaration_fragment.append (fun.copy ());
-               fun.is_declaration = false;
-
                fun.block = type_block;
 
                definition_fragment.append (fun);


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