cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
From: Julia Lawall <julia.lawall@inria.fr>
To: Palani kodeswaran <palani.k@gmail.com>
Cc: cocci@inria.fr
Subject: Re: [cocci] Can coccinelle be used for adding header files
Date: Wed, 3 Aug 2022 08:03:18 +0200 (CEST)	[thread overview]
Message-ID: <alpine.DEB.2.22.394.2208030757490.2778@hadrien> (raw)
In-Reply-To: <CAASoEDQCExdJXmMJy55OPAVaetG9b91g7ecdXojDVoC0iC-CRQ@mail.gmail.com>

[-- 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

  reply	other threads:[~2022-08-03  6:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-03  5:54 [cocci] Can coccinelle be used for adding header files Palani kodeswaran
2022-08-03  6:03 ` Julia Lawall [this message]
2022-08-03 11:26   ` Palani kodeswaran

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.22.394.2208030757490.2778@hadrien \
    --to=julia.lawall@inria.fr \
    --cc=cocci@inria.fr \
    --cc=palani.k@gmail.com \
    /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).