scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit a0eb6b42c41d7bf2f7a30374f975f927aa78b1d9
parent d7b955f42d01be3dfa590b476287879bf0e046d1
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 16 Aug 2012 19:10:37 +0200

Added freesyms function

This function is intended for remove the memory of the symbols don't used
anymore. These symbols are needed until we print the tree of the compound
statement.

Diffstat:
Msymbol.c | 28++++++++++++++++++++--------
Msymbol.h | 1+
2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/symbol.c b/symbol.c @@ -10,7 +10,7 @@ unsigned char curctx; static struct symbol *htab[NR_SYM_HASH]; -static struct symbol *head; +static struct symbol *head, *headfun; static inline unsigned char @@ -32,20 +32,32 @@ new_ctx(void) void del_ctx(void) { - register struct symbol *sym, *aux; + register struct symbol *sym, *next; static char *s; --curctx; - for (sym = head; sym; sym = aux) { + for (sym = head; sym; sym = next) { if (sym->ctx <= curctx) break; - if ((s = sym->name) != NULL) { + if ((s = sym->name) != NULL) htab[hash(s)] = sym->hash; - free(s); + next = sym->next; + sym->next = headfun; + headfun = sym; + } +} + +void +freesyms(void) +{ + register struct symbol *sym, *next; + + if (curctx == OUTER_CTX) { + for (sym = headfun; sym; sym = next) { + next = sym->next; + free(sym->name); + free(sym); } - aux = sym->next; - free(sym); - /* TODO: unlink type */ } } diff --git a/symbol.h b/symbol.h @@ -55,6 +55,7 @@ extern void pushtype(unsigned char mod); extern unsigned char btype(unsigned char, unsigned char tok); extern void new_ctx(void); extern void del_ctx(void); +extern void freesyms(void); extern struct symbol *install(const char *s); extern struct symbol *lookup(const char *s); extern void ctype(struct ctype *cp, unsigned char mod);