cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
From: Julia Lawall <julia.lawall@lip6.fr>
To: Max <msuraev@sysmocom.de>
Cc: cocci@systeme.lip6.fr
Subject: Re: [Cocci] struct replacement
Date: Tue, 18 Dec 2018 17:54:21 +0100 (CET)	[thread overview]
Message-ID: <alpine.DEB.2.20.1812181749390.2886@hadrien> (raw)
In-Reply-To: <372cf517-11cb-3021-fc5b-219b26022493@sysmocom.de>

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



On Tue, 18 Dec 2018, Max wrote:

> I see. Yes,  --all-includes did the trick for me, thank you.
>
> Although I'm still have to update struct fields in addition to struct
> name and it seems like I'm using typedef in a wrong way.
>
> For example:
>
> _______________________
>
> @@
> @@
> struct
> - old_addr
> + new_address
>
> @@
> identifier a;
> typedef new_address;
> @@
> new_address a;
> - a.len;
> + a.length;

I don't understand what you are trying to do here.  typedef new_address;
is find for indicating that new_address is a typedef.  Ie you have
somewhere said:

typedef ... new_address;

new_address a; will then match a declaration where the type of the
declared variable is new_address.  But I don't understand - a.len;.
First, this is only going to match a statement that comes right after the
variable declaration.  Second, a.len; is a very strange statement, because
it doesn't do anything.

Maybe you want:

@@
typedef new_address;
new_address a;
@@
- a.len
+ a.length

That is, a should be a metavariable representing an expression of the
given type, and then you want to replace a len field by length.

You could also write the change as:

a.
-len
+length

julia

>
> _______________________
>
> This does not cause field updates although first part (names) works.
>
> Using 'typedef struct new_address' instead gives "meta: parse error".
>
> Using 'old_addr' instead of 'new_address' in 2nd part doesn't make any
> difference.
>
> The len/length are pretty generic names used in multiple structs. How do
> I instruct Coccinelle to make replacement only for identifiers which
> belong to a particular struct type (or pointer to it)?
>
> Is there some specific metaver syntax related to structs which I haven't
> found yet?
>
> 18.12.18 17:19, Julia Lawall пишет:
> >
> > By default, Coccinelle only includes the headers that have the same name
> > as the .c file.  Ie for foo.c, it considers that foo.h is prbably
> > important, and thus worth the often large extra runtime cost to take into
> > account.
> >
> > If you want more aggressive inclusion of headers, you need --all-includes
> > (the headers explicitly mentioned in the .c file) or --recursive-includes
> > (headers included by other headers).
> >
> > julia
>
> --
> - Max Suraev <msuraev@sysmocom.de>       http://www.sysmocom.de/
> =======================================================================
> * sysmocom - systems for mobile communications GmbH
> * Alt-Moabit 93
> * 10559 Berlin, Germany
> * Sitz / Registered office: Berlin, HRB 134158 B
> * Geschaeftsfuehrer / Managing Directors: Harald Welte
>
> _______________________________________________
> 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:[~2018-12-18 16:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-12 18:39 [Cocci] struct replacement Max
2018-12-13  6:24 ` Julia Lawall
2018-12-13 16:43   ` Max
2018-12-13 20:01     ` Julia Lawall
     [not found]       ` <c8041b90-d4e9-a9a6-603d-7f5498fe081c@users.sourceforge.net>
2018-12-15 13:49         ` Julia Lawall
2018-12-18 16:15       ` Max
2018-12-18 16:19         ` Julia Lawall
2018-12-18 16:44           ` Max
2018-12-18 16:54             ` Julia Lawall [this message]
2018-12-18 17:12               ` Max
2018-12-18 17:18                 ` Julia Lawall
2018-12-18 18:13                   ` Max

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.20.1812181749390.2886@hadrien \
    --to=julia.lawall@lip6.fr \
    --cc=cocci@systeme.lip6.fr \
    --cc=msuraev@sysmocom.de \
    /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).