remove obsolete ref modifier and callback keyword
[vala-lang.git] / vala / valaarray.vala
blobf618a4b45153e768396fd81040e4e2a71c176df8
1 /* valaarray.vala
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
19 * Author:
20 * Raffaele Sandrini <rasa@gmx.ch>
21 * Jürg Billeter <j@bitron.ch>
24 using GLib;
26 /**
27 * Represents an array type i.e. everything with direct accessable elements.
29 public class Vala.Array : DataType {
31 /**
32 * DataType of which this is an array of.
34 public DataType element_type { get; set construct; }
36 /**
37 * TypeParameter of which this is an array of.
39 public TypeParameter element_type_parameter { get; set construct; }
41 /**
42 * The rank of this array.
44 public int rank { get; set construct; }
46 private string cname;
48 private ArrayLengthField length_field;
50 private ArrayResizeMethod resize_method;
52 public Array (DataType! _element_type, int _rank, SourceReference! _source_reference) {
53 rank = _rank;
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) {
59 rank = _rank;
60 element_type_parameter = _element_type_parameter;
61 source_reference = _source_reference;
64 construct {
65 /* FIXME: this implementation reveals compiler bugs
66 string commas = "";
67 int i = rank - 1;
69 while (i > 0) {
70 string += ",";
71 i--;
74 name = "%s[%s]".printf (element_type.name, commas); */
76 if (rank < 1) {
77 Report.error (null, "internal: attempt to create an array with rank smaller than 1");
80 int i = rank - 1;
81 if (element_type != null) {
82 name = "%s[".printf (element_type.name);
83 } else {
84 name = "%s[".printf (element_type_parameter.name);
86 while (i > 0) {
87 name = "%s,".printf (name);
88 i--;
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);
99 /**
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) {
105 if (cname == null) {
106 if (element_type != null) {
107 if (element_type.is_reference_type ()) {
108 cname = "%s*".printf (element_type.get_cname ());
109 } else {
110 cname = element_type.get_cname ();
112 } else {
113 cname = "gpointer";
117 return 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 () {
126 return true;
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
135 * name or null
136 * @return the upper case name to be used in C code
138 public override string get_upper_case_cname (string infix) {
139 return null;
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
148 * name or null
149 * @return the lower case name to be used in C code
151 public override string get_lower_case_cname (string infix) {
152 return null;
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 () {
165 return "g_free";
169 * Returns a list of C header filenames users of this data type must
170 * include.
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 ();
177 } else {
178 return null;
182 public override string get_marshaller_type_name () {
183 return "POINTER";
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 () {
195 return length_field;
198 public ArrayResizeMethod get_resize_method () {
199 return resize_method;