aboutsummaryrefslogtreecommitdiffstats
path: root/symbol.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2013-01-25 10:45:14 +0200
committerArnold D. Robbins <arnold@skeeve.com>2013-01-25 10:45:14 +0200
commit5cca2a2d008689dfc415415f71bae1b7b7923bd6 (patch)
tree602e1c942e6d1ca50b57ea03887fb5262838c626 /symbol.c
parent629dd814b6e24e1d5651a82cb53783e651b5ec74 (diff)
downloadegawk-5cca2a2d008689dfc415415f71bae1b7b7923bd6.tar.gz
egawk-5cca2a2d008689dfc415415f71bae1b7b7923bd6.tar.bz2
egawk-5cca2a2d008689dfc415415f71bae1b7b7923bd6.zip
Improve code in symbol.c.
Diffstat (limited to 'symbol.c')
-rw-r--r--symbol.c28
1 files changed, 12 insertions, 16 deletions
diff --git a/symbol.c b/symbol.c
index c775c931..354bfca7 100644
--- a/symbol.c
+++ b/symbol.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);
}