]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Use set_delegate_target for parameter access
authorJürg Billeter <j@bitron.ch>
Sat, 9 Oct 2010 16:04:23 +0000 (18:04 +0200)
committerJürg Billeter <j@bitron.ch>
Sat, 9 Oct 2010 16:12:17 +0000 (18:12 +0200)
codegen/valaccodedelegatemodule.vala
codegen/valaccodememberaccessmodule.vala

index 3f5eb4114708c462ad9e70ec6cd4a499b30d4f2c..7dd9b390f601b3b73801d444955c1ab4db4a5b95 100644 (file)
@@ -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;
index 10a72d6d9d28873cdc84e27333fdc8e49beec2cd..a997c09fc7af923a54e1c9f595cf061680ed77a3 100644 (file)
@@ -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) {