valaccodearraymodule.vala 40.4 KB
Newer Older
Jürg Billeter's avatar
Jürg Billeter committed
1
/* valaccodearraymodule.vala
2
 *
3
 * Copyright (C) 2006-2010  Jürg Billeter
4
 * Copyright (C) 2006-2008  Raffaele Sandrini
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	Jürg Billeter <j@bitron.ch>
 *	Raffaele Sandrini <raffaele@sandrini.ch>
 */


26
public class Vala.CCodeArrayModule : CCodeMethodCallModule {
27 28
	int next_array_dup_id = 0;
	int next_array_add_id = 0;
29

30 31 32 33 34 35 36 37 38 39 40
	void append_initializer_list (CCodeCommaExpression ce, CCodeExpression name_cnode, InitializerList initializer_list, int rank, ref int i) {
		foreach (Expression e in initializer_list.get_initializers ()) {
			if (rank > 1) {
				append_initializer_list (ce, name_cnode, (InitializerList) e, rank - 1, ref i);
			} else {
				ce.append_expression (new CCodeAssignment (new CCodeElementAccess (name_cnode, new CCodeConstant (i.to_string ())), (CCodeExpression) e.ccodenode));
				i++;
			}
		}
	}

Jürg Billeter's avatar
Jürg Billeter committed
41
	public override void visit_array_creation_expression (ArrayCreationExpression expr) {
42 43 44 45 46 47
		var array_type = expr.target_type as ArrayType;
		if (array_type != null && array_type.fixed_length) {
			// no heap allocation for fixed-length arrays

			var ce = new CCodeCommaExpression ();
			var temp_var = get_temp_variable (array_type, true, expr);
48
			var name_cnode = get_variable_cexpression (temp_var.name);
49 50
			int i = 0;

51
			temp_vars.add (temp_var);
52 53 54 55 56 57 58 59 60 61

			append_initializer_list (ce, name_cnode, expr.initializer_list, expr.rank, ref i);

			ce.append_expression (name_cnode);

			expr.ccodenode = ce;

			return;
		}

62 63
		CCodeFunctionCall gnew;
		if (context.profile == Profile.POSIX) {
64
			cfile.add_include ("stdlib.h");
65 66 67 68 69 70
			gnew = new CCodeFunctionCall (new CCodeIdentifier ("calloc"));
		} else {
			gnew = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
			gnew.add_argument (new CCodeIdentifier (expr.element_type.get_cname ()));
		}

71 72
		bool first = true;
		CCodeExpression cexpr = null;
73 74

		// iterate over each dimension
75
		foreach (Expression size in expr.get_sizes ()) {
76 77
			CCodeExpression csize = (CCodeExpression) size.ccodenode;

78 79
			if (!is_pure_ccode_expression (csize)) {
				var temp_var = get_temp_variable (int_type, false, expr);
80
				var name_cnode = get_variable_cexpression (temp_var.name);
81 82
				size.ccodenode = name_cnode;

83
				temp_vars.add (temp_var);
84

85
				csize = new CCodeAssignment (name_cnode, csize);
86 87
			}

88 89 90 91 92 93 94
			if (first) {
				cexpr = csize;
				first = false;
			} else {
				cexpr = new CCodeBinaryExpression (CCodeBinaryOperator.MUL, cexpr, csize);
			}
		}
95 96 97 98 99 100
		
		// add extra item to have array NULL-terminated for all reference types
		if (expr.element_type.data_type != null && expr.element_type.data_type.is_reference_type ()) {
			cexpr = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, cexpr, new CCodeConstant ("1"));
		}
		
101 102
		gnew.add_argument (cexpr);

103 104 105 106 107 108
		if (context.profile == Profile.POSIX) {
			var csizeof = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
			csizeof.add_argument (new CCodeIdentifier (expr.element_type.get_cname ()));
			gnew.add_argument (csizeof);
		}

109 110
		if (expr.initializer_list != null) {
			var ce = new CCodeCommaExpression ();
111
			var temp_var = get_temp_variable (expr.value_type, true, expr);
112
			var name_cnode = get_variable_cexpression (temp_var.name);
113 114
			int i = 0;
			
115
			temp_vars.add (temp_var);
116 117
			
			ce.append_expression (new CCodeAssignment (name_cnode, gnew));
118 119

			append_initializer_list (ce, name_cnode, expr.initializer_list, expr.rank, ref i);
120 121 122
			
			ce.append_expression (name_cnode);
			
123
			expr.ccodenode = ce;
124
		} else {
125
			expr.ccodenode = gnew;
126 127
		}
	}
