update for 0.3.3 release
[vala-lang.git] / gobject / valaccodegeneratorstruct.vala
blobe79d4eb3340c3e926574c4109d021f884d2491e9
1 /* valaccodegeneratorstruct.vala
3 * Copyright (C) 2006-2008 Jürg Billeter, Raffaele Sandrini
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>
21 * Raffaele Sandrini <raffaele@sandrini.ch>
24 using GLib;
26 public class Vala.CCodeGenerator {
27 public override void visit_struct (Struct st) {
28 var old_type_symbol = current_type_symbol;
29 var old_instance_struct = instance_struct;
30 var old_instance_dispose_fragment = instance_dispose_fragment;
31 current_type_symbol = st;
32 instance_struct = new CCodeStruct ("_%s".printf (st.get_cname ()));
33 instance_dispose_fragment = new CCodeFragment ();
35 CCodeFragment decl_frag;
36 CCodeFragment def_frag;
37 if (st.access != SymbolAccessibility.PRIVATE) {
38 decl_frag = header_type_declaration;
39 def_frag = header_type_definition;
40 } else {
41 decl_frag = source_type_declaration;
42 def_frag = source_type_definition;
45 if (st.source_reference.file.cycle == null) {
46 decl_frag.append (new CCodeTypeDefinition ("struct _%s".printf (st.get_cname ()), new CCodeVariableDeclarator (st.get_cname ())));
49 if (st.source_reference.comment != null) {
50 def_frag.append (new CCodeComment (st.source_reference.comment));
52 def_frag.append (instance_struct);
54 st.accept_children (this);
56 current_type_symbol = old_type_symbol;
57 instance_struct = old_instance_struct;
58 instance_dispose_fragment = old_instance_dispose_fragment;