Changeset 94d484a in mainline for uspace/app/sbi/src/rdata.c


Ignore:
Timestamp:
2010-03-07T17:45:33Z (15 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d0febca
Parents:
fa36f29
Message:

Update SBI to rev. 90.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/sbi/src/rdata.c

    rfa36f29 r94d484a  
    3232#include <assert.h>
    3333#include "mytypes.h"
     34#include "stree.h"
    3435
    3536#include "rdata.h"
     
    3940static void rdata_ref_copy(rdata_ref_t *src, rdata_ref_t **dest);
    4041static void rdata_deleg_copy(rdata_deleg_t *src, rdata_deleg_t **dest);
     42static void rdata_array_copy(rdata_array_t *src, rdata_array_t **dest);
    4143static void rdata_object_copy(rdata_object_t *src, rdata_object_t **dest);
     44
     45static int rdata_array_get_dim(rdata_array_t *array);
    4246
    4347static void rdata_address_print(rdata_address_t *address);
     
    126130}
    127131
     132rdata_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
    128152rdata_object_t *rdata_object_new(void)
    129153{
     
    163187
    164188        return string_v;
     189}
     190
     191rdata_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
     205rdata_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
     218rdata_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
     231rdata_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
     244void 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 */
     270static 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;
    165279}
    166280
     
    185299                rdata_deleg_copy(src->u.deleg_v, &nvar->u.deleg_v);
    186300                break;
     301        case vc_array:
     302                rdata_array_copy(src->u.array_v, &nvar->u.array_v);
     303                break;
    187304        case vc_object:
    188305                rdata_object_copy(src->u.object_v, &nvar->u.object_v);
     
    215332        (void) src; (void) dest;
    216333        printf("Unimplemented: Copy delegate.\n");
     334        exit(1);
     335}
     336
     337static void rdata_array_copy(rdata_array_t *src, rdata_array_t **dest)
     338{
     339        (void) src; (void) dest;
     340        printf("Unimplemented: Copy array.\n");
    217341        exit(1);
    218342}
     
    339463void rdata_address_write(rdata_address_t *address, rdata_value_t *value)
    340464{
     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 */
     472void rdata_var_write(rdata_var_t *var, rdata_value_t *value)
     473{
    341474        rdata_var_t *nvar;
    342         rdata_var_t *orig_var;
    343475
    344476        /* Perform a shallow copy of @c value->var. */
    345477        rdata_var_copy(value->var, &nvar);
    346         orig_var = address->vref;
    347478
    348479        /* XXX do this in a prettier way. */
    349480
    350         orig_var->vc = nvar->vc;
     481        var->vc = nvar->vc;
    351482        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;
    357489        }
    358490
    359491        /* 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. */
     495bool_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;
    360509}
    361510
Note: See TracChangeset for help on using the changeset viewer.