Skip to content

Commit d711587

Browse files
committed
Refactor exported and stamps.
1 parent d1fe878 commit d711587

File tree

3 files changed

+47
-43
lines changed

3 files changed

+47
-43
lines changed

analysis/src/ProcessCmt.ml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ let addItem ~name ~extent ~stamp ~env ~item attributes exported stamps =
3939
Hashtbl.add stamps stamp declared;
4040
declared
4141

42-
let rec forTypeSignatureItem ~env ~(exported : SharedTypes.exported)
42+
let rec forTypeSignatureItem ~env ~(exported : SharedTypes.Exported.t)
4343
(item : Types.signature_item) =
4444
match item with
4545
| Sig_value (ident, {val_type; val_attributes; val_loc = loc}) ->
@@ -135,7 +135,7 @@ let rec forTypeSignatureItem ~env ~(exported : SharedTypes.exported)
135135
| _ -> []
136136

137137
and forTypeSignature env signature =
138-
let exported = initExported () in
138+
let exported = Exported.init () in
139139
let topLevel =
140140
List.fold_right
141141
(fun item items -> forTypeSignatureItem ~env ~exported item @ items)
@@ -156,7 +156,7 @@ let getModuleTypePath mod_desc =
156156
| Tmty_ident (path, _) | Tmty_alias (path, _) -> Some path
157157
| Tmty_signature _ | Tmty_functor _ | Tmty_with _ | Tmty_typeof _ -> None
158158

159-
let forTypeDeclaration ~env ~(exported : exported)
159+
let forTypeDeclaration ~env ~(exported : Exported.t)
160160
{
161161
typ_id;
162162
typ_loc;
@@ -215,7 +215,7 @@ let forTypeDeclaration ~env ~(exported : exported)
215215
in
216216
{declared with item = ModuleKind.Type (declared.item, recStatus)}
217217

218-
let rec forSignatureItem ~env ~(exported : exported)
218+
let rec forSignatureItem ~env ~(exported : Exported.t)
219219
(item : Typedtree.signature_item) =
220220
match item.sig_desc with
221221
| Tsig_value {val_id; val_loc; val_name = name; val_desc; val_attributes} ->
@@ -267,7 +267,7 @@ let rec forSignatureItem ~env ~(exported : exported)
267267
| _ -> []
268268

269269
let forSignature ~env items =
270-
let exported = initExported () in
270+
let exported = Exported.init () in
271271
let topLevel =
272272
items |> List.map (forSignatureItem ~env ~exported) |> List.flatten
273273
in
@@ -301,7 +301,7 @@ let rec getModulePath mod_desc =
301301
| Tmod_constraint (expr, _typ, _constraint, _coercion) ->
302302
getModulePath expr.mod_desc
303303

304-
let rec forStructureItem ~env ~(exported : exported) item =
304+
let rec forStructureItem ~env ~(exported : Exported.t) item =
305305
match item.str_desc with
306306
| Tstr_value (_isRec, bindings) ->
307307
let declareds = ref [] in
@@ -446,7 +446,7 @@ and forModule env mod_desc moduleName =
446446
Constraint (modKind, modTypeKind)
447447

448448
and forStructure ~env items =
449-
let exported = initExported () in
449+
let exported = Exported.init () in
450450
let topLevel =
451451
List.fold_right
452452
(fun item results -> forStructureItem ~env ~exported item @ results)
@@ -491,7 +491,7 @@ let forCmt ~moduleName ~uri ({cmt_modname; cmt_annots} : Cmt_format.cmt_infos) =
491491
let env =
492492
{
493493
scope = extent;
494-
stamps = initStamps ();
494+
stamps = Stamps.init ();
495495
modulePath = File (uri, moduleName);
496496
}
497497
in
@@ -510,7 +510,7 @@ let forCmt ~moduleName ~uri ({cmt_modname; cmt_annots} : Cmt_format.cmt_infos) =
510510
let env =
511511
{
512512
scope = sigItemsExtent items;
513-
stamps = initStamps ();
513+
stamps = Stamps.init ();
514514
modulePath = File (uri, moduleName);
515515
}
516516
in
@@ -520,7 +520,7 @@ let forCmt ~moduleName ~uri ({cmt_modname; cmt_annots} : Cmt_format.cmt_infos) =
520520
let env =
521521
{
522522
scope = impItemsExtent structure.str_items;
523-
stamps = initStamps ();
523+
stamps = Stamps.init ();
524524
modulePath = File (uri, moduleName);
525525
}
526526
in
@@ -530,7 +530,7 @@ let forCmt ~moduleName ~uri ({cmt_modname; cmt_annots} : Cmt_format.cmt_infos) =
530530
let env =
531531
{
532532
scope = sigItemsExtent signature.sig_items;
533-
stamps = initStamps ();
533+
stamps = Stamps.init ();
534534
modulePath = File (uri, moduleName);
535535
}
536536
in

analysis/src/References.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ let getLocItem ~full ~line ~col =
9090
| li :: _ -> Some li
9191
| _ -> None
9292

93-
let declaredForTip ~stamps stamp (tip : Tip.t) =
93+
let declaredForTip ~(stamps : Stamps.t) stamp (tip : Tip.t) =
9494
let open Infix in
9595
match tip with
9696
| Value ->
@@ -169,7 +169,7 @@ let definedForLoc ~file ~package locKind =
169169
maybeLog "Yes!! got it";
170170
Some res))))
171171

