Changeset 23de644 in mainline for uspace/app/sbi/src/rdata.c
- Timestamp:
- 2010-04-04T22:31:01Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 074444f, ecb6ac32
- Parents:
- 3aae4e8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/rdata.c
r3aae4e8 r23de644 27 27 */ 28 28 29 /** @file Run-time data representation. */ 29 /** @file Run-time data representation. 30 * 31 * At run time SBI represents all data as a graph of interconnected @c var 32 * nodes (variable nodes). Any piece of memory addressable by the program 33 * (i.e. all variables) are stored in var nodes. However, var nodes are also 34 * used internally to implement value items. (I.e. values in value items 35 * have exactly the same structure as program variables). 36 * 37 * Unlike byte- or word-oriented memory on a real machine, var nodes provide 38 * structured and typed storage. (This typing is dynamic, however and has 39 * nothing to do with the static type system). 40 * 41 * There are several types of var nodes, one for each primitive type, 42 * reference, delegate, array, and object. A reference var node contains 43 * a pointer to another var node. Delegate var node points to some stree 44 * declaration. Array and object var nodes refer to a collection of child 45 * nodes (fields, elements). 46 */ 30 47 31 48 #include <stdlib.h> 32 49 #include <assert.h> 50 #include "bigint.h" 33 51 #include "mytypes.h" 34 52 #include "stree.h" … … 50 68 static void rdata_var_print(rdata_var_t *var); 51 69 52 70 /** Allocate new data item. 71 * 72 * @param ic Item class. 73 * @return New item. 74 */ 53 75 rdata_item_t *rdata_item_new(item_class_t ic) 54 76 { … … 65 87 } 66 88 89 /** Allocate new address. 90 * 91 * @return New address. 92 */ 67 93 rdata_addr_var_t *rdata_addr_var_new(void) 68 94 { … … 78 104 } 79 105 106 /** Allocate new named property address. 107 * 108 * @return New named property address. 109 */ 80 110 rdata_aprop_named_t *rdata_aprop_named_new(void) 81 111 { … … 91 121 } 92 122 123 /** Allocate new indexed property address. 124 * 125 * @return New indexed property address. 126 */ 93 127 rdata_aprop_indexed_t *rdata_aprop_indexed_new(void) 94 128 { … … 104 138 } 105 139 140 /** Allocate new property address. 141 * 142 * @param apc Property address class. 143 * @return New property address. 144 */ 106 145 rdata_addr_prop_t *rdata_addr_prop_new(aprop_class_t apc) 107 146 { … … 118 157 } 119 158 159 /** Allocate new address. 160 * 161 * @param ac Address class. 162 * @return New address. 163 */ 120 164 rdata_address_t *rdata_address_new(address_class_t ac) 121 165 { … … 132 176 } 133 177 178 /** Allocate new value. 179 * 180 * @return New value. 181 */ 134 182 rdata_value_t *rdata_value_new(void) 135 183 { … … 145 193 } 146 194 195 /** Allocate new var node. 196 * 197 * @param vc Var node class (varclass). 198 * @return New var node. 199 */ 147 200 rdata_var_t *rdata_var_new(var_class_t vc) 148 201 { … … 159 212 } 160 213 214 /** Allocate new reference. 215 * 216 * @return New reference. 217 */ 161 218 rdata_ref_t *rdata_ref_new(void) 162 219 { … … 172 229 } 173 230 231 /** Allocate new delegate. 232 * 233 * @return New delegate. 234 */ 174 235 rdata_deleg_t *rdata_deleg_new(void) 175 236 { … … 185 246 } 186 247 248 /** Allocate new array. 249 * 250 * @return New array. 251 */ 187 252 rdata_array_t *rdata_array_new(int rank) 188 253 { … … 205 270 } 206 271 272 /** Allocate new object. 273 * 274 * @return New object. 275 */ 207 276 rdata_object_t *rdata_object_new(void) 208 277 { … … 218 287 } 219 288 289 /** Allocate new integer. 290 * 291 * @return New integer. 292 */ 220 293 rdata_int_t *rdata_int_new(void) 221 294 { … … 231 304 } 232 305 306 /** Allocate new string. 307 * 308 * @return New string. 309 */ 233 310 rdata_string_t *rdata_string_new(void) 234 311 { … … 244 321 } 245 322 323 /** Allocate new resource. 324 * 325 * @return New resource. 326 */ 246 327 rdata_resource_t *rdata_resource_new(void) 247 328 { … … 257 338 } 258 339 340 /** Allocate array elements. 341 * 342 * Allocates var nodes for elements of @a array. 343 * 344 * @param array Array. 345 */ 259 346 void rdata_array_alloc_element(rdata_array_t *array) 260 347 { … … 282 369 * Dimension is the total number of elements in an array, in other words, 283 370 * the product of all extents. 371 * 372 * @param array Array. 284 373 */ 285 374 static int rdata_array_get_dim(rdata_array_t *array) … … 294 383 } 295 384 296 /** Make copy of a variable. */ 385 /** Make copy of a variable. 386 * 387 * Creates a new var node that is an exact copy of an existing var node. 388 * This can be thought of as a shallow copy. 389 * 390 * @param src Source var node. 391 * @param dest Place to store pointer to new var node. 392 */ 297 393 void rdata_var_copy(rdata_var_t *src, rdata_var_t **dest) 298 394 { … … 328 424 } 329 425 426 /** Copy integer. 427 * 428 * @param src Source integer. 429 * @param dest Place to store pointer to new integer. 430 */ 330 431 static void rdata_int_copy(rdata_int_t *src, rdata_int_t **dest) 331 432 { 332 433 *dest = rdata_int_new(); 333 (*dest)->value = src->value; 334 } 335 434 bigint_clone(&src->value, &(*dest)->value); 435 } 436 437 /** Copy string. 438 * 439 * @param src Source string. 440 * @param dest Place to store pointer to new string. 441 */ 336 442 static void rdata_string_copy(rdata_string_t *src, rdata_string_t **dest) 337 443 { … … 340 446 } 341 447 448 /** Copy reference. 449 * 450 * @param src Source reference. 451 * @param dest Place to store pointer to new reference. 452 */ 342 453 static void rdata_ref_copy(rdata_ref_t *src, rdata_ref_t **dest) 343 454 { … … 346 457 } 347 458 459 /** Copy delegate. 460 * 461 * @param src Source delegate. 462 * @param dest Place to store pointer to new delegate. 463 */ 348 464 static void rdata_deleg_copy(rdata_deleg_t *src, rdata_deleg_t **dest) 349 465 { … … 353 469 } 354 470 471 /** Copy array. 472 * 473 * @param src Source array. 474 * @param dest Place to store pointer to new array. 475 */ 355 476 static void rdata_array_copy(rdata_array_t *src, rdata_array_t **dest) 356 477 { … … 360 481 } 361 482 483 /** Copy object. 484 * 485 * @param src Source object. 486 * @param dest Place to store pointer to new object. 487 */ 362 488 static void rdata_object_copy(rdata_object_t *src, rdata_object_t **dest) 363 489 { … … 367 493 } 368 494 495 /** Copy resource. 496 * 497 * @param src Source resource. 498 * @param dest Place to store pointer to new resource. 499 */ 369 500 static void rdata_resource_copy(rdata_resource_t *src, rdata_resource_t **dest) 370 501 { … … 375 506 /** Read data from a variable. 376 507 * 377 * Return value stored in variable @a var. 508 * This copies data from the variable to a value item. Ideally any read access 509 * to a program variable should go through this function. (Keep in mind 510 * that although values are composed of var nodes internally, but are not 511 * variables per se. Therefore this function is not used to read from values) 512 * 513 * @param var Variable to read from (var node where it is stored). 514 * @param ritem Place to store pointer to new value item read from 515 * the variable. 378 516 */ 379 517 void rdata_var_read(rdata_var_t *var, rdata_item_t **ritem) … … 393 531 /** Write data to a variable. 394 532 * 395 * Store @a value to variable @a var. 533 * This copies data to the variable from a value. Ideally any write access 534 * to a program variable should go through this function. (Keep in mind 535 * that even though values are composed of var nodes internally, but are not 536 * variables per se. Therefore this function is not used to write to values) 537 * 538 * @param var Variable to write to (var node where it is stored). 539 * @param value The value to write. 396 540 */ 397 541 void rdata_var_write(rdata_var_t *var, rdata_value_t *value) … … 418 562 } 419 563 564 /** Print data item in human-readable form. 565 * 566 * @param item Item to print. 567 */ 420 568 void rdata_item_print(rdata_item_t *item) 421 569 { … … 437 585 } 438 586 587 /** Print address in human-readable form. 588 * 589 * Actually this displays contents of the var node that is being addressed. 590 * 591 * XXX Maybe we should really rather print the address and not the data 592 * it is pointing to? 593 * 594 * @param item Address to print. 595 */ 439 596 static void rdata_address_print(rdata_address_t *address) 440 597 { … … 449 606 } 450 607 608 /** Print value in human-readable form. 609 * 610 * @param value Value to print. 611 */ 451 612 void rdata_value_print(rdata_value_t *value) 452 613 { … … 454 615 } 455 616 617 /** Print contents of var node in human-readable form. 618 * 619 * @param item Var node to print. 620 */ 456 621 static void rdata_var_print(rdata_var_t *var) 457 622 { 458 623 switch (var->vc) { 459 624 case vc_int: 460 printf("int(%d)", var->u.int_v->value); 625 printf("int("); 626 bigint_print(&var->u.int_v->value); 627 printf(")"); 461 628 break; 462 629 case vc_string:
Note:
See TracChangeset
for help on using the changeset viewer.