Changeset c54f5d0 in mainline for uspace/app/bithenge/script.c


Ignore:
Timestamp:
2012-08-09T05:23:54Z (13 years ago)
Author:
Sean Bartell <wingedtachikoma@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
71450c8
Parents:
3c70376
Message:

Bithenge: partial transforms

File:
1 edited

Legend:

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

    r3c70376 rc54f5d0  
    6666        TOKEN_IF,
    6767        TOKEN_IN,
     68        TOKEN_PARTIAL,
    6869        TOKEN_REPEAT,
    6970        TOKEN_STRUCT,
     
    232233                } else if (!str_cmp(value, "in")) {
    233234                        state->token = TOKEN_IN;
     235                        free(value);
     236                } else if (!str_cmp(value, "partial")) {
     237                        state->token = TOKEN_PARTIAL;
    234238                        free(value);
    235239                } else if (!str_cmp(value, "repeat")) {
     
    871875}
    872876
     877static bithenge_transform_t *parse_partial(state_t *state)
     878{
     879        expect(state, TOKEN_PARTIAL);
     880        bithenge_transform_t *offset_xform = NULL;
     881        if (state->token == '(') {
     882                next_token(state);
     883                bithenge_expression_t *offset = parse_expression(state);
     884                expect(state, ')');
     885
     886                bithenge_expression_t *in_expr;
     887                int rc = bithenge_in_node_expression(&in_expr);
     888                if (rc != EOK)
     889                        error_errno(state, rc);
     890                if (state->error != EOK) {
     891                        bithenge_expression_dec_ref(offset);
     892                        return NULL;
     893                }
     894
     895                rc = bithenge_subblob_expression(&offset, in_expr, offset,
     896                    NULL, true);
     897                if (rc != EOK) {
     898                        error_errno(state, rc);
     899                        return NULL;
     900                }
     901
     902                rc = bithenge_expression_transform(&offset_xform, offset);
     903                if (rc != EOK) {
     904                        error_errno(state, rc);
     905                        return NULL;
     906                }
     907        }
     908        expect(state, '{');
     909        bithenge_transform_t *xform = parse_transform(state);
     910        expect(state, '}');
     911        if (state->error != EOK) {
     912                bithenge_transform_dec_ref(offset_xform);
     913                bithenge_transform_dec_ref(xform);
     914                return NULL;
     915        }
     916
     917        int rc = bithenge_partial_transform(&xform, xform);
     918        if (rc != EOK) {
     919                error_errno(state, rc);
     920                bithenge_transform_dec_ref(offset_xform);
     921                return NULL;
     922        }
     923
     924        if (offset_xform) {
     925                bithenge_transform_t **xforms = malloc(2 * sizeof(*xforms));
     926                if (!xforms) {
     927                        error_errno(state, ENOMEM);
     928                        bithenge_transform_dec_ref(xform);
     929                        bithenge_transform_dec_ref(offset_xform);
     930                        return NULL;
     931                }
     932                xforms[0] = xform;
     933                xforms[1] = offset_xform;
     934                rc = bithenge_new_composed_transform(&xform, xforms, 2);
     935                if (rc != EOK) {
     936                        error_errno(state, rc);
     937                        return NULL;
     938                }
     939        }
     940
     941        return xform;
     942}
     943
    873944/* The TOKEN_STRUCT and '{' must already have been skipped. */
    874945static bithenge_transform_t *parse_struct(state_t *state)
     
    9521023        } else if (state->token == TOKEN_IF) {
    9531024                return parse_if(state, false);
     1025        } else if (state->token == TOKEN_PARTIAL) {
     1026                return parse_partial(state);
    9541027        } else if (state->token == TOKEN_REPEAT) {
    9551028                return parse_repeat(state);
Note: See TracChangeset for help on using the changeset viewer.