cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit a27be60802bbb0ec692c2f92b4b29b856bc55b58
parent 0d1969024c6fd7fa9aa729cf17860d0c172b56e0
Author: Michael Forney <mforney@mforney.org>
Date:   Tue, 13 Aug 2019 17:46:08 -0700

decl: Separate _Static_assert handling to its own function

Diffstat:
Mdecl.c | 36++++++++++++++++++++++--------------
Mtoken.c | 1+
2 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/decl.c b/decl.c @@ -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; diff --git a/token.c b/token.c @@ -56,6 +56,7 @@ const char *tokstr[] = { [T_STATIC_ASSERT] = "_Static_assert", [T_THREAD_LOCAL] = "_Thread_local", [T__ASM__] = "__asm__", + [T__ATTRIBUTE__] = "__attribute__", [T__TYPEOF__] = "__typeof__", /* punctuator */