scc

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

commit 5a274755b0b8da4357c3ed3193033dcba6f6796d
parent 96a486d98ec1ed5fceae00c6f4f0fb3ff29c8519
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu,  4 Jul 2013 15:53:41 +0200

Add find fuction

This function allows locate a symbol. It is similar to lookup, but it
doesn't allocate the symbol in case of not being present.

Diffstat:
Msymbol.c | 16++++++++++++++++
Msymbol.h | 1+
2 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/symbol.c b/symbol.c @@ -63,6 +63,22 @@ freesyms(void) } struct symbol * +find(const char *s, register char ns) +{ + register struct symbol *sym; + static unsigned char l; + + l = strlen(s); + for (sym = htab[hash(s)]; sym; sym = sym->hash) { + if (ns != NS_ANY && ns != sym->ns) + continue; + if (!memcmp(sym->name, s, l)) + return sym; + } + return NULL; +} + +struct symbol * lookup(register const char *s, char ns) { register struct symbol *sym; diff --git a/symbol.h b/symbol.h @@ -62,6 +62,7 @@ extern void new_ctx(void); extern void del_ctx(void); extern void freesyms(void); extern struct symbol *lookup(register const char *s, char ns); +extern struct symbol *find(register const char *s, char ns); extern void insert(struct symbol *sym, unsigned char ctx); extern void storage(struct ctype *cp, unsigned char mod); extern struct ctype *newctype(void);