128 129 130 131 132 133

	public override string get_array_length_cname (string array_cname, int dim) {
		return "%s_length%d".printf (array_cname, dim);
	}

	public override CCodeExpression get_array_length_cexpression (Expression array_expr, int dim = -1) {
134 135 136 137 138 139
		var array_type = array_expr.value_type as ArrayType;

		if (array_type != null && array_type.fixed_length) {
			return new CCodeConstant (array_type.length.to_string ());
		}

140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
		// dim == -1 => total size over all dimensions
		if (dim == -1) {
			if (array_type != null && array_type.rank > 1) {
				CCodeExpression cexpr = get_array_length_cexpression (array_expr, 1);
				for (dim = 2; dim <= array_type.rank; dim++) {
					cexpr = new CCodeBinaryExpression (CCodeBinaryOperator.MUL, cexpr, get_array_length_cexpression (array_expr, dim));
				}
				return cexpr;
			} else {
				dim = 1;
			}
		}

		bool is_out = false;

		if (array_expr is UnaryExpression) {
			var unary_expr = (UnaryExpression) array_expr;
			if (unary_expr.operator == UnaryOperator.OUT || unary_expr.operator == UnaryOperator.REF) {
				array_expr = unary_expr.inner;
				is_out = true;
			}
		} else if (array_expr is ReferenceTransferExpression) {
			var reftransfer_expr = (ReferenceTransferExpression) array_expr;
			array_expr = reftransfer_expr.inner;
		}
		
		if (array_expr is ArrayCreationExpression) {
167
			List<Expression> size = ((ArrayCreationExpression) array_expr).get_sizes ();
168
			var length_expr = size[dim - 1];
169
			return (CCodeExpression) get_ccodenode (length_expr);
170
		} else if (array_expr is MethodCall || array_expr is CastExpression || array_expr is SliceExpression) {
171
			List<CCodeExpression> size = array_expr.get_array_sizes ();
172
			if (size != null && size.size >= dim) {
173 174
				return size[dim - 1];
			}
175 176 177
		} else if (array_expr.symbol_reference != null) {
			if (array_expr.symbol_reference is FormalParameter) {
				var param = (FormalParameter) array_expr.symbol_reference;
178 179 180
				if (param.captured) {
					// captured variables are stored on the heap
					var block = ((Method) param.parent_symbol).body;
181 182 183 184 185 186 187
					var length_expr = new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_array_length_cname (get_variable_cname (param.name), dim));
					if (is_out) {
						// passing array as out/ref
						return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, length_expr);
					} else {
						return length_expr;
					}
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
				} else {
					if (param.array_null_terminated) {
						var carray_expr = get_variable_cexpression (param.name);
						requires_array_length = true;
						var len_call = new CCodeFunctionCall (new CCodeIdentifier ("_vala_array_length"));
						len_call.add_argument (carray_expr);
						return len_call;
					} else if (!param.no_array_length) {
						CCodeExpression length_expr = get_variable_cexpression (get_array_length_cname (get_variable_cname (param.name), dim));
						if (param.direction != ParameterDirection.IN) {
							// accessing argument of out/ref param
							length_expr = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, length_expr);
						}
						if (is_out) {
							// passing array as out/ref
							return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, length_expr);
						} else {
							return length_expr;
						}
207
					}
208 209 210 211 212 213
				}
			} else if (array_expr.symbol_reference is LocalVariable) {
				var local = (LocalVariable) array_expr.symbol_reference;
				if (local.captured) {
					// captured variables are stored on the heap
					var block = (Block) local.parent_symbol;
214 215 216 217 218 219 220
					var length_expr = new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_array_length_cname (get_variable_cname (local.name), dim));
					if (is_out) {
						// passing array as out/ref
						return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, length_expr);
					} else {
						return length_expr;
					}
221 222
				} else {
					var length_expr = get_variable_cexpression (get_array_length_cname (get_variable_cname (local.name), dim));
223 224 225 226 227 228 229 230
					if (is_out) {
						return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, length_expr);
					} else {
						return length_expr;
					}
				}
			} else if (array_expr.symbol_reference is Field) {
				var field = (Field) array_expr.symbol_reference;
231
				if (field.array_null_terminated) {
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
					var ma = (MemberAccess) array_expr;

					CCodeExpression carray_expr = null;

					if (field.binding == MemberBinding.INSTANCE) {
						var cl = field.parent_symbol as Class;
						bool is_gtypeinstance = (cl != null && !cl.is_compact);

						string array_cname = field.get_cname ();
						CCodeExpression typed_inst = (CCodeExpression) get_ccodenode (ma.inner);

						CCodeExpression inst;
						if (is_gtypeinstance && field.access == SymbolAccessibility.PRIVATE) {
							inst = new CCodeMemberAccess.pointer (typed_inst, "priv");
						} else {
							inst = typed_inst;
						}
						if (((TypeSymbol) field.parent_symbol).is_reference_type ()) {
							carray_expr = new CCodeMemberAccess.pointer (inst, array_cname);
						} else {
							carray_expr = new CCodeMemberAccess (inst, array_cname);
						}
					} else {
						carray_expr = new CCodeIdentifier (field.get_cname ());
					}

258 259
					requires_array_length = true;
					var len_call = new CCodeFunctionCall (new CCodeIdentifier ("_vala_array_length"));
260 261 262
					len_call.add_argument (carray_expr);
					return len_call;
				} else if (!field.no_array_length) {
263 264 265 266
					var ma = (MemberAccess) array_expr;

					CCodeExpression length_expr = null;

267 268 269
					if (field.has_array_length_cexpr) {
						length_expr = new CCodeConstant (field.get_array_length_cexpr ());
					} else if (field.binding == MemberBinding.INSTANCE) {
270 271
						var cl = field.parent_symbol as Class;
						bool is_gtypeinstance = (cl != null && !cl.is_compact);
272

273 274 275 276 277 278
						string length_cname;
						if (field.has_array_length_cname) {
							length_cname = field.get_array_length_cname ();
						} else {
							length_cname = get_array_length_cname (field.name, dim);
						}
279
						CCodeExpression typed_inst = (CCodeExpression) get_ccodenode (ma.inner);
280 281

						CCodeExpression inst;
282
						if (is_gtypeinstance && field.access == SymbolAccessibility.PRIVATE) {
283 284 285 286 287 288 289 290 291
							inst = new CCodeMemberAccess.pointer (typed_inst, "priv");
						} else {
							inst = typed_inst;
						}
						if (((TypeSymbol) field.parent_symbol).is_reference_type ()) {
							length_expr = new CCodeMemberAccess.pointer (inst, length_cname);
						} else {
							length_expr = new CCodeMemberAccess (inst, length_cname);
						}
292 293

						if (field.array_length_type != null) {
294 295 296 297 298 299 300 301 302 303
							// cast if field does not use int for array length
							var parent_expr = array_expr.parent_node as Expression;
							if (array_expr.lvalue) {
								// don't cast if array is used as lvalue
							} else if (parent_expr != null && parent_expr.symbol_reference is ArrayLengthField &&
								   parent_expr.lvalue) {
								// don't cast if array length is used as lvalue
							} else {
								length_expr = new CCodeCastExpression (length_expr, "gint");
							}
304
						}
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319
					} else {
						length_expr = new CCodeIdentifier (get_array_length_cname (field.get_cname (), dim));
					}

					if (is_out) {
						return new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, length_expr);
					} else {
						return length_expr;
					}
				}
			} else if (array_expr.symbol_reference is Constant) {
				var constant = (Constant) array_expr.symbol_reference;
				var ccall = new CCodeFunctionCall (new CCodeIdentifier ("G_N_ELEMENTS"));
				ccall.add_argument (new CCodeIdentifier (constant.get_cname ()));
				return ccall;
320
			} else if (array_expr.symbol_reference is Property) {
321 322
				var prop = (Property) array_expr.symbol_reference;
				if (!prop.no_array_length) {
323
					List<CCodeExpression> size = array_expr.get_array_sizes ();
324
					if (size != null && size.size >= dim) {
325 326
						return size[dim - 1];
					}
327
				}
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
			}
		} else if (array_expr is NullLiteral) {
			return new CCodeConstant ("0");
		}

		if (!is_out) {
			/* allow arrays with unknown length even for value types
			 * as else it may be impossible to bind some libraries
			 * users of affected libraries should explicitly set
			 * the array length as early as possible
			 * by setting the virtual length field of the array
			 */
			return new CCodeConstant ("-1");
		} else {
			return new CCodeConstant ("NULL");
		}
	}
