codegen: Fix array size variable on assignment
[vala-lang.git] / codegen / valadovastructmodule.vala
blob94d7ef49cdd06f69830061b2b0588adb9d65da9d
1 /* valadovastructmodule.vala
3 * Copyright (C) 2006-2009 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 using GLib;
25 public abstract class Vala.DovaStructModule : DovaBaseModule {
26 public override void generate_struct_declaration (Struct st, CCodeFile decl_space) {
27 if (add_symbol_declaration (decl_space, st, st.get_cname ())) {
28 return;
31 if (st.base_struct != null) {
32 generate_struct_declaration (st.base_struct, decl_space);
34 decl_space.add_type_declaration (new CCodeTypeDefinition (st.base_struct.get_cname (), new CCodeVariableDeclarator (st.get_cname ())));
35 return;
38 if (st.is_boolean_type ()) {
39 // typedef for boolean types
40 return;
41 } else if (st.is_integer_type ()) {
42 // typedef for integral types
43 return;
44 } else if (st.is_decimal_floating_type ()) {
45 // typedef for decimal floating types
46 return;
47 } else if (st.is_floating_type ()) {
48 // typedef for generic floating types
49 return;
52 var instance_struct = new CCodeStruct ("_%s".printf (st.get_cname ()));
54 foreach (Field f in st.get_fields ()) {
55 string field_ctype = f.variable_type.get_cname ();
56 if (f.is_volatile) {
57 field_ctype = "volatile " + field_ctype;
60 if (f.binding == MemberBinding.INSTANCE) {
61 generate_type_declaration (f.variable_type, decl_space);
63 instance_struct.add_field (field_ctype, f.get_cname () + f.variable_type.get_cdeclarator_suffix ());
67 decl_space.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf (st.get_cname ()), new CCodeVariableDeclarator (st.get_cname ())));
69 decl_space.add_type_definition (instance_struct);
72 public override void visit_struct (Struct st) {
73 push_context (new EmitContext (st));
75 generate_struct_declaration (st, cfile);
77 if (!st.is_internal_symbol ()) {
78 generate_struct_declaration (st, header_file);
81 st.accept_children (this);
83 pop_context ();