From: linux@roeck-us.net (Guenter Roeck)
To: cocci@systeme.lip6.fr
Subject: [Cocci] Converting DEVICE_ATTR to DEVICE_ATTR_{RO, RW, WO} and changing function names at the same time
Date: Fri, 23 Dec 2016 15:10:19 -0800 [thread overview]
Message-ID: <20161223231019.GA25609@roeck-us.net> (raw)
In-Reply-To: <alpine.DEB.2.20.1612231404050.4056@hadrien>
Hi Julia,
On Fri, Dec 23, 2016 at 04:54:41PM +0100, Julia Lawall wrote:
[ ... ]
>
> // -------------------------------------------------------------------------
> @ro@
> declarer name SENSOR_DEVICE_ATTR, SENSOR_DEVICE_ATTR_2;
> identifier x,show;
> @@
>
> \(SENSOR_DEVICE_ATTR\|SENSOR_DEVICE_ATTR_2\)
> (x, \(0444\|S_IRUGO\), show, NULL, ...);
>
my version of spatch (?) does not like this construct.
$ spatch --version
spatch version 1.0.6-00036-gb62df17 compiled with OCaml version 4.02.3
Flags passed to the configure script: --prefix=/usr
Python scripting support: yes
Syntax of regular expresssions: PCRE
Is this something new, or am I doing something wrong ?
I played with it myself, and came up with the (less elegant) version
below. It isn't perfect (it does not handle the function-in-macro case
well), but it should give us a good comparison. Also, I might just get
rid of at least some of those macros; they just obfuscate the code anyway.
Thanks,
Guenter
---
@initialize:python@
@@
import re
// -------------------------------------------------------------------------
// Easy case
@d@
declarer name SENSOR_DEVICE_ATTR,SENSOR_DEVICE_ATTR_2;
identifier x,show,store;
expression p;
@@
(
SENSOR_DEVICE_ATTR(x,p,show,store,...);
|
SENSOR_DEVICE_ATTR_2(x,p,show,store,...);
)
@script:python expected@
show << d.show;
store << d.store;
x_show;
x_store;
func;
@@
coccinelle.func = re.sub('show_|get_|_show|_get|_read', '', show)
coccinelle.x_show = re.sub('show_|get_|_show|_get|_read', '', show) + "_show"
coccinelle.x_store = re.sub('show_|get_|_get|_show|_read', '', show) + "_store"
if show == "NULL":
coccinelle.x_store = re.sub('store_|set_|_set|_store|_write|_reset', '', store) + "_store"
coccinelle.func = re.sub('store_|set_|_store|_set|_write|_reset', '', store)
@@
declarer name SENSOR_DEVICE_ATTR_RO;
identifier d.x,expected.x_show,expected.func;
expression e;
@@
- SENSOR_DEVICE_ATTR(x, \(0444\|S_IRUGO\), x_show, NULL, e);
+ SENSOR_DEVICE_ATTR_RO(x, func, e);
@@
declarer name SENSOR_DEVICE_ATTR_WO;
identifier d.x,expected.x_store,expected.func;
expression e;
@@
- SENSOR_DEVICE_ATTR(x, \(0200\|S_IWUSR\), NULL, x_store, e);
+ SENSOR_DEVICE_ATTR_WO(x, func, e);
@@
declarer name SENSOR_DEVICE_ATTR_RW;
identifier d.x,expected.x_show,expected.x_store,expected.func;
expression e;
@@
- SENSOR_DEVICE_ATTR(x, \(0644\|S_IRUGO|S_IWUSR\|S_IWUSR|S_IRUGO\), x_show, x_store, e);
+ SENSOR_DEVICE_ATTR_RW(x, func, e);
@@
declarer name SENSOR_DEVICE_ATTR_2_RO;
identifier d.x,expected.x_show,expected.func;
expression e1,e2;
@@
- SENSOR_DEVICE_ATTR_2(x, \(0444\|S_IRUGO\), x_show, NULL, e1, e2);
+ SENSOR_DEVICE_ATTR_2_RO(x, func, e1, e2);
@@
declarer name SENSOR_DEVICE_ATTR_2_WO;
identifier d.x,expected.x_store,expected.func;
expression e1,e2;
@@
- SENSOR_DEVICE_ATTR_2(x, \(0200\|S_IWUSR\), NULL, x_store, e1, e2);
+ SENSOR_DEVICE_ATTR_2_WO(x, func, e1, e2);
@@
declarer name SENSOR_DEVICE_ATTR_2_RW;
identifier d.x,expected.x_show,expected.x_store,expected.func;
expression e1, e2;
@@
- SENSOR_DEVICE_ATTR_2(x, \(0644\|S_IRUGO|S_IWUSR\|S_IWUSR|S_IRUGO\), x_show, x_store, e1, e2);
+ SENSOR_DEVICE_ATTR_2_RW(x, func, e1, e2);
// -------------------------------------------------------------------------
// Other calls
@o@
declarer name SENSOR_DEVICE_ATTR,SENSOR_DEVICE_ATTR_2;
identifier d.x,show,store;
expression list es;
@@
(
SENSOR_DEVICE_ATTR(x,\(0444\|S_IRUGO\|0200\|S_IWUSR\|0644\|S_IRUGO|S_IWUSR\|S_IWUSR|S_IRUGO\),show,store,es);
|
SENSOR_DEVICE_ATTR_2(x,\(0444\|S_IRUGO\|0200\|S_IWUSR\|0644\|S_IRUGO|S_IWUSR\|S_IWUSR|S_IRUGO\),show,store,es);
)
// rename functions
@show1@
identifier o.show,expected.x_show;
parameter list ps;
@@
static
- show(ps)
+ x_show(ps)
{ ... }
@depends on show1@
identifier o.show,expected.x_show;
expression list es;
@@
- show(es)
+ x_show(es)
@depends on show1@
identifier o.show,expected.x_show;
@@
- show
+ x_show
@store1@
identifier o.store,expected.x_store;
parameter list ps;
@@
static
- store(ps)
+ x_store(ps)
{ ... }
@depends on store1@
identifier o.store,expected.x_store;
expression list es;
@@
- store(es)
+ x_store(es)
@depends on store1@
identifier o.store,expected.x_store;
@@
- store
+ x_store
// try again
@@
declarer name SENSOR_DEVICE_ATTR_RO;
identifier d.x,expected.x_show,expected.func;
expression e;
@@
- SENSOR_DEVICE_ATTR(x, \(0444\|S_IRUGO\), x_show, NULL, e);
+ SENSOR_DEVICE_ATTR_RO(x, func, e);
@@
declarer name SENSOR_DEVICE_ATTR_WO;
identifier d.x,expected.x_store,expected.func;
expression e;
@@
- SENSOR_DEVICE_ATTR(x, \(0200\|S_IWUSR\), NULL, x_store, e);
+ SENSOR_DEVICE_ATTR_WO(x, func, e);
@@
declarer name SENSOR_DEVICE_ATTR_RW;
identifier d.x,expected.x_show,expected.x_store,expected.func;
expression e;
@@
- SENSOR_DEVICE_ATTR(x, \(0644\|S_IRUGO|S_IWUSR\|S_IWUSR|S_IRUGO\), x_show, x_store, e);
+ SENSOR_DEVICE_ATTR_RW(x, func, e);
@@
declarer name SENSOR_DEVICE_ATTR_2_RO;
identifier d.x,expected.x_show,expected.func;
expression e1,e2;
@@
- SENSOR_DEVICE_ATTR_2(x, \(0444\|S_IRUGO\), x_show, NULL, e1, e2);
+ SENSOR_DEVICE_ATTR_2_RO(x, func, e1, e2);
@@
declarer name SENSOR_DEVICE_ATTR_2_WO;
identifier d.x,expected.x_store,expected.func;
expression e1, e2;
@@
- SENSOR_DEVICE_ATTR_2(x, \(0200\|S_IWUSR\), NULL, x_store, e1, e2);
+ SENSOR_DEVICE_ATTR_2_WO(x, func, e1, e2);
@@
declarer name SENSOR_DEVICE_ATTR_2_RW;
identifier d.x,expected.x_show,expected.x_store,expected.func;
expression e1, e2;
@@
- SENSOR_DEVICE_ATTR_2(x, \(0644\|S_IRUGO|S_IWUSR\|S_IWUSR|S_IRUGO\), x_show, x_store, e1, e2);
+ SENSOR_DEVICE_ATTR_2_RW(x, func, e1, e2);
WARNING: multiple messages have this Message-ID (diff)
From: Guenter Roeck <linux@roeck-us.net>
To: Julia Lawall <julia.lawall@lip6.fr>
Cc: cocci@systeme.lip6.fr, Greg KH <gregkh@linuxfoundation.org>,
linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: Converting DEVICE_ATTR to DEVICE_ATTR_{RO,RW,WO} and changing function names at the same time
Date: Fri, 23 Dec 2016 15:10:19 -0800 [thread overview]
Message-ID: <20161223231019.GA25609@roeck-us.net> (raw)
In-Reply-To: <alpine.DEB.2.20.1612231404050.4056@hadrien>
Hi Julia,
On Fri, Dec 23, 2016 at 04:54:41PM +0100, Julia Lawall wrote:
[ ... ]
>
> // -------------------------------------------------------------------------
> @ro@
> declarer name SENSOR_DEVICE_ATTR, SENSOR_DEVICE_ATTR_2;
> identifier x,show;
> @@
>
> \(SENSOR_DEVICE_ATTR\|SENSOR_DEVICE_ATTR_2\)
> (x, \(0444\|S_IRUGO\), show, NULL, ...);
>
my version of spatch (?) does not like this construct.
$ spatch --version
spatch version 1.0.6-00036-gb62df17 compiled with OCaml version 4.02.3
Flags passed to the configure script: --prefix=/usr
Python scripting support: yes
Syntax of regular expresssions: PCRE
Is this something new, or am I doing something wrong ?
I played with it myself, and came up with the (less elegant) version
below. It isn't perfect (it does not handle the function-in-macro case
well), but it should give us a good comparison. Also, I might just get
rid of at least some of those macros; they just obfuscate the code anyway.
Thanks,
Guenter
---
@initialize:python@
@@
import re
// -------------------------------------------------------------------------
// Easy case
@d@
declarer name SENSOR_DEVICE_ATTR,SENSOR_DEVICE_ATTR_2;
identifier x,show,store;
expression p;
@@
(
SENSOR_DEVICE_ATTR(x,p,show,store,...);
|
SENSOR_DEVICE_ATTR_2(x,p,show,store,...);
)
@script:python expected@
show << d.show;
store << d.store;
x_show;
x_store;
func;
@@
coccinelle.func = re.sub('show_|get_|_show|_get|_read', '', show)
coccinelle.x_show = re.sub('show_|get_|_show|_get|_read', '', show) + "_show"
coccinelle.x_store = re.sub('show_|get_|_get|_show|_read', '', show) + "_store"
if show == "NULL":
coccinelle.x_store = re.sub('store_|set_|_set|_store|_write|_reset', '', store) + "_store"
coccinelle.func = re.sub('store_|set_|_store|_set|_write|_reset', '', store)
@@
declarer name SENSOR_DEVICE_ATTR_RO;
identifier d.x,expected.x_show,expected.func;
expression e;
@@
- SENSOR_DEVICE_ATTR(x, \(0444\|S_IRUGO\), x_show, NULL, e);
+ SENSOR_DEVICE_ATTR_RO(x, func, e);
@@
declarer name SENSOR_DEVICE_ATTR_WO;
identifier d.x,expected.x_store,expected.func;
expression e;
@@
- SENSOR_DEVICE_ATTR(x, \(0200\|S_IWUSR\), NULL, x_store, e);
+ SENSOR_DEVICE_ATTR_WO(x, func, e);
@@
declarer name SENSOR_DEVICE_ATTR_RW;
identifier d.x,expected.x_show,expected.x_store,expected.func;
expression e;
@@
- SENSOR_DEVICE_ATTR(x, \(0644\|S_IRUGO|S_IWUSR\|S_IWUSR|S_IRUGO\), x_show, x_store, e);
+ SENSOR_DEVICE_ATTR_RW(x, func, e);
@@
declarer name SENSOR_DEVICE_ATTR_2_RO;
identifier d.x,expected.x_show,expected.func;
expression e1,e2;
@@
- SENSOR_DEVICE_ATTR_2(x, \(0444\|S_IRUGO\), x_show, NULL, e1, e2);
+ SENSOR_DEVICE_ATTR_2_RO(x, func, e1, e2);
@@
declarer name SENSOR_DEVICE_ATTR_2_WO;
identifier d.x,expected.x_store,expected.func;
expression e1,e2;
@@
- SENSOR_DEVICE_ATTR_2(x, \(0200\|S_IWUSR\), NULL, x_store, e1, e2);
+ SENSOR_DEVICE_ATTR_2_WO(x, func, e1, e2);
@@
declarer name SENSOR_DEVICE_ATTR_2_RW;
identifier d.x,expected.x_show,expected.x_store,expected.func;
expression e1, e2;
@@
- SENSOR_DEVICE_ATTR_2(x, \(0644\|S_IRUGO|S_IWUSR\|S_IWUSR|S_IRUGO\), x_show, x_store, e1, e2);
+ SENSOR_DEVICE_ATTR_2_RW(x, func, e1, e2);
// -------------------------------------------------------------------------
// Other calls
@o@
declarer name SENSOR_DEVICE_ATTR,SENSOR_DEVICE_ATTR_2;
identifier d.x,show,store;
expression list es;
@@
(
SENSOR_DEVICE_ATTR(x,\(0444\|S_IRUGO\|0200\|S_IWUSR\|0644\|S_IRUGO|S_IWUSR\|S_IWUSR|S_IRUGO\),show,store,es);
|
SENSOR_DEVICE_ATTR_2(x,\(0444\|S_IRUGO\|0200\|S_IWUSR\|0644\|S_IRUGO|S_IWUSR\|S_IWUSR|S_IRUGO\),show,store,es);
)
// rename functions
@show1@
identifier o.show,expected.x_show;
parameter list ps;
@@
static
- show(ps)
+ x_show(ps)
{ ... }
@depends on show1@
identifier o.show,expected.x_show;
expression list es;
@@
- show(es)
+ x_show(es)
@depends on show1@
identifier o.show,expected.x_show;
@@
- show
+ x_show
@store1@
identifier o.store,expected.x_store;
parameter list ps;
@@
static
- store(ps)
+ x_store(ps)
{ ... }
@depends on store1@
identifier o.store,expected.x_store;
expression list es;
@@
- store(es)
+ x_store(es)
@depends on store1@
identifier o.store,expected.x_store;
@@
- store
+ x_store
// try again
@@
declarer name SENSOR_DEVICE_ATTR_RO;
identifier d.x,expected.x_show,expected.func;
expression e;
@@
- SENSOR_DEVICE_ATTR(x, \(0444\|S_IRUGO\), x_show, NULL, e);
+ SENSOR_DEVICE_ATTR_RO(x, func, e);
@@
declarer name SENSOR_DEVICE_ATTR_WO;
identifier d.x,expected.x_store,expected.func;
expression e;
@@
- SENSOR_DEVICE_ATTR(x, \(0200\|S_IWUSR\), NULL, x_store, e);
+ SENSOR_DEVICE_ATTR_WO(x, func, e);
@@
declarer name SENSOR_DEVICE_ATTR_RW;
identifier d.x,expected.x_show,expected.x_store,expected.func;
expression e;
@@
- SENSOR_DEVICE_ATTR(x, \(0644\|S_IRUGO|S_IWUSR\|S_IWUSR|S_IRUGO\), x_show, x_store, e);
+ SENSOR_DEVICE_ATTR_RW(x, func, e);
@@
declarer name SENSOR_DEVICE_ATTR_2_RO;
identifier d.x,expected.x_show,expected.func;
expression e1,e2;
@@
- SENSOR_DEVICE_ATTR_2(x, \(0444\|S_IRUGO\), x_show, NULL, e1, e2);
+ SENSOR_DEVICE_ATTR_2_RO(x, func, e1, e2);
@@
declarer name SENSOR_DEVICE_ATTR_2_WO;
identifier d.x,expected.x_store,expected.func;
expression e1, e2;
@@
- SENSOR_DEVICE_ATTR_2(x, \(0200\|S_IWUSR\), NULL, x_store, e1, e2);
+ SENSOR_DEVICE_ATTR_2_WO(x, func, e1, e2);
@@
declarer name SENSOR_DEVICE_ATTR_2_RW;
identifier d.x,expected.x_show,expected.x_store,expected.func;
expression e1, e2;
@@
- SENSOR_DEVICE_ATTR_2(x, \(0644\|S_IRUGO|S_IWUSR\|S_IWUSR|S_IRUGO\), x_show, x_store, e1, e2);
+ SENSOR_DEVICE_ATTR_2_RW(x, func, e1, e2);
next prev parent reply other threads:[~2016-12-23 23:10 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-21 3:28 [Cocci] Converting DEVICE_ATTR to DEVICE_ATTR_{RO, RW, WO} and changing function names at the same time Guenter Roeck
2016-12-21 7:30 ` Julia Lawall
2016-12-21 13:07 ` Julia Lawall
2016-12-21 14:05 ` Julia Lawall
2016-12-21 16:29 ` Guenter Roeck
2016-12-21 19:39 ` Julia Lawall
2016-12-21 21:44 ` Guenter Roeck
2016-12-22 12:29 ` Julia Lawall
2016-12-22 12:29 ` Converting DEVICE_ATTR to DEVICE_ATTR_{RO,RW,WO} " Julia Lawall
2016-12-22 15:33 ` [Cocci] Converting DEVICE_ATTR to DEVICE_ATTR_{RO, RW, WO} " Guenter Roeck
2016-12-22 15:33 ` Converting DEVICE_ATTR to DEVICE_ATTR_{RO,RW,WO} " Guenter Roeck
2016-12-22 15:45 ` [Cocci] Converting DEVICE_ATTR to DEVICE_ATTR_{RO, RW, WO} " Julia Lawall
2016-12-22 15:45 ` Converting DEVICE_ATTR to DEVICE_ATTR_{RO,RW,WO} " Julia Lawall
2016-12-22 17:33 ` [Cocci] Converting DEVICE_ATTR to DEVICE_ATTR_{RO, RW, WO} " Greg KH
2016-12-22 17:33 ` Converting DEVICE_ATTR to DEVICE_ATTR_{RO,RW,WO} " Greg KH
2016-12-22 18:19 ` [Cocci] Converting DEVICE_ATTR to DEVICE_ATTR_{RO, RW, WO} " Guenter Roeck
2016-12-22 18:19 ` Converting DEVICE_ATTR to DEVICE_ATTR_{RO,RW,WO} " Guenter Roeck
2016-12-23 15:54 ` [Cocci] Converting DEVICE_ATTR to DEVICE_ATTR_{RO, RW, WO} " Julia Lawall
2016-12-23 15:54 ` Converting DEVICE_ATTR to DEVICE_ATTR_{RO,RW,WO} " Julia Lawall
2016-12-23 23:10 ` Guenter Roeck [this message]
2016-12-23 23:10 ` Guenter Roeck
2016-12-24 6:05 ` [Cocci] Converting DEVICE_ATTR to DEVICE_ATTR_{RO, RW, WO} " Julia Lawall
2016-12-24 6:05 ` Converting DEVICE_ATTR to DEVICE_ATTR_{RO,RW,WO} " Julia Lawall
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=20161223231019.GA25609@roeck-us.net \
--to=linux@roeck-us.net \
--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.