Coccinelle (
French for ''ladybug'') is an
open-source
Open source is source code that is made freely available for possible modification and redistribution. Products include permission to use and view the source code, design documents, or content of the product. The open source model is a decentrali ...
tool for matching and
transforming the
source code
In computing, source code, or simply code or source, is a plain text computer program written in a programming language. A programmer writes the human readable source code to control the behavior of a computer.
Since a computer, at base, only ...
of programs written in the
C programming language
A programming language is a system of notation for writing computer programs.
Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
.
Utility
Coccinelle was initially used to aid the evolution of the
Linux kernel
The Linux kernel is a Free and open-source software, free and open source Unix-like kernel (operating system), kernel that is used in many computer systems worldwide. The kernel was created by Linus Torvalds in 1991 and was soon adopted as the k ...
, providing support for changes to library
application programming interface
An application programming interface (API) is a connection between computers or between computer programs. It is a type of software Interface (computing), interface, offering a service to other pieces of software. A document or standard that des ...
s (APIs) such as renaming a
function, adding a function argument whose value is somehow context-dependent, and reorganizing a
data structure
In computer science, a data structure is a data organization and storage format that is usually chosen for Efficiency, efficient Data access, access to data. More precisely, a data structure is a collection of data values, the relationships amo ...
.
It can also be used to find defective programming patterns in code (i.e., pieces of code that are erroneous with high probability such as possible NULL pointer dereference) without transforming them. Therefore ''coccinelles role is close to that of
static analysis tools. Examples of such use are provided by the applications of the
herodotos' 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 (France), the Danish Research Council for Technology and Production Sciences, and
INRIA
The National Institute for Research in Digital Science and Technology (Inria) () is a French national research institution focusing on computer science and applied mathematics.
It was created under the name French Institute for Research in Comp ...
.
The source code of Coccinelle is licensed under the terms of version 2 of the
GNU General Public License
The GNU General Public Licenses (GNU GPL or simply GPL) are a series of widely used free software licenses, or ''copyleft'' licenses, that guarantee end users the freedom to run, study, share, or modify the software. The GPL was the first ...
(GPL).
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 (SmPL) pattern resembles a
unified diff with C-like declarations.
Example
@@
expression lock, flags;
expression urb;
@@
spin_lock_irqsave(lock, flags);
<...
- usb_submit_urb(urb)
+ usb_submit_urb(urb, GFP_ATOMIC)
...>
spin_unlock_irqrestore(lock, flags);
@@
expression urb;
@@
- usb_submit_urb(urb)
+ usb_submit_urb(urb, GFP_KERNEL)
References
External links
* {{GitHub, coccinelle/coccinelle, Source code repository
Official latest stable downloadCoccinellery: Semantic Patch Gallery
Code refactoring
Static program analysis tools
Software using the GNU General Public License