| 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 |
(* Global variables, common string functions, and helpers. *) |
| 8 |
|
| 9 |
(* ------------------------------------------------------------------------- *) |
| 10 |
(* GLOBAL VARIABLES *) |
| 11 |
|
| 12 |
(* global variables are readonly outside initialisation *) |
| 13 |
val init : |
| 14 |
rule_name:string -> (* default rule name for nameless rules *) |
| 15 |
pos_name:string -> (* default position name for generated positions *) |
| 16 |
error_msg:string -> (* default error message for org and report mode *) |
| 17 |
char_limit:int -> (* page width limit for generated script *) |
| 18 |
unit |
| 19 |
|
| 20 |
(* default position name *) |
| 21 |
val get_pos_name : unit -> string |
| 22 |
|
| 23 |
(* default error message *) |
| 24 |
val get_default_message : unit -> string |
| 25 |
|
| 26 |
(* use input rulename to make a name for its context counterpart. *) |
| 27 |
val get_context_name : context_mode:bool -> string -> string |
| 28 |
|
| 29 |
(* use input rulename to make a name for its disjunction counterpart. *) |
| 30 |
val get_disj_name : string -> string |
| 31 |
|
| 32 |
(* use input rulename to make a name for its org counterpart. *) |
| 33 |
val get_org_name : string -> string |
| 34 |
|
| 35 |
(* use input rulename to make a name for its report counterpart. *) |
| 36 |
val get_report_name : string -> string |
| 37 |
|
| 38 |
|
| 39 |
(* ------------------------------------------------------------------------- *) |
| 40 |
(* DEPENDENCY HELPERS (HARDCODED) *) |
| 41 |
|
| 42 |
(* takes existing virtual rulenames, checks them, and returns the standard |
| 43 |
* ones: (patch), context, org, and report. |
| 44 |
*) |
| 45 |
val key_virtuals : context_mode:bool -> string list -> string list |
| 46 |
|
| 47 |
(* takes rule dependencies and adds default patch dependency: |
| 48 |
* "<existing dependency> && patch && !context && !org && !report" |
| 49 |
*) |
| 50 |
val add_patch_dependency : |
| 51 |
Ast_cocci.dependency -> Ast_cocci.dependency |
| 52 |
|
| 53 |
(* takes rule dependencies and adds default context dependency: |
| 54 |
* if context_mode: "<existing dependency && (context || org || report)" |
| 55 |
* else patch: "<existing dependency> && !patch && (context || org || report)" |
| 56 |
*) |
| 57 |
val add_context_dependency : |
| 58 |
context_mode:bool -> Ast_cocci.dependency -> Ast_cocci.dependency |
| 59 |
|
| 60 |
|
| 61 |
(* ------------------------------------------------------------------------- *) |
| 62 |
(* SANITY CHECKS AND RULE HELPERS *) |
| 63 |
|
| 64 |
(* specific for nameless rule that are automatically given the name |
| 65 |
* "rule starting on line <number>". extracts the number or fails if none. |
| 66 |
*) |
| 67 |
val extract_line : string -> int |
| 68 |
|
| 69 |
(* check rulename for validity. fails if invalid. |
| 70 |
* if strict, also fail on rulenames containing spaces. |
| 71 |
*) |
| 72 |
val check_rule : strict:bool -> string -> unit |
| 73 |
|
| 74 |
(* takes a rulename; if it is invalid, generates and returns a new rulename. |
| 75 |
* if valid, returns the input name. |
| 76 |
*) |
| 77 |
val generate_rule : string -> string |
| 78 |
|
| 79 |
|
| 80 |
(* ------------------------------------------------------------------------- *) |
| 81 |
(* STRING FUNCTIONS *) |
| 82 |
|
| 83 |
val starts_with_digit : string -> bool |
| 84 |
|
| 85 |
(* splits string into string list of length at most char_limit, delimitering |
| 86 |
* by space, and prefixing each string with prefix. *) |
| 87 |
val pre_split : ?prefix:string -> string -> string |
| 88 |
|
| 89 |
(* same as above, except for string options. If None, return "". *) |
| 90 |
val pre_split_opt : ?prefix:string -> string option -> string |
| 91 |
|
| 92 |
val concat_limit_width : string list -> string |