我正在尝试寻找一些资源/教程来帮助我创建一个 coccinelle 脚本来查找结构声明并将它们从有序更改为无序。
在我们的代码库中,我们数百次使用了多个结构。有人在定义中间添加了一个成员,现在我需要更新数百个声明。默认值 0 很好,所以如果我将所有声明从有序切换为无序,一切都很好,并且为下一次更改提供更多 future 证据。
例如:
struct some_struct {
int blah;
int blah2;
}
// code is like this now.
struct some_struct ex1 = {
0,
1,
};
// Need script to change to this
struct some_struct ex2 = {
.blah1 = 0,
.blah2 = 1
}
谁能指出我正确的方向?
轻微测试:
@ok1@
identifier i1,i2;
position p;
@@
struct i1 i2@p = { \(0\|NULL\) };
@ok2@
identifier i1,i2,i3;
position p;
expression e;
@@
struct i1 i2@p = { ..., .i3 = e, ... };
@ok3@
identifier i1,i2;
position p;
@@
struct i1 i2@p = { ..., { ... }, ... };
@decl@
identifier i1,fld;
type T;
field list[n] fs;
@@
struct i1 {
fs
T fld;
...};
@bad@
identifier decl.i1,i2;
expression e;
position p != {ok1.p,ok2.p,ok3.p};
constant nm;
initializer list[decl.n] is;
position fix;
@@
struct i1 i2@p = { is,
(
nm(...)
|
e@fix
)
,...};
@@
identifier decl.i1,i2,decl.fld;
expression e;
position bad.p, bad.fix;
@@
struct i1 i2@p = { ...,
+ .fld = e
- e@fix
,...};
我是一名优秀的程序员,十分优秀!