Changeset c12b2ae in mainline for uspace/app/bithenge/transform.c


Ignore:
Timestamp:
2012-08-07T05:00:41Z (12 years ago)
Author:
Sean Bartell <wingedtachikoma@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ad5c8a48
Parents:
a8be91a
Message:

Bithenge: search for current node members in outer scopes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bithenge/transform.c

    ra8be91a rc12b2ae  
    179179                bithenge_scope_inc_ref(outer);
    180180        self->outer = outer;
     181        self->barrier = false;
    181182        self->num_params = 0;
    182183        self->params = NULL;
     
    202203}
    203204
     205/** Get the outer scope of a scope, which may be NULL.
     206 * @param self The scope to examine.
     207 * @return The outer scope, which may be NULL. */
     208bithenge_scope_t *bithenge_scope_outer(bithenge_scope_t *self)
     209{
     210        return self->outer;
     211}
     212
    204213/** Set the current node being created. Takes a reference to @a node.
    205214 * @param scope The scope to set the current node in.
     
    211220        bithenge_node_dec_ref(scope->current_node);
    212221        scope->current_node = node;
     222}
     223
     224/** Set a scope as a barrier.
     225 * @param self The scope to change. */
     226void bithenge_scope_set_barrier(bithenge_scope_t *self)
     227{
     228        self->barrier = true;
     229}
     230
     231/** Check whether a scope is a barrier, meaning that variable lookup stops at
     232 * it.
     233 * @param self The scope to check.
     234 * @return Whether the scope is a barrier. */
     235bool bithenge_scope_is_barrier(bithenge_scope_t *self)
     236{
     237        return self->barrier;
    213238}
    214239
     
    277302        bithenge_transform_t base;
    278303        bithenge_transform_t *transform;
    279 } scope_transform_t;
    280 
    281 static inline scope_transform_t *transform_as_param(
     304} barrier_transform_t;
     305
     306static inline barrier_transform_t *transform_as_barrier(
    282307    bithenge_transform_t *base)
    283308{
    284         return (scope_transform_t *)base;
    285 }
    286 
    287 static inline bithenge_transform_t *param_as_transform(
    288     scope_transform_t *self)
     309        return (barrier_transform_t *)base;
     310}
     311
     312static inline bithenge_transform_t *barrier_as_transform(
     313    barrier_transform_t *self)
    289314{
    290315        return &self->base;
    291316}
    292317
    293 static int scope_transform_apply(bithenge_transform_t *base,
     318static int barrier_transform_apply(bithenge_transform_t *base,
    294319    bithenge_scope_t *scope, bithenge_node_t *in, bithenge_node_t **out)
    295320{
    296         scope_transform_t *self = transform_as_param(base);
     321        barrier_transform_t *self = transform_as_barrier(base);
    297322        bithenge_scope_t *inner_scope;
    298323        int rc = bithenge_scope_new(&inner_scope, scope);
    299324        if (rc != EOK)
    300325                return rc;
     326        bithenge_scope_set_barrier(inner_scope);
    301327        rc = bithenge_transform_apply(self->transform, scope, in, out);
    302328        bithenge_scope_dec_ref(inner_scope);
     
    304330}
    305331
    306 static int scope_transform_prefix_length(bithenge_transform_t *base,
     332static int barrier_transform_prefix_length(bithenge_transform_t *base,
    307333    bithenge_scope_t *scope, bithenge_blob_t *in, aoff64_t *out)
    308334{
    309         scope_transform_t *self = transform_as_param(base);
    310         return bithenge_transform_prefix_length(self->transform, scope, in,
    311             out);
    312 }
    313 
    314 static void scope_transform_destroy(bithenge_transform_t *base)
    315 {
    316         scope_transform_t *self = transform_as_param(base);
     335        barrier_transform_t *self = transform_as_barrier(base);
     336        bithenge_scope_t *inner_scope;
     337        int rc = bithenge_scope_new(&inner_scope, scope);
     338        if (rc != EOK)
     339                return rc;
     340        bithenge_scope_set_barrier(inner_scope);
     341        rc = bithenge_transform_prefix_length(self->transform, scope, in, out);
     342        bithenge_scope_dec_ref(inner_scope);
     343        return rc;
     344}
     345
     346static int barrier_transform_prefix_apply(bithenge_transform_t *base,
     347    bithenge_scope_t *scope, bithenge_blob_t *in, bithenge_node_t **out_node,
     348    aoff64_t *out_length)
     349{
     350        barrier_transform_t *self = transform_as_barrier(base);
     351        bithenge_scope_t *inner_scope;
     352        int rc = bithenge_scope_new(&inner_scope, scope);
     353        if (rc != EOK)
     354                return rc;
     355        bithenge_scope_set_barrier(inner_scope);
     356        rc = bithenge_transform_prefix_apply(self->transform, scope, in,
     357            out_node, out_length);
     358        bithenge_scope_dec_ref(inner_scope);
     359        return rc;
     360}
     361
     362static void barrier_transform_destroy(bithenge_transform_t *base)
     363{
     364        barrier_transform_t *self = transform_as_barrier(base);
    317365        bithenge_transform_dec_ref(self->transform);
    318366        free(self);
    319367}
    320368
    321 static const bithenge_transform_ops_t scope_transform_ops = {
    322         .apply = scope_transform_apply,
    323         .prefix_length = scope_transform_prefix_length,
    324         .destroy = scope_transform_destroy,
    325 };
    326 
    327 /** Create a wrapper transform that creates a new outer scope. This ensures
    328  * nothing from the transform's users is passed in, other than parameters. The
    329  * wrapper may have a different value for num_params. Takes a reference to
    330  * @a transform, which it will use for all operations.
     369static const bithenge_transform_ops_t barrier_transform_ops = {
     370        .apply = barrier_transform_apply,
     371        .prefix_length = barrier_transform_prefix_length,
     372        .prefix_apply = barrier_transform_prefix_apply,
     373        .destroy = barrier_transform_destroy,
     374};
     375
     376/** Create a wrapper transform that creates a new scope. This ensures nothing
     377 * from the outer scope is passed in, other than parameters. The wrapper may
     378 * have a different value for num_params. Takes a reference to @a transform,
     379 * which it will use for all operations.
    331380 * @param[out] out Holds the created transform.
    332381 * @param transform The transform to wrap.
    333382 * @param num_params The number of parameters to require, which may be 0.
    334383 * @return EOK on success or an error code from errno.h. */
    335 int bithenge_new_scope_transform(bithenge_transform_t **out,
     384int bithenge_new_barrier_transform(bithenge_transform_t **out,
    336385    bithenge_transform_t *transform, int num_params)
    337386{
     
    340389
    341390        int rc;
    342         scope_transform_t *self = malloc(sizeof(*self));
     391        barrier_transform_t *self = malloc(sizeof(*self));
    343392        if (!self) {
    344393                rc = ENOMEM;
    345394                goto error;
    346395        }
    347         rc = bithenge_init_transform(param_as_transform(self),
    348             &scope_transform_ops, num_params);
     396        rc = bithenge_init_transform(barrier_as_transform(self),
     397            &barrier_transform_ops, num_params);
    349398        if (rc != EOK)
    350399                goto error;
    351400        self->transform = transform;
    352         *out = param_as_transform(self);
     401        *out = barrier_as_transform(self);
    353402        return EOK;
    354403error:
Note: See TracChangeset for help on using the changeset viewer.