Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: Tom Tromey <tom@tromey.com>,
	Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH 2/2] gdb: remove TYPE_NAME macro
Date: Sat, 16 May 2020 12:35:50 -0400	[thread overview]
Message-ID: <62d1efcd-01bf-a23b-7608-4ba1f1bd8ebe@efficios.com> (raw)
In-Reply-To: <877dxb7tuw.fsf@tromey.com>

On 2020-05-16 12:00 p.m., Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Simon> Remove `TYPE_NAME`, changing all the call sites to use `type::name`
> Simon> directly.  This is quite a big diff, but this was mostly done using sed
> Simon> and coccinelle.  A few call sites were done by hand.
> 
> Looks good.  I didn't realize coccinelle worked on C++.

Thanks, I'll push them in a moment.

No, coccinelle doesn't work on C++ unfortunately.  When there's a C++
construct in a function, it just skips it it seems.  But our codebase
still looks largely like C in a lot of places that it can still do
a significant number of changes.  But what this means is that it will
become less and less effective for us as time goes by :(.

Also, coccinelle doesn't really allow to specify the output code style,
so it just never puts a space before the parenthesis.  I worked around
that by making it use `a_very_unique_string` as the function name in its
output, so I could easily replace it with the desired value with sed:

-  thetype->a_very_unique_string(...)
+  thetype->set_name (...)

The above can also leave out a space in other function calls in the modified
code, for example turning

  TYPE_NAME (thetype) = a_function ();

into

  thetype->set_name (a_function());

So the space after `a_function` needs to be added back by hand, or some sed
to turn `a_function(` into `a_function (`.

While at it, here's the complete method I used, maybe it will help you or somebody
else when making similar changes:

- Add getter / setters, change the TYPE_NAME macro to use the getter.  The compiler
  will point out any spots that are using the macro to set the field.

- A first sed pass to change the obvious spots to use the setter (not essential, but it's
  quick):

  sed -ri 's|TYPE_NAME \(([a-z0-9_]+)\) = ([a-z0-9_"]+)|\1->set_name (\2)|g' *.c */*.c

- Run this coccinelle rule to change some less obvious spots to use the setter

  ---
  @@
  expression type;
  expression value;
  @@
  - TYPE_NAME(type) = value
  + type->a_very_unique_string(value)
  ---

  $ spatch --sp-file type-set-name.cocci --in-place <FILES>

  Followed by this sed to replace `a_very_unique_string`:

  $ sed -i "s|a_very_unique_string|set_name |g" <FILES>

- Fix the remaining spots to use the setter by hand.

That should be enough for the first patch.  For the second patch:

- Remove the TYPE_NAME macro.

- A first sed pass:

  sed -ri 's|TYPE_NAME \(([a-z0-9_]+)\)|\1->name ()|g'

- Run this coccinelle rule followed by sed, as mentioned above:

  @@
  expression type;
  @@
  - TYPE_NAME(type)
  + type->a_very_unique_string()

Simon


  reply	other threads:[~2020-05-16 16:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-14 18:18 [PATCH 1/2] gdb: add type::name / type::set_name Simon Marchi
2020-05-14 18:18 ` [PATCH 2/2] gdb: remove TYPE_NAME macro Simon Marchi
2020-05-16 16:00   ` Tom Tromey
2020-05-16 16:35     ` Simon Marchi [this message]
2020-05-16 18:18       ` Tom Tromey
2020-05-16 19:10         ` Simon Marchi
2020-05-16 19:26           ` Tom Tromey
2020-05-16 19:33             ` Simon Marchi
2020-05-16 15:58 ` [PATCH 1/2] gdb: add type::name / type::set_name Tom Tromey

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=62d1efcd-01bf-a23b-7608-4ba1f1bd8ebe@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tom@tromey.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox