| 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 |
(* Generate context rule |
| 8 |
* |
| 9 |
* If context_mode (ie. the original rule is already * a context rule), just |
| 10 |
* add positions, but let the stars be. |
| 11 |
* |
| 12 |
* If patch mode, add positions. |
| 13 |
* - If rule has -, then put the *'s at the -'s place. |
| 14 |
* - If rule only has +, put the *'s where the added positions are. |
| 15 |
* |
| 16 |
* ---------------------------------------------------------------------------- |
| 17 |
* Example of generated context rule (see more in rule_body.mli): |
| 18 |
* Input rule is a "+" rule represented as an AST0. |
| 19 |
* |
| 20 |
* @some_rule@ |
| 21 |
* identifier i; |
| 22 |
* @@ |
| 23 |
* |
| 24 |
* int i = 2; |
| 25 |
* + call_me(i); |
| 26 |
* ... |
| 27 |
* |
| 28 |
* Then the output will be a "*" rule similar to the one below. |
| 29 |
* It is not returned as AST0 because the contents of the rule may require a |
| 30 |
* splitting into several rules. |
| 31 |
* |
| 32 |
* @some_rule_context depends on !patch && (context || org || report)@ |
| 33 |
* identifier i; |
| 34 |
* position p; |
| 35 |
* @@ |
| 36 |
* |
| 37 |
* * int i@p = 2; |
| 38 |
* ... |
| 39 |
*) |
| 40 |
|
| 41 |
(* ------------------------------------------------------------------------- *) |
| 42 |
type t |
| 43 |
|
| 44 |
(* generates a context rule from a */+/- rule. |
| 45 |
* Invariants: |
| 46 |
* - rule contains */+/-. |
| 47 |
* - new_name, if any, must be valid. no whitespace funny business |
| 48 |
* (however, it can be <default rule name><number> at this point). |
| 49 |
* |
| 50 |
* Arguments: |
| 51 |
* - context_mode: if true, input rule has *, else input rule has +/-. |
| 52 |
* - disj_map: disjunction map, indicates */+/- slices in disjunctions. |
| 53 |
* - new_name: new name if input rule is nameless, else same as name in rule. |
| 54 |
* - rule_names: list of names of the other */+/- rules in the full script. |
| 55 |
* - rule: the input rule, must be a */+/- rule. |
| 56 |
* |
| 57 |
* Returns: |
| 58 |
* - the generated context rule |
| 59 |
* - list of added metapositions (at least one, and inherited from the |
| 60 |
* generated rule for convenience). |
| 61 |
*) |
| 62 |
val generate : |
| 63 |
context_mode:bool -> |
| 64 |
disj_map:Detect_patch.t -> |
| 65 |
new_name:string -> |
| 66 |
rule_names:string list -> |
| 67 |
rule:Ast0_cocci.parsed_rule -> |
| 68 |
t * Meta_variable.t list |
| 69 |
|
| 70 |
(* prints the generated context rule to the specified out_channel. *) |
| 71 |
val print : out_channel -> t -> unit |