Commit 1dcc51cb authored by Sylvain Dailler's avatar Sylvain Dailler

core: switch glob from parser to core. Use nested hashtbl for glob

We want to use Glob outside of why3doc to associate locations to ident
(original locations for Find_ident_req).
We need to allow glob to be erased on a per file basis to:
- avoid consuming too much memory,
- avoid having obsolete location information still saved in glob
parent 0891d5c1
......@@ -18,14 +18,18 @@ let () = Debug.unset_flag flag (* make sure it is unset by default *)
type def_use = Def | Use
let glob = Hashtbl.create 5003
(* could be improved with nested hash tables *)
let glob = Hashtbl.create 16
(* Hash [file -> Hash [(line, column) -> ident]] *)
let key loc = let f, l, c, _ = Loc.get loc in f, l, c
let key loc = let f, l, c, _ = Loc.get loc in f, (l, c)
let add loc idk =
let k = key loc in
if not (Hashtbl.mem glob k) then Hashtbl.add glob k idk
let kf, k = key loc in
match (Hashtbl.find glob kf) with
| hash_f -> if not (Hashtbl.mem hash_f k) then Hashtbl.add hash_f k idk
| exception Not_found ->
let hash_f = Hashtbl.create 255 in
Hashtbl.add glob kf hash_f
let def ~kind id =
Opt.iter (fun loc -> add loc (id, Def, kind)) id.id_loc
......@@ -33,8 +37,15 @@ let def ~kind id =
let use ~kind loc id =
add loc (id, Use, kind)
let clear f =
match Hashtbl.find glob f with
| exception Not_found -> ()
| hash_f -> Hashtbl.clear hash_f
let find loc =
Hashtbl.find glob (key loc)
let (kf, k) = key loc in
let hash_f = Hashtbl.find glob kf in
Hashtbl.find hash_f k
(* FIXME allow several entries for the same loc, find returns all of them,
and why3doc inserts several anchors *)
......@@ -19,6 +19,9 @@ val def: kind:string -> ident -> unit
val use: kind:string -> Loc.position -> ident -> unit
(** [use loc id] registers that [id] is used at position [loc] *)
val clear: string -> unit
(** [clear file] clears the locations association for said [file] *)
type def_use = Def | Use
val find: Loc.position -> ident * def_use * string
......
......@@ -1581,6 +1581,7 @@ let type_module file env loc path (id,dl) =
file
let type_mlw_file env path filename mlw_file =
if Debug.test_flag Glob.flag then Glob.clear filename;
let file = Mstr.empty in
let loc = Loc.user_position filename 0 0 0 in
let file =
......
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