All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nikolaus@rath.org (Nikolaus Rath)
To: cocci@systeme.lip6.fr
Subject: [Cocci] Replacing one (specific!) type with another
Date: Sat, 08 Oct 2016 13:52:13 -0700	[thread overview]
Message-ID: <87ponay35u.fsf@vostro.rath.org> (raw)
In-Reply-To: <alpine.DEB.2.10.1610080727090.3176@hadrien> (Julia Lawall's message of "Sat, 8 Oct 2016 07:31:01 +0200 (CEST)")

On Oct 08 2016, Julia Lawall <julia.lawall@lip6.fr> wrote:
> On Fri, 7 Oct 2016, Nikolaus Rath wrote:
>
>> On Oct 05 2016, Julia Lawall <julia.lawall@lip6.fr> wrote:
>> >>
>> >> 2. ..and how would I go about if instead of the type, I want to replace
>> >>    a variable name? (my_type *ptr --> my_type *pointer).
>> >
>> > I'm not completely sure what the issue is here.  Do you specifically want
>> > to convert ptr to pointer?  Is the type important?  To make exactly what
>> > you have written, you could put:
>> >
>> > @@
>> > typedef my_type;
>> > idexpression mytype * p1;
>> > @@
>> >
>> > - ptr at p1
>> > + pointer
>> >
>> > This checks for the word ptr, and also checks that it is an identifier of
>> > the right type.  I haven't tested it, so let me know if there is any
>> > problem.
>>
>> It workes somewhat... but not completely.
>>
>> Here's what I wanted to do: I merged two structures (struct fuse_session
>> and struct fuse_ll) into one (struct fuse_session). I've first replaced
>> all the type names, and then manually fixed the cases where this
>> resulted in bogus/redundant code (typically in functions that used to
>> work with both structs).
>>
>> Now my project compiles and runs fine, but I the variable naming is
>> inconsistent: in some cases the struct fuse_session pointer is called
>> *se (these were the variables that were always of type struct
>> fuse_session), and in other cases the pointer is called *f (these were
>> the variables that were previously of type struct fuse_ll).
>>
>> I'd like to fix this too, and always refer call fuse_session pointers
>> "se" (except where this name is already used for something else, but
>> I'll just fix this up by hand afterwards). I tried the following patch:
>>
>> $ cat se-name.cocci
>> @@
>> idexpression struct fuse_session *p1;
>> @@
>> - f at p1
>> + se
>>
>> but it resulted in these changes:
>>
>>  	struct fuse_session *f = req->se;
>> -	struct cuse_data *cd = f->cuse_data;
>> -	size_t bufsize = f->bufsize;
>> +	struct cuse_data *cd = se->cuse_data;
>> +	size_t bufsize = se->bufsize;
>>
>> So it seems to replace the variable where its used, but not where it's
>> defined.
>>
>> Is there a way to catch the definitions too?
>
> Write separate rules for that.  You would need one case for a local
> variable and one case fora parameter.  You can actually probably just drop
> the rule you have currently.  I would imagine something like the
> following:
>
> @@
> symbol f, se; // avoid unneeded warnings from Coccinelle
> @@
>
> struct fuse_session *
> -f
> +se
>  ;
> <...
> -f
> +se
> ...>

Could you explain how this works (in particular the effect of the angle
brackets)? I also can't resist to point out that "symbol" is not
included in the list of metavariable types from the tutorial slides :-).

> @@
> identifier fn;
> @@
>
> fn(...,struct fuse_session *f,...) { <...
> -f
> +se
> ...> }
>
> I think that the symbol declaration has effect in the rest of the semantic
> patch, and does not have to be repeated.  If you get warnings for the
> second rule, just copy it down.

Not sure what you mean with "copy it down". I don't get Coccinelle
warnings, but if I just use the two rules as you gave them, then
it looks as if the second one isn't working:

