cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
From: Julia Lawall <julia.lawall@inria.fr>
To: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
Cc: cocci@systeme.lip6.fr
Subject: Re: [Cocci] Inserting code after specific set of declarations?
Date: Wed, 19 Feb 2020 23:37:03 +0100 (CET)	[thread overview]
Message-ID: <alpine.DEB.2.21.2002192335560.2565@hadrien> (raw)
In-Reply-To: <20200219172849.GU13686@intel.com>

[-- Attachment #1: Type: text/plain, Size: 1754 bytes --]



--- Please note the new email address ---


On Wed, 19 Feb 2020, Ville Syrjälä wrote:

> Hi all,
>
> I was trying to do the following transformation:
> @@
> identifier M;
> expression E;
> @@
> - struct foo M = E;
> + struct foo M;
> + copy_struct(&M, &E);
>
> but without inserting the function call in the middle of the
> declarations and instead pushing it past them.
>
> This is one attempt:
> @decl@
> identifier M;
> expression E;
> @@
> - struct foo M = E;
> + struct foo M;
>
> @copy@
> identifier decl.M;
> expression decl.E;
> declaration D;
> statement S;
> @@
> struct foo M;
> ...
> D
> + copy_struct(&M, &E);
> S
>
> The copy rule fails to match anything when I have != 1
> declarations after the struct. So the ... doesn't seem
> to eat the extra declarations for some reason.

@copy@
identifier decl.M;
expression decl.E;
declaration D;
statement S;
@@
struct foo M;
... when any
D
+ copy_struct(&M, &E);
S

Otherwise, ... doesn't match code that includes what is before or after
it, ie struct foo M or D.

Aternatively:

@copy@
identifier decl.M;
expression decl.E;
declaration D;
statement S,S1;
@@
struct foo M;
... when != S1
+ copy_struct(&M, &E);
S

julia


>
> Also tried some other tricks with <... ...> but that just resulted
> in the code being inserted into every if block in the function.
> Not what I wanted.
>
> I guess what I might need is something along the lines of:
> @copy@
> ...
> declaration list[N] D;
> @@
> struct foo M;
> D
> + copy_struct(&M, &E);
> S
>
> but that's not supported it seems.
>
> Is there any way to achieve this atm?
>
> --
> Ville Syrjälä
> Intel
> _______________________________________________
> Cocci mailing list
> Cocci@systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>

[-- Attachment #2: Type: text/plain, Size: 136 bytes --]

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

  reply	other threads:[~2020-02-19 22:37 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-19 17:28 [Cocci] Inserting code after specific set of declarations? Ville Syrjälä
2020-02-19 22:37 ` Julia Lawall [this message]
2020-02-20 13:27   ` Ville Syrjälä

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.2002192335560.2565@hadrien \
    --to=julia.lawall@inria.fr \
    --cc=cocci@systeme.lip6.fr \
    --cc=ville.syrjala@linux.intel.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;
as well as URLs for NNTP newsgroup(s).