Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/xlint/lint1 lint: reorder grammar rules in the same ...



details:   https://anonhg.NetBSD.org/src/rev/d64f30eee472
branches:  trunk
changeset: 984594:d64f30eee472
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Jul 12 21:43:44 2021 +0000

description:
lint: reorder grammar rules in the same way as in C99

The code coverage before and after this change is exactly the same,
except of course for cgram.y and cgram.c.

No functional change.

diffstat:

 usr.bin/xlint/lint1/cgram.y |  2996 +++++++++++++++++++++---------------------
 1 files changed, 1509 insertions(+), 1487 deletions(-)

diffs (truncated from 3025 to 300 lines):

diff -r 4d0d9fbc01b0 -r d64f30eee472 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Mon Jul 12 19:03:20 2021 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Mon Jul 12 21:43:44 2021 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.318 2021/07/11 21:07:44 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.319 2021/07/12 21:43:44 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.318 2021/07/11 21:07:44 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.319 2021/07/12 21:43:44 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -363,6 +363,1513 @@
        | translation_unit
        ;
 
+identifier_sym:                        /* helper for struct/union/enum */
+         identifier {
+               $$ = getsym($1);
+         }
+       ;
+
+/* K&R ???, C90 ???, C99 6.4.2.1, C11 ???, C18 ??? */
+identifier:
+         T_NAME {
+               $$ = $1;
+               cgram_debug("name '%s'", $$->sb_name);
+         }
+       | T_TYPENAME {
+               $$ = $1;
+               cgram_debug("typename '%s'", $$->sb_name);
+         }
+       ;
+
+/* see C99 6.4.5, string literals are joined by 5.1.1.2 */
+string:
+         T_STRING
+       | T_STRING string2 {
+               $$ = cat_strings($1, $2);
+         }
+       ;
+
+/* see C99 6.4.5, string literals are joined by 5.1.1.2 */
+string2:
+         T_STRING {
+               if (tflag) {
+                       /* concatenated strings are illegal in traditional C */
+                       warning(219);
+               }
+               $$ = $1;
+         }
+       | string2 T_STRING {
+               $$ = cat_strings($1, $2);
+         }
+       ;
+
+/* K&R 7.1, C90 ???, C99 6.5.1, C11 6.5.1, C18 6.5.1 */
+primary_expression:
+         T_NAME {
+               /* XXX really necessary? */
+               if (yychar < 0)
+                       yychar = yylex();
+               $$ = new_name_node(getsym($1), yychar);
+         }
+       | T_CON {
+               $$ = expr_new_constant(gettyp($1->v_tspec), $1);
+         }
+       | string {
+               $$ = new_string_node($1);
+         }
+       | T_LPAREN expr T_RPAREN {
+               if ($2 != NULL)
+                       $2->tn_parenthesized = true;
+               $$ = $2;
+         }
+       | generic_selection
+       /* GCC primary-expression, see c_parser_postfix_expression */
+       | T_BUILTIN_OFFSETOF T_LPAREN type_name T_COMMA identifier T_RPAREN {
+               symtyp = FMEMBER;
+               $$ = build_offsetof($3, getsym($5));
+         }
+       ;
+
+/* K&R ---, C90 ---, C99 ---, C11 6.5.1.1, C18 6.5.1.1 */
+generic_selection:
+         T_GENERIC T_LPAREN assignment_expression T_COMMA
+           generic_assoc_list T_RPAREN {
+               /* generic selection requires C11 or later */
+               c11ism(345);
+               $$ = build_generic_selection($3, $5);
+         }
+       ;
+
+/* K&R ---, C90 ---, C99 ---, C11 6.5.1.1, C18 6.5.1.1 */
+generic_assoc_list:
+         generic_association
+       | generic_assoc_list T_COMMA generic_association {
+               $3->ga_prev = $1;
+               $$ = $3;
+         }
+       ;
+
+/* K&R ---, C90 ---, C99 ---, C11 6.5.1.1, C18 6.5.1.1 */
+generic_association:
+         type_name T_COLON assignment_expression {
+               $$ = getblk(sizeof(*$$));
+               $$->ga_arg = $1;
+               $$->ga_result = $3;
+         }
+       | T_DEFAULT T_COLON assignment_expression {
+               $$ = getblk(sizeof(*$$));
+               $$->ga_arg = NULL;
+               $$->ga_result = $3;
+         }
+       ;
+
+/* K&R 7.1, C90 ???, C99 6.5.2, C11 6.5.2, C18 6.5.2 */
+postfix_expression:
+         primary_expression
+       | postfix_expression T_LBRACK expr T_RBRACK {
+               $$ = build(INDIR, build(PLUS, $1, $3), NULL);
+         }
+       | postfix_expression T_LPAREN T_RPAREN {
+               $$ = new_function_call_node($1, NULL);
+         }
+       | postfix_expression T_LPAREN argument_expression_list T_RPAREN {
+               $$ = new_function_call_node($1, $3);
+         }
+       | postfix_expression point_or_arrow T_NAME {
+               if ($1 != NULL) {
+                       sym_t   *msym;
+                       /*
+                        * XXX struct_or_union_member should be integrated
+                        * in build()
+                        */
+                       if ($2 == ARROW) {
+                               /*
+                                * must do this before struct_or_union_member
+                                * is called
+                                */
+                               $1 = cconv($1);
+                       }
+                       msym = struct_or_union_member($1, $2, getsym($3));
+                       $$ = build($2, $1, new_name_node(msym, 0));
+               } else {
+                       $$ = NULL;
+               }
+         }
+       | postfix_expression T_INCDEC {
+               $$ = build($2 == INC ? INCAFT : DECAFT, $1, NULL);
+         }
+       | T_LPAREN type_name T_RPAREN { /* C99 6.5.2.5 "Compound literals" */
+               sym_t *tmp = mktempsym($2);
+               begin_initialization(tmp);
+               cgram_declare(tmp, true, NULL);
+         } init_lbrace initializer_list comma_opt init_rbrace {
+               if (!Sflag)
+                        /* compound literals are a C9X/GCC extension */
+                        gnuism(319);
+               $$ = new_name_node(*current_initsym(), 0);
+               end_initialization();
+         }
+       | T_LPAREN compound_statement_lbrace gcc_statement_expr_list {
+               block_level--;
+               mem_block_level--;
+               begin_initialization(mktempsym(dup_type($3->tn_type)));
+               mem_block_level++;
+               block_level++;
+               /* ({ }) is a GCC extension */
+               gnuism(320);
+         } compound_statement_rbrace T_RPAREN {
+               $$ = new_name_node(*current_initsym(), 0);
+               end_initialization();
+         }
+       ;
+
+comma_opt:                     /* helper for 'postfix_expression' */
+         /* empty */
+       | T_COMMA
+       ;
+
+/*
+ * The inner part of a GCC statement-expression of the form ({ ... }).
+ *
+ * https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
+ */
+gcc_statement_expr_list:
+         gcc_statement_expr_item
+       | gcc_statement_expr_list gcc_statement_expr_item {
+               $$ = $2;
+         }
+       ;
+
+gcc_statement_expr_item:
+         declaration {
+               clear_warning_flags();
+               $$ = NULL;
+         }
+       | non_expr_statement {
+               $$ = expr_zalloc_tnode();
+               $$->tn_type = gettyp(VOID);
+         }
+       | expr T_SEMI {
+               if ($1 == NULL) {       /* in case of syntax errors */
+                       $$ = expr_zalloc_tnode();
+                       $$->tn_type = gettyp(VOID);
+               } else {
+                       /* XXX: do that only on the last name */
+                       if ($1->tn_op == NAME)
+                               $1->tn_sym->s_used = true;
+                       $$ = $1;
+                       expr($1, false, false, false, false);
+                       seen_fallthrough = false;
+               }
+         }
+       ;
+
+point_or_arrow:                        /* helper for 'postfix_expression' */
+         T_POINT {
+               symtyp = FMEMBER;
+               $$ = POINT;
+         }
+       | T_ARROW {
+               symtyp = FMEMBER;
+               $$ = ARROW;
+         }
+       ;
+
+/* K&R 7.1, C90 ???, C99 6.5.2, C11 6.5.2, C18 6.5.2 */
+argument_expression_list:
+         expr %prec T_COMMA {
+               $$ = new_function_argument_node(NULL, $1);
+         }
+       | argument_expression_list T_COMMA expr {
+               $$ = new_function_argument_node($1, $3);
+         }
+       ;
+
+/* K&R 7.2, C90 ???, C99 6.5.3, C11 6.5.3, C18 6.5.3 */
+unary_expression:
+         postfix_expression
+       | T_INCDEC unary_expression {
+               $$ = build($1 == INC ? INCBEF : DECBEF, $2, NULL);
+         }
+       | T_AMPER cast_expression {
+               $$ = build(ADDR, $2, NULL);
+         }
+       | T_ASTERISK cast_expression {
+               $$ = build(INDIR, $2, NULL);
+         }
+       | T_ADDITIVE cast_expression {
+               if (tflag && $1 == PLUS) {
+                       /* unary + is illegal in traditional C */
+                       warning(100);
+               }
+               $$ = build($1 == PLUS ? UPLUS : UMINUS, $2, NULL);
+         }
+       | T_COMPLEMENT cast_expression {
+               $$ = build(COMPL, $2, NULL);
+         }
+       | T_LOGNOT cast_expression {
+               $$ = build(NOT, $2, NULL);
+         }
+       | T_REAL cast_expression {      /* GCC c_parser_unary_expression */
+               $$ = build(REAL, $2, NULL);
+         }
+       | T_IMAG cast_expression {      /* GCC c_parser_unary_expression */
+               $$ = build(IMAG, $2, NULL);
+         }
+       | T_EXTENSION cast_expression { /* GCC c_parser_unary_expression */
+               $$ = $2;
+         }
+       | T_SIZEOF unary_expression {
+               $$ = $2 == NULL ? NULL : build_sizeof($2->tn_type);
+               if ($$ != NULL)
+                       check_expr_misc($2, false, false, false, false, false, true);
+         }
+       | T_SIZEOF T_LPAREN type_name T_RPAREN {
+               $$ = build_sizeof($3);
+         }
+       /* K&R ---, C90 ---, C99 ---, C11 6.5.3, C18 6.5.3 */
+       | T_ALIGNOF T_LPAREN type_name T_RPAREN {
+               $$ = build_alignof($3);
+         }
+       ;
+
+/* The rule 'unary_operator' is inlined into unary_expression. */
+
+/* K&R 7.2, C90 ???, C99 6.5.4, C11 6.5.4, C18 6.5.4 */
+cast_expression:
+         unary_expression
+       | T_LPAREN type_name T_RPAREN cast_expression {
+               $$ = cast($4, $2);



Home | Main Index | Thread Index | Old Index