cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
From: Julia Lawall <julia.lawall@inria.fr>
To: Markus Elfring <Markus.Elfring@web.de>
Cc: cocci@systeme.lip6.fr
Subject: Re: [Cocci] transforming arguments to statement macros?
Date: Sun, 5 Jan 2020 11:05:49 +0100 (CET)	[thread overview]
Message-ID: <alpine.DEB.2.21.2001051100550.2579@hadrien> (raw)
In-Reply-To: <08d3a32e-7adc-ff5b-52d0-9e67ed03ae42@web.de>

On Sun, 5 Jan 2020, Markus Elfring wrote:

> > I would prefer that the macros were written with the do-while pattern,
> > but it's a legacy codebase that uses HGOTO_ERROR() no fewer than 12,000
> > times, and most occurrences have no semicolon.  I will have to automate
> > the conversion, and I guess that I cannot use spatch to do it.
>
> Would you like to try out how good semicolons can be added behind
> these macro calls by a small script for the semantic patch language?

The problem is that the arguemnt list is considered to be comments.  THere
is no way to specify to put a semicolon at the end of a comment.

The only short term suggestion I have is the following:

@r@
statement s : script:ocaml() { List.hd (Str.split (Str.regexp " *(") s) =
"ASSERT" };
statement s1,s2;
position p1;
@@

s
s1@p1

@@
statement r.s1;
position r.p1;
@@

+;
s1@p1

-------------------

This uses ASSERT as an example, because standard.h already contains

#define ASSERT(x) MACROSTATEMENT

It uses a regular expression to detect that a statement starts with the
word ASSERT, and matches the next statement as well, and then in another
rule adds a ; before the subsequent statement.  If you add the ; after the
ASSERT statement it comes out after ASSERT, not after the commented
argument list. But with this semantic patch, the ; comes out on a line of
its own, and would have to be moved up manually.  So I don't know if that
gives any real benefit.  It obviously also doesn't work if the ASSERT is
at the end of a function.

julia
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

  reply	other threads:[~2020-01-05 10:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-02 22:03 [Cocci] transforming arguments to statement macros? David Young
2020-01-03  6:32 ` Julia Lawall
2020-01-03 16:03   ` David Young
2020-01-05  9:47     ` Markus Elfring
2020-01-05 10:05       ` Julia Lawall [this message]
2020-01-05 11:32         ` Markus Elfring
2020-01-05 13:54         ` Markus Elfring
2020-01-06 12:07         ` [Cocci] Adding semicolons after macro calls Markus Elfring
2020-01-06 12:20           ` Julia Lawall
2020-01-06 12:48             ` [Cocci] Improving support for data processing around " Markus Elfring
2020-01-08 22:05     ` [Cocci] transforming arguments to statement macros? Julia Lawall

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=alpine.DEB.2.21.2001051100550.2579@hadrien \
    --to=julia.lawall@inria.fr \
    --cc=Markus.Elfring@web.de \
    --cc=cocci@systeme.lip6.fr \
    /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 NNTP newsgroup(s).