cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [cocci] Can coccinelle be used for adding header files
@ 2022-08-03  5:54 Palani kodeswaran
  2022-08-03  6:03 ` Julia Lawall
  0 siblings, 1 reply; 3+ messages in thread
From: Palani kodeswaran @ 2022-08-03  5:54 UTC (permalink / raw)
  To: cocci

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

Hello,

I am new to coccinelle and am trying to see if it would be possible in
coccinelle to add a header file to a source file.

Our current coccinelle rules change function calls to a different function
that is defined in another header file that is not included by default.
Would greatly appreciate if someone could point to an example that can
accomplish adding header files.


Regards,
Palani.

[-- Attachment #2: Type: text/html, Size: 498 bytes --]

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

* Re: [cocci] Can coccinelle be used for adding header files
  2022-08-03  5:54 [cocci] Can coccinelle be used for adding header files Palani kodeswaran
@ 2022-08-03  6:03 ` Julia Lawall
  2022-08-03 11:26   ` Palani kodeswaran
  0 siblings, 1 reply; 3+ messages in thread
From: Julia Lawall @ 2022-08-03  6:03 UTC (permalink / raw)
  To: Palani kodeswaran; +Cc: cocci

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



On Wed, 3 Aug 2022, Palani kodeswaran wrote:

> Hello,
>
> I am new to coccinelle and am trying to see if it would be possible in coccinelle to add a header file to a source file. 
> Our current coccinelle rules change function calls to a different function that is defined in another header file that is not included by default. Would greatly appreciate if someone could point to an example that can accomplish adding header files. 

You should be able to do:

@@
@@

#include <...>
+#include <myheader.h>

The problem comes if there is no include in your code at the moment.  I
don't think there is any convenient solution for this at the moment.

You could use python to print out that your Coccinelle rule has detected
that the header file shold be added, and then add it by hand.

Also, the above will not necessarily put the header file at the place
where you want it.  I don't really remember what strategy it uses.
Perhaps it is just put as the last one with the above rule, and as the
first one with the following:

@@
@@

+#include <myheader.h>
#include <...>

Instead of ... you can also put a file name, if there is a specific file
you want the new header to always be before or after.

You may also need to make separate rules for the case

#include "..."

You can give each rule a name, and then ensure that later ones are only
run if earlier ones are not used, eg:

@r1@
@@
- foo
+ bar

@depends on !r1@
@@

- xxx
+ yyy

julia

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

* Re: [cocci] Can coccinelle be used for adding header files
  2022-08-03  6:03 ` Julia Lawall
@ 2022-08-03 11:26   ` Palani kodeswaran
  0 siblings, 0 replies; 3+ messages in thread
From: Palani kodeswaran @ 2022-08-03 11:26 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci

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

This works... Thank you very much.

Palani.

On Wed, Aug 3, 2022 at 11:33 AM Julia Lawall <julia.lawall@inria.fr> wrote:

>
>
> On Wed, 3 Aug 2022, Palani kodeswaran wrote:
>
> > Hello,
> >
> > I am new to coccinelle and am trying to see if it would be possible in
> coccinelle to add a header file to a source file.
> > Our current coccinelle rules change function calls to a different
> function that is defined in another header file that is not included by
> default. Would greatly appreciate if someone could point to an example that
> can accomplish adding header files.
>
> You should be able to do:
>
> @@
> @@
>
> #include <...>
> +#include <myheader.h>
>
> The problem comes if there is no include in your code at the moment.  I
> don't think there is any convenient solution for this at the moment.
>
> You could use python to print out that your Coccinelle rule has detected
> that the header file shold be added, and then add it by hand.
>
> Also, the above will not necessarily put the header file at the place
> where you want it.  I don't really remember what strategy it uses.
> Perhaps it is just put as the last one with the above rule, and as the
> first one with the following:
>
> @@
> @@
>
> +#include <myheader.h>
> #include <...>
>
> Instead of ... you can also put a file name, if there is a specific file
> you want the new header to always be before or after.
>
> You may also need to make separate rules for the case
>
> #include "..."
>
> You can give each rule a name, and then ensure that later ones are only
> run if earlier ones are not used, eg:
>
> @r1@
> @@
> - foo
> + bar
>
> @depends on !r1@
> @@
>
> - xxx
> + yyy
>
> julia

[-- Attachment #2: Type: text/html, Size: 2210 bytes --]

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

end of thread, other threads:[~2022-08-03 11:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-03  5:54 [cocci] Can coccinelle be used for adding header files Palani kodeswaran
2022-08-03  6:03 ` Julia Lawall
2022-08-03 11:26   ` Palani kodeswaran

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