scc

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

commit 7237e9631e196ccca0f772dca2d301d443a019b3
parent 5cd22f4402bc8e5ca8fd4c82740beafaab5f68c3
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat,  8 Mar 2014 14:05:38 +0100

Add namespace parameter to decl()

decl() parses a declaration, that can be an usual declaration of a variable
or a field of a struct of union. The only difference in both cases is
the namespace where symbols are going to be stored, so this is a first
step in order to unify decl() and fielddcl().

Diffstat:
Mdecl.c | 9+++++----
Mflow.c | 2+-
Mmain.c | 2+-
Msymbol.h | 2+-
Msyntax.h | 2+-
5 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/decl.c b/decl.c @@ -325,7 +325,8 @@ initializer(register struct ctype *tp) } static struct node * -listdcl(struct ctype *base, struct storage *store, struct qualifier *qlf) +listdcl(struct ctype *base, + struct storage *store, struct qualifier *qlf, unsigned char ns) { struct compound c; char fun; @@ -337,7 +338,7 @@ listdcl(struct ctype *base, struct storage *store, struct qualifier *qlf) register struct ctype *tp; register struct symbol *sym; - sym = declarator(base, NS_IDEN); + sym = declarator(base, ns); sym->store = *store; sym->qlf = *qlf; sym->ctype = *decl_type(base); @@ -357,7 +358,7 @@ listdcl(struct ctype *base, struct storage *store, struct qualifier *qlf) } struct node * -decl(void) +decl(unsigned char ns) { struct ctype base; struct storage store; @@ -397,7 +398,7 @@ repeat: initctype(&base); return NULL; goto repeat; } - return listdcl(&base, &store, &qlf); + return listdcl(&base, &store, &qlf, ns); } void diff --git a/flow.c b/flow.c @@ -229,7 +229,7 @@ compound(void) expect('{'); new_ctx(); while (!accept('}')) { - if (np = decl()) { + if (np = decl(0)) { if (nodecl) { warn(options.mixdcls, "mixed declarations and code"); diff --git a/main.c b/main.c @@ -19,7 +19,7 @@ main(int argc, char *argv[]) init_keywords(); open_file(NULL); for (next(); yytoken != EOFTOK; run(np)) - np = decl(); + np = decl(0); return 0; } diff --git a/symbol.h b/symbol.h @@ -11,7 +11,7 @@ #define CTX_FUNC 1 enum { - NS_IDEN, + NS_IDEN = 0, NS_KEYWORD, NS_LABEL, NS_TAG diff --git a/syntax.h b/syntax.h @@ -28,7 +28,7 @@ struct compound { }; extern struct node *expr(void); -extern struct node *decl(void); +extern struct node *decl(unsigned char ns); extern void type_name(void); extern struct node *function(struct symbol *sym);