Release 0.7.8
[vala-lang.git] / codegen / valaccodedelegatemodule.vala
blobd8cad9d7050209689c0b7938956fbcdf16741786
1 /* valaccodedelegatemodule.vala
3 * Copyright (C) 2006-2009 Jürg Billeter
4 * Copyright (C) 2006-2008 Raffaele Sandrini
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Author:
21 * Jürg Billeter <j@bitron.ch>
22 * Raffaele Sandrini <raffaele@sandrini.ch>
26 /**
27 * The link between an assignment and generated code.
29 internal class Vala.CCodeDelegateModule : CCodeArrayModule {
30 public CCodeDelegateModule (CCodeGenerator codegen, CCodeModule? next) {
31 base (codegen, next);
34 public override void generate_delegate_declaration (Delegate d, CCodeDeclarationSpace decl_space) {
35 if (decl_space.add_symbol_declaration (d, d.get_cname ())) {
36 return;
39 string return_type_cname = d.return_type.get_cname ();
41 if (d.return_type.is_real_non_null_struct_type ()) {
42 // structs are returned via out parameter
43 return_type_cname = "void";
46 if (return_type_cname == d.get_cname ()) {
47 // recursive delegate
48 return_type_cname = "GCallback";
49 } else {
50 generate_type_declaration (d.return_type, decl_space);
53 var cfundecl = new CCodeFunctionDeclarator (d.get_cname ());
54 foreach (FormalParameter param in d.get_parameters ()) {
55 generate_parameter (param, decl_space, new HashMap<int,CCodeFormalParameter> (), null);
57 cfundecl.add_parameter ((CCodeFormalParameter) param.ccodenode);
59 // handle array parameters
60 if (!param.no_array_length && param.parameter_type is ArrayType) {
61 var array_type = (ArrayType) param.parameter_type;
63 var length_ctype = "int";
64 if (param.direction != ParameterDirection.IN) {
65 length_ctype = "int*";
68 for (int dim = 1; dim <= array_type.rank; dim++) {
69 var cparam = new CCodeFormalParameter (head.get_array_length_cname (get_variable_cname (param.name), dim), length_ctype);
70 cfundecl.add_parameter (cparam);
73 // handle delegate parameters
74 if (param.parameter_type is DelegateType) {
75 var deleg_type = (DelegateType) param.parameter_type;
76 var param_d = deleg_type.delegate_symbol;
77 if (param_d.has_target) {
78 var cparam = new CCodeFormalParameter (get_delegate_target_cname (get_variable_cname (param.name)), "void*");
79 cfundecl.add_parameter (cparam);
83 if (!d.no_array_length && d.return_type is ArrayType) {
84 // return array length if appropriate
85 var array_type = (ArrayType) d.return_type;
87 for (int dim = 1; dim <= array_type.rank; dim++) {
88 var cparam = new CCodeFormalParameter (head.get_array_length_cname ("result", dim), "int*");
89 cfundecl.add_parameter (cparam);
91 } else if (d.return_type is DelegateType) {
92 // return delegate target if appropriate
93 var deleg_type = (DelegateType) d.return_type;
94 var result_d = deleg_type.delegate_symbol;
95 if (result_d.has_target) {
96 var cparam = new CCodeFormalParameter (get_delegate_target_cname ("result"), "void**");
97 cfundecl.add_parameter (cparam);
99 } else if (d.return_type.is_real_non_null_struct_type ()) {
100 var cparam = new CCodeFormalParameter ("result", "%s*".printf (d.return_type.get_cname ()));
101 cfundecl.add_parameter (cparam);
103 if (d.has_target) {
104 var cparam = new CCodeFormalParameter ("user_data", "void*");
105 cfundecl.add_parameter (cparam);
107 if (d.get_error_types ().size > 0) {
108 var cparam = new CCodeFormalParameter ("error", "GError**");
109 cfundecl.add_parameter (cparam);
112 var ctypedef = new CCodeTypeDefinition (return_type_cname, cfundecl);
113 decl_space.add_type_definition (ctypedef);
116 public override void visit_delegate (Delegate d) {
117 d.accept_children (codegen);
119 generate_delegate_declaration (d, source_declarations);
121 if (!d.is_internal_symbol ()) {
122 generate_delegate_declaration (d, header_declarations);
124 if (!d.is_private_symbol ()) {
125 generate_delegate_declaration (d, internal_header_declarations);
129 public override string get_delegate_target_cname (string delegate_cname) {
130 return "%s_target".printf (delegate_cname);
133 public override CCodeExpression get_delegate_target_cexpression (Expression delegate_expr, out CCodeExpression delegate_target_destroy_notify) {
134 bool is_out = false;
136 delegate_target_destroy_notify = new CCodeConstant ("NULL");
138 if (delegate_expr is UnaryExpression) {
139 var unary_expr = (UnaryExpression) delegate_expr;
140 if (unary_expr.operator == UnaryOperator.OUT || unary_expr.operator == UnaryOperator.REF) {
141 delegate_expr = unary_expr.inner;
142 is_out = true;
146 bool expr_owned = delegate_expr.value_type.value_owned;
148 if (delegate_expr is ReferenceTransferExpression) {
149 var reftransfer_expr = (ReferenceTransferExpression) delegate_expr;
150 delegate_expr = reftransfer_expr.inner;
153 if (delegate_expr is MethodCall) {
154 var invocation_expr = (MethodCall) delegate_expr;
155 if (invocation_expr.delegate_target_destroy_notify != null) {
156 delegate_target_destroy_notify = invocation_expr.delegate_target_destroy_notify;
158 return invocation_expr.delegate_target;
159 } else if (delegate_expr is LambdaExpression) {
160 var closure_block = current_closure_block;
161 if (closure_block != null) {
162 int block_id = get_block_id (closure_block);
163 var delegate_target = get_variable_cexpression ("_data%d_".printf (block_id));
164 if (expr_owned) {
165 var ref_call = new CCodeFunctionCall (new CCodeIdentifier ("block%d_data_ref".printf (block_id)));
166 ref_call.add_argument (delegate_target);
167 delegate_target = ref_call;
168 delegate_target_destroy_notify = new CCodeIdentifier ("block%d_data_unref".printf (block_id));
170 return delegate_target;
171 } else if (get_this_type () != null || in_constructor) {
172 CCodeExpression delegate_target = get_result_cexpression ("self");
173 if (expr_owned) {
174 if (get_this_type () != null) {
175 var ref_call = new CCodeFunctionCall (get_dup_func_expression (get_this_type (), delegate_expr.source_reference));
176 ref_call.add_argument (delegate_target);
177 delegate_target = ref_call;
178 delegate_target_destroy_notify = get_destroy_func_expression (get_this_type ());
179 } else {
180 // in constructor
181 var ref_call = new CCodeFunctionCall (new CCodeIdentifier ("g_object_ref"));
182 ref_call.add_argument (delegate_target);
183 delegate_target = ref_call;
184 delegate_target_destroy_notify = new CCodeIdentifier ("g_object_unref");
187 return delegate_target;
188 } else {
189 return new CCodeConstant ("NULL");
191 } else if (delegate_expr.symbol_reference != null) {
192 if (delegate_expr.symbol_reference is FormalParameter) {
193 var param = (FormalParameter) delegate_expr.symbol_reference;
194 if (param.captured) {
195 // captured variables are stored on the heap
196 var block = ((Method) param.parent_symbol).body;
197 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)));
198 return new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_delegate_target_cname (get_variable_cname (param.name)));
199 } else if (current_method != null && current_method.coroutine) {
200 delegate_target_destroy_notify = new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)));
201 return new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), get_delegate_target_cname (get_variable_cname (param.name)));
202 } else {
203 CCodeExpression target_expr = new CCodeIdentifier (get_delegate_target_cname (get_variable_cname (param.name)));
204 if (expr_owned) {
205 delegate_target_destroy_notify = new CCodeIdentifier (get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)));
207 if (param.direction != ParameterDirection.IN) {
208 // accessing argument of out/ref param
209 target_expr = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, target_expr);
210 if (expr_owned) {
211 delegate_target_destroy_notify = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, delegate_target_destroy_notify);
214 if (is_out) {
215 // passing delegate as out/ref
216 if (expr_owned) {
217 delegate_target_destroy_notify = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, delegate_target_destroy_notify);
219 return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, target_expr);
220 } else {
221 return target_expr;
224 } else if (delegate_expr.symbol_reference is LocalVariable) {
225 var local = (LocalVariable) delegate_expr.symbol_reference;
226 if (local.captured) {
227 // captured variables are stored on the heap
228 var block = (Block) local.parent_symbol;
229 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)));
230 return new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_delegate_target_cname (get_variable_cname (local.name)));
231 } else if (current_method != null && current_method.coroutine) {
232 delegate_target_destroy_notify = new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), get_delegate_target_destroy_notify_cname (get_variable_cname (local.name)));
233 return new CCodeMemberAccess.pointer (new CCodeIdentifier ("data"), get_delegate_target_cname (get_variable_cname (local.name)));
234 } else {
235 var target_expr = new CCodeIdentifier (get_delegate_target_cname (get_variable_cname (local.name)));
236 if (expr_owned) {
237 delegate_target_destroy_notify = new CCodeIdentifier (get_delegate_target_destroy_notify_cname (get_variable_cname (local.name)));
239 if (is_out) {
240 if (expr_owned) {
241 delegate_target_destroy_notify = new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, delegate_target_destroy_notify);
243 return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, target_expr);
244 } else {
245 return target_expr;
248 } else if (delegate_expr.symbol_reference is Field) {
249 var field = (Field) delegate_expr.symbol_reference;
250 string target_cname = get_delegate_target_cname (field.get_cname ());
251 string target_destroy_notify_cname = get_delegate_target_destroy_notify_cname (field.get_cname ());
253 var ma = (MemberAccess) delegate_expr;
255 CCodeExpression target_expr = null;
257 if (field.binding == MemberBinding.INSTANCE) {
258 var instance_expression_type = ma.inner.value_type;
259 var instance_target_type = get_data_type_for_symbol ((TypeSymbol) field.parent_symbol);
261 var pub_inst = (CCodeExpression) get_ccodenode (ma.inner);
262 CCodeExpression typed_inst = transform_expression (pub_inst, instance_expression_type, instance_target_type);
264 CCodeExpression inst;
265 if (field.access == SymbolAccessibility.PRIVATE) {
266 inst = new CCodeMemberAccess.pointer (typed_inst, "priv");
267 } else {
268 inst = typed_inst;
270 if (((TypeSymbol) field.parent_symbol).is_reference_type ()) {
271 target_expr = new CCodeMemberAccess.pointer (inst, target_cname);
272 if (expr_owned) {
273 delegate_target_destroy_notify = new CCodeMemberAccess.pointer (inst, target_destroy_notify_cname);
275 } else {
276 target_expr = new CCodeMemberAccess (inst, target_cname);
277 if (expr_owned) {
278 delegate_target_destroy_notify = new CCodeMemberAccess (inst, target_destroy_notify_cname);
281 } else {
282 target_expr = new CCodeIdentifier (target_cname);
283 if (expr_owned) {
284 delegate_target_destroy_notify = new CCodeIdentifier (target_destroy_notify_cname);
288 if (is_out) {
289 return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, target_expr);
290 } else {
291 return target_expr;
293 } else if (delegate_expr.symbol_reference is Method) {
294 var m = (Method) delegate_expr.symbol_reference;
295 var ma = (MemberAccess) delegate_expr;
296 if (m.binding == MemberBinding.STATIC) {
297 return new CCodeConstant ("NULL");
298 } else if (m.is_async_callback) {
299 return new CCodeIdentifier ("data");
300 } else {
301 var delegate_target = (CCodeExpression) get_ccodenode (ma.inner);
302 if (expr_owned && ma.inner.value_type.data_type != null && ma.inner.value_type.data_type.is_reference_counting ()) {
303 var ref_call = new CCodeFunctionCall (get_dup_func_expression (ma.inner.value_type, delegate_expr.source_reference));
304 ref_call.add_argument (delegate_target);
305 delegate_target = ref_call;
306 delegate_target_destroy_notify = get_destroy_func_expression (ma.inner.value_type);
308 return delegate_target;
310 } else if (delegate_expr.symbol_reference is Property) {
311 return delegate_expr.delegate_target;
315 return new CCodeConstant ("NULL");
318 public override string get_delegate_target_destroy_notify_cname (string delegate_cname) {
319 return "%s_target_destroy_notify".printf (delegate_cname);
322 public override CCodeExpression get_implicit_cast_expression (CCodeExpression source_cexpr, DataType? expression_type, DataType? target_type, Expression? expr = null) {
323 if (target_type is DelegateType && expression_type is MethodType) {
324 var dt = (DelegateType) target_type;
325 var mt = (MethodType) expression_type;
327 var method = mt.method_symbol;
328 if (method.base_method != null) {
329 method = method.base_method;
330 } else if (method.base_interface_method != null) {
331 method = method.base_interface_method;
334 return new CCodeIdentifier (generate_delegate_wrapper (method, dt.delegate_symbol));
337 return base.get_implicit_cast_expression (source_cexpr, expression_type, target_type, expr);
340 private string generate_delegate_wrapper (Method m, Delegate d) {
341 string delegate_name;
342 var sig = d.parent_symbol as Signal;
343 var dynamic_sig = sig as DynamicSignal;
344 if (dynamic_sig != null) {
345 delegate_name = head.get_dynamic_signal_cname (dynamic_sig);
346 } else if (sig != null) {
347 delegate_name = sig.parent_symbol.get_lower_case_cprefix () + sig.get_cname ();
348 } else {
349 delegate_name = Symbol.camel_case_to_lower_case (d.get_cname ());
352 string wrapper_name = "_%s_%s".printf (m.get_cname (), delegate_name);
354 if (!add_wrapper (wrapper_name)) {
355 // wrapper already defined
356 return wrapper_name;
359 // declaration
361 string return_type_cname = d.return_type.get_cname ();
363 if (d.return_type.is_real_non_null_struct_type ()) {
364 // structs are returned via out parameter
365 return_type_cname = "void";
368 var function = new CCodeFunction (wrapper_name, return_type_cname);
369 function.modifiers = CCodeModifiers.STATIC;
370 m.ccodenode = function;
372 var cparam_map = new HashMap<int,CCodeFormalParameter> (direct_hash, direct_equal);
374 if (d.has_target) {
375 var cparam = new CCodeFormalParameter ("self", "gpointer");
376 cparam_map.set (get_param_pos (d.cinstance_parameter_position), cparam);
379 if (d.sender_type != null) {
380 var param = new FormalParameter ("_sender", d.sender_type);
381 generate_parameter (param, source_declarations, cparam_map, null);
384 var d_params = d.get_parameters ();
385 foreach (FormalParameter param in d_params) {
386 if (dynamic_sig != null
387 && param.parameter_type is ArrayType
388 && ((ArrayType) param.parameter_type).element_type.data_type == string_type.data_type) {
389 // use null-terminated string arrays for dynamic signals for compatibility reasons
390 param.no_array_length = true;
391 param.array_null_terminated = true;
394 generate_parameter (param, source_declarations, cparam_map, null);
396 if (!d.no_array_length && d.return_type is ArrayType) {
397 // return array length if appropriate
398 var array_type = (ArrayType) d.return_type;
400 for (int dim = 1; dim <= array_type.rank; dim++) {
401 var cparam = new CCodeFormalParameter (head.get_array_length_cname ("result", dim), "int*");
402 cparam_map.set (get_param_pos (d.carray_length_parameter_position + 0.01 * dim), cparam);
404 } else if (d.return_type is DelegateType) {
405 // return delegate target if appropriate
406 var deleg_type = (DelegateType) d.return_type;
408 if (deleg_type.delegate_symbol.has_target) {
409 var cparam = new CCodeFormalParameter (get_delegate_target_cname ("result"), "void**");
410 cparam_map.set (get_param_pos (d.cdelegate_target_parameter_position), cparam);
412 } else if (d.return_type.is_real_non_null_struct_type ()) {
413 var cparam = new CCodeFormalParameter ("result", "%s*".printf (d.return_type.get_cname ()));
414 cparam_map.set (get_param_pos (-3), cparam);
417 if (m.get_error_types ().size > 0) {
418 var cparam = new CCodeFormalParameter ("error", "GError**");
419 cparam_map.set (get_param_pos (-1), cparam);
422 // append C parameters in the right order
423 int last_pos = -1;
424 int min_pos;
425 while (true) {
426 min_pos = -1;
427 foreach (int pos in cparam_map.get_keys ()) {
428 if (pos > last_pos && (min_pos == -1 || pos < min_pos)) {
429 min_pos = pos;
432 if (min_pos == -1) {
433 break;
435 function.add_parameter (cparam_map.get (min_pos));
436 last_pos = min_pos;
440 // definition
442 var carg_map = new HashMap<int,CCodeExpression> (direct_hash, direct_equal);
444 int i = 0;
445 if (m.binding == MemberBinding.INSTANCE || m.closure) {
446 CCodeExpression arg;
447 if (d.has_target) {
448 arg = new CCodeIdentifier ("self");
449 } else {
450 // use first delegate parameter as instance
451 arg = new CCodeIdentifier ((d_params.get (0).ccodenode as CCodeFormalParameter).name);
452 i = 1;
454 carg_map.set (get_param_pos (m.cinstance_parameter_position), arg);
457 bool first = true;
459 foreach (FormalParameter param in m.get_parameters ()) {
460 if (first && d.sender_type != null && m.get_parameters ().size == d.get_parameters ().size + 1) {
461 // sender parameter
462 carg_map.set (get_param_pos (param.cparameter_position), new CCodeIdentifier ("_sender"));
464 first = false;
465 continue;
468 CCodeExpression arg;
469 arg = new CCodeIdentifier ((d_params.get (i).ccodenode as CCodeFormalParameter).name);
470 carg_map.set (get_param_pos (param.cparameter_position), arg);
472 // handle array arguments
473 if (!param.no_array_length && param.parameter_type is ArrayType) {
474 var array_type = (ArrayType) param.parameter_type;
475 for (int dim = 1; dim <= array_type.rank; dim++) {
476 CCodeExpression clength;
477 if (d_params.get (i).array_null_terminated) {
478 requires_array_length = true;
479 var len_call = new CCodeFunctionCall (new CCodeIdentifier ("_vala_array_length"));
480 len_call.add_argument (new CCodeIdentifier (d_params.get (i).name));
481 clength = len_call;
482 } else if (d_params.get (i).no_array_length) {
483 clength = new CCodeConstant ("-1");
484 } else {
485 clength = new CCodeIdentifier (head.get_array_length_cname (d_params.get (i).name, dim));
487 carg_map.set (get_param_pos (param.carray_length_parameter_position + 0.01 * dim), clength);
489 } else if (param.parameter_type is DelegateType) {
490 var deleg_type = (DelegateType) param.parameter_type;
492 if (deleg_type.delegate_symbol.has_target) {
493 var ctarget = new CCodeIdentifier (get_delegate_target_cname (d_params.get (i).name));
494 carg_map.set (get_param_pos (param.cdelegate_target_parameter_position), ctarget);
498 i++;
500 if (!m.no_array_length && m.return_type is ArrayType) {
501 var array_type = (ArrayType) m.return_type;
502 for (int dim = 1; dim <= array_type.rank; dim++) {
503 CCodeExpression clength;
504 if (d.no_array_length) {
505 clength = new CCodeConstant ("NULL");
506 } else {
507 clength = new CCodeIdentifier (head.get_array_length_cname ("result", dim));
509 carg_map.set (get_param_pos (m.carray_length_parameter_position + 0.01 * dim), clength);
511 } else if (m.return_type is DelegateType) {
512 var deleg_type = (DelegateType) m.return_type;
514 if (deleg_type.delegate_symbol.has_target) {
515 var ctarget = new CCodeIdentifier (get_delegate_target_cname ("result"));
516 carg_map.set (get_param_pos (m.cdelegate_target_parameter_position), ctarget);
518 } else if (m.return_type.is_real_non_null_struct_type ()) {
519 carg_map.set (get_param_pos (-3), new CCodeIdentifier ("result"));
522 if (m.get_error_types ().size > 0) {
523 carg_map.set (get_param_pos (-1), new CCodeIdentifier ("error"));
526 var ccall = new CCodeFunctionCall (new CCodeIdentifier (m.get_cname ()));
528 // append C arguments in the right order
529 last_pos = -1;
530 while (true) {
531 min_pos = -1;
532 foreach (int pos in carg_map.get_keys ()) {
533 if (pos > last_pos && (min_pos == -1 || pos < min_pos)) {
534 min_pos = pos;
537 if (min_pos == -1) {
538 break;
540 ccall.add_argument (carg_map.get (min_pos));
541 last_pos = min_pos;
544 var block = new CCodeBlock ();
545 if (m.return_type is VoidType || m.return_type.is_real_non_null_struct_type ()) {
546 block.add_statement (new CCodeExpressionStatement (ccall));
547 } else {
548 block.add_statement (new CCodeReturnStatement (ccall));
551 // append to file
553 source_declarations.add_type_member_declaration (function.copy ());
555 function.block = block;
556 source_type_member_definition.append (function);
558 return wrapper_name;
561 public override void generate_parameter (FormalParameter param, CCodeDeclarationSpace decl_space, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
562 if (!(param.parameter_type is DelegateType || param.parameter_type is MethodType)) {
563 base.generate_parameter (param, decl_space, cparam_map, carg_map);
564 return;
567 string ctypename = param.parameter_type.get_cname ();
568 string target_ctypename = "void*";
569 string target_destroy_notify_ctypename = "GDestroyNotify";
571 if (param.parent_symbol is Delegate
572 && param.parameter_type.get_cname () == ((Delegate) param.parent_symbol).get_cname ()) {
573 // recursive delegate
574 ctypename = "GCallback";
577 if (param.direction != ParameterDirection.IN) {
578 ctypename += "*";
579 target_ctypename += "*";
580 target_destroy_notify_ctypename += "*";
583 param.ccodenode = new CCodeFormalParameter (get_variable_cname (param.name), ctypename);
585 cparam_map.set (get_param_pos (param.cparameter_position), (CCodeFormalParameter) param.ccodenode);
586 if (carg_map != null) {
587 carg_map.set (get_param_pos (param.cparameter_position), get_variable_cexpression (param.name));
590 if (param.parameter_type is DelegateType) {
591 var deleg_type = (DelegateType) param.parameter_type;
592 var d = deleg_type.delegate_symbol;
594 generate_delegate_declaration (d, decl_space);
596 if (d.has_target) {
597 var cparam = new CCodeFormalParameter (get_delegate_target_cname (get_variable_cname (param.name)), target_ctypename);
598 cparam_map.set (get_param_pos (param.cdelegate_target_parameter_position), cparam);
599 if (carg_map != null) {
600 carg_map.set (get_param_pos (param.cdelegate_target_parameter_position), get_variable_cexpression (cparam.name));
602 if (deleg_type.value_owned) {
603 cparam = new CCodeFormalParameter (get_delegate_target_destroy_notify_cname (get_variable_cname (param.name)), target_destroy_notify_ctypename);
604 cparam_map.set (get_param_pos (param.cdelegate_target_parameter_position + 0.01), cparam);
605 if (carg_map != null) {
606 carg_map.set (get_param_pos (param.cdelegate_target_parameter_position + 0.01), get_variable_cexpression (cparam.name));
610 } else if (param.parameter_type is MethodType) {
611 var cparam = new CCodeFormalParameter (get_delegate_target_cname (get_variable_cname (param.name)), target_ctypename);
612 cparam_map.set (get_param_pos (param.cdelegate_target_parameter_position), cparam);
613 if (carg_map != null) {
614 carg_map.set (get_param_pos (param.cdelegate_target_parameter_position), get_variable_cexpression (cparam.name));