|
|
Log in / Subscribe / Register

Evolutionary development of a semantic patch using Coccinelle

Evolutionary development of a semantic patch using Coccinelle

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

Grepping is possible, too. You can use '*' in the first column to just display a match. So, a general approach would be:

@@
// This metavariable has a defined type
struct foo *var;
@@
*   var->next


to post comments

Evolutionary development of a semantic patch using Coccinelle

Posted Mar 31, 2010 5:18 UTC (Wed) by neilbrown (subscriber, #359) [Link] (3 responses)

Thanks... that is quite close to what I wanted.

I really wanted to know if "(struct device_driver *)->groups" was ever set and the following pattern doesn't find any. It wouldn't find a static initialisation though..


struct device_driver *var;
@@
* var->groups

A similar search for struct device->groups does find a few hits.

Evolutionary development of a semantic patch using Coccinelle

Posted Mar 31, 2010 7:50 UTC (Wed) by wsa (guest, #52415) [Link] (2 responses)

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.

Evolutionary development of a semantic patch using Coccinelle

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

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 (guest, #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 © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds