1 /* valaccodefunctiondeclarator.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>
26 * Represents a function pointer declarator in the C code.
28 public class Vala.CCodeFunctionDeclarator : CCodeDeclarator {
29 private List<CCodeParameter> parameters = new ArrayList<CCodeParameter> ();
31 public CCodeFunctionDeclarator (string name) {
36 * Appends the specified parameter to the list of function parameters.
38 * @param param a formal parameter
40 public void add_parameter (CCodeParameter param) {
41 parameters.add (param);
44 public override void write (CCodeWriter writer) {
45 write_declaration (writer);
48 public override void write_declaration (CCodeWriter writer) {
49 writer.write_string ("(*");
50 writer.write_string (name);
51 writer.write_string (") (");
53 bool has_args = (CCodeModifiers.PRINTF in modifiers || CCodeModifiers.SCANF in modifiers);
55 int format_arg_index = -1;
57 foreach (CCodeParameter param in parameters) {
59 writer.write_string (", ");
62 if (CCodeModifiers.FORMAT_ARG in param.modifiers) {
65 if (has_args && param.ellipsis) {
67 } else if (has_args && param.type_name == "va_list" && format_arg_index < 0) {
68 format_arg_index = i - 1;
73 writer.write_string ("void");
76 writer.write_string (")");
78 if (CCodeModifiers.DEPRECATED in modifiers) {
79 writer.write_string (GNUC_DEPRECATED);
82 if (CCodeModifiers.PRINTF in modifiers) {
83 format_arg_index = (format_arg_index >= 0 ? format_arg_index + 1 : args_index);
84 writer.write_string (GNUC_PRINTF.printf (format_arg_index, args_index + 1));
85 } else if (CCodeModifiers.SCANF in modifiers) {
86 format_arg_index = (format_arg_index >= 0 ? format_arg_index + 1 : args_index);
87 writer.write_string (GNUC_SCANF.printf (format_arg_index, args_index + 1));
88 } else if (format_arg_index >= 0) {
89 writer.write_string (GNUC_FORMAT.printf (format_arg_index + 1));