* [Cocci] Simple replacement of an expression of given type?
@ 2014-06-20 23:38 Rusty Russell
2014-06-21 6:27 ` Lars-Peter Clausen
2014-06-21 6:28 ` Julia Lawall
0 siblings, 2 replies; 4+ messages in thread
From: Rusty Russell @ 2014-06-20 23:38 UTC (permalink / raw)
To: cocci
Hi!
In my current project, I moved a field from a structure
(struct block) into another network-endian structure. I used the
following patch.cocci to do the fixups:
@ rule1 @
struct block *b;
@@
- b->blocknum
+ le32_to_cpu(b->hdr->depth)
It got 99%, but it missed the two cases where b was actually in another
structure, ie. "te->block->blocknum".
I *think* this is because I want to substitute any expression of type
struct block *, rather than only identifiers?
But I couldn't understand the documentation enough to do this :(
Clues appreciated!
Rusty.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Cocci] Simple replacement of an expression of given type?
2014-06-20 23:38 [Cocci] Simple replacement of an expression of given type? Rusty Russell
@ 2014-06-21 6:27 ` Lars-Peter Clausen
2014-06-21 6:28 ` Julia Lawall
1 sibling, 0 replies; 4+ messages in thread
From: Lars-Peter Clausen @ 2014-06-21 6:27 UTC (permalink / raw)
To: cocci
On 06/21/2014 01:38 AM, Rusty Russell wrote:
> Hi!
>
> In my current project, I moved a field from a structure
> (struct block) into another network-endian structure. I used the
> following patch.cocci to do the fixups:
>
> @ rule1 @
> struct block *b;
> @@
>
> - b->blocknum
> + le32_to_cpu(b->hdr->depth)
>
> It got 99%, but it missed the two cases where b was actually in another
> structure, ie. "te->block->blocknum".
>
> I *think* this is because I want to substitute any expression of type
> struct block *, rather than only identifiers?
>
> But I couldn't understand the documentation enough to do this :(
This should work. But by default coccinelle does not parse global headers,
so if the struct for te is defined in a global header it won't know that
te->block is of type 'struct block *'. If that is the case try to run it
with --all-includes
- Lars
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Cocci] Simple replacement of an expression of given type?
2014-06-20 23:38 [Cocci] Simple replacement of an expression of given type? Rusty Russell
2014-06-21 6:27 ` Lars-Peter Clausen
@ 2014-06-21 6:28 ` Julia Lawall
2014-06-21 7:06 ` Rusty Russell
1 sibling, 1 reply; 4+ messages in thread
From: Julia Lawall @ 2014-06-21 6:28 UTC (permalink / raw)
To: cocci
On Sat, 21 Jun 2014, Rusty Russell wrote:
> Hi!
>
> In my current project, I moved a field from a structure
> (struct block) into another network-endian structure. I used the
> following patch.cocci to do the fixups:
>
> @ rule1 @
> struct block *b;
> @@
>
> - b->blocknum
> + le32_to_cpu(b->hdr->depth)
>
> It got 99%, but it missed the two cases where b was actually in another
> structure, ie. "te->block->blocknum".
>
> I *think* this is because I want to substitute any expression of type
> struct block *, rather than only identifiers?
>
> But I couldn't understand the documentation enough to do this :(
You are already working on expressions. The problem is that sometimes
Coccinelle doesn't know what is the type of te->block. To give it the
most possible amount of informations, you can give the options
--recursive-includes --relax-include-path
The first means that it will take into account include files that are
referenced from other include files rather than just those referenced
directly in the C file. The second means that if it doesn't find xyz.h in
the include path but it does find exactly one xyz.h somewhere else in the
source tree, then it will use that xyz.h, since it has to be the right
one.
This will probably take more time than it is taking now, because it has to
parse more code. You may want to use the option --use-cache so that it
will cache already parsed code.
julia
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Cocci] Simple replacement of an expression of given type?
2014-06-21 6:28 ` Julia Lawall
@ 2014-06-21 7:06 ` Rusty Russell
0 siblings, 0 replies; 4+ messages in thread
From: Rusty Russell @ 2014-06-21 7:06 UTC (permalink / raw)
To: cocci
Julia Lawall <julia.lawall@lip6.fr> writes:
> On Sat, 21 Jun 2014, Rusty Russell wrote:
>
>> Hi!
>>
>> In my current project, I moved a field from a structure
>> (struct block) into another network-endian structure. I used the
>> following patch.cocci to do the fixups:
>>
>> @ rule1 @
>> struct block *b;
>> @@
>>
>> - b->blocknum
>> + le32_to_cpu(b->hdr->depth)
>>
>> It got 99%, but it missed the two cases where b was actually in another
>> structure, ie. "te->block->blocknum".
>>
>> I *think* this is because I want to substitute any expression of type
>> struct block *, rather than only identifiers?
>>
>> But I couldn't understand the documentation enough to do this :(
>
> You are already working on expressions. The problem is that sometimes
> Coccinelle doesn't know what is the type of te->block. To give it the
> most possible amount of informations, you can give the options
>
> --recursive-includes --relax-include-path
Ah, thanks for the explanation, and indeed, that worked perfectly.
And thanks Julia and Lars for your quick responses!
Cheers,
Rusty.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-06-21 7:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-20 23:38 [Cocci] Simple replacement of an expression of given type? Rusty Russell
2014-06-21 6:27 ` Lars-Peter Clausen
2014-06-21 6:28 ` Julia Lawall
2014-06-21 7:06 ` Rusty Russell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox