Skip to content

Commit bb0bfbc

Browse files
panglesdjonludlam
authored andcommitted
Add exception to [uid_to_loc] table
Signed-off-by: Paul-Elliot <[email protected]>
1 parent 2ae6558 commit bb0bfbc

File tree

5 files changed

+53
-42
lines changed

5 files changed

+53
-42
lines changed

src/loader/ident_env.cppo.ml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ type item = [
6262
| `Value of Ident.t * bool * Warnings.loc option
6363
| `Class of Ident.t * Ident.t * Ident.t * Ident.t option * bool * Warnings.loc option
6464
| `ClassType of Ident.t * Ident.t * Ident.t option * bool * Warnings.loc option
65+
| `Exception of Ident.t * Warnings.loc option
66+
(* Exceptions are never hidden, but we need to add it to the [loc_to_ident]
67+
table. *)
6568
]
6669

6770
type items =
@@ -305,6 +308,12 @@ let rec extract_structure_tree_items : bool -> Typedtree.structure_item list ->
305308
List.map (fun decl -> `Type (decl.typ_id, hide_item, Some str_loc))
306309
decls @ extract_structure_tree_items hide_item rest
307310

311+
#if OCAML_VERSION < (4,14,0)
312+
| { str_desc = Tstr_exception _; _ } :: rest -> extract_structure_tree_items hide_item rest
313+
#else
314+
| { str_desc = Tstr_exception { tyexn_constructor; tyexn_loc = _; _ }; _ } :: rest ->
315+
`Exception (tyexn_constructor.ext_id, Some tyexn_constructor.ext_loc) :: extract_structure_tree_items hide_item rest
316+
#endif
308317

309318
#if OCAML_VERSION < (4,3,0)
310319
| { str_desc = Tstr_value (_, vbs ); _} :: rest ->
@@ -379,8 +388,7 @@ let rec extract_structure_tree_items : bool -> Typedtree.structure_item list ->
379388
| { str_desc = Tstr_primitive {val_id; _}; str_loc; _ } :: rest ->
380389
[`Value (val_id, false, Some str_loc)] @ extract_structure_tree_items hide_item rest
381390
| { str_desc = Tstr_eval _; _} :: rest
382-
| { str_desc = Tstr_typext _; _} :: rest
383-
| {str_desc = Tstr_exception _; _ } :: rest -> extract_structure_tree_items hide_item rest
391+
| { str_desc = Tstr_typext _; _} :: rest -> extract_structure_tree_items hide_item rest
384392
| [] -> []
385393

386394

@@ -391,6 +399,7 @@ let flatten_extracted : items list -> item list = fun items ->
391399
| `ModuleType _
392400
| `Value _
393401
| `Class _
402+
| `Exception _
394403
| `ClassType _ as x -> [x]
395404
| `Include xs -> xs) items |> List.flatten
396405

@@ -428,6 +437,12 @@ let env_of_items : Id.Signature.t -> item list -> t -> t = fun parent items env
428437
(match loc with | Some l -> LocHashtbl.add env.loc_to_ident l (identifier :> Id.any) | _ -> ());
429438
inner rest { env with types; hidden }
430439

440+
| `Exception (t, loc) :: rest ->
441+
let name = Ident.name t in
442+
let identifier = Mk.exception_(parent, ExceptionName.make_std name) in
443+
(match loc with | Some l -> LocHashtbl.add env.loc_to_ident l (identifier :> Id.any) | _ -> ());
444+
inner rest env
445+
431446
| `Value (t, is_hidden_item, loc) :: rest ->
432447
let name = Ident.name t in
433448
let is_hidden = is_hidden_item || value_name_exists name rest in

src/loader/ident_env.cppo.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type item =
2525
| `Value of Ident.t * bool * Warnings.loc option
2626
| `Class of
2727
Ident.t * Ident.t * Ident.t * Ident.t option * bool * Warnings.loc option
28+
| `Exception of Ident.t * Warnings.loc option
2829
| `ClassType of
2930
Ident.t * Ident.t * Ident.t option * bool * Warnings.loc option ]
3031

test/sources/lookup_def.t/run.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Show the locations:
2020
[{"`Value":[{"`Module":[{"`Module":[{"`Root":["None","A"]},"N"]},"T"]},"x"]},{"Some":{"`SourceLocation":[{"`SourcePage":[{"`Page":[{"Some":{"`Page":["None","root"]}},"source"]},"a.ml"]},"def_3"]}}]
2121
[{"`Type":[{"`Root":["None","A"]},"t"]},{"Some":{"`SourceLocation":[{"`SourcePage":[{"`Page":[{"Some":{"`Page":["None","root"]}},"source"]},"a.ml"]},"type-t"]}}]
2222
[{"`Value":[{"`Root":["None","A"]},"a"]},{"Some":{"`SourceLocation":[{"`SourcePage":[{"`Page":[{"Some":{"`Page":["None","root"]}},"source"]},"a.ml"]},"value-a"]}}]
23-
[{"`Exception":[{"`Root":["None","A"]},"Exn"]},{"Some":{"`SourceLocation":[{"`SourcePage":[{"`Page":[{"Some":{"`Page":["None","root"]}},"source"]},"a.ml"]},"def_9"]}}]
23+
[{"`Exception":[{"`Root":["None","A"]},"Exn"]},{"Some":{"`SourceLocation":[{"`SourcePage":[{"`Page":[{"Some":{"`Page":["None","root"]}},"source"]},"a.ml"]},"exception-Exn"]}}]
2424
[{"`Type":[{"`Root":["None","A"]},"ext"]},{"Some":{"`SourceLocation":[{"`SourcePage":[{"`Page":[{"Some":{"`Page":["None","root"]}},"source"]},"a.ml"]},"type-ext"]}}]
2525
[{"`Extension":[{"`Root":["None","A"]},"Ext"]},{"Some":{"`SourceLocation":[{"`SourcePage":[{"`Page":[{"Some":{"`Page":["None","root"]}},"source"]},"a.ml"]},"def_11"]}}]
2626
[{"`Class":[{"`Root":["None","A"]},"cls"]},{"Some":{"`SourceLocation":[{"`SourcePage":[{"`Page":[{"Some":{"`Page":["None","root"]}},"source"]},"a.ml"]},"class-cls"]}}]

test/sources/source.t/a.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ exception Exn
1818
class cls = object end
1919
class cls' = cls
2020
class type ct = object end
21+
22+
23+
let x _ = raise Exn

test/sources/source.t/run.t

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ Files containing some values:
2121
class cls = object end
2222
class cls' = cls
2323
class type ct = object end
24+
25+
26+
let x _ = raise Exn
2427

2528
Source pages require a parent:
2629

@@ -47,7 +50,12 @@ Now, compile the pages with the --source option:
4750

4851
$ odoc compile -I . --source-name a.ml --source-parent-file src-source.odoc a.cmt
4952
$ odoc link -I . a.odoc
53+
$ odoc link -I . page-root.odoc
54+
$ odoc link -I . src-source.odoc
55+
$ odoc html-generate --indent -o html src-source.odocl
56+
$ odoc html-generate --indent -o html page-root.odocl
5057
$ odoc html-generate --source a.ml --indent -o html a.odocl
58+
$ odoc support-files -o html
5159

5260
Source links generated in the documentation:
5361

@@ -59,10 +67,6 @@ Source links generated in the documentation:
5967
<div class="spec type anchored" id="type-t">
6068
<a href="#type-t" class="anchor"></a>
6169
<a href="../root/source/a.ml.html#type-t" class="source_link">Source</a>
62-
--
63-
<div class="spec value anchored" id="val-x">
64-
<a href="#val-x" class="anchor"></a>
65-
<a href="../root/source/a.ml.html#value-x" class="source_link">Source
6670
--
6771
<div class="spec value anchored" id="val-y">
6872
<a href="#val-y" class="anchor"></a>
@@ -98,7 +102,7 @@ Source links generated in the documentation:
98102
--
99103
<div class="spec exception anchored" id="exception-Exn">
100104
<a href="#exception-Exn" class="anchor"></a>
101-
<a href="../root/source/a.ml.html#def_11" class="source_link">Source</a>
105+
<a href="../root/source/a.ml.html#exception-Exn" class="source_link">
102106
--
103107
<div class="spec class anchored" id="class-cls">
104108
<a href="#class-cls" class="anchor"></a>
@@ -111,6 +115,10 @@ Source links generated in the documentation:
111115
<div class="spec class-type anchored" id="class-type-ct">
112116
<a href="#class-type-ct" class="anchor"></a>
113117
<a href="../root/source/a.ml.html#class_type-ct" class="source_link">
118+
--
119+
<div class="spec value anchored" id="val-x">
120+
<a href="#val-x" class="anchor"></a>
121+
<a href="../root/source/a.ml.html#value-x" class="source_link">Source
114122

115123
Ids generated in the source code:
116124

@@ -135,42 +143,26 @@ Ids generated in the source code:
135143
id="L18"
136144
id="L19"
137145
id="L20"
146+
id="L21"
147+
id="L22"
148+
id="L23"
138149
id="type-t"
139-
id="value-x"
150+
id="value-{x}2"
140151
id="value-y"
141152
id="value-z"
142153
id="local_a_47"
143-
id="def-5"
144-
id="def-6"
145-
id="def-7"
146-
id="def-8"
147-
id="def-9"
148-
id="def-10"
149-
id="def-11"
150-
id="def-12"
151-
id="def-14"
152-
id="def-15"
153-
154-
Another example, with a cmti file:
155-
156-
$ printf "b.ml\n" > source_tree.map
157-
$ odoc source-tree -I . --parent page-root -o src-source2.odoc source_tree.map
158-
159-
$ ocamlc -bin-annot b.mli
160-
$ ocamlc -bin-annot b.ml
161-
162-
When giving a .cmti with the source-name and source-parent option, the cmt file
163-
has to be given explicitely with the --cmt argument:
164-
165-
$ odoc compile -I . --source-name b.ml --source-parent-file src-source2.odoc b.cmti
166-
--cmt has to be passed when --source-parent-file and --source-name are passed and the input file is not a cmt file.
167-
[2]
168-
169-
$ odoc compile -I . --cmt b.cmt --source-name b.ml --source-parent-file src-source2.odoc b.cmti
170-
171-
The --cmt argument has to be compatible with a cmt file given as input:
154+
id="module-A"
155+
id="module-B"
156+
id="module_type-T"
157+
id="module_type-U"
158+
id="type-ext"
159+
id="def_10"
160+
id="exception-Exn"
161+
id="class-cls"
162+
id="class-cls'"
163+
id="class_type-ct"
164+
id="value-x"
172165

173-
$ cp b.cmt other.cmt
174-
$ odoc compile -I . --cmt other.cmt --source-name b.ml --source-parent-file src-source2.odoc b.cmt
175-
--cmt has to be equal to the input file when this one has .cmt extension.
176-
[2]
166+
$ firefox html/root/source/a.ml.html
167+
Gtk-Message: 12:16:26.688: Failed to load module "xapp-gtk3-module"
168+
Gtk-Message: 12:16:26.689: Not loading module "atk-bridge": The functionality is provided by GTK natively. Please try to not load it.

0 commit comments

Comments
 (0)