json-glib-1.0: Make Object.set_member node parameter owned
[vala-lang.git] / vala / valadelegatetype.vala
blobc5f2ec8e0281b0b2d69e81b5a37ec7cfcf7a636f
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 string s = delegate_symbol.get_full_name ();
52 var type_args = get_type_arguments ();
53 if (type_args.size > 0) {
54 s += "<";
55 bool first = true;
56 foreach (DataType type_arg in type_args) {
57 if (!first) {
58 s += ",";
59 } else {
60 first = false;
62 if (!type_arg.value_owned) {
63 s += "weak ";
65 s += type_arg.to_qualified_string (scope);
67 s += ">";
69 if (nullable) {
70 s += "?";
72 return s;
75 public override DataType copy () {
76 var result = new DelegateType (delegate_symbol);
77 result.source_reference = source_reference;
78 result.value_owned = value_owned;
79 result.nullable = nullable;
81 foreach (DataType arg in get_type_arguments ()) {
82 result.add_type_argument (arg.copy ());
85 return result;
88 public override string? get_cname () {
89 if (CodeContext.get ().profile == Profile.DOVA) {
90 return "%s*".printf (delegate_symbol.get_cname ());
91 } else {
92 return delegate_symbol.get_cname ();
96 public override bool is_accessible (Symbol sym) {
97 return delegate_symbol.is_accessible (sym);
100 public override string? get_type_id () {
101 return "G_TYPE_POINTER";
104 public override bool check (CodeContext context) {
105 return delegate_symbol.check (context);
108 public override bool is_disposable () {
109 return delegate_symbol.has_target && value_owned;