User: Password:
|
|
Subscribe / Log in / New account

Evolutionary development of a semantic patch using Coccinelle

Evolutionary development of a semantic patch using Coccinelle

Posted Mar 31, 2010 7:50 UTC (Wed) by wsa (subscriber, #52415)
In reply to: Evolutionary development of a semantic patch using Coccinelle by neilbrown
Parent article: Evolutionary development of a semantic patch using Coccinelle

Unleashing another feature (regexp), you could do this for static ones:

@@
// Match identifiers starting with "device" for "device_type", "device_driver"...
identifier S ~= "device.*";
identifier name;
expression E;
@@
        static struct S name = {
*               .groups = E,
        };
which matched just a few device_types here.


(Log in to post comments)

Evolutionary development of a semantic patch using Coccinelle

Posted Mar 31, 2010 12:34 UTC (Wed) by lawall (guest, #56234) [Link]

The following semantic patch:

@r@
struct device_driver var;
expression E;
@@
* var.groups = E;

Expands into essentially the following, via a user-configurable notion of "isomorphisms", which describe code patterns that are considered to be the same:

@@
struct device_driver var;
struct device_driver *_E1_1;
identifier _I_0;
@@

(
*var.groups = E;
|
*_E1_1->groups = E;
|
*struct device_driver _I_0 = {.groups = E,
};
)

This, however, doesn't match cases where the assignment is a subexpression of another expression. For that you could have to do:

@r@
struct device_driver var;
expression E;
@@
* var.groups = E

which would match both the . and the -> case, again via an isomorphism.

julia

Evolutionary development of a semantic patch using Coccinelle

Posted Apr 2, 2010 16:53 UTC (Fri) by giraffedata (subscriber, #1954) [Link]

Coccinelle doesn't seem to be all that semantic. It works on C syntax. A semantic matching rule would be something like "a statement that references the 'next' field of a 'device_driver' struct," as opposed to a rule that matches particular C syntax that happens to do that.


Copyright © 2017, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds