gtk+-3.0: Drop sealed fields
[vala-lang.git] / ccode / valaccodevariabledeclarator.vala
blob8203d574c39f4a041a6426c5d1f8ef7c6504ab23
1 /* valaccodevariabledeclarator.vala
3 * Copyright (C) 2006-2009 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 variable declarator in the C code.
28 public class Vala.CCodeVariableDeclarator : CCodeDeclarator {
29 /**
30 * The variable name.
32 public string name { get; set; }
34 /**
35 * The optional initializer expression.
37 public CCodeExpression? initializer { get; set; }
39 /**
40 * The optional declarator suffix.
42 public string? declarator_suffix { get; set; }
44 /**
45 * Initializer only used to zero memory, safe to initialize as part
46 * of declaration at beginning of block instead of separate assignment.
48 public bool init0 { get; set; }
50 public CCodeVariableDeclarator (string name, CCodeExpression? initializer = null, string? declarator_suffix = null) {
51 this.name = name;
52 this.initializer = initializer;
53 this.declarator_suffix = declarator_suffix;
56 public CCodeVariableDeclarator.zero (string name, CCodeExpression initializer, string? declarator_suffix = null) {
57 this.name = name;
58 this.initializer = initializer;
59 this.declarator_suffix = declarator_suffix;
60 this.init0 = true;
63 public override void write (CCodeWriter writer) {
64 writer.write_string (name);
65 if (declarator_suffix != null) {
66 writer.write_string (declarator_suffix);
69 if (initializer != null) {
70 writer.write_string (" = ");
71 initializer.write (writer);
75 public override void write_declaration (CCodeWriter writer) {
76 writer.write_string (name);
77 if (declarator_suffix != null) {
78 writer.write_string (declarator_suffix);
81 if (initializer != null && init0) {
82 writer.write_string (" = ");
83 initializer.write (writer);
87 public override void write_initialization (CCodeWriter writer) {
88 if (initializer != null && !init0) {
89 writer.write_indent (line);
91 writer.write_string (name);
92 writer.write_string (" = ");
93 initializer.write (writer);
95 writer.write_string (";");
96 writer.write_newline ();