forked from FStarLang/karamel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Idents.ml
46 lines (37 loc) · 1019 Bytes
/
Idents.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(* Copyright (c) INRIA and Microsoft Corporation. All rights reserved. *)
(* Licensed under the Apache 2.0 License. *)
(** Manipulation of identifiers *)
module LidMap = Map.Make(struct
type t = string list * string
let compare = compare
end)
module LidSet = Set.Make(struct
type t = string list * string
let compare = compare
end)
let string_of_lident (idents, ident) =
if List.length idents > 0 then
String.concat "_" idents ^ "_" ^ ident
else
ident
let to_c_identifier name =
let is_valid = function
| 'a'..'z' | 'A'..'Z' | '0'..'9' | '_' -> true
| _ -> false
in
String.map (fun c -> if not (is_valid c) then '_' else c) name
let mk_fresh name test =
let name = to_c_identifier name in
if test name then
let i = ref 0 in
let mk () = name ^ string_of_int !i in
while test (mk ()) do
incr i
done;
mk ()
else
name
let fstar_name_of_mod =
String.map (function '.' -> '_' | x -> x)
let module_name lident =
String.concat "_" (fst lident)