3 * Copyright (C) 2011 Florian Brosch
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 * Florian Brosch <flo.brosch@gmail.com>
24 using Valadoc
.Content
;
27 * Represents a struct declaration.
29 public class Valadoc
.Api
.Struct
: TypeSymbol
{
30 private string? dup_function_cname
;
31 private string? copy_function_cname
;
32 private string? free_function_cname
;
33 private string? destroy_function_cname
;
34 private string? type_id
;
35 private string? cname
;
37 public Struct (Node parent
, SourceFile file
, string name
, SymbolAccessibility accessibility
,
38 SourceComment? comment
, string? cname
, string? type_macro_name
,
39 string? type_function_name
, string? type_id
, string? dup_function_cname
,
40 string? copy_function_cname
, string? destroy_function_cname
,
41 string? free_function_cname
, bool is_basic_type
, Vala
.Struct data
)
43 base (parent
, file
, name
, accessibility
, comment
, type_macro_name
, null, null,
44 type_function_name
, is_basic_type
, data
);
46 this
.dup_function_cname
= dup_function_cname
;
47 this
.copy_function_cname
= copy_function_cname
;
48 this
.free_function_cname
= free_function_cname
;
49 this
.destroy_function_cname
= destroy_function_cname
;
55 * Specifies the base struct.
57 public TypeReference? base_type
{
64 * Returns the name of this struct as it is used in C.
66 public string?
get_cname () {
71 * Returns the C symbol representing the runtime type id for this data type.
73 public string?
get_type_id () {
78 * Returns the C function name that duplicates instances of this data
81 public string?
get_dup_function_cname () {
82 return dup_function_cname
;
86 * Returns the C function name that copies instances of this data
89 public string?
get_copy_function_cname () {
90 return copy_function_cname
;
94 * Returns the C function name that frees instances of this data type.
96 public string?
get_free_function_cname () {
97 return free_function_cname
;
101 * Returns the C function name that destroys instances of this data type.
103 public string?
get_destroy_function_cname () {
104 return destroy_function_cname
;
110 public override NodeType node_type
{
111 get { return NodeType
.STRUCT
; }
117 public override void accept (Visitor visitor
) {
118 visitor
.visit_struct (this
);
122 private Vala
.Set
<Struct
> _known_child_structs
= new Vala
.HashSet
<Struct
> ();
125 * Returns a list of all known structs based on this struct
127 public Vala
.Collection
<Struct
> get_known_child_structs () {
128 return _known_child_structs
;
131 public void register_child_struct (Struct stru
) {
132 if (this
.base_type
!= null) {
133 ((Struct
) this
.base_type
.data_type
).register_child_struct (stru
);
136 _known_child_structs
.add (stru
);
143 protected override Inline
build_signature () {
144 var signature
= new
SignatureBuilder ();
146 signature
.append_keyword (accessibility
.to_string ());
147 signature
.append_keyword ("struct");
148 signature
.append_symbol (this
);
150 var type_parameters
= get_children_by_type (NodeType
.TYPE_PARAMETER
, false);
151 if (type_parameters
.size
> 0) {
152 signature
.append ("<", false);
154 foreach (Item param
in type_parameters
) {
156 signature
.append (",", false);
158 signature
.append_content (param
.signature
, false);
161 signature
.append (">", false);
164 if (base_type
!= null) {
165 signature
.append (":");
167 signature
.append_content (base_type
.signature
);
170 return signature
.get ();