codegen: Fix freeing of owned parameters
[vala-lang.git] / vala / valavariable.vala
blob56cb1aed4a4ee96d79ffbcbefae5e96fe7ffc256
1 /* valavariable.vala
3 * Copyright (C) 2010 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 public class Vala.Variable : Symbol {
24 /**
25 * The optional initializer expression.
27 public Expression? initializer {
28 get {
29 return _initializer;
31 set {
32 _initializer = value;
33 if (_initializer != null) {
34 _initializer.parent_node = this;
39 /**
40 * The variable type.
42 public DataType? variable_type {
43 get { return _variable_type; }
44 set {
45 _variable_type = value;
46 if (_variable_type != null) {
47 _variable_type.parent_node = this;
52 /**
53 * Specifies whether an array length field should implicitly be created
54 * if the field type is an array.
56 public bool no_array_length { get; set; }
58 /**
59 * Specifies whether a delegate target field should implicitly be created
60 * if the field type is a delegate.
62 public bool no_delegate_target { get; set; }
64 /**
65 * Specifies whether the array is null terminated.
67 public bool array_null_terminated { get; set; }
69 /**
70 * Specifies whether the array length field uses a custom name in C.
72 public bool has_array_length_cname {
73 get { return (array_length_cname != null); }
76 /**
77 * Specifies whether the array uses a custom C expression as length.
79 public bool has_array_length_cexpr {
80 get { return (array_length_cexpr != null); }
83 /**
84 * Specifies a custom type for the array length.
86 public string? array_length_type { get; set; default = null; }
88 Expression? _initializer;
89 DataType? _variable_type;
91 private string? array_length_cname;
93 private string? array_length_cexpr;
95 public Variable (DataType? variable_type, string? name, Expression? initializer = null, SourceReference? source_reference = null, Comment? comment = null) {
96 base (name, source_reference, comment);
97 this.variable_type = variable_type;
98 this.initializer = initializer;
102 * Returns the name of the array length variable as it is used in C code
104 * @return the name of the array length variable to be used in C code
106 public string? get_array_length_cname () {
107 return this.array_length_cname;
111 * Sets the name of the array length variable as it is used in C code
113 * @param array_length_cname the name of the array length variable to be
114 * used in C code
116 public void set_array_length_cname (string? array_length_cname) {
117 this.array_length_cname = array_length_cname;
121 * Returns the array length expression as it is used in C code
123 * @return the array length expression to be used in C code
125 public string? get_array_length_cexpr () {
126 return this.array_length_cexpr;
131 * Sets the array length expression as it is used in C code
133 * @param array_length_cexpr the array length expression to be used in C
134 * code
136 public void set_array_length_cexpr (string? array_length_cexpr) {
137 this.array_length_cexpr = array_length_cexpr;
140 void process_ccode_attribute (Attribute a) {
141 if (a.has_argument ("array_length")) {
142 no_array_length = !a.get_bool ("array_length");
144 if (a.has_argument ("array_null_terminated")) {
145 array_null_terminated = a.get_bool ("array_null_terminated");
147 if (a.has_argument ("array_length_cname")) {
148 set_array_length_cname (a.get_string ("array_length_cname"));
150 if (a.has_argument ("array_length_cexpr")) {
151 set_array_length_cexpr (a.get_string ("array_length_cexpr"));
153 if (a.has_argument ("array_length_type")) {
154 array_length_type = a.get_string ("array_length_type");
156 if (a.has_argument ("delegate_target")) {
157 no_delegate_target = !a.get_bool ("delegate_target");
162 * Process all associated attributes.
164 public virtual void process_attributes () {
165 foreach (Attribute a in attributes) {
166 if (a.name == "CCode") {
167 process_ccode_attribute (a);