girparser: Guess virtual method wrapper variant when possible
[vala-lang.git] / vala / valasignaltype.vala
blob6cdab020f00a56ca543dd52054675efca483bf81
1 /* valasignaltype.vala
3 * Copyright (C) 2007-2009 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
19 * Author:
20 * Jürg Billeter <j@bitron.ch>
23 using GLib;
25 /**
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 () {
40 return true;
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) {
56 return false;
59 public override string to_qualified_string (Scope? scope) {
60 return signal_symbol.get_full_name ();
63 DelegateType get_handler_type () {
64 var sender_type = new ObjectType ((ObjectTypeSymbol) signal_symbol.parent_symbol);
65 var result = new DelegateType (signal_symbol.get_delegate (sender_type, this));
66 result.value_owned = true;
67 return result;
70 Method get_connect_method () {
71 if (connect_method == null) {
72 var ulong_type = new IntegerType ((Struct) CodeContext.get ().root.scope.lookup ("ulong"));
73 connect_method = new Method ("connect", ulong_type);
74 connect_method.access = SymbolAccessibility.PUBLIC;
75 connect_method.external = true;
76 connect_method.owner = signal_symbol.scope;
77 connect_method.add_parameter (new Parameter ("handler", get_handler_type ()));
79 return connect_method;
82 Method get_connect_after_method () {
83 if (connect_after_method == null) {
84 var ulong_type = new IntegerType ((Struct) CodeContext.get ().root.scope.lookup ("ulong"));
85 connect_after_method = new Method ("connect_after", ulong_type);
86 connect_after_method.access = SymbolAccessibility.PUBLIC;
87 connect_after_method.external = true;
88 connect_after_method.owner = signal_symbol.scope;
89 connect_after_method.add_parameter (new Parameter ("handler", get_handler_type ()));
91 return connect_after_method;
94 Method get_disconnect_method () {
95 if (disconnect_method == null) {
96 disconnect_method = new Method ("disconnect", new VoidType ());
97 disconnect_method.access = SymbolAccessibility.PUBLIC;
98 disconnect_method.external = true;
99 disconnect_method.owner = signal_symbol.scope;
100 disconnect_method.add_parameter (new Parameter ("handler", get_handler_type ()));
102 return disconnect_method;
105 public override Symbol? get_member (string member_name) {
106 if (member_name == "connect") {
107 return get_connect_method ();
108 } else if (member_name == "connect_after") {
109 return get_connect_after_method ();
110 } else if (member_name == "disconnect") {
111 return get_disconnect_method ();
113 return null;
116 public override bool is_accessible (Symbol sym) {
117 return signal_symbol.is_accessible (sym);