@@ -584,9 +584,9 @@ static struct fuse_ll_pipe *fuse_ll_get_
 
 static void fuse_ll_clear_pipe(struct fuse_session *f)
 {
-	struct fuse_ll_pipe *llp = pthread_getspecific(f->pipe_key);
+	struct fuse_ll_pipe *llp = pthread_getspecific(se->pipe_key);
 	if (llp) {
-		pthread_setspecific(f->pipe_key, NULL);
+		pthread_setspecific(se->pipe_key, NULL);
 		fuse_ll_pipe_free(llp);
 	}
 }


Is the problem that "...," does not match nothing, i.e. *f must not be
the first argument of the function?


Best,
-Nikolaus

-- 
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             ?Time flies like an arrow, fruit flies like a Banana.?

  reply	other threads:[~2016-10-08 20:52 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-05  3:27 [Cocci] Replacing one (specific!) type with another Nikolaus Rath
2016-10-05  5:45 ` Julia Lawall
2016-10-05 16:09   ` Nikolaus Rath
2016-10-05 16:39     ` Michael Stefaniuc
2016-10-05 17:21     ` [Cocci] Replacing one variable name " SF Markus Elfring
2016-10-05 22:34       ` Nikolaus Rath
2016-10-06  5:42         ` SF Markus Elfring
2016-10-06  5:56         ` Julia Lawall
2016-10-05 20:02     ` [Cocci] Replacing one (specific!) type " Julia Lawall
2016-10-05 22:38       ` Nikolaus Rath
2016-10-06  5:55         ` Julia Lawall
2016-10-08  3:16           ` Nikolaus Rath
2016-10-08  5:50             ` Julia Lawall
2016-10-08 20:45               ` Nikolaus Rath
2016-10-08 21:23                 ` Julia Lawall
2016-10-09  6:32                 ` SF Markus Elfring
2016-10-08  6:48             ` [Cocci] Usage of "expressions" and "identifiers" with SmPL SF Markus Elfring
2016-10-08  6:57               ` Julia Lawall
     [not found]               ` <alpine.DEB.2.10.1610080850470.7750@hadrien>
2016-10-08  7:49                 ` SF Markus Elfring
2016-10-08  7:56                   ` Julia Lawall
2016-10-08  8:26                     ` SF Markus Elfring
2016-10-08  8:38                       ` Julia Lawall
2016-10-08  9:25                         ` SF Markus Elfring
2016-10-08 20:28                           ` Nikolaus Rath
2016-10-09  7:49                             ` SF Markus Elfring
2016-10-09 20:38                               ` Nikolaus Rath
2016-10-10  6:48                                 ` SF Markus Elfring
2016-10-10  6:50                                   ` Julia Lawall
2016-10-06  6:30         ` [Cocci] Replacing one (specific!) type with another SF Markus Elfring
2016-10-08  4:22       ` Nikolaus Rath
2016-10-08  5:31         ` Julia Lawall
2016-10-08 20:52           ` Nikolaus Rath [this message]
2016-10-08 21:21             ` Julia Lawall
2016-10-09 20:45               ` Nikolaus Rath
2016-10-10  4:49                 ` Julia Lawall
2016-10-10  4:54                 ` Julia Lawall
2016-10-10 15:56                   ` Nikolaus Rath
2016-10-10 18:45                     ` Nikolaus Rath
2016-10-10 19:45                       ` Julia Lawall
2016-10-10 21:27                         ` Nikolaus Rath
2016-10-10 21:33                           ` Julia Lawall
2016-10-10 23:00                             ` Nikolaus Rath
2016-10-11  6:51                               ` Julia Lawall
2016-10-12 15:08                                 ` Nikolaus Rath
2016-10-12 20:37                                   ` Julia Lawall
2016-10-05  5:51 ` SF Markus Elfring

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=87ponay35u.fsf@vostro.rath.org \
    --to=nikolaus@rath.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.