@@ -626,20 +626,15 @@ let fromCompilerPath ~(env : QueryEnv.t) path =
626
626
| Some (`Local (env , name )) -> `Exported (env, name)
627
627
| Some (`Global (moduleName , fullPath )) -> `Global (moduleName, fullPath))
628
628
629
- module F (Collector : sig
630
- val extra : extra
631
- val file : File .t
632
- end ) =
633
- struct
634
- let extra = Collector. extra
635
-
629
+ let getIterator (extra : extra ) (file : File.t ) =
636
630
let addReference stamp loc =
637
631
Hashtbl. replace extra.internalReferences stamp
638
632
(loc
639
633
::
640
634
(if Hashtbl. mem extra.internalReferences stamp then
641
635
Hashtbl. find extra.internalReferences stamp
642
636
else [] ))
637
+ in
643
638
644
639
let addExternalReference moduleName path tip loc =
645
640
(* TODO need to follow the path, and be able to load the files to follow module references... *)
@@ -649,6 +644,7 @@ struct
649
644
(if Hashtbl. mem extra.externalReferences moduleName then
650
645
Hashtbl. find extra.externalReferences moduleName
651
646
else [] ))
647
+ in
652
648
653
649
let addFileReference moduleName loc =
654
650
let newLocs =
@@ -657,8 +653,9 @@ struct
657
653
| None -> LocationSet. singleton loc
658
654
in
659
655
Hashtbl. replace extra.fileReferences moduleName newLocs
656
+ in
660
657
661
- let env = QueryEnv. fromFile Collector. file
658
+ let env = QueryEnv. fromFile file in
662
659
663
660
let addForPath path lident loc typ tip =
664
661
let identName = Longident. last lident in
@@ -685,6 +682,7 @@ struct
685
682
| `GlobalMod _ -> NotFound
686
683
in
687
684
addLocItem extra loc (Typed (identName, typ, locType))
685
+ in
688
686
689
687
let addForPathParent path loc =
690
688
let locType =
@@ -707,6 +705,7 @@ struct
707
705
| None -> LModule NotFound )
708
706
in
709
707
addLocItem extra loc locType
708
+ in
710
709
711
710
let getTypeAtPath ~env path =
712
711
match fromCompilerPath ~env path with
@@ -726,12 +725,14 @@ struct
726
725
match declaredType with
727
726
| Some declaredType -> `Local declaredType
728
727
| None -> `Not_found )
728
+ in
729
729
730
730
let handleConstructor txt =
731
731
match txt with
732
732
| Longident. Lident name -> name
733
733
| Ldot (_left , name ) -> name
734
734
| Lapply (_ , _ ) -> assert false
735
+ in
735
736
736
737
let addForField recordType fieldType {Asttypes. txt; loc} =
737
738
match (Shared. dig recordType).desc with
@@ -754,6 +755,7 @@ struct
754
755
in
755
756
addLocItem extra nameLoc (Typed (name, fieldType, locType))
756
757
| _ -> ()
758
+ in
757
759
758
760
let addForRecord recordType items =
759
761
match (Shared. dig recordType).desc with
@@ -781,6 +783,7 @@ struct
781
783
in
782
784
addLocItem extra nameLoc (Typed (name, lbl_res, locType)))
783
785
| _ -> ()
786
+ in
784
787
785
788
let addForConstructor constructorType {Asttypes. txt; loc} {Types. cstr_name} =
786
789
match (Shared. dig constructorType).desc with
@@ -806,12 +809,14 @@ struct
806
809
in
807
810
addLocItem extra nameLoc (Typed (name, constructorType, locType))
808
811
| _ -> ()
812
+ in
809
813
810
814
let rec lidIsComplex (lid : Longident.t ) =
811
815
match lid with
812
816
| Lapply _ -> true
813
817
| Ldot (lid , _ ) -> lidIsComplex lid
814
818
| _ -> false
819
+ in
815
820
816
821
let rec addForLongident top (path : Path.t ) (txt : Longident.t ) loc =
817
822
if (not loc.Location. loc_ghost) && not (lidIsComplex txt) then (
@@ -835,6 +840,7 @@ struct
835
840
(Utils. chopLocationEnd loc (String. length name + 1 ))
836
841
| Pident _ , Lident _ -> ()
837
842
| _ -> () )
843
+ in
838
844
839
845
let rec handle_module_expr expr =
840
846
match expr with
@@ -849,6 +855,7 @@ struct
849
855
handle_module_expr obj.mod_desc;
850
856
handle_module_expr arg.mod_desc
851
857
| _ -> ()
858
+ in
852
859
853
860
let enter_structure_item item =
854
861
match item.str_desc with
@@ -857,38 +864,41 @@ struct
857
864
| Tstr_open {open_path; open_txt = {txt; loc} } ->
858
865
(* Log.log("Have an open here"); *)
859
866
addForLongident None open_path txt loc;
860
- Hashtbl. replace Collector. extra.opens loc ()
867
+ Hashtbl. replace extra.opens loc ()
861
868
| _ -> ()
869
+ in
862
870
863
871
let enter_signature_item item =
864
872
match item.sig_desc with
865
873
| Tsig_value {val_id; val_loc; val_name = name ; val_desc; val_attributes} ->
866
874
let stamp = Ident. binding_time val_id in
867
- if Stamps. findValue Collector. file.stamps stamp = None then (
875
+ if Stamps. findValue file.stamps stamp = None then (
868
876
let declared =
869
877
ProcessAttributes. newDeclared ~name ~stamp ~extent: val_loc
870
878
~module Path:NotVisible ~item: val_desc.ctyp_type false val_attributes
871
879
in
872
- Stamps. addValue Collector. file.stamps stamp declared;
880
+ Stamps. addValue file.stamps stamp declared;
873
881
addReference stamp name.loc;
874
882
addLocItem extra name.loc
875
883
(Typed (name.txt, val_desc.ctyp_type, Definition (stamp, Value ))))
876
884
| _ -> ()
885
+ in
877
886
878
887
let enter_core_type {ctyp_type; ctyp_desc} =
879
888
match ctyp_desc with
880
889
| Ttyp_constr (path , {txt; loc} , _args ) ->
881
890
addForLongident (Some (ctyp_type, Type )) path txt loc
882
891
| _ -> ()
892
+ in
883
893
884
894
let enter_pattern {pat_desc; pat_loc; pat_type; pat_attributes} =
885
895
let addForPattern stamp name =
886
- if Stamps. findValue Collector. file.stamps stamp = None then (
896
+ if Stamps. findValue file.stamps stamp = None then (
887
897
let declared =
888
898
ProcessAttributes. newDeclared ~name ~stamp ~module Path:NotVisible
889
899
~extent: pat_loc ~item: pat_type false pat_attributes
890
900
in
891
- Stamps. addValue Collector. file.stamps stamp declared;
901
+ Stamps. addValue file.stamps stamp declared;
892
902
addReference stamp name.loc;
893
903
addLocItem extra name.loc
894
904
(Typed (name.txt, pat_type, Definition (stamp, Value ))))
@@ -906,6 +916,7 @@ struct
906
916
let stamp = Ident. binding_time ident in
907
917
addForPattern stamp name
908
918
| _ -> ()
919
+ in
909
920
910
921
let enter_expression expression =
911
922
expression.exp_extra
@@ -934,47 +945,46 @@ struct
934
945
| Texp_field (inner , lident , _label_description ) ->
935
946
addForField inner.exp_type expression.exp_type lident
936
947
| _ -> ()
948
+ in
937
949
938
950
let structure_item (iter : Tast_iterator.iterator ) item =
939
951
enter_structure_item item;
940
952
Tast_iterator. default_iterator.structure_item iter item
953
+ in
941
954
942
955
let signature_item (iter : Tast_iterator.iterator ) item =
943
956
enter_signature_item item;
944
957
Tast_iterator. default_iterator.signature_item iter item
958
+ in
945
959
946
960
let typ (iter : Tast_iterator.iterator ) item =
947
961
enter_core_type item;
948
962
Tast_iterator. default_iterator.typ iter item
963
+ in
949
964
950
965
let pat (iter : Tast_iterator.iterator ) item =
951
966
enter_pattern item;
952
967
Tast_iterator. default_iterator.pat iter item
968
+ in
953
969
954
970
let expr (iter : Tast_iterator.iterator ) item =
955
971
enter_expression item;
956
972
Tast_iterator. default_iterator.expr iter item
973
+ in
957
974
958
- let iterator =
959
- {
960
- Tast_iterator. default_iterator with
961
- expr;
962
- pat;
963
- signature_item;
964
- structure_item;
965
- typ;
966
- }
967
- end
975
+ {
976
+ Tast_iterator. default_iterator with
977
+ expr;
978
+ pat;
979
+ signature_item;
980
+ structure_item;
981
+ typ;
982
+ }
968
983
969
984
let extraForStructureItems ~(file : File.t )
970
985
(items : Typedtree.structure_item list ) parts =
971
986
let extra = extraForFile ~file in
972
- (* TODO look through parts and extend the extent *)
973
- let module FM = F (struct
974
- let extra = extra
975
- let file = file
976
- end ) in
977
- let iterator = FM. iterator in
987
+ let iterator = getIterator extra file in
978
988
items |> List. iter (iterator.structure_item iterator);
979
989
980
990
(* Log.log("Parts " ++ string_of_int(Array.length(parts))); *)
@@ -994,12 +1004,7 @@ let extraForStructureItems ~(file : File.t)
994
1004
let extraForSignatureItems ~(file : File.t )
995
1005
(items : Typedtree.signature_item list ) parts =
996
1006
let extra = extraForFile ~file in
997
-
998
- let module FM = F (struct
999
- let extra = extra
1000
- let file = file
1001
- end ) in
1002
- let iterator = FM. iterator in
1007
+ let iterator = getIterator extra file in
1003
1008
items |> List. iter (iterator.signature_item iterator);
1004
1009
(* Log.log("Parts " ++ string_of_int(Array.length(parts))); *)
1005
1010
parts
0 commit comments