valaformalparameter.vala 3.15 KB
Newer Older
1
2
/* valaformalparameter.vala
 *
3
 * Copyright (C) 2006-2007  Jürg Billeter, Raffaele Sandrini
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	Jürg Billeter <j@bitron.ch>
21
 *	Raffaele Sandrini <rasa@gmx.ch>
22
23
24
 */

using GLib;
25
using Gee;
26

27
28
29
/**
 * Represents a formal parameter in method and callback signatures.
 */
30
public class Vala.FormalParameter : Symbol, Invokable {
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
	/**
	 * The parameter type.
	 */
	public TypeReference type_reference { get; set; }
	
	/**
	 * Specifies whether the methods accepts an indefinite number of
	 * parameters.
	 */
	public bool ellipsis { get; set; }
	
	/**
	 * Specifies the expression used when the caller doesn't supply an
	 * argument for this parameter.
	 */
	public Expression default_expression { get; set; }
	
48
49
50
51
52
53
	/**
	 * Specifies whether the array length should implicitly be passed
	 * if the parameter type is an array.
	 */
	public bool no_array_length { get; set; }
	
54
55
56
57
58
59
	/**
	 * Specifies whether this parameter holds a value to be assigned to a
	 * construct property. This is only allowed in CreationMethod headers.
	 */
	public bool construct_parameter { get; set; }
	
60
61
62
63
64
65
66
67
	/**
	 * Creates a new formal parameter.
	 *
	 * @param name   parameter name
	 * @param type   parameter type
	 * @param source reference to source code
	 * @return       newly created formal parameter
	 */
68
	public FormalParameter (string! _name, TypeReference type, SourceReference source = null) {
69
70
71
		name = _name;
		type_reference = type;
		source_reference = source;
72
73
74
75
76
77
	}
	
	/**
	 * Creates a new ellipsis parameter representing an indefinite number of
	 * parameters.
	 */
78
	public FormalParameter.with_ellipsis (SourceReference source = null) {
79
80
		ellipsis = true;
		source_reference = source;
81
	}
82

83
84
85
86
	construct {
		access = SymbolAccessibility.PUBLIC;
	}

87
	public override void accept (CodeVisitor! visitor) {
88
89
90
91
		visitor.visit_formal_parameter (this);
	}

	public override void accept_children (CodeVisitor! visitor) {
92
93
		if (!ellipsis) {
			type_reference.accept (visitor);
94
95
96
97
			
			if (default_expression != null) {
				default_expression.accept (visitor);
			}
98
		}
99
	}
100

101
	public Collection<FormalParameter> get_parameters () {
102
103
104
105
106
107
108
109
		if (!is_invokable ()) {
			return null;
		}
		
		var cb = (Callback) type_reference.data_type;
		return cb.get_parameters ();
	}
	
110
	public TypeReference get_return_type () {
111
112
113
114
115
116
117
118
		if (!is_invokable ()) {
			return null;
		}
		
		var cb = (Callback) type_reference.data_type;
		return cb.return_type;
	}

119
	public bool is_invokable () {
120
121
		return (type_reference.data_type is Callback);
	}
122
}