Coccinelle (software)


Coccinelle is an open-source utility for matching and transforming the source code of programs written in the C programming language.

Utility

Coccinelle was initially used to aid the evolution of the Linux kernel, providing support for changes to library application programming interfaces such as renaming a function, adding a function argument whose value is somehow context-dependent, and reorganizing a data structure.
It can also be used to find defective programming patterns in code without transforming them. Then coccinelles role is close to that of static analysis tools. Examples of such use are provided by the applications of the ' tool, which keeps track of warnings generated by coccinelle''.
Support for Coccinelle is provided by IRILL. Funding for the development has been provided by the Agence Nationale de la Recherche, the Danish Research Council for Technology and Production Sciences, and INRIA.
The source code of Coccinelle is licensed under the terms of version 2 of the GNU General Public License.

Semantic Patch Language

The source code to be matched or replaced is specified using a "semantic patch" syntax based on the patch syntax. The Semantic Patch Language pattern resembles a unified diff with C-like declarations.

Example


@@
expression lock, flags;
expression urb;
@@
spin_lock_irqsave;
<...
- usb_submit_urb
+ usb_submit_urb
...>
spin_unlock_irqrestore;
@@
expression urb;
@@
- usb_submit_urb
+ usb_submit_urb