1 /* valaccodefunction.vala
3 * Copyright (C) 2006-2007 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>
27 * Represents a function declaration in the C code.
29 public class Vala
.CCodeFunction
: CCodeNode
{
31 * The name of this function.
33 public string name
{ get; set; }
36 * The function modifiers.
38 public CCodeModifiers modifiers
{ get; set; }
41 * The function return type.
43 public string return_type
{ get; set; }
48 public CCodeBlock block
{ get; set; }
50 private Gee
.List
<CCodeFormalParameter
> parameters
= new ArrayList
<CCodeFormalParameter
> ();
52 public CCodeFunction (string name
, string return_type
) {
53 this
.return_type
= return_type
;
58 * Appends the specified parameter to the list of function parameters.
60 * @param param a formal parameter
62 public void add_parameter (CCodeFormalParameter param
) {
63 parameters
.add (param
);
67 * Returns a copy of this function.
69 * @return copied function
71 public CCodeFunction
copy () {
72 var func
= new
CCodeFunction (name
, return_type
);
73 func
.modifiers
= modifiers
;
75 /* no deep copy for lists available yet
76 * func.parameters = parameters.copy ();
78 foreach (CCodeFormalParameter param
in parameters
) {
79 func
.parameters
.add (param
);
86 public override void write (CCodeWriter writer
) {
87 writer
.write_indent (line
);
88 if (CCodeModifiers
.STATIC
in modifiers
) {
89 writer
.write_string ("static ");
91 if (CCodeModifiers
.INLINE
in modifiers
) {
92 writer
.write_string ("inline ");
94 writer
.write_string (return_type
);
95 writer
.write_string (" ");
96 writer
.write_string (name
);
97 writer
.write_string (" (");
100 foreach (CCodeFormalParameter param
in parameters
) {
102 writer
.write_string (", ");
106 param
.write (writer
);
109 writer
.write_string ("void");
112 writer
.write_string (")");
114 writer
.write_string (";");
116 block
.write (writer
);
117 writer
.write_newline ();
119 writer
.write_newline ();