ref: 7237e9631e196ccca0f772dca2d301d443a019b3
parent: 5cd22f4402bc8e5ca8fd4c82740beafaab5f68c3
author: Roberto E. Vargas Caballero <[email protected]>
date: Sat Mar 8 09:05:38 EST 2014
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().
--- a/decl.c
+++ b/decl.c
@@ -325,7 +325,8 @@
}
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 @@
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 @@
}
struct node *
-decl(void)
+decl(unsigned char ns)
{
struct ctype base;
struct storage store;
@@ -397,7 +398,7 @@
return NULL;
goto repeat;
}
- return listdcl(&base, &store, &qlf);
+ return listdcl(&base, &store, &qlf, ns);
}
void
--- a/flow.c
+++ b/flow.c
@@ -229,7 +229,7 @@
expect('{');
new_ctx();
while (!accept('}')) {
- if (np = decl()) {
+ if (np = decl(0)) {
if (nodecl) {
warn(options.mixdcls,
"mixed declarations and code");
--- a/main.c
+++ b/main.c
@@ -19,7 +19,7 @@
init_keywords();
open_file(NULL);
for (next(); yytoken != EOFTOK; run(np))
- np = decl();
+ np = decl(0);
return 0;
}
--- 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
--- a/syntax.h
+++ b/syntax.h
@@ -28,7 +28,7 @@
};
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);