Changeset 94d484a in mainline for uspace/app/sbi/src/rdata.c
- Timestamp:
- 2010-03-07T17:45:33Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d0febca
- Parents:
- fa36f29
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/rdata.c
rfa36f29 r94d484a 32 32 #include <assert.h> 33 33 #include "mytypes.h" 34 #include "stree.h" 34 35 35 36 #include "rdata.h" … … 39 40 static void rdata_ref_copy(rdata_ref_t *src, rdata_ref_t **dest); 40 41 static void rdata_deleg_copy(rdata_deleg_t *src, rdata_deleg_t **dest); 42 static void rdata_array_copy(rdata_array_t *src, rdata_array_t **dest); 41 43 static void rdata_object_copy(rdata_object_t *src, rdata_object_t **dest); 44 45 static int rdata_array_get_dim(rdata_array_t *array); 42 46 43 47 static void rdata_address_print(rdata_address_t *address); … … 126 130 } 127 131 132 rdata_array_t *rdata_array_new(int rank) 133 { 134 rdata_array_t *array; 135 136 array = calloc(1, sizeof(rdata_array_t)); 137 if (array == NULL) { 138 printf("Memory allocation failed.\n"); 139 exit(1); 140 } 141 142 array->rank = rank; 143 array->extent = calloc(rank, sizeof(int)); 144 if (array == NULL) { 145 printf("Memory allocation failed.\n"); 146 exit(1); 147 } 148 149 return array; 150 } 151 128 152 rdata_object_t *rdata_object_new(void) 129 153 { … … 163 187 164 188 return string_v; 189 } 190 191 rdata_titem_t *rdata_titem_new(titem_class_t tic) 192 { 193 rdata_titem_t *titem; 194 195 titem = calloc(1, sizeof(rdata_titem_t)); 196 if (titem == NULL) { 197 printf("Memory allocation failed.\n"); 198 exit(1); 199 } 200 201 titem->tic = tic; 202 return titem; 203 } 204 205 rdata_tarray_t *rdata_tarray_new(void) 206 { 207 rdata_tarray_t *tarray; 208 209 tarray = calloc(1, sizeof(rdata_tarray_t)); 210 if (tarray == NULL) { 211 printf("Memory allocation failed.\n"); 212 exit(1); 213 } 214 215 return tarray; 216 } 217 218 rdata_tcsi_t *rdata_tcsi_new(void) 219 { 220 rdata_tcsi_t *tcsi; 221 222 tcsi = calloc(1, sizeof(rdata_tcsi_t)); 223 if (tcsi == NULL) { 224 printf("Memory allocation failed.\n"); 225 exit(1); 226 } 227 228 return tcsi; 229 } 230 231 rdata_tprimitive_t *rdata_tprimitive_new(void) 232 { 233 rdata_tprimitive_t *tprimitive; 234 235 tprimitive = calloc(1, sizeof(rdata_tprimitive_t)); 236 if (tprimitive == NULL) { 237 printf("Memory allocation failed.\n"); 238 exit(1); 239 } 240 241 return tprimitive; 242 } 243 244 void rdata_array_alloc_element(rdata_array_t *array) 245 { 246 int dim, idx; 247 248 dim = rdata_array_get_dim(array); 249 250 array->element = calloc(dim, sizeof(rdata_var_t *)); 251 if (array->element == NULL) { 252 printf("Memory allocation failed.\n"); 253 exit(1); 254 } 255 256 for (idx = 0; idx < dim; ++idx) { 257 array->element[idx] = calloc(1, sizeof(rdata_var_t)); 258 if (array->element[idx] == NULL) { 259 printf("Memory allocation failed.\n"); 260 exit(1); 261 } 262 } 263 } 264 265 /** Get array dimension. 266 * 267 * Dimension is the total number of elements in an array, in other words, 268 * the product of all extents. 269 */ 270 static int rdata_array_get_dim(rdata_array_t *array) 271 { 272 int didx, dim; 273 274 dim = 1; 275 for (didx = 0; didx < array->rank; ++didx) 276 dim = dim * array->extent[didx]; 277 278 return dim; 165 279 } 166 280 … … 185 299 rdata_deleg_copy(src->u.deleg_v, &nvar->u.deleg_v); 186 300 break; 301 case vc_array: 302 rdata_array_copy(src->u.array_v, &nvar->u.array_v); 303 break; 187 304 case vc_object: 188 305 rdata_object_copy(src->u.object_v, &nvar->u.object_v); … … 215 332 (void) src; (void) dest; 216 333 printf("Unimplemented: Copy delegate.\n"); 334 exit(1); 335 } 336 337 static void rdata_array_copy(rdata_array_t *src, rdata_array_t **dest) 338 { 339 (void) src; (void) dest; 340 printf("Unimplemented: Copy array.\n"); 217 341 exit(1); 218 342 } … … 339 463 void rdata_address_write(rdata_address_t *address, rdata_value_t *value) 340 464 { 465 rdata_var_write(address->vref, value); 466 } 467 468 /** Write data to a variable. 469 * 470 * Store @a value to variable @a var. 471 */ 472 void rdata_var_write(rdata_var_t *var, rdata_value_t *value) 473 { 341 474 rdata_var_t *nvar; 342 rdata_var_t *orig_var;343 475 344 476 /* Perform a shallow copy of @c value->var. */ 345 477 rdata_var_copy(value->var, &nvar); 346 orig_var = address->vref;347 478 348 479 /* XXX do this in a prettier way. */ 349 480 350 orig_var->vc = nvar->vc;481 var->vc = nvar->vc; 351 482 switch (nvar->vc) { 352 case vc_int: orig_var->u.int_v = nvar->u.int_v; break; 353 case vc_ref: orig_var->u.ref_v = nvar->u.ref_v; break; 354 case vc_deleg: orig_var->u.deleg_v = nvar->u.deleg_v; break; 355 case vc_object: orig_var->u.object_v = nvar->u.object_v; break; 356 default: assert(b_false); 483 case vc_int: var->u.int_v = nvar->u.int_v; break; 484 case vc_string: var->u.string_v = nvar->u.string_v; break; 485 case vc_ref: var->u.ref_v = nvar->u.ref_v; break; 486 case vc_deleg: var->u.deleg_v = nvar->u.deleg_v; break; 487 case vc_array: var->u.array_v = nvar->u.array_v; break; 488 case vc_object: var->u.object_v = nvar->u.object_v; break; 357 489 } 358 490 359 491 /* XXX We should free some stuff around here. */ 492 } 493 494 /** Determine if CSI @a a is derived from CSI described by type item @a tb. */ 495 bool_t rdata_is_csi_derived_from_ti(stree_csi_t *a, rdata_titem_t *tb) 496 { 497 bool_t res; 498 499 switch (tb->tic) { 500 case tic_tcsi: 501 res = stree_is_csi_derived_from_csi(a, tb->u.tcsi->csi); 502 break; 503 default: 504 printf("Error: Base type is not a CSI.\n"); 505 exit(1); 506 } 507 508 return res; 360 509 } 361 510
Note:
See TracChangeset
for help on using the changeset viewer.