scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit d247bc3fa770720335e31b8d3c735200b2484c30
parent 620b4d63082783d846415b9e240f256f11b16e51
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 11 Mar 2014 16:31:31 +0100

Make type_name void

We do not need anymore the return value of type_name(), because
we can detect when the next element is a type name calling to ahead().

Diffstat:
Mdecl.c | 6+++---
Mexpr.c | 22++++++++++++++++++----
Msyntax.h | 2+-
3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/decl.c b/decl.c @@ -384,7 +384,7 @@ decl(unsigned char ns) } } -bool +void type_name(struct ctype *tp) { struct storage store; @@ -395,9 +395,9 @@ type_name(struct ctype *tp) initqlf(&qlf); if (!specifier(tp, &store, &qlf)) - return false; + return; declarator(tp, NS_TYPE, 0); - return true; + return; } diff --git a/expr.c b/expr.c @@ -93,8 +93,14 @@ unary(void) next(); if (accept('(')) { struct ctype type; - if (!type_name(&type)) + switch (yytoken) { + case STORAGE: case TQUALIFIER: case TYPE: + type_name(&type); + break; + default: expr(); + break; + } expect(')'); } else { unary(); @@ -123,10 +129,18 @@ call_unary: static struct node * cast(void) { + register struct node *np; + struct ctype type; + while (accept('(')) { - struct ctype type; - if (!type_name(&type)) - error("expected a type name"); + switch (yytoken) { + case STORAGE: case TQUALIFIER: case TYPE: + type_name(&type); /* TODO: type_name should return a np*/ + break; + default: + np = expr(); + break; + } expect(')'); } return unary(); diff --git a/syntax.h b/syntax.h @@ -30,7 +30,7 @@ struct compound { extern struct node *expr(void); extern struct node *decl(unsigned char ns); -extern bool type_name(struct ctype *tp); +extern void type_name(struct ctype *tp); extern struct node *function(struct symbol *sym); extern struct node *node(unsigned char op, struct node *l, struct node *r);