[vala] codegen: Use set_delegate_target for parameter access
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Use set_delegate_target for parameter access
- Date: Sat, 9 Oct 2010 17:08:12 +0000 (UTC)
commit 8a87738d05dd889ac6da55e222cd35a6d203957d
Author: Jürg Billeter <j bitron ch>
Date: Sat Oct 9 18:04:23 2010 +0200
codegen: Use set_delegate_target for parameter access
codegen/valaccodedelegatemodule.vala | 38 ++++++++----------------------
codegen/valaccodememberaccessmodule.vala | 20 +++++++++++++++
2 files changed, 30 insertions(+), 28 deletions(-)
---
diff --git a/codegen/valaccodedelegatemodule.vala b/codegen/valaccodedelegatemodule.vala
index 3f5eb41..7dd9b39 100644
--- a/codegen/valaccodedelegatemodule.vala
+++ b/codegen/valaccodedelegatemodule.vala
@@ -155,36 +155,18 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule {
return get_delegate_target (delegate_expr);
} else if (delegate_expr.symbol_reference != null) {
if (delegate_expr.symbol_reference is FormalParameter) {
- var param = (FormalParameter) delegate_expr.symbol_reference;
- if (param.captured) {
- // captured variables are stored on the heap
- var block = ((Method) param.parent_symbol).body;
- delegate_target_destroy_notify = new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)));
- return new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_delegate_target_cname (get_variable_cname (param.name)));
- } else if (current_method != null && current_method.coroutine) {
- delegate_target_destroy_notify = new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)));
- return new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), get_delegate_target_cname (get_variable_cname (param.name)));
- } else {
- CCodeExpression target_expr = new CCodeIdentifier (get_delegate_target_cname (get_variable_cname (param.name)));
+ if (get_delegate_target_destroy_notify (delegate_expr) != null) {
+ delegate_target_destroy_notify = get_delegate_target_destroy_notify (delegate_expr);
+ }
+ var target_expr = get_delegate_target (delegate_expr);
+ if (is_out) {
+ // passing delegate as out/ref
if (expr_owned) {
- delegate_target_destroy_notify = new CCodeIdentifier (get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)));
- }
- if (param.direction != ParameterDirection.IN) {
- // accessing argument of out/ref param
- target_expr = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, target_expr);
- if (expr_owned) {
- delegate_target_destroy_notify = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, delegate_target_destroy_notify);
- }
- }
- if (is_out) {
- // passing delegate as out/ref
- if (expr_owned) {
- delegate_target_destroy_notify = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, delegate_target_destroy_notify);
- }
- return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, target_expr);
- } else {
- return target_expr;
+ delegate_target_destroy_notify = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, delegate_target_destroy_notify);
}
+ return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, target_expr);
+ } else {
+ return target_expr;
}
} else if (delegate_expr.symbol_reference is LocalVariable) {
var local = (LocalVariable) delegate_expr.symbol_reference;
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 10a72d6..a997c09 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -482,10 +482,17 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
for (int dim = 1; dim <= array_type.rank; dim++) {
append_array_size (expr, new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_parameter_array_length_cname (p, dim)));
}
+ } else if (p.variable_type is DelegateType) {
+ set_delegate_target (expr, new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_delegate_target_cname (get_variable_cname (p.name))));
+ set_delegate_target_destroy_notify (expr, new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_delegate_target_destroy_notify_cname (get_variable_cname (p.name))));
}
} else if (current_method != null && current_method.coroutine) {
// use closure
set_cvalue (expr, get_variable_cexpression (p.name));
+ if (p.variable_type is DelegateType) {
+ set_delegate_target (expr, new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), get_delegate_target_cname (get_variable_cname (p.name))));
+ set_delegate_target_destroy_notify (expr, new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), get_delegate_target_destroy_notify_cname (get_variable_cname (p.name))));
+ }
} else {
var type_as_struct = p.variable_type.data_type as Struct;
if (p.direction != ParameterDirection.IN
@@ -505,6 +512,19 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
set_cvalue (expr, get_variable_cexpression (p.name));
}
}
+ if (p.variable_type is DelegateType) {
+ CCodeExpression target_expr = new CCodeIdentifier (get_delegate_target_cname (get_variable_cname (p.name)));
+ CCodeExpression delegate_target_destroy_notify = new CCodeIdentifier (get_delegate_target_destroy_notify_cname (get_variable_cname (p.name)));
+ if (p.direction != ParameterDirection.IN) {
+ // accessing argument of out/ref param
+ target_expr = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, target_expr);
+ delegate_target_destroy_notify = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, delegate_target_destroy_notify);
+ }
+ set_delegate_target (expr, target_expr);
+ if (expr.value_type.value_owned) {
+ set_delegate_target_destroy_notify (expr, delegate_target_destroy_notify);
+ }
+ }
}
if (!p.captured && array_type != null) {
if (p.array_null_terminated) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]