345

346
	public override string get_array_size_cname (string array_cname) {
347
		return "_%s_size_".printf (array_cname);
348 349 350 351 352
	}

	public override CCodeExpression get_array_size_cexpression (Expression array_expr) {
		if (array_expr.symbol_reference is LocalVariable) {
			var local = (LocalVariable) array_expr.symbol_reference;
353 354 355 356 357 358 359 360 361
			if (local.captured) {
				// captured variables are stored on the heap
				var block = (Block) local.parent_symbol;
				return new CCodeMemberAccess.pointer (get_variable_cexpression ("_data%d_".printf (get_block_id (block))), get_array_size_cname (get_variable_cname (local.name)));
			} else {
				var size_expr = get_variable_cexpression (get_array_size_cname (get_variable_cname (local.name)));
				return size_expr;
			}

362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
		} else if (array_expr.symbol_reference is Field) {
			var field = (Field) array_expr.symbol_reference;
			var ma = (MemberAccess) array_expr;

			CCodeExpression size_expr = null;

			if (field.binding == MemberBinding.INSTANCE) {
				var cl = field.parent_symbol as Class;
				bool is_gtypeinstance = (cl != null && !cl.is_compact);

				string size_cname = get_array_size_cname (field.name);
				CCodeExpression typed_inst = (CCodeExpression) get_ccodenode (ma.inner);

				CCodeExpression inst;
				if (is_gtypeinstance && field.access == SymbolAccessibility.PRIVATE) {
					inst = new CCodeMemberAccess.pointer (typed_inst, "priv");
				} else {
					inst = typed_inst;
				}
				if (((TypeSymbol) field.parent_symbol).is_reference_type ()) {
					size_expr = new CCodeMemberAccess.pointer (inst, size_cname);
				} else {
					size_expr = new CCodeMemberAccess (inst, size_cname);
				}
			} else {
				size_expr = new CCodeIdentifier (get_array_size_cname (field.get_cname ()));
			}

			return size_expr;
		}

		assert_not_reached ();
	}

396
	public override void visit_element_access (ElementAccess expr) {
397
		List<Expression> indices = expr.get_indices ();
398 399 400 401 402 403 404 405 406 407
		int rank = indices.size;

		var ccontainer = (CCodeExpression) expr.container.ccodenode;
		var cindex = (CCodeExpression) indices[0].ccodenode;
		if (expr.container.symbol_reference is ArrayLengthField) {
			/* Figure if cindex is a constant expression and calculate dim...*/
			var lit = indices[0] as IntegerLiteral;
			var memberaccess = expr.container as MemberAccess;
			if (lit != null && memberaccess != null) {
				int dim = lit.value.to_int ();
408
				expr.ccodenode = get_array_length_cexpression (memberaccess.inner, dim + 1);
409 410
			} else {
				Report.error (expr.source_reference, "only integer literals supported as index");
411 412 413 414
			}
		} else {
			// access to element in an array
			for (int i = 1; i < rank; i++) {
415
				var cmul = new CCodeBinaryExpression (CCodeBinaryOperator.MUL, cindex, get_array_length_cexpression (expr.container, i + 1));
416
				cindex = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, cmul, (CCodeExpression) indices[i].ccodenode);
417 418 419 420
			}
			expr.ccodenode = new CCodeElementAccess (ccontainer, cindex);
		}
	}
421

