[vala/wip/inline-destroy: 1/3] codegen: Use static inline function in destroy_value instead of macro



commit 0e77a51ab0d90d91749b7e9845baf8f3e08f52e5
Author: Luca Bruno <lucabru src gnome org>
Date:   Fri May 6 16:40:06 2011 +0200

    codegen: Use static inline function in destroy_value instead of macro

 codegen/valaccodearraymodule.vala |    6 +++---
 codegen/valaccodebasemodule.vala  |   24 ++++++++++++++++--------
 2 files changed, 19 insertions(+), 11 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index d5622da..543dfb0 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -452,14 +452,14 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 		}
 	}
 
-	public override CCodeExpression destroy_value (TargetValue value, bool is_macro_definition = false) {
+	public override CCodeExpression destroy_value (TargetValue value, bool is_wrapper = false) {
 		var type = value.value_type;
 
 		if (type is ArrayType) {
 			var array_type = (ArrayType) type;
 
 			if (!array_type.fixed_length) {
-				return base.destroy_value (value, is_macro_definition);
+				return base.destroy_value (value, is_wrapper);
 			}
 
 			requires_array_free = true;
@@ -473,7 +473,7 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 
 			return ccall;
 		} else {
-			return base.destroy_value (value, is_macro_definition);
+			return base.destroy_value (value, is_wrapper);
 		}
 	}
 
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index afa97fe..2bd9ca5 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2813,9 +2813,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 		return destroy_value (get_field_cvalue (field, instance));
 	}
 
-	// logic in this method is temporarily duplicated in destroy_variable
-	// apply changes to both methods
-	public virtual CCodeExpression destroy_value (TargetValue value, bool is_macro_definition = false) {
+	public virtual CCodeExpression destroy_value (TargetValue value, bool is_wrapper = false) {
 		var type = value.value_type;
 		var cvar = get_cvalue_ (value);
 
@@ -2868,19 +2866,29 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 			}
 		}
 
-		if (ccall.call is CCodeIdentifier && !(type is ArrayType) && !is_macro_definition) {
-			// generate and use NULL-aware free macro to simplify code
+		if (ccall.call is CCodeIdentifier && !(type is ArrayType) && !is_wrapper) {
+			// generate and use NULL-aware free function to simplify code
 
 			var freeid = (CCodeIdentifier) ccall.call;
 			string free0_func = "_%s0".printf (freeid.name);
 
 			if (add_wrapper (free0_func)) {
-				var macro = destroy_value (new GLibValue (type, new CCodeIdentifier ("var")), true);
-				cfile.add_type_declaration (new CCodeMacroReplacement.with_expression ("%s(var)".printf (free0_func), macro));
+				var fun = new CCodeFunction (free0_func, "void");
+				fun.modifiers = CCodeModifiers.STATIC | CCodeModifiers.INLINE;
+				fun.add_parameter (new CCodeParameter ("var", "void**"));
+
+				push_function (fun);
+
+				ccode.add_expression (destroy_value (new GLibValue (type, new CCodeIdentifier ("*var")), true));
+
+				pop_function ();
+
+				cfile.add_function_declaration (fun);
+				cfile.add_function (fun);
 			}
 
 			ccall = new CCodeFunctionCall (new CCodeIdentifier (free0_func));
-			ccall.add_argument (cvar);
+			ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, cvar));
 			return ccall;
 		}
 



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