| 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 |
(* Generates context rule body with inserted positions and stars. |
| 8 |
* |
| 9 |
* If context_mode (ie. the original rule is already * a context rule), just |
| 10 |
* add positions, but let the stars be. |
| 11 |
* If patch mode, add positions structurally (see position_generator.ml) and |
| 12 |
* add stars where the minus transformation are OR where the positions were |
| 13 |
* generated. |
| 14 |
* |
| 15 |
* ---------------------------------------------------------------------------- |
| 16 |
* Example: |
| 17 |
* Say we have two rule bodies like this (rule headers included for context): |
| 18 |
* |
| 19 |
* @minus@ expression e; @@ |
| 20 |
* |
| 21 |
* if (e |
| 22 |
* - != NULL |
| 23 |
* ) { |
| 24 |
* function1(e); |
| 25 |
* ... |
| 26 |
* e++; |
| 27 |
* function2(); |
| 28 |
* - function3(e); |
| 29 |
* + function4(e); |
| 30 |
* |
| 31 |
* @plus@ expression e; @@ |
| 32 |
* |
| 33 |
* if (e |
| 34 |
* + != NULL |
| 35 |
* ) { |
| 36 |
* function1(e); |
| 37 |
* ... |
| 38 |
* e++; |
| 39 |
* function2(); |
| 40 |
* + function3(e); |
| 41 |
* |
| 42 |
* They are both patch rules, but one doesn't contain minuses. |
| 43 |
* In the first case, stars are added where the minuses were. Positions are |
| 44 |
* added according to the same heuristics as the other example. |
| 45 |
* |
| 46 |
* @minus_context@ expression e; position p1,p2,p2; @@ |
| 47 |
* |
| 48 |
* if (e@p1 |
| 49 |
* * != NULL |
| 50 |
* ) { |
| 51 |
* function1@p2(e); |
| 52 |
* ... |
| 53 |
* e@p3++; |
| 54 |
* function2(); |
| 55 |
* * function3(e); |
| 56 |
* } |
| 57 |
* |
| 58 |
* In the second case, we don't know where the interesting parts are, so we add |
| 59 |
* positions on a best-guess basis (ie. the first in a sequence). The stars are |
| 60 |
* added on the same lines as the positions. |
| 61 |
* |
| 62 |
* @plus_context@ expression e; position p1,p2,p3; @@ |
| 63 |
* |
| 64 |
* * if (e@p1) |
| 65 |
* { |
| 66 |
* * function1@p2(e); |
| 67 |
* ... |
| 68 |
* * e@p3++; |
| 69 |
* function2(); |
| 70 |
* } |
| 71 |
* |
| 72 |
*) |
| 73 |
|
| 74 |
(* ------------------------------------------------------------------------- *) |
| 75 |
(* RULE BODY FUNCTIONS *) |
| 76 |
|
| 77 |
type t |
| 78 |
|
| 79 |
(* Arguments: |
| 80 |
* - context_mode indicates whether the rule already has stars in it. |
| 81 |
* - disjunction map, indicates */+/- slices in disjunctions. |
| 82 |
* - AST0 for the minus rule (we don't need the plus rule to generate *'s). |
| 83 |
* |
| 84 |
* Returns: |
| 85 |
* - List of added metapositions (as strings) |
| 86 |
* - The generated context rule, optional generated disjunction rule |
| 87 |
*) |
| 88 |
val generate : |
| 89 |
context_mode:bool -> |
| 90 |
disj_map:Detect_patch.t -> |
| 91 |
minus_rule:Ast0_cocci.rule -> |
| 92 |
string list * (t * t option) |
| 93 |
|
| 94 |
(* prints a context rule *) |
| 95 |
val print : out_channel -> t -> unit |