scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit e33b5c0c4f3d7abd9ab3db4334ba8fa54addd8d1
parent 50bfc145d470d78dfe38594a3a94123375c3a66a
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 28 Oct 2013 21:37:10 +0100

Move decision of when a declaration is vaid to specifier

A statement is a declaration if it has a specifier or type, or
it is a global declaration without specifier and type. We were
checking all the possible conditions about specifiers in specifier(),
so it is a better place than decl() where check it.

Diffstat:
Mdecl.c | 22+++++++++++-----------
1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/decl.c b/decl.c @@ -207,9 +207,13 @@ specifier(void) } /* it is not a type name */ default: - if (!tp) - return NULL; - if (!tp->type) { + if (!tp) { + if (curctx != CTX_OUTER || yytoken != IDEN) + return NULL; + tp = ctype(tp, INT); + warn(options.implicit, + "data definition has no type or storage class"); + } else if (!tp->type) { warn(options.implicit, "type defaults to 'int' in declaration"); tp->type = INT; @@ -316,14 +320,10 @@ decl(void) register struct ctype *base; struct node *np; -repeat: if (!(base = specifier())) { - if (curctx != CTX_OUTER || yytoken != IDEN) - return NULL; - base = newctype(); - base->type = INT; - warn(options.implicit, - "data definition has no type or storage class"); - } else if (accept(';')) { +repeat: if (!(base = specifier())) + return NULL; + + if (accept(';')) { register unsigned char type = base->type; switch (type) {