[vala] dova: Add support for module init function



commit f39734805fd2c7711e8daa933b3f29d15f1f145f
Author: Jürg Billeter <j bitron ch>
Date:   Sun Jul 11 15:20:39 2010 +0200

    dova: Add support for module init function

 codegen/valadovabasemodule.vala   |   12 ++++++++----
 codegen/valadovaobjectmodule.vala |    6 ++++++
 2 files changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/codegen/valadovabasemodule.vala b/codegen/valadovabasemodule.vala
index 2526caa..d5028d6 100644
--- a/codegen/valadovabasemodule.vala
+++ b/codegen/valadovabasemodule.vala
@@ -118,6 +118,7 @@ internal class Vala.DovaBaseModule : CCodeModule {
 	string? csource_filename;
 
 	public CCodeFragment source_type_member_definition;
+	public CCodeFragment module_init_fragment;
 	public CCodeFragment instance_init_fragment;
 	public CCodeFragment instance_finalize_fragment;
 
@@ -242,6 +243,7 @@ internal class Vala.DovaBaseModule : CCodeModule {
 
 
 		source_declarations = new CCodeDeclarationSpace ();
+		module_init_fragment = new CCodeFragment ();
 		source_type_member_definition = new CCodeFragment ();
 
 		next_temp_var_id = 0;
@@ -503,10 +505,12 @@ internal class Vala.DovaBaseModule : CCodeModule {
 			var_decl.initializer = default_value_for_type (f.field_type, true);
 
 			if (f.initializer != null) {
-				var init = (CCodeExpression) f.initializer.ccodenode;
-				if (is_constant_ccode_expression (init)) {
-					var_decl.initializer = init;
-				}
+				var rhs = (CCodeExpression) f.initializer.ccodenode;
+
+				module_init_fragment.append (new CCodeExpressionStatement (new CCodeAssignment (lhs, rhs)));
+
+				append_temp_decl (module_init_fragment, temp_vars);
+				temp_vars.clear ();
 			}
 
 			var var_def = new CCodeDeclaration (field_ctype);
diff --git a/codegen/valadovaobjectmodule.vala b/codegen/valadovaobjectmodule.vala
index a673d49..f04525e 100644
--- a/codegen/valadovaobjectmodule.vala
+++ b/codegen/valadovaobjectmodule.vala
@@ -1185,6 +1185,10 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
 				var cinit = new CCodeFragment ();
 				function.block.prepend_statement (cinit);
 
+				if (context.module_init_method == m) {
+					cinit.append (module_init_fragment);
+				}
+
 				if (m.closure) {
 					// add variables for parent closure blocks
 					// as closures only have one parameter for the innermost closure block
@@ -1401,6 +1405,8 @@ internal class Vala.DovaObjectModule : DovaArrayModule {
 			cmain.add_parameter (new CCodeFormalParameter ("argv", "char **"));
 			var main_block = new CCodeBlock ();
 
+			main_block.add_statement (new CCodeExpressionStatement (new CCodeFunctionCall (new CCodeIdentifier ("dova_init"))));
+
 			var cdecl = new CCodeDeclaration ("int");
 			cdecl.add_declarator (new CCodeVariableDeclarator ("result", new CCodeConstant ("0")));
 			main_block.add_statement (cdecl);



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