3 * Copyright (C) 2011 Florian Brosch
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 * Florian Brosch <flo.brosch@gmail.com>
26 public class Valadoc
.Drivers
.SymbolResolver
: Visitor
{
27 private Vala
.HashMap
<Vala
.Symbol
, Symbol
> symbol_map
;
28 private Valadoc
.Api
.Class glib_error
;
29 private Api
.Tree root
;
31 public SymbolResolver (TreeBuilder builder
) {
32 this
.symbol_map
= builder
.get_symbol_map ();
33 this
.glib_error
= builder
.get_glib_error ();
36 public Symbol?
resolve (Vala
.Symbol symbol
) {
37 return symbol_map
.get (symbol
);
40 private void resolve_thrown_list (Symbol symbol
, Vala
.List
<Vala
.DataType
> types
) {
41 foreach (Vala
.DataType type
in types
) {
42 Vala
.ErrorDomain vala_edom
= (Vala
.ErrorDomain
) type
.data_type
;
43 Symbol? edom
= symbol_map
.get (vala_edom
);
44 symbol
.add_child (edom ?? glib_error
);
48 private void resolve_array_type_references (Api
.Array ptr
) {
49 Api
.Item data_type
= ptr
.data_type
;
50 if (data_type
== null) {
52 } else if (data_type is Api
.Array
) {
53 resolve_array_type_references ((Api
.Array
) data_type
);
54 } else if (data_type is Pointer
) {
55 resolve_pointer_type_references ((Api
.Pointer
) data_type
);
57 resolve_type_reference ((TypeReference
) data_type
);
61 private void resolve_pointer_type_references (Pointer ptr
) {
62 Api
.Item type
= ptr
.data_type
;
65 } else if (type is Api
.Array
) {
66 resolve_array_type_references ((Api
.Array
) type
);
67 } else if (type is Pointer
) {
68 resolve_pointer_type_references ((Pointer
) type
);
70 resolve_type_reference ((TypeReference
) type
);
74 private void resolve_type_reference (TypeReference reference
) {
75 Vala
.DataType vtyperef
= (Vala
.DataType
) reference
.data
;
76 if (vtyperef is Vala
.ErrorType
) {
77 Vala
.ErrorDomain verrdom
= ((Vala
.ErrorType
) vtyperef
).error_domain
;
78 if (verrdom
!= null) {
79 reference
.data_type
= resolve (verrdom
);
81 reference
.data_type
= glib_error
;
83 } else if (vtyperef is Vala
.DelegateType
) {
84 reference
.data_type
= resolve (((Vala
.DelegateType
) vtyperef
).delegate_symbol
);
85 } else if (vtyperef is Vala
.GenericType
) {
86 reference
.data_type
= resolve (((Vala
.GenericType
) vtyperef
).type_parameter
);
87 } else if (vtyperef
.data_type
!= null) {
88 reference
.data_type
= resolve (vtyperef
.data_type
);
92 foreach (TypeReference type_param_ref
in reference
.get_type_arguments ()) {
93 resolve_type_reference (type_param_ref
);
96 if (reference
.data_type is Pointer
) {
97 resolve_pointer_type_references ((Pointer
)reference
.data_type
);
98 } else if (reference
.data_type is Api
.Array
) {
99 resolve_array_type_references ((Api
.Array
)reference
.data_type
);
106 public override void visit_tree (Api
.Tree item
) {
108 item
.accept_children (this
);
115 public override void visit_package (Package item
) {
116 item
.accept_all_children (this
, false);
122 public override void visit_namespace (Namespace item
) {
123 item
.accept_all_children (this
, false);
129 public override void visit_interface (Interface item
) {
130 Vala
.Collection
<TypeReference
> interfaces
= item
.get_implemented_interface_list ();
131 foreach (var type_ref
in interfaces
) {
132 resolve_type_reference (type_ref
);
135 if (item
.base_type
!= null) {
136 resolve_type_reference (item
.base_type
);
139 item
.accept_all_children (this
, false);
145 public override void visit_class (Class item
) {
146 Vala
.Collection
<TypeReference
> interfaces
= item
.get_implemented_interface_list ();
147 foreach (TypeReference type_ref
in interfaces
) {
148 resolve_type_reference (type_ref
);
151 if (item
.base_type
!= null) {
152 resolve_type_reference (item
.base_type
);
155 item
.accept_all_children (this
, false);
161 public override void visit_struct (Struct item
) {
162 if (item
.base_type
!= null) {
163 resolve_type_reference (item
.base_type
);
166 item
.accept_all_children (this
, false);
172 public override void visit_property (Property item
) {
173 Vala
.Property vala_property
= item
.data as Vala
.Property
;
174 Vala
.Property? base_vala_property
= null;
176 if (vala_property
.base_property
!= null) {
177 base_vala_property
= vala_property
.base_property
;
178 } else if (vala_property
.base_interface_property
!= null) {
179 base_vala_property
= vala_property
.base_interface_property
;
181 if (base_vala_property
== vala_property
&& vala_property
.base_interface_property
!= null) {
182 base_vala_property
= vala_property
.base_interface_property
;
184 if (base_vala_property
!= null) {
185 item
.base_property
= (Property?
) resolve (base_vala_property
);
188 resolve_type_reference (item
.property_type
);
190 item
.accept_all_children (this
, false);
196 public override void visit_field (Field item
) {
197 resolve_type_reference (item
.field_type
);
199 item
.accept_all_children (this
, false);
205 public override void visit_constant (Constant item
) {
206 resolve_type_reference (item
.constant_type
);
208 item
.accept_all_children (this
, false);
214 public override void visit_delegate (Delegate item
) {
215 Vala
.Delegate vala_delegate
= item
.data as Vala
.Delegate
;
217 resolve_type_reference (item
.return_type
);
219 resolve_thrown_list (item
, vala_delegate
.get_error_types ());
221 item
.accept_all_children (this
, false);
227 public override void visit_signal (Api
.Signal item
) {
228 resolve_type_reference (item
.return_type
);
230 item
.accept_all_children (this
, false);
236 public override void visit_method (Method item
) {
237 Vala
.Method vala_method
= item
.data as Vala
.Method
;
238 Vala
.Method? base_vala_method
= null;
239 if (vala_method
.base_method
!= null) {
240 base_vala_method
= vala_method
.base_method
;
241 } else if (vala_method
.base_interface_method
!= null) {
242 base_vala_method
= vala_method
.base_interface_method
;
244 if (base_vala_method
== vala_method
&& vala_method
.base_interface_method
!= null) {
245 base_vala_method
= vala_method
.base_interface_method
;
247 if (base_vala_method
!= null) {
248 item
.base_method
= (Method?
) resolve (base_vala_method
);
251 resolve_thrown_list (item
, vala_method
.get_error_types ());
253 resolve_type_reference (item
.return_type
);
255 item
.accept_all_children (this
, false);
261 public override void visit_type_parameter (TypeParameter item
) {
262 item
.accept_all_children (this
, false);
268 public override void visit_formal_parameter (FormalParameter item
) {
273 if (((Vala
.Parameter
) item
.data
).initializer
!= null) {
274 SignatureBuilder signature
= new
SignatureBuilder ();
275 InitializerBuilder ibuilder
= new
InitializerBuilder (signature
, symbol_map
);
276 ((Vala
.Parameter
) item
.data
).initializer
.accept (ibuilder
);
277 item
.default_value
= signature
.get ();
280 resolve_type_reference (item
.parameter_type
);
281 item
.accept_all_children (this
, false);
287 public override void visit_error_domain (ErrorDomain item
) {
288 item
.accept_all_children (this
, false);
294 public override void visit_error_code (ErrorCode item
) {
295 item
.accept_all_children (this
, false);
301 public override void visit_enum (Enum item
) {
302 item
.accept_all_children (this
, false);
308 public override void visit_enum_value (Api
.EnumValue item
) {
310 if (((Vala
.EnumValue
) item
.data
).value
!= null) {
311 SignatureBuilder signature
= new
SignatureBuilder ();
312 InitializerBuilder ibuilder
= new
InitializerBuilder (signature
, symbol_map
);
313 ((Vala
.EnumValue
) item
.data
).value
.accept (ibuilder
);
314 item
.default_value
= signature
.get ();
317 item
.accept_all_children (this
, false);