~ubuntu-branches/ubuntu/feisty/cproto/feisty

« back to all changes in this revision

Viewing changes to cproto.h

  • Committer: Bazaar Package Importer
  • Author(s): Carsten Leonhardt
  • Date: 2000-09-02 21:14:55 UTC
  • Revision ID: james.westby@ubuntu.com-20000902211455-ixe8p17zhnuk6jft
Tags: upstream-4.6d
ImportĀ upstreamĀ versionĀ 4.6d

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: cproto.h,v 4.6 1998/01/19 00:49:16 cthuang Exp $
 
2
 *
 
3
 * Declarations for C function prototype generator
 
4
 */
 
5
#ifndef CPROTO_H
 
6
#define CPROTO_H
 
7
 
 
8
#ifdef HAVE_CONFIG_H
 
9
#include "config.h"
 
10
#endif
 
11
 
 
12
#include "system.h"
 
13
 
 
14
#if HAVE_LIBDMALLOC || HAVE_LIBDBMALLOC || defined(DOALLOC)
 
15
#undef  NO_LEAKS
 
16
#define NO_LEAKS 1
 
17
#endif
 
18
 
 
19
#ifdef  lint
 
20
#define NEW(type)       (type *)0
 
21
#else
 
22
#define NEW(type)       (type *)xmalloc(sizeof(type))
 
23
#endif
 
24
 
 
25
/* Useful constants (mainly to avoid problems balancing parentheses...) */
 
26
#define ELLIPSIS      "..."
 
27
#define PAREN_L       '('
 
28
#define PAREN_R       ')'
 
29
#define SQUARE_L      '['
 
30
#define SQUARE_R      ']'
 
31
#define CURL_L        '{'
 
32
#define CURL_R        '}'
 
33
#define COMMENT_BEGIN "/*"
 
34
#define COMMENT_END   "*/"
 
35
 
 
36
/* Boolean type */
 
37
typedef char boolean;
 
38
 
 
39
/* Source file text */
 
40
typedef struct text {
 
41
    char text[MAX_TEXT_SIZE];   /* source text */
 
42
    long begin;                 /* offset in temporary file */
 
43
} Text;
 
44
 
 
45
/* This is a list of function parameters. */
 
46
typedef struct parameter_list {
 
47
    struct parameter *first;    /* pointer to first parameter in list */
 
48
    struct parameter *last;     /* pointer to last parameter in list */  
 
49
    long begin_comment;         /* begin offset of comment */
 
50
    long end_comment;           /* end offset of comment */
 
51
    char *comment;              /* comment at start of parameter list */
 
52
} ParameterList;
 
53
 
 
54
/* Declaration specifier flags */
 
55
#define DS_NONE         0       /* default */
 
56
#define DS_EXTERN       1       /* contains "extern" specifier */
 
57
#define DS_STATIC       2       /* contains "static" specifier */
 
58
#define DS_CHAR         4       /* contains "char" type specifier */
 
59
#define DS_SHORT        8       /* contains "short" type specifier */
 
60
#define DS_FLOAT        16      /* contains "float" type specifier */
 
61
#define DS_JUNK         32      /* we're not interested in this declaration */
 
62
 
 
63
/* This structure stores information about a declaration specifier. */
 
64
typedef struct decl_spec {
 
65
    unsigned short flags;       /* flags defined above */
 
66
    char *text;                 /* source text */
 
67
    long begin;                 /* offset in temporary file */
 
68
} DeclSpec;
 
69
 
 
70
/* Styles of function definitions */
 
71
#if OPT_LINTLIBRARY
 
72
#define FUNC_UNKNOWN            -1      /* unspecified */
 
73
#else
 
74
#define FUNC_UNKNOWN            0       /* unspecified (same as FUNC_NONE) */
 
75
#endif
 
76
#define FUNC_NONE               0       /* not a function definition */
 
77
#define FUNC_TRADITIONAL        1       /* traditional style */
 
78
#define FUNC_ANSI               2       /* ANSI style */
 
79
#define FUNC_BOTH               3       /* both styles */
 
80
typedef int FuncDefStyle;
 
81
 
 
82
/* This structure stores information about a declarator. */
 
83
typedef struct declarator {
 
84
    char *name;                         /* name of variable or function */
 
85
    char *text;                         /* source text */
 
86
    long begin;                         /* offset in temporary file */
 
87
    long begin_comment;                 /* begin offset of comment */
 
88
    long end_comment;                   /* end offset of comment */
 
89
    FuncDefStyle func_def;              /* style of function definition */
 
90
    ParameterList params;               /* function parameters */
 
91
    boolean pointer;                    /* TRUE if it declares a pointer */
 
92
    struct declarator *head;            /* head function declarator */
 
93
    struct declarator *func_stack;      /* stack of function declarators */
 
94
    struct declarator *next;            /* next declarator in list */
 
95
} Declarator;
 
