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: extract check_non_constant_initial...



details:   https://anonhg.NetBSD.org/src/rev/4eb547b52fa3
branches:  trunk
changeset: 952937:4eb547b52fa3
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Feb 21 15:02:16 2021 +0000

description:
lint: extract check_non_constant_initializer from init_using_expr

No functional change.

diffstat:

 usr.bin/xlint/lint1/externs1.h |   4 ++--
 usr.bin/xlint/lint1/init.c     |  38 +++++++++++++++++++++++---------------
 usr.bin/xlint/lint1/tree.c     |   6 +++---
 3 files changed, 28 insertions(+), 20 deletions(-)

diffs (111 lines):

diff -r 75d18125dc11 -r 4eb547b52fa3 usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Sun Feb 21 15:00:04 2021 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Sun Feb 21 15:02:16 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs1.h,v 1.70 2021/02/21 07:59:17 rillig Exp $     */
+/*     $NetBSD: externs1.h,v 1.71 2021/02/21 15:02:16 rillig Exp $     */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -219,7 +219,7 @@
 extern void    expr(tnode_t *, bool, bool, bool, bool);
 extern void    check_expr_misc(const tnode_t *, bool, bool, bool,
                    bool, bool, bool);
-extern bool    constant_addr(tnode_t *, sym_t **, ptrdiff_t *);
+extern bool    constant_addr(const tnode_t *, sym_t **, ptrdiff_t *);
 extern strg_t  *cat_strings(strg_t *, strg_t *);
 extern  int64_t tsize(type_t *);
 #ifdef DEBUG
diff -r 75d18125dc11 -r 4eb547b52fa3 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c        Sun Feb 21 15:00:04 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c        Sun Feb 21 15:02:16 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init.c,v 1.86 2021/02/21 14:57:25 rillig Exp $ */
+/*     $NetBSD: init.c,v 1.87 2021/02/21 15:02:16 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.86 2021/02/21 14:57:25 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.87 2021/02/21 15:02:16 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -742,6 +742,26 @@
        }
 }
 
+static void
+check_non_constant_initializer(const tnode_t *tn, scl_t sclass)
+{
+       if (tn == NULL || tn->tn_op == CON)
+               return;
+
+       sym_t *sym;
+       ptrdiff_t offs;
+       if (constant_addr(tn, &sym, &offs))
+               return;
+
+       if (sclass == AUTO || sclass == REG) {
+               /* non-constant initializer */
+               c99ism(177);
+       } else {
+               /* non-constant initializer */
+               error(177);
+       }
+}
+
 void
 init_using_expr(tnode_t *tn)
 {
@@ -840,19 +860,7 @@
        if (lt != rt || (initstk->i_type->t_bitfield && tn->tn_op == CON))
                tn = convert(INIT, 0, initstk->i_type, tn);
 
-       if (tn != NULL && tn->tn_op != CON) {
-               sym_t *sym;
-               ptrdiff_t offs;
-               if (!constant_addr(tn, &sym, &offs)) {
-                       if (sclass == AUTO || sclass == REG) {
-                               /* non-constant initializer */
-                               c99ism(177);
-                       } else {
-                               /* non-constant initializer */
-                               error(177);
-                       }
-               }
-       }
+       check_non_constant_initializer(tn, sclass);
 
        debug_initstack();
        debug_leave();
diff -r 75d18125dc11 -r 4eb547b52fa3 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Sun Feb 21 15:00:04 2021 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Sun Feb 21 15:02:16 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.215 2021/02/21 11:23:33 rillig Exp $        */
+/*     $NetBSD: tree.c,v 1.216 2021/02/21 15:02:16 rillig Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.215 2021/02/21 11:23:33 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.216 2021/02/21 15:02:16 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -4185,7 +4185,7 @@
  * representation (including width).
  */
 bool
-constant_addr(tnode_t *tn, sym_t **symp, ptrdiff_t *offsp)
+constant_addr(const tnode_t *tn, sym_t **symp, ptrdiff_t *offsp)
 {
        sym_t   *sym;
        ptrdiff_t offs1, offs2;



Home | Main Index | Thread Index | Old Index