Fix gst_base_transform_get_unit_size bindings, fixes bug 565978
[vala-lang.git] / ccode / valaccodefunction.vala
blob38bdada30167be0ae467f840f64c6460d03e2585
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
19 * Author:
20 * Jürg Billeter <j@bitron.ch>
23 using GLib;
24 using Gee;
26 /**
27 * Represents a function declaration in the C code.
29 public class Vala.CCodeFunction : CCodeNode {
30 /**
31 * The name of this function.
33 public string name { get; set; }
35 /**
36 * The function modifiers.
38 public CCodeModifiers modifiers { get; set; }
40 /**
41 * The function return type.
43 public string return_type { get; set; }
45 /**
46 * The function body.
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;
54 this.name = name;
57 /**
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);
66 /**
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);
82 func.block = block;
83 return func;
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 (" (");
99 bool first = true;
100 foreach (CCodeFormalParameter param in parameters) {
101 if (!first) {
102 writer.write_string (", ");
103 } else {
104 first = false;
106 param.write (writer);
108 if (first) {
109 writer.write_string ("void");
112 writer.write_string (")");
113 if (block == null) {
114 writer.write_string (";");
115 } else {
116 block.write (writer);
117 writer.write_newline ();
119 writer.write_newline ();