1 /* valaccodefunction.vala
3 * Copyright (C) 2006-2009 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
20 * Jürg Billeter <j@bitron.ch>
26 * Represents a function declaration in the C code.
28 public class Vala
.CCodeFunction
: CCodeNode
{
30 * The name of this function.
32 public string name
{ get; set; }
35 * The function modifiers.
37 public CCodeModifiers modifiers
{ get; set; }
40 * The function return type.
42 public string return_type
{ get; set; }
47 public CCodeBlock block
{ get; set; }
49 private List
<CCodeFormalParameter
> parameters
= new ArrayList
<CCodeFormalParameter
> ();
51 public CCodeFunction (string name
, string return_type
= "void") {
53 this
.return_type
= return_type
;
57 * Appends the specified parameter to the list of function parameters.
59 * @param param a formal parameter
61 public void add_parameter (CCodeFormalParameter param
) {
62 parameters
.add (param
);
66 * Returns a copy of this function.
68 * @return copied function
70 public CCodeFunction
copy () {
71 var func
= new
CCodeFunction (name
, return_type
);
72 func
.modifiers
= modifiers
;
74 /* no deep copy for lists available yet
75 * func.parameters = parameters.copy ();
77 foreach (CCodeFormalParameter param
in parameters
) {
78 func
.parameters
.add (param
);
85 public override void write (CCodeWriter writer
) {
86 writer
.write_indent (line
);
87 if (CCodeModifiers
.STATIC
in modifiers
) {
88 writer
.write_string ("static ");
90 if (CCodeModifiers
.INLINE
in modifiers
) {
91 writer
.write_string ("inline ");
93 writer
.write_string (return_type
);
94 writer
.write_string (" ");
95 writer
.write_string (name
);
96 writer
.write_string (" (");
99 foreach (CCodeFormalParameter param
in parameters
) {
101 writer
.write_string (", ");
105 param
.write (writer
);
108 writer
.write_string ("void");
111 writer
.write_string (")");
113 writer
.write_string (";");
115 block
.write (writer
);
116 writer
.write_newline ();
118 writer
.write_newline ();