All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ulf Magnusson <ulfalizer@gmail.com>
To: Eugeniu Rosca <roscaeugeniu@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>,
	Petr Vorel <petr.vorel@gmail.com>,
	Nicolas Pitre <nicolas.pitre@linaro.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	Paul Bolle <pebolle@tiscali.nl>,
	Eugeniu Rosca <erosca@de.adit-jv.com>,
	Linux Kbuild mailing list <linux-kbuild@vger.kernel.org>
Subject: Re: [PATCH v3 3/3] kconfig: Print reverse dependencies in groups
Date: Sun, 18 Feb 2018 14:02:46 +0100	[thread overview]
Message-ID: <20180218130246.eqfa46eswut5xwmv@huvuddator> (raw)
In-Reply-To: <20180218110702.GA26185@example.com>

On Sun, Feb 18, 2018 at 12:07:02PM +0100, Eugeniu Rosca wrote:
> If expr_print_newline is renamed to expr_print_{select,revdep}, then
> I still face the need of expr_print_newline. So, I kept the *newline()
> function in place and came up with below solution to aggregate
> duplicated code. Please, let me know if it looks OK to you (btw, it
> creates a slightly higher --stat compared to current solution).
> 
> diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c
> index 48b99371d276..a6316e5681d9 100644
> --- a/scripts/kconfig/expr.c
> +++ b/scripts/kconfig/expr.c
> @@ -1189,6 +1189,34 @@ expr_print_newline(struct expr *e,
>  	expr_print(e, fn, data, prevtoken);
>  }
>  
> +static void
> +expr_print_revdep(struct expr *e,
> +		  void (*fn)(void *, struct symbol *, const char *),
> +		  void *data,
> +		  int prevtoken,
> +		  enum print_type type)
> +{
> +	switch (type) {
> +	case PRINT_REVDEP_ALL:
> +		expr_print_newline(e, fn, data, prevtoken);
> +		break;
> +	case PRINT_REVDEP_YES:
> +		if (expr_calc_value(e) == yes)
> +			expr_print_newline(e, fn, data, prevtoken);
> +		break;
> +	case PRINT_REVDEP_MOD:
> +		if (expr_calc_value(e) == mod)
> +			expr_print_newline(e, fn, data, prevtoken);
> +		break;
> +	case PRINT_REVDEP_NO:
> +		if (expr_calc_value(e) == no)
> +			expr_print_newline(e, fn, data, prevtoken);
> +		break;
> +	default:
> +		break;
> +	}
> +}
> +

I think it's fine to have a separate expr_print_newline() function
still. Getting rid of the repetition still makes it more readable to me.

Maybe you could do something like this if you want to eliminate
expr_print_newline() though. AFAICS, it isn't used outside
expr_print_revdep().

	static void
	expr_print_revdep(struct expr *e,
			  void (*fn)(void *, struct symbol *, const char *),
			  void *data,
			  int prevtoken,
			  enum print_type type)
	{
		if (type == PRINT_REVDEP_ALL                              ||
		    type == PRINT_REVDEP_YES && expr_calc_value(e) == yes ||
		    type == PRINT_REVDEP_MOD && expr_calc_value(e) == mod ||
		    type == PRINT_REVDEP_NO  && expr_calc_value(e) == no) {

			fn(data, NULL, "\n - ");
			expr_print(e, fn, data, prevtoken);
		}
	}


Could turn that into a switch over 'type' and set a 'print_revdep' flag
which is checked at the end too, if you'd prefer that:

	switch (type) {
	...
	case PRINT_REVDEP_YES:
		print_revdep = (expr_calc_value(e) == yes);
		break;
	...
	}

	if (print_revdep) {
		fn(data, NULL, "\n - ");
		expr_print(e, fn, data, prevtoken);
	}


Or return early:

	case PRINT_REVDEP_YES:
		if (expr_calc_value(e) != yes)
			return;
		break;
	...
	}

	fn(data, NULL, "\n - ");
	expr_print(e, fn, data, prevtoken);


The original version is already fine by me though. The 'if' version
seems pretty direct too.

Cheers,
Ulf

  reply	other threads:[~2018-02-18 13:03 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-17  2:05 [PATCH v3 0/3] Print reverse dependencies in groups Eugeniu Rosca
2018-02-17  2:05 ` [PATCH v3 1/3] kconfig: Print reverse dependencies on new line consistently Eugeniu Rosca
2018-02-17 16:39   ` Ulf Magnusson
2018-02-17  2:05 ` [PATCH v3 2/3] kconfig: Prepare for printing reverse dependencies in groups Eugeniu Rosca
2018-02-17 16:44   ` Ulf Magnusson
2018-02-17  2:05 ` [PATCH v3 3/3] kconfig: Print " Eugeniu Rosca
2018-02-17 16:55   ` Ulf Magnusson
2018-02-18 11:07     ` Eugeniu Rosca
2018-02-18 13:02       ` Ulf Magnusson [this message]
2018-02-18 13:19         ` Ulf Magnusson
2018-02-18 13:35           ` Ulf Magnusson
2018-02-18 13:40             ` Ulf Magnusson
2018-02-18 21:05               ` Eugeniu Rosca

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180218130246.eqfa46eswut5xwmv@huvuddator \
    --to=ulfalizer@gmail.com \
    --cc=erosca@de.adit-jv.com \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=nicolas.pitre@linaro.org \
    --cc=pebolle@tiscali.nl \
    --cc=petr.vorel@gmail.com \
    --cc=rdunlap@infradead.org \
    --cc=roscaeugeniu@gmail.com \
    --cc=yamada.masahiro@socionext.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.