96
 
 
97
/* This is a list of declarators. */
 
98
typedef struct declarator_list {
 
99
    Declarator *first;          /* pointer to first declarator in list */
 
100
    Declarator *last;           /* pointer to last declarator in list */  
 
101
} DeclaratorList;
 
102
 
 
103
/* This structure stores information about a function parameter. */
 
104
typedef struct parameter {
 
105
    struct parameter *next;     /* next parameter in list */
 
106
    DeclSpec decl_spec;
 
107
    Declarator *declarator;
 
108
    char *comment;              /* comment following the parameter */
 
109
} Parameter;
 
110
 
 
111
/* parser stack entry type */
 
112
typedef union {
 
113
    Text text;
 
114
    DeclSpec decl_spec;
 
115
    Parameter *parameter;
 
116
    ParameterList param_list;
 
117
    Declarator *declarator;
 
118
    DeclaratorList decl_list;
 
119
} YYSTYPE;
 
120
 
 
121
/* Prototype styles */
 
122
#if OPT_LINTLIBRARY
 
123
#define PROTO_ANSI_LLIB         -2      /* form ANSI lint-library source */
 
124
#define PROTO_LINTLIBRARY       -1      /* form lint-library source */
 
125
#endif
 
126
#define PROTO_NONE              0       /* do not output any prototypes */
 
127
#define PROTO_TRADITIONAL       1       /* comment out parameters */
 
128
#define PROTO_ABSTRACT          2       /* comment out parameter names */
 
129
#define PROTO_ANSI              3       /* ANSI C prototype */
 
130
typedef int PrototypeStyle;
 
131
 
 
132
#define ansiLintLibrary() (proto_style == PROTO_ANSI_LLIB)
 
133
#define knrLintLibrary()  (proto_style == PROTO_LINTLIBRARY)
 
134
#define lintLibrary()     (knrLintLibrary() || ansiLintLibrary())
 
135
 
 
136
/* The role of a function declarator */
 
137
#define FUNC_OTHER      0       /* miscellaneous declaration */
 
138
#define FUNC_PROTO      1       /* prototype */
 
139
#define FUNC_DEF        2       /* function definition */
 
140
typedef int FuncDeclRole;
 
141
 
 
142
/* Prototype/function definition output formats */
 
143
#define FMT_OTHER               0       /* miscellaneous */
 
144
#define FMT_PROTO               1       /* prototype */
 
145
#define FMT_FUNC                2       /* function definition */
 
146
#define FMT_FUNC_COMMENT        3       /* func. def. with parameter comments */
 
147
typedef int FuncFormatType;
 
148
 
 
149
/* select scope of declarations to output */
 
150
#define SCOPE_STATIC    1       /* only output declarations with local scope */
 
151
#define SCOPE_EXTERN    2       /* only output declarations with global scope */
 
152
#define SCOPE_ALL       3       /* output all declarations */
 
153
typedef int Scope;
 
154
 
 
155
/* Prototype/function definition output format */
 
156
typedef struct func_format {
 
157
    char *decl_spec_prefix;     /* output before declaration specifier */
 
158
    char *declarator_prefix;    /* output before declarator name */
 
159
    char *declarator_suffix;    /* output before '(' of parameter list */
 
160
    char *first_param_prefix;   /* output before first parameter */
 
161
    char *middle_param_prefix;  /* output before each subsequent parameter */
 
162
    char *last_param_suffix;    /* output after last parameter */
 
163
} FuncFormat;
 
164
 
 
165
/* Program options */
 
166
extern boolean extern_out;
 
167
extern Scope scope_out;
 
168
#if OPT_LINTLIBRARY
 
169
extern boolean types_out;
 
170
extern boolean lint_shadowed;
 
171
#endif
 
172
extern boolean variables_out;
 
173
extern boolean promote_param;
 
174
extern PrototypeStyle proto_style;
 
175
extern FuncDefStyle func_style;
 
176
extern boolean proto_macro;
 
177
extern boolean define_macro;
 
178
extern char *macro_name;
 
179
extern boolean proto_comments;
 
180
extern boolean file_comments;
 
181
extern boolean quiet;
 
182
extern char *func_directive;
 
183
extern int num_inc_dir;
 
184
extern char *inc_dir[];
 
185
extern FuncFormat fmt[4];
 
186
 
 
187
/* Global declarations */
 
188
extern char *progname;
 
189
extern int varargs_num;         /* supports varargs-comment */
 
190
extern char *varargs_str;       /* additional info, such as PRINTFLIKEnn */
 
