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: add grammar rule for the beginning...



details:   https://anonhg.NetBSD.org/src/rev/62b5bd49f22e
branches:  trunk
changeset: 1029067:62b5bd49f22e
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Dec 20 19:34:01 2021 +0000

description:
lint: add grammar rule for the beginning of a designation

This will be necessary to properly implement handling of initializers
and braced initializer-lists.

No functional change for now since the designation is already reset
after each expression and '}'.  To handle initializations properly, the
designation must not be reset after each expression, it must advance to
the next member instead.

diffstat:

 usr.bin/xlint/lint1/cgram.y    |  13 ++++++++++---
 usr.bin/xlint/lint1/externs1.h |   3 ++-
 usr.bin/xlint/lint1/init.c     |  14 ++++++++++++--
 3 files changed, 24 insertions(+), 6 deletions(-)

diffs (94 lines):

diff -r 6ea33fcc5ed2 -r 62b5bd49f22e usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Mon Dec 20 17:12:41 2021 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Mon Dec 20 19:34:01 2021 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.376 2021/12/18 11:37:00 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.377 2021/12/20 19:34:01 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.376 2021/12/18 11:37:00 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.377 2021/12/20 19:34:01 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -1561,14 +1561,21 @@
        ;
 
 designation:                   /* C99 6.7.8 "Initialization" */
-         designator_list T_ASSIGN
+         begin_designation designator_list T_ASSIGN
        | identifier T_COLON {
                /* GCC style struct or union member name in initializer */
                gnuism(315);
+               begin_designation();
                add_designator_member($1);
          }
        ;
 
+begin_designation:             /* lint-specific helper */
+         /* empty */ {
+               begin_designation();
+         }
+       ;
+
 designator_list:               /* C99 6.7.8 "Initialization" */
          designator
        | designator_list designator
diff -r 6ea33fcc5ed2 -r 62b5bd49f22e usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Mon Dec 20 17:12:41 2021 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Mon Dec 20 19:34:01 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs1.h,v 1.142 2021/12/16 23:46:21 rillig Exp $    */
+/*     $NetBSD: externs1.h,v 1.143 2021/12/20 19:34:01 rillig Exp $    */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -332,6 +332,7 @@
 extern void    init_rbrace(void);
 extern void    init_lbrace(void);
 extern void    init_expr(tnode_t *);
+extern void    begin_designation(void);
 extern void    add_designator_member(sbuf_t *);
 extern void    add_designator_subscript(range_t);
 
diff -r 6ea33fcc5ed2 -r 62b5bd49f22e usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c        Mon Dec 20 17:12:41 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c        Mon Dec 20 19:34:01 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init.c,v 1.222 2021/12/19 23:50:27 rillig Exp $        */
+/*     $NetBSD: init.c,v 1.223 2021/12/20 19:34:01 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.222 2021/12/19 23:50:27 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.223 2021/12/20 19:34:01 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -988,6 +988,16 @@
 }
 
 void
+begin_designation(void)
+{
+       brace_level *bl;
+
+       bl = current_init()->in_brace_level;
+       lint_assert(bl != NULL);
+       designation_reset(&bl->bl_designation);
+}
+
+void
 add_designator_member(sbuf_t *sb)
 {
 



Home | Main Index | Thread Index | Old Index