commit 529349a0c7457739a1d78497a0ccc7e7d7b20dd7
parent b98160148d250038b96881edf166880a2eb3d76e
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Thu, 31 Oct 2013 07:59:12 +0100
Simplify listdcl function
We have two different cases in listdcl, variables and functions.
When we have a variable we can find a initializer, but when you have
a function you can have the body of the function. This simplification
allows to have a linear code and a common exit point.
Since this construction is very uncommon, I think isn't a big
problem and we can 'extend' the language in this direction ;).
Diffstat:
M | decl.c | | | 20 | +++++++++++--------- |
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/decl.c b/decl.c
@@ -266,6 +266,9 @@ declarator(struct ctype *tp, unsigned char ns)
static struct node *
initializer(register struct ctype *tp)
{
+ if (!accept('='))
+ return NULL;
+ next();
if (accept('{')) {
struct compound c;
@@ -287,11 +290,12 @@ static struct node *
listdcl(struct ctype *base, struct storage *store)
{
struct compound c;
+ char fun;
c.tree = NULL;
do {
- struct node *np;
+ struct node *np, *aux;
register struct ctype *tp;
declarator(base, NS_IDEN);
@@ -301,15 +305,13 @@ listdcl(struct ctype *base, struct storage *store)
error("declaration of variable with incomplete type");
np = nodesym(cursym);
- if (tp->type == FTN && yytoken == '{') {
- np = node(ODEF, np, function(cursym));
- return addstmt(&c, np);
- }
- np = node(ODEF, np, accept('=') ? initializer(tp) : NULL);
- addstmt(&c, np);
- } while (accept(','));
+ fun = tp->type == FTN && yytoken == '{';
+ aux = fun ? function(cursym) : initializer(tp);
+ addstmt(&c, node(ODEF, np, aux));
+ } while (!fun && accept(','));
- expect(';');
+ if (!fun)
+ expect(';');
return c.tree;
}