3 * Copyright (C) 2010 Jürg Billeter
4 * Copyright (C) 2011 Luca Bruno
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 * Jürg Billeter <j@bitron.ch>
22 * Luca Bruno <lucabru@src.gnome.org>
25 public class Vala.GLibValue : TargetValue {
26 public CCodeExpression cvalue;
31 public List<CCodeExpression> array_length_cvalues;
32 public CCodeExpression? array_size_cvalue;
33 public bool array_null_terminated;
34 public CCodeExpression? array_length_cexpr;
36 public CCodeExpression? delegate_target_cvalue;
37 public CCodeExpression? delegate_target_destroy_notify_cvalue;
39 public GLibValue (DataType? value_type = null, CCodeExpression? cvalue = null, bool lvalue = false) {
45 public void append_array_length_cvalue (CCodeExpression length_cvalue) {
46 if (array_length_cvalues == null) {
47 array_length_cvalues = new ArrayList<CCodeExpression> ();
49 array_length_cvalues.add (length_cvalue);
52 public GLibValue copy () {
53 var result = new GLibValue (value_type.copy (), cvalue, lvalue);
54 result.actual_value_type = actual_value_type;
55 result.non_null = non_null;
58 if (array_length_cvalues != null) {
59 foreach (var cexpr in array_length_cvalues) {
60 result.append_array_length_cvalue (cexpr);
63 result.array_size_cvalue = array_size_cvalue;
64 result.array_null_terminated = array_null_terminated;
65 result.array_length_cexpr = array_length_cexpr;
67 result.delegate_target_cvalue = delegate_target_cvalue;
68 result.delegate_target_destroy_notify_cvalue = delegate_target_destroy_notify_cvalue;
75 public static unowned CCodeExpression? get_cvalue (Expression expr) {
76 if (expr.target_value == null) {
79 return ((GLibValue) expr.target_value).cvalue;
82 public static unowned CCodeExpression? get_cvalue_ (TargetValue value) {
83 return ((GLibValue) value).cvalue;
86 public static void set_cvalue (Expression expr, CCodeExpression? cvalue) {
87 unowned GLibValue glib_value = (GLibValue) expr.target_value;
88 if (glib_value == null) {
89 expr.target_value = new GLibValue (expr.value_type);
90 glib_value = (GLibValue) expr.target_value;
92 glib_value.cvalue = cvalue;
95 public static unowned CCodeExpression? get_array_size_cvalue (TargetValue value) {
96 return ((GLibValue) value).array_size_cvalue;
99 public static void set_array_size_cvalue (TargetValue value, CCodeExpression? cvalue) {
100 ((GLibValue) value).array_size_cvalue = cvalue;
103 public static unowned CCodeExpression? get_delegate_target (Expression expr) {
104 if (expr.target_value == null) {
107 return ((GLibValue) expr.target_value).delegate_target_cvalue;
110 public static void set_delegate_target (Expression expr, CCodeExpression? delegate_target) {
111 unowned GLibValue? glib_value = (GLibValue) expr.target_value;
112 if (glib_value == null) {
113 expr.target_value = new GLibValue (expr.value_type);
114 glib_value = (GLibValue) expr.target_value;
116 glib_value.delegate_target_cvalue = delegate_target;
119 public static unowned CCodeExpression? get_delegate_target_destroy_notify (Expression expr) {
120 unowned GLibValue? glib_value = (GLibValue) expr.target_value;
121 if (glib_value == null) {
124 return glib_value.delegate_target_destroy_notify_cvalue;
127 public static void set_delegate_target_destroy_notify (Expression expr, CCodeExpression? destroy_notify) {
128 unowned GLibValue? glib_value = (GLibValue) expr.target_value;
129 if (glib_value == null) {
130 expr.target_value = new GLibValue (expr.value_type);
131 glib_value = (GLibValue) expr.target_value;
133 glib_value.delegate_target_destroy_notify_cvalue = destroy_notify;
136 public static void append_array_length (Expression expr, CCodeExpression size) {
137 unowned GLibValue? glib_value = (GLibValue) expr.target_value;
138 if (glib_value == null) {
139 expr.target_value = new GLibValue (expr.value_type);
140 glib_value = (GLibValue) expr.target_value;
142 glib_value.append_array_length_cvalue (size);
145 public static void set_array_length (Expression expr, CCodeExpression size) {
146 unowned GLibValue? glib_value = (GLibValue) expr.target_value;
147 if (glib_value == null) {
148 expr.target_value = new GLibValue (expr.value_type);
149 glib_value = (GLibValue) expr.target_value;
151 glib_value.array_length_cvalues = null;
153 glib_value.append_array_length_cvalue (size);
156 public static unowned List<CCodeExpression>? get_array_lengths (Expression expr) {
157 unowned GLibValue? glib_value = (GLibValue) expr.target_value;
158 if (glib_value == null) {
161 return glib_value.array_length_cvalues;
164 public static bool get_lvalue (TargetValue value) {
165 return ((GLibValue) value).lvalue;
168 public static bool get_non_null (TargetValue value) {
169 return ((GLibValue) value).non_null;
172 public static unowned string? get_ctype (TargetValue value) {
173 return ((GLibValue) value).ctype;
176 public static bool get_array_null_terminated (TargetValue value) {
177 return ((GLibValue) value).array_null_terminated;
180 public static unowned CCodeExpression? get_array_length_cexpr (TargetValue value) {
181 return ((GLibValue) value).array_length_cexpr;