From: Jürg Billeter Date: Sat, 9 Oct 2010 16:04:23 +0000 (+0200) Subject: codegen: Use set_delegate_target for parameter access X-Git-Tag: 0.11.1~169 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a87738d05dd889ac6da55e222cd35a6d203957d;p=thirdparty%2Fvala.git codegen: Use set_delegate_target for parameter access --- diff --git a/codegen/valaccodedelegatemodule.vala b/codegen/valaccodedelegatemodule.vala index 3f5eb4114..7dd9b390f 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 10a72d6d9..a997c09fc 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) {