Here is another form of variable definition in C:
static DEFINE_PCI_DEVICE_TABLE(alx_pci_tbl) = {
ALX_ETHER_DEVICE(ALX_DEV_ID_AR8131),
ALX_ETHER_DEVICE(ALX_DEV_ID_AR8132),
{0,}
};
How can I convert it to :
static struct alx_vendor_info alx_pci_tbl[] = {
ALX_ETHER_DEVICE(ALX_DEV_ID_AR8131),
ALX_ETHER_DEVICE(ALX_DEV_ID_AR8132),
{0,}
};
I've tried the following code, but it does not work as I expected:
@@
declarer DEFINE_PCI_DEVICE_TABLE;
identifier aaa;
@@
- DEFINE_PCI_DEVICE_TABLE(aaa)
+ struct alx_vendor_info aaa[]
= ...;
--------------------------------------------------------------------------------
From: Julia Lawall
Sent: Tuesday, June 12, 2012 5:39 PM
To: yafo lee
Cc: Michael Stefaniuc ; [email protected]
Subject: Re: [Cocci] How can I replace a structure name in a C file
On Tue, 12 Jun 2012, yafo lee wrote:
thanks Julia, after removing "declarer name DEVMETHOD;", it works.
Now I write 3 rules to remove the "MODULE" relative macros.
@@
declarer name MODULE_AUTHOR;
expression e;
@@
- MODULE_AUTHOR(e);
@@
declarer name MODULE_DESCRIPTION;
expression e;
@@
- MODULE_DESCRIPTION(e);
@@
declarer name MODULE_LICENSE;
expression e;
@@
- MODULE_LICENSE(e);
Is there any possobility that I can combile these rules into a single
one?
Try
(
- MODULE_AUTHOR(...);
|
- MODULE_DESCRIPTION(...);
|
- MODULE_LICENSE(...)
)
The ... is on purpose. You don't need to declare a metavariable if you
aren't going to use the value for anything. Of course, it is OK to do so.
julia
Thanks
--------------------------------------------------------------------------------
From: Julia Lawall
Sent: Saturday, June 09, 2012 3:58 PM
To: yafo lee
Cc: Michael Stefaniuc ; [email protected]
Subject: Re: [Cocci] How can I replace a structure name in a C file
You can make just one file with two rules.
You should be able to make a pattern that has the form of the entire
initialization that changes the fields as you like. That is, after the
rules you have now, make a new rule that is like the following:
@@
identifier abc,i;
expression e;
fresh identifier newi = "device_" # i;
declarer name DEVMETHOD;
@@
device_method_t abc[]
= { ...,
- .i = e,
+ DEVMETHOD(newi, e),
...};
I'm not able to test this now, so there nay be some problems eg with the
fresh identifier syntax. Maybe there are some examples in teh demos
directory.
julia
On Sat, 9 Jun 2012, yafo lee
wrote:
Hi guys,
Thanks for your advises.
I write 2 cocci files to make this convert happened.
c1.cocci:
@@
typedef device_method_t;
@convert type@
- struct pci_driver
+ device_method_t
c2.cocci:
@convert name@
identifier abc;
@@
- device_method_t abc
+ device_method_t abc[]
= ...;
After spacthing these 2 coccis sequentially, I can get:
static device_method_t xxx[] = {
from:
static struct pci_driver xxx = {
Then comes the more complicated problem:
How can I convert the initialization part of the valuable definition
after
converting it's type?
the original code:
static device_method_t alx_driver[] = {
.suspend = alx_suspend,
.resume = alx_resume,
};
the code I expect:
static device_method_t alx_methods[] = {
/* Device interface */
DEVMETHOD(device_suspend, alx_suspend),
DEVMETHOD(device_resume, alx_resume),
{0, 0}
};
Can somebody give me some advise?
Thanks.
To julia:
I just start it now, no sure whether I can make it, maybe we can do it
together o(∩_∩)o
-----Original Message----- From: Julia Lawall
Sent: Friday, June 08, 2012 5:37 PM
To: Michael Stefaniuc
Cc: leeyafo ; [email protected]
Subject: Re: [Cocci] How can I replace a structure name in a C file
On Fri, 8 Jun 2012, Michael Stefaniuc wrote:
Hello,
On 06/08/2012 10:33 AM, leeyafo wrote:
Hello guys:
I'm new to Coccinelle, And now I wanna to develop a tool to
translate
Linux ethernet driver to freebsd.
the first problem is to convert an instance of "struct pci_driver" to
"device_method_t".
Can anybody give me some sample cocci code?
I have try the following code, but it does not work as expect.
@@
@@
- static struct pci_driver alx_driver = {
+ static device_method_t alx_methods[] = {
coccinelle is not line base like diff but knows C so you need to replace
full C entities.
@@
typedef device_method_t;
@@
- struct pci_driver alx_driver
+ device_method_t alx_methods[]
= ...;
If you would have changed just the type it would have been even simpler:
@@
typedef device_method_t;
@@
- struct pci_driver
+ device_method_t
I guess that if the introduction of an array is wanted, the more complex
rule will be needed.
Thanks,
julia
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)