grammar.y revision 1.1.1.4 1 1.1.1.4 christos /* $NetBSD: grammar.y,v 1.1.1.4 2011/09/10 21:22:07 christos Exp $ */
2 1.1.1.4 christos
3 1.1.1.4 christos /* Id: grammar.y,v 1.3 2010/11/23 01:28:47 tom Exp
4 1.1 christos *
5 1.1 christos * yacc grammar for C function prototype generator
6 1.1 christos * This was derived from the grammar in Appendix A of
7 1.1 christos * "The C Programming Language" by Kernighan and Ritchie.
8 1.1 christos */
9 1.1.1.2 christos %expect 1
10 1.1 christos %token <text> '(' '*' '&'
11 1.1 christos /* identifiers that are not reserved words */
12 1.1 christos T_IDENTIFIER T_TYPEDEF_NAME T_DEFINE_NAME
13 1.1 christos
14 1.1 christos /* storage class */
15 1.1 christos T_AUTO T_EXTERN T_REGISTER T_STATIC T_TYPEDEF
16 1.1 christos /* This keyword included for compatibility with C++. */
17 1.1 christos T_INLINE
18 1.1 christos /* This keyword included for compatibility with GCC */
19 1.1 christos T_EXTENSION
20 1.1 christos
21 1.1 christos /* type specifiers */
22 1.1 christos T_CHAR T_DOUBLE T_FLOAT T_INT T_VOID
23 1.1 christos T_LONG T_SHORT T_SIGNED T_UNSIGNED
24 1.1 christos T_ENUM T_STRUCT T_UNION
25 1.1 christos /* C9X new types */
26 1.1 christos T_Bool T_Complex T_Imaginary
27 1.1 christos
28 1.1 christos /* type qualifiers */
29 1.1 christos T_TYPE_QUALIFIER
30 1.1 christos
31 1.1 christos /* paired square brackets and everything between them: [ ... ] */
32 1.1 christos T_BRACKETS
33 1.1 christos
34 1.1 christos %token
35 1.1 christos /* left brace */
36 1.1 christos T_LBRACE
37 1.1 christos /* all input to the matching right brace */
38 1.1 christos T_MATCHRBRACE
39 1.1 christos
40 1.1 christos /* three periods */
41 1.1 christos T_ELLIPSIS
42 1.1 christos
43 1.1 christos /* constant expression or paired braces following an equal sign */
44 1.1 christos T_INITIALIZER
45 1.1 christos
46 1.1 christos /* string literal */
47 1.1 christos T_STRING_LITERAL
48 1.1 christos
49 1.1 christos /* asm */
50 1.1 christos T_ASM
51 1.1 christos /* ( "string literal" ) following asm keyword */
52 1.1 christos T_ASMARG
53 1.1 christos
54 1.1 christos /* va_dcl from <varargs.h> */
55 1.1 christos T_VA_DCL
56 1.1 christos
57 1.1 christos %type <decl_spec> decl_specifiers decl_specifier
58 1.1 christos %type <decl_spec> storage_class type_specifier type_qualifier
59 1.1 christos %type <decl_spec> struct_or_union_specifier enum_specifier
60 1.1 christos %type <decl_list> init_declarator_list
61 1.1 christos %type <declarator> init_declarator declarator direct_declarator
62 1.1 christos %type <declarator> abs_declarator direct_abs_declarator
63 1.1 christos %type <param_list> parameter_type_list parameter_list
64 1.1 christos %type <parameter> parameter_declaration
65 1.1 christos %type <param_list> opt_identifier_list identifier_list
66 1.1 christos %type <text> struct_or_union pointer opt_type_qualifiers type_qualifier_list
67 1.1 christos any_id identifier_or_ref
68 1.1 christos %type <text> enumeration
69 1.1 christos
70 1.1 christos %{
71 1.1 christos #include <stdio.h>
72 1.1 christos #include <ctype.h>
73 1.1.1.2 christos #include <string.h>
74 1.1.1.2 christos
75 1.1.1.2 christos #define OPT_LINTLIBRARY 1
76 1.1.1.2 christos
77 1.1.1.2 christos #ifndef TRUE
78 1.1.1.2 christos #define TRUE (1)
79 1.1.1.2 christos #endif
80 1.1.1.2 christos
81 1.1.1.2 christos #ifndef FALSE
82 1.1.1.2 christos #define FALSE (0)
83 1.1.1.2 christos #endif
84 1.1.1.2 christos
85 1.1.1.2 christos /* #include "cproto.h" */
86 1.1.1.2 christos #define MAX_TEXT_SIZE 1024
87 1.1.1.2 christos
88 1.1.1.2 christos /* Prototype styles */
89 1.1.1.2 christos #if OPT_LINTLIBRARY
90 1.1.1.2 christos #define PROTO_ANSI_LLIB -2 /* form ANSI lint-library source */
91 1.1.1.2 christos #define PROTO_LINTLIBRARY -1 /* form lint-library source */
92 1.1.1.2 christos #endif
93 1.1.1.2 christos #define PROTO_NONE 0 /* do not output any prototypes */
94 1.1.1.2 christos #define PROTO_TRADITIONAL 1 /* comment out parameters */
95 1.1.1.2 christos #define PROTO_ABSTRACT 2 /* comment out parameter names */
96 1.1.1.2 christos #define PROTO_ANSI 3 /* ANSI C prototype */
97 1.1.1.2 christos
98 1.1.1.2 christos typedef int PrototypeStyle;
99 1.1.1.2 christos
100 1.1.1.2 christos typedef char boolean;
101 1.1.1.2 christos
102 1.1.1.2 christos extern boolean types_out;
103 1.1.1.2 christos extern PrototypeStyle proto_style;
104 1.1.1.2 christos
105 1.1.1.2 christos #define ansiLintLibrary() (proto_style == PROTO_ANSI_LLIB)
106 1.1.1.2 christos #define knrLintLibrary() (proto_style == PROTO_LINTLIBRARY)
107 1.1.1.2 christos #define lintLibrary() (knrLintLibrary() || ansiLintLibrary())
108 1.1.1.2 christos
109 1.1.1.2 christos #if OPT_LINTLIBRARY
110 1.1.1.2 christos #define FUNC_UNKNOWN -1 /* unspecified */
111 1.1.1.2 christos #else
112 1.1.1.2 christos #define FUNC_UNKNOWN 0 /* unspecified (same as FUNC_NONE) */
113 1.1.1.2 christos #endif
114 1.1.1.2 christos #define FUNC_NONE 0 /* not a function definition */
115 1.1.1.2 christos #define FUNC_TRADITIONAL 1 /* traditional style */
116 1.1.1.2 christos #define FUNC_ANSI 2 /* ANSI style */
117 1.1.1.2 christos #define FUNC_BOTH 3 /* both styles */
118 1.1.1.2 christos
119 1.1.1.2 christos typedef int FuncDefStyle;
120 1.1.1.2 christos
121 1.1.1.2 christos /* Source file text */
122 1.1.1.2 christos typedef struct text {
123 1.1.1.2 christos char text[MAX_TEXT_SIZE]; /* source text */
124 1.1.1.2 christos long begin; /* offset in temporary file */
125 1.1.1.2 christos } Text;
126 1.1.1.2 christos
127 1.1.1.2 christos /* Declaration specifier flags */
128 1.1.1.2 christos #define DS_NONE 0 /* default */
129 1.1.1.2 christos #define DS_EXTERN 1 /* contains "extern" specifier */
130 1.1.1.2 christos #define DS_STATIC 2 /* contains "static" specifier */
131 1.1.1.2 christos #define DS_CHAR 4 /* contains "char" type specifier */
132 1.1.1.2 christos #define DS_SHORT 8 /* contains "short" type specifier */
133 1.1.1.2 christos #define DS_FLOAT 16 /* contains "float" type specifier */
134 1.1.1.2 christos #define DS_INLINE 32 /* contains "inline" specifier */
135 1.1.1.2 christos #define DS_JUNK 64 /* we're not interested in this declaration */
136 1.1.1.2 christos
137 1.1.1.2 christos /* This structure stores information about a declaration specifier. */
138 1.1.1.2 christos typedef struct decl_spec {
139 1.1.1.2 christos unsigned short flags; /* flags defined above */
140 1.1.1.2 christos char *text; /* source text */
141 1.1.1.2 christos long begin; /* offset in temporary file */
142 1.1.1.2 christos } DeclSpec;
143 1.1.1.2 christos
144 1.1.1.2 christos /* This is a list of function parameters. */
145 1.1.1.2 christos typedef struct _ParameterList {
146 1.1.1.2 christos struct parameter *first; /* pointer to first parameter in list */
147 1.1.1.2 christos struct parameter *last; /* pointer to last parameter in list */
148 1.1.1.2 christos long begin_comment; /* begin offset of comment */
149 1.1.1.2 christos long end_comment; /* end offset of comment */
150 1.1.1.2 christos char *comment; /* comment at start of parameter list */
151 1.1.1.2 christos } ParameterList;
152 1.1.1.2 christos
153 1.1.1.2 christos /* This structure stores information about a declarator. */
154 1.1.1.2 christos typedef struct _Declarator {
155 1.1.1.2 christos char *name; /* name of variable or function */
156 1.1.1.2 christos char *text; /* source text */
157 1.1.1.2 christos long begin; /* offset in temporary file */
158 1.1.1.2 christos long begin_comment; /* begin offset of comment */
159 1.1.1.2 christos long end_comment; /* end offset of comment */
160 1.1.1.2 christos FuncDefStyle func_def; /* style of function definition */
161 1.1.1.2 christos ParameterList params; /* function parameters */
162 1.1.1.2 christos boolean pointer; /* TRUE if it declares a pointer */
163 1.1.1.2 christos struct _Declarator *head; /* head function declarator */
164 1.1.1.2 christos struct _Declarator *func_stack; /* stack of function declarators */
165 1.1.1.2 christos struct _Declarator *next; /* next declarator in list */
166 1.1.1.2 christos } Declarator;
167 1.1.1.2 christos
168 1.1.1.2 christos /* This structure stores information about a function parameter. */
169 1.1.1.2 christos typedef struct parameter {
170 1.1.1.2 christos struct parameter *next; /* next parameter in list */
171 1.1.1.2 christos DeclSpec decl_spec;
172 1.1.1.2 christos Declarator *declarator;
173 1.1.1.2 christos char *comment; /* comment following the parameter */
174 1.1.1.2 christos } Parameter;
175 1.1.1.2 christos
176 1.1.1.2 christos /* This is a list of declarators. */
177 1.1.1.2 christos typedef struct declarator_list {
178 1.1.1.2 christos Declarator *first; /* pointer to first declarator in list */
179 1.1.1.2 christos Declarator *last; /* pointer to last declarator in list */
180 1.1.1.2 christos } DeclaratorList;
181 1.1.1.2 christos
182 1.1.1.2 christos /* #include "symbol.h" */
183 1.1.1.2 christos typedef struct symbol {
184 1.1.1.2 christos struct symbol *next; /* next symbol in list */
185 1.1.1.2 christos char *name; /* name of symbol */
186 1.1.1.2 christos char *value; /* value of symbol (for defines) */
187 1.1.1.2 christos short flags; /* symbol attributes */
188 1.1.1.2 christos } Symbol;
189 1.1.1.2 christos
190 1.1.1.2 christos /* parser stack entry type */
191 1.1.1.2 christos typedef union {
192 1.1.1.2 christos Text text;
193 1.1.1.2 christos DeclSpec decl_spec;
194 1.1.1.2 christos Parameter *parameter;
195 1.1.1.2 christos ParameterList param_list;
196 1.1.1.2 christos Declarator *declarator;
197 1.1.1.2 christos DeclaratorList decl_list;
198 1.1.1.2 christos } YYSTYPE;
199 1.1.1.2 christos
200 1.1.1.2 christos /* The hash table length should be a prime number. */
201 1.1.1.2 christos #define SYM_MAX_HASH 251
202 1.1.1.2 christos
203 1.1.1.2 christos typedef struct symbol_table {
204 1.1.1.2 christos Symbol *bucket[SYM_MAX_HASH]; /* hash buckets */
205 1.1.1.2 christos } SymbolTable;
206 1.1.1.2 christos
207 1.1.1.2 christos extern SymbolTable *new_symbol_table /* Create symbol table */
208 1.1.1.2 christos (void);
209 1.1.1.2 christos extern void free_symbol_table /* Destroy symbol table */
210 1.1.1.2 christos (SymbolTable *s);
211 1.1.1.2 christos extern Symbol *find_symbol /* Lookup symbol name */
212 1.1.1.2 christos (SymbolTable *s, const char *n);
213 1.1.1.2 christos extern Symbol *new_symbol /* Define new symbol */
214 1.1.1.2 christos (SymbolTable *s, const char *n, const char *v, int f);
215 1.1.1.2 christos
216 1.1.1.2 christos /* #include "semantic.h" */
217 1.1.1.2 christos extern void new_decl_spec (DeclSpec *, const char *, long, int);
218 1.1.1.2 christos extern void free_decl_spec (DeclSpec *);
219 1.1.1.2 christos extern void join_decl_specs (DeclSpec *, DeclSpec *, DeclSpec *);
220 1.1.1.2 christos extern void check_untagged (DeclSpec *);
221 1.1.1.2 christos extern Declarator *new_declarator (const char *, const char *, long);
222 1.1.1.2 christos extern void free_declarator (Declarator *);
223 1.1.1.2 christos extern void new_decl_list (DeclaratorList *, Declarator *);
224 1.1.1.2 christos extern void free_decl_list (DeclaratorList *);
225 1.1.1.2 christos extern void add_decl_list (DeclaratorList *, DeclaratorList *, Declarator *);
226 1.1.1.2 christos extern Parameter *new_parameter (DeclSpec *, Declarator *);
227 1.1.1.2 christos extern void free_parameter (Parameter *);
228 1.1.1.2 christos extern void new_param_list (ParameterList *, Parameter *);
229 1.1.1.2 christos extern void free_param_list (ParameterList *);
230 1.1.1.2 christos extern void add_param_list (ParameterList *, ParameterList *, Parameter *);
231 1.1.1.2 christos extern void new_ident_list (ParameterList *);
232 1.1.1.2 christos extern void add_ident_list (ParameterList *, ParameterList *, const char *);
233 1.1.1.2 christos extern void set_param_types (ParameterList *, DeclSpec *, DeclaratorList *);
234 1.1.1.2 christos extern void gen_declarations (DeclSpec *, DeclaratorList *);
235 1.1.1.2 christos extern void gen_prototype (DeclSpec *, Declarator *);
236 1.1.1.2 christos extern void gen_func_declarator (Declarator *);
237 1.1.1.2 christos extern void gen_func_definition (DeclSpec *, Declarator *);
238 1.1.1.2 christos
239 1.1.1.2 christos extern void init_parser (void);
240 1.1.1.2 christos extern void process_file (FILE *infile, char *name);
241 1.1.1.2 christos extern char *cur_text (void);
242 1.1.1.2 christos extern char *cur_file_name (void);
243 1.1.1.2 christos extern char *implied_typedef (void);
244 1.1.1.2 christos extern void include_file (char *name, int convert);
245 1.1.1.2 christos extern char *supply_parm (int count);
246 1.1.1.2 christos extern char *xstrdup (const char *);
247 1.1.1.2 christos extern int already_declared (char *name);
248 1.1.1.2 christos extern int is_actual_func (Declarator *d);
249 1.1.1.2 christos extern int lint_ellipsis (Parameter *p);
250 1.1.1.2 christos extern int want_typedef (void);
251 1.1.1.2 christos extern void begin_tracking (void);
252 1.1.1.2 christos extern void begin_typedef (void);
253 1.1.1.2 christos extern void copy_typedef (char *s);
254 1.1.1.2 christos extern void ellipsis_varargs (Declarator *d);
255 1.1.1.2 christos extern void end_typedef (void);
256 1.1.1.2 christos extern void flush_varargs (void);
257 1.1.1.2 christos extern void fmt_library (int code);
258 1.1.1.2 christos extern void imply_typedef (const char *s);
259 1.1.1.2 christos extern void indent (FILE *outf);
260 1.1.1.2 christos extern void put_blankline (FILE *outf);
261 1.1.1.2 christos extern void put_body (FILE *outf, DeclSpec *decl_spec, Declarator *declarator);
262 1.1.1.2 christos extern void put_char (FILE *outf, int c);
263 1.1.1.2 christos extern void put_error (void);
264 1.1.1.2 christos extern void put_newline (FILE *outf);
265 1.1.1.2 christos extern void put_padded (FILE *outf, const char *s);
266 1.1.1.2 christos extern void put_string (FILE *outf, const char *s);
267 1.1.1.2 christos extern void track_in (void);
268 1.1.1.2 christos
269 1.1.1.2 christos extern boolean file_comments;
270 1.1.1.2 christos extern FuncDefStyle func_style;
271 1.1.1.2 christos extern char base_file[];
272 1.1 christos
273 1.1 christos #define YYMAXDEPTH 150
274 1.1 christos
275 1.1 christos extern int yylex (void);
276 1.1 christos
277 1.1 christos /* declaration specifier attributes for the typedef statement currently being
278 1.1 christos * scanned
279 1.1 christos */
280 1.1 christos static int cur_decl_spec_flags;
281 1.1 christos
282 1.1 christos /* pointer to parameter list for the current function definition */
283 1.1 christos static ParameterList *func_params;
284 1.1 christos
285 1.1 christos /* A parser semantic action sets this pointer to the current declarator in
286 1.1 christos * a function parameter declaration in order to catch any comments following
287 1.1 christos * the parameter declaration on the same line. If the lexer scans a comment
288 1.1 christos * and <cur_declarator> is not NULL, then the comment is attached to the
289 1.1 christos * declarator. To ignore subsequent comments, the lexer sets this to NULL
290 1.1 christos * after scanning a comment or end of line.
291 1.1 christos */
292 1.1 christos static Declarator *cur_declarator;
293 1.1 christos
294 1.1 christos /* temporary string buffer */
295 1.1 christos static char buf[MAX_TEXT_SIZE];
296 1.1 christos
297 1.1 christos /* table of typedef names */
298 1.1 christos static SymbolTable *typedef_names;
299 1.1 christos
300 1.1 christos /* table of define names */
301 1.1 christos static SymbolTable *define_names;
302 1.1 christos
303 1.1 christos /* table of type qualifiers */
304 1.1 christos static SymbolTable *type_qualifiers;
305 1.1 christos
306 1.1 christos /* information about the current input file */
307 1.1 christos typedef struct {
308 1.1 christos char *base_name; /* base input file name */
309 1.1 christos char *file_name; /* current file name */
310 1.1 christos FILE *file; /* input file */
311 1.1 christos unsigned line_num; /* current line number in input file */
312 1.1 christos FILE *tmp_file; /* temporary file */
313 1.1 christos long begin_comment; /* tmp file offset after last written ) or ; */
314 1.1 christos long end_comment; /* tmp file offset after last comment */
315 1.1 christos boolean convert; /* if TRUE, convert function definitions */
316 1.1 christos boolean changed; /* TRUE if conversion done in this file */
317 1.1 christos } IncludeStack;
318 1.1 christos
319 1.1 christos static IncludeStack *cur_file; /* current input file */
320 1.1 christos
321 1.1.1.2 christos /* #include "yyerror.c" */
322 1.1 christos
323 1.1 christos static int haveAnsiParam (void);
324 1.1 christos
325 1.1 christos
326 1.1 christos /* Flags to enable us to find if a procedure returns a value.
327 1.1 christos */
328 1.1.1.2 christos static int return_val; /* nonzero on BRACES iff return-expression found */
329 1.1 christos
330 1.1.1.2 christos static const char *
331 1.1 christos dft_decl_spec (void)
332 1.1 christos {
333 1.1 christos return (lintLibrary() && !return_val) ? "void" : "int";
334 1.1 christos }
335 1.1 christos
336 1.1 christos static int
337 1.1 christos haveAnsiParam (void)
338 1.1 christos {
339 1.1 christos Parameter *p;
340 1.1 christos if (func_params != 0) {
341 1.1 christos for (p = func_params->first; p != 0; p = p->next) {
342 1.1 christos if (p->declarator->func_def == FUNC_ANSI) {
343 1.1 christos return TRUE;
344 1.1 christos }
345 1.1 christos }
346 1.1 christos }
347 1.1 christos return FALSE;
348 1.1 christos }
349 1.1 christos %}
350 1.1 christos %%
351 1.1 christos
352 1.1 christos program
353 1.1 christos : /* empty */
354 1.1 christos | translation_unit
355 1.1 christos ;
356 1.1 christos
357 1.1 christos translation_unit
358 1.1 christos : external_declaration
359 1.1 christos | translation_unit external_declaration
360 1.1 christos ;
361 1.1 christos
362 1.1 christos external_declaration
363 1.1 christos : declaration
364 1.1 christos | function_definition
365 1.1 christos | ';'
366 1.1 christos | linkage_specification
367 1.1 christos | T_ASM T_ASMARG ';'
368 1.1 christos | error T_MATCHRBRACE
369 1.1 christos {
370 1.1 christos yyerrok;
371 1.1 christos }
372 1.1 christos | error ';'
373 1.1 christos {
374 1.1 christos yyerrok;
375 1.1 christos }
376 1.1 christos ;
377 1.1 christos
378 1.1 christos braces
379 1.1 christos : T_LBRACE T_MATCHRBRACE
380 1.1 christos ;
381 1.1 christos
382 1.1 christos linkage_specification
383 1.1 christos : T_EXTERN T_STRING_LITERAL braces
384 1.1 christos {
385 1.1 christos /* Provide an empty action here so bison will not complain about
386 1.1 christos * incompatible types in the default action it normally would
387 1.1 christos * have generated.
388 1.1 christos */
389 1.1 christos }
390 1.1 christos | T_EXTERN T_STRING_LITERAL declaration
391 1.1 christos {
392 1.1 christos /* empty */
393 1.1 christos }
394 1.1 christos ;
395 1.1 christos
396 1.1 christos declaration
397 1.1 christos : decl_specifiers ';'
398 1.1 christos {
399 1.1 christos #if OPT_LINTLIBRARY
400 1.1 christos if (types_out && want_typedef()) {
401 1.1 christos gen_declarations(&$1, (DeclaratorList *)0);
402 1.1 christos flush_varargs();
403 1.1 christos }
404 1.1 christos #endif
405 1.1 christos free_decl_spec(&$1);
406 1.1 christos end_typedef();
407 1.1 christos }
408 1.1 christos | decl_specifiers init_declarator_list ';'
409 1.1 christos {
410 1.1 christos if (func_params != NULL) {
411 1.1 christos set_param_types(func_params, &$1, &$2);
412 1.1 christos } else {
413 1.1 christos gen_declarations(&$1, &$2);
414 1.1 christos #if OPT_LINTLIBRARY
415 1.1 christos flush_varargs();
416 1.1 christos #endif
417 1.1 christos free_decl_list(&$2);
418 1.1 christos }
419 1.1 christos free_decl_spec(&$1);
420 1.1 christos end_typedef();
421 1.1 christos }
422 1.1 christos | any_typedef decl_specifiers
423 1.1 christos {
424 1.1 christos cur_decl_spec_flags = $2.flags;
425 1.1 christos free_decl_spec(&$2);
426 1.1 christos }
427 1.1 christos opt_declarator_list ';'
428 1.1 christos {
429 1.1 christos end_typedef();
430 1.1 christos }
431 1.1 christos ;
432 1.1 christos
433 1.1 christos any_typedef
434 1.1 christos : T_EXTENSION T_TYPEDEF
435 1.1 christos {
436 1.1 christos begin_typedef();
437 1.1 christos }
438 1.1 christos | T_TYPEDEF
439 1.1 christos {
440 1.1 christos begin_typedef();
441 1.1 christos }
442 1.1 christos ;
443 1.1 christos
444 1.1 christos opt_declarator_list
445 1.1 christos : /* empty */
446 1.1 christos | declarator_list
447 1.1 christos ;
448 1.1 christos
449 1.1 christos declarator_list
450 1.1 christos : declarator
451 1.1 christos {
452 1.1 christos int flags = cur_decl_spec_flags;
453 1.1 christos
454 1.1 christos /* If the typedef is a pointer type, then reset the short type
455 1.1 christos * flags so it does not get promoted.
456 1.1 christos */
457 1.1 christos if (strcmp($1->text, $1->name) != 0)
458 1.1 christos flags &= ~(DS_CHAR | DS_SHORT | DS_FLOAT);
459 1.1 christos new_symbol(typedef_names, $1->name, NULL, flags);
460 1.1 christos free_declarator($1);
461 1.1 christos }
462 1.1 christos | declarator_list ',' declarator
463 1.1 christos {
464 1.1 christos int flags = cur_decl_spec_flags;
465 1.1 christos
466 1.1 christos if (strcmp($3->text, $3->name) != 0)
467 1.1 christos flags &= ~(DS_CHAR | DS_SHORT | DS_FLOAT);
468 1.1 christos new_symbol(typedef_names, $3->name, NULL, flags);
469 1.1 christos free_declarator($3);
470 1.1 christos }
471 1.1 christos ;
472 1.1 christos
473 1.1 christos function_definition
474 1.1 christos : decl_specifiers declarator
475 1.1 christos {
476 1.1 christos check_untagged(&$1);
477 1.1 christos if ($2->func_def == FUNC_NONE) {
478 1.1 christos yyerror("syntax error");
479 1.1 christos YYERROR;
480 1.1 christos }
481 1.1 christos func_params = &($2->head->params);
482 1.1 christos func_params->begin_comment = cur_file->begin_comment;
483 1.1 christos func_params->end_comment = cur_file->end_comment;
484 1.1 christos }
485 1.1 christos opt_declaration_list T_LBRACE
486 1.1 christos {
487 1.1 christos /* If we're converting to K&R and we've got a nominally K&R
488 1.1 christos * function which has a parameter which is ANSI (i.e., a prototyped
489 1.1 christos * function pointer), then we must override the deciphered value of
490 1.1 christos * 'func_def' so that the parameter will be converted.
491 1.1 christos */
492 1.1 christos if (func_style == FUNC_TRADITIONAL
493 1.1 christos && haveAnsiParam()
494 1.1 christos && $2->head->func_def == func_style) {
495 1.1 christos $2->head->func_def = FUNC_BOTH;
496 1.1 christos }
497 1.1 christos
498 1.1 christos func_params = NULL;
499 1.1 christos
500 1.1 christos if (cur_file->convert)
501 1.1 christos gen_func_definition(&$1, $2);
502 1.1 christos gen_prototype(&$1, $2);
503 1.1 christos #if OPT_LINTLIBRARY
504 1.1 christos flush_varargs();
505 1.1 christos #endif
506 1.1 christos free_decl_spec(&$1);
507 1.1 christos free_declarator($2);
508 1.1 christos }
509 1.1 christos T_MATCHRBRACE
510 1.1 christos | declarator
511 1.1 christos {
512 1.1 christos if ($1->func_def == FUNC_NONE) {
513 1.1 christos yyerror("syntax error");
514 1.1 christos YYERROR;
515 1.1 christos }
516 1.1 christos func_params = &($1->head->params);
517 1.1 christos func_params->begin_comment = cur_file->begin_comment;
518 1.1 christos func_params->end_comment = cur_file->end_comment;
519 1.1 christos }
520 1.1 christos opt_declaration_list T_LBRACE T_MATCHRBRACE
521 1.1 christos {
522 1.1 christos DeclSpec decl_spec;
523 1.1 christos
524 1.1 christos func_params = NULL;
525 1.1 christos
526 1.1 christos new_decl_spec(&decl_spec, dft_decl_spec(), $1->begin, DS_NONE);
527 1.1 christos if (cur_file->convert)
528 1.1 christos gen_func_definition(&decl_spec, $1);
529 1.1 christos gen_prototype(&decl_spec, $1);
530 1.1 christos #if OPT_LINTLIBRARY
531 1.1 christos flush_varargs();
532 1.1 christos #endif
533 1.1 christos free_decl_spec(&decl_spec);
534 1.1 christos free_declarator($1);
535 1.1 christos }
536 1.1 christos ;
537 1.1 christos
538 1.1 christos opt_declaration_list
539 1.1 christos : /* empty */
540 1.1 christos | T_VA_DCL
541 1.1 christos | declaration_list
542 1.1 christos ;
543 1.1 christos
544 1.1 christos declaration_list
545 1.1 christos : declaration
546 1.1 christos | declaration_list declaration
547 1.1 christos ;
548 1.1 christos
549 1.1 christos decl_specifiers
550 1.1 christos : decl_specifier
551 1.1 christos | decl_specifiers decl_specifier
552 1.1 christos {
553 1.1 christos join_decl_specs(&$$, &$1, &$2);
554 1.1 christos free($1.text);
555 1.1 christos free($2.text);
556 1.1 christos }
557 1.1 christos ;
558 1.1 christos
559 1.1 christos decl_specifier
560 1.1 christos : storage_class
561 1.1 christos | type_specifier
562 1.1 christos | type_qualifier
563 1.1 christos ;
564 1.1 christos
565 1.1 christos storage_class
566 1.1 christos : T_AUTO
567 1.1 christos {
568 1.1 christos new_decl_spec(&$$, $1.text, $1.begin, DS_NONE);
569 1.1 christos }
570 1.1 christos | T_EXTERN
571 1.1 christos {
572 1.1 christos new_decl_spec(&$$, $1.text, $1.begin, DS_EXTERN);
573 1.1 christos }
574 1.1 christos | T_REGISTER
575 1.1 christos {
576 1.1 christos new_decl_spec(&$$, $1.text, $1.begin, DS_NONE);
577 1.1 christos }
578 1.1 christos | T_STATIC
579 1.1 christos {
580 1.1 christos new_decl_spec(&$$, $1.text, $1.begin, DS_STATIC);
581 1.1 christos }
582 1.1 christos | T_INLINE
583 1.1 christos {
584 1.1 christos new_decl_spec(&$$, $1.text, $1.begin, DS_INLINE);
585 1.1 christos }
586 1.1 christos | T_EXTENSION
587 1.1 christos {
588 1.1 christos new_decl_spec(&$$, $1.text, $1.begin, DS_JUNK);
589 1.1 christos }
590 1.1 christos ;
591 1.1 christos
592 1.1 christos type_specifier
593 1.1 christos : T_CHAR
594 1.1 christos {
595 1.1 christos new_decl_spec(&$$, $1.text, $1.begin, DS_CHAR);
596 1.1 christos }
597 1.1 christos | T_DOUBLE
598 1.1 christos {
599 1.1 christos new_decl_spec(&$$, $1.text, $1.begin, DS_NONE);
600 1.1 christos }
601 1.1 christos | T_FLOAT
602 1.1 christos {
603 1.1 christos new_decl_spec(&$$, $1.text, $1.begin, DS_FLOAT);
604 1.1 christos }
605 1.1 christos | T_INT
606 1.1 christos {
607 1.1 christos new_decl_spec(&$$, $1.text, $1.begin, DS_NONE);
608 1.1 christos }
609 1.1 christos | T_LONG
610 1.1 christos {
611 1.1 christos new_decl_spec(&$$, $1.text, $1.begin, DS_NONE);
612 1.1 christos }
613 1.1 christos | T_SHORT
614 1.1 christos {
615 1.1 christos new_decl_spec(&$$, $1.text, $1.begin, DS_SHORT);
616 1.1 christos }
617 1.1 christos | T_SIGNED
618 1.1 christos {
619 1.1 christos new_decl_spec(&$$, $1.text, $1.begin, DS_NONE);
620 1.1 christos }
621 1.1 christos | T_UNSIGNED
622 1.1 christos {
623 1.1 christos new_decl_spec(&$$, $1.text, $1.begin, DS_NONE);
624 1.1 christos }
625 1.1 christos | T_VOID
626 1.1 christos {
627 1.1 christos new_decl_spec(&$$, $1.text, $1.begin, DS_NONE);
628 1.1 christos }
629 1.1 christos | T_Bool
630 1.1 christos {
631 1.1 christos new_decl_spec(&$$, $1.text, $1.begin, DS_CHAR);
632 1.1 christos }
633 1.1 christos | T_Complex
634 1.1 christos {
635 1.1 christos new_decl_spec(&$$, $1.text, $1.begin, DS_NONE);
636 1.1 christos }
637 1.1 christos | T_Imaginary
638 1.1 christos {
639 1.1 christos new_decl_spec(&$$, $1.text, $1.begin, DS_NONE);
640 1.1 christos }
641 1.1 christos | T_TYPEDEF_NAME
642 1.1 christos {
643 1.1 christos Symbol *s;
644 1.1 christos s = find_symbol(typedef_names, $1.text);
645 1.1 christos if (s != NULL)
646 1.1 christos new_decl_spec(&$$, $1.text, $1.begin, s->flags);
647 1.1 christos }
648 1.1 christos | struct_or_union_specifier
649 1.1 christos | enum_specifier
650 1.1 christos ;
651 1.1 christos
652 1.1 christos type_qualifier
653 1.1 christos : T_TYPE_QUALIFIER
654 1.1 christos {
655 1.1 christos new_decl_spec(&$$, $1.text, $1.begin, DS_NONE);
656 1.1 christos }
657 1.1 christos | T_DEFINE_NAME
658 1.1 christos {
659 1.1 christos /* This rule allows the <pointer> nonterminal to scan #define
660 1.1 christos * names as if they were type modifiers.
661 1.1 christos */
662 1.1 christos Symbol *s;
663 1.1 christos s = find_symbol(define_names, $1.text);
664 1.1 christos if (s != NULL)
665 1.1 christos new_decl_spec(&$$, $1.text, $1.begin, s->flags);
666 1.1 christos }
667 1.1 christos ;
668 1.1 christos
669 1.1 christos struct_or_union_specifier
670 1.1 christos : struct_or_union any_id braces
671 1.1 christos {
672 1.1 christos char *s;
673 1.1 christos if ((s = implied_typedef()) == 0)
674 1.1 christos (void)sprintf(s = buf, "%s %s", $1.text, $2.text);
675 1.1 christos new_decl_spec(&$$, s, $1.begin, DS_NONE);
676 1.1 christos }
677 1.1 christos | struct_or_union braces
678 1.1 christos {
679 1.1 christos char *s;
680 1.1 christos if ((s = implied_typedef()) == 0)
681 1.1 christos (void)sprintf(s = buf, "%s {}", $1.text);
682 1.1 christos new_decl_spec(&$$, s, $1.begin, DS_NONE);
683 1.1 christos }
684 1.1 christos | struct_or_union any_id
685 1.1 christos {
686 1.1 christos (void)sprintf(buf, "%s %s", $1.text, $2.text);
687 1.1 christos new_decl_spec(&$$, buf, $1.begin, DS_NONE);
688 1.1 christos }
689 1.1 christos ;
690 1.1 christos
691 1.1 christos struct_or_union
692 1.1 christos : T_STRUCT
693 1.1 christos {
694 1.1 christos imply_typedef($$.text);
695 1.1 christos }
696 1.1 christos | T_UNION
697 1.1 christos {
698 1.1 christos imply_typedef($$.text);
699 1.1 christos }
700 1.1 christos ;
701 1.1 christos
702 1.1 christos init_declarator_list
703 1.1 christos : init_declarator
704 1.1 christos {
705 1.1 christos new_decl_list(&$$, $1);
706 1.1 christos }
707 1.1 christos | init_declarator_list ',' init_declarator
708 1.1 christos {
709 1.1 christos add_decl_list(&$$, &$1, $3);
710 1.1 christos }
711 1.1 christos ;
712 1.1 christos
713 1.1 christos init_declarator
714 1.1 christos : declarator
715 1.1 christos {
716 1.1 christos if ($1->func_def != FUNC_NONE && func_params == NULL &&
717 1.1 christos func_style == FUNC_TRADITIONAL && cur_file->convert) {
718 1.1 christos gen_func_declarator($1);
719 1.1 christos fputs(cur_text(), cur_file->tmp_file);
720 1.1 christos }
721 1.1 christos cur_declarator = $$;
722 1.1 christos }
723 1.1 christos | declarator '='
724 1.1 christos {
725 1.1 christos if ($1->func_def != FUNC_NONE && func_params == NULL &&
726 1.1 christos func_style == FUNC_TRADITIONAL && cur_file->convert) {
727 1.1 christos gen_func_declarator($1);
728 1.1 christos fputs(" =", cur_file->tmp_file);
729 1.1 christos }
730 1.1 christos }
731 1.1 christos T_INITIALIZER
732 1.1 christos ;
733 1.1 christos
734 1.1 christos enum_specifier
735 1.1 christos : enumeration any_id braces
736 1.1 christos {
737 1.1 christos char *s;
738 1.1 christos if ((s = implied_typedef()) == 0)
739 1.1 christos (void)sprintf(s = buf, "enum %s", $2.text);
740 1.1 christos new_decl_spec(&$$, s, $1.begin, DS_NONE);
741 1.1 christos }
742 1.1 christos | enumeration braces
743 1.1 christos {
744 1.1 christos char *s;
745 1.1 christos if ((s = implied_typedef()) == 0)
746 1.1 christos (void)sprintf(s = buf, "%s {}", $1.text);
747 1.1 christos new_decl_spec(&$$, s, $1.begin, DS_NONE);
748 1.1 christos }
749 1.1 christos | enumeration any_id
750 1.1 christos {
751 1.1 christos (void)sprintf(buf, "enum %s", $2.text);
752 1.1 christos new_decl_spec(&$$, buf, $1.begin, DS_NONE);
753 1.1 christos }
754 1.1 christos ;
755 1.1 christos
756 1.1 christos enumeration
757 1.1 christos : T_ENUM
758 1.1 christos {
759 1.1 christos imply_typedef("enum");
760 1.1 christos $$ = $1;
761 1.1 christos }
762 1.1 christos ;
763 1.1 christos
764 1.1 christos any_id
765 1.1 christos : T_IDENTIFIER
766 1.1 christos | T_TYPEDEF_NAME
767 1.1 christos ;
768 1.1 christos
769 1.1 christos declarator
770 1.1 christos : pointer direct_declarator
771 1.1 christos {
772 1.1 christos $$ = $2;
773 1.1 christos (void)sprintf(buf, "%s%s", $1.text, $$->text);
774 1.1 christos free($$->text);
775 1.1 christos $$->text = xstrdup(buf);
776 1.1 christos $$->begin = $1.begin;
777 1.1 christos $$->pointer = TRUE;
778 1.1 christos }
779 1.1 christos | direct_declarator
780 1.1 christos ;
781 1.1 christos
782 1.1 christos direct_declarator
783 1.1 christos : identifier_or_ref
784 1.1 christos {
785 1.1 christos $$ = new_declarator($1.text, $1.text, $1.begin);
786 1.1 christos }
787 1.1 christos | '(' declarator ')'
788 1.1 christos {
789 1.1 christos $$ = $2;
790 1.1 christos (void)sprintf(buf, "(%s)", $$->text);
791 1.1 christos free($$->text);
792 1.1 christos $$->text = xstrdup(buf);
793 1.1 christos $$->begin = $1.begin;
794 1.1 christos }
795 1.1 christos | direct_declarator T_BRACKETS
796 1.1 christos {
797 1.1 christos $$ = $1;
798 1.1 christos (void)sprintf(buf, "%s%s", $$->text, $2.text);
799 1.1 christos free($$->text);
800 1.1 christos $$->text = xstrdup(buf);
801 1.1 christos }
802 1.1 christos | direct_declarator '(' parameter_type_list ')'
803 1.1 christos {
804 1.1 christos $$ = new_declarator("%s()", $1->name, $1->begin);
805 1.1 christos $$->params = $3;
806 1.1 christos $$->func_stack = $1;
807 1.1 christos $$->head = ($1->func_stack == NULL) ? $$ : $1->head;
808 1.1 christos $$->func_def = FUNC_ANSI;
809 1.1 christos }
810 1.1 christos | direct_declarator '(' opt_identifier_list ')'
811 1.1 christos {
812 1.1 christos $$ = new_declarator("%s()", $1->name, $1->begin);
813 1.1 christos $$->params = $3;
814 1.1 christos $$->func_stack = $1;
815 1.1 christos $$->head = ($1->func_stack == NULL) ? $$ : $1->head;
816 1.1 christos $$->func_def = FUNC_TRADITIONAL;
817 1.1 christos }
818 1.1 christos ;
819 1.1 christos
820 1.1 christos pointer
821 1.1 christos : '*' opt_type_qualifiers
822 1.1 christos {
823 1.1 christos (void)sprintf($$.text, "*%s", $2.text);
824 1.1 christos $$.begin = $1.begin;
825 1.1 christos }
826 1.1 christos | '*' opt_type_qualifiers pointer
827 1.1 christos {
828 1.1 christos (void)sprintf($$.text, "*%s%s", $2.text, $3.text);
829 1.1 christos $$.begin = $1.begin;
830 1.1 christos }
831 1.1 christos ;
832 1.1 christos
833 1.1 christos opt_type_qualifiers
834 1.1 christos : /* empty */
835 1.1 christos {
836 1.1 christos strcpy($$.text, "");
837 1.1 christos $$.begin = 0L;
838 1.1 christos }
839 1.1 christos | type_qualifier_list
840 1.1 christos ;
841 1.1 christos
842 1.1 christos type_qualifier_list
843 1.1 christos : type_qualifier
844 1.1 christos {
845 1.1 christos (void)sprintf($$.text, "%s ", $1.text);
846 1.1 christos $$.begin = $1.begin;
847 1.1 christos free($1.text);
848 1.1 christos }
849 1.1 christos | type_qualifier_list type_qualifier
850 1.1 christos {
851 1.1 christos (void)sprintf($$.text, "%s%s ", $1.text, $2.text);
852 1.1 christos $$.begin = $1.begin;
853 1.1 christos free($2.text);
854 1.1 christos }
855 1.1 christos ;
856 1.1 christos
857 1.1 christos parameter_type_list
858 1.1 christos : parameter_list
859 1.1 christos | parameter_list ',' T_ELLIPSIS
860 1.1 christos {
861 1.1 christos add_ident_list(&$$, &$1, "...");
862 1.1 christos }
863 1.1 christos ;
864 1.1 christos
865 1.1 christos parameter_list
866 1.1 christos : parameter_declaration
867 1.1 christos {
868 1.1 christos new_param_list(&$$, $1);
869 1.1 christos }
870 1.1 christos | parameter_list ',' parameter_declaration
871 1.1 christos {
872 1.1 christos add_param_list(&$$, &$1, $3);
873 1.1 christos }
874 1.1 christos ;
875 1.1 christos
876 1.1 christos parameter_declaration
877 1.1 christos : decl_specifiers declarator
878 1.1 christos {
879 1.1 christos check_untagged(&$1);
880 1.1 christos $$ = new_parameter(&$1, $2);
881 1.1 christos }
882 1.1 christos | decl_specifiers abs_declarator
883 1.1 christos {
884 1.1 christos check_untagged(&$1);
885 1.1 christos $$ = new_parameter(&$1, $2);
886 1.1 christos }
887 1.1 christos | decl_specifiers
888 1.1 christos {
889 1.1 christos check_untagged(&$1);
890 1.1 christos $$ = new_parameter(&$1, (Declarator *)0);
891 1.1 christos }
892 1.1 christos ;
893 1.1 christos
894 1.1 christos opt_identifier_list
895 1.1 christos : /* empty */
896 1.1 christos {
897 1.1 christos new_ident_list(&$$);
898 1.1 christos }
899 1.1 christos | identifier_list
900 1.1 christos ;
901 1.1 christos
902 1.1 christos identifier_list
903 1.1 christos : any_id
904 1.1 christos {
905 1.1 christos new_ident_list(&$$);
906 1.1 christos add_ident_list(&$$, &$$, $1.text);
907 1.1 christos }
908 1.1 christos | identifier_list ',' any_id
909 1.1 christos {
910 1.1 christos add_ident_list(&$$, &$1, $3.text);
911 1.1 christos }
912 1.1 christos ;
913 1.1 christos
914 1.1 christos identifier_or_ref
915 1.1 christos : any_id
916 1.1 christos {
917 1.1 christos $$ = $1;
918 1.1 christos }
919 1.1 christos | '&' any_id
920 1.1 christos {
921 1.1 christos #if OPT_LINTLIBRARY
922 1.1 christos if (lintLibrary()) { /* Lint doesn't grok C++ ref variables */
923 1.1 christos $$ = $2;
924 1.1 christos } else
925 1.1 christos #endif
926 1.1 christos (void)sprintf($$.text, "&%s", $2.text);
927 1.1 christos $$.begin = $1.begin;
928 1.1 christos }
929 1.1 christos ;
930 1.1 christos
931 1.1 christos abs_declarator
932 1.1 christos : pointer
933 1.1 christos {
934 1.1 christos $$ = new_declarator($1.text, "", $1.begin);
935 1.1 christos }
936 1.1 christos | pointer direct_abs_declarator
937 1.1 christos {
938 1.1 christos $$ = $2;
939 1.1 christos (void)sprintf(buf, "%s%s", $1.text, $$->text);
940 1.1 christos free($$->text);
941 1.1 christos $$->text = xstrdup(buf);
942 1.1 christos $$->begin = $1.begin;
943 1.1 christos }
944 1.1 christos | direct_abs_declarator
945 1.1 christos ;
946 1.1 christos
947 1.1 christos direct_abs_declarator
948 1.1 christos : '(' abs_declarator ')'
949 1.1 christos {
950 1.1 christos $$ = $2;
951 1.1 christos (void)sprintf(buf, "(%s)", $$->text);
952 1.1 christos free($$->text);
953 1.1 christos $$->text = xstrdup(buf);
954 1.1 christos $$->begin = $1.begin;
955 1.1 christos }
956 1.1 christos | direct_abs_declarator T_BRACKETS
957 1.1 christos {
958 1.1 christos $$ = $1;
959 1.1 christos (void)sprintf(buf, "%s%s", $$->text, $2.text);
960 1.1 christos free($$->text);
961 1.1 christos $$->text = xstrdup(buf);
962 1.1 christos }
963 1.1 christos | T_BRACKETS
964 1.1 christos {
965 1.1 christos $$ = new_declarator($1.text, "", $1.begin);
966 1.1 christos }
967 1.1 christos | direct_abs_declarator '(' parameter_type_list ')'
968 1.1 christos {
969 1.1 christos $$ = new_declarator("%s()", "", $1->begin);
970 1.1 christos $$->params = $3;
971 1.1 christos $$->func_stack = $1;
972 1.1 christos $$->head = ($1->func_stack == NULL) ? $$ : $1->head;
973 1.1 christos $$->func_def = FUNC_ANSI;
974 1.1 christos }
975 1.1 christos | direct_abs_declarator '(' ')'
976 1.1 christos {
977 1.1 christos $$ = new_declarator("%s()", "", $1->begin);
978 1.1 christos $$->func_stack = $1;
979 1.1 christos $$->head = ($1->func_stack == NULL) ? $$ : $1->head;
980 1.1 christos $$->func_def = FUNC_ANSI;
981 1.1 christos }
982 1.1 christos | '(' parameter_type_list ')'
983 1.1 christos {
984 1.1 christos Declarator *d;
985 1.1 christos
986 1.1 christos d = new_declarator("", "", $1.begin);
987 1.1 christos $$ = new_declarator("%s()", "", $1.begin);
988 1.1 christos $$->params = $2;
989 1.1 christos $$->func_stack = d;
990 1.1 christos $$->head = $$;
991 1.1 christos $$->func_def = FUNC_ANSI;
992 1.1 christos }
993 1.1 christos | '(' ')'
994 1.1 christos {
995 1.1 christos Declarator *d;
996 1.1 christos
997 1.1 christos d = new_declarator("", "", $1.begin);
998 1.1 christos $$ = new_declarator("%s()", "", $1.begin);
999 1.1 christos $$->func_stack = d;
1000 1.1 christos $$->head = $$;
1001 1.1 christos $$->func_def = FUNC_ANSI;
1002 1.1 christos }
1003 1.1 christos ;
1004 1.1 christos
1005 1.1 christos %%
1006 1.1 christos
1007 1.1.1.2 christos /* lex.yy.c */
1008 1.1.1.2 christos #define BEGIN yy_start = 1 + 2 *
1009 1.1.1.2 christos
1010 1.1.1.2 christos #define CPP1 1
1011 1.1.1.2 christos #define INIT1 2
1012 1.1.1.2 christos #define INIT2 3
1013 1.1.1.2 christos #define CURLY 4
1014 1.1.1.2 christos #define LEXYACC 5
1015 1.1.1.2 christos #define ASM 6
1016 1.1.1.2 christos #define CPP_INLINE 7
1017 1.1.1.2 christos
1018 1.1.1.2 christos extern char *yytext;
1019 1.1.1.2 christos extern FILE *yyin, *yyout;
1020 1.1.1.2 christos
1021 1.1.1.2 christos static int curly; /* number of curly brace nesting levels */
1022 1.1.1.2 christos static int ly_count; /* number of occurances of %% */
1023 1.1.1.2 christos static int inc_depth; /* include nesting level */
1024 1.1.1.2 christos static SymbolTable *included_files; /* files already included */
1025 1.1.1.2 christos static int yy_start = 0; /* start state number */
1026 1.1.1.2 christos
1027 1.1.1.2 christos #define grammar_error(s) yaccError(s)
1028 1.1 christos
1029 1.1 christos static void
1030 1.1.1.2 christos yaccError (const char *msg)
1031 1.1 christos {
1032 1.1 christos func_params = NULL;
1033 1.1 christos put_error(); /* tell what line we're on, and what file */
1034 1.1 christos fprintf(stderr, "%s at token '%s'\n", msg, yytext);
1035 1.1 christos }
1036 1.1 christos
1037 1.1 christos /* Initialize the table of type qualifier keywords recognized by the lexical
1038 1.1 christos * analyzer.
1039 1.1 christos */
1040 1.1 christos void
1041 1.1 christos init_parser (void)
1042 1.1 christos {
1043 1.1.1.2 christos static const char *keywords[] = {
1044 1.1 christos "const",
1045 1.1 christos "restrict",
1046 1.1 christos "volatile",
1047 1.1 christos "interrupt",
1048 1.1 christos #ifdef vms
1049 1.1 christos "noshare",
1050 1.1 christos "readonly",
1051 1.1 christos #endif
1052 1.1 christos #if defined(MSDOS) || defined(OS2)
1053 1.1 christos "__cdecl",
1054 1.1 christos "__export",
1055 1.1 christos "__far",
1056 1.1 christos "__fastcall",
1057 1.1 christos "__fortran",
1058 1.1 christos "__huge",
1059 1.1 christos "__inline",
1060 1.1 christos "__interrupt",
1061 1.1 christos "__loadds",
1062 1.1 christos "__near",
1063 1.1 christos "__pascal",
1064 1.1 christos "__saveregs",
1065 1.1 christos "__segment",
1066 1.1 christos "__stdcall",
1067 1.1 christos "__syscall",
1068 1.1 christos "_cdecl",
1069 1.1 christos "_cs",
1070 1.1 christos "_ds",
1071 1.1 christos "_es",
1072 1.1 christos "_export",
1073 1.1 christos "_far",
1074 1.1 christos "_fastcall",
1075 1.1 christos "_fortran",
1076 1.1 christos "_huge",
1077 1.1 christos "_interrupt",
1078 1.1 christos "_loadds",
1079 1.1 christos "_near",
1080 1.1 christos "_pascal",
1081 1.1 christos "_saveregs",
1082 1.1 christos "_seg",
1083 1.1 christos "_segment",
1084 1.1 christos "_ss",
1085 1.1 christos "cdecl",
1086 1.1 christos "far",
1087 1.1 christos "huge",
1088 1.1 christos "near",
1089 1.1 christos "pascal",
1090 1.1 christos #ifdef OS2
1091 1.1 christos "__far16",
1092 1.1 christos #endif
1093 1.1 christos #endif
1094 1.1 christos #ifdef __GNUC__
1095 1.1 christos /* gcc aliases */
1096 1.1 christos "__builtin_va_arg",
1097 1.1 christos "__builtin_va_list",
1098 1.1 christos "__const",
1099 1.1 christos "__const__",
1100 1.1 christos "__inline",
1101 1.1 christos "__inline__",
1102 1.1 christos "__restrict",
1103 1.1 christos "__restrict__",
1104 1.1 christos "__volatile",
1105 1.1 christos "__volatile__",
1106 1.1 christos #endif
1107 1.1 christos };
1108 1.1 christos unsigned i;
1109 1.1 christos
1110 1.1 christos /* Initialize type qualifier table. */
1111 1.1 christos type_qualifiers = new_symbol_table();
1112 1.1 christos for (i = 0; i < sizeof(keywords)/sizeof(keywords[0]); ++i) {
1113 1.1 christos new_symbol(type_qualifiers, keywords[i], NULL, DS_NONE);
1114 1.1 christos }
1115 1.1 christos }
1116 1.1 christos
1117 1.1 christos /* Process the C source file. Write function prototypes to the standard
1118 1.1 christos * output. Convert function definitions and write the converted source
1119 1.1 christos * code to a temporary file.
1120 1.1 christos */
1121 1.1 christos void
1122 1.1 christos process_file (FILE *infile, char *name)
1123 1.1 christos {
1124 1.1 christos char *s;
1125 1.1 christos
1126 1.1 christos if (strlen(name) > 2) {
1127 1.1 christos s = name + strlen(name) - 2;
1128 1.1 christos if (*s == '.') {
1129 1.1 christos ++s;
1130 1.1 christos if (*s == 'l' || *s == 'y')
1131 1.1 christos BEGIN LEXYACC;
1132 1.1 christos #if defined(MSDOS) || defined(OS2)
1133 1.1 christos if (*s == 'L' || *s == 'Y')
1134 1.1 christos BEGIN LEXYACC;
1135 1.1 christos #endif
1136 1.1 christos }
1137 1.1 christos }
1138 1.1 christos
1139 1.1 christos included_files = new_symbol_table();
1140 1.1 christos typedef_names = new_symbol_table();
1141 1.1 christos define_names = new_symbol_table();
1142 1.1 christos inc_depth = -1;
1143 1.1 christos curly = 0;
1144 1.1 christos ly_count = 0;
1145 1.1 christos func_params = NULL;
1146 1.1 christos yyin = infile;
1147 1.1 christos include_file(strcpy(base_file, name), func_style != FUNC_NONE);
1148 1.1 christos if (file_comments) {
1149 1.1 christos #if OPT_LINTLIBRARY
1150 1.1 christos if (lintLibrary()) {
1151 1.1 christos put_blankline(stdout);
1152 1.1 christos begin_tracking();
1153 1.1 christos }
1154 1.1 christos #endif
1155 1.1 christos put_string(stdout, "/* ");
1156 1.1 christos put_string(stdout, cur_file_name());
1157 1.1 christos put_string(stdout, " */\n");
1158 1.1 christos }
1159 1.1 christos yyparse();
1160 1.1 christos free_symbol_table(define_names);
1161 1.1 christos free_symbol_table(typedef_names);
1162 1.1 christos free_symbol_table(included_files);
1163 1.1 christos }
1164 1.1 christos
1165 1.1 christos #ifdef NO_LEAKS
1166 1.1 christos void
1167 1.1 christos free_parser(void)
1168 1.1 christos {
1169 1.1 christos free_symbol_table (type_qualifiers);
1170 1.1 christos #ifdef FLEX_SCANNER
1171 1.1 christos if (yy_current_buffer != 0)
1172 1.1 christos yy_delete_buffer(yy_current_buffer);
1173 1.1 christos #endif
1174 1.1 christos }
1175 1.1 christos #endif
1176