aboutsummaryrefslogtreecommitdiff
path: root/src/symbol.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>1999-03-31 14:58:14 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>1999-03-31 14:58:14 +0000
commitbd0c52a038bd0d9f486fb04acfcfc8e252eef4c1 (patch)
tree2d5a5b81069bc4b667424ec5d63c9bc0899435d6 /src/symbol.c
parent230324808df6172c93987c3eb03ed60c09d4c657 (diff)
downloadcflow-bd0c52a038bd0d9f486fb04acfcfc8e252eef4c1.tar.gz
cflow-bd0c52a038bd0d9f486fb04acfcfc8e252eef4c1.tar.bz2
*** empty log message ***
Diffstat (limited to 'src/symbol.c')
-rw-r--r--src/symbol.c70
1 files changed, 68 insertions, 2 deletions
diff --git a/src/symbol.c b/src/symbol.c
index cf4a908..bb02e96 100644
--- a/src/symbol.c
+++ b/src/symbol.c
@@ -22,6 +22,7 @@
int hash_size = 509;
Symbol **symtab;
+Symbol *statsym;
typedef struct bucket Bucket;
struct bucket {
@@ -32,6 +33,7 @@ struct bucket {
int bucket_nodes = 512;
Bucket *root_bucket, *last_bucket;
+int symbol_count;
void
set_hash_size(num)
@@ -75,7 +77,7 @@ lookup(s)
Symbol *sp;
for (sp = symtab[hash(s)]; sp != (Symbol *) 0; sp = sp->next)
- if (strcmp(sp->name, s) == 0)
+ if (strcmp(sp->name, s) == 0)
return sp;
return 0;
}
@@ -88,15 +90,52 @@ install(s)
unsigned hc;
sp = (Symbol *) emalloc(sizeof(Symbol));
+ memset(sp, 0, sizeof(*sp));
sp->name = emalloc(strlen(s) + 1);
strcpy(sp->name, s);
sp->type = SymUndefined;
hc = hash(s);
sp->next = symtab[hc];
symtab[hc] = sp;
+ symbol_count++;
return sp;
}
+void
+delete_statics()
+{
+ int i;
+ Symbol *sp;
+
+ for (i = 0; i < hash_size; i++) {
+ if (symtab[i] &&
+ symtab[i]->type == SymFunction &&
+ symtab[i]->v.func.storage == StaticStorage) {
+ /* Delete the entry from the main symbol table */
+ sp = symtab[i];
+ symtab[i] = sp->next;
+ /* Add it to the static symbol list */
+ sp->next = statsym;
+ statsym = sp;
+ }
+ }
+}
+
+void
+delete_autos(level)
+ int level;
+{
+ int i;
+
+ for (i = 0; i < hash_size; i++) {
+ if (symtab[i] &&
+ symtab[i]->type == SymFunction &&
+ symtab[i]->v.func.level == level) {
+ symtab[i] = symtab[i]->next;
+ }
+ }
+}
+
void
alloc_new_bucket()
@@ -119,7 +158,7 @@ alloc_new_bucket()
Consptr
alloc_cons_from_bucket()
{
- if (last_bucket->free == bucket_nodes)
+ if (!last_bucket || last_bucket->free == bucket_nodes)
return NULL;
return &last_bucket->cons[last_bucket->free++];
}
@@ -138,3 +177,30 @@ alloc_cons()
}
return cp;
}
+
+int
+collect_symbols(return_sym, sel)
+ Symbol ***return_sym;
+ int (*sel)();
+{
+ Symbol **sym, *st_ptr;
+ int i, num=0;
+
+ sym = calloc(symbol_count, sizeof(*sym));
+ if (!sym)
+ error(FATAL(2), "not enough core to sort symbols.");
+
+ /* collect usable sybols */
+ for (i = 0; i < hash_size; i++) {
+ for (st_ptr = symtab[i]; st_ptr; st_ptr = st_ptr->next)
+ if (sel(st_ptr))
+ sym[num++] = st_ptr;
+ }
+ if (!globals_only) {
+ for (st_ptr = statsym; st_ptr; st_ptr = st_ptr->next)
+ if (sel(st_ptr))
+ sym[num++] = st_ptr;
+ }
+ *return_sym = sym;
+ return num;
+}

Return to:

Send suggestions and report system problems to the System administrator.