| 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 |
(* Transforms the original Coccinelle script and prints it (transformation is |
| 8 |
* done while printing). |
| 9 |
* |
| 10 |
* Prints preface, added virtual rules. |
| 11 |
* |
| 12 |
* Patch mode: |
| 13 |
* - add rule names to previously unnamed rules. |
| 14 |
* - add standard dependencies to existing patch rules. |
| 15 |
* |
| 16 |
* Context mode: |
| 17 |
* - skip all original context rules, since we now have the same rules but in |
| 18 |
* a generated (and therefore superior!) version. |
| 19 |
* |
| 20 |
* The transformation is done alongside the printing so if anything fails, |
| 21 |
* some of it might already have been printed. |
| 22 |
* |
| 23 |
* ---------------------------------------------------------------------------- |
| 24 |
* Example: |
| 25 |
* Input file (ie. the one in file_name) is: |
| 26 |
* |
| 27 |
* @im_a_rule@ |
| 28 |
* @@ |
| 29 |
* |
| 30 |
* function(); |
| 31 |
* |
| 32 |
* @depends on im_a_rule@ |
| 33 |
* @@ |
| 34 |
* |
| 35 |
* another_function( ... ); |
| 36 |
* + call_me(); |
| 37 |
* ... |
| 38 |
* |
| 39 |
* Then if we call it with e.g. |
| 40 |
* preface = { confidence = Moderate; description = "this is a script" }, |
| 41 |
* virtuals = ["patch";"context";"org";"report"], |
| 42 |
* rules = [(<im_a_rule>, None); (<rule starting on line 6>, Some "NAME")], |
| 43 |
* context_mode = false (because it has a +), |
| 44 |
* it would print the following to the out_channel: |
| 45 |
* |
| 46 |
* /// this is a script |
| 47 |
* /// |
| 48 |
* // Confidence: Moderate |
| 49 |
* |
| 50 |
* virtual patch |
| 51 |
* virtual context |
| 52 |
* virtual org |
| 53 |
* virtual report |
| 54 |
* |
| 55 |
* @im_a_rule@ |
| 56 |
* @@ |
| 57 |
* |
| 58 |
* function(); |
| 59 |
* |
| 60 |
* @NAME depends on im_a_rule && patch && !context && !org && !report@ |
| 61 |
* @@ |
| 62 |
* |
| 63 |
* another_function( ... ); |
| 64 |
* + call_me(); |
| 65 |
* ... |
| 66 |
*) |
| 67 |
|
| 68 |
(* ------------------------------------------------------------------------- *) |
| 69 |
(* TRANSFORMATION FUNCTIONS *) |
| 70 |
|
| 71 |
(* rules must be in the same order that they occurred in the original file *) |
| 72 |
val print : |
| 73 |
context_mode:bool -> |
| 74 |
file_name:string -> |
| 75 |
preface:string -> |
| 76 |
virtuals:string list -> |
| 77 |
ordered_rules:(Ast0_cocci.parsed_rule * string (* new name *)) list -> |
| 78 |
out_channel -> |
| 79 |
unit |