change run to use meson/ninja and then exec. - remove libvala code from application...
[roobuilder] / src / codegen / valaglibvalue.vala
1 /* valaglibvalue.vala
2  *
3  * Copyright (C) 2010  Jürg Billeter
4  * Copyright (C) 2011  Luca Bruno
5  *
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.
10
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.
15
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
19  *
20  * Author:
21  *      Jürg Billeter <j@bitron.ch>
22  *      Luca Bruno <lucabru@src.gnome.org>
23  */
24
25 public class Vala.GLibValue : TargetValue {
26         public CCodeExpression cvalue;
27         public bool lvalue;
28         public bool non_null;
29         public string? ctype;
30
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;
35
36         public CCodeExpression? delegate_target_cvalue;
37         public CCodeExpression? delegate_target_destroy_notify_cvalue;
38
39         public GLibValue (DataType? value_type = null, CCodeExpression? cvalue = null, bool lvalue = false) {
40                 base (value_type);
41                 this.cvalue = cvalue;
42                 this.lvalue = lvalue;
43         }
44
45         public void append_array_length_cvalue (CCodeExpression length_cvalue) {
46                 if (array_length_cvalues == null) {
47                         array_length_cvalues = new ArrayList<CCodeExpression> ();
48                 }
49                 array_length_cvalues.add (length_cvalue);
50         }
51
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;
56                 result.ctype = ctype;
57
58                 if (array_length_cvalues != null) {
59                         foreach (var cexpr in array_length_cvalues) {
60                                 result.append_array_length_cvalue (cexpr);
61                         }
62                 }
63                 result.array_size_cvalue = array_size_cvalue;
64                 result.array_null_terminated = array_null_terminated;
65                 result.array_length_cexpr = array_length_cexpr;
66
67                 result.delegate_target_cvalue = delegate_target_cvalue;
68                 result.delegate_target_destroy_notify_cvalue = delegate_target_destroy_notify_cvalue;
69
70                 return result;
71         }
72 }
73
74 namespace Vala {
75         public static unowned CCodeExpression? get_cvalue (Expression expr) {
76                 if (expr.target_value == null) {
77                         return null;
78                 }
79                 return ((GLibValue) expr.target_value).cvalue;
80         }
81
82         public static unowned CCodeExpression? get_cvalue_ (TargetValue value) {
83                 return ((GLibValue) value).cvalue;
84         }
85
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;
91                 }
92                 glib_value.cvalue = cvalue;
93         }
94
95         public static unowned CCodeExpression? get_array_size_cvalue (TargetValue value) {
96                 return ((GLibValue) value).array_size_cvalue;
97         }
98
99         public static void set_array_size_cvalue (TargetValue value, CCodeExpression? cvalue) {
100                 ((GLibValue) value).array_size_cvalue = cvalue;
101         }
102
103         public static unowned CCodeExpression? get_delegate_target (Expression expr) {
104                 if (expr.target_value == null) {
105                         return null;
106                 }
107                 return ((GLibValue) expr.target_value).delegate_target_cvalue;
108         }
109
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;
115                 }
116                 glib_value.delegate_target_cvalue = delegate_target;
117         }
118
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) {
122                         return null;
123                 }
124                 return glib_value.delegate_target_destroy_notify_cvalue;
125         }
126
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;
132                 }
133                 glib_value.delegate_target_destroy_notify_cvalue = destroy_notify;
134         }
135
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;
141                 }
142                 glib_value.append_array_length_cvalue (size);
143         }
144
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;
150                 } else {
151                         glib_value.array_length_cvalues = null;
152                 }
153                 glib_value.append_array_length_cvalue (size);
154         }
155
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) {
159                         return null;
160                 }
161                 return glib_value.array_length_cvalues;
162         }
163
164         public static bool get_lvalue (TargetValue value) {
165                 return ((GLibValue) value).lvalue;
166         }
167
168         public static bool get_non_null (TargetValue value) {
169                 return ((GLibValue) value).non_null;
170         }
171
172         public static unowned string? get_ctype (TargetValue value) {
173                 return ((GLibValue) value).ctype;
174         }
175
176         public static bool get_array_null_terminated (TargetValue value) {
177                 return ((GLibValue) value).array_null_terminated;
178         }
179
180         public static unowned CCodeExpression? get_array_length_cexpr (TargetValue value) {
181                 return ((GLibValue) value).array_length_cexpr;
182         }
183 }