diff options
author | Patrick McHardy <kaber@trash.net> | 2013-04-15 16:18:17 +0200 |
---|---|---|
committer | Patrick McHardy <kaber@trash.net> | 2013-04-18 15:12:13 +0200 |
commit | 2d148c5311cc4fa5d2f7b0c439dd051abcafa9ab (patch) | |
tree | 143c71d95ce8c451f1ab6560fdeac019c058a6d2 /src/datatype.c | |
parent | 7f98d140f31151d9e81f55faad2f271b2e28f2b7 (diff) |
datatype: parse/print in all basetypes subsequently
Go down the chain of basetypes until we find a ->parse()/->print() callback
or symbol table. Needed to invoke the generic link layer address parsing
function for the etheraddr_type.
Signed-off-by: Patrick McHardy <kaber@trash.net>
Diffstat (limited to 'src/datatype.c')
-rw-r--r-- | src/datatype.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/datatype.c b/src/datatype.c index f369d5f0..c687edd4 100644 --- a/src/datatype.c +++ b/src/datatype.c @@ -69,10 +69,13 @@ void datatype_print(const struct expr *expr) { const struct datatype *dtype = expr->dtype; - if (dtype->print != NULL) - return dtype->print(expr); - if (dtype->sym_tbl != NULL) - return symbolic_constant_print(dtype->sym_tbl, expr); + do { + if (dtype->print != NULL) + return dtype->print(expr); + if (dtype->sym_tbl != NULL) + return symbolic_constant_print(dtype->sym_tbl, expr); + } while ((dtype = dtype->basetype)); + BUG("datatype has no print method or symbol table\n"); } @@ -85,10 +88,13 @@ struct error_record *symbol_parse(const struct expr *sym, if (dtype == NULL) return error(&sym->location, "No symbol type information"); - if (dtype->parse != NULL) - return dtype->parse(sym, res); - if (dtype->sym_tbl != NULL) - return symbolic_constant_parse(sym, dtype->sym_tbl, res); + do { + if (dtype->parse != NULL) + return dtype->parse(sym, res); + if (dtype->sym_tbl != NULL) + return symbolic_constant_parse(sym, dtype->sym_tbl, + res); + } while ((dtype = dtype->basetype)); return error(&sym->location, "Can't parse symbolic %s expressions", @@ -301,7 +307,7 @@ static struct error_record *lladdr_type_parse(const struct expr *sym, s = ++p; } - *res = constant_expr_alloc(&sym->location, &lladdr_type, + *res = constant_expr_alloc(&sym->location, sym->dtype, BYTEORDER_HOST_ENDIAN, len * BITS_PER_BYTE, buf); return NULL; |