cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [Cocci] "depends on" per file
@ 2019-05-24 13:18 Christoph Böhmwalder
  2019-05-24 13:20 ` Julia Lawall
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Christoph Böhmwalder @ 2019-05-24 13:18 UTC (permalink / raw)
  To: cocci

Hi,

I'm trying to replace a function with a one-liner, where the one-liner
has a dependency on a header file that the function doesn't.
Now I want to include said header file iff it isn't already included
in the affected file.
In more concrete terms, this is my script:


@ find_linux_dcache_h @
@@
 #include <linux/dcache.h>

@ replace_simple_positive @
expression den;
@@
- simple_positive(den)
+ (den->d_inode && !d_unhashed(den))

@ add_linux_dcache_h depends on !find_linux_dcache_h && ever
replace_simple_positive @
@@
 #include <...>
+ #include <linux/dcache.h>


So far so good, (almost) works just fine. The issue is that if the
rule gets matched in one file, it will include the header in every
other file as well, because the "depends on ever" clause is satisfied.
Is there a way to tell coccinelle "apply this rule to file X, but only
if another rule matched in the same file"?

--
Regards,
Christoph
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Cocci] "depends on" per file
  2019-05-24 13:18 [Cocci] "depends on" per file Christoph Böhmwalder
@ 2019-05-24 13:20 ` Julia Lawall
  2019-05-24 15:17 ` Markus Elfring
  2019-05-27 18:13 ` Markus Elfring
  2 siblings, 0 replies; 4+ messages in thread
From: Julia Lawall @ 2019-05-24 13:20 UTC (permalink / raw)
  To: Christoph Böhmwalder; +Cc: cocci

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



On Fri, 24 May 2019, Christoph Böhmwalder wrote:

> Hi,
>
> I'm trying to replace a function with a one-liner, where the one-liner
> has a dependency on a header file that the function doesn't.
> Now I want to include said header file iff it isn't already included
> in the affected file.
> In more concrete terms, this is my script:
>
>
> @ find_linux_dcache_h @
> @@
>  #include <linux/dcache.h>
>
> @ replace_simple_positive @
> expression den;
> @@
> - simple_positive(den)
> + (den->d_inode && !d_unhashed(den))
>
> @ add_linux_dcache_h depends on !find_linux_dcache_h && ever
> replace_simple_positive @
> @@
>  #include <...>
> + #include <linux/dcache.h>
>
>
> So far so good, (almost) works just fine. The issue is that if the
> rule gets matched in one file, it will include the header in every
> other file as well, because the "depends on ever" clause is satisfied.
> Is there a way to tell coccinelle "apply this rule to file X, but only
> if another rule matched in the same file"?

Do you have multiple file names on the command line?  If so, this i not a
good idea.  It will try to process all of the files at once.  Normally,
you just run Coccinelle on a directory.  Then it will process each file
independently.  You can do it in parallel as well, with the -j option.

julia

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

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Cocci] "depends on" per file
  2019-05-24 13:18 [Cocci] "depends on" per file Christoph Böhmwalder
  2019-05-24 13:20 ` Julia Lawall
@ 2019-05-24 15:17 ` Markus Elfring
  2019-05-27 18:13 ` Markus Elfring
  2 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2019-05-24 15:17 UTC (permalink / raw)
  To: Christoph Böhmwalder; +Cc: cocci

> @ replace_simple_positive @

How do you think about to move this rule to a separate SmPL script?

Do any other subsequent rules depend on it?

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Cocci] "depends on" per file
  2019-05-24 13:18 [Cocci] "depends on" per file Christoph Böhmwalder
  2019-05-24 13:20 ` Julia Lawall
  2019-05-24 15:17 ` Markus Elfring
@ 2019-05-27 18:13 ` Markus Elfring
  2 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2019-05-27 18:13 UTC (permalink / raw)
  To: Christoph Böhmwalder; +Cc: cocci

> The issue is that if the rule gets matched in one file,
> it will include the header in every other file as well,

How did you choose the selected source file combination?


> because the "depends on ever" clause is satisfied.
> Is there a way to tell coccinelle "apply this rule to file X,
> but only if another rule matched in the same file"?

Did you try out to set any script variable which can eventually be checked
by a SmPL rule at the end?

Will your development interests grow for corresponding software extensions?

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-05-27 18:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-24 13:18 [Cocci] "depends on" per file Christoph Böhmwalder
2019-05-24 13:20 ` Julia Lawall
2019-05-24 15:17 ` Markus Elfring
2019-05-27 18:13 ` Markus Elfring

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).