D-Bus: Fix get_proxy.begin calls
[vala-lang.git] / ccode / valaccodeblock.vala
blob5c8f2c74d16625e6d26ffbab7ad13127415b79e4
1 /* valaccodeblock.vala
3 * Copyright (C) 2006-2008 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;
25 /**
26 * Represents a C code block.
28 public class Vala.CCodeBlock : CCodeStatement {
29 /**
30 * Specifies whether a newline at the end of the block should be
31 * suppressed.
33 public bool suppress_newline { get; set; }
35 private List<CCodeNode> statements = new ArrayList<CCodeNode> ();
37 /**
38 * Prepend the specified statement to the list of statements.
40 public void prepend_statement (CCodeNode statement) {
41 statements.insert (0, statement);
44 /**
45 * Append the specified statement to the list of statements.
47 public void add_statement (CCodeNode statement) {
48 /* allow generic nodes to include comments */
49 statements.add (statement);
52 public override void write (CCodeWriter writer) {
53 // the last reachable statement
54 CCodeNode last_statement = null;
56 writer.write_begin_block ();
57 foreach (CCodeNode statement in statements) {
58 statement.write_declaration (writer);
60 // determine last reachable statement
61 if (statement is CCodeLabel || statement is CCodeCaseStatement) {
62 last_statement = null;
63 } else if (statement is CCodeReturnStatement || statement is CCodeGotoStatement
64 || statement is CCodeContinueStatement || statement is CCodeBreakStatement) {
65 last_statement = statement;
69 foreach (CCodeNode statement in statements) {
70 statement.write (writer);
72 // only output reachable code
73 if (statement == last_statement) {
74 break;
78 writer.write_end_block ();
80 if (!suppress_newline) {
81 writer.write_newline ();