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
20 * Jürg Billeter <j@bitron.ch>
21 * Raffaele Sandrini <raffaele@sandrini.ch>
28 * Represents a runtime data type. This data type may be defined in Vala source
29 * code or imported from an external library with a Vala API file.
31 public abstract class Vala
.TypeSymbol
: Symbol
{
32 public Comment? comment
{ get; set; }
34 private Gee
.List
<string> cheader_filenames
= new ArrayList
<string> ();
36 public TypeSymbol (string? name
, SourceReference? source_reference
= null, Comment? comment
= null) {
37 base (name
, source_reference
);
38 this
.comment
= comment
;
42 * Returns the name of this data type as it is used in C code.
44 * @return the name to be used in C code
46 public abstract string get_cname (bool const_type
= false);
49 * Checks whether this data type has value or reference type semantics.
51 * @return true if this data type has reference type semantics
53 public virtual bool is_reference_type () {
58 * Returns the C function name that duplicates instances of this data
59 * type. The specified C function must accept one argument referencing
60 * the instance of this data type and return a reference to the
63 * @return the name of the C function if supported or null otherwise
65 public virtual string?
get_dup_function () {
70 * Returns the C function name that frees instances of this data type.
71 * The specified C function must accept one argument pointing to the
72 * instance to be freed.
74 * @return the name of the C function if supported or null otherwise
76 public virtual string?
get_free_function () {
81 * Returns the C function name that copies contents of instances of
82 * this data type. This is only applicable to structs. The specified
83 * C function must accept two arguments, the first is the source value
84 * and the second is the destination value.
86 * @return the name of the C function if supported or null otherwise
88 public virtual string?
get_copy_function () {
93 * Returns the C function name that destroys the contents of instances
94 * of this data type. This is only applicable to structs. The specified
95 * C function must accept one argument pointing to the instance to be
98 * @return the name of the C function if supported or null otherwise
100 public virtual string?
get_destroy_function () {
105 * Checks whether this data type supports reference counting. This is
106 * only valid for reference types.
108 * @return true if this data type supports reference counting
110 public virtual bool is_reference_counting () {
115 * Returns the C function name that increments the reference count of
116 * instances of this data type. This is only valid for data types
117 * supporting reference counting. The specified C function must accept
118 * one argument referencing the instance of this data type and return
121 * @return the name of the C function or null if this data type does not
122 * support reference counting
124 public virtual string?
get_ref_function () {
129 * Returns the C function name that decrements the reference count of
130 * instances of this data type. This is only valid for data types
131 * supporting reference counting. The specified C function must accept
132 * one argument referencing the instance of this data type.
134 * @return the name of the C function or null if this data type does not
135 * support reference counting
137 public virtual string?
get_unref_function () {
142 * Returns the C function name that sinks the reference count of
143 * "floating" instances of this data type. This is only valid for data
144 * types supporting floating references. The specified C function must
145 * accept one argument referencing the instance of this data type and
146 * return a non-floating reference.
148 * The ref_sink function is called for any constructor of the class and
149 * for other methods that have the class as a return value and are
150 * marked with the 'floating' attribute.
152 * @return the name of the C function or null if this data type does not
153 * support floating reference counts
155 public virtual string?
get_ref_sink_function () {
160 * Returns the C symbol representing the runtime type id for this data
161 * type. The specified symbol must express a registered GType.
163 * @return the name of the GType name in C code or null if this data
164 * type is not registered with GType
166 public virtual string?
get_type_id () {
171 * Returns the name of this data type as used in C code marshallers
173 * @return type name for marshallers
175 public virtual string?
get_marshaller_type_name () {
180 * Returns the cname of the GValue parameter spec function.
182 public virtual string?
get_param_spec_function () {
187 * Returns the cname of the GValue getter function.
189 public virtual string?
get_get_value_function () {
194 * Returns the cname of the GValue setter function.
196 public virtual string?
get_set_value_function () {
201 * Returns the C name of this data type in upper case. Words are
202 * separated by underscores. The upper case C name of the namespace is
203 * prefix of the result.
205 * @param infix a string to be placed between namespace and data type
207 * @return the upper case name to be used in C code
209 public virtual string?
get_upper_case_cname (string? infix
= null) {
214 * Returns the default value for the given type. Returning null means
215 * there is no default value (i.e. not that the default name is NULL).
217 * @return the name of the default value
219 public virtual string?
get_default_value () {
223 public override Gee
.List
<string> get_cheader_filenames () {
224 // parent_symbol can be null on incremental parsing
225 if (cheader_filenames
.size
== 0 && parent_symbol
!= null) {
226 /* default to header filenames of the namespace */
227 foreach (string filename
in parent_symbol
.get_cheader_filenames ()) {
228 add_cheader_filename (filename
);
231 if (cheader_filenames
.size
== 0 && source_reference
!= null && !external_package
) {
232 // don't add default include directives for VAPI files
233 cheader_filenames
.add (source_reference
.file
.get_cinclude_filename ());
236 return new ReadOnlyList
<string> (cheader_filenames
);
240 * Adds a filename to the list of C header filenames users of this data
243 * @param filename a C header filename
245 public void add_cheader_filename (string filename
) {
246 cheader_filenames
.add (filename
);
250 * Checks whether this data type is equal to or a subtype of the
251 * specified data type.
253 * @param t a data type
254 * @return true if t is a supertype of this data type, false otherwise
256 public virtual bool is_subtype_of (TypeSymbol t
) {
261 * Return the index of the specified type parameter name.
263 public virtual int get_type_parameter_index (string name
) {
268 * Returns type signature as used for GVariant and D-Bus
270 public virtual string?
get_type_signature () {