gpt4 book ai didi

Coccinelle:将有序结构声明更改为无序

转载 作者:太空宇宙 更新时间:2023-11-04 00:03:56 24 4
gpt4 key购买 nike

我正在尝试寻找一些资源/教程来帮助我创建一个 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
,...};

关于Coccinelle:将有序结构声明更改为无序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31597573/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com