422 423 424 425 426 427 428 429 430
	public override void visit_slice_expression (SliceExpression expr) {
		var ccontainer = (CCodeExpression) expr.container.ccodenode;
		var cstart = (CCodeExpression) expr.start.ccodenode;
		var cstop = (CCodeExpression) expr.stop.ccodenode;

		var ccomma = new CCodeCommaExpression ();

		var len_var = get_temp_variable (int_type);
		len_var.source_reference = expr.source_reference;
431
		temp_vars.add (len_var);
432 433

		var slice_var = get_temp_variable (expr.value_type, true, expr);
434
		temp_vars.add (slice_var);
435 436 437 438

		if (!is_pure_ccode_expression (cstart)) {
			// avoid double evaluation of start
			var start_var = get_temp_variable (int_type);
439
			temp_vars.add (start_var);
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460

			var start_assignment = new CCodeAssignment (get_variable_cexpression (start_var.name), cstart);
			ccomma.append_expression (start_assignment);

			cstart = get_variable_cexpression (start_var.name);
		}

		var cstartpointer = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, ccontainer, cstart);
		var slice_assignment = new CCodeAssignment (get_variable_cexpression (slice_var.name), cstartpointer);
		ccomma.append_expression (slice_assignment);

		var splicelen = new CCodeBinaryExpression (CCodeBinaryOperator.MINUS, cstop, cstart);
		var len_assignment = new CCodeAssignment (get_variable_cexpression (len_var.name), splicelen);
		ccomma.append_expression (len_assignment);

		ccomma.append_expression (get_variable_cexpression (slice_var.name));

		expr.ccodenode = ccomma;
		expr.append_array_size (get_variable_cexpression (len_var.name));
	}

461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
	private CCodeForStatement get_struct_array_free_loop (Struct st) {
		var cbody = new CCodeBlock ();
		var cptrarray = new CCodeIdentifier ("array");
		var cea = new CCodeElementAccess (cptrarray, new CCodeIdentifier ("i"));

		var cfreecall = new CCodeFunctionCall (get_destroy_func_expression (new StructValueType (st)));
		cfreecall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, cea));

		var cforcond = new CCodeBinaryExpression (CCodeBinaryOperator.LESS_THAN, new CCodeIdentifier ("i"), new CCodeIdentifier ("array_length"));
		cbody.add_statement (new CCodeExpressionStatement (cfreecall));

		var cfor = new CCodeForStatement (cforcond, cbody);
		cfor.add_initializer (new CCodeAssignment (new CCodeIdentifier ("i"), new CCodeConstant ("0")));
		cfor.add_iterator (new CCodeAssignment (new CCodeIdentifier ("i"), new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, new CCodeIdentifier ("i"), new CCodeConstant ("1"))));

		return cfor;
	}

	public override string? append_struct_array_free (Struct st) {
		string cname = "_vala_%s_array_free".printf (st.get_cname ());;

482
		if (cfile.add_declaration (cname)) {
483 484 485 486 487 488 489
			return cname;
		}

		var fun = new CCodeFunction (cname, "void");
		fun.modifiers = CCodeModifiers.STATIC;
		fun.add_parameter (new CCodeFormalParameter ("array", "%s*".printf (st.get_cname ())));
		fun.add_parameter (new CCodeFormalParameter ("array_length", "gint"));
490
		cfile.add_type_member_declaration (fun.copy ());
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508

		var cdofree = new CCodeBlock ();

		var citdecl = new CCodeDeclaration ("int");
		citdecl.add_declarator (new CCodeVariableDeclarator ("i"));
		cdofree.add_statement (citdecl);

		cdofree.add_statement (get_struct_array_free_loop (st));

		var ccondarr = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, new CCodeIdentifier ("array"), new CCodeConstant ("NULL"));
		var cif = new CCodeIfStatement (ccondarr, cdofree);
		fun.block = new CCodeBlock ();
		fun.block.add_statement (cif);

		var carrfree = new CCodeFunctionCall (new CCodeIdentifier ("g_free"));
		carrfree.add_argument (new CCodeIdentifier ("array"));
		fun.block.add_statement (new CCodeExpressionStatement (carrfree));

509
		cfile.add_function (fun);
510 511 512 513

		return cname;
	}

514
	private CCodeForStatement get_vala_array_free_loop () {
515 516 517 518 519 520 521
		var cbody = new CCodeBlock ();
		var cptrarray = new CCodeCastExpression (new CCodeIdentifier ("array"), "gpointer*");
		var cea = new CCodeElementAccess (cptrarray, new CCodeIdentifier ("i"));

		var cfreecall = new CCodeFunctionCall (new CCodeIdentifier ("destroy_func"));
		cfreecall.add_argument (cea);

522 523 524 525 526
		var cfreecond = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, cea, new CCodeConstant ("NULL"));
		var cforcond = new CCodeBinaryExpression (CCodeBinaryOperator.LESS_THAN, new CCodeIdentifier ("i"), new CCodeIdentifier ("array_length"));
		var cfreeblock = new CCodeBlock ();
		cfreeblock.add_statement (new CCodeExpressionStatement (cfreecall));
		cbody.add_statement (new CCodeIfStatement (cfreecond, cfreeblock));
