From: Peep P. <so...@us...> - 2004-06-14 20:53:59
|
Update of /cvsroot/agd/server/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19970 Modified Files: compile.c Log Message: Removed commented and unused code; removed xfree. Index: compile.c =================================================================== RCS file: /cvsroot/agd/server/src/compile.c,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- compile.c 12 Jun 2004 20:06:08 -0000 1.25 +++ compile.c 14 Jun 2004 20:53:49 -0000 1.26 @@ -23,14 +23,6 @@ int compile_errors, compile_warnings; -#if 0 -/* These are arrays to pointers. realloc might - * move the memory segments, and we have - * pointers to this memory - that would get corrupted. */ -def_id_t **local_ids, **global_ids; -int num_local_ids, num_global_ids; -#endif - /* For define_id. */ int scope_level; int numlvars, numgvars, @@ -57,59 +49,6 @@ return h; } -#if 0 -/* define_id functions. */ -def_id_t *define_id(char *name, int type, int lpc_type, int *args, int numarg) -{ - def_id_t *idp; - - idp = xmalloc(sizeof(def_id_t)); - if(type == ID_DFUN) { - num_global_ids++; - global_ids = xrealloc(global_ids, num_global_ids * sizeof(def_id_t*)); - global_ids[num_global_ids - 1] = idp; - } else { - num_local_ids++; - local_ids = xrealloc(local_ids, num_local_ids * sizeof(def_id_t*)); - local_ids[num_local_ids - 1] = idp; - } - - idp->name = stringdup(name); - idp->type = type; - idp->lpc_type = lpc_type; - idp->args = args; - idp->numarg = numarg; - idp->base_scope = scope_level; - switch(type) { - case ID_ARG: - case ID_LVAR: - idp->index = numlvars; - numlvars++; - break; - case ID_GVAR: - idp->index = numgvars; - numgvars++; - break; - case ID_FUN_PROT: - case ID_FUN: - idp->index = numlfuns; - numlfuns++; - break; - case ID_DFUN: - idp->index = numdfuns; - numdfuns++; - break; - } - -#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; -} -#endif - int assign_index(int type) { switch(type) { @@ -173,7 +112,7 @@ } buf = strcat(buf, buf2); comp_error(buf); - xfree(buf); + free(buf); } int redeclaration_allowed(def_id_t *target, int type) @@ -186,6 +125,7 @@ return 1; } + def_id_t *define_id(char *name, int type, int lpc_type, int *args, int num_arg) { unsigned hash; @@ -210,8 +150,10 @@ redeclaration_error(target, type); return; } - - printf("hash collision! \"%s\" && \"%s\" == %d!\n", name, target->name, hash); + +#ifdef DEBUG + debug("define_id", "hash collision! \"%s\" && \"%s\" == %d!\n", name, target->name, hash); +#endif temp = *elem; @@ -263,47 +205,18 @@ def_id_t *idp; unsigned hash = strhash(name); - /* First look in global table. */ - idp = find_elem(gid_tbl, GLOBAL_HASH_SIZE, hash); - if(idp) - return idp; - /* Now look in local table. */ idp = find_elem(lid_tbl, LOCAL_HASH_SIZE, hash); if(idp) return idp; - return NULL; -} - -#if 0 -def_id_t *find_id(char *name) -{ - def_id_t *idp; - int i; - - /* First search in local_ids. */ - for(i=0;i<num_local_ids;i++) { - idp = local_ids[i]; - if(idp->base_scope == -1) { - continue; - } - if(!strcmp(name, idp->name)) - return idp; - } + /* First look in global table. */ + idp = find_elem(gid_tbl, GLOBAL_HASH_SIZE, hash); + if(idp) + return idp; - /* Then global_ids. */ - for(i=0;i<num_global_ids;i++) { - idp = global_ids[i]; - if(idp->base_scope == -1) { - continue; - } - if(!strcmp(name, idp->name)) - return idp; - } return NULL; } -#endif #if 0 void pop_scope() @@ -333,9 +246,9 @@ break; } - xfree(id->name); + free(id->name); if(id->args) - xfree(id->args); + free(id->args); } } } @@ -351,10 +264,10 @@ idp = tbl[i].data; if(idp->base_scope > scope_level) { unassign_index(idp->type); - xfree(idp->name); + free(idp->name); if(idp->args) - xfree(idp->args); - xfree(idp); + free(idp->args); + free(idp); if(tbl[i].next) { list_t *temp; @@ -510,13 +423,16 @@ function_t *f; f = this_prog->functions[idp->index]; f->type = idp->lpc_type; - f->args = idp->args; f->num_arg = idp->num_arg; + f->args = xmalloc(sizeof(int) * f->num_arg); + memcpy(f->args, idp->args, f->num_arg); f->lineno = lineno; } else { curr_fun_check(); curr_fun->type = idp->lpc_type; - curr_fun->args = idp->args; + curr_fun->num_arg = idp->num_arg; + curr_fun->args = xmalloc(sizeof(int) * curr_fun->num_arg); + memcpy(curr_fun->args, idp->args, curr_fun->num_arg); curr_fun->lineno = lineno; this_prog->numfunc++; @@ -556,13 +472,14 @@ v = &this_ob->globals[this_ob->numglobals-1]; v->name = name; v->type = lpc_type; + init_var(v); } else /* LVAR */{ - if(type & T_ARRAY) { + if(lpc_type & T_ARRAY) { add_token(F_PUSH_ARRAY); add_two_tokens(T_VOID, 0); - } else switch(type & ~T_ARRAY) { + } else switch(lpc_type & ~T_ARRAY) { case T_INT: add_two_tokens(F_PUSH_INT, 0); break; - case T_STRING: add_two_tokens(F_PUSH_STRING, 0); break; + case T_STRING: add_two_tokens(F_PUSH_STRING, -1); break; case T_OBJECT: add_token(F_PUSH_NULL_OBJECT); break; } } @@ -625,7 +542,7 @@ sprintf(buf, "function %s has been called, " "but not defined", id->name); comp_error(buf); - xfree(buf); + free(buf); return 1; } @@ -693,13 +610,13 @@ compile_warnings == 1 ? "": "s"); } printf(" - failed\n"); - xfree(this_prog); + free(this_prog); prog = NULL; goto out; } if(check_fun_definitions()) { - xfree(this_prog); + free(this_prog); prog = NULL; goto out; } @@ -729,7 +646,7 @@ out: this_prog = NULL; this_file = NULL; - xfree(real_path); + free(real_path); start_with_newline = 0; return prog; } |