191
extern int extern_in;           /* supports "LINT_EXTERNnn" */
 
192
extern int exitlike_func;       /* supports noreturn-attribute */
 
193
extern int in_include;          /* current include-level */
 
194
extern int debug_trace;
 
195
extern char base_file[];
 
196
 
 
197
/* cproto.c */
 
198
#if HAVE_LIBDBMALLOC
 
199
extern void ExitProgram     ARGS((int code));
 
200
#define exit(code) ExitProgram(code)
 
201
#endif
 
202
#if !HAVE_LIBDMALLOC
 
203
#ifdef NO_LEAKS
 
204
extern char *xMalloc        ARGS((unsigned n, char *f, int l));
 
205
extern char *xStrdup        ARGS((char *s,    char *f, int l));
 
206
#define xmalloc(n)          xMalloc(n, __FILE__, __LINE__)
 
207
#define xstrdup(s)          xStrdup(s, __FILE__, __LINE__)
 
208
#else
 
209
extern char *xmalloc        ARGS((unsigned n));
 
210
extern char *xstrdup        ARGS((char *src));
 
211
#endif
 
212
#endif /* !HAVE_LIBDMALLOC */
 
213
extern void put_error       ARGS((void));
 
214
extern int is_path_sep      ARGS((int ch));
 
215
extern char *trim_path_sep  ARGS((char *s));
 
216
 
 
217
/* lintlibs.c */
 
218
#if OPT_LINTLIBRARY
 
219
extern void put_string      ARGS((FILE *outf, char *s));
 
220
extern void put_char        ARGS((FILE *outf, int c));
 
221
extern void put_newline     ARGS((FILE *outf));
 
222
extern void put_blankline   ARGS((FILE *outf));
 
223
extern void put_padded      ARGS((FILE *outf, char *s));
 
224
extern void fmt_library     ARGS((int code));
 
225
extern void begin_tracking  ARGS((void));
 
226
extern int already_declared ARGS((char *name));
 
227
extern void track_in        ARGS((void));
 
228
extern int want_typedef     ARGS((void));
 
229
extern void begin_typedef   ARGS((void));
 
230
extern void copy_typedef    ARGS((char *s));
 
231
extern void end_typedef     ARGS((void));
 
232
extern void imply_typedef   ARGS((char *s));
 
233
extern char *implied_typedef ARGS((void));
 
234
extern void indent          ARGS((FILE *outf));
 
235
extern int lint_ellipsis    ARGS((Parameter *p));
 
236
#if OPT_LINTLIBRARY
 
237
extern void flush_varargs   ARGS((void));
 
238
#else
 
239
#define flush_varargs() /* nothing */
 
240
#endif
 
241
extern void ellipsis_varargs ARGS((Declarator *d));
 
242
extern char *supply_parm    ARGS((int count));
 
243
extern int is_actual_func   ARGS((Declarator *d));
 
244
extern void put_body        ARGS((FILE *outf, DeclSpec *decl_spec, Declarator *declarator));
 
245
# ifdef NO_LEAKS
 
246
extern void free_lintlibs   ARGS((void));
 
247
# endif
 
248
#else
 
249
#define put_string(fp,S)    fputs(S, fp)
 
250
#define put_char(fp,C)      fputc(C, fp)
 
251
#define put_padded(fp,S)    fprintf(fp, "%s ", S)
 
252
#define put_body(fp,s,d)    put_string(fp,";\n")
 
253
#define track_in()
 
254
#define begin_typedef()
 
255
#define copy_typedef()
 
256
#define end_typedef()
 
257
#define imply_typedef(s)
 
258
#define implied_typedef()   ((char *)0)
 
259
#endif
 
260
 
 
261
/* strkey.c */
 
262
extern char *strkey         ARGS((char *src, char *key));
 
263
extern void strcut          ARGS((char *src, char *key));
 
264
 
 
265
/* grammar.y */
 
266
extern boolean is_typedef_name ARGS((char *name));
 
267
extern char *cur_file_name  ARGS((void));
 
268
extern unsigned cur_line_num ARGS((void));
 
269
extern FILE *cur_tmp_file   ARGS((void));
 
270
extern void cur_file_changed ARGS((void));
 
271
extern long cur_begin_comment ARGS((void));
 
272
extern char *cur_text       ARGS((void));
 
273
extern void pop_file        ARGS((int closed));
 
274
extern void init_parser     ARGS((void));
 
275
extern void process_file    ARGS((FILE *infile, char *name));
 
276
#ifdef NO_LEAKS
 
277
extern void free_parser     ARGS((void));
 
278
#endif
 
279
 
 
280
#endif /* CPROTO_H */