527 528 529 530 531 532 533 534 535

		var cfor = new CCodeForStatement (cforcond, cbody);
		cfor.add_initializer (new CCodeAssignment (new CCodeIdentifier ("i"), new CCodeConstant ("0")));
		cfor.add_iterator (new CCodeAssignment (new CCodeIdentifier ("i"), new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, new CCodeIdentifier ("i"), new CCodeConstant ("1"))));

		return cfor;
	}

	public override void append_vala_array_free () {
536 537 538
		// _vala_array_destroy only frees elements but not the array itself

		var fun = new CCodeFunction ("_vala_array_destroy", "void");
539 540 541 542
		fun.modifiers = CCodeModifiers.STATIC;
		fun.add_parameter (new CCodeFormalParameter ("array", "gpointer"));
		fun.add_parameter (new CCodeFormalParameter ("array_length", "gint"));
		fun.add_parameter (new CCodeFormalParameter ("destroy_func", "GDestroyNotify"));
543
		cfile.add_type_member_declaration (fun.copy ());
544 545 546 547 548 549 550

		var cdofree = new CCodeBlock ();

		var citdecl = new CCodeDeclaration ("int");
		citdecl.add_declarator (new CCodeVariableDeclarator ("i"));
		cdofree.add_statement (citdecl);

551
		cdofree.add_statement (get_vala_array_free_loop ());
552 553 554 555 556 557 558

		var ccondarr = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, new CCodeIdentifier ("array"), new CCodeConstant ("NULL"));
		var ccondfunc = new CCodeBinaryExpression (CCodeBinaryOperator.INEQUALITY, new CCodeIdentifier ("destroy_func"), new CCodeConstant ("NULL"));
		var cif = new CCodeIfStatement (new CCodeBinaryExpression (CCodeBinaryOperator.AND, ccondarr, ccondfunc), cdofree);
		fun.block = new CCodeBlock ();
		fun.block.add_statement (cif);

559
		cfile.add_function (fun);
560 561 562 563 564 565 566 567

		// _vala_array_free frees elements and array

		fun = new CCodeFunction ("_vala_array_free", "void");
		fun.modifiers = CCodeModifiers.STATIC;
		fun.add_parameter (new CCodeFormalParameter ("array", "gpointer"));
		fun.add_parameter (new CCodeFormalParameter ("array_length", "gint"));
		fun.add_parameter (new CCodeFormalParameter ("destroy_func", "GDestroyNotify"));
568
		cfile.add_type_member_declaration (fun.copy ());
569 570 571 572 573 574 575 576 577 578

		// call _vala_array_destroy to free the array elements
		var ccall = new CCodeFunctionCall (new CCodeIdentifier ("_vala_array_destroy"));
		ccall.add_argument (new CCodeIdentifier ("array"));
		ccall.add_argument (new CCodeIdentifier ("array_length"));
		ccall.add_argument (new CCodeIdentifier ("destroy_func"));

		fun.block = new CCodeBlock ();
		fun.block.add_statement (new CCodeExpressionStatement (ccall));

579 580 581 582
		var carrfree = new CCodeFunctionCall (new CCodeIdentifier ("g_free"));
		carrfree.add_argument (new CCodeIdentifier ("array"));
		fun.block.add_statement (new CCodeExpressionStatement (carrfree));

583
		cfile.add_function (fun);
584 585 586
	}

	public override void append_vala_array_move () {
587
		cfile.add_include ("string.h");
588 589 590 591 592 593 594 595 596 597

		// assumes that overwritten array elements are null before invocation
		// FIXME will leak memory if that's not the case
		var fun = new CCodeFunction ("_vala_array_move", "void");
		fun.modifiers = CCodeModifiers.STATIC;
		fun.add_parameter (new CCodeFormalParameter ("array", "gpointer"));
		fun.add_parameter (new CCodeFormalParameter ("element_size", "gsize"));
		fun.add_parameter (new CCodeFormalParameter ("src", "gint"));
		fun.add_parameter (new CCodeFormalParameter ("dest", "gint"));
		fun.add_parameter (new CCodeFormalParameter ("length", "gint"));
598
		cfile.add_type_member_declaration (fun.copy ());
599 600 601 602 603 604 605 606

		var array = new CCodeCastExpression (new CCodeIdentifier ("array"), "char*");
		var element_size = new CCodeIdentifier ("element_size");
		var length = new CCodeIdentifier ("length");
		var src = new CCodeIdentifier ("src");
		var dest = new CCodeIdentifier ("dest");
		var src_address = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, array, new CCodeBinaryExpression (CCodeBinaryOperator.MUL, src, element_size));
		var dest_address = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, array, new CCodeBinaryExpression (CCodeBinaryOperator.MUL, dest, element_size));
607
		var dest_end_address = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, array, new CCodeBinaryExpression (CCodeBinaryOperator.MUL, new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, dest, length), element_size));
608 609 610 611 612 613 614 615 616 617 618 619

		fun.block = new CCodeBlock ();

		var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_memmove"));
		ccall.add_argument (dest_address);
		ccall.add_argument (src_address);
		ccall.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.MUL, length, element_size));
		fun.block.add_statement (new CCodeExpressionStatement (ccall));

		var czero1 = new CCodeFunctionCall (new CCodeIdentifier ("memset"));
		czero1.add_argument (src_address);
		czero1.add_argument (new CCodeConstant ("0"));
620
		czero1.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.MUL, new CCodeBinaryExpression (CCodeBinaryOperator.MINUS, dest, src), element_size));
621 622 623 624 625 626
		var czeroblock1 = new CCodeBlock ();
		czeroblock1.add_statement (new CCodeExpressionStatement (czero1));

		var czero2 = new CCodeFunctionCall (new CCodeIdentifier ("memset"));
		czero2.add_argument (dest_end_address);
		czero2.add_argument (new CCodeConstant ("0"));
627
		czero2.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.MUL, new CCodeBinaryExpression (CCodeBinaryOperator.MINUS, src, dest), element_size));
628 629 630 631 632
		var czeroblock2 = new CCodeBlock ();
		czeroblock2.add_statement (new CCodeExpressionStatement (czero2));

		fun.block.add_statement (new CCodeIfStatement (new CCodeBinaryExpression (CCodeBinaryOperator.LESS_THAN, src, dest), czeroblock1, czeroblock2));

