ref: a0eb6b42c41d7bf2f7a30374f975f927aa78b1d9
parent: d7b955f42d01be3dfa590b476287879bf0e046d1
author: Roberto E. Vargas Caballero <[email protected]>
date: Thu Aug 16 15:10:37 EDT 2012
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.
--- 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 @@
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 */
}
}
--- a/symbol.h
+++ b/symbol.h
@@ -55,6 +55,7 @@
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);