diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cflow.h | 1 | ||||
-rw-r--r-- | src/linked-list.c | 15 | ||||
-rw-r--r-- | src/main.c | 1 | ||||
-rw-r--r-- | src/symbol.c | 35 |
4 files changed, 39 insertions, 13 deletions
diff --git a/src/cflow.h b/src/cflow.h index 5867a18..0e3ee44 100644 --- a/src/cflow.h +++ b/src/cflow.h @@ -195,12 +195,13 @@ void linked_list_destroy(struct linked_list **plist); void linked_list_append(struct linked_list **plist, void *data); void linked_list_prepend(struct linked_list **plist, void *data); void linked_list_iterate(struct linked_list **plist, int (*itr) (void *, void *), void *data); void linked_list_unlink(struct linked_list *list, struct linked_list_entry *ent); +size_t linked_list_size(struct linked_list *list); int data_in_list(void *data, struct linked_list *list); int get_token(void); int source(char *name); void init_lex(int debug_level); diff --git a/src/linked-list.c b/src/linked-list.c index 095b63e..3c57bf0 100644 --- a/src/linked-list.c +++ b/src/linked-list.c @@ -14,13 +14,13 @@ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ #include <cflow.h> static struct linked_list * -deref_linked_list (struct linked_list **plist) +deref_linked_list(struct linked_list **plist) { if (!*plist) { struct linked_list *list = xmalloc(sizeof(*list)); list->free_data = NULL; list->head = list->tail = NULL; *plist = list; @@ -141,6 +141,19 @@ data_in_list(void *data, struct linked_list *list) for (p = linked_list_head(list); p; p = p->next) if (p->data == data) return 1; return 0; } + +size_t +linked_list_size(struct linked_list *list) +{ + size_t size = 0; + if (list) { + struct linked_list_entry *p; + for (p = linked_list_head(list); p; p = p->next) + size++; + } + return size; +} + @@ -644,12 +644,13 @@ parse_opt (int key, char *arg, struct argp_state *state) break; case OPT_NO_VERBOSE: verbose = 0; break; case 'x': print_option = PRINT_XREF; + SYMBOL_EXCLUDE('s'); /* Exclude static symbols by default */ break; case OPT_PREPROCESS: preprocess_option = 1; set_preprocessor(arg ? arg : CFLOW_PREPROC); break; case OPT_NO_PREPROCESS: diff --git a/src/symbol.c b/src/symbol.c index 460f954..5f7dec2 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -294,43 +294,54 @@ collect_processor(void *data, void *proc_data) cd->index++; } } return true; } +static int +collect_list_entry(void *item, void *proc_data) +{ + Symbol *s = item; + struct collect_data *cd = proc_data; + if (cd->sel(s)) { + cd->sym[cd->index] = s; + cd->index++; + } + return 0; +} + size_t collect_symbols(Symbol ***return_sym, int (*sel)(Symbol *p), size_t reserved_slots) { struct collect_data cdata; - - cdata.sym = NULL; + size_t size; + + size = hash_get_n_entries(symbol_table) + + linked_list_size(static_func_list); + cdata.sym = xcalloc(size + reserved_slots, sizeof(*cdata.sym)); cdata.index = 0; cdata.sel = sel; - hash_do_for_each (symbol_table, collect_processor, &cdata); - cdata.sym = calloc(cdata.index + reserved_slots, sizeof(*cdata.sym)); - if (!cdata.sym) - xalloc_die(); - cdata.index = 0; - hash_do_for_each (symbol_table, collect_processor, &cdata); + hash_do_for_each(symbol_table, collect_processor, &cdata); + linked_list_iterate(&static_func_list, collect_list_entry, &cdata); + + cdata.sym = xrealloc(cdata.sym, + (cdata.index + reserved_slots) * sizeof(*cdata.sym)); *return_sym = cdata.sym; return cdata.index; } size_t collect_functions(Symbol ***return_sym) { Symbol **symbols; size_t num, snum; struct linked_list_entry *p; /* Count static functions */ - snum = 0; - if (static_func_list) - for (p = linked_list_head(static_func_list); p; p = p->next) - snum++; + snum = linked_list_size(static_func_list); /* Collect global functions */ num = collect_symbols(&symbols, symbol_is_function, snum); /* Collect static functions */ if (snum) |