1 /* valacallabletype.vala
3 * Copyright (C) 2017 Rico Tzschichholz
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 * Rico Tzschichholz <ricotz@ubuntu.com>
26 * A callable type, i.e. a delegate, method, or signal type.
28 public abstract class Vala
.CallableType
: DataType
{
29 public override string to_prototype_string (string? override_name
= null) {
30 StringBuilder builder
= new
StringBuilder ();
33 var return_type
= get_return_type ();
34 if (return_type
.is_weak ()) {
35 builder
.append ("unowned ");
37 builder
.append (return_type
.to_qualified_string ());
40 builder
.append_c (' ');
41 builder
.append (override_name ?? this
.to_string ());
42 builder
.append_c (' ');
44 // Append parameter-list
45 builder
.append_c ('(');
47 // add sender parameter for internal signal-delegates
48 var delegate_type
= this as DelegateType
;
49 if (delegate_type
!= null) {
50 var delegate_symbol
= delegate_type
.delegate_symbol
;
51 if (delegate_symbol
.parent_symbol is Signal
&& delegate_symbol
.sender_type
!= null) {
52 builder
.append (delegate_symbol
.sender_type
.to_qualified_string ());
56 foreach (Parameter param
in get_parameters ()) {
58 builder
.append (", ");
62 builder
.append ("...");
66 if (param
.direction
== ParameterDirection
.IN
) {
67 if (param
.variable_type
.value_owned
) {
68 builder
.append ("owned ");
71 if (param
.direction
== ParameterDirection
.REF
) {
72 builder
.append ("ref ");
73 } else if (param
.direction
== ParameterDirection
.OUT
) {
74 builder
.append ("out ");
76 if (!param
.variable_type
.value_owned
&& param
.variable_type is ReferenceType
) {
77 builder
.append ("weak ");
81 builder
.append (param
.variable_type
.to_qualified_string ());
83 if (param
.initializer
!= null) {
84 builder
.append (" = ");
85 builder
.append (param
.initializer
.to_string ());
90 builder
.append_c (')');
93 var error_types
= get_error_types ();
94 if (error_types
.size
> 0) {
95 builder
.append (" throws ");
98 foreach (DataType type
in error_types
) {
100 builder
.append (", ");
105 builder
.append (type
.to_string ());