D-Bus: Remove extra semicolon to avoid C warning
[vala-lang.git] / vala / valadelegatetype.vala
blobda17014ee713a7d581ef1ca21503c3d1bb2764e5
1 /* valadelegatetype.vala
3 * Copyright (C) 2007-2010 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 an instance of a delegate.
28 public class Vala.DelegateType : DataType {
29 public Delegate delegate_symbol { get; set; }
31 public bool is_called_once { get; set; }
33 public DelegateType (Delegate delegate_symbol) {
34 this.delegate_symbol = delegate_symbol;
37 public override bool is_invokable () {
38 return true;
41 public override DataType? get_return_type () {
42 return delegate_symbol.return_type;
45 public override List<Parameter>? get_parameters () {
46 return delegate_symbol.get_parameters ();
49 public override string to_qualified_string (Scope? scope) {
50 // logic temporarily duplicated from DataType class
52 Symbol global_symbol = delegate_symbol;
53 while (global_symbol.parent_symbol.name != null) {
54 global_symbol = global_symbol.parent_symbol;
57 Symbol sym = null;
58 Scope parent_scope = scope;
59 while (sym == null && parent_scope != null) {
60 sym = parent_scope.lookup (global_symbol.name);
61 parent_scope = parent_scope.parent_scope;
64 string s;
66 if (sym != null && global_symbol != sym) {
67 s = "global::" + delegate_symbol.get_full_name ();;
68 } else {
69 s = delegate_symbol.get_full_name ();
72 var type_args = get_type_arguments ();
73 if (type_args.size > 0) {
74 s += "<";
75 bool first = true;
76 foreach (DataType type_arg in type_args) {
77 if (!first) {
78 s += ",";
79 } else {
80 first = false;
82 if (!type_arg.value_owned) {
83 s += "weak ";
85 s += type_arg.to_qualified_string (scope);
87 s += ">";
89 if (nullable) {
90 s += "?";
92 return s;
95 public override DataType copy () {
96 var result = new DelegateType (delegate_symbol);
97 result.source_reference = source_reference;
98 result.value_owned = value_owned;
99 result.nullable = nullable;
101 foreach (DataType arg in get_type_arguments ()) {
102 result.add_type_argument (arg.copy ());
105 return result;
108 public override string? get_cname () {
109 if (CodeContext.get ().profile == Profile.DOVA) {
110 return "%s*".printf (delegate_symbol.get_cname ());
111 } else {
112 return delegate_symbol.get_cname ();
116 public override bool is_accessible (Symbol sym) {
117 return delegate_symbol.is_accessible (sym);
120 public override string? get_type_id () {
121 return "G_TYPE_POINTER";
124 public override bool check (CodeContext context) {
125 return delegate_symbol.check (context);
128 public override bool is_disposable () {
129 return delegate_symbol.has_target && value_owned;