[vala] codegen: Add destroy_value function
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Add destroy_value function
- Date: Thu, 28 Oct 2010 10:35:35 +0000 (UTC)
commit 4bbab6a46aee951a727e286a2f1e32f9686d704d
Author: Jürg Billeter <j bitron ch>
Date: Thu Oct 21 15:44:09 2010 +0200
codegen: Add destroy_value function
codegen/valaccodearraymodule.vala | 10 ++++++----
codegen/valaccodebasemodule.vala | 25 +++++++++++++++++++------
codegen/valadovabasemodule.vala | 9 ++++++++-
3 files changed, 33 insertions(+), 11 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index ec375c3..c906fb2 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -522,12 +522,14 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
}
}
- public override CCodeExpression get_unref_expression (CCodeExpression cvar, DataType type, Expression? expr, bool is_macro_definition) {
+ public override CCodeExpression destroy_value (TargetValue value, bool is_macro_definition = false) {
+ var type = value.value_type;
+
if (type is ArrayType) {
var array_type = (ArrayType) type;
if (!array_type.fixed_length) {
- return base.get_unref_expression (cvar, type, expr, is_macro_definition);
+ return base.destroy_value (value, is_macro_definition);
}
requires_array_free = true;
@@ -535,13 +537,13 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
var ccall = new CCodeFunctionCall (get_destroy_func_expression (type));
ccall = new CCodeFunctionCall (new CCodeIdentifier ("_vala_array_destroy"));
- ccall.add_argument (cvar);
+ ccall.add_argument (get_cvalue_ (value));
ccall.add_argument (new CCodeConstant ("%d".printf (array_type.length)));
ccall.add_argument (new CCodeCastExpression (get_destroy_func_expression (array_type.element_type), "GDestroyNotify"));
return ccall;
} else {
- return base.get_unref_expression (cvar, type, expr, is_macro_definition);
+ return base.destroy_value (value, is_macro_definition);
}
}
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 7bbcc92..4e52849 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2900,10 +2900,23 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
return null;
}
- public virtual CCodeExpression get_unref_expression (CCodeExpression cvar, DataType type, Expression? expr, bool is_macro_definition = false) {
+ public CCodeExpression get_unref_expression (CCodeExpression cvar, DataType type, Expression? expr, bool is_macro_definition = false) {
+ var value = new GLibValue (type, cvar);
+ if (expr != null && expr.target_value != null) {
+ value.array_length_cvalues = ((GLibValue) expr.target_value).array_length_cvalues;
+ value.delegate_target_cvalue = get_delegate_target_cvalue (expr.target_value);
+ value.delegate_target_destroy_notify_cvalue = get_delegate_target_destroy_notify_cvalue (expr.target_value);
+ }
+ return destroy_value (value, is_macro_definition);
+ }
+
+ public virtual CCodeExpression destroy_value (TargetValue value, bool is_macro_definition = false) {
+ var type = value.value_type;
+ var cvar = get_cvalue_ (value);
+
if (type is DelegateType) {
- CCodeExpression delegate_target_destroy_notify;
- var delegate_target = get_delegate_target_cexpression (expr, out delegate_target_destroy_notify);
+ var delegate_target = get_delegate_target_cvalue (value);
+ var delegate_target_destroy_notify = get_delegate_target_destroy_notify_cvalue (value);
var ccall = new CCodeFunctionCall (delegate_target_destroy_notify);
ccall.add_argument (delegate_target);
@@ -2957,7 +2970,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
string free0_func = "_%s0".printf (freeid.name);
if (add_wrapper (free0_func)) {
- var macro = get_unref_expression (new CCodeIdentifier ("var"), type, expr, true);
+ 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));
}
@@ -3006,10 +3019,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
bool first = true;
for (int dim = 1; dim <= array_type.rank; dim++) {
if (first) {
- csizeexpr = get_array_length_cexpression (expr, dim);
+ csizeexpr = get_array_length_cvalue (value, dim);
first = false;
} else {
- csizeexpr = new CCodeBinaryExpression (CCodeBinaryOperator.MUL, csizeexpr, get_array_length_cexpression (expr, dim));
+ csizeexpr = new CCodeBinaryExpression (CCodeBinaryOperator.MUL, csizeexpr, get_array_length_cvalue (value, dim));
}
}
diff --git a/codegen/valadovabasemodule.vala b/codegen/valadovabasemodule.vala
index 63ebb6d..58ba7e9 100644
--- a/codegen/valadovabasemodule.vala
+++ b/codegen/valadovabasemodule.vala
@@ -1058,7 +1058,14 @@ public abstract class Vala.DovaBaseModule : CodeGenerator {
}
}
- public virtual CCodeExpression get_unref_expression (CCodeExpression cvar, DataType type, Expression? expr = null) {
+ public CCodeExpression get_unref_expression (CCodeExpression cvar, DataType type, Expression? expr = null) {
+ return destroy_value (new DovaValue (type, cvar));
+ }
+
+ public CCodeExpression destroy_value (TargetValue value) {
+ var type = value.value_type;
+ var cvar = get_cvalue_ (value);
+
var ccall = new CCodeFunctionCall (get_destroy_func_expression (type));
if (type is ValueType && !type.nullable) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]