diff options
author | Michael Forney <mforney@mforney.org> | 2019-08-13 17:46:08 -0700 |
---|---|---|
committer | Michael Forney <mforney@mforney.org> | 2019-08-13 17:46:08 -0700 |
commit | a27be60802bbb0ec692c2f92b4b29b856bc55b58 (patch) | |
tree | 507bd9526eac59f03649c19b33e1ee475ef0c7ae /decl.c | |
parent | 0d1969024c6fd7fa9aa729cf17860d0c172b56e0 (diff) |
decl: Separate _Static_assert handling to its own function
Diffstat (limited to 'decl.c')
-rw-r--r-- | decl.c | 36 |
1 files changed, 22 insertions, 14 deletions
@@ -864,6 +864,27 @@ declcommon(struct scope *s, enum declkind kind, char *name, char *asmname, struc return d; } +static bool +staticassert(struct scope *s) +{ + struct expr *e; + uint64_t c; + + if (!consume(T_STATIC_ASSERT)) + return false; + expect(TLPAREN, "after _Static_assert"); + c = intconstexpr(s, true); + expect(TCOMMA, "after static assertion expression"); + e = assignexpr(s); + if (!e->decayed || e->base->kind != EXPRSTRING) + error(&tok.loc, "expected string literal after static assertion expression"); + if (!c) + error(&tok.loc, "static assertion failed: %.*s", (int)e->base->string.size, e->base->string.data); + expect(TRPAREN, "after static assertion message"); + expect(TSEMICOLON, "after static assertion"); + return true; +} + bool decl(struct scope *s, struct func *f) { @@ -878,23 +899,10 @@ decl(struct scope *s, struct func *f) int allowfunc = !f; struct decl *d, *prior; enum declkind kind; - struct expr *e; - uint64_t c; int align; - if (consume(T_STATIC_ASSERT)) { - expect(TLPAREN, "after _Static_assert"); - c = intconstexpr(s, true); - expect(TCOMMA, "after static assertion expression"); - e = assignexpr(s); - if (!e->decayed || e->base->kind != EXPRSTRING) - error(&tok.loc, "expected string literal after static assertion expression"); - if (!c) - error(&tok.loc, "static assertion failed: %.*s", (int)e->base->string.size, e->base->string.data); - expect(TRPAREN, "after static assertion message"); - expect(TSEMICOLON, "after static assertion"); + if (staticassert(s)) return true; - } base = declspecs(s, &sc, &fs, &align); if (!base.type) return false; |