172-
let declaredForExportedTip ~(stamps : stamps) ~(exported : exported) name
172+
let declaredForExportedTip ~(stamps : Stamps.t) ~(exported : Exported.t) name
173173
(tip : Tip.t) =
174174
let open Infix in
175175
match tip with

analysis/src/SharedTypes.ml

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,20 @@ type 't stampMap = (int, 't) Hashtbl.t
2828
type 't namedMap = (string, 't) Hashtbl.t
2929
type namedStampMap = int namedMap
3030

31-
type exported = {
32-
types : namedStampMap;
33-
values : namedStampMap;
34-
modules : namedStampMap;
35-
}
31+
module Exported = struct
32+
type t = {
33+
types : namedStampMap;
34+
values : namedStampMap;
35+
modules : namedStampMap;
36+
}
37+
38+
let init () =
39+
{
40+
types = Hashtbl.create 10;
41+
values = Hashtbl.create 10;
42+
modules = Hashtbl.create 10;
43+
}
44+
end
3645

3746
type 't declared = {
3847
name : string Location.loc;
@@ -54,7 +63,7 @@ module ModuleKind = struct
5463

5564
and contents = {
5665
docstring : string list;
57-
exported : exported;
66+
exported : Exported.t;
5867
topLevel : moduleItem declared list;
5968
}
6069

@@ -80,49 +89,44 @@ module Kind = struct
8089
| Value _ -> 12
8190
end
8291

83-
let initExported () =
84-
{
85-
types = Hashtbl.create 10;
86-
values = Hashtbl.create 10;
87-
modules = Hashtbl.create 10;
92+
module Stamps = struct
93+
type t = {
94+
types : Type.t declared stampMap;
95+
values : Types.type_expr declared stampMap;
96+
modules : ModuleKind.t declared stampMap;
97+
constructors : constructor declared stampMap;
8898
}
8999

90-
type stamps = {
91-
types : Type.t declared stampMap;
92-
values : Types.type_expr declared stampMap;
93-
modules : ModuleKind.t declared stampMap;
94-
constructors : constructor declared stampMap;
95-
}
96-
97-
let initStamps () =
98-
{
99-
types = Hashtbl.create 10;
100-
values = Hashtbl.create 10;
101-
modules = Hashtbl.create 10;
102-
constructors = Hashtbl.create 10;
103-
}
100+
let init () =
101+
{
102+
types = Hashtbl.create 10;
103+
values = Hashtbl.create 10;
104+
modules = Hashtbl.create 10;
105+
constructors = Hashtbl.create 10;
106+
}
107+
end
104108

105-
type env = {stamps : stamps; modulePath : visibilityPath; scope : Location.t}
109+
type env = {stamps : Stamps.t; modulePath : visibilityPath; scope : Location.t}
106110

107111
module File = struct
108112
type t = {
109113
uri : Uri2.t;
110-
stamps : stamps;
114+
stamps : Stamps.t;
111115
moduleName : string;
112116
contents : ModuleKind.contents;
113117
}
114118

115119
let create moduleName uri =
116120
{
117121
uri;
118-
stamps = initStamps ();
122+
stamps = Stamps.init ();
119123
moduleName;
120-
contents = {docstring = []; exported = initExported (); topLevel = []};
124+
contents = {docstring = []; exported = Exported.init (); topLevel = []};
121125
}
122126
end
123127

124128
module QueryEnv = struct
125-
type t = {file : File.t; exported : exported}
129+
type t = {file : File.t; exported : Exported.t}
126130

127131
let fromFile file = {file; exported = file.contents.exported}
128132
end

0 commit comments

Comments
 (0)