633
		cfile.add_function (fun);
634
	}
635

636 637 638 639
	public override void append_vala_array_length () {
		var fun = new CCodeFunction ("_vala_array_length", "gint");
		fun.modifiers = CCodeModifiers.STATIC;
		fun.add_parameter (new CCodeFormalParameter ("array", "gpointer"));
640
		cfile.add_type_member_declaration (fun.copy ());
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664

		var block = new CCodeBlock ();

		var len_decl = new CCodeDeclaration ("int");
		len_decl.add_declarator (new CCodeVariableDeclarator ("length", new CCodeConstant ("0")));
		block.add_statement (len_decl);

		var non_null_block = new CCodeBlock ();

		var while_body = new CCodeBlock ();
		while_body.add_statement (new CCodeExpressionStatement (new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT, new CCodeIdentifier ("length"))));

		var array_element_check = new CCodeElementAccess (new CCodeCastExpression (new CCodeIdentifier ("array"), "gpointer*"), new CCodeConstant ("length"));
		non_null_block.add_statement (new CCodeWhileStatement (array_element_check, while_body));

		// return 0 if the array is NULL
		// avoids an extra NULL check on the caller side
		var array_check = new CCodeIdentifier ("array");
		block.add_statement (new CCodeIfStatement (array_check, non_null_block));

		block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("length")));

		fun.block = block;

665
		cfile.add_function (fun);
666 667
	}

668 669 670 671 672 673 674 675 676
	public override CCodeExpression? get_ref_cexpression (DataType expression_type, CCodeExpression cexpr, Expression? expr, CodeNode node) {
		if (expression_type is ArrayType) {
			var array_type = (ArrayType) expression_type;

			if (!array_type.fixed_length) {
				return base.get_ref_cexpression (expression_type, cexpr, expr, node);
			}

			var decl = get_temp_variable (expression_type, false, node);
677
			temp_vars.add (decl);
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695

			var ctemp = get_variable_cexpression (decl.name);

			var copy_call = new CCodeFunctionCall (new CCodeIdentifier (generate_array_copy_wrapper (array_type)));
			copy_call.add_argument (cexpr);
			copy_call.add_argument (ctemp);

			var ccomma = new CCodeCommaExpression ();

			ccomma.append_expression (copy_call);
			ccomma.append_expression (ctemp);

			return ccomma;
		} else {
			return base.get_ref_cexpression (expression_type, cexpr, expr, node);
		}
	}

696
	public override CCodeExpression? get_dup_func_expression (DataType type, SourceReference? source_reference, bool is_chainup) {
697
		if (type is ArrayType) {
698 699 700 701 702
			var array_type = (ArrayType) type;
			// fixed length arrays use different code
			// generated by overridden get_ref_cexpression method
			assert (!array_type.fixed_length);
			return new CCodeIdentifier (generate_array_dup_wrapper (array_type));
703
		} else {
704
			return base.get_dup_func_expression (type, source_reference, is_chainup);
705 706 707
		}
	}

708
	public override CCodeExpression get_unref_expression (CCodeExpression cvar, DataType type, Expression? expr, bool is_macro_definition) {
709 710 711 712
		if (type is ArrayType) {
			var array_type = (ArrayType) type;

			if (!array_type.fixed_length) {
713
				return base.get_unref_expression (cvar, type, expr, is_macro_definition);
714 715 716 717 718 719 720 721 722 723 724 725 726
			}

			requires_array_free = true;

			var ccall = new CCodeFunctionCall (get_destroy_func_expression (type));

			ccall = new CCodeFunctionCall (new CCodeIdentifier ("_vala_array_destroy"));
			ccall.add_argument (cvar);
			ccall.add_argument (new CCodeConstant ("%d".printf (array_type.length)));
			ccall.add_argument (new CCodeCastExpression (get_destroy_func_expression (array_type.element_type), "GDestroyNotify"));

			return ccall;
		} else {
727
			return base.get_unref_expression (cvar, type, expr, is_macro_definition);
728 729 730
		}
	}

