---
name: "Coccilib"
section: "3cocci"
platform: "linux"
package: "coccinelle"
version: "1.3.0.deb-1+b2"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Coccilib"
---

# Coccilib(3cocci)

Library of functions for use with Coccinelle OCaml script code

## NAME

Coccilib - Library of functions for use with Coccinelle OCaml script code

## MODULE

Module   Coccilib

## DOCUMENTATION

Module **Coccilib**\
  : **sig end**

**===** **Positions** **===**

*type pos* = {\
  current\_element : **string** ;\
  current\_element\_line : **int** ;\
  current\_element\_col : **int** ;\
  current\_element\_line\_end : **int** ;\
  current\_element\_col\_end : **int** ;\
  file : **string** ;\
  line : **int** ;\
  col : **int** ;\
  line\_end : **int** ;\
  col\_end : **int** ;\
  }

A value of type **pos** describes a position in a source file. **current\_element** is the name of the function containing the matched position; **current\_element\_line** is the number of the line containing the first character of the function containing the matched position; **current\_element\_col** is the (0-based) column containing the first character of the function containing the matched position; **current\_element\_line\_end** is the number of the line containing the last character of the function containing the matched position; **current\_element\_col\_end** is the (0-based) column containing the last character of the function containing the matched position **file** is the name of the file containing the matched position; **line** is the number of the line containing the first character of the matched position; **col** is the (0-based) column containing the first character of the matched position; **line\_end** is the number of the line containing the last character of the matched position; **col\_end** is the (0-based) column containing the last character of the matched position.

**===** **Abstract Syntax Tree** **===**

*type param\_type*\
  \=\
  \| Pos **of** **pos list**\
  \| Str **of** **string**\
  \| Type **of** **Ast\_c.fullType**\
  \| Init **of** **Ast\_c.initialiser**\
  \| InitList **of** **Ast\_c.initialiser Ast\_c.wrap2 list**\
  \| Int **of** **int**\
  \| Param **of** **Ast\_c.parameterType**\
  \| ParamList **of** **Ast\_c.parameterType Ast\_c.wrap2 list**\
  \| Expr **of** **Ast\_c.expression**\
  \| ExprList **of** **Ast\_c.argument Ast\_c.wrap2 list**\
  \| Decl **of** **Ast\_c.declaration**\
  \| Field **of** **Ast\_c.field**\
  \| FieldList **of** **Ast\_c.field list**\
  \| Stmt **of** **Ast\_c.statement**

*val make\_ident* : **string -\> Ast\_c.metavar\_binding\_kind**

Make an identifier

*val make\_expr* : **string -\> Ast\_c.metavar\_binding\_kind**

Make an expression

*val make\_expr\_with\_env* : **string -\> string -\> Ast\_c.metavar\_binding\_kind**

Make an expression in a type environment.  The first argument is a string containing any C variable declarations needed to make the environment and the second argument is a string containing the expression.

*val make\_stmt* : **string -\> Ast\_c.metavar\_binding\_kind**

Make a single statement

*val make\_stmt\_in\_env* : **string -\> Ast\_c.metavar\_binding\_kind**

Make a single statement in a type environment.  The first argument is a string containing any C variable declarations needed to make the environment and the second argument is a string containing the statement.

*val make\_type* : **string -\> Ast\_c.metavar\_binding\_kind**

Make a type

*val make\_listlen* : **int -\> Ast\_c.metavar\_binding\_kind**

Make a list length, for parameter lists, expression lists, etc.

*val make\_full\_position* : **string -\> string -\> int -\> int -\> int -\> int -\> int -\> int -\> int -\> int -\> Ast\_c.metavar\_binding\_kind**

Make a position.  The arguments are the file name, the function or other toplevel element containing the position, the starting line of the containing element, the starting column of the containing element, the ending line of the containing element, the ending column of the containing element, the starting line of the created position, the starting column of the created position, the ending line of the created position, and the ending column of the created position.

start at 0.  The ending line is the one that contains the last character of what is to be matched.  The ending character is one past the last character of the thing to be matched.  The containing element position will be a default value.

*val make\_position* : **string -\> string -\> int -\> int -\> int -\> int -\> Ast\_c.metavar\_binding\_kind**

Make a position.  The arguments are the file name, the function or other toplevel element containing the position, the starting line, the starting column, the ending line, and the ending column.  Lines start at 1.  Columns start at 0.  The ending line is the one that contains the last character of what is to be matched.  The ending character is one past the last character of the thing to be matched.  The containing element position will be a default value.

**===** **Match management functions** **===**

*val include\_match* : **bool -\> unit**

If the argument is true, retain the environment with respect to which the ocaml script code is being executed for use in subsequent rules.  If the argument is false, discard this environment.  By default, the environment is retained.

*val exit* : **unit -\> unit**

If called, aborts the treatment of the current file.  All previous changes take effect.

*val dir* : **unit -\> string**

Returns the directory on which spatch was launched.

*val files* : **unit -\> string list**

Returns the list of files on which spatch is currently working.  The result is the empty list if spatch is not currently working on any file (eg, in an initialize or finalize rule).

*val cocci\_version* : **unit -\> string**

Returns a string indicating the current version.  Note that if Coccinelle has been modified since a release, the version number will be postfixed with "-dirty".

*val print\_main* : **?color:string -\> string -\> pos list -\> unit**

Print information about a main position using org mode.

*val print\_sec* : **?color:string -\> string -\> pos list -\> unit**

Print information about a single secondary position using org mode.

*val print\_secs* : **?color:string -\> string -\> pos list -\> unit**

Print information about a list of secondary positions using org mode.

## REFERENCES

Y. Padioleau, J.L. Lawall, R.R Hansen, G. Muller "Documenting and Automating Collateral Evolutions in Linux Device Driver" *EuroSys 2008,* Glasgow, Scotland (April 2008) pp. 247-260.

## AUTHOR

This manual page was written by Julia Lawall \<Julia.Lawall@lip6.fr\>.

## REPORTING BUGS

Send a mail to \<cocci@inria.fr\>

## COPYRIGHT

Copyright 2011, DIKU, University of Copenhagen and INRIA. Copyright 2012-2015, INRIA.
