| 1 |
(* |
| 2 |
* This file is part of Coccinelle, licensed under the terms of the GPL v2. |
| 3 |
* See copyright.txt in the Coccinelle source code for more information. |
| 4 |
* The Coccinelle source code can be obtained at http://coccinelle.lip6.fr |
| 5 |
*) |
| 6 |
|
| 7 |
(* Detects if a rule contains */+/- or not. Such a rule is here referred to as |
| 8 |
* a patch rule (includes also * rules). |
| 9 |
* Does not distinguish between whether it has *, +, or -, just returns true |
| 10 |
* if it contains either. |
| 11 |
* |
| 12 |
* Also generates disjunction map, a map that maps the line number of the |
| 13 |
* beginning of the disjunction to an ordered list of bools, each indicating |
| 14 |
* whether their corresponding disjunction case contains */+/-. |
| 15 |
* |
| 16 |
* ---------------------------------------------------------------------------- |
| 17 |
* Example of disjunction map: |
| 18 |
* |
| 19 |
* @@ expression e; @@ |
| 20 |
* |
| 21 |
* ( |
| 22 |
* f(0) |
| 23 |
* | |
| 24 |
* f(1) |
| 25 |
* | |
| 26 |
* - f(e) |
| 27 |
* + g(e) |
| 28 |
* ) |
| 29 |
* |
| 30 |
* This rule contains both +/- so it would return true on a call to detect. |
| 31 |
* |
| 32 |
* It also has one disjunction on <line number of opening parenthesis> so the |
| 33 |
* disjunction map would have one entry with |
| 34 |
* key = <line number> |
| 35 |
* value = [false;false;true;]. |
| 36 |
* |
| 37 |
*) |
| 38 |
|
| 39 |
(* ------------------------------------------------------------------------- *) |
| 40 |
(* DETECTION FUNCTIONS *) |
| 41 |
|
| 42 |
type t |
| 43 |
|
| 44 |
(* constructs t from AST0 rule, uses both minus and plus tree. *) |
| 45 |
val make : Ast0_cocci.parsed_rule -> t |
| 46 |
|
| 47 |
(* constructs t from statement dots. |
| 48 |
* NOTE: minus and plus slices are stored in separate AST0s, so the statement |
| 49 |
* dots here will only cover either the */- portion of the tree OR the |
| 50 |
* + portion of the tree. Ie. a call to is_patch will only return true if the |
| 51 |
* statement dots contain EITHER */- or +, depending on which AST0 it is from. |
| 52 |
*) |
| 53 |
val make_statement_dots : Ast0_cocci.statement Ast0_cocci.dots -> t |
| 54 |
|
| 55 |
(* returns true if the rule contains stars, pluses, or minuses. *) |
| 56 |
val is_patch : t -> bool |
| 57 |
|
| 58 |
(* get the patch map for the disjunction starting on given line number. |
| 59 |
* fails if no disjunction found on that line. |
| 60 |
*) |
| 61 |
val get_disj_patch : int -> t -> bool list |
| 62 |
|
| 63 |
(* returns only the rules that contained */+/- along with their disjunction |
| 64 |
* maps. Preserves order. |
| 65 |
*) |
| 66 |
val filter_patch_rules : |
| 67 |
Ast0_cocci.parsed_rule list -> |
| 68 |
(Ast0_cocci.parsed_rule * t) list |