Coccinelle Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: julia.lawall@lip6.fr (Julia Lawall)
To: cocci@systeme.lip6.fr
Subject: [Cocci] remove typedefs from struct
Date: Mon, 16 Feb 2015 09:10:43 +0100 (CET)	[thread overview]
Message-ID: <alpine.DEB.2.10.1502160909560.2584@hadrien> (raw)
In-Reply-To: <4e2b1d4e856f4e98b2df175d1f46aa57@BN1BFFO11FD013.protection.gbl>



On Sun, 15 Feb 2015, S?ren Brinkmann wrote:

> On Mon, 2015-02-16 at 07:19AM +0100, Julia Lawall wrote:
> > > Sorry for bugging you again, but I tried to create a rule for cases that
> > > don't name the struct. E.g.
> > >   typedef struct {
> > >   	int bar;
> > >   } foo;
> > >
> > > My problem seems to be, that a struct identifier is an identifier, while
> > > the newly created type is a type. Hence, my naive approach:
> > > @@
> > > type t;
> > > @@
> > > -typedef struct {
> > > +struct t {
> > > 	...
> > > }
> > > - t
> > > ;
> > >
> > > does not work. And thus far, I couldn't find a way to get around this. I
> > > suspect there is some subtle trick to make it do what I want but I'm
> > > just not seeing it.
> >
> > It's a hack, but you can pass through python or ocaml.
> >
> > @r@
> > type t;
> > @@
> > typedef struct {
> > 	...
> > } t ;
> >
> > @script:python s@
> > t << r.t;
> > i;
> > @@
> >
> > coccinelle.i = t
> >
> > @@
> > tpye r.t;
> > identifier s.i;
> > @@
> >
> > ...
> >
> > Now in the last rule, you have all the information you need.  You might even
> > remove eg any trailing _t from t along the way.
>
> Awesome, that's it. I was pretty close. At some time I had pretty much
> exactly that. I think all I missed was the 'coccinelle.' in the python
> code.

In the demos subdirectory there are two examples:

pythontococci.cocci
camltococci.cocci

They are very helpful for remembering the syntax.

julia

      reply	other threads:[~2015-02-16  8:10 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-14 18:29 [Cocci] remove typedefs from struct Sören Brinkmann
2015-02-14 18:56 ` Julia Lawall
2015-02-15  1:22   ` Sören Brinkmann
2015-02-15  5:54     ` Julia Lawall
2015-02-15  9:38     ` Julia Lawall
2015-02-15 21:05       ` Sören Brinkmann
2015-02-15 21:16         ` Julia Lawall
2015-02-15 21:31           ` Sören Brinkmann
2015-02-15 21:41             ` Julia Lawall
2015-02-15 21:53               ` Sören Brinkmann
2015-02-15 21:56                 ` Julia Lawall
2015-02-16  9:00                   ` Sören Brinkmann
2015-02-16  9:10                     ` Julia Lawall
2015-02-16 15:59                       ` Sören Brinkmann
2015-02-17  6:56                     ` Julia Lawall
2015-02-17 19:42                       ` Sören Brinkmann
2015-02-17 20:31                         ` Julia Lawall
2015-02-18  0:50                           ` Sören Brinkmann
2015-02-18 21:44                             ` Julia Lawall
2015-02-19  9:08                               ` [Cocci] Finding several type qualifiers with SmPL? SF Markus Elfring
2015-02-19 16:47                                 ` Sören Brinkmann
2015-02-19 16:54                                   ` Julia Lawall
2015-02-19 18:55                                     ` SF Markus Elfring
2015-02-19 18:30                                   ` SF Markus Elfring
2015-02-15 17:13 ` [Cocci] remove typedefs from struct SF Markus Elfring
2015-02-15 17:32   ` Julia Lawall
2015-02-15 20:15     ` Sören Brinkmann
2015-02-16  4:31     ` Sören Brinkmann
2015-02-16  6:19       ` Julia Lawall
2015-02-16  7:51         ` Sören Brinkmann
2015-02-16  8:10           ` Julia Lawall [this message]

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.10.1502160909560.2584@hadrien \
    --to=julia.lawall@lip6.fr \
    --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