Coccinelle (
French for ''ladybug'') is an
open-source utility for matching and
transforming the
source code
In computing, source code, or simply code, is any collection of code, with or without comments, written using a human-readable programming language, usually as plain text. The source code of a program is specially designed to facilitate the w ...
of programs written in the
C programming language
A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language.
The description of a programming ...
.
Utility
Coccinelle was initially used to aid the evolution of the
Linux kernel, providing support for changes to library
application programming interfaces (APIs) such as renaming a
function
Function or functionality may refer to:
Computing
* Function key, a type of key on computer keyboards
* Function model, a structured representation of processes in a system
* Function object or functor or functionoid, a concept of object-oriente ...
, 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 (i.e., pieces of code that are erroneous with high probability such as possible NULL pointer dereference) without transforming them. Then ''coccinelles role is close to that of
static analysis
Static analysis, static projection, or static scoring is a simplified analysis wherein the effect of an immediate change to a system is calculated without regard to the longer-term response of the system to that change. If the short-term effect i ...
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 ''Institut de recherche en informatiq ...
.
The source code of Coccinelle is licensed under the terms of version 2 of the
GNU General Public License
The GNU General Public License (GNU GPL or simply GPL) is a series of widely used free software licenses that guarantee end users the four freedoms to run, study, share, and modify the software. The license was the first copyleft for general ...
(GPL).
Semantic Patch Language
The source code to be matched or replaced is specified using a "semantic patch" syntax based on the
patch
Patch or Patches may refer to:
Arts, entertainment and media
* Patch Johnson, a fictional character from ''Days of Our Lives''
* Patch (''My Little Pony''), a toy
* "Patches" (Dickey Lee song), 1962
* "Patches" (Chairmen of the Board song) ...
syntax. The Semantic Patch Language (SmPL) pattern resembles a
unified diff
In computing, the utility diff is a data comparison tool that computes and displays the differences between the contents of files. Unlike edit distance notions used for other purposes, diff is line-oriented rather than character-oriented, but it ...
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 GPL license