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

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

      reply	other threads:[~2022-08-03 11:26 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
2022-08-03 11:26   ` Palani kodeswaran [this message]

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=CAASoEDQX5WA8eXoYhToficaNUBocB5Kfw2O6nGWY0wCxNH-evg@mail.gmail.com \
    --to=palani.k@gmail.com \
    --cc=cocci@inria.fr \
    --cc=julia.lawall@inria.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 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 read-only IMAP folder(s) and NNTP newsgroup(s).