summaryrefslogtreecommitdiffabout
path: root/src/cflow.h
blob: 25933980fed94d4af91682851d2b85365cbb2db7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/* This file is part of GNU cflow
   Copyright (C) 1997,2005,2007,2009 Sergey Poznyakoff
 
   GNU cflow is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.
 
   GNU cflow is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public
   License along with GNU cflow; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
   MA 02110-1301 USA */

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include <errno.h>
#define obstack_chunk_alloc xmalloc
#define obstack_chunk_free free
#include <obstack.h>
#include <error.h>
#include <xalloc.h>
#include <gettext.h>

#define _(c) gettext(c)
#define N_(c) c

#if HAVE_LOCALE_H
# include <locale.h>
#endif
#if !HAVE_SETLOCALE
# define setlocale(category, locale) /* empty */
#endif

#define NUMITEMS(a) sizeof(a)/sizeof((a)[0])

struct linked_list_entry {
     struct linked_list_entry *next, *prev;
     struct linked_list *list;
     void *data;
};

typedef void (*linked_list_free_data_fp) (void*);

struct linked_list {
     linked_list_free_data_fp free_data;
     struct linked_list_entry *head, *tail;
};

#define linked_list_head(list) ((list) ? (list)->head : NULL)

enum symtype {
     SymUndefined,  /* Undefined or deleted symbol */
     SymToken,      /* A token */
     SymIdentifier  /* Function or variable */
};

enum storage {
     ExternStorage,
     ExplicitExternStorage,
     StaticStorage,
     AutoStorage,
     AnyStorage
};

typedef struct {
     int line;
     char *source;
} Ref;

enum symbol_flag {
     symbol_none,
     symbol_temp,                  /* Temporary symbol. Must be deleted after
				      processing of the current module */
     symbol_parm                   /* Parameter */
};

typedef struct symbol Symbol;

struct symbol {
     struct table_entry *owner;
     Symbol *next;                 /* Next symbol with the same hash */
     struct linked_list_entry *entry;
     
     enum symtype type;            /* Type of the symbol */
     char *name;                   /* Identifier */
     enum symbol_flag flag;        /* Specific flag */
     
     int active;                   /* Set to 1 when the symbol's subtree is
				      being processed, prevent recursion */
     int expand_line;              /* Output line when this symbol was first
				      expanded */

     int token_type;               /* Type of the token */
     char *source;                 /* Source file */
     int def_line;                 /* Source line */
     struct linked_list *ref_line; /* Referenced in */
     
     int level;                    /* Block nesting level (for local vars),
				      Parameter nesting level (for params) */
     
     char *decl;                   /* Declaration */ 
     enum storage storage;         /* Storage type */
     
     int arity;                    /* Number of parameters or -1 for
				      variables */  
     
     int recursive;                /* Is the function recursive */
     size_t ord;                   /* ordinal number */
     struct linked_list *caller;   /* List of callers */
     struct linked_list *callee;   /* List of callees */
};

/* Output flags */
#define PRINT_XREF 0x01
#define PRINT_TREE 0x02

#ifndef CFLOW_PREPROC
# define CFLOW_PREPROC "/usr/bin/cpp"
#endif

#define MAX_OUTPUT_DRIVERS 8

extern unsigned char *level_mark;
extern FILE *outfile;
extern char *outname;

extern int verbose;
extern int print_option;
extern int use_indentation;
extern int assume_cplusplus;
extern int record_defines;
extern int strict_ansi;
extern char *level_indent[];
extern char *level_end[];
extern char *level_begin;
extern int print_levels;
extern int print_line_numbers;
extern int print_as_tree;
extern int brief_listing;
extern int reverse_tree;
extern int out_line;
extern char *start_name;
extern int max_depth;
extern int emacs_option;
extern int debug;
extern int preprocess_option;
extern int omit_arguments_option;
extern int omit_symbol_names_option;

extern int token_stack_length;
extern int token_stack_increase;

extern int symbol_count;
extern unsigned input_file_count;

Symbol *lookup(char*);
Symbol *install(char*);
Symbol *install_ident(char *name, enum storage storage);
void ident_change_storage(Symbol *sp, enum storage storage);
void delete_autos(int level);
void delete_statics(void);
void delete_parms(int level);
void move_parms(int level);
size_t collect_symbols(Symbol ***, int (*sel)(), size_t rescnt);
size_t collect_functions(Symbol ***return_sym);
struct linked_list *linked_list_create(linked_list_free_data_fp fun);
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);

int data_in_list(void *data, struct linked_list *list);

int get_token(void);
int source(char *name);
void init_lex(int debug_level);
void set_preprocessor(const char *arg);
void pp_option(const char *arg); 

void init_parse(void);
int yyparse(void);

void output(void);
void newline(void);
void print_level(int lev, int last);
int globals_only(void);
int include_symbol(Symbol *sym);
int symbol_is_function(Symbol *sym);

void sourcerc(int *, char ***);

typedef enum {
     cflow_output_init,
     cflow_output_begin,
     cflow_output_end,
     cflow_output_newline,
     cflow_output_separator,
     cflow_output_symbol,
     cflow_output_text
} cflow_output_command;

struct output_symbol {
     int direct;
     int level;
     int last;
     Symbol *sym;
};

int register_output(const char *name,
		    int (*handler) (cflow_output_command cmd,
				    FILE *outfile, int line,
				    void *data, void *handler_data),
		    void *handler_data);
int select_output_driver (const char *name);
void output_init(void);

int gnu_output_handler(cflow_output_command cmd,
		       FILE *outfile, int line,
		       void *data, void *handler_data);
int posix_output_handler(cflow_output_command cmd,
			 FILE *outfile, int line,
			 void *data, void *handler_data);


typedef struct cflow_depmap *cflow_depmap_t;
cflow_depmap_t depmap_alloc(size_t count);
void depmap_set(cflow_depmap_t dmap, size_t row, size_t col);
int depmap_isset(cflow_depmap_t dmap, size_t row, size_t col);
void depmap_tc(cflow_depmap_t dmap);

Return to:

Send suggestions and report system problems to the System administrator.