From 9e2271940a081214f045341fa521a6231736bae8 Mon Sep 17 00:00:00 2001 From: Patrick McHardy Date: Mon, 22 Dec 2014 17:45:48 +0100 Subject: concat: add concat subtype lookup/id helpers Signed-off-by: Patrick McHardy --- src/datatype.c | 4 ++-- src/evaluate.c | 9 +++------ src/parser_bison.y | 3 +-- 3 files changed, 6 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/datatype.c b/src/datatype.c index 76f2af13..c93f76a3 100644 --- a/src/datatype.c +++ b/src/datatype.c @@ -931,8 +931,8 @@ const struct datatype *concat_type_alloc(uint32_t type) unsigned int size = 0, subtypes = 0, n; n = div_round_up(fls(type), TYPE_BITS); - while ((type >> TYPE_BITS * --n) & TYPE_MASK) { - i = datatype_lookup((type >> TYPE_BITS * n) & TYPE_MASK); + while (concat_subtype_id(type, --n)) { + i = concat_subtype_lookup(type, n); if (i == NULL) return NULL; diff --git a/src/evaluate.c b/src/evaluate.c index 00c6d918..53f3cf0a 100644 --- a/src/evaluate.c +++ b/src/evaluate.c @@ -612,25 +612,22 @@ static int expr_evaluate_concat(struct eval_ctx *ctx, struct expr **expr) int off = dtype ? dtype->subtypes : 0; unsigned int flags = EXPR_F_CONSTANT | EXPR_F_SINGLETON; struct expr *i, *next; - unsigned int n; - n = 1; list_for_each_entry_safe(i, next, &(*expr)->expressions, list) { if (dtype && off == 0) return expr_binary_error(ctx->msgs, i, *expr, "unexpected concat component, " "expecting %s", dtype->desc); - tmp = datatype_lookup((type >> TYPE_BITS * --off) & TYPE_MASK); + + tmp = concat_subtype_lookup(type, --off); expr_set_context(&ctx->ectx, tmp, tmp->size); if (list_member_evaluate(ctx, &i) < 0) return -1; flags &= i->flags; - ntype <<= TYPE_BITS; - ntype |= i->dtype->type; - n++; + ntype = concat_subtype_add(ntype, i->dtype->type); } (*expr)->flags |= flags; diff --git a/src/parser_bison.y b/src/parser_bison.y index b20f4deb..6c46d098 100644 --- a/src/parser_bison.y +++ b/src/parser_bison.y @@ -1020,8 +1020,7 @@ type_identifier : identifier state->msgs); YYERROR; } - $$ <<= TYPE_BITS; - $$ |= dtype->type; + $$ = concat_subtype_add($$, dtype->type); } ; -- cgit v1.2.3