ref: 139e71769f1473cf942b020d4eb60cf6221f6db9
parent: ac28fe221439795f74be808040767bb112017659
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Mar 17 17:42:21 EDT 2014
Fix namespace of enumeration constants Enumeration constants are in the same name space that identifiers, so do not use the ns field of the type struct.
--- a/decl.c
+++ b/decl.c
@@ -10,6 +10,9 @@
#include "symbol.h"
#include "machine.h"
+#define ID_EXPECTED 1
+#define ID_ACCEPTED 2
+
int8_t forbid_eof;
struct dcldata {
@@ -72,7 +75,7 @@
expect(')');
} else if (flags) {
if (yytoken != IDEN) {
- if (flags > 0)
+ if (flags & ID_EXPECTED)
goto expected;
sym = install(NULL, ns);
} else {
@@ -250,7 +253,6 @@
}
}
-/* TODO: add define for the 3 parameter of declarator */
/* TODO: bitfields */
static void
@@ -330,7 +332,7 @@
if (yytoken != ';') {
do {
- sym = declarator(tp, ns, 1);
+ sym = declarator(tp, ns, ID_EXPECTED);
newfield(tp, sym);
} while (accept(','));
}
@@ -407,7 +409,7 @@
while (yytoken != '}') {
if (yytoken != IDEN)
goto iden_expected;
- sym = newiden(namespace);
+ sym = newiden(NS_IDEN);
sym->type = inttype;
if (accept('='))
initializer(inttype);
@@ -439,7 +441,7 @@
tp = specifier(&sclass);
if (yytoken != ';') {
do {
- sym = declarator(tp, NS_IDEN, 1);
+ sym = declarator(tp, NS_IDEN, ID_EXPECTED);
/* assign storage class */
if (accept('='))
initializer(sym->type);
@@ -453,7 +455,7 @@
struct node *
typename(void)
{
- declarator(specifier(NULL), NS_IDEN, -1)->type;
+ declarator(specifier(NULL), NS_IDEN, 0);
return NULL;
}
@@ -487,7 +489,7 @@
if (yytoken != ';') {
do {
extern void printtype(struct ctype *tp);
- sym = declarator(tp, NS_IDEN, 1);
+ sym = declarator(tp, NS_IDEN, ID_EXPECTED);
printtype(sym->type);
/* assign storage class */
if (isfun(sym)) {
--- a/symbol.c
+++ b/symbol.c
@@ -98,6 +98,7 @@
sym->name = s;
sym->ctx = curctx;
sym->token = IDEN;
+ sym->ns = ns;
tbl = &symtab[(ns >= NR_NAMESPACES) ? NS_IDEN : ns];
sym->next = tbl->head;
tbl->head = sym;