Line data Source code
1 : /* valamethodtype.vala
2 : *
3 : * Copyright (C) 2007-2008 Jürg Billeter
4 : *
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.
9 :
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.
14 :
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
18 : *
19 : * Author:
20 : * Jürg Billeter <j@bitron.ch>
21 : */
22 :
23 : using GLib;
24 :
25 : /**
26 : * The type of a method referencea.
27 : */
28 1423 : public class Vala.MethodType : CallableType {
29 : public weak Method method_symbol {
30 2029945 : get {
31 2029945 : return (Method) symbol;
32 : }
33 : }
34 :
35 1126188 : public MethodType (Method method_symbol, SourceReference? source_reference = null) {
36 375396 : base (method_symbol, source_reference);
37 : }
38 :
39 159963 : public override DataType copy () {
40 159963 : return new MethodType (method_symbol, source_reference);
41 : }
42 :
43 7745 : public override bool compatible (DataType target_type) {
44 7745 : unowned DelegateType? dt = target_type as DelegateType;
45 7748 : if (dt == null) {
46 : // method types incompatible to anything but delegates
47 5 : return false;
48 : }
49 :
50 : // FIXME delegates don't provide dedicated parameters for generic arguments,
51 : // therefore they are never compatible
52 7743 : if (!(method_symbol.parent_node is LambdaExpression) && method_symbol.has_type_parameters ()) {
53 5 : return false;
54 : }
55 :
56 7740 : return dt.delegate_symbol.matches_method (method_symbol, dt);
57 : }
58 :
59 13 : public override string to_qualified_string (Scope? scope) {
60 13 : return method_symbol.get_full_name ();
61 : }
62 :
63 94 : public override Symbol? get_member (string member_name) {
64 94 : if (method_symbol.coroutine && member_name == "begin") {
65 94 : return method_symbol;
66 42 : } else if (method_symbol.coroutine && member_name == "end") {
67 44 : return method_symbol;
68 20 : } else if (method_symbol.coroutine && member_name == "callback") {
69 40 : return method_symbol.get_callback_method ();
70 : }
71 94 : return null;
72 : }
73 : }
|