3 * Copyright (C) 2007-2011 Jürg Billeter
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 * Jürg Billeter <j@bitron.ch>
26 * The type of a signal referencea.
28 public class Vala
.SignalType
: DataType
{
29 public Signal signal_symbol
{ get; set; }
31 Method? connect_method
;
32 Method? connect_after_method
;
33 Method? disconnect_method
;
35 public SignalType (Signal signal_symbol
) {
36 this
.signal_symbol
= signal_symbol
;
39 public override bool is_invokable () {
43 public override DataType?
get_return_type () {
44 return signal_symbol
.return_type
;
47 public override List
<Parameter
>?
get_parameters () {
48 return signal_symbol
.get_parameters ();
51 public override DataType
copy () {
52 return new
SignalType (signal_symbol
);
55 public override bool compatible (DataType target_type
) {
59 public override string to_qualified_string (Scope? scope
) {
60 return signal_symbol
.get_full_name ();
63 DelegateType
get_handler_type () {
64 var type_sym
= (ObjectTypeSymbol
) signal_symbol
.parent_symbol
;
66 var sender_type
= new
ObjectType (type_sym
);
67 var result
= new
DelegateType (signal_symbol
.get_delegate (sender_type
, this
));
68 result
.value_owned
= true;
70 if (result
.delegate_symbol
.get_type_parameters ().size
> 0) {
71 foreach (var type_param
in type_sym
.get_type_parameters ()) {
72 var type_arg
= new
GenericType (type_param
);
73 type_arg
.value_owned
= true;
74 result
.add_type_argument (type_arg
);
81 Method
get_connect_method () {
82 if (connect_method
== null) {
83 var ulong_type
= new
IntegerType ((Struct
) CodeContext
.get ().root
.scope
.lookup ("ulong"));
84 connect_method
= new
Method ("connect", ulong_type
);
85 connect_method
.access
= SymbolAccessibility
.PUBLIC
;
86 connect_method
.external
= true;
87 connect_method
.owner
= signal_symbol
.scope
;
88 connect_method
.add_parameter (new
Parameter ("handler", get_handler_type ()));
90 return connect_method
;
93 Method
get_connect_after_method () {
94 if (connect_after_method
== null) {
95 var ulong_type
= new
IntegerType ((Struct
) CodeContext
.get ().root
.scope
.lookup ("ulong"));
96 connect_after_method
= new
Method ("connect_after", ulong_type
);
97 connect_after_method
.access
= SymbolAccessibility
.PUBLIC
;
98 connect_after_method
.external
= true;
99 connect_after_method
.owner
= signal_symbol
.scope
;
100 connect_after_method
.add_parameter (new
Parameter ("handler", get_handler_type ()));
102 return connect_after_method
;
105 Method
get_disconnect_method () {
106 if (disconnect_method
== null) {
107 disconnect_method
= new
Method ("disconnect", new
VoidType ());
108 disconnect_method
.access
= SymbolAccessibility
.PUBLIC
;
109 disconnect_method
.external
= true;
110 disconnect_method
.owner
= signal_symbol
.scope
;
111 disconnect_method
.add_parameter (new
Parameter ("handler", get_handler_type ()));
113 return disconnect_method
;
116 public override Symbol?
get_member (string member_name
) {
117 if (member_name
== "connect") {
118 return get_connect_method ();
119 } else if (member_name
== "connect_after") {
120 return get_connect_after_method ();
121 } else if (member_name
== "disconnect") {
122 return get_disconnect_method ();
127 public override bool is_accessible (Symbol sym
) {
128 return signal_symbol
.is_accessible (sym
);