3 * Copyright (C) 2006-2007 Raffaele Sandrini, Jürg Billeter
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 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 * Raffaele Sandrini <rasa@gmx.ch>
21 * Jürg Billeter <j@bitron.ch>
27 * Represents an array type i.e. everything with direct accessable elements.
29 public class Vala
.Array
: DataType
{
32 * DataType of which this is an array of.
34 public DataType element_type
{ get; set construct; }
37 * TypeParameter of which this is an array of.
39 public TypeParameter element_type_parameter
{ get; set construct; }
42 * The rank of this array.
44 public int rank
{ get; set construct; }
48 private ArrayLengthField length_field
;
50 private ArrayResizeMethod resize_method
;
52 public Array (DataType
! _element_type
, int _rank
, SourceReference
! _source_reference
) {
54 element_type
= _element_type
;
55 source_reference
= _source_reference
;
58 public Array
.with_type_parameter (TypeParameter
! _element_type_parameter
, int _rank
, SourceReference
! _source_reference
) {
60 element_type_parameter
= _element_type_parameter
;
61 source_reference
= _source_reference
;
65 /* FIXME: this implementation reveals compiler bugs
74 name = "%s[%s]".printf (element_type.name, commas); */
77 Report
.error (null, "internal: attempt to create an array with rank smaller than 1");
81 if (element_type
!= null) {
82 name
= "%s[".printf (element_type
.name
);
84 name
= "%s[".printf (element_type_parameter
.name
);
87 name
= "%s,".printf (name
);
90 name
= "%s]".printf (name
);
92 length_field
= new
ArrayLengthField (source_reference
);
93 length_field
.symbol
= new
Symbol (length_field
);
95 resize_method
= new
ArrayResizeMethod (source_reference
);
96 resize_method
.symbol
= new
Symbol (resize_method
);
100 * Returns the name of this data type as it is used in C code.
102 * @return the name to be used in C code
104 public override string get_cname (bool const_type
= false) {
106 if (element_type
!= null) {
107 if (element_type
.is_reference_type ()) {
108 cname
= "%s*".printf (element_type
.get_cname ());
110 cname
= element_type
.get_cname ();
121 * Checks whether this data type has value or reference type semantics.
123 * @return true if this data type has reference type semantics
125 public override bool is_reference_type () {
130 * Returns the C name of this data type in upper case. Words are
131 * separated by underscores. The upper case C name of the namespace is
132 * prefix of the result.
134 * @param infix a string to be placed between namespace and data type
136 * @return the upper case name to be used in C code
138 public override string get_upper_case_cname (string infix
) {
143 * Returns the C name of this data type in lower case. Words are
144 * separated by underscores. The lower case C name of the namespace is
145 * prefix of the result.
147 * @param infix a string to be placed between namespace and data type
149 * @return the lower case name to be used in C code
151 public override string get_lower_case_cname (string infix
) {
156 * Returns the C function name that frees instances of this data type.
157 * This is only valid for data types with reference type semantics that
158 * do not support reference counting. The specified C function must
159 * accept one argument pointing to the instance to be freed.
161 * @return the name of the C function or null if this data type is not a
162 * reference type or if it supports reference counting
164 public override string get_free_function () {
169 * Returns a list of C header filenames users of this data type must
172 * @return list of C header filenames for this data type
174 public override List
<string> get_cheader_filenames () {
175 if (element_type
!= null) {
176 return element_type
.get_cheader_filenames ();
182 public override string get_marshaller_type_name () {
186 public override string get_get_value_function () {
187 return "g_value_get_pointer";
190 public override string get_set_value_function () {
191 return "g_value_set_pointer";
194 public ArrayLengthField
get_length_field () {
198 public ArrayResizeMethod
get_resize_method () {
199 return resize_method
;