Skip to content

Commit 2437530

Browse files
committed
Improve locate API
1 parent 4fe578a commit 2437530

5 files changed

Lines changed: 22 additions & 15 deletions

File tree

src/ecCommands.ml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ module Loader : sig
120120

121121
val addidir : ?namespace:namespace -> ?recursive:bool -> string -> loader -> unit
122122
val aslist : loader -> ((namespace option * string) * idx_t) list
123-
val locate : ?namespaces:namespace option list -> string ->
124-
loader -> (namespace option * string * kind) option
123+
val locate : ?namespaces:namespace option list ->
124+
?kinds:(EcLoader.kind list) -> string ->
125+
loader -> (namespace option * string * kind) option
125126

126127
val push : string -> loader -> unit
127128
val pop : loader -> string option
@@ -170,8 +171,8 @@ end = struct
170171
let aslist (ld : loader) =
171172
EcLoader.aslist ld.ld_core
172173

173-
let locate ?namespaces (path : string) (ld : loader) =
174-
EcLoader.locate ?namespaces path ld.ld_core
174+
let locate ?namespaces ?kinds (path : string) (ld : loader) =
175+
EcLoader.locate ?namespaces ?kinds path ld.ld_core
175176

176177
let push (p : string) (ld : loader) =
177178
ld.ld_stack <- norm p :: ld.ld_stack
@@ -522,7 +523,7 @@ and process_th_require1 ld scope (nm, (sysname, thname), io) =
522523
then [Loader.namespace ld; None]
523524
else [nm] in
524525

525-
match Loader.locate ~namespaces:nm sysname ld with
526+
match Loader.locate ~kinds:[`Ec; `EcA] ~namespaces:nm sysname ld with
526527
| None ->
527528
EcScope.hierror "cannot locate theory `%s'" sysname
528529

@@ -557,7 +558,10 @@ and process_th_require1 ld scope (nm, (sysname, thname), io) =
557558
(fun () -> Pragma.set i_pragma)
558559
in
559560

560-
let kind = match kind with `Ec -> `Concrete | `EcA -> `Abstract in
561+
let kind = match kind with
562+
| `Ec -> `Concrete | `EcA -> `Abstract
563+
| _ -> assert false
564+
in
561565

562566
let scope = EcScope.Theory.require scope (name, kind) loader in
563567
match io with

src/ecDoc.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ let c_filename ?(ext : string option) (nms : string list) =
2626
(* -------------------------------------------------------------------- *)
2727
let thkind_str (kind : EcLoader.kind) : string =
2828
match kind with
29-
| `Ec -> "Theory"
30-
| `EcA -> "Abstract Theory"
29+
| `Ec -> "Theory"
30+
| `EcA -> "Abstract Theory"
31+
| `Spec -> "Spec File" (* FIXME *)
3132

3233
(* -------------------------------------------------------------------- *)
3334
let itemkind_str_pl (ik : itemkind) : string =

src/ecEco.ml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,15 @@ let list_of_json (tx : Json.t -> 'a) (data : Json.t) : 'a list =
6464
(* -------------------------------------------------------------------- *)
6565
let kind_to_json (k : EcLoader.kind) =
6666
match k with
67-
| `Ec -> `String "ec"
68-
| `EcA -> `String "eca"
67+
| `Ec -> `String "ec"
68+
| `EcA -> `String "eca"
69+
| `Spec -> `String "spec"
6970

7071
let kind_of_json (data : Json.t) =
7172
match data with
72-
| `String "ec" -> `Ec
73-
| `String "eca" -> `EcA
73+
| `String "ec" -> `Ec
74+
| `String "eca" -> `EcA
75+
| `String "spec" -> `Spec
7476
| _ -> raise InvalidEco
7577

7678
(* -------------------------------------------------------------------- *)

src/ecLoader.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ let check_case idir name (dev, ino) =
114114
with Unix.Unix_error _ -> None
115115

116116
(* -------------------------------------------------------------------- *)
117-
let locate ?(namespaces = [None]) (name : string) (ecl : ecloader) =
117+
let locate ?(namespaces = [None]) ?(kinds = [`Ec; `EcA]) (name : string) (ecl : ecloader) =
118118
if not (EcRegexp.match_ (`S "^[a-zA-Z0-9_]+$") name) then
119119
None
120120
else
@@ -157,7 +157,7 @@ let locate ?(namespaces = [None]) (name : string) (ecl : ecloader) =
157157
match
158158
List.rev_pmap
159159
(fun kind -> List.opick (locate kind) ecl.ecl_idirs)
160-
[`Ec; `EcA; `Spec]
160+
kinds
161161
with
162162
| [x] -> Some x
163163
| _ -> None

src/ecLoader.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ val aslist : ecloader -> ((namespace option * string) * idx_t) list
1818
val dup : ecloader -> ecloader
1919
val forsys : ecloader -> ecloader
2020
val addidir : ?namespace:namespace -> ?recursive:bool -> string -> ecloader -> unit
21-
val locate : ?namespaces:(namespace option) list -> string -> ecloader -> (namespace option * string * kind) option
21+
val locate : ?namespaces:(namespace option) list -> ?kinds:(kind list) -> string -> ecloader -> (namespace option * string * kind) option

0 commit comments

Comments
 (0)