3 * Copyright (C) 2006-2010 Jürg Billeter
4 * Copyright (C) 2006-2008 Raffaele Sandrini
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 * Raffaele Sandrini <raffaele@sandrini.ch>
28 * Code visitor parsing all GIDL files.
30 public class Vala
.GIdlParser
: CodeVisitor
{
31 private CodeContext context
;
33 private SourceFile current_source_file
;
35 private SourceReference current_source_reference
;
37 private Namespace current_namespace
;
38 private TypeSymbol current_data_type
;
39 private Map
<string,string> codenode_attributes_map
;
40 private Map
<PatternSpec
*,string> codenode_attributes_patterns
;
41 private Set
<string> current_type_symbol_set
;
43 private Map
<string,TypeSymbol
> cname_type_map
;
45 static GLib
.Regex type_from_string_regex
;
48 * Parse all source files in the specified code context and build a
51 * @param context a code context
53 public void parse (CodeContext context
) {
54 cname_type_map
= new HashMap
<string,TypeSymbol
> (str_hash
, str_equal
);
56 this
.context
= context
;
57 context
.accept (this
);
59 cname_type_map
= null;
62 public override void visit_namespace (Namespace ns
) {
63 ns
.accept_children (this
);
66 public override void visit_class (Class cl
) {
70 public override void visit_struct (Struct st
) {
74 public override void visit_interface (Interface iface
) {
78 public override void visit_enum (Enum en
) {
82 public override void visit_error_domain (ErrorDomain ed
) {
86 public override void visit_delegate (Delegate d
) {
90 private void visit_type (TypeSymbol t
) {
91 if (!cname_type_map
.contains (t
.get_cname ())) {
92 cname_type_map
[t
.get_cname ()] = t
;
96 public override void visit_source_file (SourceFile source_file
) {
97 if (source_file
.filename
.has_suffix (".gi")) {
98 parse_file (source_file
);
102 private void parse_file (SourceFile source_file
) {
103 string metadata_filename
= "%s.metadata".printf (source_file
.filename
.substring (0, source_file
.filename
.length
- ".gi".length
));
105 current_source_file
= source_file
;
107 codenode_attributes_map
= new HashMap
<string,string> (str_hash
, str_equal
);
108 codenode_attributes_patterns
= new HashMap
<PatternSpec
*,string> (direct_hash
, (EqualFunc
) PatternSpec
.equal
);
110 if (FileUtils
.test (metadata_filename
, FileTest
.EXISTS
)) {
113 FileUtils
.get_contents (metadata_filename
, out metadata
, null);
115 foreach (string line
in metadata
.split ("\n")) {
116 if (line
.has_prefix ("#")) {
117 // ignore comment lines
121 var tokens
= line
.split (" ", 2);
123 if (null == tokens
[0]) {
127 if (-1 != tokens
[0].index_of_char ('*')) {
128 PatternSpec
* pattern
= new
PatternSpec (tokens
[0]);
129 codenode_attributes_patterns
[pattern
] = tokens
[0];
132 codenode_attributes_map
[tokens
[0]] = tokens
[1];
134 } catch (FileError e
) {
135 Report
.error (null, "Unable to read metadata file: %s".printf (e
.message
));
140 var modules
= Idl
.parse_file (source_file
.filename
);
142 current_source_reference
= new
SourceReference (source_file
);
144 foreach (weak IdlModule module
in modules
) {
145 var ns
= parse_module (module
);
147 context
.root
.add_namespace (ns
);
150 } catch (MarkupError e
) {
151 Report
.error (null, "Unable to parse GIDL file: %s".printf (e
.message
));
155 private string fix_type_name (string type_name
, Symbol container
) {
156 var attributes
= get_attributes (type_name
);
157 if (attributes
!= null) {
158 foreach (string attr
in attributes
) {
159 var nv
= attr
.split ("=", 2);
160 if (nv
[0] == "name") {
166 if (type_name
.has_prefix (container
.name
)) {
167 return type_name
.substring (container
.name
.length
);
168 } else if (container
.name
== "GLib" && type_name
.has_prefix ("G")) {
169 return type_name
.substring (1);
171 string best_match
= null;
172 if (container is Namespace
) {
173 foreach (string cprefix
in ((Namespace
) container
).get_cprefixes ()) {
174 if (type_name
.has_prefix (cprefix
)) {
175 if (best_match
== null || cprefix
.length
> best_match
.length
)
176 best_match
= cprefix
;
180 best_match
= container
.get_cprefix ();
183 if (best_match
!= null) {
184 return type_name
.substring (best_match
.length
);;
191 private string fix_const_name (string const_name
, Symbol container
) {
192 var pref
= container
.get_lower_case_cprefix ().up ();
193 if (const_name
.has_prefix (pref
)) {
194 return const_name
.substring (pref
.length
);
199 private string[] get_attributes_for_node (IdlNode node
) {
202 if (node
.type
== IdlNodeTypeId
.FUNCTION
) {
203 name
= ((IdlNodeFunction
) node
).symbol
;
204 } else if (node
.type
== IdlNodeTypeId
.SIGNAL
) {
205 name
= "%s::%s".printf (current_data_type
.get_cname (), node
.name
);
206 } else if (node
.type
== IdlNodeTypeId
.PROPERTY
) {
207 name
= "%s:%s".printf (current_data_type
.get_cname (), node
.name
);
208 } else if (node
.type
== IdlNodeTypeId
.FIELD
) {
209 name
= "%s.%s".printf (current_data_type
.get_cname (), node
.name
);
214 return get_attributes (name
);
217 private void add_symbol_to_container (Symbol container
, Symbol sym
) {
218 if (container is Class
) {
219 unowned Class cl
= (Class
) container
;
222 cl
.add_class ((Class
) sym
);
223 } else if (sym is Constant
) {
224 cl
.add_constant ((Constant
) sym
);
225 } else if (sym is Enum
) {
226 cl
.add_enum ((Enum
) sym
);
227 } else if (sym is Field
) {
228 cl
.add_field ((Field
) sym
);
229 } else if (sym is Method
) {
230 cl
.add_method ((Method
) sym
);
231 } else if (sym is Property
) {
232 cl
.add_property ((Property
) sym
);
233 } else if (sym is Signal
) {
234 cl
.add_signal ((Signal
) sym
);
235 } else if (sym is Struct
) {
236 cl
.add_struct ((Struct
) sym
);
238 } else if (container is Enum
) {
239 unowned Enum en
= (Enum
) container
;
241 if (sym is EnumValue
) {
242 en
.add_value ((EnumValue
) sym
);
243 } else if (sym is Constant
) {
244 en
.add_constant ((Constant
) sym
);
245 } else if (sym is Method
) {
246 en
.add_method ((Method
) sym
);
248 } else if (container is Interface
) {
249 unowned Interface iface
= (Interface
) container
;
252 iface
.add_class ((Class
) sym
);
253 } else if (sym is Constant
) {
254 iface
.add_constant ((Constant
) sym
);
255 } else if (sym is Enum
) {
256 iface
.add_enum ((Enum
) sym
);
257 } else if (sym is Field
) {
258 iface
.add_field ((Field
) sym
);
259 } else if (sym is Method
) {
260 iface
.add_method ((Method
) sym
);
261 } else if (sym is Property
) {
262 iface
.add_property ((Property
) sym
);
263 } else if (sym is Signal
) {
264 iface
.add_signal ((Signal
) sym
);
265 } else if (sym is Struct
) {
266 iface
.add_struct ((Struct
) sym
);
268 } else if (container is Namespace
) {
269 unowned Namespace ns
= (Namespace
) container
;
271 if (sym is Namespace
) {
272 ns
.add_namespace ((Namespace
) sym
);
273 } else if (sym is Class
) {
274 ns
.add_class ((Class
) sym
);
275 } else if (sym is Constant
) {
276 ns
.add_constant ((Constant
) sym
);
277 } else if (sym is Delegate
) {
278 ns
.add_delegate ((Delegate
) sym
);
279 } else if (sym is Enum
) {
280 ns
.add_enum ((Enum
) sym
);
281 } else if (sym is ErrorDomain
) {
282 ns
.add_error_domain ((ErrorDomain
) sym
);
283 } else if (sym is Field
) {
284 ns
.add_field ((Field
) sym
);
285 } else if (sym is Interface
) {
286 ns
.add_interface ((Interface
) sym
);
287 } else if (sym is Method
) {
288 ns
.add_method ((Method
) sym
);
289 } else if (sym is Namespace
) {
290 ns
.add_namespace ((Namespace
) sym
);
291 } else if (sym is Struct
) {
292 ns
.add_struct ((Struct
) sym
);
294 } else if (container is Struct
) {
295 unowned Struct st
= (Struct
) container
;
297 if (sym is Constant
) {
298 st
.add_constant ((Constant
) sym
);
299 } else if (sym is Field
) {
300 st
.add_field ((Field
) sym
);
301 } else if (sym is Method
) {
302 st
.add_method ((Method
) sym
);
303 } else if (sym is Property
) {
304 st
.add_property ((Property
) sym
);
309 private void parse_node (IdlNode node
, IdlModule module
, Symbol container
) {
310 if (node
.type
== IdlNodeTypeId
.CALLBACK
) {
311 var cb
= parse_delegate ((IdlNodeFunction
) node
);
315 cb
.name
= fix_type_name (cb
.name
, container
);
316 add_symbol_to_container (container
, cb
);
317 current_source_file
.add_node (cb
);
318 } else if (node
.type
== IdlNodeTypeId
.STRUCT
) {
319 parse_struct ((IdlNodeStruct
) node
, container
, module
);
320 } else if (node
.type
== IdlNodeTypeId
.UNION
) {
321 parse_union ((IdlNodeUnion
) node
, container
, module
);
322 } else if (node
.type
== IdlNodeTypeId
.BOXED
) {
323 parse_boxed ((IdlNodeBoxed
) node
, container
, module
);
324 } else if (node
.type
== IdlNodeTypeId
.ENUM
) {
325 parse_enum ((IdlNodeEnum
) node
, container
, module
, false);
326 } else if (node
.type
== IdlNodeTypeId
.FLAGS
) {
327 parse_enum ((IdlNodeEnum
) node
, container
, module
, true);
328 } else if (node
.type
== IdlNodeTypeId
.OBJECT
) {
329 parse_object ((IdlNodeInterface
) node
, container
, module
);
330 } else if (node
.type
== IdlNodeTypeId
.INTERFACE
) {
331 parse_interface ((IdlNodeInterface
) node
, container
, module
);
332 } else if (node
.type
== IdlNodeTypeId
.CONSTANT
) {
333 var c
= parse_constant ((IdlNodeConstant
) node
);
335 c
.name
= fix_const_name (c
.name
, container
);
336 add_symbol_to_container (container
, c
);
337 current_source_file
.add_node (c
);
339 } else if (node
.type
== IdlNodeTypeId
.FUNCTION
) {
340 var m
= parse_function ((IdlNodeFunction
) node
);
342 m
.binding
= MemberBinding
.STATIC
;
343 add_symbol_to_container (container
, m
);
344 current_source_file
.add_node (m
);
349 private Symbol?
get_container_from_name (string name
) {
350 var path
= name
.split (".");
351 Symbol? cp
= current_namespace
;
354 foreach ( unowned
string tok
in path
) {
355 cc
= cp
.scope
.lookup (tok
) as Symbol
;
357 cc
= new
Namespace (tok
, current_source_reference
);
358 ((Namespace
) cc
).add_cprefix (cp
.get_cprefix () + tok
);
359 add_symbol_to_container (cp
, cc
);
367 private Namespace?
parse_module (IdlModule module
) {
368 Symbol sym
= context
.root
.scope
.lookup (module
.name
);
370 if (sym is Namespace
) {
371 ns
= (Namespace
) sym
;
372 if (ns
.external_package
) {
373 ns
.attributes
= null;
374 ns
.source_reference
= current_source_reference
;
377 ns
= new
Namespace (module
.name
, current_source_reference
);
380 current_namespace
= ns
;
382 var attributes
= get_attributes (ns
.name
);
383 if (attributes
!= null) {
384 foreach (string attr
in attributes
) {
385 var nv
= attr
.split ("=", 2);
386 if (nv
[0] == "cheader_filename") {
387 ns
.set_cheader_filename (eval (nv
[1]));
388 } else if (nv
[0] == "cprefix") {
389 var cprefixes
= eval (nv
[1]).split (",");
390 foreach(string name
in cprefixes
) {
391 ns
.add_cprefix (name
);
393 } else if (nv
[0] == "lower_case_cprefix") {
394 ns
.set_lower_case_cprefix (eval (nv
[1]));
395 } else if (nv
[0] == "gir_namespace") {
396 ns
.source_reference
.file
.gir_namespace
= eval (nv
[1]);
397 } else if (nv
[0] == "gir_version") {
398 ns
.source_reference
.file
.gir_version
= eval (nv
[1]);
403 var deferred
= new ArrayList
<unowned IdlNode
> ();
405 foreach (weak IdlNode node
in module
.entries
) {
406 bool is_deferred
= false;
407 var child_attributes
= get_attributes_for_node (node
);
408 if (child_attributes
!= null) {
409 foreach (unowned
string attr
in child_attributes
) {
410 var nv
= attr
.split ("=", 2);
411 if (nv
[0] == "parent") {
419 parse_node (node
, module
, ns
);
423 foreach (unowned IdlNode node
in deferred
) {
424 Symbol container
= ns
;
425 var child_attributes
= get_attributes_for_node (node
);
426 if (child_attributes
!= null) {
427 foreach (unowned
string attr
in child_attributes
) {
428 var nv
= attr
.split ("=", 2);
429 if (nv
[0] == "parent") {
430 container
= get_container_from_name (eval (nv
[1]));
435 parse_node (node
, module
, container
);
438 current_namespace
= null;
440 if (sym is Namespace
) {
446 private Delegate?
parse_delegate (IdlNodeFunction f_node
) {
447 weak IdlNode node
= (IdlNode
) f_node
;
449 var return_type
= parse_param (f_node
.result
);
451 var cb
= new
Delegate (node
.name
, return_type
, current_source_reference
);
452 cb
.access
= SymbolAccessibility
.PUBLIC
;
454 bool check_has_target
= true;
456 var attributes
= get_attributes (node
.name
);
457 if (attributes
!= null) {
458 foreach (string attr
in attributes
) {
459 var nv
= attr
.split ("=", 2);
460 if (nv
[0] == "hidden") {
461 if (eval (nv
[1]) == "1") {
464 } else if (nv
[0] == "cheader_filename") {
465 cb
.add_cheader_filename (eval (nv
[1]));
466 } else if (nv
[0] == "has_target") {
467 if (eval (nv
[1]) == "0") {
468 check_has_target
= false;
469 } else if (eval (nv
[1]) == "1") {
470 cb
.has_target
= true;
472 } else if (nv
[0] == "transfer_ownership") {
473 if (eval (nv
[1]) == "1") {
474 return_type
.value_owned
= true;
476 } else if (nv
[0] == "deprecated") {
477 if (eval (nv
[1]) == "1") {
478 cb
.deprecated
= true;
480 } else if (nv
[0] == "replacement") {
481 cb
.replacement
= eval (nv
[1]);
482 } else if (nv
[0] == "deprecated_since") {
483 cb
.deprecated_since
= eval (nv
[1]);
484 } else if (nv
[0] == "type_arguments") {
485 parse_type_arguments_from_string (return_type
, eval (nv
[1]));
486 } else if (nv
[0] == "instance_pos") {
487 cb
.cinstance_parameter_position
= double.parse (eval (nv
[1]));
488 } else if (nv
[0] == "type_parameters") {
489 foreach (string type_param_name
in eval (nv
[1]).split (",")) {
490 cb
.add_type_parameter (new
TypeParameter (type_param_name
, current_source_reference
));
492 } else if (nv
[0] == "experimental") {
493 if (eval (nv
[1]) == "1") {
494 cb
.experimental
= true;
500 uint remaining_params
= f_node
.parameters
.length ();
501 foreach (weak IdlNodeParam param
in f_node
.parameters
) {
502 weak IdlNode param_node
= (IdlNode
) param
;
504 if (check_has_target
&& remaining_params
== 1 && (param_node
.name
== "user_data" || param_node
.name
== "data")) {
505 // hide user_data parameter for instance delegates
506 cb
.has_target
= true;
508 string param_name
= param_node
.name
;
509 if (param_name
== "string") {
510 // avoid conflict with string type
512 } else if (param_name
== "self") {
513 // avoid conflict with delegate target
514 param_name
= "_self";
517 ParameterDirection direction
;
518 var param_type
= parse_param (param
, out direction
);
519 var p
= new
Parameter (param_name
, param_type
);
520 p
.direction
= direction
;
522 bool hide_param
= false;
523 bool show_param
= false;
524 bool array_requested
= false;
525 bool out_requested
= false;
526 attributes
= get_attributes ("%s.%s".printf (node
.name
, param_node
.name
));
527 if (attributes
!= null) {
528 foreach (string attr
in attributes
) {
529 var nv
= attr
.split ("=", 2);
530 if (nv
[0] == "hidden") {
531 if (eval (nv
[1]) == "1") {
533 } else if (eval (nv
[1]) == "0") {
536 } else if (nv
[0] == "is_array") {
537 if (eval (nv
[1]) == "1") {
538 param_type
= new
ArrayType (param_type
, 1, param_type
.source_reference
);
539 p
.variable_type
= param_type
;
540 if (!out_requested
) {
541 p
.direction
= ParameterDirection
.IN
;
543 array_requested
= true;
545 } else if (nv
[0] == "is_out") {
546 if (eval (nv
[1]) == "1") {
547 p
.direction
= ParameterDirection
.OUT
;
548 out_requested
= true;
549 if (!array_requested
&& param_type is ArrayType
) {
550 var array_type
= (ArrayType
) param_type
;
551 param_type
= array_type
.element_type
;
552 p
.variable_type
= param_type
;
555 } else if (nv
[0] == "is_ref") {
556 if (eval (nv
[1]) == "1") {
557 p
.direction
= ParameterDirection
.REF
;
558 if (!array_requested
&& param_type is ArrayType
) {
559 var array_type
= (ArrayType
) param_type
;
560 param_type
= array_type
.element_type
;
561 p
.variable_type
= param_type
;
564 } else if (nv
[0] == "takes_ownership") {
565 if (eval (nv
[1]) == "1") {
566 param_type
.value_owned
= true;
568 } else if (nv
[0] == "nullable") {
569 if (eval (nv
[1]) == "1") {
570 param_type
.nullable
= true;
572 } else if (nv
[0] == "type_arguments") {
573 parse_type_arguments_from_string (param_type
, eval (nv
[1]));
574 } else if (nv
[0] == "no_array_length") {
575 if (eval (nv
[1]) == "1") {
576 p
.no_array_length
= true;
578 } else if (nv
[0] == "array_length_type") {
579 p
.array_length_type
= eval (nv
[1]);
580 } else if (nv
[0] == "array_null_terminated") {
581 if (eval (nv
[1]) == "1") {
582 p
.no_array_length
= true;
583 p
.array_null_terminated
= true;
585 } else if (nv
[0] == "type_name") {
586 p
.variable_type
= param_type
= parse_type_from_string (eval (nv
[1]), false);
591 if (show_param
|| !hide_param
) {
592 cb
.add_parameter (p
);
602 private bool is_reference_type (string cname
) {
603 var st_attributes
= get_attributes (cname
);
604 if (st_attributes
!= null) {
605 foreach (string attr
in st_attributes
) {
606 var nv
= attr
.split ("=", 2);
607 if (nv
[0] == "is_value_type" && eval (nv
[1]) == "1") {
615 private void parse_struct (IdlNodeStruct st_node
, Symbol container
, IdlModule module
) {
616 weak IdlNode node
= (IdlNode
) st_node
;
618 if (st_node
.deprecated
) {
622 string name
= fix_type_name (node
.name
, container
);
624 if (!is_reference_type (node
.name
)) {
625 var st
= container
.scope
.lookup (name
) as Struct
;
627 st
= new
Struct (name
, current_source_reference
);
628 st
.access
= SymbolAccessibility
.PUBLIC
;
630 var st_attributes
= get_attributes (node
.name
);
631 if (st_attributes
!= null) {
632 foreach (string attr
in st_attributes
) {
633 var nv
= attr
.split ("=", 2);
634 if (nv
[0] == "cheader_filename") {
635 st
.add_cheader_filename (eval (nv
[1]));
636 } else if (nv
[0] == "hidden") {
637 if (eval (nv
[1]) == "1") {
640 } else if (nv
[0] == "base_type") {
641 st
.base_type
= parse_type_string (eval (nv
[1]));
642 } else if (nv
[0] == "rank") {
643 st
.set_rank (int.parse (eval (nv
[1])));
644 } else if (nv
[0] == "simple_type") {
645 if (eval (nv
[1]) == "1") {
646 st
.set_simple_type (true);
648 } else if (nv
[0] == "immutable") {
649 if (eval (nv
[1]) == "1") {
650 st
.is_immutable
= true;
652 } else if (nv
[0] == "has_type_id") {
653 if (eval (nv
[1]) == "0") {
654 st
.has_type_id
= false;
656 } else if (nv
[0] == "type_id") {
657 st
.set_type_id (eval (nv
[1]));
658 } else if (nv
[0] == "has_copy_function") {
659 if (eval (nv
[1]) == "0") {
660 st
.has_copy_function
= false;
662 } else if (nv
[0] == "deprecated") {
663 if (eval (nv
[1]) == "1") {
664 st
.deprecated
= true;
666 } else if (nv
[0] == "replacement") {
667 st
.replacement
= eval (nv
[1]);
668 } else if (nv
[0] == "deprecated_since") {
669 st
.deprecated_since
= eval (nv
[1]);
670 } else if (nv
[0] == "has_destroy_function") {
671 if (eval (nv
[1]) == "0") {
672 st
.has_destroy_function
= false;
674 } else if (nv
[0] == "experimental") {
675 if (eval (nv
[1]) == "1") {
676 st
.experimental
= true;
682 add_symbol_to_container (container
, st
);
683 current_source_file
.add_node (st
);
686 current_data_type
= st
;
688 foreach (weak IdlNode member
in st_node
.members
) {
689 if (member
.type
== IdlNodeTypeId
.FUNCTION
) {
690 var m
= parse_function ((IdlNodeFunction
) member
);
694 } else if (member
.type
== IdlNodeTypeId
.FIELD
) {
695 var f
= parse_field ((IdlNodeField
) member
);
702 current_data_type
= null;
704 bool ref_function_void
= false;
705 string ref_function
= null;
706 string unref_function
= null;
707 string copy_function
= null;
708 string free_function
= null;
710 var cl
= container
.scope
.lookup (name
) as Class
;
712 string base_class
= null;
714 cl
= new
Class (name
, current_source_reference
);
715 cl
.access
= SymbolAccessibility
.PUBLIC
;
716 cl
.is_compact
= true;
718 var cl_attributes
= get_attributes (node
.name
);
719 if (cl_attributes
!= null) {
720 foreach (string attr
in cl_attributes
) {
721 var nv
= attr
.split ("=", 2);
722 if (nv
[0] == "cheader_filename") {
723 cl
.add_cheader_filename (eval (nv
[1]));
724 } else if (nv
[0] == "base_class") {
725 base_class
= eval (nv
[1]);
726 } else if (nv
[0] == "hidden") {
727 if (eval (nv
[1]) == "1") {
730 } else if (nv
[0] == "is_immutable") {
731 if (eval (nv
[1]) == "1") {
732 cl
.is_immutable
= true;
734 } else if (nv
[0] == "const_cname") {
735 cl
.const_cname
= eval (nv
[1]);
736 } else if (nv
[0] == "is_fundamental") {
737 if (eval (nv
[1]) == "1") {
738 cl
.is_compact
= false;
740 } else if (nv
[0] == "abstract" && base_class
!= null) {
741 if (eval (nv
[1]) == "1") {
742 cl
.is_abstract
= true;
744 } else if (nv
[0] == "free_function") {
745 free_function
= eval (nv
[1]);
746 } else if (nv
[0] == "ref_function") {
747 ref_function
= eval (nv
[1]);
748 } else if (nv
[0] == "unref_function") {
749 unref_function
= eval (nv
[1]);
750 } else if (nv
[0] == "copy_function") {
751 copy_function
= eval (nv
[1]);
752 } else if (nv
[0] == "ref_function_void") {
753 if (eval (nv
[1]) == "1") {
754 ref_function_void
= true;
756 } else if (nv
[0] == "deprecated") {
757 if (eval (nv
[1]) == "1") {
758 cl
.deprecated
= true;
760 } else if (nv
[0] == "replacement") {
761 cl
.replacement
= eval (nv
[1]);
762 } else if (nv
[0] == "deprecated_since") {
763 cl
.deprecated_since
= eval (nv
[1]);
764 } else if (nv
[0] == "type_parameters") {
765 foreach (string type_param_name
in eval (nv
[1]).split (",")) {
766 cl
.add_type_parameter (new
TypeParameter (type_param_name
, current_source_reference
));
768 } else if (nv
[0] == "experimental") {
769 if (eval (nv
[1]) == "1") {
770 cl
.experimental
= true;
776 add_symbol_to_container (container
, cl
);
777 current_source_file
.add_node (cl
);
779 if (base_class
!= null) {
780 var parent
= parse_type_string (base_class
);
781 cl
.add_base_type (parent
);
785 current_data_type
= cl
;
787 foreach (weak IdlNode member
in st_node
.members
) {
788 if (member
.type
== IdlNodeTypeId
.FUNCTION
) {
789 if ((ref_function
== null) && (member
.name
== "ref")) {
790 ref_function
= ((IdlNodeFunction
) member
).symbol
;
791 ref_function_void
= (parse_type (((IdlNodeFunction
) member
).result
.type
) is VoidType
);
792 } else if ((unref_function
== null) && (member
.name
== "unref")) {
793 unref_function
= ((IdlNodeFunction
) member
).symbol
;
794 } else if ((free_function
== null) && (member
.name
== "free" || member
.name
== "destroy")) {
795 free_function
= ((IdlNodeFunction
) member
).symbol
;
797 if ((copy_function
== null) && (member
.name
== "copy")) {
798 copy_function
= ((IdlNodeFunction
) member
).symbol
;
800 var m
= parse_function ((IdlNodeFunction
) member
);
805 } else if (member
.type
== IdlNodeTypeId
.FIELD
) {
806 var f
= parse_field ((IdlNodeField
) member
);
813 if (ref_function
!= null) {
814 cl
.set_ref_function (ref_function
);
815 cl
.ref_function_void
= ref_function_void
;
817 if (copy_function
!= null) {
818 cl
.set_dup_function (copy_function
);
820 if (unref_function
!= null) {
821 cl
.set_unref_function (unref_function
);
822 } else if (free_function
!= null) {
823 cl
.set_free_function (free_function
);
826 current_data_type
= null;
830 private void parse_union (IdlNodeUnion un_node
, Symbol container
, IdlModule module
) {
831 weak IdlNode node
= (IdlNode
) un_node
;
833 if (un_node
.deprecated
) {
837 string name
= fix_type_name (node
.name
, container
);
839 if (!is_reference_type (node
.name
)) {
840 var st
= container
.scope
.lookup (name
) as Struct
;
842 st
= new
Struct (name
, current_source_reference
);
843 st
.access
= SymbolAccessibility
.PUBLIC
;
845 var st_attributes
= get_attributes (node
.name
);
846 if (st_attributes
!= null) {
847 foreach (string attr
in st_attributes
) {
848 var nv
= attr
.split ("=", 2);
849 if (nv
[0] == "cheader_filename") {
850 st
.add_cheader_filename (eval (nv
[1]));
851 } else if (nv
[0] == "deprecated") {
852 if (eval (nv
[1]) == "1") {
853 st
.deprecated
= true;
855 } else if (nv
[0] == "replacement") {
856 st
.replacement
= eval (nv
[1]);
857 } else if (nv
[0] == "deprecated_since") {
858 st
.deprecated_since
= eval (nv
[1]);
859 } else if (nv
[0] == "hidden") {
860 if (eval (nv
[1]) == "1") {
863 } else if (nv
[0] == "experimental") {
864 if (eval (nv
[1]) == "1") {
865 st
.experimental
= true;
871 add_symbol_to_container (container
, st
);
872 current_source_file
.add_node (st
);
875 current_data_type
= st
;
877 foreach (weak IdlNode member
in un_node
.members
) {
878 if (member
.type
== IdlNodeTypeId
.FUNCTION
) {
879 var m
= parse_function ((IdlNodeFunction
) member
);
883 } else if (member
.type
== IdlNodeTypeId
.FIELD
) {
884 var f
= parse_field ((IdlNodeField
) member
);
891 current_data_type
= null;
893 var cl
= container
.scope
.lookup (name
) as Class
;
895 cl
= new
Class (name
, current_source_reference
);
896 cl
.access
= SymbolAccessibility
.PUBLIC
;
897 cl
.is_compact
= true;
899 var cl_attributes
= get_attributes (node
.name
);
900 if (cl_attributes
!= null) {
901 foreach (string attr
in cl_attributes
) {
902 var nv
= attr
.split ("=", 2);
903 if (nv
[0] == "cheader_filename") {
904 cl
.add_cheader_filename (eval (nv
[1]));
905 } else if (nv
[0] == "hidden") {
906 if (eval (nv
[1]) == "1") {
913 add_symbol_to_container (container
, cl
);
914 current_source_file
.add_node (cl
);
917 current_data_type
= cl
;
919 bool ref_function_void
= false;
920 string ref_function
= null;
921 string unref_function
= null;
922 string copy_function
= null;
923 string free_function
= null;
925 foreach (weak IdlNode member
in un_node
.members
) {
926 if (member
.type
== IdlNodeTypeId
.FUNCTION
) {
927 if (member
.name
== "ref") {
928 ref_function
= ((IdlNodeFunction
) member
).symbol
;
929 ref_function_void
= (parse_type (((IdlNodeFunction
) member
).result
.type
) is VoidType
);
930 } else if (member
.name
== "unref") {
931 unref_function
= ((IdlNodeFunction
) member
).symbol
;
932 } else if (member
.name
== "free" || member
.name
== "destroy") {
933 free_function
= ((IdlNodeFunction
) member
).symbol
;
935 if (member
.name
== "copy") {
936 copy_function
= ((IdlNodeFunction
) member
).symbol
;
938 var m
= parse_function ((IdlNodeFunction
) member
);
943 } else if (member
.type
== IdlNodeTypeId
.FIELD
) {
944 var f
= parse_field ((IdlNodeField
) member
);
951 if (ref_function
!= null) {
952 cl
.set_ref_function (ref_function
);
953 cl
.ref_function_void
= ref_function_void
;
955 if (copy_function
!= null) {
956 cl
.set_dup_function (copy_function
);
958 if (unref_function
!= null) {
959 cl
.set_unref_function (unref_function
);
960 } else if (free_function
!= null) {
961 cl
.set_free_function (free_function
);
964 current_data_type
= null;
968 private void parse_boxed (IdlNodeBoxed boxed_node
, Symbol container
, IdlModule module
) {
969 weak IdlNode node
= (IdlNode
) boxed_node
;
971 string name
= fix_type_name (node
.name
, container
);
973 var node_attributes
= get_attributes (node
.name
);
974 if (node_attributes
!= null) {
975 foreach (string attr
in node_attributes
) {
976 var nv
= attr
.split ("=", 2);
977 if (nv
[0] == "hidden") {
983 if (!is_reference_type (node
.name
)) {
984 var st
= container
.scope
.lookup (name
) as Struct
;
986 st
= new
Struct (name
, current_source_reference
);
987 st
.access
= SymbolAccessibility
.PUBLIC
;
989 var st_attributes
= get_attributes (node
.name
);
990 if (st_attributes
!= null) {
991 foreach (string attr
in st_attributes
) {
992 var nv
= attr
.split ("=", 2);
993 if (nv
[0] == "cheader_filename") {
994 st
.add_cheader_filename (eval (nv
[1]));
995 } else if (nv
[0] == "deprecated") {
996 if (eval (nv
[1]) == "1") {
997 st
.deprecated
= true;
999 } else if (nv
[0] == "replacement") {
1000 st
.replacement
= eval (nv
[1]);
1001 } else if (nv
[0] == "deprecated_since") {
1002 st
.deprecated_since
= eval (nv
[1]);
1003 } else if (nv
[0] == "immutable") {
1004 if (eval (nv
[1]) == "1") {
1005 st
.is_immutable
= true;
1007 } else if (nv
[0] == "has_copy_function") {
1008 if (eval (nv
[1]) == "0") {
1009 st
.has_copy_function
= false;
1011 } else if (nv
[0] == "has_destroy_function") {
1012 if (eval (nv
[1]) == "0") {
1013 st
.has_destroy_function
= false;
1015 } else if (nv
[0] == "experimental") {
1016 if (eval (nv
[1]) == "1") {
1017 st
.experimental
= true;
1023 add_symbol_to_container (container
, st
);
1024 st
.set_type_id (st
.get_upper_case_cname ("TYPE_"));
1025 current_source_file
.add_node (st
);
1028 current_data_type
= st
;
1030 foreach (weak IdlNode member
in boxed_node
.members
) {
1031 if (member
.type
== IdlNodeTypeId
.FUNCTION
) {
1032 var m
= parse_function ((IdlNodeFunction
) member
);
1036 } else if (member
.type
== IdlNodeTypeId
.FIELD
) {
1037 var f
= parse_field ((IdlNodeField
) member
);
1044 current_data_type
= null;
1046 bool ref_function_void
= false;
1047 string ref_function
= null;
1048 string unref_function
= null;
1049 string copy_function
= null;
1050 string free_function
= null;
1052 var cl
= container
.scope
.lookup (name
) as Class
;
1054 string base_class
= null;
1056 cl
= new
Class (name
, current_source_reference
);
1057 cl
.access
= SymbolAccessibility
.PUBLIC
;
1058 cl
.is_compact
= true;
1060 var cl_attributes
= get_attributes (node
.name
);
1061 if (cl_attributes
!= null) {
1062 foreach (string attr
in cl_attributes
) {
1063 var nv
= attr
.split ("=", 2);
1064 if (nv
[0] == "cheader_filename") {
1065 cl
.add_cheader_filename (eval (nv
[1]));
1066 } else if (nv
[0] == "base_class") {
1067 base_class
= eval (nv
[1]);
1068 } else if (nv
[0] == "is_immutable") {
1069 if (eval (nv
[1]) == "1") {
1070 cl
.is_immutable
= true;
1072 } else if (nv
[0] == "deprecated") {
1073 if (eval (nv
[1]) == "1") {
1074 cl
.deprecated
= true;
1076 } else if (nv
[0] == "replacement") {
1077 cl
.replacement
= eval (nv
[1]);
1078 } else if (nv
[0] == "deprecated_since") {
1079 cl
.deprecated_since
= eval (nv
[1]);
1080 } else if (nv
[0] == "const_cname") {
1081 cl
.const_cname
= eval (nv
[1]);
1082 } else if (nv
[0] == "free_function") {
1083 free_function
= eval (nv
[1]);
1084 } else if (nv
[0] == "ref_function") {
1085 ref_function
= eval (nv
[1]);
1086 } else if (nv
[0] == "unref_function") {
1087 unref_function
= eval (nv
[1]);
1088 } else if (nv
[0] == "copy_function") {
1089 copy_function
= eval (nv
[1]);
1090 } else if (nv
[0] == "ref_function_void") {
1091 if (eval (nv
[1]) == "1") {
1092 ref_function_void
= true;
1094 } else if (nv
[0] == "experimental") {
1095 if (eval (nv
[1]) == "1") {
1096 cl
.experimental
= true;
1102 add_symbol_to_container (container
, cl
);
1103 cl
.set_type_id (cl
.get_upper_case_cname ("TYPE_"));
1104 current_source_file
.add_node (cl
);
1106 if (base_class
!= null) {
1107 var parent
= parse_type_string (base_class
);
1108 cl
.add_base_type (parent
);
1112 current_data_type
= cl
;
1114 foreach (weak IdlNode member
in boxed_node
.members
) {
1115 if (member
.type
== IdlNodeTypeId
.FUNCTION
) {
1116 if (member
.name
== "ref") {
1117 ref_function
= ((IdlNodeFunction
) member
).symbol
;
1118 ref_function_void
= (parse_type (((IdlNodeFunction
) member
).result
.type
) is VoidType
);
1119 } else if (member
.name
== "unref") {
1120 unref_function
= ((IdlNodeFunction
) member
).symbol
;
1121 } else if (member
.name
== "free" || member
.name
== "destroy") {
1122 free_function
= ((IdlNodeFunction
) member
).symbol
;
1124 if (member
.name
== "copy") {
1125 copy_function
= ((IdlNodeFunction
) member
).symbol
;
1127 var m
= parse_function ((IdlNodeFunction
) member
);
1132 } else if (member
.type
== IdlNodeTypeId
.FIELD
) {
1133 var f
= parse_field ((IdlNodeField
) member
);
1140 if (ref_function
!= null) {
1141 cl
.set_ref_function (ref_function
);
1142 cl
.ref_function_void
= ref_function_void
;
1144 if (copy_function
!= null) {
1145 cl
.set_dup_function (copy_function
);
1147 if (unref_function
!= null) {
1148 cl
.set_unref_function (unref_function
);
1149 } else if (free_function
!= null) {
1150 cl
.set_free_function (free_function
);
1153 current_data_type
= null;
1157 private void parse_enum (IdlNodeEnum en_node
, Symbol container
, IdlModule module
, bool is_flags
) {
1158 weak IdlNode node
= (IdlNode
) en_node
;
1159 string name
= fix_type_name (node
.name
, container
);
1160 bool existing
= true;
1162 var en
= container
.scope
.lookup (name
) as Enum
;
1164 en
= new
Enum (name
, current_source_reference
);
1165 en
.access
= SymbolAccessibility
.PUBLIC
;
1168 // ignore dummy enum values in -custom.vala files
1169 // they exist for syntactical reasons
1170 var dummy
= (EnumValue
) en
.scope
.lookup ("__DUMMY__");
1171 if (dummy
!= null) {
1172 en
.get_values ().remove (dummy
);
1173 en
.scope
.remove ("__DUMMY__");
1177 en
.has_type_id
= (en_node
.gtype_name
!= null && en_node
.gtype_name
!= "");
1179 string common_prefix
= null;
1181 foreach (weak IdlNode value
in en_node
.values
) {
1182 var val_attributes
= get_attributes (value
.name
);
1183 bool is_hidden
= false;
1184 if (val_attributes
!= null) {
1185 foreach (string attr
in val_attributes
) {
1186 var nv
= attr
.split ("=", 2);
1187 if (nv
[0] == "hidden" && eval(nv
[1]) == "1") {
1197 if (common_prefix
== null) {
1198 common_prefix
= value
.name
;
1199 while (common_prefix
.length
> 0 && !common_prefix
.has_suffix ("_")) {
1200 // FIXME: could easily be made faster
1201 common_prefix
= common_prefix
.substring (0, common_prefix
.length
- 1);
1204 while (!value
.name
.has_prefix (common_prefix
)) {
1205 common_prefix
= common_prefix
.substring (0, common_prefix
.length
- 1);
1208 while (common_prefix
.length
> 0 && (!common_prefix
.has_suffix ("_") ||
1209 (value
.name
.get_char (common_prefix
.length
).isdigit ()) && (value
.name
.length
- common_prefix
.length
) <= 1)) {
1210 // enum values may not consist solely of digits
1211 common_prefix
= common_prefix
.substring (0, common_prefix
.length
- 1);
1215 bool is_errordomain
= false;
1217 var cheader_filenames
= new ArrayList
<string> ();
1219 var en_attributes
= get_attributes (node
.name
);
1220 if (en_attributes
!= null) {
1221 foreach (string attr
in en_attributes
) {
1222 var nv
= attr
.split ("=", 2);
1223 if (nv
[0] == "common_prefix") {
1224 common_prefix
= eval (nv
[1]);
1225 } else if (nv
[0] == "cheader_filename") {
1226 cheader_filenames
.add (eval (nv
[1]));
1227 en
.add_cheader_filename (eval (nv
[1]));
1228 } else if (nv
[0] == "hidden") {
1229 if (eval (nv
[1]) == "1") {
1232 } else if (nv
[0] == "deprecated") {
1233 if (eval (nv
[1]) == "1") {
1234 en
.deprecated
= true;
1236 } else if (nv
[0] == "replacement") {
1237 en
.replacement
= eval (nv
[1]);
1238 } else if (nv
[0] == "deprecated_since") {
1239 en
.deprecated_since
= eval (nv
[1]);
1240 } else if (nv
[0] == "rename_to") {
1241 en
.name
= eval (nv
[1]);
1242 } else if (nv
[0] == "errordomain") {
1243 if (eval (nv
[1]) == "1") {
1244 is_errordomain
= true;
1246 } else if (nv
[0] == "to_string") {
1247 var return_type
= new
UnresolvedType ();
1248 return_type
.unresolved_symbol
= new
UnresolvedSymbol (null, "string");
1249 return_type
.value_owned
= false;
1250 var m
= new
Method ("to_string", return_type
, current_source_reference
);
1251 m
.access
= SymbolAccessibility
.PUBLIC
;
1252 m
.set_cname (eval(nv
[1]));
1254 } else if (nv
[0] == "experimental") {
1255 if (eval (nv
[1]) == "1") {
1256 en
.experimental
= true;
1262 en
.set_cprefix (common_prefix
);
1264 foreach (weak IdlNode value2
in en_node
.values
) {
1265 var val_attributes
= get_attributes (value2
.name
);
1266 bool is_hidden
= false;
1267 if (val_attributes
!= null) {
1268 foreach (string attr
in val_attributes
) {
1269 var nv
= attr
.split ("=", 2);
1270 if (nv
[0] == "hidden" && eval(nv
[1]) == "1") {
1277 var ev
= new
EnumValue (value2
.name
.substring (common_prefix
.length
), null);
1282 if (is_errordomain
) {
1283 var ed
= new
ErrorDomain (en
.name
, current_source_reference
);
1284 ed
.access
= SymbolAccessibility
.PUBLIC
;
1285 ed
.set_cprefix (common_prefix
);
1287 foreach (string filename
in cheader_filenames
) {
1288 ed
.add_cheader_filename (filename
);
1291 foreach (EnumValue ev
in en
.get_values ()) {
1292 ed
.add_code (new
ErrorCode (ev
.name
));
1295 current_source_file
.add_node (ed
);
1297 add_symbol_to_container (container
, ed
);
1300 en
.is_flags
= is_flags
;
1301 current_source_file
.add_node (en
);
1303 add_symbol_to_container (container
, en
);
1308 private void parse_object (IdlNodeInterface node
, Symbol container
, IdlModule module
) {
1309 string name
= fix_type_name (((IdlNode
) node
).name
, container
);
1311 string base_class
= null;
1313 var cl
= container
.scope
.lookup (name
) as Class
;
1315 cl
= new
Class (name
, current_source_reference
);
1316 cl
.access
= SymbolAccessibility
.PUBLIC
;
1318 var attributes
= get_attributes (node
.gtype_name
);
1319 if (attributes
!= null) {
1320 foreach (string attr
in attributes
) {
1321 var nv
= attr
.split ("=", 2);
1322 if (nv
[0] == "cheader_filename") {
1323 cl
.add_cheader_filename (eval (nv
[1]));
1324 } else if (nv
[0] == "base_class") {
1325 base_class
= eval (nv
[1]);
1326 } else if (nv
[0] == "hidden") {
1327 if (eval (nv
[1]) == "1") {
1330 } else if (nv
[0] == "type_check_function") {
1331 cl
.type_check_function
= eval (nv
[1]);
1332 } else if (nv
[0] == "deprecated") {
1333 if (eval (nv
[1]) == "1") {
1334 cl
.deprecated
= true;
1336 } else if (nv
[0] == "replacement") {
1337 cl
.replacement
= eval (nv
[1]);
1338 } else if (nv
[0] == "deprecated_since") {
1339 cl
.deprecated_since
= eval (nv
[1]);
1340 } else if (nv
[0] == "type_id") {
1341 cl
.set_type_id (eval (nv
[1]));
1342 } else if (nv
[0] == "abstract") {
1343 if (eval (nv
[1]) == "1") {
1344 cl
.is_abstract
= true;
1346 } else if (nv
[0] == "experimental") {
1347 if (eval (nv
[1]) == "1") {
1348 cl
.experimental
= true;
1354 add_symbol_to_container (container
, cl
);
1355 current_source_file
.add_node (cl
);
1358 if (base_class
!= null) {
1359 var parent
= parse_type_string (base_class
);
1360 cl
.add_base_type (parent
);
1361 } else if (node
.parent
!= null) {
1362 var parent
= parse_type_string (node
.parent
);
1363 cl
.add_base_type (parent
);
1365 var gobject_symbol
= new
UnresolvedSymbol (new
UnresolvedSymbol (null, "GLib"), "Object");
1366 cl
.add_base_type (new UnresolvedType
.from_symbol (gobject_symbol
));
1369 foreach (string iface_name
in node
.interfaces
) {
1370 bool skip_iface
= false;
1372 var attributes
= get_attributes (iface_name
);
1373 if (attributes
!= null) {
1374 foreach (string attr
in attributes
) {
1375 var nv
= attr
.split ("=", 2);
1376 if (nv
[0] == "hidden") {
1377 if (eval (nv
[1]) == "1") {
1388 var iface
= parse_type_string (iface_name
);
1389 cl
.add_base_type (iface
);
1392 current_data_type
= cl
;
1394 current_type_symbol_set
= new HashSet
<string> (str_hash
, str_equal
);
1395 var current_type_func_map
= new HashMap
<string,weak IdlNodeFunction
> (str_hash
, str_equal
);
1396 var current_type_vfunc_map
= new HashMap
<string,string> (str_hash
, str_equal
);
1398 foreach (weak IdlNode member
in node
.members
) {
1399 if (member
.type
== IdlNodeTypeId
.FUNCTION
) {
1400 current_type_func_map
.set (member
.name
, (IdlNodeFunction
) member
);
1402 if (member
.type
== IdlNodeTypeId
.VFUNC
) {
1403 current_type_vfunc_map
.set (member
.name
, "1");
1407 foreach (weak IdlNode member
in node
.members
) {
1408 if (member
.type
== IdlNodeTypeId
.FUNCTION
) {
1409 // Ignore if vfunc (handled below)
1410 if (!current_type_vfunc_map
.contains (member
.name
)) {
1411 var m
= parse_function ((IdlNodeFunction
) member
);
1416 } else if (member
.type
== IdlNodeTypeId
.VFUNC
) {
1417 var m
= parse_virtual ((IdlNodeVFunc
) member
, current_type_func_map
.get (member
.name
));
1421 } else if (member
.type
== IdlNodeTypeId
.PROPERTY
) {
1422 var prop
= parse_property ((IdlNodeProperty
) member
);
1424 cl
.add_property (prop
);
1426 } else if (member
.type
== IdlNodeTypeId
.SIGNAL
) {
1427 var sig
= parse_signal ((IdlNodeSignal
) member
);
1429 cl
.add_signal (sig
);
1434 foreach (weak IdlNode member
in node
.members
) {
1435 if (member
.type
== IdlNodeTypeId
.FIELD
) {
1436 if (!current_type_symbol_set
.contains (member
.name
)) {
1437 var f
= parse_field ((IdlNodeField
) member
);
1445 foreach (Property prop
in cl
.get_properties ()) {
1446 var getter
= "get_%s".printf (prop
.name
);
1448 if (prop
.get_accessor
!= null && !current_type_symbol_set
.contains (getter
)) {
1449 prop
.no_accessor_method
= true;
1452 var setter
= "set_%s".printf (prop
.name
);
1454 if (prop
.set_accessor
!= null && prop
.set_accessor
.writable
1455 && !current_type_symbol_set
.contains (setter
)) {
1456 prop
.no_accessor_method
= true;
1459 if (prop
.no_accessor_method
&& prop
.get_accessor
!= null) {
1460 prop
.get_accessor
.value_type
.value_owned
= true;
1464 handle_async_methods (cl
);
1466 if (cl
.default_construction_method
== null) {
1467 // always provide constructor in generated bindings
1468 // to indicate that implicit Object () chainup is allowed
1469 var cm
= new
CreationMethod (null, null, cl
.source_reference
);
1470 cm
.has_construct_function
= false;
1471 cm
.access
= SymbolAccessibility
.PROTECTED
;
1475 current_data_type
= null;
1476 current_type_symbol_set
= null;
1479 private void parse_interface (IdlNodeInterface node
, Symbol container
, IdlModule module
) {
1480 string name
= fix_type_name (node
.gtype_name
, container
);
1482 var iface
= container
.scope
.lookup (name
) as Interface
;
1483 if (iface
== null) {
1484 iface
= new
Interface (name
, current_source_reference
);
1485 iface
.access
= SymbolAccessibility
.PUBLIC
;
1487 var attributes
= get_attributes (node
.gtype_name
);
1488 if (attributes
!= null) {
1489 foreach (string attr
in attributes
) {
1490 var nv
= attr
.split ("=", 2);
1491 if (nv
[0] == "cheader_filename") {
1492 iface
.add_cheader_filename (eval (nv
[1]));
1493 } else if (nv
[0] == "lower_case_csuffix") {
1494 iface
.set_lower_case_csuffix (eval (nv
[1]));
1499 foreach (string prereq_name
in node
.prerequisites
) {
1500 var prereq
= parse_type_string (prereq_name
);
1501 iface
.add_prerequisite (prereq
);
1504 add_symbol_to_container (container
, iface
);
1505 current_source_file
.add_node (iface
);
1508 current_data_type
= iface
;
1510 var current_type_func_map
= new HashMap
<string,weak IdlNodeFunction
> (str_hash
, str_equal
);
1511 var current_type_vfunc_map
= new HashMap
<string,string> (str_hash
, str_equal
);
1513 foreach (weak IdlNode member
in node
.members
) {
1514 if (member
.type
== IdlNodeTypeId
.FUNCTION
) {
1515 current_type_func_map
.set (member
.name
, (IdlNodeFunction
) member
);
1517 if (member
.type
== IdlNodeTypeId
.VFUNC
) {
1518 current_type_vfunc_map
.set (member
.name
, "1");
1522 foreach (weak IdlNode member
in node
.members
) {
1523 if (member
.type
== IdlNodeTypeId
.FUNCTION
) {
1524 // Ignore if vfunc (handled below)
1525 if (!current_type_vfunc_map
.contains (member
.name
)) {
1526 var m
= parse_function ((IdlNodeFunction
) member
, true);
1528 iface
.add_method (m
);
1531 } else if (member
.type
== IdlNodeTypeId
.VFUNC
) {
1532 var m
= parse_virtual ((IdlNodeVFunc
) member
, current_type_func_map
.get (member
.name
), true);
1534 iface
.add_method (m
);
1536 } else if (member
.type
== IdlNodeTypeId
.PROPERTY
) {
1537 var prop
= parse_property ((IdlNodeProperty
) member
);
1539 iface
.add_property (prop
);
1541 } else if (member
.type
== IdlNodeTypeId
.SIGNAL
) {
1542 var sig
= parse_signal ((IdlNodeSignal
) member
);
1544 iface
.add_signal (sig
);
1545 sig
.is_virtual
= false;
1550 handle_async_methods (iface
);
1552 current_data_type
= null;
1555 void handle_async_methods (ObjectTypeSymbol type_symbol
) {
1556 Set
<Method
> finish_methods
= new HashSet
<Method
> ();
1557 var methods
= type_symbol
.get_methods ();
1559 foreach (Method m
in methods
) {
1561 string finish_method_base
;
1562 if (m
.name
.has_suffix ("_async")) {
1563 finish_method_base
= m
.name
.substring (0, m
.name
.length
- "_async".length
);
1565 finish_method_base
= m
.name
;
1567 var finish_method
= type_symbol
.scope
.lookup (finish_method_base
+ "_finish") as Method
;
1569 // check if the method is using non-standard finish method name
1570 if (finish_method
== null) {
1571 var method_cname
= m
.get_finish_cname ();
1572 foreach (Method method
in type_symbol
.get_methods ()) {
1573 if (method
.get_cname () == method_cname
) {
1574 finish_method
= method
;
1580 if (finish_method
!= null) {
1581 m
.return_type
= finish_method
.return_type
.copy ();
1582 m
.no_array_length
= finish_method
.no_array_length
;
1583 m
.array_null_terminated
= finish_method
.array_null_terminated
;
1584 foreach (var param
in finish_method
.get_parameters ()) {
1585 if (param
.direction
== ParameterDirection
.OUT
) {
1586 var async_param
= param
.copy ();
1587 if (m
.scope
.lookup (param
.name
) != null) {
1588 // parameter name conflict
1589 async_param
.name
+= "_out";
1591 m
.add_parameter (async_param
);
1594 foreach (DataType error_type
in finish_method
.get_error_types ()) {
1595 m
.add_error_type (error_type
.copy ());
1597 finish_methods
.add (finish_method
);
1602 foreach (Method m
in finish_methods
)
1604 type_symbol
.scope
.remove (m
.name
);
1609 private DataType?
parse_type (IdlNodeType type_node
, out ParameterDirection direction
= null) {
1610 ParameterDirection dir
= ParameterDirection
.IN
;
1612 var type
= new
UnresolvedType ();
1613 if (type_node
.tag
== TypeTag
.VOID
) {
1614 if (type_node
.is_pointer
) {
1615 return new
PointerType (new
VoidType ());
1617 return new
VoidType ();
1619 } else if (type_node
.tag
== TypeTag
.BOOLEAN
) {
1620 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "bool");
1621 } else if (type_node
.tag
== TypeTag
.INT8
) {
1622 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "char");
1623 } else if (type_node
.tag
== TypeTag
.UINT8
) {
1624 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "uchar");
1625 } else if (type_node
.tag
== TypeTag
.INT16
) {
1626 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "int16");
1627 } else if (type_node
.tag
== TypeTag
.UINT16
) {
1628 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "uint16");
1629 } else if (type_node
.tag
== TypeTag
.INT32
) {
1630 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "int32");
1631 } else if (type_node
.tag
== TypeTag
.UINT32
) {
1632 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "uint32");
1633 } else if (type_node
.tag
== TypeTag
.INT64
) {
1634 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "int64");
1635 } else if (type_node
.tag
== TypeTag
.UINT64
) {
1636 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "uint64");
1637 } else if (type_node
.tag
== TypeTag
.INT
) {
1638 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "int");
1639 } else if (type_node
.tag
== TypeTag
.UINT
) {
1640 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "uint");
1641 } else if (type_node
.tag
== TypeTag
.LONG
) {
1642 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "long");
1643 } else if (type_node
.tag
== TypeTag
.ULONG
) {
1644 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "ulong");
1645 } else if (type_node
.tag
== TypeTag
.SSIZE
) {
1646 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "ssize_t");
1647 } else if (type_node
.tag
== TypeTag
.SIZE
) {
1648 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "size_t");
1649 } else if (type_node
.tag
== TypeTag
.FLOAT
) {
1650 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "float");
1651 } else if (type_node
.tag
== TypeTag
.DOUBLE
) {
1652 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "double");
1653 } else if (type_node
.tag
== TypeTag
.UTF8
) {
1654 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "string");
1655 } else if (type_node
.tag
== TypeTag
.FILENAME
) {
1656 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "string");
1657 } else if (type_node
.tag
== TypeTag
.ARRAY
) {
1658 var element_type
= parse_type (type_node
.parameter_type1
);
1659 type
= element_type as UnresolvedType
;
1661 return element_type
;
1663 return new
ArrayType (element_type
, 1, element_type
.source_reference
);
1664 } else if (type_node
.tag
== TypeTag
.LIST
) {
1665 type
.unresolved_symbol
= new
UnresolvedSymbol (new
UnresolvedSymbol (null, "GLib"), "List");
1666 } else if (type_node
.tag
== TypeTag
.SLIST
) {
1667 type
.unresolved_symbol
= new
UnresolvedSymbol (new
UnresolvedSymbol (null, "GLib"), "SList");
1668 } else if (type_node
.tag
== TypeTag
.HASH
) {
1669 type
.unresolved_symbol
= new
UnresolvedSymbol (new
UnresolvedSymbol (null, "GLib"), "HashTable");
1670 } else if (type_node
.tag
== TypeTag
.ERROR
) {
1671 type
.unresolved_symbol
= new
UnresolvedSymbol (new
UnresolvedSymbol (null, "GLib"), "Error");
1672 } else if (type_node
.is_interface
) {
1673 var n
= type_node
.@
interface;
1679 if (n
.has_prefix ("const-")) {
1680 n
= n
.substring ("const-".length
);
1683 if (type_node
.is_pointer
&&
1684 (n
== "gchar" || n
== "char")) {
1685 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "string");
1686 if (type_node
.unparsed
.has_suffix ("**")) {
1687 dir
= ParameterDirection
.OUT
;
1689 } else if (n
== "gunichar") {
1690 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "unichar");
1691 } else if (n
== "gchar") {
1692 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "char");
1693 } else if (n
== "guchar" || n
== "guint8") {
1694 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "uchar");
1695 if (type_node
.is_pointer
) {
1696 return new
ArrayType (type
, 1, type
.source_reference
);
1698 } else if (n
== "gushort") {
1699 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "ushort");
1700 } else if (n
== "gshort") {
1701 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "short");
1702 } else if (n
== "gconstpointer" || n
== "void") {
1703 return new
PointerType (new
VoidType ());
1704 } else if (n
== "goffset" || n
== "off_t") {
1705 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "int64");
1706 } else if (n
== "value_array") {
1707 type
.unresolved_symbol
= new
UnresolvedSymbol (new
UnresolvedSymbol (null, "GLib"), "ValueArray");
1708 } else if (n
== "time_t") {
1709 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "ulong");
1710 } else if (n
== "socklen_t") {
1711 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "uint32");
1712 } else if (n
== "mode_t") {
1713 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "uint");
1714 } else if (n
== "gint" || n
== "pid_t") {
1715 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "int");
1716 } else if (n
== "unsigned" || n
== "unsigned-int") {
1717 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "uint");
1718 } else if (n
== "FILE") {
1719 type
.unresolved_symbol
= new
UnresolvedSymbol (new
UnresolvedSymbol (null, "GLib"), "FileStream");
1720 } else if (n
== "struct") {
1721 return new
PointerType (new
VoidType ());
1722 } else if (n
== "iconv_t") {
1723 return new
PointerType (new
VoidType ());
1724 } else if (n
== "GType") {
1725 type
.unresolved_symbol
= new
UnresolvedSymbol (new
UnresolvedSymbol (null, "GLib"), "Type");
1726 if (type_node
.is_pointer
) {
1727 return new
ArrayType (type
, 1, type
.source_reference
);
1729 } else if (n
== "GStrv") {
1730 type
.unresolved_symbol
= new
UnresolvedSymbol (null, "string");
1731 return new
ArrayType (type
, 1, type
.source_reference
);
1733 var named_type
= parse_type_string (n
);
1734 type
= named_type as UnresolvedType
;
1738 if (is_simple_type (n
)) {
1739 if (type_node
.is_pointer
) {
1740 dir
= ParameterDirection
.OUT
;
1742 } else if (type_node
.unparsed
.has_suffix ("**")) {
1743 dir
= ParameterDirection
.OUT
;
1747 stdout
.printf ("%d\n", type_node
.tag
);
1749 if (&direction
!= null) {
1755 private bool is_simple_type (string type_name
) {
1756 var st
= cname_type_map
[type_name
] as Struct
;
1757 if (st
!= null && st
.is_simple_type ()) {
1764 private DataType
parse_type_string (string n
) {
1765 if (n
== "va_list") {
1767 return new
PointerType (new
VoidType ());
1770 var type
= new
UnresolvedType ();
1772 var dt
= cname_type_map
[n
];
1774 UnresolvedSymbol parent_symbol
= null;
1775 if (dt
.parent_symbol
.name
!= null) {
1776 parent_symbol
= new
UnresolvedSymbol (null, dt
.parent_symbol
.name
);
1778 type
.unresolved_symbol
= new
UnresolvedSymbol (parent_symbol
, dt
.name
);
1782 var type_attributes
= get_attributes (n
);
1784 string ns_name
= null;
1786 if (null != type_attributes
) {
1787 foreach (string attr
in type_attributes
) {
1788 var nv
= attr
.split ("=", 2);
1790 if (nv
[0] == "cprefix") {
1791 type
.unresolved_symbol
= new
UnresolvedSymbol (null, n
.substring (eval (nv
[1]).length
));
1792 } else if (nv
[0] == "name") {
1793 type
.unresolved_symbol
= new
UnresolvedSymbol (null, eval (nv
[1]));
1794 } else if (nv
[0] == "namespace") {
1795 ns_name
= eval (nv
[1]);
1796 } else if (nv
[0] == "rename_to") {
1797 type
.unresolved_symbol
= new
UnresolvedSymbol (null, eval (nv
[1]));
1802 if (type
.unresolved_symbol
!= null) {
1803 if (type
.unresolved_symbol
.name
== "pointer") {
1804 return new
PointerType (new
VoidType ());
1806 if (ns_name
!= null) {
1807 type
.unresolved_symbol
.inner
= new
UnresolvedSymbol (null, ns_name
);
1812 if (n
.has_prefix (current_namespace
.name
)) {
1813 type
.unresolved_symbol
= new
UnresolvedSymbol (new
UnresolvedSymbol (null, current_namespace
.name
), n
.substring (current_namespace
.name
.length
));
1814 } else if (n
.has_prefix ("G")) {
1815 type
.unresolved_symbol
= new
UnresolvedSymbol (new
UnresolvedSymbol (null, "GLib"), n
.substring (1));
1817 var name_parts
= n
.split (".", 2);
1818 if (name_parts
[1] == null) {
1819 type
.unresolved_symbol
= new
UnresolvedSymbol (null, name_parts
[0]);
1821 type
.unresolved_symbol
= new
UnresolvedSymbol (new
UnresolvedSymbol (null, name_parts
[0]), name_parts
[1]);
1828 private DataType?
parse_param (IdlNodeParam param
, out ParameterDirection direction
= null) {
1829 var type
= parse_type (param
.type
, out direction
);
1831 // disable for now as null_ok not yet correctly set
1832 // type.non_null = !param.null_ok;
1837 private UnresolvedSymbol?
parse_symbol_from_string (string symbol_string
, SourceReference? source_reference
= null) {
1838 UnresolvedSymbol? sym
= null;
1839 foreach (unowned
string s
in symbol_string
.split (".")) {
1840 sym
= new
UnresolvedSymbol (sym
, s
, source_reference
);
1843 Report
.error (source_reference
, "a symbol must be specified");
1848 private bool parse_type_arguments_from_string (DataType parent_type
, string type_arguments
, SourceReference? source_reference
= null) {
1849 int type_arguments_length
= (int) type_arguments
.length
;
1850 GLib
.StringBuilder current
= new GLib
.StringBuilder
.sized (type_arguments_length
);
1853 for (var c
= 0 ; c
< type_arguments_length
; c
++) {
1854 if (type_arguments
[c
] == '<' || type_arguments
[c
] == '[') {
1856 current
.append_unichar (type_arguments
[c
]);
1857 } else if (type_arguments
[c
] == '>' || type_arguments
[c
] == ']') {
1859 current
.append_unichar (type_arguments
[c
]);
1860 } else if (type_arguments
[c
] == ',') {
1862 var dt
= parse_type_from_string (current
.str
, true, source_reference
);
1866 parent_type
.add_type_argument (dt
);
1867 current
.truncate ();
1869 current
.append_unichar (type_arguments
[c
]);
1872 current
.append_unichar (type_arguments
[c
]);
1876 var dt
= parse_type_from_string (current
.str
, true, source_reference
);
1880 parent_type
.add_type_argument (dt
);
1885 private DataType?
parse_type_from_string (string type_string
, bool owned_by_default
, SourceReference? source_reference
= null) {
1886 if (type_from_string_regex
== null) {
1888 type_from_string_regex
= new GLib
.Regex ("^(?:(owned|unowned|weak) +)?([0-9a-zA-Z_\\.]+)(?:<(.+)>)?(\\*+)?(\\[(,*)?\\])?(\\?)?$", GLib
.RegexCompileFlags
.ANCHORED
| GLib
.RegexCompileFlags
.DOLLAR_ENDONLY
| GLib
.RegexCompileFlags
.OPTIMIZE
);
1889 } catch (GLib
.RegexError e
) {
1890 GLib
.error ("Unable to compile regex: %s", e
.message
);
1894 GLib
.MatchInfo match
;
1895 if (!type_from_string_regex
.match (type_string
, 0, out match
)) {
1896 Report
.error (source_reference
, "unable to parse type");
1900 DataType? type
= null;
1902 var ownership_data
= match
.fetch (1);
1903 var type_name
= match
.fetch (2);
1904 var type_arguments_data
= match
.fetch (3);
1905 var pointers_data
= match
.fetch (4);
1906 var array_data
= match
.fetch (5);
1907 var array_dimension_data
= match
.fetch (6);
1908 var nullable_data
= match
.fetch (7);
1910 var nullable
= nullable_data
!= null && nullable_data
.length
> 0;
1912 if (ownership_data
== null && type_name
== "void") {
1913 if (array_data
== null && !nullable
) {
1914 type
= new
VoidType (source_reference
);
1915 if (pointers_data
!= null) {
1916 for (int i
=0; i
< pointers_data
.length
; i
++) {
1917 type
= new
PointerType (type
);
1922 Report
.error (source_reference
, "invalid void type");
1927 bool value_owned
= owned_by_default
;
1929 if (ownership_data
== "owned") {
1931 } else if (ownership_data
== "unowned") {
1932 value_owned
= false;
1935 var sym
= parse_symbol_from_string (type_name
, source_reference
);
1939 type
= new UnresolvedType
.from_symbol (sym
, source_reference
);
1941 if (type_arguments_data
!= null && type_arguments_data
.length
> 0) {
1942 if (!parse_type_arguments_from_string (type
, type_arguments_data
, source_reference
)) {
1947 if (pointers_data
!= null) {
1948 for (int i
=0; i
< pointers_data
.length
; i
++) {
1949 type
= new
PointerType (type
);
1953 if (array_data
!= null && array_data
.length
> 0) {
1954 type
= new
ArrayType (type
, array_dimension_data
.length
+ 1, source_reference
);
1957 type
.nullable
= nullable
;
1958 type
.value_owned
= value_owned
;
1962 private Method?
create_method (string name
, string symbol
, IdlNodeParam? res
, GLib
.List
<IdlNodeParam
>? parameters
, bool is_constructor
, bool is_interface
) {
1963 DataType return_type
= null;
1965 return_type
= parse_param (res
);
1969 if (!is_interface
&& (is_constructor
|| name
.has_prefix ("new"))) {
1970 m
= new
CreationMethod (null, name
, current_source_reference
);
1971 m
.has_construct_function
= false;
1972 if (m
.name
== "new") {
1974 } else if (m
.name
.has_prefix ("new_")) {
1975 m
.name
= m
.name
.substring ("new_".length
);
1977 // For classes, check whether a creation method return type equals to the
1978 // type of the class created. If the types do not match (e.g. in most
1979 // gtk widgets) add an attribute to the creation method indicating the used
1981 if (current_data_type is Class
&& res
!= null) {
1982 if ("%s*".printf (current_data_type
.get_cname()) != res
.type
.unparsed
) {
1983 ((CreationMethod
)m
).custom_return_type_cname
= res
.type
.unparsed
;
1987 m
= new
Method (name
, return_type
, current_source_reference
);
1989 m
.access
= SymbolAccessibility
.PUBLIC
;
1991 if (current_type_symbol_set
!= null) {
1992 current_type_symbol_set
.add (name
);
1995 if (current_data_type
!= null) {
1996 var sig_attributes
= get_attributes ("%s::%s".printf (current_data_type
.get_cname (), name
));
1997 if (sig_attributes
!= null) {
1998 foreach (string attr
in sig_attributes
) {
1999 var nv
= attr
.split ("=", 2);
2000 if (nv
[0] == "has_emitter" && eval (nv
[1]) == "1") {
2007 bool add_ellipsis
= false;
2008 bool suppress_throws
= false;
2009 string? error_types
= null;
2011 var attributes
= get_attributes (symbol
);
2012 if (attributes
!= null) {
2013 foreach (string attr
in attributes
) {
2014 var nv
= attr
.split ("=", 2);
2015 if (nv
[0] == "name") {
2016 m
.set_cname (m
.name
);
2017 m
.name
= eval (nv
[1]);
2018 } else if (nv
[0] == "hidden") {
2019 if (eval (nv
[1]) == "1") {
2022 } else if (nv
[0] == "ellipsis") {
2023 if (eval (nv
[1]) == "1") {
2024 add_ellipsis
= true;
2026 } else if (nv
[0] == "printf_format") {
2027 if (eval (nv
[1]) == "1") {
2028 m
.printf_format
= true;
2030 } else if (nv
[0] == "transfer_ownership") {
2031 if (eval (nv
[1]) == "1") {
2032 return_type
.value_owned
= true;
2034 } else if (nv
[0] == "nullable") {
2035 if (eval (nv
[1]) == "1") {
2036 return_type
.nullable
= true;
2038 } else if (nv
[0] == "sentinel") {
2039 m
.sentinel
= eval (nv
[1]);
2040 } else if (nv
[0] == "is_array") {
2041 if (eval (nv
[1]) == "1") {
2042 return_type
= new
ArrayType (return_type
, 1, return_type
.source_reference
);
2043 m
.return_type
= return_type
;
2045 } else if (nv
[0] == "throws") {
2046 if (eval (nv
[1]) == "0") {
2047 suppress_throws
= true;
2049 } else if (nv
[0] == "error_types") {
2050 error_types
= eval (nv
[1]);
2051 } else if (nv
[0] == "no_array_length") {
2052 if (eval (nv
[1]) == "1") {
2053 m
.no_array_length
= true;
2055 } else if (nv
[0] == "array_null_terminated") {
2056 if (eval (nv
[1]) == "1") {
2057 m
.no_array_length
= true;
2058 m
.array_null_terminated
= true;
2060 } else if (nv
[0] == "array_length_type") {
2061 m
.array_length_type
= eval (nv
[1]);
2062 } else if (nv
[0] == "type_name") {
2063 m
.return_type
= return_type
= parse_type_from_string (eval (nv
[1]), return_type
.value_owned
);
2064 } else if (nv
[0] == "type_arguments") {
2065 parse_type_arguments_from_string (return_type
, eval (nv
[1]));
2066 } else if (nv
[0] == "deprecated") {
2067 if (eval (nv
[1]) == "1") {
2068 m
.deprecated
= true;
2070 } else if (nv
[0] == "replacement") {
2071 m
.replacement
= eval (nv
[1]);
2072 } else if (nv
[0] == "deprecated_since") {
2073 m
.deprecated_since
= eval (nv
[1]);
2074 } else if (nv
[0] == "cheader_filename") {
2075 m
.add_cheader_filename (eval (nv
[1]));
2076 } else if (nv
[0] == "abstract") {
2077 if (eval (nv
[1]) == "1") {
2078 m
.is_abstract
= true;
2080 } else if (nv
[0] == "virtual") {
2081 if (eval (nv
[1]) == "1") {
2082 m
.is_virtual
= true;
2084 } else if (nv
[0] == "vfunc_name") {
2085 m
.vfunc_name
= eval (nv
[1]);
2086 } else if (nv
[0] == "finish_name") {
2087 m
.set_finish_cname (eval (nv
[1]));
2088 } else if (nv
[0] == "async") {
2089 if (eval (nv
[1]) == "1") {
2090 // force async function, even if it doesn't end in _async
2093 } else if (nv
[0] == "parent") {
2094 Symbol container
= get_container_from_name (eval (nv
[1]));
2095 var prefix
= container
.get_lower_case_cprefix ();
2096 if (symbol
.has_prefix (prefix
)) {
2097 m
.set_cname (m
.name
);
2098 m
.name
= symbol
.substring (prefix
.length
);
2100 } else if (nv
[0] == "experimental") {
2101 if (eval (nv
[1]) == "1") {
2102 m
.experimental
= true;
2108 m
.set_cname (symbol
);
2111 Parameter last_param
= null;
2112 DataType last_param_type
= null;
2113 foreach (weak IdlNodeParam param
in parameters
) {
2114 weak IdlNode param_node
= (IdlNode
) param
;
2118 if (!(m is CreationMethod
) &&
2119 current_data_type
!= null &&
2120 param
.type
.is_interface
&&
2121 (param_node
.name
== "self" ||
2122 param
.type
.@
interface.has_suffix (current_data_type
.get_cname ()))) {
2125 } else if (!(m is CreationMethod
) &&
2126 current_data_type
!= null &&
2127 param
.type
.is_interface
&&
2128 (param_node
.name
== "klass" ||
2129 param
.type
.@
interface.has_suffix ("%sClass".printf(current_data_type
.get_cname ())))) {
2131 m
.binding
= MemberBinding
.CLASS
;
2132 if (m
.name
.has_prefix ("class_")) {
2133 m
.name
= m
.name
.substring ("class_".length
, m
.name
.length
- "class_".length
);
2138 m
.binding
= MemberBinding
.STATIC
;
2142 if (param
.type
.@
interface == "GAsyncReadyCallback" && (symbol
.has_suffix ("_async") || m
.coroutine
)) {
2148 if (suppress_throws
== false && param_is_exception (param
)) {
2149 if (error_types
== null)
2150 m
.add_error_type (parse_type (param
.type
));
2154 string param_name
= param_node
.name
;
2155 if (param_name
== "result") {
2156 // avoid conflict with generated result variable
2157 param_name
= "_result";
2158 } else if (param_name
== "string") {
2159 // avoid conflict with string type
2162 ParameterDirection direction
;
2163 var param_type
= parse_param (param
, out direction
);
2164 var p
= new
Parameter (param_name
, param_type
);
2165 p
.direction
= direction
;
2167 bool hide_param
= false;
2168 bool show_param
= false;
2169 bool set_array_length_pos
= false;
2170 double array_length_pos
= 0;
2171 bool set_delegate_target_pos
= false;
2172 double delegate_target_pos
= 0;
2173 bool array_requested
= false;
2174 bool out_requested
= false;
2175 attributes
= get_attributes ("%s.%s".printf (symbol
, param_node
.name
));
2176 if (attributes
!= null) {
2177 foreach (string attr
in attributes
) {
2178 var nv
= attr
.split ("=", 2);
2179 if (nv
[0] == "is_array") {
2180 if (eval (nv
[1]) == "1") {
2181 param_type
= new
ArrayType (param_type
, 1, param_type
.source_reference
);
2182 p
.variable_type
= param_type
;
2183 if (!out_requested
) {
2184 p
.direction
= ParameterDirection
.IN
;
2186 array_requested
= true;
2188 } else if (nv
[0] == "is_out") {
2189 if (eval (nv
[1]) == "1") {
2190 p
.direction
= ParameterDirection
.OUT
;
2191 out_requested
= true;
2192 if (!array_requested
&& param_type is ArrayType
) {
2193 var array_type
= (ArrayType
) param_type
;
2194 param_type
= array_type
.element_type
;
2195 p
.variable_type
= param_type
;
2198 } else if (nv
[0] == "is_ref") {
2199 if (eval (nv
[1]) == "1") {
2200 p
.direction
= ParameterDirection
.REF
;
2201 if (!array_requested
&& param_type is ArrayType
) {
2202 var array_type
= (ArrayType
) param_type
;
2203 param_type
= array_type
.element_type
;
2204 p
.variable_type
= param_type
;
2207 } else if (nv
[0] == "nullable") {
2208 if (eval (nv
[1]) == "1") {
2209 param_type
.nullable
= true;
2211 } else if (nv
[0] == "transfer_ownership") {
2212 if (eval (nv
[1]) == "1") {
2213 param_type
.value_owned
= true;
2215 } else if (nv
[0] == "takes_ownership") {
2216 if (eval (nv
[1]) == "1") {
2217 param_type
.value_owned
= true;
2219 } else if (nv
[0] == "value_owned") {
2220 if (eval (nv
[1]) == "0") {
2221 param_type
.value_owned
= false;
2222 } else if (eval (nv
[1]) == "1") {
2223 param_type
.value_owned
= true;
2225 } else if (nv
[0] == "hidden") {
2226 if (eval (nv
[1]) == "1") {
2228 } else if (eval (nv
[1]) == "0") {
2231 } else if (nv
[0] == "no_array_length") {
2232 if (eval (nv
[1]) == "1") {
2233 p
.no_array_length
= true;
2235 } else if (nv
[0] == "array_length_type") {
2236 p
.array_length_type
= eval (nv
[1]);
2237 } else if (nv
[0] == "array_null_terminated") {
2238 if (eval (nv
[1]) == "1") {
2239 p
.no_array_length
= true;
2240 p
.array_null_terminated
= true;
2242 } else if (nv
[0] == "array_length_pos") {
2243 set_array_length_pos
= true;
2244 array_length_pos
= double.parse (eval (nv
[1]));
2245 } else if (nv
[0] == "delegate_target_pos") {
2246 set_delegate_target_pos
= true;
2247 delegate_target_pos
= double.parse (eval (nv
[1]));
2248 } else if (nv
[0] == "type_name") {
2249 p
.variable_type
= param_type
= parse_type_from_string (eval (nv
[1]), false);
2250 } else if (nv
[0] == "ctype") {
2251 p
.ctype
= eval (nv
[1]);
2252 } else if (nv
[0] == "type_arguments") {
2253 parse_type_arguments_from_string (param_type
, eval (nv
[1]));
2254 } else if (nv
[0] == "default_value") {
2255 var val
= eval (nv
[1]);
2256 if (val
== "null") {
2257 p
.initializer
= new
NullLiteral (param_type
.source_reference
);
2258 } else if (val
== "true") {
2259 p
.initializer
= new
BooleanLiteral (true, param_type
.source_reference
);
2260 } else if (val
== "false") {
2261 p
.initializer
= new
BooleanLiteral (false, param_type
.source_reference
);
2262 } else if (val
== "") {
2263 p
.initializer
= new
StringLiteral ("\"\"", param_type
.source_reference
);
2265 if (int64.try_parse (val
)) {
2266 p
.initializer
= new
IntegerLiteral (val
, param_type
.source_reference
);
2268 if (double.try_parse (val
)) {
2269 p
.initializer
= new
RealLiteral (val
, param_type
.source_reference
);
2271 if (val
.has_prefix ("\"") && val
.has_suffix ("\"")) {
2272 p
.initializer
= new
StringLiteral (val
, param_type
.source_reference
);
2274 foreach (var member
in val
.split (".")) {
2275 p
.initializer
= new
MemberAccess (p
.initializer
, member
, param_type
.source_reference
);
2285 if (last_param
!= null && p
.name
== "n_" + last_param
.name
) {
2286 if (!(last_param_type is ArrayType
)) {
2287 // last_param is array, p is array length
2288 last_param_type
= new
ArrayType (last_param_type
, 1, last_param_type
.source_reference
);
2289 last_param
.variable_type
= last_param_type
;
2290 last_param
.direction
= ParameterDirection
.IN
;
2293 // hide array length param
2295 } else if (last_param
!= null && p
.name
== "user_data") {
2296 // last_param is delegate
2298 // hide deleate target param
2302 if (show_param
|| !hide_param
) {
2303 m
.add_parameter (p
);
2304 if (set_array_length_pos
) {
2305 p
.carray_length_parameter_position
= array_length_pos
;
2307 if (set_delegate_target_pos
) {
2308 p
.cdelegate_target_parameter_position
= delegate_target_pos
;
2313 last_param_type
= param_type
;
2316 if (suppress_throws
== false && error_types
!= null) {
2317 var type_args
= eval (error_types
).split (",");
2318 foreach (string type_arg
in type_args
) {
2319 m
.add_error_type (parse_type_from_string (type_arg
, true));
2324 // no parameters => static method
2325 m
.binding
= MemberBinding
.STATIC
;
2328 if (last_param
!= null && last_param
.name
.has_prefix ("first_")) {
2329 last_param
.ellipsis
= true;
2330 } else if (add_ellipsis
) {
2331 m
.add_parameter (new Parameter
.with_ellipsis ());
2337 private bool param_is_exception (IdlNodeParam param
) {
2338 if (!param
.type
.is_error
) {
2341 var s
= param
.type
.unparsed
.chomp ();
2342 if (s
.has_suffix ("**")) {
2348 private Method?
parse_function (IdlNodeFunction f
, bool is_interface
= false) {
2349 weak IdlNode node
= (IdlNode
) f
;
2355 return create_method (node
.name
, f
.symbol
, f
.result
, f
.parameters
, f
.is_constructor
, is_interface
);
2358 private Method
parse_virtual (IdlNodeVFunc v
, IdlNodeFunction? func
, bool is_interface
= false) {
2359 weak IdlNode node
= (IdlNode
) v
;
2360 string symbol
= "%s%s".printf (current_data_type
.get_lower_case_cprefix(), node
.name
);
2363 symbol
= func
.symbol
;
2366 Method m
= create_method (node
.name
, symbol
, v
.result
, func
!= null ? func
.parameters
: v
.parameters
, false, is_interface
);
2368 m
.binding
= MemberBinding
.INSTANCE
;
2369 m
.is_virtual
= !(m
.is_abstract
|| is_interface
);
2370 m
.is_abstract
= m
.is_abstract
|| is_interface
;
2372 var attributes
= get_attributes (symbol
);
2373 if (attributes
!= null) {
2374 foreach (string attr
in attributes
) {
2375 var nv
= attr
.split ("=", 2);
2376 if (nv
[0] == "virtual") {
2377 if (eval (nv
[1]) == "0") {
2378 m
.is_virtual
= false;
2379 m
.is_abstract
= false;
2381 m
.is_virtual
= true;
2382 m
.is_abstract
= false;
2389 m
.attributes
.append (new
Attribute ("NoWrapper", null));
2396 private string fix_prop_name (string name
) {
2397 var str
= new
StringBuilder ();
2401 while (i
.length
> 0) {
2402 unichar c
= i
.get_char ();
2406 str
.append_unichar (c
);
2415 private Property?
parse_property (IdlNodeProperty prop_node
) {
2416 weak IdlNode node
= (IdlNode
) prop_node
;
2418 if (prop_node
.deprecated
) {
2422 if (!prop_node
.readable
&& !prop_node
.writable
) {
2423 // buggy GIDL definition
2424 prop_node
.readable
= true;
2425 prop_node
.writable
= true;
2428 var prop
= new
Property (fix_prop_name (node
.name
), parse_type (prop_node
.type
), null, null, current_source_reference
);
2429 prop
.access
= SymbolAccessibility
.PUBLIC
;
2430 prop
.interface_only
= true;
2432 if (prop_node
.type
.is_interface
&& prop_node
.type
.interface == "GStrv") {
2433 prop
.no_array_length
= true;
2434 prop
.array_null_terminated
= true;
2437 if (prop_node
.readable
) {
2438 prop
.get_accessor
= new
PropertyAccessor (true, false, false, prop
.property_type
.copy (), null, null);
2440 if (prop_node
.writable
) {
2441 prop
.set_accessor
= new
PropertyAccessor (false, false, false, prop
.property_type
.copy (), null, null);
2442 if (prop_node
.construct_only
) {
2443 prop
.set_accessor
.construction
= true;
2445 prop
.set_accessor
.writable
= true;
2446 prop
.set_accessor
.construction
= prop_node
.@
construct;
2450 var attributes
= get_attributes ("%s:%s".printf (current_data_type
.get_cname (), node
.name
));
2451 if (attributes
!= null) {
2452 foreach (string attr
in attributes
) {
2453 var nv
= attr
.split ("=", 2);
2454 if (nv
[0] == "hidden") {
2455 if (eval (nv
[1]) == "1") {
2458 } else if (nv
[0] == "type_arguments") {
2459 parse_type_arguments_from_string (prop
.property_type
, eval (nv
[1]));
2460 } else if (nv
[0] == "deprecated") {
2461 if (eval (nv
[1]) == "1") {
2462 prop
.deprecated
= true;
2464 } else if (nv
[0] == "replacement") {
2465 prop
.replacement
= eval (nv
[1]);
2466 } else if (nv
[0] == "deprecated_since") {
2467 prop
.deprecated_since
= eval (nv
[1]);
2468 } else if (nv
[0] == "accessor_method") {
2469 if (eval (nv
[1]) == "0") {
2470 prop
.no_accessor_method
= true;
2472 } else if (nv
[0] == "owned_get") {
2473 if (eval (nv
[1]) == "1") {
2474 prop
.get_accessor
.value_type
.value_owned
= true;
2476 } else if (nv
[0] == "type_name") {
2477 prop
.property_type
= parse_type_from_string (eval (nv
[1]), false);
2478 } else if (nv
[0] == "experimental") {
2479 if (eval (nv
[1]) == "1") {
2480 prop
.experimental
= true;
2486 if (current_type_symbol_set
!= null) {
2487 current_type_symbol_set
.add (prop
.name
);
2493 private Constant?
parse_constant (IdlNodeConstant const_node
) {
2494 weak IdlNode node
= (IdlNode
) const_node
;
2496 var type
= parse_type (const_node
.type
);
2501 var c
= new
Constant (node
.name
, type
, null, current_source_reference
);
2504 string[] attributes
= get_attributes (node
.name
);
2505 if (attributes
!= null) {
2506 foreach (string attr
in attributes
) {
2507 var nv
= attr
.split ("=", 2);
2508 if (nv
[0] == "cheader_filename") {
2509 c
.add_cheader_filename (eval (nv
[1]));
2510 } else if (nv
[0] == "deprecated") {
2511 if (eval (nv
[1]) == "1") {
2512 c
.deprecated
= true;
2514 } else if (nv
[0] == "replacement") {
2515 c
.replacement
= eval (nv
[1]);
2516 } else if (nv
[0] == "deprecated_since") {
2517 c
.deprecated_since
= eval (nv
[1]);
2518 } else if (nv
[0] == "hidden") {
2519 if (eval (nv
[1]) == "1") {
2522 } else if (nv
[0] == "experimental") {
2523 if (eval (nv
[1]) == "1") {
2524 c
.experimental
= true;
2530 c
.access
= SymbolAccessibility
.PUBLIC
;
2535 private Field?
parse_field (IdlNodeField field_node
) {
2536 weak IdlNode node
= (IdlNode
) field_node
;
2537 bool unhidden
= false;
2539 var type
= parse_type (field_node
.type
);
2544 string cheader_filename
= null;
2545 string ctype
= null;
2546 string array_length_cname
= null;
2547 string array_length_type
= null;
2548 bool array_null_terminated
= false;
2549 bool deprecated
= false;
2550 string deprecated_since
= null;
2551 string replacement
= null;
2552 bool experimental
= false;
2554 var attributes
= get_attributes ("%s.%s".printf (current_data_type
.get_cname (), node
.name
));
2555 if (attributes
!= null) {
2556 foreach (string attr
in attributes
) {
2557 var nv
= attr
.split ("=", 2);
2558 if (nv
[0] == "hidden") {
2559 if (eval (nv
[1]) == "1") {
2564 } else if (nv
[0] == "is_array") {
2565 if (eval (nv
[1]) == "1") {
2566 type
= new
ArrayType (type
, 1, type
.source_reference
);
2568 } else if (nv
[0] == "weak") {
2569 if (eval (nv
[1]) == "0") {
2570 type
.value_owned
= true;
2572 } else if (nv
[0] == "value_owned") {
2573 if (eval (nv
[1]) == "0") {
2574 type
.value_owned
= false;
2575 } else if (eval (nv
[1]) == "1") {
2576 type
.value_owned
= true;
2578 } else if (nv
[0] == "type_name") {
2579 type
= parse_type_from_string (eval (nv
[1]), true);
2580 } else if (nv
[0] == "type_arguments") {
2581 parse_type_arguments_from_string (type
, eval (nv
[1]));
2582 } else if (nv
[0] == "deprecated") {
2583 if (eval (nv
[1]) == "1") {
2586 } else if (nv
[0] == "replacement") {
2587 replacement
= eval (nv
[1]);
2588 } else if (nv
[0] == "deprecated_since") {
2589 deprecated_since
= eval (nv
[1]);
2590 } else if (nv
[0] == "cheader_filename") {
2591 cheader_filename
= eval (nv
[1]);
2592 } else if (nv
[0] == "ctype") {
2593 ctype
= eval (nv
[1]);
2594 } else if (nv
[0] == "array_null_terminated") {
2595 if (eval (nv
[1]) == "1") {
2596 array_null_terminated
= true;
2598 } else if (nv
[0] == "array_length_cname") {
2599 array_length_cname
= eval (nv
[1]);
2600 } else if (nv
[0] == "array_length_type") {
2601 array_length_type
= eval (nv
[1]);
2602 } else if (nv
[0] == "experimental") {
2603 if (eval (nv
[1]) == "1") {
2604 experimental
= true;
2610 if (node
.name
.has_prefix("_") && !unhidden
) {
2614 if (current_type_symbol_set
!= null) {
2615 current_type_symbol_set
.add (node
.name
);
2618 string field_name
= node
.name
;
2619 if (field_name
== "string") {
2620 // avoid conflict with string type
2624 var field
= new
Field (field_name
, type
, null, current_source_reference
);
2625 field
.access
= SymbolAccessibility
.PUBLIC
;
2627 if (field_name
!= node
.name
) {
2628 field
.set_cname (node
.name
);
2632 field
.deprecated
= true;
2634 if (deprecated_since
!= null) {
2635 field
.deprecated_since
= deprecated_since
;
2638 if (replacement
!= null) {
2639 field
.replacement
= replacement
;
2644 field
.experimental
= true;
2647 if (ctype
!= null) {
2648 field
.set_ctype (ctype
);
2651 if (cheader_filename
!= null) {
2652 field
.add_cheader_filename (cheader_filename
);
2655 if (array_null_terminated
) {
2656 field
.array_null_terminated
= true;
2659 if (array_length_cname
!= null || array_length_type
!= null) {
2660 if (array_length_cname
!= null) {
2661 field
.set_array_length_cname (array_length_cname
);
2663 if (array_length_type
!= null) {
2664 field
.array_length_type
= array_length_type
;
2667 field
.no_array_length
= true;
2673 private string[]?
get_attributes (string codenode
) {
2674 var attributes
= codenode_attributes_map
.get (codenode
);
2676 if (attributes
== null) {
2677 var dot_required
= (-1 != codenode
.index_of_char ('.'));
2678 var colon_required
= (-1 != codenode
.index_of_char (':'));
2680 var pattern_specs
= codenode_attributes_patterns
.get_keys ();
2681 foreach (PatternSpec
* pattern
in pattern_specs
) {
2682 var pspec
= codenode_attributes_patterns
[pattern
];
2684 if ((dot_required
&& -1 == pspec
.index_of_char ('.')) ||
2685 (colon_required
&& -1 == pspec
.index_of_char (':'))) {
2689 if (pattern
->match_string (codenode
)) {
2690 return get_attributes (pspec
);
2695 if (attributes
== null) {
2699 GLib
.SList
<string> attr_list
= new GLib
.SList
<string> ();
2700 var attr
= new GLib
.StringBuilder
.sized (attributes
.length
);
2701 var attributes_len
= attributes
.length
;
2702 unowned
string remaining
= attributes
;
2703 bool quoted
= false, escaped
= false;
2704 for (int b
= 0 ; b
< attributes_len
; b
++) {
2705 unichar c
= remaining
.get_char ();
2709 attr
.append_unichar (c
);
2712 attr
.append_unichar (c
);
2714 } else if (c
== '\\') {
2716 } else if (!quoted
&& (c
== ' ')) {
2717 attr_list
.prepend (attr
.str
);
2720 attr
.append_unichar (c
);
2724 remaining
= (string) ((char*) remaining
+ remaining
.index_of_nth_char (1));
2728 attr_list
.prepend (attr
.str
);
2731 var attrs
= new
string[attr_list
.length ()];
2732 unowned GLib
.SList
<string>? attr_i
= attr_list
;
2733 for (int a
= 0 ; a
< attrs
.length
; a
++, attr_i
= attr_i
.next
) {
2734 attrs
[(attrs
.length
- 1) - a
] = attr_i
.data
;
2740 private string eval (string s
) {
2741 return ((s
.length
>= 2) && s
.has_prefix ("\"") && s
.has_suffix ("\"")) ? s
.substring (1, s
.length
- 2) : s
;
2744 private Signal?
parse_signal (IdlNodeSignal sig_node
) {
2745 weak IdlNode node
= (IdlNode
) sig_node
;
2747 if (sig_node
.deprecated
|| sig_node
.result
== null) {
2751 var sig
= new
Signal (fix_prop_name (node
.name
), parse_param (sig_node
.result
), current_source_reference
);
2752 sig
.access
= SymbolAccessibility
.PUBLIC
;
2754 var attributes
= get_attributes ("%s::%s".printf (current_data_type
.get_cname (), sig
.name
));
2755 if (attributes
!= null) {
2756 string ns_name
= null;
2757 foreach (string attr
in attributes
) {
2758 var nv
= attr
.split ("=", 2);
2759 if (nv
[0] == "name") {
2760 sig
.set_cname (sig
.name
);
2761 sig
.name
= eval (nv
[1]);
2762 } else if (nv
[0] == "has_emitter" && eval (nv
[1]) == "1") {
2763 sig
.has_emitter
= true;
2764 } else if (nv
[0] == "hidden") {
2765 if (eval (nv
[1]) == "1") {
2768 } else if (nv
[0] == "deprecated") {
2769 if (eval (nv
[1]) == "1") {
2770 sig
.deprecated
= true;
2772 } else if (nv
[0] == "replacement") {
2773 sig
.replacement
= eval (nv
[1]);
2774 } else if (nv
[0] == "deprecated_since") {
2775 sig
.deprecated_since
= eval (nv
[1]);
2776 } else if (nv
[0] == "transfer_ownership") {
2777 if (eval (nv
[1]) == "1") {
2778 sig
.return_type
.value_owned
= true;
2780 } else if (nv
[0] == "namespace_name") {
2781 ns_name
= eval (nv
[1]);
2782 } else if (nv
[0] == "type_name") {
2783 sig
.return_type
= parse_type_from_string (eval (nv
[1]), false);
2784 } else if (nv
[0] == "type_arguments") {
2785 parse_type_arguments_from_string (sig
.return_type
, eval (nv
[1]));
2786 } else if (nv
[0] == "experimental") {
2787 if (eval (nv
[1]) == "1") {
2788 sig
.experimental
= true;
2792 if (ns_name
!= null) {
2793 ((UnresolvedType
) sig
.return_type
).unresolved_symbol
.inner
= new
UnresolvedSymbol (null, ns_name
);
2797 sig
.is_virtual
= true;
2801 foreach (weak IdlNodeParam param
in sig_node
.parameters
) {
2803 // ignore implicit first signal parameter (sender)
2808 weak IdlNode param_node
= (IdlNode
) param
;
2810 ParameterDirection direction
;
2811 var param_type
= parse_param (param
, out direction
);
2812 var p
= new
Parameter (param_node
.name
, param_type
);
2813 p
.direction
= direction
;
2815 bool hide_param
= false;
2816 bool show_param
= false;
2817 attributes
= get_attributes ("%s::%s.%s".printf (current_data_type
.get_cname (), sig
.name
, param_node
.name
));
2818 if (attributes
!= null) {
2819 string ns_name
= null;
2820 foreach (string attr
in attributes
) {
2821 var nv
= attr
.split ("=", 2);
2822 if (nv
[0] == "hidden") {
2823 if (eval (nv
[1]) == "1") {
2825 } else if (eval (nv
[1]) == "0") {
2828 } else if (nv
[0] == "is_array") {
2829 if (eval (nv
[1]) == "1") {
2830 param_type
= new
ArrayType (param_type
, 1, param_type
.source_reference
);
2831 p
.variable_type
= param_type
;
2832 p
.direction
= ParameterDirection
.IN
;
2834 } else if (nv
[0] == "no_array_length") {
2835 if (eval (nv
[1]) == "1") {
2836 p
.no_array_length
= true;
2838 } else if (nv
[0] == "array_length_type") {
2839 p
.array_length_type
= eval (nv
[1]);
2840 } else if (nv
[0] == "array_null_terminated") {
2841 if (eval (nv
[1]) == "1") {
2842 p
.no_array_length
= true;
2843 p
.array_null_terminated
= true;
2845 } else if (nv
[0] == "is_out") {
2846 if (eval (nv
[1]) == "1") {
2847 p
.direction
= ParameterDirection
.OUT
;
2849 } else if (nv
[0] == "is_ref") {
2850 if (eval (nv
[1]) == "1") {
2851 p
.direction
= ParameterDirection
.REF
;
2853 } else if (nv
[0] == "nullable") {
2854 if (eval (nv
[1]) == "1") {
2855 param_type
.nullable
= true;
2857 } else if (nv
[0] == "transfer_ownership") {
2858 if (eval (nv
[1]) == "1") {
2859 param_type
.value_owned
= true;
2861 } else if (nv
[0] == "type_name") {
2862 p
.variable_type
= param_type
= parse_type_from_string (eval (nv
[1]), false);
2863 } else if (nv
[0] == "type_arguments") {
2864 parse_type_arguments_from_string (p
.variable_type
, eval (nv
[1]));
2865 } else if (nv
[0] == "namespace_name") {
2866 ns_name
= eval (nv
[1]);
2869 if (ns_name
!= null) {
2870 ((UnresolvedType
) param_type
).unresolved_symbol
.inner
= new
UnresolvedSymbol (null, ns_name
);
2874 if (show_param
|| !hide_param
) {
2875 sig
.add_parameter (p
);