731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746
	string generate_array_dup_wrapper (ArrayType array_type) {
		string dup_func = "_vala_array_dup%d".printf (++next_array_dup_id);

		if (!add_wrapper (dup_func)) {
			// wrapper already defined
			return dup_func;
		}

		// declaration

		var function = new CCodeFunction (dup_func, array_type.get_cname ());
		function.modifiers = CCodeModifiers.STATIC;

		function.add_parameter (new CCodeFormalParameter ("self", array_type.get_cname ()));
		// total length over all dimensions
		function.add_parameter (new CCodeFormalParameter ("length", "int"));
747 748 749 750 751
		if (array_type.element_type is GenericType) {
			// dup function array elements
			string func_name = "%s_dup_func".printf (array_type.element_type.type_parameter.name.down ());
			function.add_parameter (new CCodeFormalParameter (func_name, "GBoxedCopyFunc"));
		}
752 753 754 755 756 757

		// definition

		var block = new CCodeBlock ();

		if (requires_copy (array_type.element_type)) {
758
			push_context (new EmitContext ());
759 760 761 762 763 764

			var cdecl = new CCodeDeclaration (array_type.get_cname ());
			var cvardecl = new CCodeVariableDeclarator ("result");
			cdecl.add_declarator (cvardecl);
			var gnew = new CCodeFunctionCall (new CCodeIdentifier ("g_new0"));
			gnew.add_argument (new CCodeIdentifier (array_type.element_type.get_cname ()));
765 766 767 768 769 770 771 772

			CCodeExpression length_expr = new CCodeIdentifier ("length");
			// add extra item to have array NULL-terminated for all reference types
			if (array_type.element_type.data_type != null && array_type.element_type.data_type.is_reference_type ()) {
				length_expr = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, length_expr, new CCodeConstant ("1"));
			}
			gnew.add_argument (length_expr);

773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792
			cvardecl.initializer = gnew;
			block.add_statement (cdecl);

			var idx_decl = new CCodeDeclaration ("int");
			idx_decl.add_declarator (new CCodeVariableDeclarator ("i"));
			block.add_statement (idx_decl);

			var loop_body = new CCodeBlock ();
			loop_body.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeElementAccess (new CCodeIdentifier ("result"), new CCodeIdentifier ("i")), get_ref_cexpression (array_type.element_type, new CCodeElementAccess (new CCodeIdentifier ("self"), new CCodeIdentifier ("i")), null, array_type))));

			var cfor = new CCodeForStatement (new CCodeBinaryExpression (CCodeBinaryOperator.LESS_THAN, new CCodeIdentifier ("i"), new CCodeIdentifier ("length")), loop_body);
			cfor.add_initializer (new CCodeAssignment (new CCodeIdentifier ("i"), new CCodeConstant ("0")));
			cfor.add_iterator (new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT, new CCodeIdentifier ("i")));
			block.add_statement (cfor);

			block.add_statement (new CCodeReturnStatement (new CCodeIdentifier ("result")));

			var cfrag = new CCodeFragment ();
			append_temp_decl (cfrag, temp_vars);
			block.add_statement (cfrag);
793 794

			pop_context ();
795 796 797 798 799 800 801 802 803 804 805 806 807
		} else {
			var dup_call = new CCodeFunctionCall (new CCodeIdentifier ("g_memdup"));
			dup_call.add_argument (new CCodeIdentifier ("self"));

			var sizeof_call = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
			sizeof_call.add_argument (new CCodeIdentifier (array_type.element_type.get_cname ()));
			dup_call.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.MUL, new CCodeIdentifier ("length"), sizeof_call));

			block.add_statement (new CCodeReturnStatement (dup_call));
		}

		// append to file

808
		cfile.add_type_member_declaration (function.copy ());
809 810

		function.block = block;
811
		cfile.add_function (function);
812 813 814

		return dup_func;
	}
815

816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836
	string generate_array_copy_wrapper (ArrayType array_type) {
		string dup_func = "_vala_array_copy%d".printf (++next_array_dup_id);

		if (!add_wrapper (dup_func)) {
			// wrapper already defined
			return dup_func;
		}

		// declaration

		var function = new CCodeFunction (dup_func, "void");
		function.modifiers = CCodeModifiers.STATIC;

		function.add_parameter (new CCodeFormalParameter ("self", array_type.get_cname () + "*"));
		function.add_parameter (new CCodeFormalParameter ("dest", array_type.get_cname () + "*"));

		// definition

		var block = new CCodeBlock ();

		if (requires_copy (array_type.element_type)) {
837
			push_context (new EmitContext ());
838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853

			var idx_decl = new CCodeDeclaration ("int");
			idx_decl.add_declarator (new CCodeVariableDeclarator ("i"));
			block.add_statement (idx_decl);

			var loop_body = new CCodeBlock ();
			loop_body.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeElementAccess (new CCodeIdentifier ("dest"), new CCodeIdentifier ("i")), get_ref_cexpression (array_type.element_type, new CCodeElementAccess (new CCodeIdentifier ("self"), new CCodeIdentifier ("i")), null, array_type))));

			var cfor = new CCodeForStatement (new CCodeBinaryExpression (CCodeBinaryOperator.LESS_THAN, new CCodeIdentifier ("i"), new CCodeConstant ("%d".printf (array_type.length))), loop_body);
			cfor.add_initializer (new CCodeAssignment (new CCodeIdentifier ("i"), new CCodeConstant ("0")));
			cfor.add_iterator (new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT, new CCodeIdentifier ("i")));
			block.add_statement (cfor);

			var cfrag = new CCodeFragment ();
			append_temp_decl (cfrag, temp_vars);
			block.add_statement (cfrag);
854 855

			pop_context ();
856
		} else {
857
			cfile.add_include ("string.h");
858

859 860 861 862 863 864 865 866 867 868 869 870 871
			var dup_call = new CCodeFunctionCall (new CCodeIdentifier ("memcpy"));
			dup_call.add_argument (new CCodeIdentifier ("dest"));
			dup_call.add_argument (new CCodeIdentifier ("self"));

			var sizeof_call = new CCodeFunctionCall (new CCodeIdentifier ("sizeof"));
			sizeof_call.add_argument (new CCodeIdentifier (array_type.element_type.get_cname ()));
			dup_call.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.MUL, new CCodeConstant ("%d".printf (array_type.length)), sizeof_call));

			block.add_statement (new CCodeExpressionStatement (dup_call));
		}

		// append to file

872
		cfile.add_type_member_declaration (function.copy ());
873 874

		function.block = block;
875
		cfile.add_function (function);
876 877 878 879

		return dup_func;
	}

