00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00048 #include <stdlib.h>
00049 #include <assert.h>
00050 #include "bigint.h"
00051 #include "list.h"
00052 #include "mytypes.h"
00053 #include "stree.h"
00054 #include "symbol.h"
00055 #include "strtab.h"
00056
00057 #include "rdata.h"
00058
00059 static void rdata_bool_copy(rdata_bool_t *src, rdata_bool_t **dest);
00060 static void rdata_char_copy(rdata_char_t *src, rdata_char_t **dest);
00061 static void rdata_int_copy(rdata_int_t *src, rdata_int_t **dest);
00062 static void rdata_string_copy(rdata_string_t *src, rdata_string_t **dest);
00063 static void rdata_ref_copy(rdata_ref_t *src, rdata_ref_t **dest);
00064 static void rdata_deleg_copy(rdata_deleg_t *src, rdata_deleg_t **dest);
00065 static void rdata_enum_copy(rdata_enum_t *src, rdata_enum_t **dest);
00066 static void rdata_array_copy(rdata_array_t *src, rdata_array_t **dest);
00067 static void rdata_object_copy(rdata_object_t *src, rdata_object_t **dest);
00068 static void rdata_resource_copy(rdata_resource_t *src,
00069 rdata_resource_t **dest);
00070 static void rdata_symbol_copy(rdata_symbol_t *src, rdata_symbol_t **dest);
00071
00072 static void rdata_var_destroy_inner(rdata_var_t *var);
00073
00074 static void rdata_bool_destroy(rdata_bool_t *bool_v);
00075 static void rdata_char_destroy(rdata_char_t *char_v);
00076 static void rdata_int_destroy(rdata_int_t *int_v);
00077 static void rdata_string_destroy(rdata_string_t *string_v);
00078 static void rdata_ref_destroy(rdata_ref_t *ref_v);
00079 static void rdata_deleg_destroy(rdata_deleg_t *deleg_v);
00080 static void rdata_enum_destroy(rdata_enum_t *enum_v);
00081 static void rdata_array_destroy(rdata_array_t *array_v);
00082 static void rdata_object_destroy(rdata_object_t *object_v);
00083 static void rdata_resource_destroy(rdata_resource_t *resource_v);
00084 static void rdata_symbol_destroy(rdata_symbol_t *symbol_v);
00085
00086 static int rdata_array_get_dim(rdata_array_t *array);
00087 static void rdata_var_copy_to(rdata_var_t *src, rdata_var_t *dest);
00088
00089 static void rdata_address_print(rdata_address_t *address);
00090 static void rdata_var_print(rdata_var_t *var);
00091
00097 rdata_item_t *rdata_item_new(item_class_t ic)
00098 {
00099 rdata_item_t *item;
00100
00101 item = calloc(1, sizeof(rdata_item_t));
00102 if (item == NULL) {
00103 printf("Memory allocation failed.\n");
00104 exit(1);
00105 }
00106
00107 item->ic = ic;
00108 return item;
00109 }
00110
00115 rdata_addr_var_t *rdata_addr_var_new(void)
00116 {
00117 rdata_addr_var_t *addr_var;
00118
00119 addr_var = calloc(1, sizeof(rdata_addr_var_t));
00120 if (addr_var == NULL) {
00121 printf("Memory allocation failed.\n");
00122 exit(1);
00123 }
00124
00125 return addr_var;
00126 }
00127
00132 rdata_aprop_named_t *rdata_aprop_named_new(void)
00133 {
00134 rdata_aprop_named_t *aprop_named;
00135
00136 aprop_named = calloc(1, sizeof(rdata_aprop_named_t));
00137 if (aprop_named == NULL) {
00138 printf("Memory allocation failed.\n");
00139 exit(1);
00140 }
00141
00142 return aprop_named;
00143 }
00144
00149 rdata_aprop_indexed_t *rdata_aprop_indexed_new(void)
00150 {
00151 rdata_aprop_indexed_t *aprop_indexed;
00152
00153 aprop_indexed = calloc(1, sizeof(rdata_aprop_indexed_t));
00154 if (aprop_indexed == NULL) {
00155 printf("Memory allocation failed.\n");
00156 exit(1);
00157 }
00158
00159 return aprop_indexed;
00160 }
00161
00167 rdata_addr_prop_t *rdata_addr_prop_new(aprop_class_t apc)
00168 {
00169 rdata_addr_prop_t *addr_prop;
00170
00171 addr_prop = calloc(1, sizeof(rdata_addr_prop_t));
00172 if (addr_prop == NULL) {
00173 printf("Memory allocation failed.\n");
00174 exit(1);
00175 }
00176
00177 addr_prop->apc = apc;
00178 return addr_prop;
00179 }
00180
00186 rdata_address_t *rdata_address_new(address_class_t ac)
00187 {
00188 rdata_address_t *address;
00189
00190 address = calloc(1, sizeof(rdata_address_t));
00191 if (address == NULL) {
00192 printf("Memory allocation failed.\n");
00193 exit(1);
00194 }
00195
00196 address->ac = ac;
00197 return address;
00198 }
00199
00204 rdata_value_t *rdata_value_new(void)
00205 {
00206 rdata_value_t *value;
00207
00208 value = calloc(1, sizeof(rdata_value_t));
00209 if (value == NULL) {
00210 printf("Memory allocation failed.\n");
00211 exit(1);
00212 }
00213
00214 return value;
00215 }
00216
00222 rdata_var_t *rdata_var_new(var_class_t vc)
00223 {
00224 rdata_var_t *var;
00225
00226 var = calloc(1, sizeof(rdata_var_t));
00227 if (var == NULL) {
00228 printf("Memory allocation failed.\n");
00229 exit(1);
00230 }
00231
00232 var->vc = vc;
00233 return var;
00234 }
00235
00240 rdata_ref_t *rdata_ref_new(void)
00241 {
00242 rdata_ref_t *ref;
00243
00244 ref = calloc(1, sizeof(rdata_ref_t));
00245 if (ref == NULL) {
00246 printf("Memory allocation failed.\n");
00247 exit(1);
00248 }
00249
00250 return ref;
00251 }
00252
00257 rdata_deleg_t *rdata_deleg_new(void)
00258 {
00259 rdata_deleg_t *deleg;
00260
00261 deleg = calloc(1, sizeof(rdata_deleg_t));
00262 if (deleg == NULL) {
00263 printf("Memory allocation failed.\n");
00264 exit(1);
00265 }
00266
00267 return deleg;
00268 }
00269
00274 rdata_enum_t *rdata_enum_new(void)
00275 {
00276 rdata_enum_t *enum_v;
00277
00278 enum_v = calloc(1, sizeof(rdata_enum_t));
00279 if (enum_v == NULL) {
00280 printf("Memory allocation failed.\n");
00281 exit(1);
00282 }
00283
00284 return enum_v;
00285 }
00286
00291 rdata_array_t *rdata_array_new(int rank)
00292 {
00293 rdata_array_t *array;
00294
00295 array = calloc(1, sizeof(rdata_array_t));
00296 if (array == NULL) {
00297 printf("Memory allocation failed.\n");
00298 exit(1);
00299 }
00300
00301 array->rank = rank;
00302 array->extent = calloc(rank, sizeof(int));
00303 if (array == NULL) {
00304 printf("Memory allocation failed.\n");
00305 exit(1);
00306 }
00307
00308 return array;
00309 }
00310
00315 rdata_object_t *rdata_object_new(void)
00316 {
00317 rdata_object_t *object;
00318
00319 object = calloc(1, sizeof(rdata_object_t));
00320 if (object == NULL) {
00321 printf("Memory allocation failed.\n");
00322 exit(1);
00323 }
00324
00325 return object;
00326 }
00327
00332 rdata_bool_t *rdata_bool_new(void)
00333 {
00334 rdata_bool_t *bool_v;
00335
00336 bool_v = calloc(1, sizeof(rdata_bool_t));
00337 if (bool_v == NULL) {
00338 printf("Memory allocation failed.\n");
00339 exit(1);
00340 }
00341
00342 return bool_v;
00343 }
00344
00349 rdata_char_t *rdata_char_new(void)
00350 {
00351 rdata_char_t *char_v;
00352
00353 char_v = calloc(1, sizeof(rdata_char_t));
00354 if (char_v == NULL) {
00355 printf("Memory allocation failed.\n");
00356 exit(1);
00357 }
00358
00359 return char_v;
00360 }
00361
00366 rdata_int_t *rdata_int_new(void)
00367 {
00368 rdata_int_t *int_v;
00369
00370 int_v = calloc(1, sizeof(rdata_int_t));
00371 if (int_v == NULL) {
00372 printf("Memory allocation failed.\n");
00373 exit(1);
00374 }
00375
00376 return int_v;
00377 }
00378
00383 rdata_string_t *rdata_string_new(void)
00384 {
00385 rdata_string_t *string_v;
00386
00387 string_v = calloc(1, sizeof(rdata_string_t));
00388 if (string_v == NULL) {
00389 printf("Memory allocation failed.\n");
00390 exit(1);
00391 }
00392
00393 return string_v;
00394 }
00395
00400 rdata_resource_t *rdata_resource_new(void)
00401 {
00402 rdata_resource_t *resource_v;
00403
00404 resource_v = calloc(1, sizeof(rdata_resource_t));
00405 if (resource_v == NULL) {
00406 printf("Memory allocation failed.\n");
00407 exit(1);
00408 }
00409
00410 return resource_v;
00411 }
00412
00417 rdata_symbol_t *rdata_symbol_new(void)
00418 {
00419 rdata_symbol_t *symbol_v;
00420
00421 symbol_v = calloc(1, sizeof(rdata_symbol_t));
00422 if (symbol_v == NULL) {
00423 printf("Memory allocation failed.\n");
00424 exit(1);
00425 }
00426
00427 return symbol_v;
00428 }
00429
00436 void rdata_array_alloc_element(rdata_array_t *array)
00437 {
00438 int dim;
00439
00440 dim = rdata_array_get_dim(array);
00441
00442 array->element = calloc(dim, sizeof(rdata_var_t *));
00443 if (array->element == NULL) {
00444 printf("Memory allocation failed.\n");
00445 exit(1);
00446 }
00447 }
00448
00456 static int rdata_array_get_dim(rdata_array_t *array)
00457 {
00458 int didx, dim;
00459
00460 dim = 1;
00461 for (didx = 0; didx < array->rank; ++didx)
00462 dim = dim * array->extent[didx];
00463
00464 return dim;
00465 }
00466
00471 void rdata_item_delete(rdata_item_t *item)
00472 {
00473 assert(item != NULL);
00474 free(item);
00475 }
00476
00481 void rdata_addr_var_delete(rdata_addr_var_t *addr_var)
00482 {
00483 assert(addr_var != NULL);
00484 free(addr_var);
00485 }
00486
00491 void rdata_addr_prop_delete(rdata_addr_prop_t *addr_prop)
00492 {
00493 assert(addr_prop != NULL);
00494 free(addr_prop);
00495 }
00496
00501 void rdata_aprop_named_delete(rdata_aprop_named_t *aprop_named)
00502 {
00503 assert(aprop_named != NULL);
00504 free(aprop_named);
00505 }
00506
00511 void rdata_aprop_indexed_delete(rdata_aprop_indexed_t *aprop_indexed)
00512 {
00513 assert(aprop_indexed != NULL);
00514 free(aprop_indexed);
00515 }
00516
00521 void rdata_address_delete(rdata_address_t *address)
00522 {
00523 assert(address != NULL);
00524 free(address);
00525 }
00526
00531 void rdata_value_delete(rdata_value_t *value)
00532 {
00533 assert(value != NULL);
00534 free(value);
00535 }
00536
00541 void rdata_var_delete(rdata_var_t *var)
00542 {
00543 assert(var != NULL);
00544 free(var);
00545 }
00546
00551 void rdata_bool_delete(rdata_bool_t *bool_v)
00552 {
00553 assert(bool_v != NULL);
00554 free(bool_v);
00555 }
00556
00561 void rdata_char_delete(rdata_char_t *char_v)
00562 {
00563 assert(char_v != NULL);
00564 free(char_v);
00565 }
00566
00571 void rdata_int_delete(rdata_int_t *int_v)
00572 {
00573 assert(int_v != NULL);
00574 free(int_v);
00575 }
00576
00581 void rdata_string_delete(rdata_string_t *string_v)
00582 {
00583 assert(string_v != NULL);
00584 free(string_v);
00585 }
00586
00591 void rdata_ref_delete(rdata_ref_t *ref_v)
00592 {
00593 assert(ref_v != NULL);
00594 free(ref_v);
00595 }
00596
00601 void rdata_deleg_delete(rdata_deleg_t *deleg_v)
00602 {
00603 assert(deleg_v != NULL);
00604 free(deleg_v);
00605 }
00606
00611 void rdata_enum_delete(rdata_enum_t *enum_v)
00612 {
00613 assert(enum_v != NULL);
00614 free(enum_v);
00615 }
00616
00621 void rdata_array_delete(rdata_array_t *array_v)
00622 {
00623 assert(array_v != NULL);
00624 free(array_v);
00625 }
00626
00631 void rdata_object_delete(rdata_object_t *object_v)
00632 {
00633 assert(object_v != NULL);
00634 free(object_v);
00635 }
00636
00641 void rdata_resource_delete(rdata_resource_t *resource_v)
00642 {
00643 assert(resource_v != NULL);
00644 free(resource_v);
00645 }
00646
00651 void rdata_symbol_delete(rdata_symbol_t *symbol_v)
00652 {
00653 assert(symbol_v != NULL);
00654 free(symbol_v);
00655 }
00656
00662 void rdata_value_copy(rdata_value_t *src, rdata_value_t **dest)
00663 {
00664 assert(src != NULL);
00665
00666 *dest = rdata_value_new();
00667 rdata_var_copy(src->var, &(*dest)->var);
00668 }
00669
00678 void rdata_var_copy(rdata_var_t *src, rdata_var_t **dest)
00679 {
00680 rdata_var_t *nvar;
00681
00682 nvar = rdata_var_new(src->vc);
00683 rdata_var_copy_to(src, nvar);
00684
00685 *dest = nvar;
00686 }
00687
00697 static void rdata_var_copy_to(rdata_var_t *src, rdata_var_t *dest)
00698 {
00699 dest->vc = src->vc;
00700
00701 switch (src->vc) {
00702 case vc_bool:
00703 rdata_bool_copy(src->u.bool_v, &dest->u.bool_v);
00704 break;
00705 case vc_char:
00706 rdata_char_copy(src->u.char_v, &dest->u.char_v);
00707 break;
00708 case vc_int:
00709 rdata_int_copy(src->u.int_v, &dest->u.int_v);
00710 break;
00711 case vc_string:
00712 rdata_string_copy(src->u.string_v, &dest->u.string_v);
00713 break;
00714 case vc_ref:
00715 rdata_ref_copy(src->u.ref_v, &dest->u.ref_v);
00716 break;
00717 case vc_deleg:
00718 rdata_deleg_copy(src->u.deleg_v, &dest->u.deleg_v);
00719 break;
00720 case vc_enum:
00721 rdata_enum_copy(src->u.enum_v, &dest->u.enum_v);
00722 break;
00723 case vc_array:
00724 rdata_array_copy(src->u.array_v, &dest->u.array_v);
00725 break;
00726 case vc_object:
00727 rdata_object_copy(src->u.object_v, &dest->u.object_v);
00728 break;
00729 case vc_resource:
00730 rdata_resource_copy(src->u.resource_v, &dest->u.resource_v);
00731 break;
00732 case vc_symbol:
00733 rdata_symbol_copy(src->u.symbol_v, &dest->u.symbol_v);
00734 break;
00735 }
00736 }
00737
00738
00744 static void rdata_bool_copy(rdata_bool_t *src, rdata_bool_t **dest)
00745 {
00746 *dest = rdata_bool_new();
00747 (*dest)->value = src->value;
00748 }
00749
00755 static void rdata_char_copy(rdata_char_t *src, rdata_char_t **dest)
00756 {
00757 *dest = rdata_char_new();
00758 bigint_clone(&src->value, &(*dest)->value);
00759 }
00760
00766 static void rdata_int_copy(rdata_int_t *src, rdata_int_t **dest)
00767 {
00768 *dest = rdata_int_new();
00769 bigint_clone(&src->value, &(*dest)->value);
00770 }
00771
00777 static void rdata_string_copy(rdata_string_t *src, rdata_string_t **dest)
00778 {
00779 *dest = rdata_string_new();
00780 (*dest)->value = src->value;
00781 }
00782
00788 static void rdata_ref_copy(rdata_ref_t *src, rdata_ref_t **dest)
00789 {
00790 *dest = rdata_ref_new();
00791 (*dest)->vref = src->vref;
00792 }
00793
00799 static void rdata_deleg_copy(rdata_deleg_t *src, rdata_deleg_t **dest)
00800 {
00801 *dest = rdata_deleg_new();
00802 (*dest)->obj = src->obj;
00803 (*dest)->sym = src->sym;
00804 }
00805
00811 static void rdata_enum_copy(rdata_enum_t *src, rdata_enum_t **dest)
00812 {
00813 *dest = rdata_enum_new();
00814 (*dest)->value = src->value;
00815 }
00816
00822 static void rdata_array_copy(rdata_array_t *src, rdata_array_t **dest)
00823 {
00824 (void) src; (void) dest;
00825 printf("Unimplemented: Copy array.\n");
00826 exit(1);
00827 }
00828
00834 static void rdata_object_copy(rdata_object_t *src, rdata_object_t **dest)
00835 {
00836 (void) src; (void) dest;
00837 printf("Unimplemented: Copy object.\n");
00838 abort();
00839 }
00840
00846 static void rdata_resource_copy(rdata_resource_t *src, rdata_resource_t **dest)
00847 {
00848 *dest = rdata_resource_new();
00849 (*dest)->data = src->data;
00850 }
00851
00857 static void rdata_symbol_copy(rdata_symbol_t *src, rdata_symbol_t **dest)
00858 {
00859 *dest = rdata_symbol_new();
00860 (*dest)->sym = src->sym;
00861 }
00862
00867 void rdata_var_destroy(rdata_var_t *var)
00868 {
00869
00870 rdata_var_destroy_inner(var);
00871
00872
00873 rdata_var_delete(var);
00874 }
00875
00883 static void rdata_var_destroy_inner(rdata_var_t *var)
00884 {
00885
00886
00887 switch (var->vc) {
00888 case vc_bool:
00889 rdata_bool_destroy(var->u.bool_v);
00890 break;
00891 case vc_char:
00892 rdata_char_destroy(var->u.char_v);
00893 break;
00894 case vc_int:
00895 rdata_int_destroy(var->u.int_v);
00896 break;
00897 case vc_string:
00898 rdata_string_destroy(var->u.string_v);
00899 break;
00900 case vc_ref:
00901 rdata_ref_destroy(var->u.ref_v);
00902 break;
00903 case vc_deleg:
00904 rdata_deleg_destroy(var->u.deleg_v);
00905 break;
00906 case vc_enum:
00907 rdata_enum_destroy(var->u.enum_v);
00908 break;
00909 case vc_array:
00910 rdata_array_destroy(var->u.array_v);
00911 break;
00912 case vc_object:
00913 rdata_object_destroy(var->u.object_v);
00914 break;
00915 case vc_resource:
00916 rdata_resource_destroy(var->u.resource_v);
00917 break;
00918 case vc_symbol:
00919 rdata_symbol_destroy(var->u.symbol_v);
00920 break;
00921 }
00922 }
00923
00930 void rdata_item_destroy(rdata_item_t *item)
00931 {
00932
00933
00934 switch (item->ic) {
00935 case ic_address:
00936 rdata_address_destroy(item->u.address);
00937 break;
00938 case ic_value:
00939 rdata_value_destroy(item->u.value);
00940 break;
00941 }
00942
00943
00944 rdata_item_delete(item);
00945 }
00946
00953 void rdata_address_destroy(rdata_address_t *address)
00954 {
00955 switch (address->ac) {
00956 case ac_var:
00957 rdata_addr_var_destroy(address->u.var_a);
00958 break;
00959 case ac_prop:
00960 rdata_addr_prop_destroy(address->u.prop_a);
00961 break;
00962 }
00963
00964
00965 rdata_address_delete(address);
00966 }
00967
00974 void rdata_addr_var_destroy(rdata_addr_var_t *addr_var)
00975 {
00976 addr_var->vref = NULL;
00977
00978
00979 rdata_addr_var_delete(addr_var);
00980 }
00981
00988 void rdata_addr_prop_destroy(rdata_addr_prop_t *addr_prop)
00989 {
00990 switch (addr_prop->apc) {
00991 case apc_named:
00992 rdata_aprop_named_destroy(addr_prop->u.named);
00993 break;
00994 case apc_indexed:
00995 rdata_aprop_indexed_destroy(addr_prop->u.indexed);
00996 break;
00997 }
00998
00999 if (addr_prop->tvalue != NULL) {
01000 rdata_value_destroy(addr_prop->tvalue);
01001 addr_prop->tvalue = NULL;
01002 }
01003
01004 addr_prop->tpos = NULL;
01005
01006
01007 rdata_addr_prop_delete(addr_prop);
01008 }
01009
01016 void rdata_aprop_named_destroy(rdata_aprop_named_t *aprop_named)
01017 {
01018 rdata_deleg_destroy(aprop_named->prop_d);
01019
01020
01021 rdata_aprop_named_delete(aprop_named);
01022 }
01023
01030 void rdata_aprop_indexed_destroy(rdata_aprop_indexed_t *aprop_indexed)
01031 {
01032 list_node_t *arg_node;
01033 rdata_item_t *arg_i;
01034
01035
01036 rdata_deleg_destroy(aprop_indexed->object_d);
01037
01038
01039
01040
01041
01042 while (!list_is_empty(&aprop_indexed->args)) {
01043 arg_node = list_first(&aprop_indexed->args);
01044 arg_i = list_node_data(arg_node, rdata_item_t *);
01045
01046 rdata_item_destroy(arg_i);
01047 list_remove(&aprop_indexed->args, arg_node);
01048 }
01049
01050
01051 list_fini(&aprop_indexed->args);
01052
01053
01054 rdata_aprop_indexed_delete(aprop_indexed);
01055 }
01056
01063 void rdata_value_destroy(rdata_value_t *value)
01064 {
01065
01066 rdata_var_destroy(value->var);
01067
01068
01069 rdata_value_delete(value);
01070 }
01071
01076 static void rdata_bool_destroy(rdata_bool_t *bool_v)
01077 {
01078 rdata_bool_delete(bool_v);
01079 }
01080
01085 static void rdata_char_destroy(rdata_char_t *char_v)
01086 {
01087 bigint_destroy(&char_v->value);
01088 rdata_char_delete(char_v);
01089 }
01090
01095 static void rdata_int_destroy(rdata_int_t *int_v)
01096 {
01097 bigint_destroy(&int_v->value);
01098 rdata_int_delete(int_v);
01099 }
01100
01105 static void rdata_string_destroy(rdata_string_t *string_v)
01106 {
01107
01108
01109
01110
01111 rdata_string_delete(string_v);
01112 }
01113
01118 static void rdata_ref_destroy(rdata_ref_t *ref_v)
01119 {
01120 ref_v->vref = NULL;
01121 rdata_ref_delete(ref_v);
01122 }
01123
01128 static void rdata_deleg_destroy(rdata_deleg_t *deleg_v)
01129 {
01130 deleg_v->obj = NULL;
01131 deleg_v->sym = NULL;
01132 rdata_deleg_delete(deleg_v);
01133 }
01134
01139 static void rdata_enum_destroy(rdata_enum_t *enum_v)
01140 {
01141 enum_v->value = NULL;
01142 rdata_enum_delete(enum_v);
01143 }
01144
01149 static void rdata_array_destroy(rdata_array_t *array_v)
01150 {
01151 int d;
01152 size_t n_elems, p;
01153
01154
01155
01156
01157
01158 n_elems = 1;
01159 for (d = 0; d < array_v->rank; d++) {
01160 n_elems = n_elems * array_v->extent[d];
01161 array_v->extent[d] = 0;
01162 }
01163
01164
01165 for (p = 0; p < n_elems; p++) {
01166 rdata_var_delete(array_v->element[p]);
01167 array_v->element[p] = NULL;
01168 }
01169
01170
01171 free(array_v->element);
01172 free(array_v->extent);
01173
01174 array_v->rank = 0;
01175
01176
01177 rdata_array_delete(array_v);
01178 }
01179
01184 static void rdata_object_destroy(rdata_object_t *object_v)
01185 {
01186
01187 rdata_object_delete(object_v);
01188 }
01189
01194 static void rdata_resource_destroy(rdata_resource_t *resource_v)
01195 {
01196
01197
01198
01199
01200 resource_v->data = NULL;
01201 rdata_resource_delete(resource_v);
01202 }
01203
01208 static void rdata_symbol_destroy(rdata_symbol_t *symbol_v)
01209 {
01210 symbol_v->sym = NULL;
01211 rdata_symbol_delete(symbol_v);
01212 }
01213
01225 void rdata_var_read(rdata_var_t *var, rdata_item_t **ritem)
01226 {
01227 rdata_value_t *value;
01228 rdata_var_t *rvar;
01229
01230
01231 rdata_var_copy(var, &rvar);
01232
01233 value = rdata_value_new();
01234 value->var = rvar;
01235 *ritem = rdata_item_new(ic_value);
01236 (*ritem)->u.value = value;
01237 }
01238
01249 void rdata_var_write(rdata_var_t *var, rdata_value_t *value)
01250 {
01251
01252 rdata_var_destroy_inner(var);
01253
01254
01255 rdata_var_copy_to(value->var, var);
01256 }
01257
01262 void rdata_item_print(rdata_item_t *item)
01263 {
01264 if (item == NULL) {
01265 printf("none");
01266 return;
01267 }
01268
01269 switch (item->ic) {
01270 case ic_address:
01271 printf("address:");
01272 rdata_address_print(item->u.address);
01273 break;
01274 case ic_value:
01275 printf("value:");
01276 rdata_value_print(item->u.value);
01277 break;
01278 }
01279 }
01280
01290 static void rdata_address_print(rdata_address_t *address)
01291 {
01292 switch (address->ac) {
01293 case ac_var:
01294 rdata_var_print(address->u.var_a->vref);
01295 break;
01296 case ac_prop:
01297 printf("Warning: Unimplemented: Print property address.\n");
01298 break;
01299 }
01300 }
01301
01306 void rdata_value_print(rdata_value_t *value)
01307 {
01308 rdata_var_print(value->var);
01309 }
01310
01315 static void rdata_var_print(rdata_var_t *var)
01316 {
01317 int val;
01318
01319 switch (var->vc) {
01320 case vc_bool:
01321 printf("bool(%s)", var->u.bool_v->value ? "true" : "false");
01322 break;
01323 case vc_char:
01324 printf("char(");
01325 if (bigint_get_value_int(&var->u.char_v->value, &val) == EOK)
01326 printf("'%c'", val);
01327 else
01328 printf("???:x%x\n", (unsigned) val);
01329 printf(")");
01330 break;
01331 case vc_int:
01332 printf("int(");
01333 bigint_print(&var->u.int_v->value);
01334 printf(")");
01335 break;
01336 case vc_string:
01337 printf("string(\"%s\")", var->u.string_v->value);
01338 break;
01339 case vc_ref:
01340 if (var->u.ref_v->vref != NULL) {
01341 printf("ref(");
01342 rdata_var_print(var->u.ref_v->vref);
01343 printf(")");
01344 } else {
01345 printf("nil");
01346 }
01347 break;
01348 case vc_deleg:
01349 printf("deleg(");
01350 if (var->u.deleg_v->sym != NULL) {
01351 if (var->u.deleg_v->obj != NULL) {
01352 rdata_var_print(var->u.deleg_v->obj);
01353 printf(",");
01354 }
01355 symbol_print_fqn(var->u.deleg_v->sym);
01356 } else {
01357 printf("nil");
01358 }
01359 printf(")");
01360 break;
01361 case vc_enum:
01362 symbol_print_fqn(
01363 enum_to_symbol(var->u.enum_v->value->outer_enum));
01364 printf(".%s",
01365 strtab_get_str(var->u.enum_v->value->name->sid));
01366 break;
01367 case vc_array:
01368 printf("array");
01369 break;
01370 case vc_object:
01371 printf("object");
01372 break;
01373 case vc_resource:
01374 printf("resource(%p)", var->u.resource_v->data);
01375 break;
01376 case vc_symbol:
01377 printf("symbol(");
01378 if (var->u.symbol_v->sym != NULL) {
01379 symbol_print_fqn(var->u.symbol_v->sym);
01380 } else {
01381 printf("nil");
01382 }
01383 printf(")");
01384 break;
01385 }
01386 }