valaccodefunctioncall.vala 2 KB
Newer Older
1 2
/* valaccodefunctioncall.vala
 *
3
 * Copyright (C) 2006-2007  Jürg Billeter
4 5 6 7
 *
 * 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
8
 * version 2.1 of the License, or (at your option) any later version.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

 * 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>
 */

using GLib;

25 26 27 28 29 30 31
/**
 * Represents a function call in the C code.
 */
public class Vala.CCodeFunctionCall : CCodeExpression {
	/**
	 * The function to be called.
	 */
32
	public CCodeExpression? call { get; set; }
33

34
	private List<CCodeExpression> arguments = new ArrayList<CCodeExpression> ();
35

36
	public CCodeFunctionCall (CCodeExpression? call = null) {
37
		this.call = call;
38
	}
39

40 41 42 43 44
	/**
	 * Appends the specified expression to the list of arguments.
	 *
	 * @param expr a C code expression
	 */
45
	public void add_argument (CCodeExpression expr) {
46
		arguments.add (expr);
47
	}
48

49 50 51 52
	public void insert_argument (int index, CCodeExpression expr) {
		arguments.insert (index, expr);
	}

53 54 55 56 57
	/**
	 * Returns a copy of the list of arguments.
	 *
	 * @return list of arguments
	 */
58
	public List<CCodeExpression> get_arguments () {
59
		return arguments;
60 61
	}

62
	public override void write (CCodeWriter writer) {
63
		call.write_inner (writer);
64
		writer.write_string (" (");
65

66 67 68 69 70 71 72
		bool first = true;
		foreach (CCodeExpression expr in arguments) {
			if (!first) {
				writer.write_string (", ");
			} else {
				first = false;
			}
73

74 75
			if (expr != null) {
				expr.write (writer);
76 77
			}
		}
78 79

		writer.write_string (")");
80 81
	}
}