Skip to content

Commit e9853d5

Browse files
committedDec 15, 2022
Refactor env module path construction.
1 parent 07fbffa commit e9853d5

File tree

2 files changed

+12
-43
lines changed

2 files changed

+12
-43
lines changed
 

‎analysis/src/ProcessCmt.ml

+5-43
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,7 @@ let rec forSignatureItem ~env ~(exported : Exported.t)
249249
decl |> forTypeDeclaration ~env ~exported ~recStatus)
250250
| Tsig_module
251251
{md_id; md_attributes; md_loc; md_name = name; md_type = {mty_type}} ->
252-
let item =
253-
let env =
254-
{
255-
env with
256-
modulePath =
257-
ExportedModule
258-
{name = name.txt; modulePath = env.modulePath; isType = false};
259-
}
260-
in
261-
forTypeModule env mty_type
262-
in
252+
let item = forTypeModule (env |> Env.addModule ~name:name.txt) mty_type in
263253
let declared =
264254
addDeclared ~item ~name ~extent:md_loc ~stamp:(Ident.binding_time md_id)
265255
~env md_attributes
@@ -384,14 +374,7 @@ let rec forStructureItem ~env ~(exported : Exported.t) item =
384374
mtd_type = Some {mty_type = modType};
385375
mtd_loc;
386376
} ->
387-
let env =
388-
{
389-
env with
390-
modulePath =
391-
ExportedModule
392-
{name = name.txt; modulePath = env.modulePath; isType = true};
393-
}
394-
in
377+
let env = env |> Env.addModuleType ~name:name.txt in
395378
let modTypeItem = forTypeModule env modType in
396379
let declared =
397380
addDeclared ~item:modTypeItem ~name ~extent:mtd_loc
@@ -439,14 +422,7 @@ and forModule env mod_desc moduleName =
439422
match mod_desc with
440423
| Tmod_ident (path, _lident) -> Ident path
441424
| Tmod_structure structure ->
442-
let env =
443-
{
444-
env with
445-
modulePath =
446-
ExportedModule
447-
{name = moduleName; modulePath = env.modulePath; isType = false};
448-
}
449-
in
425+
let env = env |> Env.addModule ~name:moduleName in
450426
let contents = forStructure ~env structure.str_items in
451427
Structure contents
452428
| Tmod_functor (ident, argName, maybeType, resultExpr) ->
@@ -466,26 +442,12 @@ and forModule env mod_desc moduleName =
466442
| Tmod_apply (functor_, _arg, _coercion) ->
467443
forModule env functor_.mod_desc moduleName
468444
| Tmod_unpack (_expr, moduleType) ->
469-
let env =
470-
{
471-
env with
472-
modulePath =
473-
ExportedModule
474-
{name = moduleName; modulePath = env.modulePath; isType = false};
475-
}
476-
in
445+
let env = env |> Env.addModule ~name:moduleName in
477446
forTypeModule env moduleType
478447
| Tmod_constraint (expr, typ, _constraint, _coercion) ->
479448
(* TODO do this better I think *)
480449
let modKind = forModule env expr.mod_desc moduleName in
481-
let env =
482-
{
483-
env with
484-
modulePath =
485-
ExportedModule
486-
{name = moduleName; modulePath = env.modulePath; isType = false};
487-
}
488-
in
450+
let env = env |> Env.addModule ~name:moduleName in
489451
let modTypeKind = forTypeModule env typ in
490452
Constraint (modKind, modTypeKind)
491453

‎analysis/src/SharedTypes.ml

+7
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,13 @@ end
274274

275275
module Env = struct
276276
type t = {stamps: Stamps.t; modulePath: ModulePath.t}
277+
let addExportedModule ~name ~isType env =
278+
{
279+
env with
280+
modulePath = ExportedModule {name; modulePath = env.modulePath; isType};
281+
}
282+
let addModule ~name env = env |> addExportedModule ~name ~isType:false
283+
let addModuleType ~name env = env |> addExportedModule ~name ~isType:true
277284
end
278285

279286
type filePath = string

0 commit comments

Comments
 (0)
Please sign in to comment.