X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fcdump%2Fcdump.c;h=f080b968b5732593dbed861d241614878c5191bf;hp=fb942594e0578f15ec9b37d4a60071296f9507ed;hb=ed95d8600afe1564ffd1783ae9ea0ef6324904dc;hpb=3d6fe8391ab0b6e6b9da0a715a4a8308303fc72e diff --git a/ccan/cdump/cdump.c b/ccan/cdump/cdump.c index fb942594..f080b968 100644 --- a/ccan/cdump/cdump.c +++ b/ccan/cdump/cdump.c @@ -390,6 +390,28 @@ static bool tok_maybe_take_cdump_note(const tal_t *ctx, return true; } +/* __attribute__((...)) */ +static bool tok_ignore_attribute(struct parse_state *ps) +{ + if (!tok_take_if(&ps->toks, "__attribute__")) + return true; + + if (!tok_take_if(&ps->toks, "(") || !tok_take_if(&ps->toks, "(")) { + complain(ps, "Expected (( after __attribute__"); + return false; + } + + if (!tok_take_expr(ps, ")")) { + complain(ps, "Expected expression after __attribute__(("); + return false; + } + if (!tok_take_if(&ps->toks, ")")) { + complain(ps, "Expected )) __attribute__(("); + return false; + } + return true; +} + /* struct|union ... */ static bool tok_take_conglom(struct parse_state *ps, enum cdump_type_kind conglom_kind) @@ -415,6 +437,9 @@ static bool tok_take_conglom(struct parse_state *ps, if (!tok_maybe_take_cdump_note(e, ps, &e->note)) return false; + if (!tok_ignore_attribute(ps)) + return false; + if (!tok_take_if(&ps->toks, "{")) { complain(ps, "Expected { for struct/union"); return false; @@ -426,6 +451,9 @@ static bool tok_take_conglom(struct parse_state *ps, const struct token *quals; unsigned int num_quals = 0; + if (!tok_ignore_attribute(ps)) + return false; + /* Anything can have these prepended. */ quals = ps->toks; while (tok_take_if(&ps->toks, "const") @@ -455,6 +483,9 @@ static bool tok_take_conglom(struct parse_state *ps, while (tok_take_if(&ps->toks, "*")) m->type = ptr_of(ps, m->type); + if (!tok_ignore_attribute(ps)) + return false; + m->name = tok_take_ident(e, &ps->toks); if (!m->name) { complain(ps, "Expected name for member"); @@ -471,6 +502,9 @@ static bool tok_take_conglom(struct parse_state *ps, if (!tok_maybe_take_cdump_note(e->u.members, ps, &m->note)) return false; + + if (!tok_ignore_attribute(ps)) + return false; } while (tok_take_if(&ps->toks, ",")); if (!tok_take_if(&ps->toks, ";")) { @@ -479,10 +513,19 @@ static bool tok_take_conglom(struct parse_state *ps, } } - if (tok_take_if(&ps->toks, "}") && tok_take_if(&ps->toks, ";")) - return true; - complain(ps, "Expected }; at end of struct/union"); - return false; + if (!tok_take_if(&ps->toks, "}")) { + complain(ps, "Expected } at end of struct/union"); + return false; + } + + if (!tok_ignore_attribute(ps)) + return false; + + if (!tok_take_if(&ps->toks, ";")) { + complain(ps, "Expected ; at end of struct/union"); + return false; + } + return true; } /* enum ... */ @@ -510,6 +553,9 @@ static bool tok_take_enum(struct parse_state *ps) if (!tok_maybe_take_cdump_note(e, ps, &e->note)) return false; + if (!tok_ignore_attribute(ps)) + return false; + if (!tok_take_if(&ps->toks, "{")) { complain(ps, "Expected { after enum name"); return false; @@ -546,11 +592,19 @@ static bool tok_take_enum(struct parse_state *ps) v->value = NULL; } while (tok_take_if(&ps->toks, ",")); - if (tok_take_if(&ps->toks, "}") && tok_take_if(&ps->toks, ";")) - return true; + if (!tok_take_if(&ps->toks, "}")) { + complain(ps, "Expected } at end of enum"); + return false; + } - complain(ps, "Expected }; at end of enum"); - return false; + if (!tok_ignore_attribute(ps)) + return false; + + if (!tok_take_if(&ps->toks, ";")) { + complain(ps, "Expected ; at end of enum"); + return false; + } + return true; } static bool gather_undefines(const char *name, @@ -608,6 +662,8 @@ struct cdump_definitions *cdump_extract(const tal_t *ctx, const char *code, toks = ps.toks = tokenize(ps.defs, code); while (tok_peek(&ps.toks)) { + if (!tok_ignore_attribute(&ps)) + goto fail; if (tok_take_if(&ps.toks, "struct")) { if (!tok_take_conglom(&ps, CDUMP_STRUCT)) goto fail;