valac: Always use the given "pkg-config" and respect PKG_CONFIG envar
[vala-gnome.git] / vala / valamethodtype.vala
blob9a492faebfdccd77f5e812cfc1939920b8043c1b
1 /* valamethodtype.vala
3 * Copyright (C) 2007-2008 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 method referencea.
28 public class Vala.MethodType : DataType {
29 public Method method_symbol { get; set; }
31 public MethodType (Method method_symbol) {
32 this.method_symbol = method_symbol;
35 public override bool is_invokable () {
36 return true;
39 public override DataType? get_return_type () {
40 return method_symbol.return_type;
43 public override List<Parameter>? get_parameters () {
44 return method_symbol.get_parameters ();
47 public override DataType copy () {
48 return new MethodType (method_symbol);
51 public override bool compatible (DataType target_type) {
52 var dt = target_type as DelegateType;
53 if (dt == null) {
54 // method types incompatible to anything but delegates
55 return false;
58 return dt.delegate_symbol.matches_method (method_symbol, dt);
61 public override string to_qualified_string (Scope? scope) {
62 return method_symbol.get_full_name ();
65 public override Symbol? get_member (string member_name) {
66 if (method_symbol.coroutine && member_name == "begin") {
67 return method_symbol;
68 } else if (method_symbol.coroutine && member_name == "end") {
69 return method_symbol;
70 } else if (method_symbol.coroutine && member_name == "callback") {
71 return method_symbol.get_callback_method ();
73 return null;
76 public string to_prototype_string (bool with_type_parameters = false) {
77 var proto = "%s %s (".printf (get_return_type ().to_string (), this.to_string ());
79 int i = 1;
80 foreach (Parameter param in get_parameters ()) {
81 if (i > 1) {
82 proto += ", ";
85 if (param.ellipsis) {
86 proto += "...";
87 continue;
90 if (param.direction == ParameterDirection.IN) {
91 if (param.variable_type.value_owned) {
92 proto += "owned ";
94 } else {
95 if (param.direction == ParameterDirection.REF) {
96 proto += "ref ";
97 } else if (param.direction == ParameterDirection.OUT) {
98 proto += "out ";
100 if (param.variable_type.is_weak ()) {
101 proto += "unowned ";
105 proto = "%s%s %s".printf (proto, param.variable_type.to_qualified_string (), param.name);
107 if (param.initializer != null) {
108 proto = "%s = %s".printf (proto, param.initializer.to_string ());
111 i++;
114 return proto + ")";