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


Simon Marchi <simark@simark.ca> writes:

>> 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)

Good idea, I adopted your version. I just added a doc string to the
indentation function. Since a big part of the patch is now your code, I
added a “Co-developed-by: Simon Marchi <simon.marchi@efficios.com>” to
it, hope you don't mind.


-- 
Thiago

  reply	other threads:[~2022-12-02 19:10 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
2022-12-02 19:10     ` Thiago Jung Bauermann [this message]
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=87ilitfwp9.fsf@linaro.org \
    --to=thiago.bauermann@linaro.org \
    --cc=gdb-patches@sourceware.org \
    --cc=simark@simark.ca \
    /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).