[vala/wip/inline-destroy: 2/3] codegen: Use wrapper function for destroying delegates
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/inline-destroy: 2/3] codegen: Use wrapper function for destroying delegates
- Date: Fri, 6 May 2011 16:27:07 +0000 (UTC)
commit cccd2c2dcd39acdf4baf469136ebb119e7d545a2
Author: Luca Bruno <lucabru src gnome org>
Date: Fri May 6 17:07:39 2011 +0200
codegen: Use wrapper function for destroying delegates
codegen/valaccodebasemodule.vala | 75 ++++++++++++++++++++++++--------------
1 files changed, 48 insertions(+), 27 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 2bd9ca5..d3ca761 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2817,6 +2817,53 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
var type = value.value_type;
var cvar = get_cvalue_ (value);
+ var destroy_func = get_destroy_func_expression (type);
+
+ if (!is_wrapper && (type is DelegateType || (destroy_func is CCodeIdentifier && !(type is ArrayType) && !(type is ValueType && !type.nullable)))) {
+ // generate and use NULL-aware free macro to simplify code
+
+ string freeid;
+ if (type is DelegateType) {
+ freeid = ((DelegateType) type).delegate_symbol.get_lower_case_cname () + "_destroy";
+ } else {
+ freeid = ((CCodeIdentifier) destroy_func).name;
+ }
+ string free0_func = "_%s0".printf (freeid);
+
+ if (add_wrapper (free0_func)) {
+ var fun = new CCodeFunction (free0_func, "void");
+ fun.modifiers = CCodeModifiers.STATIC | CCodeModifiers.INLINE;
+ if (type is DelegateType) {
+ fun.add_parameter (new CCodeParameter ("var", type.get_cname () + "*"));
+ fun.add_parameter (new CCodeParameter ("target", "gpointer*"));
+ fun.add_parameter (new CCodeParameter ("target_destroy_notify", "GDestroyNotify*"));
+ } else {
+ fun.add_parameter (new CCodeParameter ("var", "void**"));
+ }
+
+ push_function (fun);
+
+ var ref_value = ((GLibValue) value).copy ();
+ ref_value.cvalue = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier ("var"));
+ ref_value.delegate_target_cvalue = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier ("target"));
+ ref_value.delegate_target_destroy_notify_cvalue = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier ("target_destroy_notify"));
+ ccode.add_expression (destroy_value (ref_value, true));
+
+ pop_function ();
+
+ cfile.add_function_declaration (fun);
+ cfile.add_function (fun);
+ }
+
+ var ccall = new CCodeFunctionCall (new CCodeIdentifier (free0_func));
+ ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, cvar));
+ if (type is DelegateType) {
+ ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_delegate_target_cvalue (value)));
+ ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_delegate_target_destroy_notify_cvalue (value)));
+ }
+ return ccall;
+ }
+
if (type is DelegateType) {
var delegate_target = get_delegate_target_cvalue (value);
var delegate_target_destroy_notify = get_delegate_target_destroy_notify_cvalue (value);
@@ -2839,7 +2886,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
return ccomma;
}
- var ccall = new CCodeFunctionCall (get_destroy_func_expression (type));
+ var ccall = new CCodeFunctionCall (destroy_func);
if (type is ValueType && !type.nullable) {
// normal value type, no null check
@@ -2866,32 +2913,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
}
}
- 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 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 (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, cvar));
- return ccall;
- }
-
/* (foo == NULL ? NULL : foo = (unref (foo), NULL)) */
/* can be simplified to
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]