1 /* original parser id follows */ 2 /* yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93" */ 3 /* (use YYMAJOR/YYMINOR for ifdefs dependent on parser version) */ 4 5 #define YYBYACC 1 6 #define YYMAJOR 1 7 #define YYMINOR 9 8 #define YYCHECK "yyyymmdd" 9 10 #define YYEMPTY (-1) 11 #define yyclearin (yychar = YYEMPTY) 12 #define yyerrok (yyerrflag = 0) 13 #define YYRECOVERING() (yyerrflag != 0) 14 #define YYENOMEM (-2) 15 #define YYEOF 0 16 17 #ifndef yyparse 18 #define yyparse grammar_parse 19 #endif /* yyparse */ 20 21 #ifndef yylex 22 #define yylex grammar_lex 23 #endif /* yylex */ 24 25 #ifndef yyerror 26 #define yyerror grammar_error 27 #endif /* yyerror */ 28 29 #ifndef yychar 30 #define yychar grammar_char 31 #endif /* yychar */ 32 33 #ifndef yyval 34 #define yyval grammar_val 35 #endif /* yyval */ 36 37 #ifndef yylval 38 #define yylval grammar_lval 39 #endif /* yylval */ 40 41 #ifndef yydebug 42 #define yydebug grammar_debug 43 #endif /* yydebug */ 44 45 #ifndef yynerrs 46 #define yynerrs grammar_nerrs 47 #endif /* yynerrs */ 48 49 #ifndef yyerrflag 50 #define yyerrflag grammar_errflag 51 #endif /* yyerrflag */ 52 53 #ifndef yylhs 54 #define yylhs grammar_lhs 55 #endif /* yylhs */ 56 57 #ifndef yylen 58 #define yylen grammar_len 59 #endif /* yylen */ 60 61 #ifndef yydefred 62 #define yydefred grammar_defred 63 #endif /* yydefred */ 64 65 #ifndef yydgoto 66 #define yydgoto grammar_dgoto 67 #endif /* yydgoto */ 68 69 #ifndef yysindex 70 #define yysindex grammar_sindex 71 #endif /* yysindex */ 72 73 #ifndef yyrindex 74 #define yyrindex grammar_rindex 75 #endif /* yyrindex */ 76 77 #ifndef yygindex 78 #define yygindex grammar_gindex 79 #endif /* yygindex */ 80 81 #ifndef yytable 82 #define yytable grammar_table 83 #endif /* yytable */ 84 85 #ifndef yycheck 86 #define yycheck grammar_check 87 #endif /* yycheck */ 88 89 #ifndef yyname 90 #define yyname grammar_name 91 #endif /* yyname */ 92 93 #ifndef yyrule 94 #define yyrule grammar_rule 95 #endif /* yyrule */ 96 #define YYPREFIX "grammar_" 97 98 #define YYPURE 0 99 100 #line 9 "grammar.y" 101 #ifdef YYBISON 102 #include <stdlib.h> 103 #define YYSTYPE_IS_DECLARED 104 #define yyerror yaccError 105 #endif 106 107 #if defined(YYBISON) || !defined(YYBYACC) 108 static void yyerror(const char *s); 109 #endif 110 #line 81 "grammar.y" 111 #include <stdio.h> 112 #include <ctype.h> 113 #include <string.h> 114 115 #define OPT_LINTLIBRARY 1 116 117 #ifndef TRUE 118 #define TRUE (1) 119 #endif 120 121 #ifndef FALSE 122 #define FALSE (0) 123 #endif 124 125 /* #include "cproto.h" */ 126 #define MAX_TEXT_SIZE 1024 127 128 /* Prototype styles */ 129 #if OPT_LINTLIBRARY 130 #define PROTO_ANSI_LLIB -2 /* form ANSI lint-library source */ 131 #define PROTO_LINTLIBRARY -1 /* form lint-library source */ 132 #endif 133 #define PROTO_NONE 0 /* do not output any prototypes */ 134 #define PROTO_TRADITIONAL 1 /* comment out parameters */ 135 #define PROTO_ABSTRACT 2 /* comment out parameter names */ 136 #define PROTO_ANSI 3 /* ANSI C prototype */ 137 138 typedef int PrototypeStyle; 139 140 typedef char boolean; 141 142 extern boolean types_out; 143 extern PrototypeStyle proto_style; 144 145 #define ansiLintLibrary() (proto_style == PROTO_ANSI_LLIB) 146 #define knrLintLibrary() (proto_style == PROTO_LINTLIBRARY) 147 #define lintLibrary() (knrLintLibrary() || ansiLintLibrary()) 148 149 #if OPT_LINTLIBRARY 150 #define FUNC_UNKNOWN -1 /* unspecified */ 151 #else 152 #define FUNC_UNKNOWN 0 /* unspecified (same as FUNC_NONE) */ 153 #endif 154 #define FUNC_NONE 0 /* not a function definition */ 155 #define FUNC_TRADITIONAL 1 /* traditional style */ 156 #define FUNC_ANSI 2 /* ANSI style */ 157 #define FUNC_BOTH 3 /* both styles */ 158 159 typedef int FuncDefStyle; 160 161 /* Source file text */ 162 typedef struct text { 163 char text[MAX_TEXT_SIZE]; /* source text */ 164 long begin; /* offset in temporary file */ 165 } Text; 166 167 /* Declaration specifier flags */ 168 #define DS_NONE 0 /* default */ 169 #define DS_EXTERN 1 /* contains "extern" specifier */ 170 #define DS_STATIC 2 /* contains "static" specifier */ 171 #define DS_CHAR 4 /* contains "char" type specifier */ 172 #define DS_SHORT 8 /* contains "short" type specifier */ 173 #define DS_FLOAT 16 /* contains "float" type specifier */ 174 #define DS_INLINE 32 /* contains "inline" specifier */ 175 #define DS_JUNK 64 /* we're not interested in this declaration */ 176 177 /* This structure stores information about a declaration specifier. */ 178 typedef struct decl_spec { 179 unsigned short flags; /* flags defined above */ 180 char *text; /* source text */ 181 long begin; /* offset in temporary file */ 182 } DeclSpec; 183 184 /* This is a list of function parameters. */ 185 typedef struct _ParameterList { 186 struct parameter *first; /* pointer to first parameter in list */ 187 struct parameter *last; /* pointer to last parameter in list */ 188 long begin_comment; /* begin offset of comment */ 189 long end_comment; /* end offset of comment */ 190 char *comment; /* comment at start of parameter list */ 191 } ParameterList; 192 193 /* This structure stores information about a declarator. */ 194 typedef struct _Declarator { 195 char *name; /* name of variable or function */ 196 char *text; /* source text */ 197 long begin; /* offset in temporary file */ 198 long begin_comment; /* begin offset of comment */ 199 long end_comment; /* end offset of comment */ 200 FuncDefStyle func_def; /* style of function definition */ 201 ParameterList params; /* function parameters */ 202 boolean pointer; /* TRUE if it declares a pointer */ 203 struct _Declarator *head; /* head function declarator */ 204 struct _Declarator *func_stack; /* stack of function declarators */ 205 struct _Declarator *next; /* next declarator in list */ 206 } Declarator; 207 208 /* This structure stores information about a function parameter. */ 209 typedef struct parameter { 210 struct parameter *next; /* next parameter in list */ 211 DeclSpec decl_spec; 212 Declarator *declarator; 213 char *comment; /* comment following the parameter */ 214 } Parameter; 215 216 /* This is a list of declarators. */ 217 typedef struct declarator_list { 218 Declarator *first; /* pointer to first declarator in list */ 219 Declarator *last; /* pointer to last declarator in list */ 220 } DeclaratorList; 221 222 /* #include "symbol.h" */ 223 typedef struct symbol { 224 struct symbol *next; /* next symbol in list */ 225 char *name; /* name of symbol */ 226 char *value; /* value of symbol (for defines) */ 227 short flags; /* symbol attributes */ 228 } Symbol; 229 230 /* parser stack entry type */ 231 typedef union { 232 Text text; 233 DeclSpec decl_spec; 234 Parameter *parameter; 235 ParameterList param_list; 236 Declarator *declarator; 237 DeclaratorList decl_list; 238 } YYSTYPE; 239 240 /* The hash table length should be a prime number. */ 241 #define SYM_MAX_HASH 251 242 243 typedef struct symbol_table { 244 Symbol *bucket[SYM_MAX_HASH]; /* hash buckets */ 245 } SymbolTable; 246 247 extern SymbolTable *new_symbol_table /* Create symbol table */ 248 (void); 249 extern void free_symbol_table /* Destroy symbol table */ 250 (SymbolTable *s); 251 extern Symbol *find_symbol /* Lookup symbol name */ 252 (SymbolTable *s, const char *n); 253 extern Symbol *new_symbol /* Define new symbol */ 254 (SymbolTable *s, const char *n, const char *v, int f); 255 256 /* #include "semantic.h" */ 257 extern void new_decl_spec (DeclSpec *, const char *, long, int); 258 extern void free_decl_spec (DeclSpec *); 259 extern void join_decl_specs (DeclSpec *, DeclSpec *, DeclSpec *); 260 extern void check_untagged (DeclSpec *); 261 extern Declarator *new_declarator (const char *, const char *, long); 262 extern void free_declarator (Declarator *); 263 extern void new_decl_list (DeclaratorList *, Declarator *); 264 extern void free_decl_list (DeclaratorList *); 265 extern void add_decl_list (DeclaratorList *, DeclaratorList *, Declarator *); 266 extern Parameter *new_parameter (DeclSpec *, Declarator *); 267 extern void free_parameter (Parameter *); 268 extern void new_param_list (ParameterList *, Parameter *); 269 extern void free_param_list (ParameterList *); 270 extern void add_param_list (ParameterList *, ParameterList *, Parameter *); 271 extern void new_ident_list (ParameterList *); 272 extern void add_ident_list (ParameterList *, ParameterList *, const char *); 273 extern void set_param_types (ParameterList *, DeclSpec *, DeclaratorList *); 274 extern void gen_declarations (DeclSpec *, DeclaratorList *); 275 extern void gen_prototype (DeclSpec *, Declarator *); 276 extern void gen_func_declarator (Declarator *); 277 extern void gen_func_definition (DeclSpec *, Declarator *); 278 279 extern void init_parser (void); 280 extern void process_file (FILE *infile, char *name); 281 extern char *cur_text (void); 282 extern char *cur_file_name (void); 283 extern char *implied_typedef (void); 284 extern void include_file (char *name, int convert); 285 extern char *supply_parm (int count); 286 extern char *xstrdup (const char *); 287 extern int already_declared (char *name); 288 extern int is_actual_func (Declarator *d); 289 extern int lint_ellipsis (Parameter *p); 290 extern int want_typedef (void); 291 extern void begin_tracking (void); 292 extern void begin_typedef (void); 293 extern void copy_typedef (char *s); 294 extern void ellipsis_varargs (Declarator *d); 295 extern void end_typedef (void); 296 extern void flush_varargs (void); 297 extern void fmt_library (int code); 298 extern void imply_typedef (const char *s); 299 extern void indent (FILE *outf); 300 extern void put_blankline (FILE *outf); 301 extern void put_body (FILE *outf, DeclSpec *decl_spec, Declarator *declarator); 302 extern void put_char (FILE *outf, int c); 303 extern void put_error (void); 304 extern void put_newline (FILE *outf); 305 extern void put_padded (FILE *outf, const char *s); 306 extern void put_string (FILE *outf, const char *s); 307 extern void track_in (void); 308 309 extern boolean file_comments; 310 extern FuncDefStyle func_style; 311 extern char base_file[]; 312 313 extern int yylex (void); 314 315 /* declaration specifier attributes for the typedef statement currently being 316 * scanned 317 */ 318 static int cur_decl_spec_flags; 319 320 /* pointer to parameter list for the current function definition */ 321 static ParameterList *func_params; 322 323 /* A parser semantic action sets this pointer to the current declarator in 324 * a function parameter declaration in order to catch any comments following 325 * the parameter declaration on the same line. If the lexer scans a comment 326 * and <cur_declarator> is not NULL, then the comment is attached to the 327 * declarator. To ignore subsequent comments, the lexer sets this to NULL 328 * after scanning a comment or end of line. 329 */ 330 static Declarator *cur_declarator; 331 332 /* temporary string buffer */ 333 static char buf[MAX_TEXT_SIZE]; 334 335 /* table of typedef names */ 336 static SymbolTable *typedef_names; 337 338 /* table of define names */ 339 static SymbolTable *define_names; 340 341 /* table of type qualifiers */ 342 static SymbolTable *type_qualifiers; 343 344 /* information about the current input file */ 345 typedef struct { 346 char *base_name; /* base input file name */ 347 char *file_name; /* current file name */ 348 FILE *file; /* input file */ 349 unsigned line_num; /* current line number in input file */ 350 FILE *tmp_file; /* temporary file */ 351 long begin_comment; /* tmp file offset after last written ) or ; */ 352 long end_comment; /* tmp file offset after last comment */ 353 boolean convert; /* if TRUE, convert function definitions */ 354 boolean changed; /* TRUE if conversion done in this file */ 355 } IncludeStack; 356 357 static IncludeStack *cur_file; /* current input file */ 358 359 /* #include "yyerror.c" */ 360 361 static int haveAnsiParam (void); 362 363 364 /* Flags to enable us to find if a procedure returns a value. 365 */ 366 static int return_val; /* nonzero on BRACES iff return-expression found */ 367 368 static const char * 369 dft_decl_spec (void) 370 { 371 return (lintLibrary() && !return_val) ? "void" : "int"; 372 } 373 374 static int 375 haveAnsiParam (void) 376 { 377 Parameter *p; 378 if (func_params != 0) { 379 for (p = func_params->first; p != 0; p = p->next) { 380 if (p->declarator->func_def == FUNC_ANSI) { 381 return TRUE; 382 } 383 } 384 } 385 return FALSE; 386 } 387 #line 388 "grammar.tab.c" 388 389 /* compatibility with bison */ 390 #ifdef YYPARSE_PARAM 391 /* compatibility with FreeBSD */ 392 # ifdef YYPARSE_PARAM_TYPE 393 # define YYPARSE_DECL() yyparse(YYPARSE_PARAM_TYPE YYPARSE_PARAM) 394 # else 395 # define YYPARSE_DECL() yyparse(void *YYPARSE_PARAM) 396 # endif 397 #else 398 # define YYPARSE_DECL() yyparse(void) 399 #endif 400 401 /* Parameters sent to lex. */ 402 #ifdef YYLEX_PARAM 403 # define YYLEX_DECL() yylex(void *YYLEX_PARAM) 404 # define YYLEX yylex(YYLEX_PARAM) 405 #else 406 # define YYLEX_DECL() yylex(void) 407 # define YYLEX yylex() 408 #endif 409 410 /* Parameters sent to yyerror. */ 411 #ifndef YYERROR_DECL 412 #define YYERROR_DECL() yyerror(const char *s) 413 #endif 414 #ifndef YYERROR_CALL 415 #define YYERROR_CALL(msg) yyerror(msg) 416 #endif 417 418 extern int YYPARSE_DECL(); 419 420 #define T_IDENTIFIER 257 421 #define T_TYPEDEF_NAME 258 422 #define T_DEFINE_NAME 259 423 #define T_AUTO 260 424 #define T_EXTERN 261 425 #define T_REGISTER 262 426 #define T_STATIC 263 427 #define T_TYPEDEF 264 428 #define T_INLINE 265 429 #define T_EXTENSION 266 430 #define T_CHAR 267 431 #define T_DOUBLE 268 432 #define T_FLOAT 269 433 #define T_INT 270 434 #define T_VOID 271 435 #define T_LONG 272 436 #define T_SHORT 273 437 #define T_SIGNED 274 438 #define T_UNSIGNED 275 439 #define T_ENUM 276 440 #define T_STRUCT 277 441 #define T_UNION 278 442 #define T_Bool 279 443 #define T_Complex 280 444 #define T_Imaginary 281 445 #define T_TYPE_QUALIFIER 282 446 #define T_BRACKETS 283 447 #define T_LBRACE 284 448 #define T_MATCHRBRACE 285 449 #define T_ELLIPSIS 286 450 #define T_INITIALIZER 287 451 #define T_STRING_LITERAL 288 452 #define T_ASM 289 453 #define T_ASMARG 290 454 #define T_VA_DCL 291 455 #define YYERRCODE 256 456 typedef int YYINT; 457 static const YYINT grammar_lhs[] = { -1, 458 0, 0, 26, 26, 27, 27, 27, 27, 27, 27, 459 27, 31, 30, 30, 28, 28, 34, 28, 32, 32, 460 33, 33, 35, 35, 37, 38, 29, 39, 29, 36, 461 36, 36, 40, 40, 1, 1, 2, 2, 2, 3, 462 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 463 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 464 5, 5, 6, 6, 6, 19, 19, 8, 8, 9, 465 41, 9, 7, 7, 7, 25, 23, 23, 10, 10, 466 11, 11, 11, 11, 11, 20, 20, 21, 21, 22, 467 22, 14, 14, 15, 15, 16, 16, 16, 17, 17, 468 18, 18, 24, 24, 12, 12, 12, 13, 13, 13, 469 13, 13, 13, 13, 470 }; 471 static const YYINT grammar_len[] = { 2, 472 0, 1, 1, 2, 1, 1, 1, 1, 3, 2, 473 2, 2, 3, 3, 2, 3, 0, 5, 2, 1, 474 0, 1, 1, 3, 0, 0, 7, 0, 5, 0, 475 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 476 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 477 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 478 1, 1, 3, 2, 2, 1, 1, 1, 3, 1, 479 0, 4, 3, 2, 2, 1, 1, 1, 2, 1, 480 1, 3, 2, 4, 4, 2, 3, 0, 1, 1, 481 2, 1, 3, 1, 3, 2, 2, 1, 0, 1, 482 1, 3, 1, 2, 1, 2, 1, 3, 2, 1, 483 4, 3, 3, 2, 484 }; 485 static const YYINT grammar_defred[] = { 0, 486 0, 0, 0, 0, 77, 0, 62, 40, 0, 42, 487 43, 20, 44, 0, 46, 47, 48, 49, 54, 50, 488 51, 52, 53, 76, 66, 67, 55, 56, 57, 61, 489 0, 7, 0, 0, 35, 37, 38, 39, 59, 60, 490 28, 0, 0, 0, 103, 81, 0, 0, 3, 5, 491 6, 8, 0, 10, 11, 78, 0, 90, 0, 0, 492 104, 0, 19, 0, 41, 45, 15, 36, 0, 68, 493 0, 0, 0, 83, 0, 0, 64, 0, 0, 74, 494 4, 58, 0, 82, 87, 91, 0, 14, 13, 9, 495 16, 0, 71, 0, 31, 33, 0, 0, 0, 0, 496 0, 94, 0, 0, 101, 12, 63, 73, 0, 0, 497 69, 0, 0, 0, 34, 0, 110, 96, 97, 0, 498 0, 84, 0, 85, 0, 23, 0, 0, 72, 26, 499 29, 114, 0, 0, 0, 109, 0, 93, 95, 102, 500 18, 0, 0, 108, 113, 112, 0, 24, 27, 111, 501 }; 502 static const YYINT grammar_dgoto[] = { 33, 503 87, 35, 36, 37, 38, 39, 40, 69, 70, 41, 504 42, 119, 120, 100, 101, 102, 103, 104, 43, 44, 505 59, 60, 45, 46, 47, 48, 49, 50, 51, 52, 506 77, 53, 127, 109, 128, 97, 94, 143, 72, 98, 507 112, 508 }; 509 static const YYINT grammar_sindex[] = { -2, 510 -3, 27, -239, -177, 0, 0, 0, 0, -274, 0, 511 0, 0, 0, -246, 0, 0, 0, 0, 0, 0, 512 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 513 -266, 0, 0, 455, 0, 0, 0, 0, 0, 0, 514 0, -35, -245, 128, 0, 0, -245, -2, 0, 0, 515 0, 0, 642, 0, 0, 0, -15, 0, -12, -239, 516 0, 590, 0, -27, 0, 0, 0, 0, -10, 0, 517 -11, 534, -72, 0, -237, -232, 0, -35, -232, 0, 518 0, 0, 642, 0, 0, 0, 455, 0, 0, 0, 519 0, 27, 0, 534, 0, 0, -222, 617, 209, 34, 520 39, 0, 44, 42, 0, 0, 0, 0, 27, -11, 521 0, -200, -196, -195, 0, 174, 0, 0, 0, -33, 522 243, 0, 561, 0, -177, 0, 33, 49, 0, 0, 523 0, 0, 53, 55, 417, 0, -33, 0, 0, 0, 524 0, 27, -188, 0, 0, 0, 57, 0, 0, 0, 525 }; 526 static const YYINT grammar_rindex[] = { 99, 527 0, 0, 275, 0, 0, -38, 0, 0, 481, 0, 528 0, 0, 0, 509, 0, 0, 0, 0, 0, 0, 529 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 530 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 531 0, 30, 0, 0, 0, 0, 0, 101, 0, 0, 532 0, 0, 0, 0, 0, 0, 0, 0, 343, 309, 533 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 534 98, -182, 62, 0, 0, 133, 0, 64, 379, 0, 535 0, 0, -5, 0, 0, 0, 0, 0, 0, 0, 536 0, 0, 0, -182, 0, 0, 0, -180, -19, 0, 537 65, 0, 0, 68, 0, 0, 0, 0, 51, 9, 538 0, 0, 0, 0, 0, 0, 0, 0, 0, -13, 539 19, 0, 0, 0, 0, 0, 0, 52, 0, 0, 540 0, 0, 0, 0, 0, 0, 35, 0, 0, 0, 541 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 542 }; 543 static const YYINT grammar_gindex[] = { 0, 544 11, -17, 0, 0, 13, 0, 0, 0, 20, 8, 545 -43, -1, -8, -89, 0, -9, 0, 0, 0, -44, 546 0, 0, 4, 0, 0, 0, 70, -53, 0, 0, 547 -18, 0, 0, 0, 0, 22, 0, 0, 0, 0, 548 0, 549 }; 550 #define YYTABLESIZE 924 551 static const YYINT grammar_table[] = { 58, 552 78, 58, 58, 58, 73, 58, 135, 61, 88, 57, 553 34, 5, 56, 62, 85, 58, 68, 63, 96, 7, 554 58, 98, 78, 64, 98, 84, 134, 107, 80, 3, 555 107, 90, 17, 92, 17, 4, 17, 2, 75, 3, 556 96, 71, 30, 89, 115, 147, 76, 106, 91, 93, 557 79, 75, 70, 17, 121, 55, 32, 107, 34, 105, 558 108, 114, 105, 83, 4, 68, 2, 70, 3, 68, 559 80, 121, 86, 80, 122, 106, 105, 78, 106, 5, 560 56, 68, 123, 99, 124, 125, 129, 130, 80, 131, 561 80, 141, 142, 144, 110, 145, 149, 150, 1, 110, 562 2, 30, 99, 32, 79, 92, 118, 79, 100, 21, 563 22, 111, 137, 139, 133, 113, 126, 81, 0, 0, 564 0, 0, 79, 57, 79, 0, 99, 0, 140, 0, 565 0, 0, 0, 99, 0, 0, 0, 0, 0, 0, 566 0, 70, 0, 0, 0, 99, 0, 0, 0, 148, 567 0, 0, 0, 0, 0, 0, 70, 0, 0, 0, 568 0, 0, 0, 0, 0, 4, 0, 2, 0, 0, 569 65, 0, 65, 65, 65, 0, 65, 0, 0, 0, 570 0, 0, 0, 0, 5, 6, 7, 8, 65, 10, 571 11, 65, 13, 66, 15, 16, 17, 18, 19, 20, 572 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 573 0, 4, 0, 116, 132, 3, 0, 0, 58, 58, 574 58, 58, 58, 58, 58, 78, 58, 58, 58, 58, 575 58, 58, 58, 58, 58, 58, 58, 58, 58, 58, 576 58, 58, 58, 58, 58, 78, 4, 74, 116, 136, 577 3, 17, 78, 1, 5, 6, 7, 8, 9, 10, 578 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 579 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 580 4, 54, 116, 5, 56, 0, 31, 80, 80, 80, 581 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 582 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 583 80, 80, 88, 80, 88, 88, 88, 0, 88, 0, 584 80, 79, 79, 79, 79, 79, 79, 79, 79, 79, 585 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 586 79, 79, 79, 79, 79, 79, 89, 79, 89, 89, 587 89, 0, 89, 0, 79, 25, 25, 25, 25, 25, 588 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 589 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 590 86, 25, 86, 86, 5, 56, 86, 0, 25, 65, 591 65, 65, 65, 65, 65, 65, 0, 65, 65, 65, 592 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 593 65, 65, 65, 65, 65, 65, 75, 0, 75, 75, 594 75, 0, 75, 0, 0, 0, 0, 0, 0, 0, 595 5, 6, 7, 8, 65, 10, 11, 75, 13, 66, 596 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 597 25, 26, 27, 28, 29, 30, 117, 146, 0, 0, 598 0, 0, 0, 0, 0, 5, 6, 7, 8, 65, 599 10, 11, 0, 13, 66, 15, 16, 17, 18, 19, 600 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 601 30, 117, 4, 0, 2, 0, 3, 0, 0, 5, 602 56, 0, 0, 0, 0, 0, 0, 0, 0, 0, 603 0, 0, 0, 67, 0, 0, 0, 0, 41, 0, 604 41, 0, 41, 0, 0, 117, 0, 0, 0, 0, 605 0, 88, 88, 0, 0, 0, 0, 0, 0, 41, 606 0, 0, 0, 0, 0, 0, 45, 0, 45, 0, 607 45, 0, 0, 0, 0, 0, 0, 88, 0, 0, 608 0, 0, 0, 0, 0, 89, 89, 45, 0, 0, 609 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 610 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 611 0, 89, 0, 0, 0, 0, 0, 0, 0, 86, 612 86, 0, 0, 0, 0, 0, 0, 0, 0, 0, 613 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 614 0, 0, 0, 0, 0, 86, 0, 0, 0, 0, 615 0, 0, 0, 0, 0, 75, 75, 75, 75, 75, 616 75, 75, 0, 75, 75, 75, 75, 75, 75, 75, 617 75, 75, 75, 75, 75, 75, 75, 75, 75, 75, 618 75, 75, 0, 0, 0, 0, 0, 0, 0, 0, 619 0, 0, 0, 0, 82, 7, 8, 65, 10, 11, 620 0, 13, 66, 15, 16, 17, 18, 19, 20, 21, 621 22, 23, 24, 25, 26, 27, 28, 29, 30, 0, 622 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 623 0, 5, 6, 7, 8, 65, 10, 11, 0, 13, 624 66, 15, 16, 17, 18, 19, 20, 21, 22, 23, 625 24, 25, 26, 27, 28, 29, 30, 41, 41, 41, 626 41, 41, 41, 41, 0, 41, 41, 41, 41, 41, 627 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 628 41, 41, 41, 0, 0, 45, 45, 45, 45, 45, 629 45, 45, 0, 45, 45, 45, 45, 45, 45, 45, 630 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 631 45, 82, 7, 8, 65, 10, 11, 12, 13, 14, 632 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 633 25, 26, 27, 28, 29, 30, 0, 0, 82, 7, 634 8, 65, 10, 11, 95, 13, 66, 15, 16, 17, 635 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 636 28, 29, 30, 0, 0, 0, 138, 82, 7, 8, 637 65, 10, 11, 12, 13, 14, 15, 16, 17, 18, 638 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 639 29, 30, 0, 75, 82, 7, 8, 65, 10, 11, 640 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 641 22, 23, 24, 25, 26, 27, 28, 29, 30, 82, 642 7, 8, 65, 10, 11, 0, 13, 66, 15, 16, 643 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 644 27, 28, 29, 30, 645 }; 646 static const YYINT grammar_check[] = { 38, 647 44, 40, 41, 42, 40, 44, 40, 4, 62, 2, 648 0, 257, 258, 288, 59, 3, 34, 264, 72, 259, 649 59, 41, 61, 290, 44, 41, 116, 41, 47, 42, 650 44, 59, 38, 44, 40, 38, 42, 40, 284, 42, 651 94, 34, 282, 62, 98, 135, 43, 285, 59, 61, 652 47, 284, 44, 59, 99, 59, 59, 76, 48, 41, 653 79, 284, 44, 53, 38, 83, 40, 59, 42, 87, 654 41, 116, 60, 44, 41, 41, 73, 121, 44, 257, 655 258, 99, 44, 73, 41, 44, 287, 284, 59, 285, 656 61, 59, 44, 41, 87, 41, 285, 41, 0, 92, 657 0, 284, 41, 284, 41, 41, 99, 44, 41, 59, 658 59, 92, 121, 123, 116, 94, 109, 48, -1, -1, 659 -1, -1, 59, 116, 61, -1, 116, -1, 125, -1, 660 -1, -1, -1, 123, -1, -1, -1, -1, -1, -1, 661 -1, 44, -1, -1, -1, 135, -1, -1, -1, 142, 662 -1, -1, -1, -1, -1, -1, 59, -1, -1, -1, 663 -1, -1, -1, -1, -1, 38, -1, 40, -1, -1, 664 38, -1, 40, 41, 42, -1, 44, -1, -1, -1, 665 -1, -1, -1, -1, 257, 258, 259, 260, 261, 262, 666 263, 59, 265, 266, 267, 268, 269, 270, 271, 272, 667 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 668 -1, 38, -1, 40, 41, 42, -1, -1, 257, 258, 669 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 670 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 671 279, 280, 281, 282, 283, 284, 38, 283, 40, 283, 672 42, 257, 291, 256, 257, 258, 259, 260, 261, 262, 673 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 674 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 675 38, 285, 40, 257, 258, -1, 289, 258, 259, 260, 676 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 677 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 678 281, 282, 38, 284, 40, 41, 42, -1, 44, -1, 679 291, 258, 259, 260, 261, 262, 263, 264, 265, 266, 680 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 681 277, 278, 279, 280, 281, 282, 38, 284, 40, 41, 682 42, -1, 44, -1, 291, 258, 259, 260, 261, 262, 683 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 684 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 685 38, 284, 40, 41, 257, 258, 44, -1, 291, 257, 686 258, 259, 260, 261, 262, 263, -1, 265, 266, 267, 687 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 688 278, 279, 280, 281, 282, 283, 38, -1, 40, 41, 689 42, -1, 44, -1, -1, -1, -1, -1, -1, -1, 690 257, 258, 259, 260, 261, 262, 263, 59, 265, 266, 691 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 692 277, 278, 279, 280, 281, 282, 283, 41, -1, -1, 693 -1, -1, -1, -1, -1, 257, 258, 259, 260, 261, 694 262, 263, -1, 265, 266, 267, 268, 269, 270, 271, 695 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 696 282, 283, 38, -1, 40, -1, 42, -1, -1, 257, 697 258, -1, -1, -1, -1, -1, -1, -1, -1, -1, 698 -1, -1, -1, 59, -1, -1, -1, -1, 38, -1, 699 40, -1, 42, -1, -1, 283, -1, -1, -1, -1, 700 -1, 257, 258, -1, -1, -1, -1, -1, -1, 59, 701 -1, -1, -1, -1, -1, -1, 38, -1, 40, -1, 702 42, -1, -1, -1, -1, -1, -1, 283, -1, -1, 703 -1, -1, -1, -1, -1, 257, 258, 59, -1, -1, 704 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 705 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 706 -1, 283, -1, -1, -1, -1, -1, -1, -1, 257, 707 258, -1, -1, -1, -1, -1, -1, -1, -1, -1, 708 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 709 -1, -1, -1, -1, -1, 283, -1, -1, -1, -1, 710 -1, -1, -1, -1, -1, 257, 258, 259, 260, 261, 711 262, 263, -1, 265, 266, 267, 268, 269, 270, 271, 712 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 713 282, 283, -1, -1, -1, -1, -1, -1, -1, -1, 714 -1, -1, -1, -1, 258, 259, 260, 261, 262, 263, 715 -1, 265, 266, 267, 268, 269, 270, 271, 272, 273, 716 274, 275, 276, 277, 278, 279, 280, 281, 282, -1, 717 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 718 -1, 257, 258, 259, 260, 261, 262, 263, -1, 265, 719 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 720 276, 277, 278, 279, 280, 281, 282, 257, 258, 259, 721 260, 261, 262, 263, -1, 265, 266, 267, 268, 269, 722 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 723 280, 281, 282, -1, -1, 257, 258, 259, 260, 261, 724 262, 263, -1, 265, 266, 267, 268, 269, 270, 271, 725 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 726 282, 258, 259, 260, 261, 262, 263, 264, 265, 266, 727 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 728 277, 278, 279, 280, 281, 282, -1, -1, 258, 259, 729 260, 261, 262, 263, 291, 265, 266, 267, 268, 269, 730 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 731 280, 281, 282, -1, -1, -1, 286, 258, 259, 260, 732 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 733 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 734 281, 282, -1, 284, 258, 259, 260, 261, 262, 263, 735 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 736 274, 275, 276, 277, 278, 279, 280, 281, 282, 258, 737 259, 260, 261, 262, 263, -1, 265, 266, 267, 268, 738 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 739 279, 280, 281, 282, 740 }; 741 #define YYFINAL 33 742 #ifndef YYDEBUG 743 #define YYDEBUG 0 744 #endif 745 #define YYMAXTOKEN 291 746 #define YYUNDFTOKEN 335 747 #define YYTRANSLATE(a) ((a) > YYMAXTOKEN ? YYUNDFTOKEN : (a)) 748 #if YYDEBUG 749 static const char *const grammar_name[] = { 750 751 "end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 752 0,0,0,0,"'&'",0,"'('","')'","'*'",0,"','",0,0,0,0,0,0,0,0,0,0,0,0,0,0,"';'",0, 753 "'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 754 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 755 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 756 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 757 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 758 "T_IDENTIFIER","T_TYPEDEF_NAME","T_DEFINE_NAME","T_AUTO","T_EXTERN", 759 "T_REGISTER","T_STATIC","T_TYPEDEF","T_INLINE","T_EXTENSION","T_CHAR", 760 "T_DOUBLE","T_FLOAT","T_INT","T_VOID","T_LONG","T_SHORT","T_SIGNED", 761 "T_UNSIGNED","T_ENUM","T_STRUCT","T_UNION","T_Bool","T_Complex","T_Imaginary", 762 "T_TYPE_QUALIFIER","T_BRACKETS","T_LBRACE","T_MATCHRBRACE","T_ELLIPSIS", 763 "T_INITIALIZER","T_STRING_LITERAL","T_ASM","T_ASMARG","T_VA_DCL",0,0,0,0,0,0,0, 764 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 765 "illegal-symbol", 766 }; 767 static const char *const grammar_rule[] = { 768 "$accept : program", 769 "program :", 770 "program : translation_unit", 771 "translation_unit : external_declaration", 772 "translation_unit : translation_unit external_declaration", 773 "external_declaration : declaration", 774 "external_declaration : function_definition", 775 "external_declaration : ';'", 776 "external_declaration : linkage_specification", 777 "external_declaration : T_ASM T_ASMARG ';'", 778 "external_declaration : error T_MATCHRBRACE", 779 "external_declaration : error ';'", 780 "braces : T_LBRACE T_MATCHRBRACE", 781 "linkage_specification : T_EXTERN T_STRING_LITERAL braces", 782 "linkage_specification : T_EXTERN T_STRING_LITERAL declaration", 783 "declaration : decl_specifiers ';'", 784 "declaration : decl_specifiers init_declarator_list ';'", 785 "$$1 :", 786 "declaration : any_typedef decl_specifiers $$1 opt_declarator_list ';'", 787 "any_typedef : T_EXTENSION T_TYPEDEF", 788 "any_typedef : T_TYPEDEF", 789 "opt_declarator_list :", 790 "opt_declarator_list : declarator_list", 791 "declarator_list : declarator", 792 "declarator_list : declarator_list ',' declarator", 793 "$$2 :", 794 "$$3 :", 795 "function_definition : decl_specifiers declarator $$2 opt_declaration_list T_LBRACE $$3 T_MATCHRBRACE", 796 "$$4 :", 797 "function_definition : declarator $$4 opt_declaration_list T_LBRACE T_MATCHRBRACE", 798 "opt_declaration_list :", 799 "opt_declaration_list : T_VA_DCL", 800 "opt_declaration_list : declaration_list", 801 "declaration_list : declaration", 802 "declaration_list : declaration_list declaration", 803 "decl_specifiers : decl_specifier", 804 "decl_specifiers : decl_specifiers decl_specifier", 805 "decl_specifier : storage_class", 806 "decl_specifier : type_specifier", 807 "decl_specifier : type_qualifier", 808 "storage_class : T_AUTO", 809 "storage_class : T_EXTERN", 810 "storage_class : T_REGISTER", 811 "storage_class : T_STATIC", 812 "storage_class : T_INLINE", 813 "storage_class : T_EXTENSION", 814 "type_specifier : T_CHAR", 815 "type_specifier : T_DOUBLE", 816 "type_specifier : T_FLOAT", 817 "type_specifier : T_INT", 818 "type_specifier : T_LONG", 819 "type_specifier : T_SHORT", 820 "type_specifier : T_SIGNED", 821 "type_specifier : T_UNSIGNED", 822 "type_specifier : T_VOID", 823 "type_specifier : T_Bool", 824 "type_specifier : T_Complex", 825 "type_specifier : T_Imaginary", 826 "type_specifier : T_TYPEDEF_NAME", 827 "type_specifier : struct_or_union_specifier", 828 "type_specifier : enum_specifier", 829 "type_qualifier : T_TYPE_QUALIFIER", 830 "type_qualifier : T_DEFINE_NAME", 831 "struct_or_union_specifier : struct_or_union any_id braces", 832 "struct_or_union_specifier : struct_or_union braces", 833 "struct_or_union_specifier : struct_or_union any_id", 834 "struct_or_union : T_STRUCT", 835 "struct_or_union : T_UNION", 836 "init_declarator_list : init_declarator", 837 "init_declarator_list : init_declarator_list ',' init_declarator", 838 "init_declarator : declarator", 839 "$$5 :", 840 "init_declarator : declarator '=' $$5 T_INITIALIZER", 841 "enum_specifier : enumeration any_id braces", 842 "enum_specifier : enumeration braces", 843 "enum_specifier : enumeration any_id", 844 "enumeration : T_ENUM", 845 "any_id : T_IDENTIFIER", 846 "any_id : T_TYPEDEF_NAME", 847 "declarator : pointer direct_declarator", 848 "declarator : direct_declarator", 849 "direct_declarator : identifier_or_ref", 850 "direct_declarator : '(' declarator ')'", 851 "direct_declarator : direct_declarator T_BRACKETS", 852 "direct_declarator : direct_declarator '(' parameter_type_list ')'", 853 "direct_declarator : direct_declarator '(' opt_identifier_list ')'", 854 "pointer : '*' opt_type_qualifiers", 855 "pointer : '*' opt_type_qualifiers pointer", 856 "opt_type_qualifiers :", 857 "opt_type_qualifiers : type_qualifier_list", 858 "type_qualifier_list : type_qualifier", 859 "type_qualifier_list : type_qualifier_list type_qualifier", 860 "parameter_type_list : parameter_list", 861 "parameter_type_list : parameter_list ',' T_ELLIPSIS", 862 "parameter_list : parameter_declaration", 863 "parameter_list : parameter_list ',' parameter_declaration", 864 "parameter_declaration : decl_specifiers declarator", 865 "parameter_declaration : decl_specifiers abs_declarator", 866 "parameter_declaration : decl_specifiers", 867 "opt_identifier_list :", 868 "opt_identifier_list : identifier_list", 869 "identifier_list : any_id", 870 "identifier_list : identifier_list ',' any_id", 871 "identifier_or_ref : any_id", 872 "identifier_or_ref : '&' any_id", 873 "abs_declarator : pointer", 874 "abs_declarator : pointer direct_abs_declarator", 875 "abs_declarator : direct_abs_declarator", 876 "direct_abs_declarator : '(' abs_declarator ')'", 877 "direct_abs_declarator : direct_abs_declarator T_BRACKETS", 878 "direct_abs_declarator : T_BRACKETS", 879 "direct_abs_declarator : direct_abs_declarator '(' parameter_type_list ')'", 880 "direct_abs_declarator : direct_abs_declarator '(' ')'", 881 "direct_abs_declarator : '(' parameter_type_list ')'", 882 "direct_abs_declarator : '(' ')'", 883 884 }; 885 #endif 886 887 int yydebug; 888 int yynerrs; 889 890 int yyerrflag; 891 int yychar; 892 YYSTYPE yyval; 893 YYSTYPE yylval; 894 895 /* define the initial stack-sizes */ 896 #ifdef YYSTACKSIZE 897 #undef YYMAXDEPTH 898 #define YYMAXDEPTH YYSTACKSIZE 899 #else 900 #ifdef YYMAXDEPTH 901 #define YYSTACKSIZE YYMAXDEPTH 902 #else 903 #define YYSTACKSIZE 10000 904 #define YYMAXDEPTH 10000 905 #endif 906 #endif 907 908 #define YYINITSTACKSIZE 200 909 910 typedef struct { 911 unsigned stacksize; 912 YYINT *s_base; 913 YYINT *s_mark; 914 YYINT *s_last; 915 YYSTYPE *l_base; 916 YYSTYPE *l_mark; 917 } YYSTACKDATA; 918 /* variables for the parser stack */ 919 static YYSTACKDATA yystack; 920 #line 1014 "grammar.y" 921 922 /* lex.yy.c */ 923 #define BEGIN yy_start = 1 + 2 * 924 925 #define CPP1 1 926 #define INIT1 2 927 #define INIT2 3 928 #define CURLY 4 929 #define LEXYACC 5 930 #define ASM 6 931 #define CPP_INLINE 7 932 933 extern char *yytext; 934 extern FILE *yyin, *yyout; 935 936 static int curly; /* number of curly brace nesting levels */ 937 static int ly_count; /* number of occurances of %% */ 938 static int inc_depth; /* include nesting level */ 939 static SymbolTable *included_files; /* files already included */ 940 static int yy_start = 0; /* start state number */ 941 942 #define grammar_error(s) yaccError(s) 943 944 static void 945 yaccError (const char *msg) 946 { 947 func_params = NULL; 948 put_error(); /* tell what line we're on, and what file */ 949 fprintf(stderr, "%s at token '%s'\n", msg, yytext); 950 } 951 952 /* Initialize the table of type qualifier keywords recognized by the lexical 953 * analyzer. 954 */ 955 void 956 init_parser (void) 957 { 958 static const char *keywords[] = { 959 "const", 960 "restrict", 961 "volatile", 962 "interrupt", 963 #ifdef vms 964 "noshare", 965 "readonly", 966 #endif 967 #if defined(MSDOS) || defined(OS2) 968 "__cdecl", 969 "__export", 970 "__far", 971 "__fastcall", 972 "__fortran", 973 "__huge", 974 "__inline", 975 "__interrupt", 976 "__loadds", 977 "__near", 978 "__pascal", 979 "__saveregs", 980 "__segment", 981 "__stdcall", 982 "__syscall", 983 "_cdecl", 984 "_cs", 985 "_ds", 986 "_es", 987 "_export", 988 "_far", 989 "_fastcall", 990 "_fortran", 991 "_huge", 992 "_interrupt", 993 "_loadds", 994 "_near", 995 "_pascal", 996 "_saveregs", 997 "_seg", 998 "_segment", 999 "_ss", 1000 "cdecl", 1001 "far", 1002 "huge", 1003 "near", 1004 "pascal", 1005 #ifdef OS2 1006 "__far16", 1007 #endif 1008 #endif 1009 #ifdef __GNUC__ 1010 /* gcc aliases */ 1011 "__builtin_va_arg", 1012 "__builtin_va_list", 1013 "__const", 1014 "__const__", 1015 "__inline", 1016 "__inline__", 1017 "__restrict", 1018 "__restrict__", 1019 "__volatile", 1020 "__volatile__", 1021 #endif 1022 }; 1023 unsigned i; 1024 1025 /* Initialize type qualifier table. */ 1026 type_qualifiers = new_symbol_table(); 1027 for (i = 0; i < sizeof(keywords)/sizeof(keywords[0]); ++i) { 1028 new_symbol(type_qualifiers, keywords[i], NULL, DS_NONE); 1029 } 1030 } 1031 1032 /* Process the C source file. Write function prototypes to the standard 1033 * output. Convert function definitions and write the converted source 1034 * code to a temporary file. 1035 */ 1036 void 1037 process_file (FILE *infile, char *name) 1038 { 1039 char *s; 1040 1041 if (strlen(name) > 2) { 1042 s = name + strlen(name) - 2; 1043 if (*s == '.') { 1044 ++s; 1045 if (*s == 'l' || *s == 'y') 1046 BEGIN LEXYACC; 1047 #if defined(MSDOS) || defined(OS2) 1048 if (*s == 'L' || *s == 'Y') 1049 BEGIN LEXYACC; 1050 #endif 1051 } 1052 } 1053 1054 included_files = new_symbol_table(); 1055 typedef_names = new_symbol_table(); 1056 define_names = new_symbol_table(); 1057 inc_depth = -1; 1058 curly = 0; 1059 ly_count = 0; 1060 func_params = NULL; 1061 yyin = infile; 1062 include_file(strcpy(base_file, name), func_style != FUNC_NONE); 1063 if (file_comments) { 1064 #if OPT_LINTLIBRARY 1065 if (lintLibrary()) { 1066 put_blankline(stdout); 1067 begin_tracking(); 1068 } 1069 #endif 1070 put_string(stdout, "/* "); 1071 put_string(stdout, cur_file_name()); 1072 put_string(stdout, " */\n"); 1073 } 1074 yyparse(); 1075 free_symbol_table(define_names); 1076 free_symbol_table(typedef_names); 1077 free_symbol_table(included_files); 1078 } 1079 1080 #ifdef NO_LEAKS 1081 void 1082 free_parser(void) 1083 { 1084 free_symbol_table (type_qualifiers); 1085 #ifdef FLEX_SCANNER 1086 if (yy_current_buffer != 0) 1087 yy_delete_buffer(yy_current_buffer); 1088 #endif 1089 } 1090 #endif 1091 #line 1092 "grammar.tab.c" 1092 1093 #if YYDEBUG 1094 #include <stdio.h> /* needed for printf */ 1095 #endif 1096 1097 #include <stdlib.h> /* needed for malloc, etc */ 1098 #include <string.h> /* needed for memset */ 1099 1100 /* allocate initial stack or double stack size, up to YYMAXDEPTH */ 1101 static int yygrowstack(YYSTACKDATA *data) 1102 { 1103 int i; 1104 unsigned newsize; 1105 YYINT *newss; 1106 YYSTYPE *newvs; 1107 1108 if ((newsize = data->stacksize) == 0) 1109 newsize = YYINITSTACKSIZE; 1110 else if (newsize >= YYMAXDEPTH) 1111 return YYENOMEM; 1112 else if ((newsize *= 2) > YYMAXDEPTH) 1113 newsize = YYMAXDEPTH; 1114 1115 i = (int) (data->s_mark - data->s_base); 1116 newss = (YYINT *)realloc(data->s_base, newsize * sizeof(*newss)); 1117 if (newss == 0) 1118 return YYENOMEM; 1119 1120 data->s_base = newss; 1121 data->s_mark = newss + i; 1122 1123 newvs = (YYSTYPE *)realloc(data->l_base, newsize * sizeof(*newvs)); 1124 if (newvs == 0) 1125 return YYENOMEM; 1126 1127 data->l_base = newvs; 1128 data->l_mark = newvs + i; 1129 1130 data->stacksize = newsize; 1131 data->s_last = data->s_base + newsize - 1; 1132 return 0; 1133 } 1134 1135 #if YYPURE || defined(YY_NO_LEAKS) 1136 static void yyfreestack(YYSTACKDATA *data) 1137 { 1138 free(data->s_base); 1139 free(data->l_base); 1140 memset(data, 0, sizeof(*data)); 1141 } 1142 #else 1143 #define yyfreestack(data) /* nothing */ 1144 #endif 1145 1146 #define YYABORT goto yyabort 1147 #define YYREJECT goto yyabort 1148 #define YYACCEPT goto yyaccept 1149 #define YYERROR goto yyerrlab 1150 1151 int 1152 YYPARSE_DECL() 1153 { 1154 int yym, yyn, yystate; 1155 #if YYDEBUG 1156 const char *yys; 1157 1158 if ((yys = getenv("YYDEBUG")) != 0) 1159 { 1160 yyn = *yys; 1161 if (yyn >= '0' && yyn <= '9') 1162 yydebug = yyn - '0'; 1163 } 1164 #endif 1165 1166 yynerrs = 0; 1167 yyerrflag = 0; 1168 yychar = YYEMPTY; 1169 yystate = 0; 1170 1171 #if YYPURE 1172 memset(&yystack, 0, sizeof(yystack)); 1173 #endif 1174 1175 if (yystack.s_base == NULL && yygrowstack(&yystack) == YYENOMEM) goto yyoverflow; 1176 yystack.s_mark = yystack.s_base; 1177 yystack.l_mark = yystack.l_base; 1178 yystate = 0; 1179 *yystack.s_mark = 0; 1180 1181 yyloop: 1182 if ((yyn = yydefred[yystate]) != 0) goto yyreduce; 1183 if (yychar < 0) 1184 { 1185 if ((yychar = YYLEX) < 0) yychar = YYEOF; 1186 #if YYDEBUG 1187 if (yydebug) 1188 { 1189 yys = yyname[YYTRANSLATE(yychar)]; 1190 printf("%sdebug: state %d, reading %d (%s)\n", 1191 YYPREFIX, yystate, yychar, yys); 1192 } 1193 #endif 1194 } 1195 if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && 1196 yyn <= YYTABLESIZE && yycheck[yyn] == yychar) 1197 { 1198 #if YYDEBUG 1199 if (yydebug) 1200 printf("%sdebug: state %d, shifting to state %d\n", 1201 YYPREFIX, yystate, yytable[yyn]); 1202 #endif 1203 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) 1204 { 1205 goto yyoverflow; 1206 } 1207 yystate = yytable[yyn]; 1208 *++yystack.s_mark = yytable[yyn]; 1209 *++yystack.l_mark = yylval; 1210 yychar = YYEMPTY; 1211 if (yyerrflag > 0) --yyerrflag; 1212 goto yyloop; 1213 } 1214 if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && 1215 yyn <= YYTABLESIZE && yycheck[yyn] == yychar) 1216 { 1217 yyn = yytable[yyn]; 1218 goto yyreduce; 1219 } 1220 if (yyerrflag) goto yyinrecovery; 1221 1222 YYERROR_CALL("syntax error"); 1223 1224 goto yyerrlab; 1225 1226 yyerrlab: 1227 ++yynerrs; 1228 1229 yyinrecovery: 1230 if (yyerrflag < 3) 1231 { 1232 yyerrflag = 3; 1233 for (;;) 1234 { 1235 if ((yyn = yysindex[*yystack.s_mark]) && (yyn += YYERRCODE) >= 0 && 1236 yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) 1237 { 1238 #if YYDEBUG 1239 if (yydebug) 1240 printf("%sdebug: state %d, error recovery shifting\ 1241 to state %d\n", YYPREFIX, *yystack.s_mark, yytable[yyn]); 1242 #endif 1243 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) 1244 { 1245 goto yyoverflow; 1246 } 1247 yystate = yytable[yyn]; 1248 *++yystack.s_mark = yytable[yyn]; 1249 *++yystack.l_mark = yylval; 1250 goto yyloop; 1251 } 1252 else 1253 { 1254 #if YYDEBUG 1255 if (yydebug) 1256 printf("%sdebug: error recovery discarding state %d\n", 1257 YYPREFIX, *yystack.s_mark); 1258 #endif 1259 if (yystack.s_mark <= yystack.s_base) goto yyabort; 1260 --yystack.s_mark; 1261 --yystack.l_mark; 1262 } 1263 } 1264 } 1265 else 1266 { 1267 if (yychar == YYEOF) goto yyabort; 1268 #if YYDEBUG 1269 if (yydebug) 1270 { 1271 yys = yyname[YYTRANSLATE(yychar)]; 1272 printf("%sdebug: state %d, error recovery discards token %d (%s)\n", 1273 YYPREFIX, yystate, yychar, yys); 1274 } 1275 #endif 1276 yychar = YYEMPTY; 1277 goto yyloop; 1278 } 1279 1280 yyreduce: 1281 #if YYDEBUG 1282 if (yydebug) 1283 printf("%sdebug: state %d, reducing by rule %d (%s)\n", 1284 YYPREFIX, yystate, yyn, yyrule[yyn]); 1285 #endif 1286 yym = yylen[yyn]; 1287 if (yym) 1288 yyval = yystack.l_mark[1-yym]; 1289 else 1290 memset(&yyval, 0, sizeof yyval); 1291 switch (yyn) 1292 { 1293 case 10: 1294 #line 377 "grammar.y" 1295 { 1296 yyerrok; 1297 } 1298 break; 1299 case 11: 1300 #line 381 "grammar.y" 1301 { 1302 yyerrok; 1303 } 1304 break; 1305 case 13: 1306 #line 392 "grammar.y" 1307 { 1308 /* Provide an empty action here so bison will not complain about 1309 * incompatible types in the default action it normally would 1310 * have generated. 1311 */ 1312 } 1313 break; 1314 case 14: 1315 #line 399 "grammar.y" 1316 { 1317 /* empty */ 1318 } 1319 break; 1320 case 15: 1321 #line 406 "grammar.y" 1322 { 1323 #if OPT_LINTLIBRARY 1324 if (types_out && want_typedef()) { 1325 gen_declarations(&yystack.l_mark[-1].decl_spec, (DeclaratorList *)0); 1326 flush_varargs(); 1327 } 1328 #endif 1329 free_decl_spec(&yystack.l_mark[-1].decl_spec); 1330 end_typedef(); 1331 } 1332 break; 1333 case 16: 1334 #line 417 "grammar.y" 1335 { 1336 if (func_params != NULL) { 1337 set_param_types(func_params, &yystack.l_mark[-2].decl_spec, &yystack.l_mark[-1].decl_list); 1338 } else { 1339 gen_declarations(&yystack.l_mark[-2].decl_spec, &yystack.l_mark[-1].decl_list); 1340 #if OPT_LINTLIBRARY 1341 flush_varargs(); 1342 #endif 1343 free_decl_list(&yystack.l_mark[-1].decl_list); 1344 } 1345 free_decl_spec(&yystack.l_mark[-2].decl_spec); 1346 end_typedef(); 1347 } 1348 break; 1349 case 17: 1350 #line 431 "grammar.y" 1351 { 1352 cur_decl_spec_flags = yystack.l_mark[0].decl_spec.flags; 1353 free_decl_spec(&yystack.l_mark[0].decl_spec); 1354 } 1355 break; 1356 case 18: 1357 #line 436 "grammar.y" 1358 { 1359 end_typedef(); 1360 } 1361 break; 1362 case 19: 1363 #line 443 "grammar.y" 1364 { 1365 begin_typedef(); 1366 } 1367 break; 1368 case 20: 1369 #line 447 "grammar.y" 1370 { 1371 begin_typedef(); 1372 } 1373 break; 1374 case 23: 1375 #line 459 "grammar.y" 1376 { 1377 int flags = cur_decl_spec_flags; 1378 1379 /* If the typedef is a pointer type, then reset the short type 1380 * flags so it does not get promoted. 1381 */ 1382 if (strcmp(yystack.l_mark[0].declarator->text, yystack.l_mark[0].declarator->name) != 0) 1383 flags &= ~(DS_CHAR | DS_SHORT | DS_FLOAT); 1384 new_symbol(typedef_names, yystack.l_mark[0].declarator->name, NULL, flags); 1385 free_declarator(yystack.l_mark[0].declarator); 1386 } 1387 break; 1388 case 24: 1389 #line 471 "grammar.y" 1390 { 1391 int flags = cur_decl_spec_flags; 1392 1393 if (strcmp(yystack.l_mark[0].declarator->text, yystack.l_mark[0].declarator->name) != 0) 1394 flags &= ~(DS_CHAR | DS_SHORT | DS_FLOAT); 1395 new_symbol(typedef_names, yystack.l_mark[0].declarator->name, NULL, flags); 1396 free_declarator(yystack.l_mark[0].declarator); 1397 } 1398 break; 1399 case 25: 1400 #line 483 "grammar.y" 1401 { 1402 check_untagged(&yystack.l_mark[-1].decl_spec); 1403 if (yystack.l_mark[0].declarator->func_def == FUNC_NONE) { 1404 yyerror("syntax error"); 1405 YYERROR; 1406 } 1407 func_params = &(yystack.l_mark[0].declarator->head->params); 1408 func_params->begin_comment = cur_file->begin_comment; 1409 func_params->end_comment = cur_file->end_comment; 1410 } 1411 break; 1412 case 26: 1413 #line 494 "grammar.y" 1414 { 1415 /* If we're converting to K&R and we've got a nominally K&R 1416 * function which has a parameter which is ANSI (i.e., a prototyped 1417 * function pointer), then we must override the deciphered value of 1418 * 'func_def' so that the parameter will be converted. 1419 */ 1420 if (func_style == FUNC_TRADITIONAL 1421 && haveAnsiParam() 1422 && yystack.l_mark[-3].declarator->head->func_def == func_style) { 1423 yystack.l_mark[-3].declarator->head->func_def = FUNC_BOTH; 1424 } 1425 1426 func_params = NULL; 1427 1428 if (cur_file->convert) 1429 gen_func_definition(&yystack.l_mark[-4].decl_spec, yystack.l_mark[-3].declarator); 1430 gen_prototype(&yystack.l_mark[-4].decl_spec, yystack.l_mark[-3].declarator); 1431 #if OPT_LINTLIBRARY 1432 flush_varargs(); 1433 #endif 1434 free_decl_spec(&yystack.l_mark[-4].decl_spec); 1435 free_declarator(yystack.l_mark[-3].declarator); 1436 } 1437 break; 1438 case 28: 1439 #line 519 "grammar.y" 1440 { 1441 if (yystack.l_mark[0].declarator->func_def == FUNC_NONE) { 1442 yyerror("syntax error"); 1443 YYERROR; 1444 } 1445 func_params = &(yystack.l_mark[0].declarator->head->params); 1446 func_params->begin_comment = cur_file->begin_comment; 1447 func_params->end_comment = cur_file->end_comment; 1448 } 1449 break; 1450 case 29: 1451 #line 529 "grammar.y" 1452 { 1453 DeclSpec decl_spec; 1454 1455 func_params = NULL; 1456 1457 new_decl_spec(&decl_spec, dft_decl_spec(), yystack.l_mark[-4].declarator->begin, DS_NONE); 1458 if (cur_file->convert) 1459 gen_func_definition(&decl_spec, yystack.l_mark[-4].declarator); 1460 gen_prototype(&decl_spec, yystack.l_mark[-4].declarator); 1461 #if OPT_LINTLIBRARY 1462 flush_varargs(); 1463 #endif 1464 free_decl_spec(&decl_spec); 1465 free_declarator(yystack.l_mark[-4].declarator); 1466 } 1467 break; 1468 case 36: 1469 #line 560 "grammar.y" 1470 { 1471 join_decl_specs(&yyval.decl_spec, &yystack.l_mark[-1].decl_spec, &yystack.l_mark[0].decl_spec); 1472 free(yystack.l_mark[-1].decl_spec.text); 1473 free(yystack.l_mark[0].decl_spec.text); 1474 } 1475 break; 1476 case 40: 1477 #line 575 "grammar.y" 1478 { 1479 new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE); 1480 } 1481 break; 1482 case 41: 1483 #line 579 "grammar.y" 1484 { 1485 new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_EXTERN); 1486 } 1487 break; 1488 case 42: 1489 #line 583 "grammar.y" 1490 { 1491 new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE); 1492 } 1493 break; 1494 case 43: 1495 #line 587 "grammar.y" 1496 { 1497 new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_STATIC); 1498 } 1499 break; 1500 case 44: 1501 #line 591 "grammar.y" 1502 { 1503 new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_INLINE); 1504 } 1505 break; 1506 case 45: 1507 #line 595 "grammar.y" 1508 { 1509 new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_JUNK); 1510 } 1511 break; 1512 case 46: 1513 #line 602 "grammar.y" 1514 { 1515 new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_CHAR); 1516 } 1517 break; 1518 case 47: 1519 #line 606 "grammar.y" 1520 { 1521 new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE); 1522 } 1523 break; 1524 case 48: 1525 #line 610 "grammar.y" 1526 { 1527 new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_FLOAT); 1528 } 1529 break; 1530 case 49: 1531 #line 614 "grammar.y" 1532 { 1533 new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE); 1534 } 1535 break; 1536 case 50: 1537 #line 618 "grammar.y" 1538 { 1539 new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE); 1540 } 1541 break; 1542 case 51: 1543 #line 622 "grammar.y" 1544 { 1545 new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_SHORT); 1546 } 1547 break; 1548 case 52: 1549 #line 626 "grammar.y" 1550 { 1551 new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE); 1552 } 1553 break; 1554 case 53: 1555 #line 630 "grammar.y" 1556 { 1557 new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE); 1558 } 1559 break; 1560 case 54: 1561 #line 634 "grammar.y" 1562 { 1563 new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE); 1564 } 1565 break; 1566 case 55: 1567 #line 638 "grammar.y" 1568 { 1569 new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_CHAR); 1570 } 1571 break; 1572 case 56: 1573 #line 642 "grammar.y" 1574 { 1575 new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE); 1576 } 1577 break; 1578 case 57: 1579 #line 646 "grammar.y" 1580 { 1581 new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE); 1582 } 1583 break; 1584 case 58: 1585 #line 650 "grammar.y" 1586 { 1587 Symbol *s; 1588 s = find_symbol(typedef_names, yystack.l_mark[0].text.text); 1589 if (s != NULL) 1590 new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, s->flags); 1591 } 1592 break; 1593 case 61: 1594 #line 662 "grammar.y" 1595 { 1596 new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, DS_NONE); 1597 } 1598 break; 1599 case 62: 1600 #line 666 "grammar.y" 1601 { 1602 /* This rule allows the <pointer> nonterminal to scan #define 1603 * names as if they were type modifiers. 1604 */ 1605 Symbol *s; 1606 s = find_symbol(define_names, yystack.l_mark[0].text.text); 1607 if (s != NULL) 1608 new_decl_spec(&yyval.decl_spec, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin, s->flags); 1609 } 1610 break; 1611 case 63: 1612 #line 679 "grammar.y" 1613 { 1614 char *s; 1615 if ((s = implied_typedef()) == 0) 1616 (void)sprintf(s = buf, "%s %s", yystack.l_mark[-2].text.text, yystack.l_mark[-1].text.text); 1617 new_decl_spec(&yyval.decl_spec, s, yystack.l_mark[-2].text.begin, DS_NONE); 1618 } 1619 break; 1620 case 64: 1621 #line 686 "grammar.y" 1622 { 1623 char *s; 1624 if ((s = implied_typedef()) == 0) 1625 (void)sprintf(s = buf, "%s {}", yystack.l_mark[-1].text.text); 1626 new_decl_spec(&yyval.decl_spec, s, yystack.l_mark[-1].text.begin, DS_NONE); 1627 } 1628 break; 1629 case 65: 1630 #line 693 "grammar.y" 1631 { 1632 (void)sprintf(buf, "%s %s", yystack.l_mark[-1].text.text, yystack.l_mark[0].text.text); 1633 new_decl_spec(&yyval.decl_spec, buf, yystack.l_mark[-1].text.begin, DS_NONE); 1634 } 1635 break; 1636 case 66: 1637 #line 701 "grammar.y" 1638 { 1639 imply_typedef(yyval.text.text); 1640 } 1641 break; 1642 case 67: 1643 #line 705 "grammar.y" 1644 { 1645 imply_typedef(yyval.text.text); 1646 } 1647 break; 1648 case 68: 1649 #line 712 "grammar.y" 1650 { 1651 new_decl_list(&yyval.decl_list, yystack.l_mark[0].declarator); 1652 } 1653 break; 1654 case 69: 1655 #line 716 "grammar.y" 1656 { 1657 add_decl_list(&yyval.decl_list, &yystack.l_mark[-2].decl_list, yystack.l_mark[0].declarator); 1658 } 1659 break; 1660 case 70: 1661 #line 723 "grammar.y" 1662 { 1663 if (yystack.l_mark[0].declarator->func_def != FUNC_NONE && func_params == NULL && 1664 func_style == FUNC_TRADITIONAL && cur_file->convert) { 1665 gen_func_declarator(yystack.l_mark[0].declarator); 1666 fputs(cur_text(), cur_file->tmp_file); 1667 } 1668 cur_declarator = yyval.declarator; 1669 } 1670 break; 1671 case 71: 1672 #line 732 "grammar.y" 1673 { 1674 if (yystack.l_mark[-1].declarator->func_def != FUNC_NONE && func_params == NULL && 1675 func_style == FUNC_TRADITIONAL && cur_file->convert) { 1676 gen_func_declarator(yystack.l_mark[-1].declarator); 1677 fputs(" =", cur_file->tmp_file); 1678 } 1679 } 1680 break; 1681 case 73: 1682 #line 744 "grammar.y" 1683 { 1684 char *s; 1685 if ((s = implied_typedef()) == 0) 1686 (void)sprintf(s = buf, "enum %s", yystack.l_mark[-1].text.text); 1687 new_decl_spec(&yyval.decl_spec, s, yystack.l_mark[-2].text.begin, DS_NONE); 1688 } 1689 break; 1690 case 74: 1691 #line 751 "grammar.y" 1692 { 1693 char *s; 1694 if ((s = implied_typedef()) == 0) 1695 (void)sprintf(s = buf, "%s {}", yystack.l_mark[-1].text.text); 1696 new_decl_spec(&yyval.decl_spec, s, yystack.l_mark[-1].text.begin, DS_NONE); 1697 } 1698 break; 1699 case 75: 1700 #line 758 "grammar.y" 1701 { 1702 (void)sprintf(buf, "enum %s", yystack.l_mark[0].text.text); 1703 new_decl_spec(&yyval.decl_spec, buf, yystack.l_mark[-1].text.begin, DS_NONE); 1704 } 1705 break; 1706 case 76: 1707 #line 766 "grammar.y" 1708 { 1709 imply_typedef("enum"); 1710 yyval.text = yystack.l_mark[0].text; 1711 } 1712 break; 1713 case 79: 1714 #line 779 "grammar.y" 1715 { 1716 yyval.declarator = yystack.l_mark[0].declarator; 1717 (void)sprintf(buf, "%s%s", yystack.l_mark[-1].text.text, yyval.declarator->text); 1718 free(yyval.declarator->text); 1719 yyval.declarator->text = xstrdup(buf); 1720 yyval.declarator->begin = yystack.l_mark[-1].text.begin; 1721 yyval.declarator->pointer = TRUE; 1722 } 1723 break; 1724 case 81: 1725 #line 792 "grammar.y" 1726 { 1727 yyval.declarator = new_declarator(yystack.l_mark[0].text.text, yystack.l_mark[0].text.text, yystack.l_mark[0].text.begin); 1728 } 1729 break; 1730 case 82: 1731 #line 796 "grammar.y" 1732 { 1733 yyval.declarator = yystack.l_mark[-1].declarator; 1734 (void)sprintf(buf, "(%s)", yyval.declarator->text); 1735 free(yyval.declarator->text); 1736 yyval.declarator->text = xstrdup(buf); 1737 yyval.declarator->begin = yystack.l_mark[-2].text.begin; 1738 } 1739 break; 1740 case 83: 1741 #line 804 "grammar.y" 1742 { 1743 yyval.declarator = yystack.l_mark[-1].declarator; 1744 (void)sprintf(buf, "%s%s", yyval.declarator->text, yystack.l_mark[0].text.text); 1745 free(yyval.declarator->text); 1746 yyval.declarator->text = xstrdup(buf); 1747 } 1748 break; 1749 case 84: 1750 #line 811 "grammar.y" 1751 { 1752 yyval.declarator = new_declarator("%s()", yystack.l_mark[-3].declarator->name, yystack.l_mark[-3].declarator->begin); 1753 yyval.declarator->params = yystack.l_mark[-1].param_list; 1754 yyval.declarator->func_stack = yystack.l_mark[-3].declarator; 1755 yyval.declarator->head = (yystack.l_mark[-3].declarator->func_stack == NULL) ? yyval.declarator : yystack.l_mark[-3].declarator->head; 1756 yyval.declarator->func_def = FUNC_ANSI; 1757 } 1758 break; 1759 case 85: 1760 #line 819 "grammar.y" 1761 { 1762 yyval.declarator = new_declarator("%s()", yystack.l_mark[-3].declarator->name, yystack.l_mark[-3].declarator->begin); 1763 yyval.declarator->params = yystack.l_mark[-1].param_list; 1764 yyval.declarator->func_stack = yystack.l_mark[-3].declarator; 1765 yyval.declarator->head = (yystack.l_mark[-3].declarator->func_stack == NULL) ? yyval.declarator : yystack.l_mark[-3].declarator->head; 1766 yyval.declarator->func_def = FUNC_TRADITIONAL; 1767 } 1768 break; 1769 case 86: 1770 #line 830 "grammar.y" 1771 { 1772 (void)sprintf(yyval.text.text, "*%s", yystack.l_mark[0].text.text); 1773 yyval.text.begin = yystack.l_mark[-1].text.begin; 1774 } 1775 break; 1776 case 87: 1777 #line 835 "grammar.y" 1778 { 1779 (void)sprintf(yyval.text.text, "*%s%s", yystack.l_mark[-1].text.text, yystack.l_mark[0].text.text); 1780 yyval.text.begin = yystack.l_mark[-2].text.begin; 1781 } 1782 break; 1783 case 88: 1784 #line 843 "grammar.y" 1785 { 1786 strcpy(yyval.text.text, ""); 1787 yyval.text.begin = 0L; 1788 } 1789 break; 1790 case 90: 1791 #line 852 "grammar.y" 1792 { 1793 (void)sprintf(yyval.text.text, "%s ", yystack.l_mark[0].decl_spec.text); 1794 yyval.text.begin = yystack.l_mark[0].decl_spec.begin; 1795 free(yystack.l_mark[0].decl_spec.text); 1796 } 1797 break; 1798 case 91: 1799 #line 858 "grammar.y" 1800 { 1801 (void)sprintf(yyval.text.text, "%s%s ", yystack.l_mark[-1].text.text, yystack.l_mark[0].decl_spec.text); 1802 yyval.text.begin = yystack.l_mark[-1].text.begin; 1803 free(yystack.l_mark[0].decl_spec.text); 1804 } 1805 break; 1806 case 93: 1807 #line 868 "grammar.y" 1808 { 1809 add_ident_list(&yyval.param_list, &yystack.l_mark[-2].param_list, "..."); 1810 } 1811 break; 1812 case 94: 1813 #line 875 "grammar.y" 1814 { 1815 new_param_list(&yyval.param_list, yystack.l_mark[0].parameter); 1816 } 1817 break; 1818 case 95: 1819 #line 879 "grammar.y" 1820 { 1821 add_param_list(&yyval.param_list, &yystack.l_mark[-2].param_list, yystack.l_mark[0].parameter); 1822 } 1823 break; 1824 case 96: 1825 #line 886 "grammar.y" 1826 { 1827 check_untagged(&yystack.l_mark[-1].decl_spec); 1828 yyval.parameter = new_parameter(&yystack.l_mark[-1].decl_spec, yystack.l_mark[0].declarator); 1829 } 1830 break; 1831 case 97: 1832 #line 891 "grammar.y" 1833 { 1834 check_untagged(&yystack.l_mark[-1].decl_spec); 1835 yyval.parameter = new_parameter(&yystack.l_mark[-1].decl_spec, yystack.l_mark[0].declarator); 1836 } 1837 break; 1838 case 98: 1839 #line 896 "grammar.y" 1840 { 1841 check_untagged(&yystack.l_mark[0].decl_spec); 1842 yyval.parameter = new_parameter(&yystack.l_mark[0].decl_spec, (Declarator *)0); 1843 } 1844 break; 1845 case 99: 1846 #line 904 "grammar.y" 1847 { 1848 new_ident_list(&yyval.param_list); 1849 } 1850 break; 1851 case 101: 1852 #line 912 "grammar.y" 1853 { 1854 new_ident_list(&yyval.param_list); 1855 add_ident_list(&yyval.param_list, &yyval.param_list, yystack.l_mark[0].text.text); 1856 } 1857 break; 1858 case 102: 1859 #line 917 "grammar.y" 1860 { 1861 add_ident_list(&yyval.param_list, &yystack.l_mark[-2].param_list, yystack.l_mark[0].text.text); 1862 } 1863 break; 1864 case 103: 1865 #line 924 "grammar.y" 1866 { 1867 yyval.text = yystack.l_mark[0].text; 1868 } 1869 break; 1870 case 104: 1871 #line 928 "grammar.y" 1872 { 1873 #if OPT_LINTLIBRARY 1874 if (lintLibrary()) { /* Lint doesn't grok C++ ref variables */ 1875 yyval.text = yystack.l_mark[0].text; 1876 } else 1877 #endif 1878 (void)sprintf(yyval.text.text, "&%s", yystack.l_mark[0].text.text); 1879 yyval.text.begin = yystack.l_mark[-1].text.begin; 1880 } 1881 break; 1882 case 105: 1883 #line 941 "grammar.y" 1884 { 1885 yyval.declarator = new_declarator(yystack.l_mark[0].text.text, "", yystack.l_mark[0].text.begin); 1886 } 1887 break; 1888 case 106: 1889 #line 945 "grammar.y" 1890 { 1891 yyval.declarator = yystack.l_mark[0].declarator; 1892 (void)sprintf(buf, "%s%s", yystack.l_mark[-1].text.text, yyval.declarator->text); 1893 free(yyval.declarator->text); 1894 yyval.declarator->text = xstrdup(buf); 1895 yyval.declarator->begin = yystack.l_mark[-1].text.begin; 1896 } 1897 break; 1898 case 108: 1899 #line 957 "grammar.y" 1900 { 1901 yyval.declarator = yystack.l_mark[-1].declarator; 1902 (void)sprintf(buf, "(%s)", yyval.declarator->text); 1903 free(yyval.declarator->text); 1904 yyval.declarator->text = xstrdup(buf); 1905 yyval.declarator->begin = yystack.l_mark[-2].text.begin; 1906 } 1907 break; 1908 case 109: 1909 #line 965 "grammar.y" 1910 { 1911 yyval.declarator = yystack.l_mark[-1].declarator; 1912 (void)sprintf(buf, "%s%s", yyval.declarator->text, yystack.l_mark[0].text.text); 1913 free(yyval.declarator->text); 1914 yyval.declarator->text = xstrdup(buf); 1915 } 1916 break; 1917 case 110: 1918 #line 972 "grammar.y" 1919 { 1920 yyval.declarator = new_declarator(yystack.l_mark[0].text.text, "", yystack.l_mark[0].text.begin); 1921 } 1922 break; 1923 case 111: 1924 #line 976 "grammar.y" 1925 { 1926 yyval.declarator = new_declarator("%s()", "", yystack.l_mark[-3].declarator->begin); 1927 yyval.declarator->params = yystack.l_mark[-1].param_list; 1928 yyval.declarator->func_stack = yystack.l_mark[-3].declarator; 1929 yyval.declarator->head = (yystack.l_mark[-3].declarator->func_stack == NULL) ? yyval.declarator : yystack.l_mark[-3].declarator->head; 1930 yyval.declarator->func_def = FUNC_ANSI; 1931 } 1932 break; 1933 case 112: 1934 #line 984 "grammar.y" 1935 { 1936 yyval.declarator = new_declarator("%s()", "", yystack.l_mark[-2].declarator->begin); 1937 yyval.declarator->func_stack = yystack.l_mark[-2].declarator; 1938 yyval.declarator->head = (yystack.l_mark[-2].declarator->func_stack == NULL) ? yyval.declarator : yystack.l_mark[-2].declarator->head; 1939 yyval.declarator->func_def = FUNC_ANSI; 1940 } 1941 break; 1942 case 113: 1943 #line 991 "grammar.y" 1944 { 1945 Declarator *d; 1946 1947 d = new_declarator("", "", yystack.l_mark[-2].text.begin); 1948 yyval.declarator = new_declarator("%s()", "", yystack.l_mark[-2].text.begin); 1949 yyval.declarator->params = yystack.l_mark[-1].param_list; 1950 yyval.declarator->func_stack = d; 1951 yyval.declarator->head = yyval.declarator; 1952 yyval.declarator->func_def = FUNC_ANSI; 1953 } 1954 break; 1955 case 114: 1956 #line 1002 "grammar.y" 1957 { 1958 Declarator *d; 1959 1960 d = new_declarator("", "", yystack.l_mark[-1].text.begin); 1961 yyval.declarator = new_declarator("%s()", "", yystack.l_mark[-1].text.begin); 1962 yyval.declarator->func_stack = d; 1963 yyval.declarator->head = yyval.declarator; 1964 yyval.declarator->func_def = FUNC_ANSI; 1965 } 1966 break; 1967 #line 1968 "grammar.tab.c" 1968 } 1969 yystack.s_mark -= yym; 1970 yystate = *yystack.s_mark; 1971 yystack.l_mark -= yym; 1972 yym = yylhs[yyn]; 1973 if (yystate == 0 && yym == 0) 1974 { 1975 #if YYDEBUG 1976 if (yydebug) 1977 printf("%sdebug: after reduction, shifting from state 0 to\ 1978 state %d\n", YYPREFIX, YYFINAL); 1979 #endif 1980 yystate = YYFINAL; 1981 *++yystack.s_mark = YYFINAL; 1982 *++yystack.l_mark = yyval; 1983 if (yychar < 0) 1984 { 1985 if ((yychar = YYLEX) < 0) yychar = YYEOF; 1986 #if YYDEBUG 1987 if (yydebug) 1988 { 1989 yys = yyname[YYTRANSLATE(yychar)]; 1990 printf("%sdebug: state %d, reading %d (%s)\n", 1991 YYPREFIX, YYFINAL, yychar, yys); 1992 } 1993 #endif 1994 } 1995 if (yychar == YYEOF) goto yyaccept; 1996 goto yyloop; 1997 } 1998 if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && 1999 yyn <= YYTABLESIZE && yycheck[yyn] == yystate) 2000 yystate = yytable[yyn]; 2001 else 2002 yystate = yydgoto[yym]; 2003 #if YYDEBUG 2004 if (yydebug) 2005 printf("%sdebug: after reduction, shifting from state %d \ 2006 to state %d\n", YYPREFIX, *yystack.s_mark, yystate); 2007 #endif 2008 if (yystack.s_mark >= yystack.s_last && yygrowstack(&yystack) == YYENOMEM) 2009 { 2010 goto yyoverflow; 2011 } 2012 *++yystack.s_mark = (YYINT) yystate; 2013 *++yystack.l_mark = yyval; 2014 goto yyloop; 2015 2016 yyoverflow: 2017 YYERROR_CALL("yacc stack overflow"); 2018 2019 yyabort: 2020 yyfreestack(&yystack); 2021 return (1); 2022 2023 yyaccept: 2024 yyfreestack(&yystack); 2025 return (0); 2026 } 2027