880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920
	string generate_array_add_wrapper (ArrayType array_type) {
		string add_func = "_vala_array_add%d".printf (++next_array_add_id);

		if (!add_wrapper (add_func)) {
			// wrapper already defined
			return add_func;
		}

		// declaration

		var function = new CCodeFunction (add_func, "void");
		function.modifiers = CCodeModifiers.STATIC;

		function.add_parameter (new CCodeFormalParameter ("array", array_type.get_cname () + "*"));
		function.add_parameter (new CCodeFormalParameter ("length", "int*"));
		function.add_parameter (new CCodeFormalParameter ("size", "int*"));

		string typename = array_type.element_type.get_cname ();
		CCodeExpression value = new CCodeIdentifier ("value");
		if (array_type.element_type.is_real_struct_type ()) {
			if (!array_type.element_type.nullable || !array_type.element_type.value_owned) {
				typename = "const " + typename;
			}
			if (!array_type.element_type.nullable) {
				typename += "*";
				value = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, value);
			}
		}
		function.add_parameter (new CCodeFormalParameter ("value", typename));

		var array = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier ("array"));
		var length = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier ("length"));
		var size = new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier ("size"));

		// definition

		var block = new CCodeBlock ();

		var renew_call = new CCodeFunctionCall (new CCodeIdentifier ("g_renew"));
		renew_call.add_argument (new CCodeIdentifier (array_type.element_type.get_cname ()));
		renew_call.add_argument (array);
921 922 923 924 925 926
		if (array_type.element_type.is_reference_type_or_type_parameter ()) {
			// NULL terminate array
			renew_call.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, size, new CCodeConstant ("1")));
		} else {
			renew_call.add_argument (size);
		}
927 928 929 930 931 932 933 934 935 936

		var resize_block = new CCodeBlock ();
		resize_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (size, new CCodeConditionalExpression (size, new CCodeBinaryExpression (CCodeBinaryOperator.MUL, new CCodeConstant ("2"), size), new CCodeConstant ("4")))));
		resize_block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (array, renew_call)));

		var csizecheck = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, length, size);
		block.add_statement (new CCodeIfStatement (csizecheck, resize_block));

		block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeElementAccess (array, new CCodeUnaryExpression (CCodeUnaryOperator.POSTFIX_INCREMENT, length)), value)));

937 938 939 940 941
		if (array_type.element_type.is_reference_type_or_type_parameter ()) {
			// NULL terminate array
			block.add_statement (new CCodeExpressionStatement (new CCodeAssignment (new CCodeElementAccess (array, length), new CCodeConstant ("NULL"))));
		}

942 943
		// append to file

944
		cfile.add_type_member_declaration (function.copy ());
945 946

		function.block = block;
947
		cfile.add_function (function);
948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986

		return add_func;
	}

	bool is_array_add (Assignment assignment) {
		var binary = assignment.right as BinaryExpression;
		if (binary != null && binary.left.value_type is ArrayType) {
			if (binary.operator == BinaryOperator.PLUS) {
				if (assignment.left.symbol_reference == binary.left.symbol_reference) {
					return true;
				}
			}
		}

		return false;
	}

	public override void visit_assignment (Assignment assignment) {
		if (!is_array_add (assignment)) {
			base.visit_assignment (assignment);
			return;
		}

		var binary = assignment.right as BinaryExpression;

		var array = binary.left;
		var array_type = (ArrayType) array.value_type;
		var element = binary.right;

		var value_param = new FormalParameter ("value", element.target_type);

		var ccall = new CCodeFunctionCall (new CCodeIdentifier (generate_array_add_wrapper (array_type)));
		ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, (CCodeExpression) array.ccodenode));
		ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_array_length_cexpression (array)));
		ccall.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, get_array_size_cexpression (array)));
		ccall.add_argument (handle_struct_argument (value_param, element, (CCodeExpression) element.ccodenode));

		assignment.ccodenode = ccall;
	}
987

988
	public override void generate_parameter (FormalParameter param, CCodeFile decl_space, Map<int,CCodeFormalParameter> cparam_map, Map<int,CCodeExpression>? carg_map) {
Jürg Billeter's avatar
Jürg Billeter committed
989
		if (!(param.variable_type is ArrayType)) {
990
			base.generate_parameter (param, decl_space, cparam_map, carg_map);
991 992 993
			return;
		}

Jürg Billeter's avatar
Jürg Billeter committed
994
		string ctypename = param.variable_type.get_cname ();
995 996 997 998 999

		if (param.direction != ParameterDirection.IN) {
			ctypename += "*";
		}

1000
		param.ccodenode = new CCodeFormalParameter (get_variable_cname (param.name), ctypename);
1001

Jürg Billeter's avatar
Jürg Billeter committed
1002
		var array_type = (ArrayType) param.variable_type;
1003

1004 1005
		generate_type_declaration (array_type.element_type, decl_space);

1006 1007
		cparam_map.set (get_param_pos (param.cparameter_position), (CCodeFormalParameter) param.ccodenode);
		if (carg_map != null) {
1008
			carg_map.set (get_param_pos (param.cparameter_position), get_variable_cexpression (param.name));
1009 1010 1011
		}

		if (!param.no_array_length) {
1012 1013 1014 1015
			string length_ctype = "int";
			if (param.array_length_type != null) {
				length_ctype = param.array_length_type;
			}
1016
			if (param.direction != ParameterDirection.IN) {
1017
				length_ctype = "%s*".printf (length_ctype);
1018 1019 1020
			}
			
			for (int dim = 1; dim <= array_type.rank; dim++) {
1021
				var cparam = new CCodeFormalParameter (get_array_length_cname (get_variable_cname (param.name), dim), length_ctype);
1022 1023
				cparam_map.set (get_param_pos (param.carray_length_parameter_position + 0.01 * dim), cparam);
				if (carg_map != null) {
1024
					carg_map.set (get_param_pos (param.carray_length_parameter_position + 0.01 * dim), get_variable_cexpression (cparam.name));
1025 1026 1027 1028
				}
			}
		}
	}
1029
}