scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 50c78edf22ceb0a91da49921f16d65baef94cdac
parent dda0df0e38cf6b53d4db9b8858ee2dc0e07acc7f
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat,  9 Jan 2016 22:29:14 +0100

Return typedef symbols in struct namespaces

Typedef symbols are stored in NS_IDEN namespace, which is the
default namespace of the lexer. When the definition of struct
type is done, the lexer take the namespace of the struct, and
it means that typedef symbols are not seen in such context,
making impossible to declara fields with typedefed types.

Diffstat:
cc1/symbol.c | 18+++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/cc1/symbol.c b/cc1/symbol.c @@ -243,8 +243,24 @@ lookup(int ns, char *name) if (*t != c || strcmp(t, name)) continue; sns = sym->ns; - if (sns == NS_KEYWORD || sns == NS_CPP || sns == ns) + /* + * CPP namespace has a total priority over the another + * namespaces, because it is a previous pass, + * If we are looking in the CPP namespace, + * we don't want symbols related to keywords or types. + * When a lookup is done in a namespace associated + * to a struct we also want symbols of NS_IDEN which + * are typedef, because in other case we cannot declare + * fields of such types. + */ + if (sns == NS_CPP || sns == ns) return sym; + if (ns == NS_CPP) + continue; + if (sns == NS_KEYWORD || + (sym->flags & ISTYPEDEF) && ns >= NS_STRUCTS) { + return sym; + } } return allocsym(ns, name); }