From: Peep P. <so...@us...> - 2004-06-12 20:06:16
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25182 Modified Files: compile.c Log Message: Identifiers from a previous compile are now freed. Index: compile.c =================================================================== RCS file: /cvsroot/agd/server/src/compile.c,v retrieving revision 1.24 retrieving revision 1.25 diff -u -d -r1.24 -r1.25 --- compile.c 12 Jun 2004 16:48:00 -0000 1.24 +++ compile.c 12 Jun 2004 20:06:08 -0000 1.25 @@ -233,6 +233,11 @@ idp->base_scope = scope_level; idp->index = assign_index(idp->type); +#ifdef DEBUG + debug("define_id", "%s [hash %u] base_scope %d index %d\n", + idp->name, strhash(idp->name), idp->base_scope, idp->index); +#endif + return idp; } @@ -369,8 +374,8 @@ { scope_level--; +/* clean_ids(gid_tbl, GLOBAL_HASH_SIZE);*/ /* Uhh.. globals don't get *ever* out of scope. */ /* Ok, this is as ugly as it gets.. find another way. */ - clean_ids(gid_tbl, GLOBAL_HASH_SIZE); clean_ids(lid_tbl, LOCAL_HASH_SIZE); } @@ -498,6 +503,8 @@ void add_function(def_id_t *idp, int lineno) { + lineno = 0; /* XXX */ + if(idp->index < this_prog->numfunc) { /* Adding a definition for a prototype. */ function_t *f; @@ -517,7 +524,7 @@ this_prog->functions[this_prog->numfunc-1] = curr_fun; this_prog->fun_table = xrealloc(this_prog->fun_table, this_prog->numfunc * sizeof(char *)); - this_prog->fun_table[this_prog->numfunc-1] = idp->name; + this_prog->fun_table[this_prog->numfunc-1] = stringdup(idp->name); /* Name gets freed later. (by clean_ids()) */ curr_fun = NULL; } @@ -589,6 +596,8 @@ void parse_init(void) { + scope_level = 1; /* So globals are at level 1, and can be cleaned with + scope_level == 0. */ compile_errors = 0; this_ob->numglobals = 0; @@ -634,6 +643,7 @@ { char *real_path; program_t *prog; + int ret; #ifdef DEBUG struct timeval tm, tm2; @@ -670,7 +680,11 @@ } #endif - if(yyparse() > 0 || compile_errors) { + ret = yyparse(); + + pop_scope(); /* Go to scope level 0 and free all identifiers. */ + + if(ret > 0 || compile_errors) { if(compile_errors) { printf("%d error%s", compile_errors, compile_errors == 1 ? "" : "s"); |