Sat Jul 10 04:25:47 2021 UTC ()
lint: remove duplicate code for parsing declarations

No functional change.


(rillig)
diff -r1.277 -r1.278 src/usr.bin/xlint/lint1/cgram.y

cvs diff -r1.277 -r1.278 src/usr.bin/xlint/lint1/cgram.y (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/cgram.y 2021/07/09 20:51:27 1.277
+++ src/usr.bin/xlint/lint1/cgram.y 2021/07/10 04:25:47 1.278
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1%{ 1%{
2/* $NetBSD: cgram.y,v 1.277 2021/07/09 20:51:27 rillig Exp $ */ 2/* $NetBSD: cgram.y,v 1.278 2021/07/10 04:25:47 rillig Exp $ */
3 3
4/* 4/*
5 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. 5 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
6 * Copyright (c) 1994, 1995 Jochen Pohl 6 * Copyright (c) 1994, 1995 Jochen Pohl
7 * All Rights Reserved. 7 * All Rights Reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the 15 * notice, this list of conditions and the following disclaimer in the
@@ -25,27 +25,27 @@ @@ -25,27 +25,27 @@
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */ 34 */
35 35
36#include <sys/cdefs.h> 36#include <sys/cdefs.h>
37#if defined(__RCSID) && !defined(lint) 37#if defined(__RCSID) && !defined(lint)
38__RCSID("$NetBSD: cgram.y,v 1.277 2021/07/09 20:51:27 rillig Exp $"); 38__RCSID("$NetBSD: cgram.y,v 1.278 2021/07/10 04:25:47 rillig Exp $");
39#endif 39#endif
40 40
41#include <limits.h> 41#include <limits.h>
42#include <stdlib.h> 42#include <stdlib.h>
43#include <string.h> 43#include <string.h>
44 44
45#include "lint1.h" 45#include "lint1.h"
46 46
47extern char *yytext; 47extern char *yytext;
48 48
49/* 49/*
50 * Contains the level of current declaration, used for symbol table entries. 50 * Contains the level of current declaration, used for symbol table entries.
51 * 0 is the top-level, > 0 is inside a function body. 51 * 0 is the top-level, > 0 is inside a function body.
@@ -393,46 +393,27 @@ top_level_declaration: /* C99 6.9 calls @@ -393,46 +393,27 @@ top_level_declaration: /* C99 6.9 calls
393 /* empty declaration */ 393 /* empty declaration */
394 warning(0); 394 warning(0);
395 } 395 }
396 } 396 }
397 | clrtyp deftyp notype_init_decls T_SEMI { 397 | clrtyp deftyp notype_init_decls T_SEMI {
398 if (sflag) { 398 if (sflag) {
399 /* old style declaration; add 'int' */ 399 /* old style declaration; add 'int' */
400 error(1); 400 error(1);
401 } else if (!tflag) { 401 } else if (!tflag) {
402 /* old style declaration; add 'int' */ 402 /* old style declaration; add 'int' */
403 warning(1); 403 warning(1);
404 } 404 }
405 } 405 }
406 | declmods deftyp T_SEMI { 406 | declaration_noerror
407 if (dcs->d_scl == TYPEDEF) { 
408 /* typedef declares no type name */ 
409 warning(72); 
410 } else { 
411 /* empty declaration */ 
412 warning(2); 
413 } 
414 } 
415 | declmods deftyp notype_init_decls T_SEMI 
416 | declaration_specifiers deftyp T_SEMI { 
417 if (dcs->d_scl == TYPEDEF) { 
418 /* typedef declares no type name */ 
419 warning(72); 
420 } else if (!dcs->d_nonempty_decl) { 
421 /* empty declaration */ 
422 warning(2); 
423 } 
424 } 
425 | declaration_specifiers deftyp type_init_decls T_SEMI 
426 | error T_SEMI { 407 | error T_SEMI {
427 global_clean_up(); 408 global_clean_up();
428 } 409 }
429 | error T_RBRACE { 410 | error T_RBRACE {
430 global_clean_up(); 411 global_clean_up();
431 } 412 }
432 ; 413 ;
433 414
434function_definition: /* C99 6.9.1 */ 415function_definition: /* C99 6.9.1 */
435 func_decl { 416 func_decl {
436 if ($1->s_type->t_tspec != FUNC) { 417 if ($1->s_type->t_tspec != FUNC) {
437 /* syntax error '%s' */ 418 /* syntax error '%s' */
438 error(249, yytext); 419 error(249, yytext);
@@ -504,47 +485,51 @@ arg_declaration: @@ -504,47 +485,51 @@ arg_declaration:
504 } 485 }
505 } 486 }
506 | declaration_specifiers deftyp type_init_decls T_SEMI { 487 | declaration_specifiers deftyp type_init_decls T_SEMI {
507 if (dcs->d_nonempty_decl) { 488 if (dcs->d_nonempty_decl) {
508 /* '%s' declared in argument declaration list */ 489 /* '%s' declared in argument declaration list */
509 warning(3, type_name(dcs->d_type)); 490 warning(3, type_name(dcs->d_type));
510 } 491 }
511 } 492 }
512 | declmods error 493 | declmods error
513 | declaration_specifiers error 494 | declaration_specifiers error
514 ; 495 ;
515 496
516declaration: /* C99 6.7 */ 497declaration: /* C99 6.7 */
 498 declaration_noerror
 499 | error T_SEMI
 500 ;
 501
 502declaration_noerror: /* see C99 6.7 'declaration' */
517 declmods deftyp T_SEMI { 503 declmods deftyp T_SEMI {
518 if (dcs->d_scl == TYPEDEF) { 504 if (dcs->d_scl == TYPEDEF) {
519 /* typedef declares no type name */ 505 /* typedef declares no type name */
520 warning(72); 506 warning(72);
521 } else { 507 } else {
522 /* empty declaration */ 508 /* empty declaration */
523 warning(2); 509 warning(2);
524 } 510 }
525 } 511 }
526 | declmods deftyp notype_init_decls T_SEMI 512 | declmods deftyp notype_init_decls T_SEMI
527 | declaration_specifiers deftyp T_SEMI { 513 | declaration_specifiers deftyp T_SEMI {
528 if (dcs->d_scl == TYPEDEF) { 514 if (dcs->d_scl == TYPEDEF) {
529 /* typedef declares no type name */ 515 /* typedef declares no type name */
530 warning(72); 516 warning(72);
531 } else if (!dcs->d_nonempty_decl) { 517 } else if (!dcs->d_nonempty_decl) {
532 /* empty declaration */ 518 /* empty declaration */
533 warning(2); 519 warning(2);
534 } 520 }
535 } 521 }
536 | declaration_specifiers deftyp type_init_decls T_SEMI 522 | declaration_specifiers deftyp type_init_decls T_SEMI
537 | error T_SEMI 
538 ; 523 ;
539 524
540clrtyp: 525clrtyp:
541 /* empty */ { 526 /* empty */ {
542 clrtyp(); 527 clrtyp();
543 } 528 }
544 ; 529 ;
545 530
546deftyp: 531deftyp:
547 /* empty */ { 532 /* empty */ {
548 deftyp(); 533 deftyp();
549 } 534 }
550 ; 535 ;