Commit 41f05be4 authored by Andrei Paskevich's avatar Andrei Paskevich

in ident printer, look better for free names

My birthday gift for François.
parent 3930d3dd
...@@ -81,16 +81,19 @@ type ident_printer = { ...@@ -81,16 +81,19 @@ type ident_printer = {
blacklist : string list; blacklist : string list;
} }
let rec find_index indices name ind =
if Hashtbl.mem indices (name ^ string_of_int ind)
then find_index indices name (succ ind) else ind
let find_unique indices name = let find_unique indices name =
let specname ind = name ^ string_of_int ind in
let testname ind = Hashtbl.mem indices (specname ind) in
let rec advance ind =
if testname ind then advance (succ ind) else ind in
let rec retreat ind =
if ind = 1 || testname (pred ind) then ind else retreat (pred ind) in
let fetch ind =
if testname ind then advance (succ ind) else retreat ind in
let name = try let name = try
let ind = Hashtbl.find indices name + 1 in let ind = fetch (succ (Hashtbl.find indices name)) in
let ind = find_index indices name ind in
Hashtbl.replace indices name ind; Hashtbl.replace indices name ind;
name ^ string_of_int ind specname ind
with Not_found -> name in with Not_found -> name in
Hashtbl.replace indices name 0; Hashtbl.replace indices name 0;
name name
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment