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
21 * Jürg Billeter <j@bitron.ch>
22 * Philip Van Hoof <pvanhoof@gnome.org>
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
31 public abstract class Vala
.ObjectTypeSymbol
: TypeSymbol
{
32 private List
<TypeParameter
> type_parameters
= new ArrayList
<TypeParameter
> ();
34 private List
<Symbol
> members
= new ArrayList
<Symbol
> ();
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
> ();
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
);
55 * Returns the list of members.
57 * @return list of members
59 public List
<Symbol
> get_members () {
64 * Returns the list of fields.
66 * @return list of fields
68 public List
<Field
> get_fields () {
73 * Returns the list of methods.
75 * @return list of methods
77 public List
<Method
> get_methods () {
82 * Returns the list of properties.
84 * @return list of properties
86 public List
<Property
> get_properties () {
91 * Returns the list of signals.
93 * @return list of signals
95 public List
<Signal
> get_signals () {
100 * Adds the specified field as a member to this object-symbol.
104 public override void add_field (Field f
) {
107 scope
.add (f
.name
, f
);
111 * Adds the specified method as a member to this object-symbol.
115 public override void add_method (Method 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
);
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
) {
140 scope
.add (sig
.name
, sig
);
144 * Returns the list of classes.
146 * @return list of classes
148 public List
<Class
> get_classes () {
153 * Returns the list of structs.
155 * @return list of structs
157 public List
<Struct
> get_structs () {
162 * Returns the list of enums.
164 * @return list of enums
166 public List
<Enum
> get_enums () {
171 * Returns the list of delegates.
173 * @return list of delegates
175 public List
<Delegate
> get_delegates () {
180 * Adds the specified class as an inner class.
184 public override void add_class (Class cl
) {
186 scope
.add (cl
.name
, cl
);
190 * Adds the specified struct as an inner struct.
194 public override void add_struct (Struct st
) {
196 scope
.add (st
.name
, st
);
200 * Adds the specified enum as an inner enum.
204 public override void add_enum (Enum 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
) {
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
) {
226 scope
.add (c
.name
, c
);
230 * Returns the list of constants.
232 * @return list of constants
234 public List
<Constant
> get_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
) {
259 foreach (TypeParameter parameter
in type_parameters
) {
260 if (parameter
.name
== name
) {
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
);
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?
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;