codegen: Drop useless comma expression when handling struct arguments
[vala-lang.git] / codegen / valadovaarraymodule.vala
blobce249872c456eb19ab1a99e787f3ecbbad200be9
1 /* valadovaarraymodule.vala
3 * Copyright (C) 2006-2010 Jürg Billeter
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 * Author:
20 * Jürg Billeter <j@bitron.ch>
23 public class Vala.DovaArrayModule : DovaMethodCallModule {
24 void append_initializer_list (CCodeExpression name_cnode, InitializerList initializer_list, ref int i) {
25 foreach (Expression e in initializer_list.get_initializers ()) {
26 ccode.add_assignment (new CCodeElementAccess (name_cnode, new CCodeConstant (i.to_string ())), get_cvalue (e));
27 i++;
31 public override void visit_array_creation_expression (ArrayCreationExpression expr) {
32 var array_type = expr.target_type as ArrayType;
33 if (array_type != null && array_type.fixed_length) {
34 // no heap allocation for fixed-length arrays
36 var temp_var = get_temp_variable (array_type, true, expr);
37 var name_cnode = new CCodeIdentifier (temp_var.name);
38 int i = 0;
40 emit_temp_var (temp_var);
42 append_initializer_list (name_cnode, expr.initializer_list, ref i);
44 set_cvalue (expr, name_cnode);
46 return;
49 generate_method_declaration (array_class.default_construction_method, cfile);
51 var array_new = new CCodeFunctionCall (new CCodeIdentifier ("dova_array_new"));
52 array_new.add_argument (get_type_id_expression (expr.element_type));
54 // length of new array
55 array_new.add_argument (get_cvalue (expr.get_sizes ().get (0)));
57 var temp_var = get_temp_variable (expr.value_type, true, expr);
58 var name_cnode = get_variable_cexpression (temp_var.name);
60 emit_temp_var (temp_var);
62 ccode.add_assignment (name_cnode, array_new);
64 set_cvalue (expr, name_cnode);
67 public override void visit_element_access (ElementAccess expr) {
68 List<Expression> indices = expr.get_indices ();
70 var ccontainer = get_cvalue (expr.container);
71 var cindex = get_cvalue (indices[0]);
73 // access to element in an array
74 set_cvalue (expr, new CCodeElementAccess (ccontainer, cindex));