| 1 |
(* |
| 2 |
* This file is part of Coccinelle, lincensed 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 |
module Ast = Ast_cocci |
| 8 |
|
| 9 |
(* ------------------------------------------------------------------------- *) |
| 10 |
(* TOSTRING FUNCTIONS FOR AST_COCCI BASE TYPES *) |
| 11 |
|
| 12 |
(* takes a list of 'a and concatenates it using fn ('a -> string), |
| 13 |
* delimitering with between (string) |
| 14 |
*) |
| 15 |
let between_tostring between tostring_fn = |
| 16 |
let rec between_tostring' acc between fn = function |
| 17 |
| [] -> acc |
| 18 |
| [x] -> acc ^ (fn x) |
| 19 |
| x::xs -> between_tostring' (acc ^ (fn x) ^ between) between fn xs in |
| 20 |
between_tostring' "" between tostring_fn |
| 21 |
|
| 22 |
let meta_tostring (r, x) = x |
| 23 |
|
| 24 |
and sz2c = function |
| 25 |
Ast.IsChar -> "" |
| 26 |
| Ast.IsUchar -> "U" |
| 27 |
| Ast.Isuchar -> "u" |
| 28 |
| Ast.Isu8char -> "u8" |
| 29 |
| Ast.IsWchar -> "L" |
| 30 |
|
| 31 |
let constant_tostring = function |
| 32 |
| Ast.String(s,w) -> (sz2c w) ^ "\"" ^ s ^ "\"" |
| 33 |
| Ast.Char(s,w) -> (sz2c w) ^ "'" ^ s ^ "'" |
| 34 |
| Ast.Int(s) -> s |
| 35 |
| Ast.Float(s) -> s |
| 36 |
| Ast.DecimalConst(s,_,_) -> s |
| 37 |
|
| 38 |
let struct_union_tostring = Ast.string_of_structUnion |
| 39 |
|
| 40 |
let sign_tostring = function |
| 41 |
| Ast.Signed -> "signed" |
| 42 |
| Ast.Unsigned -> "unsigned" |
| 43 |
|
| 44 |
let const_vol_tostring = function |
| 45 |
| Ast.Const -> "const" |
| 46 |
| Ast.Volatile -> "volatile" |
| 47 |
|
| 48 |
let storage_tostring = function |
| 49 |
| Ast.Static -> "static" |
| 50 |
| Ast.Auto -> "auto" |
| 51 |
| Ast.Register -> "register" |
| 52 |
| Ast.Extern -> "extern" |
| 53 |
|
| 54 |
let inc_elem_tostring = function |
| 55 |
| Ast.IncPath s -> s |
| 56 |
| Ast.IncDots -> "..." |
| 57 |
|
| 58 |
let inc_file_tostring = function |
| 59 |
| Ast.Local(elems) -> |
| 60 |
"\"" ^ (between_tostring "/" inc_elem_tostring elems) ^ "\"" |
| 61 |
| Ast.NonLocal(elems) -> |
| 62 |
"<" ^ (between_tostring "/" inc_elem_tostring elems) ^ ">" |
| 63 |
| Ast.AnyInc -> "..." |
| 64 |
|
| 65 |
let fix_tostring = function |
| 66 |
| Ast.Dec -> "--" |
| 67 |
| Ast.Inc -> "++" |
| 68 |
|
| 69 |
let arith_tostring = Ast.string_of_arithOp |
| 70 |
|
| 71 |
let logic_tostring = Ast.string_of_logicalOp |
| 72 |
|
| 73 |
let unary_tostring = function |
| 74 |
| Ast.GetRef -> "&" |
| 75 |
| Ast.GetRefLabel -> "&&" |
| 76 |
| Ast.DeRef -> "*" |
| 77 |
| Ast.UnPlus -> "+" |
| 78 |
| Ast.UnMinus -> "-" |
| 79 |
| Ast.Tilde s -> s |
| 80 |
| Ast.Not s -> s |
| 81 |
|
| 82 |
let binary_tostring = Ast.string_of_binaryOp |
| 83 |
|
| 84 |
let assign_tostring = Ast.string_of_assignOp |
| 85 |
|
| 86 |
let type_tostring = Ast.string_of_baseType |
| 87 |
|
| 88 |
let whenmodifier_tostring = function |
| 89 |
| Ast.WhenAny -> "any" |
| 90 |
| Ast.WhenStrict -> "strict" |
| 91 |
| Ast.WhenForall -> "forall" |
| 92 |
| Ast.WhenExists -> "exists" |