* matching a modified identifier?
@ 2017-02-06 11:35 Johannes Berg
2017-02-06 11:55 ` Johannes Berg
2017-02-06 12:22 ` [Cocci] " Julia Lawall
0 siblings, 2 replies; 4+ messages in thread
From: Johannes Berg @ 2017-02-06 11:35 UTC (permalink / raw)
To: cocci; +Cc: backports
Hi,
In backports, we have the following spatch:
@ attribute_group @
identifier group;
declarer name ATTRIBUTE_GROUPS;
@@
ATTRIBUTE_GROUPS(group);
@ class_group depends on attribute_group @
identifier group_class;
identifier groups;
fresh identifier group_dev_attr = attribute_group.group ## "_dev_attrs";
@@
struct class group_class = {
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0)
.dev_groups = groups,
+#else
+ .dev_attrs = group_dev_attr,
+#endif
};
[...]
But this isn't sufficient and falls over if there are multiple
instances of ATTRIBUTE_GROUPS, it's essentially undefined which one
gets picked.
I tried to match a modified identifier like this:
@ attribute_group @
identifier group;
fresh identifier groups = group ## "_groups";
declarer name ATTRIBUTE_GROUPS;
@@
ATTRIBUTE_GROUPS(group);
@ class_group depends on attribute_group @
identifier group_class;
identifier attribute_group.groups;
fresh identifier group_dev_attr = attribute_group.group ## "_dev_attrs";
@@
struct class group_class = {
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0)
.dev_groups = groups,
+#else
+ .dev_attrs = group_dev_attr,
+#endif
};
[...]
but that doesn't work at all.
Any thoughts?
johannes
--
To unsubscribe from this list: send the line "unsubscribe backports" in
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: matching a modified identifier?
2017-02-06 11:35 matching a modified identifier? Johannes Berg
@ 2017-02-06 11:55 ` Johannes Berg
2017-02-06 12:22 ` [Cocci] " Julia Lawall
1 sibling, 0 replies; 4+ messages in thread
From: Johannes Berg @ 2017-02-06 11:55 UTC (permalink / raw)
To: cocci; +Cc: backports
> @ attribute_group @
> identifier group;
> fresh identifier groups = group ## "_groups";
> declarer name ATTRIBUTE_GROUPS;
> @@
>
> ATTRIBUTE_GROUPS(group);
If I add a dummy here:
+ATTRIBUTE_GROUPS_NAME(groups);
> @ class_group depends on attribute_group @
> identifier group_class;
> identifier attribute_group.groups;
> fresh identifier group_dev_attr = attribute_group.group ##
> "_dev_attrs";
> @@
>
> struct class group_class = {
> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0)
> .dev_groups = groups,
> +#else
> + .dev_attrs = group_dev_attr,
> +#endif
> };
>
> [...]
Then the whole thing works - I guess I can live with that.
johannes
--
To unsubscribe from this list: send the line "unsubscribe backports" in
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Cocci] matching a modified identifier?
2017-02-06 11:35 matching a modified identifier? Johannes Berg
2017-02-06 11:55 ` Johannes Berg
@ 2017-02-06 12:22 ` Julia Lawall
2017-02-06 12:37 ` Johannes Berg
1 sibling, 1 reply; 4+ messages in thread
From: Julia Lawall @ 2017-02-06 12:22 UTC (permalink / raw)
To: Johannes Berg; +Cc: cocci, backports
[-- Attachment #1: Type: text/plain, Size: 1514 bytes --]
On Mon, 6 Feb 2017, Johannes Berg wrote:
> Hi,
>
> In backports, we have the following spatch:
>
> @ attribute_group @
> identifier group;
> declarer name ATTRIBUTE_GROUPS;
> @@
>
> ATTRIBUTE_GROUPS(group);
>
> @ class_group depends on attribute_group @
> identifier group_class;
> identifier groups;
> fresh identifier group_dev_attr = attribute_group.group ## "_dev_attrs";
> @@
>
> struct class group_class = {
> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0)
> .dev_groups = groups,
> +#else
> + .dev_attrs = group_dev_attr,
> +#endif
> };
>
> [...]
>
>
>
> But this isn't sufficient and falls over if there are multiple
> instances of ATTRIBUTE_GROUPS, it's essentially undefined which one
> gets picked.
>
> I tried to match a modified identifier like this:
>
> @ attribute_group @
> identifier group;
> fresh identifier groups = group ## "_groups";
> declarer name ATTRIBUTE_GROUPS;
> @@
>
> ATTRIBUTE_GROUPS(group);
>
> @ class_group depends on attribute_group @
> identifier group_class;
> identifier attribute_group.groups;
> fresh identifier group_dev_attr = attribute_group.group ## "_dev_attrs";
> @@
>
> struct class group_class = {
> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,11,0)
> .dev_groups = groups,
> +#else
> + .dev_attrs = group_dev_attr,
> +#endif
> };
>
> [...]
>
>
> but that doesn't work at all.
Use python between the two rules to construct the identifier you want.
You can see examples in coccinelle/demos/pythontococci.cocci
julia
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Cocci] matching a modified identifier?
2017-02-06 12:22 ` [Cocci] " Julia Lawall
@ 2017-02-06 12:37 ` Johannes Berg
0 siblings, 0 replies; 4+ messages in thread
From: Johannes Berg @ 2017-02-06 12:37 UTC (permalink / raw)
To: Julia Lawall; +Cc: cocci, backports
> Use python between the two rules to construct the identifier you
> want.
Indeed, that works and is simpler than I thought (had briefly
considered, but then found the workaround)
Thanks :)
johannes
--
To unsubscribe from this list: send the line "unsubscribe backports" in
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-02-06 12:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-06 11:35 matching a modified identifier? Johannes Berg
2017-02-06 11:55 ` Johannes Berg
2017-02-06 12:22 ` [Cocci] " Julia Lawall
2017-02-06 12:37 ` Johannes Berg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox