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 indirection for accessing the ...



details:   https://anonhg.NetBSD.org/src/rev/085c0e7da95d
branches:  trunk
changeset: 953893:085c0e7da95d
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Mar 23 17:36:55 2021 +0000

description:
lint: add indirection for accessing the current initialization

This indirection will be needed to handle nested initializations, which
are a new feature of C99.  These are currently not handled correctly,
see msg_171.c.

No functional change.

diffstat:

 usr.bin/xlint/lint1/cgram.y    |  14 ++++----
 usr.bin/xlint/lint1/decl.c     |  16 +++++-----
 usr.bin/xlint/lint1/externs1.h |   6 ++--
 usr.bin/xlint/lint1/init.c     |  62 ++++++++++++++++++++++++++++++++---------
 4 files changed, 66 insertions(+), 32 deletions(-)

diffs (233 lines):

diff -r cdc422b276f9 -r 085c0e7da95d usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Tue Mar 23 13:22:40 2021 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Tue Mar 23 17:36:55 2021 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.196 2021/03/21 14:49:21 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.197 2021/03/23 17:36:55 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.196 2021/03/21 14:49:21 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.197 2021/03/23 17:36:55 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -1885,24 +1885,24 @@
            expr_statement_list {
                block_level--;
                mem_block_level--;
-               initsym = mktempsym(duptyp($4->tn_type));
+               *current_initsym() = mktempsym(duptyp($4->tn_type));
                mem_block_level++;
                block_level++;
                /* ({ }) is a GCC extension */
                gnuism(320);
         } compound_statement_rbrace T_RPAREN {
-               $$ = new_name_node(initsym, 0);
+               $$ = new_name_node(*current_initsym(), 0);
         }
        | T_LPAREN compound_statement_lbrace expr_statement_list {
                block_level--;
                mem_block_level--;
-               initsym = mktempsym($3->tn_type);
+               *current_initsym() = mktempsym($3->tn_type);
                mem_block_level++;
                block_level++;
                /* ({ }) is a GCC extension */
                gnuism(320);
         } compound_statement_rbrace T_RPAREN {
-               $$ = new_name_node(initsym, 0);
+               $$ = new_name_node(*current_initsym(), 0);
         }
        | term T_INCDEC {
                $$ = build($2 == INC ? INCAFT : DECAFT, $1, NULL);
@@ -1995,7 +1995,7 @@
                if (!Sflag)
                         /* compound literals are a C9X/GCC extension */
                         gnuism(319);
-               $$ = new_name_node(initsym, 0);
+               $$ = new_name_node(*current_initsym(), 0);
          }
        ;
 
diff -r cdc422b276f9 -r 085c0e7da95d usr.bin/xlint/lint1/decl.c
--- a/usr.bin/xlint/lint1/decl.c        Tue Mar 23 13:22:40 2021 +0000
+++ b/usr.bin/xlint/lint1/decl.c        Tue Mar 23 17:36:55 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: decl.c,v 1.157 2021/03/21 20:18:45 rillig Exp $ */
+/* $NetBSD: decl.c,v 1.158 2021/03/23 17:36:56 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.157 2021/03/21 20:18:45 rillig Exp $");
+__RCSID("$NetBSD: decl.c,v 1.158 2021/03/23 17:36:56 rillig Exp $");
 #endif
 
 #include <sys/param.h>
@@ -1896,8 +1896,8 @@
 {
        char *s;
 
-       initerr = false;
-       initsym = decl;
+       *current_initerr() = false;
+       *current_initsym() = decl;
 
        switch (dcs->d_ctx) {
        case EXTERN:
@@ -1929,7 +1929,7 @@
                break;
        }
 
-       if (initflg && !initerr)
+       if (initflg && !*current_initerr())
                initstack_init();
 }
 
@@ -1946,7 +1946,7 @@
 
        check_type(dsym);
 
-       if (initflg && !(initerr = check_init(dsym)))
+       if (initflg && !(*current_initerr() = check_init(dsym)))
                dsym->s_def = DEF;
 
        /*
@@ -2424,7 +2424,7 @@
        if (initflg) {
                /* cannot initialize parameter: %s */
                error(52, sym->s_name);
-               initerr = true;
+               *current_initerr() = true;
        }
 
        if ((t = sym->s_type->t_tspec) == ARRAY) {
@@ -2759,7 +2759,7 @@
 
        }
 
-       if (initflg && !(initerr = check_init(dsym))) {
+       if (initflg && !(*current_initerr() = check_init(dsym))) {
                dsym->s_def = DEF;
                mark_as_set(dsym);
        }
diff -r cdc422b276f9 -r 085c0e7da95d usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Tue Mar 23 13:22:40 2021 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Tue Mar 23 17:36:55 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs1.h,v 1.82 2021/03/21 19:08:10 rillig Exp $     */
+/*     $NetBSD: externs1.h,v 1.83 2021/03/23 17:36:56 rillig Exp $     */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -292,8 +292,8 @@
 /*
  * init.c
  */
-extern bool    initerr;
-extern sym_t   *initsym;
+extern bool    *current_initerr(void);
+extern sym_t   **current_initsym(void);
 
 extern void    initstack_init(void);
 extern void    init_rbrace(void);
diff -r cdc422b276f9 -r 085c0e7da95d usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c        Tue Mar 23 13:22:40 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c        Tue Mar 23 17:36:55 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init.c,v 1.109 2021/03/22 19:29:43 rillig Exp $        */
+/*     $NetBSD: init.c,v 1.110 2021/03/23 17:36:56 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.109 2021/03/22 19:29:43 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.110 2021/03/23 17:36:56 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -199,26 +199,60 @@
        struct namlist *n_next;
 } namlist_t;
 
+struct initialization {
+       /*
+        * initerr is set as soon as a fatal error occurred in an initialization.
+        * The effect is that the rest of the initialization is ignored (parsed
+        * by yacc, expression trees built, but no initialization takes place).
+        */
+       bool    initerr;
 
-/*
- * initerr is set as soon as a fatal error occurred in an initialization.
- * The effect is that the rest of the initialization is ignored (parsed
- * by yacc, expression trees built, but no initialization takes place).
- */
-bool   initerr;
+       /* Pointer to the symbol which is to be initialized. */
+       sym_t   *initsym;
 
-/* Pointer to the symbol which is to be initialized. */
-sym_t  *initsym;
+       /* Points to the top element of the initialization stack. */
+       initstack_element *initstk;
 
-/* Points to the top element of the initialization stack. */
-static initstack_element *initstk;
+       /* Points to a c9x named member. */
+       namlist_t *namedmem;
 
-/* Points to a c9x named member; */
-static namlist_t *namedmem = NULL;
+       struct initialization *next;
+};
+
+static struct initialization init;
 
 
 static bool    init_array_using_string(tnode_t *);
 
+bool *
+current_initerr(void)
+{
+       return &init.initerr;
+}
+
+sym_t **
+current_initsym(void)
+{
+       return &init.initsym;
+}
+
+static namlist_t **
+current_namedmem(void)
+{
+       return &init.namedmem;
+}
+
+static initstack_element **
+current_initstk(void)
+{
+       return &init.initstk;
+}
+
+#define initerr (*current_initerr())
+#define initsym (*current_initsym())
+#define initstk (*current_initstk())
+#define namedmem (*current_namedmem())
+
 #ifndef DEBUG
 
 #define debug_printf(fmt, ...) do { } while (false)



Home | Main Index | Thread Index | Old Index