glib-2.0: Add float.parse/try_parse()
[vala-gnome.git] / vala / valaobjecttypesymbol.vala
blobeab81c425f6e0b211b6c5275fe61dbfee9817106
1 /* valaobjecttypesymbol.vala
3 * Copyright (C) 2008-2009 Jürg Billeter
4 * Copyright (C) 2008 Philip Van Hoof
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Author:
21 * Jürg Billeter <j@bitron.ch>
22 * Philip Van Hoof <pvanhoof@gnome.org>
26 /**
27 * Represents a runtime data type for objects and interfaces. This data type may
28 * be defined in Vala source code or imported from an external library with a
29 * Vala API file.
31 public abstract class Vala.ObjectTypeSymbol : TypeSymbol {
32 private List<TypeParameter> type_parameters = new ArrayList<TypeParameter> ();
34 private List<Symbol> members = new ArrayList<Symbol> ();
36 // member symbols
37 private List<Field> fields = new ArrayList<Field> ();
38 private List<Method> methods = new ArrayList<Method> ();
39 private List<Property> properties = new ArrayList<Property> ();
40 private List<Signal> signals = new ArrayList<Signal> ();
42 // inner types
43 private List<Class> classes = new ArrayList<Class> ();
44 private List<Struct> structs = new ArrayList<Struct> ();
45 private List<Enum> enums = new ArrayList<Enum> ();
46 private List<Delegate> delegates = new ArrayList<Delegate> ();
48 private List<Constant> constants = new ArrayList<Constant> ();
50 public ObjectTypeSymbol (string name, SourceReference? source_reference = null, Comment? comment = null) {
51 base (name, source_reference, comment);
54 /**
55 * Returns the list of members.
57 * @return list of members
59 public List<Symbol> get_members () {
60 return members;
63 /**
64 * Returns the list of fields.
66 * @return list of fields
68 public List<Field> get_fields () {
69 return fields;
72 /**
73 * Returns the list of methods.
75 * @return list of methods
77 public List<Method> get_methods () {
78 return methods;
81 /**
82 * Returns the list of properties.
84 * @return list of properties
86 public List<Property> get_properties () {
87 return properties;
90 /**
91 * Returns the list of signals.
93 * @return list of signals
95 public List<Signal> get_signals () {
96 return signals;
99 /**
100 * Adds the specified field as a member to this object-symbol.
102 * @param f a field
104 public override void add_field (Field f) {
105 fields.add (f);
106 members.add (f);
107 scope.add (f.name, f);
111 * Adds the specified method as a member to this object-symbol.
113 * @param m a method
115 public override void add_method (Method m) {
116 methods.add (m);
117 members.add (m);
118 scope.add (m.name, m);
122 * Adds the specified property as a member to this object-symbol.
124 * @param prop a property
126 public override void add_property (Property prop) {
127 properties.add (prop);
128 members.add (prop);
129 scope.add (prop.name, prop);
133 * Adds the specified signal as a member to this object-symbol.
135 * @param sig a signal
137 public override void add_signal (Signal sig) {
138 signals.add (sig);
139 members.add (sig);
140 scope.add (sig.name, sig);
144 * Returns the list of classes.
146 * @return list of classes
148 public List<Class> get_classes () {
149 return classes;
153 * Returns the list of structs.
155 * @return list of structs
157 public List<Struct> get_structs () {
158 return structs;
162 * Returns the list of enums.
164 * @return list of enums
166 public List<Enum> get_enums () {
167 return enums;
171 * Returns the list of delegates.
173 * @return list of delegates
175 public List<Delegate> get_delegates () {
176 return delegates;
180 * Adds the specified class as an inner class.
182 * @param cl a class
184 public override void add_class (Class cl) {
185 classes.add (cl);
186 scope.add (cl.name, cl);
190 * Adds the specified struct as an inner struct.
192 * @param st a struct
194 public override void add_struct (Struct st) {
195 structs.add (st);
196 scope.add (st.name, st);
200 * Adds the specified enum as an inner enum.
202 * @param en an enum
204 public override void add_enum (Enum en) {
205 enums.add (en);
206 scope.add (en.name, en);
210 * Adds the specified delegate as an inner delegate.
212 * @param d a delegate
214 public override void add_delegate (Delegate d) {
215 delegates.add (d);
216 scope.add (d.name, d);
220 * Adds the specified constant as a member to this interface.
222 * @param c a constant
224 public override void add_constant (Constant c) {
225 constants.add (c);
226 scope.add (c.name, c);
230 * Returns the list of constants.
232 * @return list of constants
234 public List<Constant> get_constants () {
235 return constants;
239 * Appends the specified parameter to the list of type parameters.
241 * @param p a type parameter
243 public void add_type_parameter (TypeParameter p) {
244 type_parameters.add (p);
245 scope.add (p.name, p);
249 * Returns a copy of the type parameter list.
251 * @return list of type parameters
253 public List<TypeParameter> get_type_parameters () {
254 return type_parameters;
257 public override int get_type_parameter_index (string name) {
258 int i = 0;
259 foreach (TypeParameter parameter in type_parameters) {
260 if (parameter.name == name) {
261 return i;
263 i++;
265 return -1;
268 public ObjectType get_this_type () {
269 var result = new ObjectType (this);
270 foreach (var type_parameter in get_type_parameters ()) {
271 var type_arg = new GenericType (type_parameter);
272 type_arg.value_owned = true;
273 result.add_type_argument (type_arg);
275 return result;
279 * Adds the specified method as a hidden member to this class,
280 * primarily used for default signal handlers.
282 * The hidden methods are not part of the `methods` collection.
284 * There may also be other use cases, eg, convert array.resize() to
285 * this type of method?
287 * @param m a method
289 public void add_hidden_method (Method m) {
290 if (m.binding == MemberBinding.INSTANCE) {
291 if (m.this_parameter != null) {
292 m.scope.remove (m.this_parameter.name);
294 m.this_parameter = new Parameter ("this", get_this_type ());
295 m.scope.add (m.this_parameter.name, m.this_parameter);
297 if (!(m.return_type is VoidType) && m.get_postconditions ().size > 0) {
298 if (m.result_var != null) {
299 m.scope.remove (m.result_var.name);
301 m.result_var = new LocalVariable (m.return_type.copy (), "result");
302 m.result_var.is_result = true;
305 scope.add (null, m);