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>
27 * Represents a runtime data type. This data type may be defined in Vala source
28 * code or imported from an external library with a Vala API file.
30 public abstract class Vala
.TypeSymbol
: Symbol
{
31 public Comment? comment
{ get; set; }
33 private List
<string> cheader_filenames
= new ArrayList
<string> ();
35 public TypeSymbol (string? name
, SourceReference? source_reference
= null, Comment? comment
= null) {
36 base (name
, source_reference
);
37 this
.comment
= comment
;
41 * Returns the name of this data type as it is used in C code.
43 * @return the name to be used in C code
45 public abstract string get_cname (bool const_type
= false);
48 * Checks whether this data type has value or reference type semantics.
50 * @return true if this data type has reference type semantics
52 public virtual bool is_reference_type () {
57 * Returns the C function name that duplicates instances of this data
58 * type. The specified C function must accept one argument referencing
59 * the instance of this data type and return a reference to the
62 * @return the name of the C function if supported or null otherwise
64 public virtual string?
get_dup_function () {
69 * Returns the C function name that frees instances of this data type.
70 * The specified C function must accept one argument pointing to the
71 * instance to be freed.
73 * @return the name of the C function if supported or null otherwise
75 public virtual string?
get_free_function () {
80 * Returns the C function name that copies contents of instances of
81 * this data type. This is only applicable to structs. The specified
82 * C function must accept two arguments, the first is the source value
83 * and the second is the destination value.
85 * @return the name of the C function if supported or null otherwise
87 public virtual string?
get_copy_function () {
92 * Returns the C function name that destroys the contents of instances
93 * of this data type. This is only applicable to structs. The specified
94 * C function must accept one argument pointing to the instance to be
97 * @return the name of the C function if supported or null otherwise
99 public virtual string?
get_destroy_function () {
104 * Checks whether this data type supports reference counting. This is
105 * only valid for reference types.
107 * @return true if this data type supports reference counting
109 public virtual bool is_reference_counting () {
114 * Returns the C function name that increments the reference count of
115 * instances of this data type. This is only valid for data types
116 * supporting reference counting. The specified C function must accept
117 * one argument referencing the instance of this data type and return
120 * @return the name of the C function or null if this data type does not
121 * support reference counting
123 public virtual string?
get_ref_function () {
128 * Returns the C function name that decrements the reference count of
129 * instances of this data type. This is only valid for data types
130 * supporting reference counting. The specified C function must accept
131 * one argument referencing the instance of this data type.
133 * @return the name of the C function or null if this data type does not
134 * support reference counting
136 public virtual string?
get_unref_function () {
141 * Returns the C function name that sinks the reference count of
142 * "floating" instances of this data type. This is only valid for data
143 * types supporting floating references. The specified C function must
144 * accept one argument referencing the instance of this data type and
145 * return a non-floating reference.
147 * The ref_sink function is called for any constructor of the class and
148 * for other methods that have the class as a return value and are
149 * marked with the 'floating' attribute.
151 * @return the name of the C function or null if this data type does not
152 * support floating reference counts
154 public virtual string?
get_ref_sink_function () {
159 * Returns the C symbol representing the runtime type id for this data
160 * type. The specified symbol must express a registered GType.
162 * @return the name of the GType name in C code or null if this data
163 * type is not registered with GType
165 public virtual string?
get_type_id () {
170 * Returns the name of this data type as used in C code marshallers
172 * @return type name for marshallers
174 public virtual string?
get_marshaller_type_name () {
179 * Returns the cname of the GValue parameter spec function.
181 public virtual string?
get_param_spec_function () {
186 * Returns the cname of the GValue getter function.
188 public virtual string?
get_get_value_function () {
193 * Returns the cname of the GValue setter function.
195 public virtual string?
get_set_value_function () {
200 * Returns the C name of this data type in upper case. Words are
201 * separated by underscores. The upper case C name of the namespace is
202 * prefix of the result.
204 * @param infix a string to be placed between namespace and data type
206 * @return the upper case name to be used in C code
208 public virtual string?
get_upper_case_cname (string? infix
= null) {
213 * Returns the default value for the given type. Returning null means
214 * there is no default value (i.e. not that the default name is NULL).
216 * @return the name of the default value
218 public virtual string?
get_default_value () {
222 public override List
<string> get_cheader_filenames () {
223 // parent_symbol can be null on incremental parsing
224 if (cheader_filenames
.size
== 0 && parent_symbol
!= null) {
225 /* default to header filenames of the namespace */
226 foreach (string filename
in parent_symbol
.get_cheader_filenames ()) {
227 add_cheader_filename (filename
);
230 if (cheader_filenames
.size
== 0 && source_reference
!= null && !external_package
) {
231 // don't add default include directives for VAPI files
232 cheader_filenames
.add (source_reference
.file
.get_cinclude_filename ());
235 return new ReadOnlyList
<string> (cheader_filenames
);
239 * Adds a filename to the list of C header filenames users of this data
242 * @param filename a C header filename
244 public void add_cheader_filename (string filename
) {
245 cheader_filenames
.add (filename
);
249 * Checks whether this data type is equal to or a subtype of the
250 * specified data type.
252 * @param t a data type
253 * @return true if t is a supertype of this data type, false otherwise
255 public virtual bool is_subtype_of (TypeSymbol t
) {
260 * Return the index of the specified type parameter name.
262 public virtual int get_type_parameter_index (string name
) {
267 * Returns type signature as used for GVariant and D-Bus
269 public virtual string?
get_type_signature () {