commit 804ee8287281ddb95bf676825021f944a6fbe398
parent 4292e620e8f4305403a0ef59a7b41b48354314be
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Fri, 29 Jun 2012 10:55:40 +0200
Split decl into decl and listdcl
This split improves the code because simplify the logic of the different
warnings (we don't need to use the nd variable for counting the number of
declarations).
Diffstat:
M | decl.c | | | 51 | +++++++++++++++++++++++++++------------------------ |
1 file changed, 27 insertions(+), 24 deletions(-)
diff --git a/decl.c b/decl.c
@@ -119,41 +119,44 @@ static void declarator(void)
pushtype(*bp);
}
+static void listdcl(register struct ctype *cp)
+{
+ register struct type *tp;
+
+ do {
+ declarator();
+ tp = decl_type(cp->base);
+ if (!tp) {
+ warning_error(user_opt.implicit_int,
+ "type defaults to 'int' in declaration of '%s'",
+ yytext);
+ }
+ if (tp->op == FTN && yytoken == '{') {
+ compound();
+ return;
+ }
+ } while (accept(','));
+}
+
unsigned char decl(void)
{
- auto struct ctype ctype;
- auto struct type *tp;
- auto unsigned char nd = 0;
+ static struct ctype ctype;
if (accept(';'))
return 1;
if (!spec(&ctype)) {
- if (nested_level == 0)
- warning("data definition has no type or storage class");
- else
+ if (nested_level != 0)
return 0;
+ warning("data definition has no type or storage class");
}
- if (yytoken != ';') {
- do {
- declarator();
- tp = decl_type(ctype.base);
- if (!tp) {
- warning_error(user_opt.implicit_int,
- "type defaults to 'int' in declaration of '%s'",
- yytext);
- }
- if (tp->op == FTN && yytoken == '{') {
- compound();
- return;
- }
- ++nd;
- } while (accept(','));
- }
- expect(';');
- if (nd == 0) {
+ if (yytoken == ';') {
warning_error(user_opt.useless_typename,
"useless type name in empty declaration");
+ } else {
+ listdcl(&ctype);
}
+ expect(';');
+
return 1;
}