public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Thiago Jung Bauermann <thiago.bauermann@linaro.org>,
	gdb-patches@sourceware.org
Subject: Re: [PATCH 2/2] gdbarch.py: Fix indentation in the generated set_gdbarch_* definitions
Date: Fri, 2 Dec 2022 09:46:14 -0500	[thread overview]
Message-ID: <18711e08-f91c-3e56-fbf0-333bbca5e50f@simark.ca> (raw)
In-Reply-To: <20221201223914.366184-3-thiago.bauermann@linaro.org>

> diff --git a/gdb/gdbarch.py b/gdb/gdbarch.py
> index 7ac7140e1452..ce430318eb49 100755
> --- a/gdb/gdbarch.py
> +++ b/gdb/gdbarch.py
> @@ -479,10 +479,10 @@ with open("gdbarch.c", "w") as f:
>              print(file=f)
>              print("void", file=f)
>              print(f"set_gdbarch_{c.name} (struct gdbarch *gdbarch,", file=f)
> -            print(
> -                f"            {' ' * len(c.name)}  gdbarch_{c.name}_ftype {c.name})",
> -                file=f,
> -            )
> +            total_indentation = len("set_gdbarch_") + len(c.name) + 2
> +            tabs = '\t' * (total_indentation // 8)
> +            spaces = ' ' * (total_indentation % 8)
> +            print(f"{tabs}{spaces}gdbarch_{c.name}_ftype {c.name})", file=f)

For clarity and to factor out the implementation, I think it would be
worth putting the computation of the indentation characters in its own
function (untested):

  def indentation(n_columns):
    return '\' * (n_columns // 8) + ' ' * (n_columns % 8)

It can then be used directly in the format string:

  setter_name = f"set_gdbarch_{c.name}"
  ftype_name = f"gdbarch_{c.name}_ftype"
  print(f"{setter_name} (struct gdbarch *gdbarch,", file=f)
  indent_columns = len(f"{setter_name} (")
  print("f{indentation(indent_columns)}{ftype_name})", file=f)

Simon

  reply	other threads:[~2022-12-02 14:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-01 22:39 [PATCH 0/2] Fix tab vs spaces in generated gdbarch.c Thiago Jung Bauermann
2022-12-01 22:39 ` [PATCH 1/2] gdbarch.py: Fix indentation in the generated gdbarch_dump function Thiago Jung Bauermann
2022-12-02 14:34   ` Simon Marchi
2022-12-02 19:07     ` Thiago Jung Bauermann
2022-12-01 22:39 ` [PATCH 2/2] gdbarch.py: Fix indentation in the generated set_gdbarch_* definitions Thiago Jung Bauermann
2022-12-02 14:46   ` Simon Marchi [this message]
2022-12-02 19:10     ` Thiago Jung Bauermann
2022-12-02 14:44 ` [PATCH 0/2] Fix tab vs spaces in generated gdbarch.c Simon Marchi

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=18711e08-f91c-3e56-fbf0-333bbca5e50f@simark.ca \
    --to=simark@simark.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=thiago.bauermann@linaro.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).