source: mainline/uspace/app/sbi/src/rdata_t.h

Last change on this file was d1582b50, checked in by Jiri Svoboda <jiri@…>, 5 years ago

Fix spacing in single-line comments using latest ccheck

This found incorrectly formatted section comments (with blocks of
asterisks or dashes). I strongly believe against using section comments
but I am not simply removing them since that would probably be
controversial.

  • Property mode set to 100644
File size: 7.1 KB
Line 
1/*
2 * Copyright (c) 2011 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @file Run-time data representation. */
30
31#ifndef RDATA_T_H_
32#define RDATA_T_H_
33
34#include "intmap_t.h"
35
36/** Boolean variable. */
37typedef struct {
38 bool_t value;
39} rdata_bool_t;
40
41/** Character variable.
42 *
43 * Sysel character type should be able to store arbitrarily (or at least
44 * very) large character sets.
45 */
46typedef struct {
47 bigint_t value;
48} rdata_char_t;
49
50/** Integer variable.
51 *
52 * Sysel int type should be able to store arbitrarily (or at least
53 * very) large numbers.
54 */
55typedef struct {
56 bigint_t value;
57} rdata_int_t;
58
59/** String variable */
60typedef struct {
61 const char *value;
62} rdata_string_t;
63
64/** Reference variable */
65typedef struct {
66 struct rdata_var *vref;
67} rdata_ref_t;
68
69/** Delegate variable
70 *
71 * A delegate variable points to a static or non-static symbol. If the
72 * symbol is non static, @c obj points to the object the symbol
73 * belongs to.
74 */
75typedef struct {
76 /** Object or @c NULL if deleg. points to a static function. */
77 struct rdata_var *obj;
78
79 /** Member symbol. */
80 struct stree_symbol *sym;
81} rdata_deleg_t;
82
83/** Enumerated type value. */
84typedef struct {
85 /** Enum member declaration */
86 struct stree_embr *value;
87} rdata_enum_t;
88
89/** Array variable */
90typedef struct {
91 /** Rank */
92 int rank;
93
94 /** Extents (@c rank entries) */
95 int *extent;
96
97 /**
98 * Elements (extent[0] * extent[1] * ... extent[rank - 1] entries)
99 * stored in lexicographical order. Each element is (rdata_var_t *).
100 */
101 struct rdata_var **element;
102} rdata_array_t;
103
104/** Object variable */
105typedef struct {
106 /** Class of this object (symbol) */
107 struct stree_symbol *class_sym;
108
109 /** @c sn_static if this is a static object (i.e. class object) */
110 statns_t static_obj;
111
112 /** Map field name SID to field data */
113 intmap_t fields; /* of (rdata_var_t *) */
114} rdata_object_t;
115
116/** Resource handle
117 *
118 * Binding to external data. This type can be used to refer to data used
119 * by builtin functions (such as files).
120 */
121typedef struct {
122 /** Only understood by the right builtin function. */
123 void *data;
124} rdata_resource_t;
125
126/** Symbol reference variable
127 *
128 * A symbol reference points to a program symbol.
129 */
130typedef struct {
131 /** Program symbol. */
132 struct stree_symbol *sym;
133} rdata_symbol_t;
134
135typedef enum var_class {
136 /** Boolean */
137 vc_bool,
138
139 /** Character */
140 vc_char,
141
142 /** Integer */
143 vc_int,
144
145 /** String */
146 vc_string,
147
148 /** Reference */
149 vc_ref,
150
151 /** Delegate */
152 vc_deleg,
153
154 /** Enumerated type value */
155 vc_enum,
156
157 /** Array */
158 vc_array,
159
160 /** Object */
161 vc_object,
162
163 /** Interpreter builtin resource */
164 vc_resource,
165
166 /** Symbol reference */
167 vc_symbol
168} var_class_t;
169
170/** Variable.
171 *
172 * A piece of memory holding one of the basic types of data element.
173 * It is addressable (via rdata_var_t *) and mutable, at least from
174 * internal point of view of the interpreter.
175 */
176typedef struct rdata_var {
177 var_class_t vc;
178
179 union {
180 rdata_bool_t *bool_v;
181 rdata_char_t *char_v;
182 rdata_int_t *int_v;
183 rdata_string_t *string_v;
184 rdata_ref_t *ref_v;
185 rdata_deleg_t *deleg_v;
186 rdata_enum_t *enum_v;
187 rdata_array_t *array_v;
188 rdata_object_t *object_v;
189 rdata_resource_t *resource_v;
190 rdata_symbol_t *symbol_v;
191 } u;
192} rdata_var_t;
193
194/** Address class */
195typedef enum {
196 /** Variable address */
197 ac_var,
198
199 /** Property address */
200 ac_prop
201} address_class_t;
202
203/** Variable address */
204typedef struct {
205 /** Targeted variable */
206 rdata_var_t *vref;
207} rdata_addr_var_t;
208
209/** Named property address */
210typedef struct {
211 /** Delegate to the property */
212 rdata_deleg_t *prop_d;
213} rdata_aprop_named_t;
214
215/** Indexed property address */
216typedef struct {
217 /** Delegate to the object (or CSI) which is being indexed. */
218 rdata_deleg_t *object_d;
219
220 /** Arguments (indices) */
221 list_t args; /* of rdata_item_t */
222} rdata_aprop_indexed_t;
223
224typedef enum {
225 /* Named property address */
226 apc_named,
227
228 /* Indexed property address */
229 apc_indexed
230} aprop_class_t;
231
232/** Property address.
233 *
234 * When an access or index operation is performed on a property, the getter
235 * is run and the prefetched value is stored in @c tvalue. If the property
236 * is a non-scalar value type (a struct), then we might want to point to
237 * the proper @c var node inside it. @c tpos is used for this purpose.
238 *
239 * The assignment operator will modify @c tvalue and at the end the setter
240 * is called to store @c tvalue back into the property.
241 */
242typedef struct {
243 aprop_class_t apc;
244
245 /** Temporary copy of property value or @c NULL when not used. */
246 struct rdata_value *tvalue;
247
248 /**
249 * Points to the specific var node within @c tvalue that is addressed
250 * or @c NULL when @c tvalue is not used.
251 */
252 rdata_var_t *tpos;
253
254 union {
255 rdata_aprop_named_t *named;
256 rdata_aprop_indexed_t *indexed;
257 } u;
258} rdata_addr_prop_t;
259
260/** Address item */
261typedef struct rdata_address {
262 address_class_t ac;
263
264 union {
265 rdata_addr_var_t *var_a;
266 rdata_addr_prop_t *prop_a;
267 } u;
268} rdata_address_t;
269
270/** Value item. */
271typedef struct rdata_value {
272 /**
273 * Read-only Variable holding a copy of the data. Currently we don't
274 * allow sharing the same @c var node between different value nodes
275 * so that when destroying the value we can destroy the var.
276 *
277 * We could share this, but would need to reference-count it.
278 */
279 rdata_var_t *var;
280} rdata_value_t;
281
282typedef enum {
283 /** Address of a variable. */
284 ic_address,
285 /** Value */
286 ic_value
287} item_class_t;
288
289/** Data item.
290 *
291 * Data item is the result of evaluating an expression. An address expression
292 * yields an address item (a.k.a. L-value), a value expression yields a data
293 * item (a.k.a. R-value). This model is used to accomodate semantics of the
294 * assignment operator.
295 */
296typedef struct rdata_item {
297 item_class_t ic;
298
299 union {
300 rdata_address_t *address;
301 rdata_value_t *value;
302 } u;
303} rdata_item_t;
304
305#endif
Note: See TracBrowser for help on using the repository browser.