Skip to content

Commit 5c13462

Browse files
committed
remove enter_...
1 parent 0769f30 commit 5c13462

File tree

1 file changed

+52
-71
lines changed

1 file changed

+52
-71
lines changed

analysis/src/ProcessCmt.ml

Lines changed: 52 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -833,20 +833,21 @@ let rec handle_module_expr ~env ~extra expr =
833833
| _ -> ()
834834

835835
let getIterator ~env ~(extra : extra) ~(file : File.t) =
836-
let enter_structure_item item =
837-
match item.str_desc with
836+
let structure_item (iter : Tast_iterator.iterator) item =
837+
(match item.str_desc with
838838
| Tstr_include {incl_mod = expr} ->
839839
handle_module_expr ~env ~extra expr.mod_desc
840840
| Tstr_module {mb_expr} -> handle_module_expr ~env ~extra mb_expr.mod_desc
841841
| Tstr_open {open_path; open_txt = {txt; loc}} ->
842842
(* Log.log("Have an open here"); *)
843843
addForLongident ~env ~extra None open_path txt loc;
844844
Hashtbl.replace extra.opens loc ()
845-
| _ -> ()
845+
| _ -> ());
846+
Tast_iterator.default_iterator.structure_item iter item
846847
in
847848

848-
let enter_signature_item item =
849-
match item.sig_desc with
849+
let signature_item (iter : Tast_iterator.iterator) item =
850+
(match item.sig_desc with
850851
| Tsig_value {val_id; val_loc; val_name = name; val_desc; val_attributes} ->
851852
let stamp = Ident.binding_time val_id in
852853
if Stamps.findValue file.stamps stamp = None then (
@@ -858,97 +859,77 @@ let getIterator ~env ~(extra : extra) ~(file : File.t) =
858859
addReference ~extra stamp name.loc;
859860
addLocItem extra name.loc
860861
(Typed (name.txt, val_desc.ctyp_type, Definition (stamp, Value))))
861-
| _ -> ()
862+
| _ -> ());
863+
Tast_iterator.default_iterator.signature_item iter item
862864
in
863865

864-
let enter_core_type {ctyp_type; ctyp_desc} =
865-
match ctyp_desc with
866+
let typ (iter : Tast_iterator.iterator) (item : Typedtree.core_type) =
867+
(match item.ctyp_desc with
866868
| Ttyp_constr (path, {txt; loc}, _args) ->
867-
addForLongident ~env ~extra (Some (ctyp_type, Type)) path txt loc
868-
| _ -> ()
869+
addForLongident ~env ~extra (Some (item.ctyp_type, Type)) path txt loc
870+
| _ -> ());
871+
Tast_iterator.default_iterator.typ iter item
869872
in
870873

