aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cflow.h34
-rw-r--r--src/main.c18
-rw-r--r--src/output.c43
-rw-r--r--src/parser.c14
-rw-r--r--src/symbol.c187
5 files changed, 123 insertions, 173 deletions
diff --git a/src/cflow.h b/src/cflow.h
index 7a38682..c6712c9 100644
--- a/src/cflow.h
+++ b/src/cflow.h
@@ -1,5 +1,5 @@
1/* This file is part of GNU cflow 1/* This file is part of GNU cflow
2 Copyright (C) 1997,2005,2007 Sergey Poznyakoff 2 Copyright (C) 1997,2005,2007,2009 Sergey Poznyakoff
3 3
4 GNU cflow is free software; you can redistribute it and/or modify 4 GNU cflow is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
@@ -45,15 +45,19 @@
45 45
46#define NUMITEMS(a) sizeof(a)/sizeof((a)[0]) 46#define NUMITEMS(a) sizeof(a)/sizeof((a)[0])
47 47
48typedef struct cons *Consptr; 48struct linked_list_entry {
49typedef struct cons Cons; 49 struct linked_list_entry *next;
50struct cons { 50 void *data;
51 Consptr car;
52 Consptr cdr;
53}; 51};
54 52
55#define CAR(a) (a)->car 53typedef void (*linked_list_free_data_fp) (void*);
56#define CDR(a) (a)->cdr 54
55struct linked_list {
56 linked_list_free_data_fp free_data;
57 struct linked_list_entry *head, *tail;
58};
59
60#define linked_list_head(list) ((list) ? (list)->head : NULL)
57 61
58enum symtype { 62enum symtype {
59 SymUndefined, /* Undefined or deleted symbol */ 63 SymUndefined, /* Undefined or deleted symbol */
@@ -97,7 +101,7 @@ struct symbol {
97 int token_type; /* Type of the token */ 101 int token_type; /* Type of the token */
98 char *source; /* Source file */ 102 char *source; /* Source file */
99 int def_line; /* Source line */ 103 int def_line; /* Source line */
100 Consptr ref_line; /* Referenced in */ 104 struct linked_list *ref_line; /* Referenced in */
101 105
102 int level; /* Block nesting level (for local vars), 106 int level; /* Block nesting level (for local vars),
103 Parameter nesting level (for params) */ 107 Parameter nesting level (for params) */
@@ -109,8 +113,8 @@ struct symbol {
109 variables */ 113 variables */
110 114
111 int recursive; /* Is the function recursive */ 115 int recursive; /* Is the function recursive */
112 Consptr caller; /* List of callers */ 116 struct linked_list *caller; /* List of callers */
113 Consptr callee; /* List of callees */ 117 struct linked_list *callee; /* List of callees */
114}; 118};
115 119
116/* Output flags */ 120/* Output flags */
@@ -162,10 +166,12 @@ void delete_autos(int level);
162void delete_statics(void); 166void delete_statics(void);
163void delete_parms(int level); 167void delete_parms(int level);
164void move_parms(int level); 168void move_parms(int level);
165void cleanup(void);
166int collect_symbols(Symbol ***, int (*sel)()); 169int collect_symbols(Symbol ***, int (*sel)());
167Consptr append_to_list(Consptr *, void *); 170struct linked_list *linked_list_create(linked_list_free_data_fp fun);
168int symbol_in_list(Symbol *sym, Consptr list); 171void linked_list_destroy(struct linked_list **plist);
172void linked_list_append(struct linked_list **plist, void *data);
173void linked_list_prepend(struct linked_list **plist, void *data);
174int symbol_in_list(Symbol *sym, struct linked_list *list);
169 175
170int get_token(void); 176int get_token(void);
171int source(char *name); 177int source(char *name);
diff --git a/src/main.c b/src/main.c
index cbb472e..b08ccdd 100644
--- a/src/main.c
+++ b/src/main.c
@@ -218,7 +218,7 @@ int preprocess_option = 0; /* Do they want to preprocess sources? */
218 218
219char *start_name = "main"; /* Name of start symbol */ 219char *start_name = "main"; /* Name of start symbol */
220 220
221Consptr arglist; /* List of command line arguments */ 221struct linked_list *arglist; /* List of command line arguments */
222 222
223/* Given the option_type array and (possibly abbreviated) option argument 223/* Given the option_type array and (possibly abbreviated) option argument
224 * find the type corresponding to that argument. 224 * find the type corresponding to that argument.
@@ -487,7 +487,7 @@ set_level_indent(const char *str)
487static void 487static void
488add_name(const char *name) 488add_name(const char *name)
489{ 489{
490 append_to_list(&arglist, (void*) name); 490 linked_list_append(&arglist, (void*) name);
491} 491}
492 492
493static void 493static void
@@ -769,16 +769,18 @@ main(int argc, char **argv)
769 769
770 init(); 770 init();
771 771
772 if (arglist) 772 if (arglist) {
773 /* See comment to cleanup_processor */ 773 struct linked_list_entry *p;
774 for (arglist = CAR(arglist); arglist; arglist = CDR(arglist)) { 774
775 char *s = (char*)CAR(arglist); 775 for (p = arglist->head; p; p = p->next) {
776 char *s = (char*)p->data;
776 if (s[0] == '-') 777 if (s[0] == '-')
777 pp_option(s); 778 pp_option(s);
778 else if (source(s) == 0) 779 else if (source(s) == 0)
779 yyparse(); 780 yyparse();
780 } 781 }
781 782 }
783
782 argc -= index; 784 argc -= index;
783 argv += index; 785 argv += index;
784 786
@@ -790,8 +792,6 @@ main(int argc, char **argv)
790 if (input_file_count == 0) 792 if (input_file_count == 0)
791 error(1, 0, _("no input files")); 793 error(1, 0, _("no input files"));
792 794
793 cleanup();
794
795 output(); 795 output();
796 return 0; 796 return 0;
797} 797}
diff --git a/src/output.c b/src/output.c
index 7e604f4..f33d0ae 100644
--- a/src/output.c
+++ b/src/output.c
@@ -1,5 +1,5 @@
1/* This file is part of GNU cflow 1/* This file is part of GNU cflow
2 Copyright (C) 1997,2005,2007 Sergey Poznyakoff 2 Copyright (C) 1997,2005,2007,2009 Sergey Poznyakoff
3 3
4 GNU cflow is free software; you can redistribute it and/or modify 4 GNU cflow is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
@@ -200,12 +200,13 @@ clear_active(Symbol *sym)
200 200
201/* Cross-reference output */ 201/* Cross-reference output */
202void 202void
203print_refs(char *name, Consptr cons) 203print_refs(char *name, struct linked_list *reflist)
204{ 204{
205 Ref *refptr; 205 Ref *refptr;
206 206 struct linked_list_entry *p;
207 for ( ; cons; cons = CDR(cons)) { 207
208 refptr = (Ref*)CAR(cons); 208 for (p = linked_list_head(reflist); p; p = p->next) {
209 refptr = (Ref*)p->data;
209 fprintf(outfile, "%s %s:%d\n", 210 fprintf(outfile, "%s %s:%d\n",
210 name, 211 name,
211 refptr->source, 212 refptr->source,
@@ -271,7 +272,7 @@ xref_output()
271static void 272static void
272scan_tree(int lev, Symbol *sym) 273scan_tree(int lev, Symbol *sym)
273{ 274{
274 Consptr cons; 275 struct linked_list_entry *p;
275 276
276 if (sym->type == SymUndefined) 277 if (sym->type == SymUndefined)
277 return; 278 return;
@@ -280,8 +281,8 @@ scan_tree(int lev, Symbol *sym)
280 return; 281 return;
281 } 282 }
282 sym->active = 1; 283 sym->active = 1;
283 for (cons = sym->callee; cons; cons = CDR(cons)) { 284 for (p = linked_list_head(sym->callee); p; p = p->next) {
284 scan_tree(lev+1, (Symbol*)CAR(cons)); 285 scan_tree(lev+1, (Symbol*)p->data);
285 } 286 }
286 sym->active = 0; 287 sym->active = 0;
287} 288}
@@ -293,16 +294,16 @@ set_active(Symbol *sym)
293} 294}
294 295
295static int 296static int
296is_printable(Consptr cons) 297is_printable(struct linked_list_entry *p)
297{ 298{
298 return cons != NULL && include_symbol((Symbol*)CAR(cons)); 299 return p != NULL && include_symbol((Symbol*)p->data);
299} 300}
300 301
301static int 302static int
302is_last(Consptr cons) 303is_last(struct linked_list_entry *p)
303{ 304{
304 while (cons = CDR(cons)) 305 while (p = p->next)
305 if (is_printable(cons)) 306 if (is_printable(p))
306 return 0; 307 return 0;
307 return 1; 308 return 1;
308} 309}
@@ -312,7 +313,7 @@ is_last(Consptr cons)
312static void 313static void
313direct_tree(int lev, int last, Symbol *sym) 314direct_tree(int lev, int last, Symbol *sym)
314{ 315{
315 Consptr cons; 316 struct linked_list_entry *p;
316 int rc; 317 int rc;
317 318
318 if (sym->type == SymUndefined 319 if (sym->type == SymUndefined
@@ -325,9 +326,9 @@ direct_tree(int lev, int last, Symbol *sym)
325 if (rc || sym->active) 326 if (rc || sym->active)
326 return; 327 return;
327 set_active(sym); 328 set_active(sym);
328 for (cons = sym->callee; cons; cons = CDR(cons)) { 329 for (p = linked_list_head(sym->callee); p; p = p->next) {
329 set_level_mark(lev+1, is_printable(CDR(cons)));