All of lore.kernel.org
 help / color / mirror / Atom feed
From: afd@ti.com (Andrew F. Davis)
To: cocci@systeme.lip6.fr
Subject: [Cocci] Ignoring all code in #ifdef blocks
Date: Mon, 9 May 2016 13:07:58 -0500	[thread overview]
Message-ID: <5730D1FE.5020100@ti.com> (raw)

Hello all,

I am working on a cocci script to remove unneeded code and I have
hopefully a simple question. My script attempts to remove a macro's use,
but only when a relevant struct definition is *not* blocked off by #if
and/or #ifdef CONFIG_OF. I think I would just like to have cocci ignore
all code in-between any blocks but I cannot seem to get it to work. I
have tried --no-includes and --undefined CONFIG_OF, but it still removes
the target macro, even when the struct is in an ifdef block. Example:

static const struct of_device_id gpio_ids[];

static int somefunction()
{
	const struct of_device_id *match;

	match = of_match_device(of_match_ptr(davinci_gpio_ids));
}

#if IS_ENABLED(CONFIG_OF)
static const struct of_device_id gpio_ids[] = {
	{ .compatible = "gpio", },
	{ /* sentinel */ },
};
MODULE_DEVICE_TABLE(of, gpio_ids);
#endif

static struct platform_driver gpio_driver = {
	.probe		= gpio_probe,
	.driver		= {
		.name		= "gpio",
		.of_match_table	= of_match_ptr(gpio_ids),
	},
};

None of the of_match_ptr should be removed in the above file, but if the
#if/endif were remove all should be removed, but I'm not sure how to
match for the ifdef?

Here is my script so far:

@s@
identifier arr;
@@
(
  struct of_device_id arr[] = {
  	...
  };
)

@depends on s@
identifier s.arr;
@@
(
- of_match_ptr(arr)
+ arr
)

Thanks,
Andrew

             reply	other threads:[~2016-05-09 18:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-09 18:07 Andrew F. Davis [this message]
2016-05-09 20:01 ` [Cocci] Ignoring all code in #ifdef blocks Julia Lawall
2016-05-12 21:09   ` Iago Abal

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=5730D1FE.5020100@ti.com \
    --to=afd@ti.com \
    --cc=cocci@systeme.lip6.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.