~ubuntu-branches/ubuntu/hardy/vala/hardy

« back to all changes in this revision

Viewing changes to gobject/valaccodegeneratorstruct.vala

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge, Marc-Andre Lureau, Sebastian Dröge
  • Date: 2007-10-15 14:37:51 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071015143751-zy7hqcyjutdyfkg3
Tags: 0.1.4-1
[ Marc-Andre Lureau ]
* New Upstream Version
* debian/patches:
  + Remove patch no longer needed in 0.1.4
* debian/rules
  + Add xsltproc build dependency for the Vala manual.
  + Add libenchant-dev build dependency for enchant test case.
* debian/control, debian/vala-doc.install:
  + Add a "vala-doc" documentation package.

[ Sebastian Dröge ]
* debian/control:
  + Let vala-doc suggest valac/devhelp and don't depend on libvala0.
* debian/libvala-dev.install:
  + Add the new vapicheck utility.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* valaccodegeneratorstruct.vala
 
2
 *
 
3
 * Copyright (C) 2006-2007  Jürg Billeter, Raffaele Sandrini
 
4
 *
 
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.
 
9
 
 
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.
 
14
 
 
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
 
18
 *
 
19
 * Author:
 
20
 *      Jürg Billeter <j@bitron.ch>
 
21
 *      Raffaele Sandrini <rasa@gmx.ch>
 
22
 */
 
23
 
 
24
using GLib;
 
25
 
 
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 ();
 
34
 
 
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_member_declaration;
 
42
                        def_frag = source_type_member_declaration;
 
43
                }
 
44
 
 
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 ())));
 
47
                }
 
48
 
 
49
                if (st.source_reference.comment != null) {
 
50
                        def_frag.append (new CCodeComment (st.source_reference.comment));
 
51
                }
 
52
                def_frag.append (instance_struct);
 
53
 
 
54
                st.accept_children (this);
 
55
 
 
56
                if (st.default_construction_method != null) {
 
57
                        var function = new CCodeFunction (st.get_lower_case_cprefix () + "free", "void");
 
58
                        if (st.access == SymbolAccessibility.PRIVATE) {
 
59
                                function.modifiers = CCodeModifiers.STATIC;
 
60
                        }
 
61
 
 
62
                        function.add_parameter (new CCodeFormalParameter ("self", st.get_cname () + "*"));
 
63
 
 
64
                        decl_frag.append (function.copy ());
 
65
 
 
66
                        var cblock = new CCodeBlock ();
 
67
 
 
68
                        cblock.add_statement (instance_dispose_fragment);
 
69
 
 
70
                        var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_slice_free"));
 
71
                        ccall.add_argument (new CCodeIdentifier (st.get_cname ()));
 
72
                        ccall.add_argument (new CCodeIdentifier ("self"));
 
73
                        cblock.add_statement (new CCodeExpressionStatement (ccall));
 
74
 
 
75
                        function.block = cblock;
 
76
 
 
77
                        def_frag.append (function);
 
78
                }
 
79
 
 
80
                current_type_symbol = old_type_symbol;
 
81
                instance_struct = old_instance_struct;
 
82
                instance_dispose_fragment = old_instance_dispose_fragment;
 
83
        }
 
84
}