diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2013-01-25 10:45:14 +0200 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2013-01-25 10:45:14 +0200 |
commit | 5cca2a2d008689dfc415415f71bae1b7b7923bd6 (patch) | |
tree | 602e1c942e6d1ca50b57ea03887fb5262838c626 | |
parent | 629dd814b6e24e1d5651a82cb53783e651b5ec74 (diff) | |
download | egawk-5cca2a2d008689dfc415415f71bae1b7b7923bd6.tar.gz egawk-5cca2a2d008689dfc415415f71bae1b7b7923bd6.tar.bz2 egawk-5cca2a2d008689dfc415415f71bae1b7b7923bd6.zip |
Improve code in symbol.c.
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | awk.h | 2 | ||||
-rw-r--r-- | symbol.c | 28 |
3 files changed, 20 insertions, 17 deletions
@@ -1,3 +1,10 @@ +2013-01-23 Arnold D. Robbins <arnold@skeeve.com> + + * awk.h (list_functions): Change parameter to bool. + * symbol.c (list_functions): Ditto. + (get_symbols): Change sort parameter to bool. Additional + code cleanup. + 2013-01-22 Arnold D. Robbins <arnold@skeeve.com> * symbol.c (get_symbols): Reset count after each loop to only @@ -1647,7 +1647,7 @@ extern void pop_context(); extern int in_main_context(); extern void free_context(AWK_CONTEXT *ctxt, bool keep_globals); extern NODE **variable_list(); -extern NODE **function_list(int sort); +extern NODE **function_list(bool sort); extern void print_vars(NODE **table, Func_print print_func, FILE *fp); /* floatcomp.c */ @@ -366,13 +366,13 @@ typedef enum { FUNCTION = 1, VARIABLE } SYMBOL_TYPE; /* get_symbols --- return a list of optionally sorted symbols */ static NODE ** -get_symbols(SYMBOL_TYPE what, int sort) +get_symbols(SYMBOL_TYPE what, bool sort) { int i; NODE **table; NODE **list; NODE *r; - long j, count = 0; + long count = 0; long max; NODE *the_table; @@ -384,38 +384,34 @@ get_symbols(SYMBOL_TYPE what, int sort) */ if (what == FUNCTION) { - count = func_count; the_table = func_table; - max = the_table->table_size * 2; + list = assoc_list(the_table, "@unsorted", ASORTI); - emalloc(table, NODE **, (count + 1) * sizeof(NODE *), "get_symbols"); + emalloc(table, NODE **, (func_count + 1) * sizeof(NODE *), "get_symbols"); - for (i = j = 0; i < max; i += 2) { + for (i = count = 0; i < max; i += 2) { r = list[i+1]; if (r->type == Node_ext_func) continue; assert(r->type == Node_func); - table[j++] = r; + table[count++] = r; } - count = j; } else { /* what == VARIABLE */ - the_table = symbol_table; - count = var_count; - update_global_values(); + the_table = symbol_table; max = the_table->table_size * 2; + list = assoc_list(the_table, "@unsorted", ASORTI); - emalloc(table, NODE **, (count + 1) * sizeof(NODE *), "get_symbols"); + emalloc(table, NODE **, (var_count + 1) * sizeof(NODE *), "get_symbols"); - for (i = j = 0; i < max; i += 2) { + for (i = count = 0; i < max; i += 2) { r = list[i+1]; if (r->type == Node_val) /* non-variable in SYMTAB */ continue; - table[j++] = r; + table[count++] = r; } - count = j; } efree(list); @@ -438,7 +434,7 @@ variable_list() /* function_list --- list of functions */ NODE ** -function_list(int sort) +function_list(bool sort) { return get_symbols(FUNCTION, sort); } |