Skip to content

Commit c657167

Browse files
committed
refactor addReferece
1 parent 9f30b6b commit c657167

File tree

1 file changed

+22
-31
lines changed

1 file changed

+22
-31
lines changed

analysis/src/ProcessCmt.ml

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -517,42 +517,42 @@ let addLocItem extra loc locType =
517517
if not loc.Warnings.loc_ghost then
518518
extra.locItems <- {loc; locType} :: extra.locItems
519519

520+
let addReference ~extra stamp loc =
521+
Hashtbl.replace extra.internalReferences stamp
522+
(loc
523+
::
524+
(if Hashtbl.mem extra.internalReferences stamp then
525+
Hashtbl.find extra.internalReferences stamp
526+
else []))
527+
520528
let extraForFile ~(file : File.t) =
521529
let extra = initExtra () in
522-
let addReference stamp loc =
523-
Hashtbl.replace extra.internalReferences stamp
524-
(loc
525-
::
526-
(if Hashtbl.mem extra.internalReferences stamp then
527-
Hashtbl.find extra.internalReferences stamp
528-
else []))
529-
in
530530
file.stamps
531531
|> Stamps.iterModules (fun stamp (d : Module.t Declared.t) ->
532532
addLocItem extra d.name.loc (LModule (Definition (stamp, Module)));
533-
addReference stamp d.name.loc);
533+
addReference ~extra stamp d.name.loc);
534534
file.stamps
535535
|> Stamps.iterValues (fun stamp (d : Types.type_expr Declared.t) ->
536536
addLocItem extra d.name.loc
537537
(Typed (d.name.txt, d.item, Definition (stamp, Value)));
538-
addReference stamp d.name.loc);
538+
addReference ~extra stamp d.name.loc);
539539
file.stamps
540540
|> Stamps.iterTypes (fun stamp (d : Type.t Declared.t) ->
541541
addLocItem extra d.name.loc
542542
(TypeDefinition (d.name.txt, d.item.Type.decl, stamp));
543-
addReference stamp d.name.loc;
543+
addReference ~extra stamp d.name.loc;
544544
match d.item.Type.kind with
545545
| Record labels ->
546546
labels
547547
|> List.iter (fun {stamp; fname; typ} ->
548-
addReference stamp fname.loc;
548+
addReference ~extra stamp fname.loc;
549549
addLocItem extra fname.loc
550550
(Typed
551551
(d.name.txt, typ, Definition (d.stamp, Field fname.txt))))
552552
| Variant constructors ->
553553
constructors
554554
|> List.iter (fun {Constructor.stamp; cname} ->
555-
addReference stamp cname.loc;
555+
addReference ~extra stamp cname.loc;
556556
let t =
557557
{
558558
Types.id = 0;
@@ -627,15 +627,6 @@ let fromCompilerPath ~(env : QueryEnv.t) path =
627627
| Some (`Global (moduleName, fullPath)) -> `Global (moduleName, fullPath))
628628

629629
let getIterator (extra : extra) (file : File.t) =
630-
let addReference stamp loc =
631-
Hashtbl.replace extra.internalReferences stamp
632-
(loc
633-
::
634-
(if Hashtbl.mem extra.internalReferences stamp then
635-
Hashtbl.find extra.internalReferences stamp
636-
else []))
637-
in
638-
639630
let addExternalReference moduleName path tip loc =
640631
(* TODO need to follow the path, and be able to load the files to follow module references... *)
641632
Hashtbl.replace extra.externalReferences moduleName
@@ -663,7 +654,7 @@ let getIterator (extra : extra) (file : File.t) =
663654
let locType =
664655
match fromCompilerPath ~env path with
665656
| `Stamp stamp ->
666-
addReference stamp identLoc;
657+
addReference ~extra stamp identLoc;
667658
LocalReference (stamp, tip)
668659
| `Not_found -> NotFound
669660
| `Global (moduleName, path) ->
@@ -676,7 +667,7 @@ let getIterator (extra : extra) (file : File.t) =
676667
| _ -> Exported.find env.exported Exported.Value name
677668
with
678669
| Some stamp ->
679-
addReference stamp identLoc;
670+
addReference ~extra stamp identLoc;
680671
LocalReference (stamp, tip)
681672
| None -> NotFound)
682673
| `GlobalMod _ -> NotFound
@@ -691,7 +682,7 @@ let getIterator (extra : extra) (file : File.t) =
691682
addFileReference moduleName loc;
692683
TopLevelModule moduleName
693684
| `Stamp stamp ->
694-
addReference stamp loc;
685+
addReference ~extra stamp loc;
695686
LModule (LocalReference (stamp, Module))
696687
| `Not_found -> LModule NotFound
697688
| `Global (moduleName, path) ->
@@ -700,7 +691,7 @@ let getIterator (extra : extra) (file : File.t) =
700691
| `Exported (env, name) -> (
701692
match Exported.find env.exported Exported.Module name with
702693
| Some stamp ->
703-
addReference stamp loc;
694+
addReference ~extra stamp loc;
704695
LModule (LocalReference (stamp, Module))
705696
| None -> LModule NotFound)
706697
in
@@ -745,7 +736,7 @@ let getIterator (extra : extra) (file : File.t) =
745736
| `Local {stamp; item = {kind = Record fields}} -> (
746737
match fields |> List.find_opt (fun f -> f.fname.txt = name) with
747738
| Some {stamp = astamp} ->
748-
addReference astamp nameLoc;
739+
addReference ~extra astamp nameLoc;
749740
LocalReference (stamp, Field name)
750741
| None -> NotFound)
751742
| `Global (moduleName, path) ->
@@ -773,7 +764,7 @@ let getIterator (extra : extra) (file : File.t) =
773764
fields |> List.find_opt (fun f -> f.fname.txt = name)
774765
with
775766
| Some {stamp = astamp} ->
776-
addReference astamp nameLoc;
767+
addReference ~extra astamp nameLoc;
777768
LocalReference (stamp, Field name)
778769
| None -> NotFound)
779770
| `Global (moduleName, path) ->
@@ -799,7 +790,7 @@ let getIterator (extra : extra) (file : File.t) =
799790
|> List.find_opt (fun c -> c.Constructor.cname.txt = cstr_name)
800791
with
801792
| Some {stamp = cstamp} ->
802-
addReference cstamp nameLoc;
793+
addReference ~extra cstamp nameLoc;
803794
LocalReference (stamp, Constructor name)
804795
| None -> NotFound)
805796
| `Global (moduleName, path) ->
@@ -878,7 +869,7 @@ let getIterator (extra : extra) (file : File.t) =
878869
~modulePath:NotVisible ~item:val_desc.ctyp_type false val_attributes
879870
in
880871
Stamps.addValue file.stamps stamp declared;
881-
addReference stamp name.loc;
872+
addReference ~extra stamp name.loc;
882873
addLocItem extra name.loc
883874
(Typed (name.txt, val_desc.ctyp_type, Definition (stamp, Value))))
884875
| _ -> ()
@@ -899,7 +890,7 @@ let getIterator (extra : extra) (file : File.t) =
899890
~extent:pat_loc ~item:pat_type false pat_attributes
900891
in
901892
Stamps.addValue file.stamps stamp declared;
902-
addReference stamp name.loc;
893+
addReference ~extra stamp name.loc;
903894
addLocItem extra name.loc
904895
(Typed (name.txt, pat_type, Definition (stamp, Value))))
905896
in

0 commit comments

Comments
 (0)