871-
let enter_pattern {pat_desc; pat_loc; pat_type; pat_attributes} =
874+
let pat (iter : Tast_iterator.iterator) (pattern : Typedtree.pattern) =
872875
let addForPattern stamp name =
873876
if Stamps.findValue file.stamps stamp = None then (
874877
let declared =
875878
ProcessAttributes.newDeclared ~name ~stamp ~modulePath:NotVisible
876-
~extent:pat_loc ~item:pat_type false pat_attributes
879+
~extent:pattern.pat_loc ~item:pattern.pat_type false
880+
pattern.pat_attributes
877881
in
878882
Stamps.addValue file.stamps stamp declared;
879883
addReference ~extra stamp name.loc;
880884
addLocItem extra name.loc
881-
(Typed (name.txt, pat_type, Definition (stamp, Value))))
885+
(Typed (name.txt, pattern.pat_type, Definition (stamp, Value))))
882886
in
883887
(* Log.log("Entering pattern " ++ Utils.showLocation(pat_loc)); *)
884-
match pat_desc with
885-
| Tpat_record (items, _) -> addForRecord ~env ~extra pat_type items
888+
(match pattern.pat_desc with
889+
| Tpat_record (items, _) -> addForRecord ~env ~extra pattern.pat_type items
886890
| Tpat_construct (lident, constructor, _) ->
887-
addForConstructor ~env ~extra pat_type lident constructor
891+
addForConstructor ~env ~extra pattern.pat_type lident constructor
888892
| Tpat_alias (_inner, ident, name) ->
889893
let stamp = Ident.binding_time ident in
890894
addForPattern stamp name
891895
| Tpat_var (ident, name) ->
892896
(* Log.log("Pattern " ++ name.txt); *)
893897
let stamp = Ident.binding_time ident in
894898
addForPattern stamp name
895-
| _ -> ()
896-
in
897-
898-
let enter_expression expression =
899-
expression.exp_extra
900-
|> List.iter (fun (e, eloc, _) ->
901-
match e with
902-
| Texp_open (_, _path, _ident, _) -> Hashtbl.add extra.opens eloc ()
903-
| _ -> ());
904-
match expression.exp_desc with
905-
| Texp_ident (path, {txt; loc}, _) ->
906-
addForLongident ~env ~extra
907-
(Some (expression.exp_type, Value))
908-
path txt loc
909-
| Texp_record {fields} ->
910-
addForRecord ~env ~extra expression.exp_type
911-
(fields |> Array.to_list
912-
|> Utils.filterMap (fun (desc, item) ->
913-
match item with
914-
| Overridden (loc, _) -> Some (loc, desc, ())
915-
| _ -> None))
916-
| Texp_constant constant ->
917-
addLocItem extra expression.exp_loc (Constant constant)
918-
(* Skip unit and list literals *)
919-
| Texp_construct ({txt = Lident ("()" | "::"); loc}, _, _args)
920-
when loc.loc_end.pos_cnum - loc.loc_start.pos_cnum <> 2 ->
921-
()
922-
| Texp_construct (lident, constructor, _args) ->
923-
addForConstructor ~env ~extra expression.exp_type lident constructor
924-
| Texp_field (inner, lident, _label_description) ->
925-
addForField ~env ~extra inner.exp_type expression.exp_type lident
926-
| _ -> ()
927-
in
928-
929-
let structure_item (iter : Tast_iterator.iterator) item =
930-
enter_structure_item item;
931-
Tast_iterator.default_iterator.structure_item iter item
932-
in
933-
934-
let signature_item (iter : Tast_iterator.iterator) item =
935-
enter_signature_item item;
936-
Tast_iterator.default_iterator.signature_item iter item
937-
in
938-
939-
let typ (iter : Tast_iterator.iterator) item =
940-
enter_core_type item;
941-
Tast_iterator.default_iterator.typ iter item
942-
in
943-
944-
let pat (iter : Tast_iterator.iterator) item =
945-
enter_pattern item;
946-
Tast_iterator.default_iterator.pat iter item
899+
| _ -> ());
900+
Tast_iterator.default_iterator.pat iter pattern
947901
in
948902

949-
let expr (iter : Tast_iterator.iterator) item =
950-
enter_expression item;
951-
Tast_iterator.default_iterator.expr iter item
903+
let expr (iter : Tast_iterator.iterator) (expression : Typedtree.expression) =
904+
(expression.exp_extra
905+
|> List.iter (fun (e, eloc, _) ->
906+
match e with
907+
| Texp_open (_, _path, _ident, _) -> Hashtbl.add extra.opens eloc ()
908+
| _ -> ());
909+
match expression.exp_desc with
910+
| Texp_ident (path, {txt; loc}, _) ->
911+
addForLongident ~env ~extra
912+
(Some (expression.exp_type, Value))
913+
path txt loc
914+
| Texp_record {fields} ->
915+
addForRecord ~env ~extra expression.exp_type
916+
(fields |> Array.to_list
917+
|> Utils.filterMap (fun (desc, item) ->
918+
match item with
919+
| Overridden (loc, _) -> Some (loc, desc, ())
920+
| _ -> None))
921+
| Texp_constant constant ->
922+
addLocItem extra expression.exp_loc (Constant constant)
923+
(* Skip unit and list literals *)
924+
| Texp_construct ({txt = Lident ("()" | "::"); loc}, _, _args)
925+
when loc.loc_end.pos_cnum - loc.loc_start.pos_cnum <> 2 ->
926+
()
927+
| Texp_construct (lident, constructor, _args) ->
928+
addForConstructor ~env ~extra expression.exp_type lident constructor
929+
| Texp_field (inner, lident, _label_description) ->
930+
addForField ~env ~extra inner.exp_type expression.exp_type lident
931+
| _ -> ());
932+
Tast_iterator.default_iterator.expr iter expression
952933
in
953934

954935
{

0 commit comments

Comments
 (0)