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_init_expr from init_...



details:   https://anonhg.NetBSD.org/src/rev/7fa316722a64
branches:  trunk
changeset: 953922:7fa316722a64
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Mar 25 00:35:16 2021 +0000

description:
lint: extract check_init_expr from init_using_expr

No functional change.

diffstat:

 usr.bin/xlint/lint1/init.c |  91 ++++++++++++++++++++++++---------------------
 1 files changed, 49 insertions(+), 42 deletions(-)

diffs (122 lines):

diff -r 75a3778a2a5a -r 7fa316722a64 usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c        Wed Mar 24 18:19:31 2021 +0000
+++ b/usr.bin/xlint/lint1/init.c        Thu Mar 25 00:35:16 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: init.c,v 1.115 2021/03/23 22:58:08 rillig Exp $        */
+/*     $NetBSD: init.c,v 1.116 2021/03/25 00:35: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.115 2021/03/23 22:58:08 rillig Exp $");
+__RCSID("$NetBSD: init.c,v 1.116 2021/03/25 00:35:16 rillig Exp $");
 #endif
 
 #include <stdlib.h>
@@ -990,12 +990,55 @@
        return true;
 }
 
+static void
+check_init_expr(tnode_t *tn, scl_t sclass)
+{
+       tnode_t *ln;
+       tspec_t lt, rt;
+       struct mbl *tmem;
+
+       /* Create a temporary node for the left side. */
+       ln = tgetblk(sizeof (tnode_t));
+       ln->tn_op = NAME;
+       ln->tn_type = tduptyp(initstk->i_type);
+       ln->tn_type->t_const = false;
+       ln->tn_lvalue = true;
+       ln->tn_sym = initsym;           /* better than nothing */
+
+       tn = cconv(tn);
+
+       lt = ln->tn_type->t_tspec;
+       rt = tn->tn_type->t_tspec;
+
+       lint_assert(is_scalar(lt));     /* at least before C99 */
+
+       debug_step("typeok '%s', '%s'",
+           type_name(ln->tn_type), type_name(tn->tn_type));
+       if (!typeok(INIT, 0, ln, tn))
+               return;
+
+       /*
+        * Store the tree memory. This is necessary because otherwise
+        * expr() would free it.
+        */
+       tmem = tsave();
+       expr(tn, true, false, true, false);
+       trestor(tmem);
+
+       check_bit_field_init(ln, lt, rt);
+
+       /*
+        * XXX: Is it correct to do this conversion _after_ the typeok above?
+        */
+       if (lt != rt || (initstk->i_type->t_bitfield && tn->tn_op == CON))
+               tn = convert(INIT, 0, initstk->i_type, tn);
+
+       check_non_constant_initializer(tn, sclass);
+}
+
 void
 init_using_expr(tnode_t *tn)
 {
-       tspec_t lt, rt;
-       tnode_t *ln;
-       struct  mbl *tmem;
        scl_t   sclass;
 
        debug_enter();
@@ -1034,43 +1077,7 @@
        initstk->i_remaining--;
        debug_step("%d elements remaining", initstk->i_remaining);
 
-       /* Create a temporary node for the left side. */
-       ln = tgetblk(sizeof (tnode_t));
-       ln->tn_op = NAME;
-       ln->tn_type = tduptyp(initstk->i_type);
-       ln->tn_type->t_const = false;
-       ln->tn_lvalue = true;
-       ln->tn_sym = initsym;           /* better than nothing */
-
-       tn = cconv(tn);
-
-       lt = ln->tn_type->t_tspec;
-       rt = tn->tn_type->t_tspec;
-
-       lint_assert(is_scalar(lt));     /* at least before C99 */
-
-       debug_step("typeok '%s', '%s'",
-           type_name(ln->tn_type), type_name(tn->tn_type));
-       if (!typeok(INIT, 0, ln, tn))
-               goto done_initstack;
-
-       /*
-        * Store the tree memory. This is necessary because otherwise
-        * expr() would free it.
-        */
-       tmem = tsave();
-       expr(tn, true, false, true, false);
-       trestor(tmem);
-
-       check_bit_field_init(ln, lt, rt);
-
-       /*
-        * XXX: Is it correct to do this conversion _after_ the typeok above?
-        */
-       if (lt != rt || (initstk->i_type->t_bitfield && tn->tn_op == CON))
-               tn = convert(INIT, 0, initstk->i_type, tn);
-
-       check_non_constant_initializer(tn, sclass);
+       check_init_expr(tn, sclass);
 
 done_initstack:
        debug_initstack();



Home | Main Index | Thread Index | Old Index