From ebecd520aff4de4040e0adc1b86345187992fb67 Mon Sep 17 00:00:00 2001 From: rillig Date: Sat, 27 Mar 2021 13:08:20 +0000 Subject: [PATCH] lint: merge duplicate code in initialization No functional change. --- usr.bin/xlint/lint1/init.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/usr.bin/xlint/lint1/init.c b/usr.bin/xlint/lint1/init.c index bd67579a5b52..379ca272ea18 100644 --- a/usr.bin/xlint/lint1/init.c +++ b/usr.bin/xlint/lint1/init.c @@ -1,4 +1,4 @@ -/* $NetBSD: init.c,v 1.134 2021/03/26 20:31:07 rillig Exp $ */ +/* $NetBSD: init.c,v 1.135 2021/03/27 13:08:20 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,7 +37,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: init.c,v 1.134 2021/03/26 20:31:07 rillig Exp $"); +__RCSID("$NetBSD: init.c,v 1.135 2021/03/27 13:08:20 rillig Exp $"); #endif #include @@ -215,8 +215,9 @@ typedef struct initstack_element { } initstack_element; /* - * Leads the path to the sub-object to initialize using the expression. - * Example designators are '.member' or '.member[123].member.member[1][1]'. + * A single component on the path to the sub-object that is initialized by an + * initializer expression. Either a struct or union member, or an array + * subscript. * * See also: C99 6.7.8 "Initialization" */ @@ -227,6 +228,10 @@ typedef struct designator { } designator; /* + * The optional designation for an initializer, saying which sub-object to + * initialize. Examples for designations are '.member' or + * '.member[123].member.member[1][1]'. + * * See also: C99 6.7.8 "Initialization" */ typedef struct { @@ -265,27 +270,29 @@ static struct initialization *init; static bool init_array_using_string(tnode_t *); -/* TODO: replace the following functions with current_init */ +static struct initialization * +current_init(void) +{ + lint_assert(init != NULL); + return init; +} bool * current_initerr(void) { - lint_assert(init != NULL); - return &init->initerr; + return ¤t_init()->initerr; } sym_t ** current_initsym(void) { - lint_assert(init != NULL); - return &init->initsym; + return ¤t_init()->initsym; } static designation * current_designation_mod(void) { - lint_assert(init != NULL); - return &init->designation; + return ¤t_init()->designation; } static designation @@ -297,15 +304,13 @@ current_designation(void) static const initstack_element * current_initstk(void) { - lint_assert(init != NULL); - return init->initstk; + return current_init()->initstk; } static initstack_element ** current_initstk_lvalue(void) { - lint_assert(init != NULL); - return &init->initstk; + return ¤t_init()->initstk; } static void