1
/* valaccodegeneratorstruct.vala
3
* Copyright (C) 2006-2007 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
20
* Jürg Billeter <j@bitron.ch>
21
* Raffaele Sandrini <rasa@gmx.ch>
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;
41
decl_frag = source_type_member_declaration;
42
def_frag = source_type_member_declaration;
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
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;
62
function.add_parameter (new CCodeFormalParameter ("self", st.get_cname () + "*"));
64
decl_frag.append (function.copy ());
66
var cblock = new CCodeBlock ();
68
cblock.add_statement (instance_dispose_fragment);
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));
75
function.block = cblock;
77
def_frag.append (function);
80
current_type_symbol = old_type_symbol;
81
instance_struct = old_instance_struct;
82
instance_dispose_fragment = old_instance_dispose_fragment;