123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917(* {{{ Copying *(
This file is part of Merlin, an helper for ocaml editors
Copyright (C) 2013 - 2017 Frédéric Bour <frederic.bour(_)lakaban.net>
Thomas Refis <refis.thomas(_)gmail.com>
Simon Castellan <simon.castellan(_)iuwt.fr>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The Software is provided "as is", without warranty of any kind, express or
implied, including but not limited to the warranties of merchantability,
fitness for a particular purpose and noninfringement. In no event shall
the authors or copyright holders be liable for any claim, damages or other
liability, whether in an action of contract, tort or otherwise, arising
from, out of or in connection with the software or the use or other dealings
in the Software.
)* }}} *)[@@@ocaml.warning"-9"]openStdtypeconstructor_declaration=Typedtree.constructor_declarationopenTypedtreetypenode=|Dummy|Pattern:_general_pattern->node|Expressionofexpression|Case:_case->node|Class_exprofclass_expr|Class_structureofclass_structure|Class_fieldofclass_field|Class_field_kindofclass_field_kind|Module_exprofmodule_expr|Module_type_constraintofmodule_type_constraint|Structureofstructure|Signatureofsignature|Structure_itemofstructure_item*Env.t|Signature_itemofsignature_item*Env.t|Module_bindingofmodule_binding|Value_bindingofvalue_binding|Module_typeofmodule_type|Module_declarationofmodule_declaration|Module_type_declarationofmodule_type_declaration|With_constraintofwith_constraint|Core_typeofcore_type|Package_typeofpackage_type|Row_fieldofrow_field|Value_descriptionofvalue_description|Type_declarationoftype_declaration|Type_kindoftype_kind|Type_extensionoftype_extension|Extension_constructorofextension_constructor|Label_declarationoflabel_declaration|Constructor_declarationofconstructor_declaration|Class_typeofclass_type|Class_signatureofclass_signature|Class_type_fieldofclass_type_field|Class_declarationofclass_declaration|Class_descriptionofclass_description|Class_type_declarationofclass_type_declaration|Binding_opofbinding_op|Include_descriptionofinclude_description|Include_declarationofinclude_declaration|Open_descriptionofopen_description|Open_declarationofopen_declaration|Method_callofexpression*meth*Location.t|Record_fieldof[`Expressionofexpression|`Patternofpattern]*Types.label_description*Longident.tLocation.loc|Module_binding_nameofmodule_binding|Module_declaration_nameofmodule_declaration|Module_type_declaration_nameofmodule_type_declarationletnode_update_envenv0=function|Pattern{pat_env=env}|Expression{exp_env=env}|Class_expr{cl_env=env}|Method_call({exp_env=env},_,_)|Record_field(`Expression{exp_env=env},_,_)|Record_field(`Pattern{pat_env=env},_,_)|Module_expr{mod_env=env}|Module_type{mty_env=env}|Structure_item(_,env)|Signature_item(_,env)|Core_type{ctyp_env=env}|Class_type{cltyp_env=env}->env|Dummy|Case_|Class_structure_|Class_signature_|Class_field_|Class_field_kind_|Type_extension_|Extension_constructor_|Package_type_|Row_field_|Type_declaration_|Type_kind_|Module_binding_|Module_declaration_|Module_binding_name_|Module_declaration_name_|Module_type_declaration_|Module_type_constraint_|Module_type_declaration_name_|With_constraint_|Structure_|Signature_|Value_description_|Value_binding_|Constructor_declaration_|Label_declaration_|Class_declaration_|Class_description_|Class_type_declaration_|Class_type_field_|Include_description_|Include_declaration_|Open_description_|Open_declaration_|Binding_op_->env0letnode_real_locloc0=function|Expression{exp_loc=loc}|Pattern{pat_loc=loc}|Method_call(_,_,loc)|Record_field(_,_,{loc})|Class_expr{cl_loc=loc}|Module_expr{mod_loc=loc}|Structure_item({str_loc=loc},_)|Signature_item({sig_loc=loc},_)|Module_type{mty_loc=loc}|Core_type{ctyp_loc=loc}|Class_type{cltyp_loc=loc}|Class_field{cf_loc=loc}|Module_binding{mb_loc=loc}|Module_declaration{md_loc=loc}|Module_type_declaration{mtd_loc=loc}|Value_description{val_loc=loc}|Value_binding{vb_loc=loc}|Type_declaration{typ_loc=loc}|Label_declaration{ld_loc=loc}|Constructor_declaration{cd_loc=loc}|Class_type_field{ctf_loc=loc}|Class_declaration{ci_loc=loc}|Class_description{ci_loc=loc}|Class_type_declaration{ci_loc=loc}|Extension_constructor{ext_loc=loc}|Include_description{incl_loc=loc}|Include_declaration{incl_loc=loc}|Open_description{open_loc=loc}|Open_declaration{open_loc=loc}|Binding_op{bop_op_name={loc}}->loc|Module_type_declaration_name{mtd_name=loc}->loc.Location.loc|Module_declaration_name{md_name=loc}|Module_binding_name{mb_name=loc}->loc.Location.loc|Structure_|Signature_|Case_|Class_structure_|Type_extension_|Class_field_kind_|Module_type_constraint_|With_constraint_|Row_field_|Type_kind_|Class_signature_|Package_type_|Dummy->loc0letnode_attributes=function|Expressionexp->exp.exp_attributes|Patternpat->pat.pat_attributes|Class_exprcl->cl.cl_attributes|Class_fieldcf->cf.cf_attributes|Module_exprme->me.mod_attributes|Structure_item({str_desc=Tstr_eval(_,attr)},_)->attr|Structure_item({str_desc=Tstr_attributea},_)->[a]|Signature_item({sig_desc=Tsig_attributea},_)->[a]|Module_bindingmb->mb.mb_attributes|Value_bindingvb->vb.vb_attributes|Module_typemt->mt.mty_attributes|Module_declarationmd->md.md_attributes|Module_type_declarationmtd->mtd.mtd_attributes|Open_descriptiono->o.open_attributes|Include_declarationi->i.incl_attributes|Include_descriptioni->i.incl_attributes|Core_typect->ct.ctyp_attributes|Row_fieldrf->rf.rf_attributes|Value_descriptionvd->vd.val_attributes|Type_declarationtd->td.typ_attributes|Label_declarationld->ld.ld_attributes|Constructor_declarationcd->cd.cd_attributes|Type_extensionte->te.tyext_attributes|Extension_constructorec->ec.ext_attributes|Class_typect->ct.cltyp_attributes|Class_type_fieldctf->ctf.ctf_attributes|Class_declarationci->ci.ci_attributes|Class_descriptionci->ci.ci_attributes|Class_type_declarationci->ci.ci_attributes|Method_call(obj,_,_)->obj.exp_attributes|Record_field(`Expressionobj,_,_)->obj.exp_attributes|Record_field(`Patternobj,_,_)->obj.pat_attributes|_->[]lethas_attr~namenode=letattrs=node_attributesnodeinList.exists~f:(funa->letstr,_=Ast_helper.Attr.as_tupleainstr.Location.txt=name)attrsletnode_merlin_locloc0node=letattributes=node_attributesnodeinletloc=letopenParsetreeinletpred{attr_name=loc;_}=Location_aux.is_relaxed_locationlocinmatchList.findattributes~f:predwith|{attr_name;_}->attr_name.Location.loc|exceptionNot_found->node_real_locloc0nodeinletloc=matchnodewith|Expression{exp_extra;_}->List.fold_left~f:(funloc0(_,loc,_)->Location_aux.unionloc0loc)~init:locexp_extra|Pattern{pat_extra;_}->List.fold_left~f:(funloc0(_,loc,_)->Location_aux.unionloc0loc)~init:locpat_extra|_->locinlocletappnodeenvfacc=f(node_update_envenvnode)nodeacctype'af0=Env.t->node->'a->'atype('b,'a)f1='b->Env.t->'af0->'a->'aletid_fold_env(_f:_f0)acc=acclet(**)f1f2env(f:_f0)acc=f2envf(f1envfacc)letreclist_fold(f':_f1)xsenvfacc=matchxswith|x::xs->list_foldf'xsenvf(f'xenvfacc)|[]->accletarray_fold(f':_f1)arrenvfacc=letacc=refaccinfori=0toArray.lengtharr-1doacc:=f'arr.(i)envf!accdone;!accletreclist_fold_with_next(f':_->_f1)xsenvfacc=matchxswith|x::(y::_asxs)->list_fold_with_nextf'xsenvf(f'(Somey)xenvfacc)|[x]->f'Nonexenvfacc|[]->accletoption_foldf'oenv(f:_f0)acc=matchowith|None->acc|Somex->f'xenvfaccletof_core_typect=app(Core_typect)letof_exp_extra(exp,_,_)=matchexpwith|Texp_constraintct->of_core_typect|Texp_coerce(cto,ct)->of_core_typect**option_foldof_core_typecto|Texp_polycto->option_foldof_core_typecto|Texp_newtype'_|Texp_newtype_->id_foldletof_expressione=app(Expressione)**list_foldof_exp_extrae.exp_extraletof_pat_extra(pat,_,_)=matchpatwith|Tpat_constraintct->of_core_typect|Tpat_type_|Tpat_unpack|Tpat_open_->id_foldletof_pattern(typek)(p:kgeneral_pattern)=app(Patternp)**list_foldof_pat_extrap.pat_extraletof_casec=app(Casec)letof_label_declarationct=app(Label_declarationct)letof_value_bindingvb=app(Value_bindingvb)letof_module_typemt=app(Module_typemt)letof_module_exprme=app(Module_exprme)letof_typ_param(ct,_)=of_core_typectletof_constructor_arguments=function|Cstr_tuplects->list_foldof_core_typects|Cstr_recordlbls->list_foldof_label_declarationlblsletof_bop({bop_exp;_}asbop)=app(Binding_opbop)**of_expressionbop_expletof_record_fieldobjloclblenv(f:_f0)acc=app(Record_field(obj,lbl,loc))envfaccletof_exp_record_fieldobjlid_loclbl=of_record_field(`Expressionobj)lid_loclblletof_pat_record_fieldobjloclbl=of_record_field(`Patternobj)loclblletof_pattern_desc(typek)(desc:kpattern_desc)=matchdescwith|Tpat_any|Tpat_var_|Tpat_constant_|Tpat_variant(_,None,_)->id_fold|Tpat_alias(p,_,_)|Tpat_variant(_,Somep,_)|Tpat_lazyp|Tpat_exceptionp->of_patternp|Tpat_valuep->of_pattern(p:>valuegeneral_pattern)|Tpat_tupleps|Tpat_construct(_,_,ps,None)|Tpat_arrayps->list_foldof_patternps|Tpat_construct(_,_,ps,Some(_,ct))->list_foldof_patternps**of_core_typect|Tpat_record(ls,_)->list_fold(fun(lid_loc,desc,p)->of_pat_record_fieldplid_locdesc**of_patternp)ls|Tpat_or(p1,p2,_)->of_patternp1**of_patternp2letof_method_callobjmethlocenv(f:_f0)acc=letloc_start=obj.exp_loc.Location.loc_endinletloc_end=loc.Location.loc_endinletloc={locwithLocation.loc_start;loc_end}inapp(Method_call(obj,meth,loc))envfaccletof_expression_descloc=function|Texp_ident_|Texp_constant_|Texp_instvar_|Texp_variant(_,None)|Texp_new_|Texp_hole->id_fold|Texp_let(_,vbs,e)->of_expressione**list_foldof_value_bindingvbs|Texp_function{cases;_}->list_foldof_casecases|Texp_apply(e,ls)->of_expressione**list_fold(function|_,None->id_fold|_,Somee->of_expressione)ls|Texp_match(e,cs,_)->of_expressione**list_foldof_casecs|Texp_try(e,cs)->of_expressione**list_foldof_casecs|Texp_tuplees|Texp_construct(_,_,es)|Texp_arrayes->list_foldof_expressiones|Texp_variant(_,Somee)|Texp_assert(e,_)|Texp_lazye|Texp_setinstvar(_,_,_,e)->of_expressione|Texp_record{fields;extended_expression}->option_foldof_expressionextended_expression**letfold_field=function|_,Typedtree.Kept_->id_fold|desc,Typedtree.Overridden(lid_loc,e)->of_exp_record_fieldelid_locdesc**of_expressioneinarray_foldfold_fieldfields|Texp_field(e,lid_loc,lbl)->of_expressione**of_exp_record_fieldelid_loclbl|Texp_setfield(e1,lid_loc,lbl,e2)->of_expressione1**of_expressione2**of_exp_record_fielde1lid_loclbl|Texp_ifthenelse(e1,e2,None)|Texp_sequence(e1,e2)|Texp_while(e1,e2)->of_expressione1**of_expressione2|Texp_ifthenelse(e1,e2,Somee3)|Texp_for(_,_,e1,e2,_,e3)->of_expressione1**of_expressione2**of_expressione3|Texp_send(e,meth)->of_expressione**of_method_callemethloc(* TODO ulysse CHECK*)|Texp_override(_,ls)->list_fold(fun(_,_,e)->of_expressione)ls|Texp_letmodule(mb_id,mb_name,mb_presence,mb_expr,e)->letmb={mb_id;mb_name;mb_expr;mb_loc=Location.none;mb_attributes=[];mb_presence}inapp(Module_bindingmb)**of_expressione|Texp_letexception(ec,e)->app(Extension_constructorec)**of_expressione|Texp_object(cs,_)->app(Class_structurecs)|Texp_packme->of_module_exprme|Texp_unreachable|Texp_extension_constructor_->id_fold|Texp_letop{let_;ands;body;_}->(* let+ ..pat1 and pat2 and ... are represented as pattern couples:
[pat1; [pat2; ...]]. The following function flattens these couples.
Keeping track of the known size of the tuple prevent wrongly flattening
the patterns patN when they are tuples themselves. *)letrecflatten_patterns~sizeaccpat=matchpat.pat_descwith|Tpat_tuple[tuple;pat]whensize>0->flatten_patterns~size:(size-1)(pat::acc)tuple|_->List.rev(pat::acc)inletbindops=let_::andsinletpatterns=flatten_patterns~size:(List.lengthands)[]body.c_lhsinletof_letop(pat,bindop)=of_bopbindop**of_patternpatinlist_foldof_letop(List.combinepatternsbindops)**of_expressionbody.c_rhs|Texp_open(od,e)->app(Module_exprod.open_expr)**of_expressioneandof_class_expr_desc=function|Tcl_ident(_,_,cts)->list_foldof_core_typects|Tcl_structurecs->app(Class_structurecs)|Tcl_fun(_,p,es,ce,_)->list_fold(fun(_,e)->of_expressione)es**of_patternp**app(Class_exprce)|Tcl_apply(ce,es)->list_fold(function|_,None->id_fold|_,Somee->of_expressione)es**app(Class_exprce)|Tcl_let(_,vbs,es,ce)->list_foldof_value_bindingvbs**list_fold(fun(_,e)->of_expressione)es**app(Class_exprce)|Tcl_constraint(ce,cto,_,_,_)->option_fold(funct->app(Class_typect))cto**app(Class_exprce)|Tcl_open(_,ce)->app(Class_exprce)andof_class_field_desc=function|Tcf_inherit(_,ce,_,_,_)->app(Class_exprce)|Tcf_val(_,_,_,cfk,_)|Tcf_method(_,_,cfk)->app(Class_field_kindcfk)|Tcf_constraint(ct1,ct2)->of_core_typect1**of_core_typect2|Tcf_initializere->of_expressione|Tcf_attribute_->id_fold(*TODO*)andof_module_expr_desc=function|Tmod_ident_->id_fold|Tmod_structurestr->app(Structurestr)|Tmod_functor(Unit,me)->of_module_exprme|Tmod_functor(Named(_,_,mt),me)->of_module_typemt**of_module_exprme|Tmod_apply(me1,me2,_)->of_module_exprme1**of_module_exprme2|Tmod_apply_unitme1->of_module_exprme1|Tmod_constraint(me,_,mtc,_)->of_module_exprme**app(Module_type_constraintmtc)|Tmod_unpack(e,_)->of_expressione|Tmod_hole->id_foldandof_structure_item_desc=function|Tstr_eval(e,_)->of_expressione|Tstr_value(_,vbs)->list_foldof_value_bindingvbs|Tstr_primitivevd->app(Value_descriptionvd)|Tstr_type(_,tds)->list_fold(funtd->app(Type_declarationtd))tds|Tstr_typexttext->app(Type_extensiontext)|Tstr_exceptiontexn->app(Extension_constructortexn.tyexn_constructor)|Tstr_modulemb->app(Module_bindingmb)|Tstr_recmodulembs->list_fold(funx->app(Module_bindingx))mbs|Tstr_modtypemtd->app(Module_type_declarationmtd)|Tstr_classcds->list_fold(fun(cd,_)->app(Class_declarationcd))cds|Tstr_class_typectds->list_fold(fun(_,_,ctd)->app(Class_type_declarationctd))ctds|Tstr_includei->app(Include_declarationi)|Tstr_opend->app(Open_declarationd)|Tstr_attribute_->id_foldandof_module_type_desc=function|Tmty_ident_|Tmty_alias_->id_fold|Tmty_signaturesg->app(Signaturesg)|Tmty_functor(Named(_,_,mt1),mt2)->of_module_typemt1**of_module_typemt2|Tmty_functor(Unit,mt)->of_module_typemt|Tmty_with(mt,wcs)->list_fold(fun(_,_,wc)->app(With_constraintwc))wcs**of_module_typemt|Tmty_typeofme->of_module_exprmeandof_signature_item_desc=function|Tsig_attribute_->id_fold|Tsig_opend->app(Open_descriptiond)|Tsig_valuevd->app(Value_descriptionvd)|Tsig_type(_,tds)->list_fold(funtd->app(Type_declarationtd))tds|Tsig_typexttext->app(Type_extensiontext)|Tsig_exceptiontexn->app(Extension_constructortexn.tyexn_constructor)|Tsig_modulemd->app(Module_declarationmd)|Tsig_recmodulemds->list_fold(funmd->app(Module_declarationmd))mds|Tsig_modtypemtd->app(Module_type_declarationmtd)|Tsig_includei->app(Include_descriptioni)|Tsig_classcds->list_fold(funcd->app(Class_descriptioncd))cds|Tsig_class_typectds->list_fold(functd->app(Class_type_declarationctd))ctds|Tsig_typesubsttds->(* FIXME: shitty approximation *)list_fold(funtd->app(Type_declarationtd))tds|Tsig_modsubst_ms->(* TODO. *)id_fold|Tsig_modtypesubst_mts->(* TODO. *)id_foldandof_core_type_desc=function|Ttyp_any|Ttyp_var_->id_fold|Ttyp_arrow(_,ct1,ct2)->of_core_typect1**of_core_typect2|Ttyp_tuplects|Ttyp_constr(_,_,cts)|Ttyp_class(_,_,cts)->list_foldof_core_typects|Ttyp_object(cts,_)->list_fold(funof_->matchof_.of_descwith|OTtag(_,ct)|OTinheritct->of_core_typect)cts|Ttyp_poly(_,ct)|Ttyp_alias(ct,_)->of_core_typect|Ttyp_variant(rfs,_,_)->list_fold(funrf->app(Row_fieldrf))rfs|Ttyp_packagept->app(Package_typept)andof_class_type_desc=function|Tcty_constr(_,_,cts)->list_foldof_core_typects|Tcty_signaturecs->app(Class_signaturecs)|Tcty_arrow(_,ct,clt)->of_core_typect**app(Class_typeclt)|Tcty_open(_,ct)->app(Class_typect)andof_class_type_field_desc=function|Tctf_inheritct->app(Class_typect)|Tctf_val(_,_,_,ct)|Tctf_method(_,_,_,ct)->of_core_typect|Tctf_constraint(ct1,ct2)->of_core_typect1**of_core_typect2|Tctf_attribute_->id_foldletof_node=function|Dummy->id_fold|Pattern{pat_desc;pat_extra=_}->of_pattern_descpat_desc|Expression{exp_desc;exp_extra=_;exp_loc}->of_expression_descexp_locexp_desc|Case{c_lhs;c_guard;c_rhs}->of_patternc_lhs**of_expressionc_rhs**option_foldof_expressionc_guard|Class_expr{cl_desc}->of_class_expr_desccl_desc|Class_structure{cstr_self;cstr_fields}->of_patterncstr_self**list_fold(funf->app(Class_fieldf))cstr_fields|Class_field{cf_desc}->of_class_field_desccf_desc|Class_field_kind(Tcfk_virtualct)->of_core_typect|Class_field_kind(Tcfk_concrete(_,e))->of_expressione|Module_expr{mod_desc}->of_module_expr_descmod_desc|Module_type_constraintTmodtype_implicit->id_fold|Module_type_constraint(Tmodtype_explicitmt)->of_module_typemt|Structure{str_items;str_final_env}->list_fold_with_next(funnextitem->matchnextwith|None->app(Structure_item(item,str_final_env))|Someitem'->app(Structure_item(item,item'.str_env)))str_items|Structure_item({str_desc},_)->of_structure_item_descstr_desc|Module_bindingmb->app(Module_exprmb.mb_expr)**app(Module_binding_namemb)|Value_binding{vb_pat;vb_expr}->of_patternvb_pat**of_expressionvb_expr|Module_type{mty_desc}->of_module_type_descmty_desc|Signature{sig_items;sig_final_env}->list_fold_with_next(funnextitem->matchnextwith|None->app(Signature_item(item,sig_final_env))|Someitem'->app(Signature_item(item,item'.sig_env)))sig_items|Signature_item({sig_desc},_)->of_signature_item_descsig_desc|Module_declarationmd->of_module_typemd.md_type**app(Module_declaration_namemd)|Module_type_declarationmtd->option_foldof_module_typemtd.mtd_type**app(Module_type_declaration_namemtd)|With_constraint(Twith_typetd|Twith_typesubsttd)->app(Type_declarationtd)|With_constraint(Twith_module_|Twith_modsubst_)->id_fold|With_constraint(Twith_modtypemt|Twith_modtypesubstmt)->of_module_typemt|Core_type{ctyp_desc}->of_core_type_descctyp_desc|Package_type{pack_fields}->list_fold(fun(_,ct)->of_core_typect)pack_fields|Row_fieldrf->beginmatchrf.rf_descwith|Ttag(_,_,cts)->list_foldof_core_typects|Tinheritct->of_core_typectend|Value_description{val_desc}->of_core_typeval_desc|Type_declaration{typ_params;typ_cstrs;typ_kind;typ_manifest}->letof_typ_cstrs(ct1,ct2,_)=of_core_typect1**of_core_typect2inoption_foldof_core_typetyp_manifest**list_foldof_typ_paramtyp_params**app(Type_kindtyp_kind)**list_foldof_typ_cstrstyp_cstrs|Type_kind(Ttype_abstract|Ttype_open)->id_fold|Type_kind(Ttype_variantcds)->list_fold(funcd->app(Constructor_declarationcd))cds|Type_kind(Ttype_recordlds)->list_foldof_label_declarationlds|Type_extension{tyext_params;tyext_constructors}->list_foldof_typ_paramtyext_params**list_fold(funec->app(Extension_constructorec))tyext_constructors|Extension_constructor{ext_kind=Text_decl(_,carg,cto)}->option_foldof_core_typecto**of_constructor_argumentscarg|Extension_constructor{ext_kind=Text_rebind_}->id_fold|Label_declaration{ld_type}->of_core_typeld_type|Constructor_declaration{cd_args;cd_res}->option_foldof_core_typecd_res**of_constructor_argumentscd_args|Class_type{cltyp_desc}->of_class_type_desccltyp_desc|Class_signature{csig_self;csig_fields}->of_core_typecsig_self**list_fold(funx->app(Class_type_fieldx))csig_fields|Class_type_field{ctf_desc}->of_class_type_field_descctf_desc|Class_declaration{ci_params;ci_expr}->app(Class_exprci_expr)**list_foldof_typ_paramci_params|Class_description{ci_params;ci_expr}->app(Class_typeci_expr)**list_foldof_typ_paramci_params|Class_type_declaration{ci_params;ci_expr}->app(Class_typeci_expr)**list_foldof_typ_paramci_params|Method_call_->id_fold|Record_field_->id_fold|Module_binding_name_->id_fold|Module_declaration_name_->id_fold|Module_type_declaration_name_->id_fold|Open_description_->id_fold|Open_declarationod->app(Module_exprod.open_expr)|Include_declarationi->of_module_expri.incl_mod|Include_descriptioni->of_module_typei.incl_mod|Binding_op{bop_exp=_}->id_foldletfold_nodefenvnodeacc=of_nodenodeenvfacc(** Accessors for information specific to a node *)letstring_of_node=function|Dummy->"dummy"|Patternp->letfmt,printer=Format.to_string()inPrinttyped.pattern0fmtp;printer()|Expression_->"expression"|Case_->"case"|Class_expr_->"class_expr"|Class_structure_->"class_structure"|Class_field_->"class_field"|Class_field_kind_->"class_field_kind"|Module_expr_->"module_expr"|Module_type_constraint_->"module_type_constraint"|Structure_->"structure"|Structure_item_->"structure_item"|Module_binding_->"module_binding"|Value_binding_->"value_binding"|Module_type_->"module_type"|Signature_->"signature"|Signature_item_->"signature_item"|Module_declaration_->"module_declaration"|Module_type_declaration_->"module_type_declaration"|With_constraint_->"with_constraint"|Core_type_->"core_type"|Package_type_->"package_type"|Row_field_->"row_field"|Value_description_->"value_description"|Type_declaration_->"type_declaration"|Type_kind_->"type_kind"|Type_extension_->"type_extension"|Extension_constructor_->"extension_constructor"|Label_declaration_->"label_declaration"|Constructor_declaration_->"constructor_declaration"|Class_type_->"class_type"|Class_signature_->"class_signature"|Class_type_field_->"class_type_field"|Class_declaration_->"class_declaration"|Class_description_->"class_description"|Class_type_declaration_->"class_type_declaration"|Binding_op_->"binding_op"|Method_call_->"method_call"|Record_field_->"record_field"|Module_binding_name_->"module_binding_name"|Module_declaration_name_->"module_declaration_name"|Module_type_declaration_name_->"module_type_declaration_name"|Open_description_->"open_description"|Open_declaration_->"open_declaration"|Include_description_->"include_description"|Include_declaration_->"include_declaration"letmkloc=Location.mklocletreloctxtloc={locwithLocation.txt}letmk_lidentx=Longident.Lidentxlettype_constructor_pathtyp=matchTypes.get_desctypwith|Types.Tconstr(p,_,_)->p|_->raiseNot_found(* Build a fake path for value constructors and labels *)letfake_path{Location.loc;txt=lid}typname=matchtype_constructor_pathtypwith|Path.Pdot(p,_)->[(mkloc(Path.Pdot(p,name))loc,Somelid)]|Path.Pident_->[(mkloc(Path.Pident(Ident.create_persistentname))loc,Somelid)]|_|(exceptionNot_found)->[]letpattern_paths(typek){Typedtree.pat_desc;pat_extra;_}=letinit=match(pat_desc:kpattern_desc)with|Tpat_construct(lid_loc,{Types.cstr_name;cstr_res;_},_,_)->fake_pathlid_loccstr_rescstr_name|Tpat_var(id,{Location.loc;txt})->[(mkloc(Path.Pidentid)loc,Some(Longident.Lidenttxt))]|Tpat_alias(_,id,loc)->[(reloc(Path.Pidentid)loc,Some(Longident.Lidentloc.txt))]|_->[]inList.fold_left~initpat_extra~f:(funacc(extra,_,_)->matchextrawith|Tpat_open(path,loc,_)|Tpat_type(path,loc)->(relocpathloc,Someloc.txt)::acc|_->acc)letmodule_expr_paths{Typedtree.mod_desc}=matchmod_descwith|Tmod_ident(path,loc)->[(relocpathloc,Someloc.txt)]|Tmod_functor(Named(Someid,loc,_),_)->[(reloc(Path.Pidentid)loc,Option.map~f:mk_lidentloc.txt)]|_->[]letbindop_path{bop_op_name;bop_op_path}=letloc=bop_op_nameinletpath=bop_op_pathin(relocpathloc,Some(Longident.Lidentloc.txt))letexpression_paths{Typedtree.exp_desc;exp_extra;_}=letinit=matchexp_descwith|Texp_ident(path,loc,_)->[(relocpathloc,Someloc.txt)]|Texp_letop{let_;ands}->bindop_pathlet_::List.map~f:bindop_pathands|Texp_new(path,loc,_)->[(relocpathloc,Someloc.txt)]|Texp_instvar(_,path,loc)->[(relocpathloc,Some(Lidentloc.txt))]|Texp_setinstvar(_,path,loc,_)->[(relocpathloc,Some(Lidentloc.txt))]|Texp_override(_,ps)->List.map~f:(fun(id,loc,_)->(reloc(Path.Pidentid)loc,Some(Longident.Lidentloc.txt)))ps|Texp_letmodule(Someid,loc,_,_,_)->[(reloc(Path.Pidentid)loc,Option.map~f:mk_lidentloc.txt)]|Texp_for(id,{Parsetree.ppat_loc=loc;ppat_desc},_,_,_,_)->letlid=matchppat_descwith|Ppat_any->None|Ppat_var{txt}->Some(Longident.Lidenttxt)|_->assertfalsein[(mkloc(Path.Pidentid)loc,lid)]|Texp_construct(lid_loc,{Types.cstr_name;cstr_res;_},_)->fake_pathlid_loccstr_rescstr_name|Texp_open(od,_)->module_expr_pathsod.open_expr|_->[]inList.fold_left~initexp_extra~f:(funacc(extra,_,_)->matchextrawith|Texp_newtype'(id,label_loc)->letpath=Path.Pidentidinletlid=Longident.Lidentlabel_loc.txtin(mklocpathlabel_loc.loc,Somelid)::acc|_->acc)letcore_type_paths{Typedtree.ctyp_desc}=matchctyp_descwith|Ttyp_constr(path,loc,_)->[(relocpathloc,Someloc.txt)]|Ttyp_class(path,loc,_)->[(relocpathloc,Someloc.txt)]|_->[]letclass_expr_paths{Typedtree.cl_desc}=matchcl_descwith|Tcl_ident(path,loc,_)->[(relocpathloc,Someloc.txt)]|_->[]letclass_field_paths{Typedtree.cf_desc}=matchcf_descwith|Tcf_val(loc,_,id,_,_)->[(reloc(Path.Pidentid)loc,Some(Longident.Lidentloc.txt))]|_->[]letstructure_item_paths{Typedtree.str_desc}=matchstr_descwith|Tstr_class_typecls->List.map~f:(fun(id,loc,_)->(reloc(Path.Pidentid)loc,Some(Longident.Lidentloc.txt)))cls|Tstr_openod->module_expr_pathsod.open_expr|_->[]letmodule_type_paths{Typedtree.mty_desc}=matchmty_descwith|Tmty_ident(path,loc)|Tmty_alias(path,loc)->[(relocpathloc,Someloc.txt)]|Tmty_functor(Named(Someid,loc,_),_)->[(reloc(Path.Pidentid)loc,Option.map~f:mk_lidentloc.txt)]|Tmty_with(_,ls)->List.map~f:(fun(p,l,_)->(relocpl,Somel.txt))ls|_->[]letsignature_item_paths{Typedtree.sig_desc}=matchsig_descwith|Tsig_open{Typedtree.open_expr=open_path,open_txt;_}->[(relocopen_pathopen_txt,Someopen_txt.txt)]|_->[]letwith_constraint_paths=function|Twith_module(path,loc)|Twith_modsubst(path,loc)->[(relocpathloc,Someloc.txt)]|_->[]letci_paths{Typedtree.ci_id_name;ci_id_class}=[(reloc(Path.Pidentci_id_class)ci_id_name,Some(Longident.Lidentci_id_name.txt))]letnode_paths_full=letopenTypedtreeinfunction|Patternp->pattern_pathsp|Expressione->expression_pathse|Class_expre->class_expr_pathse|Class_fieldf->class_field_pathsf|Module_exprme->module_expr_pathsme|Structure_item(i,_)->structure_item_pathsi|Module_binding_name{mb_id=Somemb_id;mb_name}->[(reloc(Path.Pidentmb_id)mb_name,Option.map~f:mk_lidentmb_name.txt)]|Module_typemt->module_type_pathsmt|Signature_item(i,_)->signature_item_pathsi|Module_declaration_name{md_id=Somemd_id;md_name}->[(reloc(Path.Pidentmd_id)md_name,Option.map~f:mk_lidentmd_name.txt)]|Module_type_declaration_name{mtd_id;mtd_name}->[(reloc(Path.Pidentmtd_id)mtd_name,Some(Lidentmtd_name.txt))]|With_constraintc->with_constraint_pathsc|Core_typect->core_type_pathsct|Package_type{pack_path;pack_txt}->[(relocpack_pathpack_txt,Somepack_txt.txt)]|Value_description{val_id;val_name}->[(reloc(Path.Pidentval_id)val_name,Some(Lidentval_name.txt))]|Type_declaration{typ_id;typ_name}->[(reloc(Path.Pidenttyp_id)typ_name,Some(Lidenttyp_name.txt))]|Type_extension{tyext_path;tyext_txt}->[(reloctyext_pathtyext_txt,Sometyext_txt.txt)]|Extension_constructor{ext_id;ext_name}->[(reloc(Path.Pidentext_id)ext_name,Some(Lidentext_name.txt))]|Label_declaration{ld_id;ld_name}->[(reloc(Path.Pidentld_id)ld_name,Some(Lidentld_name.txt))]|Constructor_declaration{cd_id;cd_name}->[(reloc(Path.Pidentcd_id)cd_name,Some(Lidentcd_name.txt))]|Class_declarationci->ci_pathsci|Class_descriptionci->ci_pathsci|Class_type_declarationci->ci_pathsci|Record_field(_,{Types.lbl_res;lbl_name;_},lid_loc)->fake_pathlid_loclbl_reslbl_name|_->[]letnode_pathst=List.map(node_paths_fullt)~f:fstletnode_paths_and_longidentt=List.filter_map(node_paths_fullt)~f:(function|_,None->None|p,Somelid->Some(p,lid))letnode_is_constructor=function|Constructor_declarationdecl->Some{decl.cd_namewithLocation.txt=`Declarationdecl}|Expression{exp_desc=Texp_construct(loc,desc,_)}->Some{locwithLocation.txt=`Descriptiondesc}|Pattern{pat_desc=Tpat_construct(loc,desc,_,_)}->Some{locwithLocation.txt=`Descriptiondesc}|Extension_constructorext_cons->Some{Location.loc=ext_cons.ext_loc;txt=`Extension_constructorext_cons}|_->Noneletnode_of_binary_partenvpart=letopenCmt_formatinmatchpartwith|Partial_structurex->Structurex|Partial_structure_itemx->Structure_item(x,env)|Partial_expressionx->Expressionx|Partial_pattern(_,x)->Patternx|Partial_class_exprx->Class_exprx|Partial_signaturex->Signaturex|Partial_signature_itemx->Signature_item(x,env)|Partial_module_typex->Module_typexletall_holes(env,node)=letrecauxacc(env,node)=letfenvnodeacc=matchnodewith|Expression{exp_desc=Texp_hole;exp_loc;exp_type;exp_env;_}->(exp_loc,exp_env,`Expexp_type)::acc|Module_expr{mod_desc=Tmod_hole;mod_loc;mod_type;mod_env;_}->(mod_loc,mod_env,`Modmod_type)::acc|_->auxacc(env,node)infold_nodefenvnodeaccinaux[](env,node)|>List.rev