All of lore.kernel.org
 help / color / mirror / Atom feed
* [Cocci] Ignoring all code in #ifdef blocks
@ 2016-05-09 18:07 Andrew F. Davis
  2016-05-09 20:01 ` Julia Lawall
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew F. Davis @ 2016-05-09 18:07 UTC (permalink / raw)
  To: cocci

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

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

end of thread, other threads:[~2016-05-12 21:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-09 18:07 [Cocci] Ignoring all code in #ifdef blocks Andrew F. Davis
2016-05-09 20:01 ` Julia Lawall
2016-05-12 21:09   ` Iago Abal

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.