From: Jürg Billeter Date: Sat, 9 Oct 2010 16:16:32 +0000 (+0200) Subject: codegen: Use set_delegate_target for local variable access X-Git-Tag: 0.11.1~168 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4bdcea830d293f2ccaf038dbd68a052054eb49eb;p=thirdparty%2Fvala.git codegen: Use set_delegate_target for local variable access --- diff --git a/codegen/valaccodedelegatemodule.vala b/codegen/valaccodedelegatemodule.vala index 7dd9b390f..2b698f191 100644 --- a/codegen/valaccodedelegatemodule.vala +++ b/codegen/valaccodedelegatemodule.vala @@ -154,7 +154,7 @@ 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) { + if (delegate_expr.symbol_reference is FormalParameter || delegate_expr.symbol_reference is LocalVariable) { if (get_delegate_target_destroy_notify (delegate_expr) != null) { delegate_target_destroy_notify = get_delegate_target_destroy_notify (delegate_expr); } @@ -168,30 +168,6 @@ public class Vala.CCodeDelegateModule : CCodeArrayModule { } else { return target_expr; } - } else if (delegate_expr.symbol_reference is LocalVariable) { - var local = (LocalVariable) delegate_expr.symbol_reference; - if (local.captured) { - // captured variables are stored on the heap - var block = (Block) local.parent_symbol; - 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 (local.name))); - return new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_delegate_target_cname (get_variable_cname (local.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 (local.name))); - return new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), get_delegate_target_cname (get_variable_cname (local.name))); - } else { - var target_expr = new CCodeIdentifier (get_delegate_target_cname (get_variable_cname (local.name))); - if (expr_owned) { - delegate_target_destroy_notify = new CCodeIdentifier (get_delegate_target_destroy_notify_cname (get_variable_cname (local.name))); - } - if (is_out) { - 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; - } - } } else if (delegate_expr.symbol_reference is Field) { var field = (Field) delegate_expr.symbol_reference; string target_cname = get_delegate_target_cname (field.get_cname ()); diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala index a997c09fc..a0d61158f 100644 --- a/codegen/valaccodememberaccessmodule.vala +++ b/codegen/valaccodememberaccessmodule.vala @@ -433,6 +433,9 @@ 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_array_length_cname (get_variable_cname (local.name), dim))); } + } else if (local.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 (local.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 (local.name)))); } } else { set_cvalue (expr, get_variable_cexpression (local.name)); @@ -440,6 +443,16 @@ public class Vala.CCodeMemberAccessModule : CCodeControlFlowModule { for (int dim = 1; dim <= array_type.rank; dim++) { append_array_size (expr, get_variable_cexpression (get_array_length_cname (get_variable_cname (local.name), dim))); } + } else if (local.variable_type is DelegateType) { + if (current_method != null && current_method.coroutine) { + set_delegate_target (expr, new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), get_delegate_target_cname (get_variable_cname (local.name)))); + set_delegate_target_destroy_notify (expr, new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), get_delegate_target_destroy_notify_cname (get_variable_cname (local.name)))); + } else { + set_delegate_target (expr, new CCodeIdentifier (get_delegate_target_cname (get_variable_cname (local.name)))); + if (expr.value_type.value_owned) { + set_delegate_target_destroy_notify (expr, new CCodeIdentifier (get_delegate_target_destroy_notify_cname (get_variable_cname (local.name)))); + } + } } if (expr.parent_node is ReturnStatement &&