123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882(*
* Copyright (c) 2014 Leo White <lpw25@cl.cam.ac.uk>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)openOdoc_modelopenNamesmoduleId=Paths.IdentifiermoduleP=Paths.PathmoduleLocHashtbl=Hashtbl.Make(structtypet=Location.tletequall1l2=l1=l2lethash=Hashtbl.hashend)typet={modules:Id.Module.tIdent.tbl;parameters:Id.FunctorParameter.tIdent.tbl;module_paths:P.Module.tIdent.tbl;module_types:Id.ModuleType.tIdent.tbl;types:Id.DataType.tIdent.tbl;exceptions:Id.Exception.tIdent.tbl;extensions:Id.Extension.tIdent.tbl;constructors:Id.Constructor.tIdent.tbl;values:Id.Value.tIdent.tbl;classes:Id.Class.tIdent.tbl;class_types:Id.ClassType.tIdent.tbl;loc_to_ident:Id.tLocHashtbl.t;shadowed:Ident.tlist;}letempty()={modules =Ident.empty;parameters=Ident.empty;module_paths=Ident.empty;module_types=Ident.empty;types=Ident.empty;exceptions=Ident.empty;constructors=Ident.empty;extensions=Ident.empty;values=Ident.empty;classes=Ident.empty;class_types=Ident.empty;loc_to_ident=LocHashtbl.create100;shadowed=[];}(* The boolean is an override for whether it should be hidden - true only for
items introduced by extended open *)typeitem=[`ModuleofIdent.t*bool*Location.toption|`ModuleTypeofIdent.t*bool*Location.toption|`TypeofIdent.t*bool*Location.toption|`ConstructorofIdent.t*Ident.t*Location.toption(* Second ident.t is for the type parent *)|`ValueofIdent.t*bool*Location.toption|`ClassofIdent.t*Ident.t*Ident.t*Ident.toption*bool*Location.toption|`ClassTypeofIdent.t*Ident.t*Ident.toption*bool*Location.toption|`ExceptionofIdent.t*Location.toption(* Exceptions needs to be added to the [loc_to_ident] table. *)|`ExtensionofIdent.t*Location.toption(* Extension constructor also need to be added to the [loc_to_ident] table,
since they get an entry in the [uid_to_loc] table. *)]typeitems=[item|`Includeofitemlist]letextract_visibility=letopenCompatinfunction|Sig_type(_,_,_,vis)|Sig_module(_,_,_,_,vis)|Sig_modtype(_,_,vis)|Sig_value(_,_,vis)|Sig_class(_,_,_,vis)|Sig_class_type(_,_,_,vis)|Sig_typext(_,_,_,vis)->visletrecextract_signature_type_itemsvisitems=letopenCompatinmatch itemswith|item ::rest->letvis'=extract_visibility iteminifvis=vis'thenlethidden=vis'=Hiddeninextract_signature_type_items_extract vis~hiddenitemrestelseextract_signature_type_items_skip visitemrest|[]->[]andextract_signature_type_items_extractvis~hiddenitemrest=letopenCompatinmatchitem,restwith|Sig_type(id,td,_,_),_->ifBtype.is_row_name (Ident.nameid)thenextract_signature_type_items visrestelseletconstrs=matchtd.type_kindwith#ifOCAML_VERSION<(5,2,0)|Types.Type_abstract->[]#else|Types.Type_abstract_->[]#endif#ifdefinedOXCAML|Type_record(_,_,_)->[]|Type_record_unboxed_product(_,_,_)->[]#else|Type_record(_,_)->[]#endif#ifOCAML_VERSION<(4,13,0)|Type_variantcstrs->#elifdefinedOXCAML|Type_variant(cstrs,_,_)->#else|Type_variant(cstrs,_)->#endifList.map(func->`Constructor(c.Types.cd_id,id,Somec.cd_loc))cstrs|Type_open->[]#ifOCAML_VERSION>=(5,5,0)|Type_external_->[]#endifin`Type(id,hidden,None)::constrs@extract_signature_type_itemsvisrest|Sig_module(id,_,_,_,_),_->`Module(id,hidden,None)::extract_signature_type_items visrest|Sig_modtype(id,_,_),_->`ModuleType (id,hidden,None)::extract_signature_type_itemsvis rest|Sig_value(id,_,_),_->`Value(id,hidden,None)::extract_signature_type_itemsvisrest#ifOCAML_VERSION<(5,1,0)|Sig_class(id,_,_,_),Sig_class_type(ty_id,_,_,_)::Sig_type(obj_id,_,_,_)::Sig_type(cl_id,_,_,_)::_->`Class(id,ty_id,obj_id,Somecl_id,hidden,None):: extract_signature_type_itemsvisrest|Sig_class_type(id,_,_,_),Sig_type(obj_id,_,_,_)::Sig_type(cl_id,_,_,_)::_->`ClassType(id,obj_id,Somecl_id,hidden,None)::extract_signature_type_itemsvisrest#else|Sig_class(id,_,_,_),Sig_class_type(ty_id,_,_,_)::Sig_type(obj_id,_,_,_)::_->`Class(id,ty_id,obj_id,None,hidden,None)::extract_signature_type_itemsvisrest|Sig_class_type(id,_,_,_),Sig_type(obj_id,_,_,_)::_->`ClassType(id,obj_id,None,hidden,None)::extract_signature_type_itemsvisrest#endif|Sig_typext(id,constr,Text_exception,_),_->`Exception(id,Someconstr.ext_loc)::extract_signature_type_itemsvisrest|Sig_typext(id,constr,_,_),_->`Extension(id,Someconstr.ext_loc)::extract_signature_type_itemsvisrest|Sig_class_,_|Sig_class_type_,_->assertfalseandextract_signature_type_items_skipvisitemrest=letopenCompatinmatchitem,rest with|Sig_class_type_,Sig_type_::Sig_type _::rest|Sig_class _,Sig_class_type_::Sig_type_::Sig_type_::rest|Sig_typext_,rest|Sig_modtype_,rest|Sig_module _,rest|Sig_type_,rest|Sig_value_,rest->extract_signature_type_itemsvisrest|Sig_class_,_|Sig_class_type _,_->assertfalse#ifOCAML_VERSION>=(4,8,0)letextract_extended_openo=letopenTypedtreeinextract_signature_type_items Hidden(Compat.signatureo.open_bound_items)#endifletrecextract_signature_tree_items:bool->Typedtree.signature_itemlist-> itemslist=funhide_itemitems->letopenTypedtreeinmatchitemswith#ifOCAML_VERSION<(4,3,0)|{sig_desc=Tsig_typedecls;_}::rest->#else|{sig_desc=Tsig_type(_,decls);_}::rest->#endifOdoc_utils.List.concat_map(fundecl->ifBtype.is_row_name(Ident.namedecl.typ_id)then[]else`Type(decl.typ_id,hide_item,Somedecl.typ_loc)::matchdecl.typ_kindwithTtype_abstract->[]|Ttype_variant constrs->List.map(func->`Constructor(c.cd_id,decl.typ_id,Somec.cd_loc))constrs|Ttype_record _->[]#ifdefinedOXCAML|Ttype_record_unboxed_product _->[]#endif|Ttype_open->[]#ifOCAML_VERSION >=(5,5,0)|Ttype_external_->[]#endif)decls@extract_signature_tree_itemshide_itemrest#ifOCAML_VERSION<(4,8,0)|{sig_desc=Tsig_exceptiontyexn_constructor;_}::rest->#else|{sig_desc=Tsig_exception{tyexn_constructor;_};_}::rest->#endif`Exception(tyexn_constructor.ext_id,Sometyexn_constructor.ext_loc)::extract_signature_tree_itemshide_itemrest|{sig_desc=Tsig_typext{tyext_constructors;_};_}::rest->letx=List.map(fun{ext_id;ext_loc;_}->`Extension(ext_id,Someext_loc))tyext_constructorsinx@extract_signature_tree_itemshide_itemrest#ifOCAML_VERSION>=(4,10,0)|{sig_desc=Tsig_module{md_id=Someid;_};sig_loc;_}::rest->[`Module(id,hide_item,Somesig_loc)]@extract_signature_tree_itemshide_itemrest|{sig_desc=Tsig_module_;_}::rest->extract_signature_tree_items hide_itemrest|{sig_desc=Tsig_recmodulemds;_}::rest->List.fold_right(funmditems->matchmd.md_idwith|Someid->`Module(id,hide_item,Somemd.md_loc)::items|None->items)mds[]@extract_signature_tree_itemshide_itemrest#else|{sig_desc=Tsig_module{md_id;_};_}::rest ->[`Module(md_id,hide_item,None)]@extract_signature_tree_itemshide_itemrest|{sig_desc=Tsig_recmodulemds;_}::rest->List.map(funmd->`Module(md.md_id,hide_item,None))mds@extract_signature_tree_itemshide_itemrest#endif|{sig_desc=Tsig_value{val_id;_};sig_loc;_}::rest->[`Value(val_id,hide_item,Somesig_loc)]@extract_signature_tree_itemshide_itemrest|{sig_desc=Tsig_modtypemtd;sig_loc;_}::rest->[`ModuleType (mtd.mtd_id,hide_item,Somesig_loc)]@extract_signature_tree_itemshide_itemrest#ifdefinedOXCAML|{sig_desc=Tsig_include(incl,_);_}::rest->#else|{sig_desc=Tsig_includeincl;_}::rest->#endif[`Include(extract_signature_type_itemsExported(Compat.signatureincl.incl_type))]@extract_signature_tree_itemshide_itemrest|{sig_desc=Tsig_attributeattr;_}::rest->lethide_item=ifDoc_attr.is_stop_commentattrthennothide_itemelsehide_iteminextract_signature_tree_itemshide_itemrest|{sig_desc=Tsig_classcls;_}::rest->List.map(funcld->lettypehash=#ifOCAML_VERSION<(4,4,0)Some cld.ci_id_typesharp#elifOCAML_VERSION<(5,1,0)Somecld.ci_id_typehash#elseNone#endifin`Class(cld.ci_id_class,cld.ci_id_class_type,cld.ci_id_object,typehash,hide_item,Somecld.ci_id_name.loc))cls @extract_signature_tree_itemshide_itemrest|{sig_desc=Tsig_class_typecltyps;_}::rest->List.map(fun clty->lettypehash=#ifOCAML_VERSION <(4,4,0)Someclty.ci_id_typesharp#elifOCAML_VERSION<(5,1,0)Someclty.ci_id_typehash#elseNone#endifin`ClassType(clty.ci_id_class_type,clty.ci_id_object,typehash,hide_item,Someclty.ci_id_name.loc))cltyps@extract_signature_tree_itemshide_itemrest#ifOCAML_VERSION>=(4,8,0)|{sig_desc=Tsig_modsubstms;sig_loc;_}::rest->[`Module(ms.ms_id,hide_item,Somesig_loc)]@extract_signature_tree_itemshide_itemrest|{sig_desc =Tsig_typesubstts;sig_loc;_}::rest->List.map(fundecl->`Type(decl.typ_id,hide_item,Somesig_loc))ts@extract_signature_tree_items hide_itemrest#endif#ifOCAML_VERSION>=(4,13,0)|{sig_desc=Tsig_modtypesubstmtd;sig_loc;_}::rest->[`ModuleType(mtd.mtd_id,hide_item,Somesig_loc)]@extract_signature_tree_itemshide_itemrest#endif|{sig_desc=Tsig_open_;_}::rest->extract_signature_tree_items hide_itemrest#ifdefinedOXCAML|{sig_desc=Tsig_jkind_;_}::rest->extract_signature_tree_itemshide_itemrest#endif|[]->[]letrecread_patternhide_itempat=letopenTypedtreeinmatchpat.pat_descwith#ifOCAML_VERSION<(5,2,0)|Tpat_var(id,loc)->#elifdefined OXCAML|Tpat_var(id,loc,_,_,_)->#else|Tpat_var(id,loc,_)->#endif[`Value(id,hide_item,Someloc.loc)]#ifOCAML_VERSION<(5,2,0)|Tpat_alias(pat,id,loc)->#elifdefinedOXCAML|Tpat_alias(pat,id,loc,_,_,_,_)->#elif OCAML_VERSION<(5,4,0)|Tpat_alias(pat,id,loc,_)->#else|Tpat_alias(pat,id,loc,_,_)->#endif`Value(id,hide_item,Someloc.loc)::read_patternhide_itempat|Tpat_record(pats,_)->List.concat(List.map(fun(_,_,pat)->read_patternhide_itempat)pats)#ifdefinedOXCAML|Tpat_record_unboxed_product(pats,_)->List.concat(List.map(fun(_,_,pat)->read_patternhide_itempat)pats)#endif#ifOCAML_VERSION<(4,13,0)|Tpat_construct(_,_,pats)#else|Tpat_construct(_,_,pats,_)#endif#ifdefinedOXCAML|Tpat_array(_,_,pats)->List.concat(List.map(funpat->read_patternhide_itempat)pats)#elifOCAML_VERSION<(5,4,0)|Tpat_arraypats->List.concat(List.map(funpat->read_patternhide_itempat)pats)#else|Tpat_array(_,pats)->List.concat(List.map(funpat->read_patternhide_itempat)pats)#endif|Tpat_tuple pats->#ifOCAML_VERSION>=(5,4,0)||definedOXCAMLList.concat(List.map(fun(_lbl,pat)->read_patternhide_itempat)pats)#elseList.concat(List.map(funpat-> read_patternhide_itempat)pats)#endif#ifdefinedOXCAML|Tpat_unboxed_tuplepats->List.concat(List.map(fun(_,pat,_)->read_patternhide_itempat)pats)#endif|Tpat_or(pat,_,_)|Tpat_variant(_,Somepat,_)|Tpat_lazy pat ->read_patternhide_itempat|Tpat_any|Tpat_constant_|Tpat_variant(_,None,_)->[]#ifOCAML_VERSION>=(4,8,0)&&OCAML_VERSION<(4,11,0)|Tpat_exceptionpat->read_patternhide_itempat#endif#ifdefinedOXCAML|Tpat_unboxed_unit->[]|Tpat_unboxed_bool_->[]#endifletrecextract_structure_tree_items:bool->Typedtree.structure_itemlist->itemslist=fun hide_itemitems->letopenTypedtreeinmatchitemswith#ifOCAML_VERSION<(4,3,0)|{str_desc=Tstr_typedecls;_}::rest->#else|{str_desc=Tstr_type(_,decls);_}::rest->(* TODO: handle rec_flag *)#endifOdoc_utils.List.concat_map(fundecl->`Type (decl.typ_id,hide_item,Somedecl.typ_loc)::(matchdecl.typ_kindwithTtype_abstract ->[]|Ttype_variantconstrs->List.map(func->`Constructor(c.cd_id,decl.typ_id,Some c.cd_loc))constrs|Ttype_record_->[]#ifdefined OXCAML|Ttype_record_unboxed_product_->[]#endif|Ttype_open ->[]#ifOCAML_VERSION>=(5,5,0)|Ttype_external_->[]#endif))decls@extract_structure_tree_itemshide_itemrest#ifOCAML_VERSION<(4,8,0)|{str_desc=Tstr_exceptiontyexn_constructor;_}::rest ->#else|{str_desc =Tstr_exception{tyexn_constructor;_};_}::rest->#endif`Exception(tyexn_constructor.ext_id,Sometyexn_constructor.ext_loc)::extract_structure_tree_itemshide_itemrest|{str_desc=Tstr_typext{tyext_constructors;_};_}::rest->letx=List.map(fun{ext_id;ext_loc;_}->`Extension(ext_id,Someext_loc))tyext_constructorsinx@extract_structure_tree_itemshide_itemrest#ifOCAML_VERSION<(4,3,0)|{str_desc=Tstr_value(_,vbs);_}::rest->#else|{str_desc=Tstr_value(_,vbs);_}::rest->(*TODO: handle rec_flag *)#endif(List.map(funvb->read_patternhide_itemvb.vb_pat)vbs|>List.flatten)@extract_structure_tree_itemshide_itemrest#ifOCAML_VERSION>=(4,10,0)|{str_desc=Tstr_module{mb_id=Someid;mb_loc;_};_}::rest->[`Module(id,hide_item,Somemb_loc)]@extract_structure_tree_itemshide_item rest|{str_desc=Tstr_module_;_}::rest ->extract_structure_tree_itemshide_itemrest|{str_desc =Tstr_recmodulembs;_}::rest->List.fold_right(funmbitems->matchmb.mb_idwith|Someid->`Module(id,hide_item,Somemb.mb_loc):: items|None->items)mbs[]@extract_structure_tree_itemshide_itemrest#else|{str_desc=Tstr_module{mb_id;mb_loc;_};_}::rest->[`Module(mb_id,hide_item,Somemb_loc)]@extract_structure_tree_itemshide_itemrest|{str_desc=Tstr_recmodulembs;_}::rest->List.map(fun mb->`Module(mb.mb_id,hide_item,None))mbs@extract_structure_tree_itemshide_itemrest#endif|{str_desc=Tstr_modtypemtd;str_loc;_}::rest->[`ModuleType(mtd.mtd_id,hide_item,Somestr_loc)]@extract_structure_tree_itemshide_itemrest|{str_desc=Tstr_includeincl;_}::rest->[`Include(extract_signature_type_itemsExported(Compat.signatureincl.incl_type))]@extract_structure_tree_itemshide_itemrest|{str_desc=Tstr_attributeattr;_}::rest->lethide_item=ifDoc_attr.is_stop_commentattrthennothide_itemelsehide_iteminextract_structure_tree_itemshide_itemrest|{str_desc =Tstr_classcls;_}::rest->List.map#ifOCAML_VERSION <(4,3,0)(fun(cld,_,_)->#else(fun(cld,_)->#endif`Class (cld.ci_id_class,cld.ci_id_class_type,cld.ci_id_object,#ifOCAML_VERSION<(4,4,0)Somecld.ci_id_typesharp,#elifOCAML_VERSION<(5,1,0)Somecld.ci_id_typehash,#elseNone,#endifhide_item,Somecld.ci_id_name.loc))cls@extract_structure_tree_items hide_itemrest|{str_desc=Tstr_class_type cltyps;_}::rest->List.map(fun(_,_,clty)->`ClassType(clty.ci_id_class_type,clty.ci_id_object,#ifOCAML_VERSION<(4,4,0)Someclty.ci_id_typesharp,#elifOCAML_VERSION<(5,1,0)Some clty.ci_id_typehash,#elseNone,#endifhide_item,Someclty.ci_id_name.loc))cltyps@extract_structure_tree_itemshide_itemrest#ifOCAML_VERSION <(4,8,0)|{str_desc=Tstr_open_;_}::rest->extract_structure_tree_itemshide_itemrest#else|{str_desc=Tstr_openo;_}::rest->((extract_extended_openo):>itemslist)@extract_structure_tree_itemshide_itemrest#endif|{str_desc=Tstr_primitive{val_id;_};str_loc;_}::rest->[`Value(val_id,false,Somestr_loc)]@extract_structure_tree_items hide_item rest|{str_desc =Tstr_eval_;_}:: rest->extract_structure_tree_itemshide_itemrest#ifdefined OXCAML|{str_desc=Tstr_jkind_;_}::rest->extract_structure_tree_itemshide_itemrest#endif|[]->[]letflatten_includes:itemslist->itemlist=funitems->List.map(function|`Type _|`Constructor_|`Module_|`ModuleType _|`Value_|`Class_|`Exception_|`Extension_|`ClassType_asx->[x]|`Includexs->xs)items|>List.flattenlettype_name_existsnameitems=List.exists(function|`Type(id',_,_)whenIdent.nameid'=name ->true|_->false)itemsletvalue_name_existsnameitems=List.exists(function |`Value(id',_,_)whenIdent.nameid'=name->true |_->false)itemsletmodule_name_exists nameitems=List.exists(function|`Module(id',_,_)whenIdent.nameid'=name->true|_->false)itemsletmodule_type_name_existsnameitems=List.exists(function|`ModuleType (id',_,_)whenIdent.nameid'=name->true|_->false)itemsletclass_name_existsnameitems=List.exists (function |`Class(id',_,_,_,_,_)whenIdent.nameid'=name->true|_->false)itemsletclass_type_name_exists nameitems=List.exists(function|`ClassType(id',_,_,_,_)whenIdent.nameid'=name->true|_->false)itemsletadd_items :Id.Signature.t->itemlist->t->t=funparent items env->letopenOdoc_model.Paths.Identifierinletrecinneritemsenv=matchitemswith|`Type(t,is_hidden_item,loc)::rest->letname=Ident.nametinlet is_shadowed=type_name_existsnamerestinletidentifier,shadowed =ifis_shadowedthenMk.type_(parent,TypeName.shadowed_of_stringname),t::env.shadowedelseMk.type_(parent,(ifis_hidden_item thenTypeName.hidden_of_stringelseTypeName.make_std)name),env.shadowedinlettypes=Ident.addtidentifierenv.typesin(matchlocwith|Somel->LocHashtbl.addenv.loc_to_identl(identifier:>Id.any)|_->());innerrest{envwithtypes;shadowed}|`Constructor(t,t_parent,loc)::rest->letname=Ident.nametinletidentifier=letparent=Ident.find_samet_parentenv.types inMk.constructor(parent,ConstructorName.make_std name)inletconstructors =Ident.addtidentifierenv.constructors in(matchlocwith|Somel->LocHashtbl.addenv.loc_to_identl(identifier:>Id.any)|_->());innerrest{envwithconstructors}|`Exception(t,loc)::rest->letname =Ident.nametinletidentifier=Mk.exception_(parent,ExceptionName.make_stdname)in(matchlocwith|Somel->LocHashtbl.addenv.loc_to_identl(identifier:>Id.any)|_->());letexceptions =Ident.addtidentifierenv.exceptionsininnerrest {envwith exceptions}|`Extension (t,loc)::rest->letname=Ident.nametinletidentifier=Mk.extension(parent,ExtensionName.make_std name)in(matchlocwith|Somel->LocHashtbl.addenv.loc_to_ident l(identifier:>Id.any)|_->());let extensions=Ident.addtidentifierenv.extensionsininnerrest{envwithextensions}|`Value(t,is_hidden_item,loc)::rest->letname=Ident.nametinletis_shadowed=value_name_existsnamerestinlet identifier,shadowed =ifis_shadowedthenMk.value(parent,ValueName.shadowed_of_stringname),t::env.shadowedelseMk.value(parent,(ifis_hidden_itemthenValueName.hidden_of_string elseValueName.make_std)name),env.shadowedinlet values=Ident.addtidentifierenv.values in(matchlocwith|Somel->LocHashtbl.addenv.loc_to_ident l(identifier:>Id.any)|_->());innerrest{envwithvalues;shadowed}|`ModuleType(t,is_hidden_item,loc)::rest->letname=Ident.nametinletis_shadowed=module_type_name_existsnamerestinletidentifier,shadowed=ifis_shadowedthenMk.module_type(parent,ModuleTypeName.shadowed_of_stringname),t::env.shadowedelseMk.module_type(parent,(ifis_hidden_itemthenModuleTypeName.hidden_of_stringelseModuleTypeName.make_std)name),env.shadowedinletmodule_types=Ident.addtidentifier env.module_typesin(matchlocwith|Somel->LocHashtbl.addenv.loc_to_identl(identifier:>Id.any)|_->());innerrest{envwithmodule_types;shadowed }|`Module(t,is_hidden_item,loc)::rest->letname=Ident.nametinletis_shadowed=module_name_existsnamerestinletidentifier,shadowed=ifis_shadowedthen Mk.module_(parent,ModuleName.shadowed_of_stringname),t::env.shadowedelseMk.module_(parent,(ifis_hidden_item thenModuleName.hidden_of_stringelseModuleName.make_std)name),env.shadowedinletpath=`Identifier(identifier,is_hidden_item||is_shadowed)inletmodules=Ident.addtidentifierenv.modulesinletmodule_paths =Ident.addtpathenv.module_pathsin(matchlocwith|Somel->LocHashtbl.addenv.loc_to_identl(identifier:>Id.any)|_->());innerrest{envwithmodules;module_paths;shadowed}|`Class(t,t2,t3,t4,is_hidden_item,loc)::rest->letname =Ident.nametinletis_shadowed=class_name_existsnamerestinletclass_types =matcht4with|None->[t;t2;t3]|Somet4->[t;t2;t3;t4]inlet identifier,shadowed =ifis_shadowedthenMk.class_(parent,TypeName.shadowed_of_stringname),class_types@env.shadowedelseMk.class_(parent,(ifis_hidden_itemthenTypeName.hidden_of_string elseTypeName.make_std)name),env.shadowedinletclasses=List.fold_right (fun idclasses->Ident.addididentifierclasses)class_types env.classesin(match locwith|Somel->LocHashtbl.addenv.loc_to_identl(identifier:>Id.any)|_->());innerrest{envwithclasses;shadowed}|`ClassType(t,t2,t3,is_hidden_item,loc)::rest->let name =Ident.nametinletis_shadowed =class_type_name_exists namerestinletclass_types=matcht3 with|None->[t;t2]|Somet3->[t;t2;t3]inletidentifier,shadowed=ifis_shadowedthenMk.class_type(parent,TypeName.shadowed_of_string name),class_types@env.shadowedelseMk.class_type(parent,(ifis_hidden_itemthenTypeName.hidden_of_string elseTypeName.make_std)name),env.shadowedinletclass_types=List.fold_right(funidclass_types->Ident.addid identifierclass_types)class_types env.class_typesin(matchlocwith|Somel->LocHashtbl.addenv.loc_to_ident l(identifier:>Id.any)|_->());innerrest{envwithclass_types;shadowed}|[]->envininneritemsenvletidentifier_of_loc:t->Location.t->Odoc_model.Paths.Identifier.toption =funenvloc->trySome(LocHashtbl.findenv.loc_to_identloc)withNot_found ->Noneletiter_located_identifier:t->(Location.t->Odoc_model.Paths.Identifier.t->unit)->unit=funenvf->LocHashtbl.iterfenv.loc_to_identletadd_signature_tree_items:Paths.Identifier.Signature.t->Typedtree.signature->t->t=funparent sgenv->letitems=extract_signature_tree_itemsfalsesg.sig_items|>flatten_includes inadd_itemsparentitemsenvletadd_structure_tree_items :Paths.Identifier.Signature.t->Typedtree.structure->t->t=funparentsgenv->let items=extract_structure_tree_itemsfalsesg.str_items|>flatten_includes inadd_itemsparentitemsenvlethandle_signature_type_items:Paths.Identifier.Signature.t->Compat.signature->t->t=funparentsgenv->letitems=extract_signature_type_itemsExportedsginadd_itemsparentitemsenvletadd_parameter parentidnameenv=lethidden=ModuleName.is_hiddennameinletoid=Odoc_model.Paths.Identifier.Mk.parameter(parent,name)inletpath=`Identifier(oid,hidden)inletmodule_paths=Ident.addidpathenv.module_pathsinletmodules=Ident.addidoidenv.modulesinletparameters=Ident.addidoid env.parametersin{envwithmodule_paths;modules;parameters}letadd_module_argparentidnameenv=letoid=Odoc_model.Paths.Identifier.Mk.(parameter(parent,name))inletpath=`Identifier(oid,false)inletmodule_paths=Ident.addidpathenv.module_pathsinletmodules=Ident.addidoidenv.modulesin{envwithmodule_paths;modules},oidletfind_moduleenvid=Ident.find_sameidenv.module_pathsletfind_module_identifierenvid=Ident.find_sameidenv.modulesletfind_parameter_identifierenvid=Ident.find_sameidenv.parametersletfind_module_typeenvid=Ident.find_sameidenv.module_typesletfind_type_identifierenvid=Ident.find_sameidenv.typesletfind_constructor_identifierenvid=Ident.find_sameidenv.constructorsletfind_exception_identifierenvid=Ident.find_sameidenv.exceptionsletfind_extension_identifierenvid=Ident.find_same idenv.extensionsletfind_value_identifierenvid=Ident.find_same idenv.values(** Lookup a type in the environment. If it isn'tfound, it means it's a core
type. *)letfind_typeenvid=trySome(Ident.find_sameidenv.types:>Id.Path.Type.t)withNot_found->(trySome(Ident.find_sameidenv.classes:>Id.Path.Type.t)withNot_found->(trySome(Ident.find_sameidenv.class_types:>Id.Path.Type.t)withNot_found->None))letfind_class_typeenvid=try(Ident.find_sameidenv.classes:>Id.Path.ClassType.t)withNot_found->(Ident.find_sameidenv.class_types:>Id.Path.ClassType.t)letfind_class_identifierenvid=Ident.find_sameidenv.classesletfind_class_type_identifierenvid=Ident.find_sameidenv.class_typesletident_is_global_or_predefid=#ifdefinedOXCAMLIdent.is_global_or_predefid#elseIdent.persistentid#endifletis_shadowedenvid=List.memidenv.shadowedmodulePath=structletread_module_identenvid=ifident_is_global_or_predefidthen`Root(ModuleName.of_identid)elsetryfind_moduleenvidwithNot_found->assertfalseletread_module_type_identenvid=try`Identifier(find_module_typeenvid,false)withNot_found->assertfalseletread_type_identenvid=matchfind_typeenv idwith|Someid-> `Identifier(id,false)|None->`Resolved(`CoreType(TypeName.of_identid))letread_value_ident envid:Paths.Path.Value.t=`Identifier(find_value_identifierenvid,false)letread_class_type_identenvid:Paths.Path.ClassType.t=try`Identifier(find_class_typeenvid,false)withNot_found->`DotT(`Root(ModuleName.make_std "*"),(TypeName.of_identid))(* TODO remove this hack once the fixfor PR#6650
is in theOCaml release *)(* When a type is a classtype path (with a #), the # is stripped off because
each ident is mapped to the identifier named for the ident without a
hash. e.g. in the following, we take the name of the identifier from cd_id_class, and therefore even [Pident #u/10] will map to identifier
[u].
Typedtree.Tsig_class_type
[{Typedtree.ci_virt = Asttypes.Concrete; ci_params = [];
ci_id_name = {Asttypes.txt = ...; loc = ...}; ci_id_class = u/13[14];
ci_id_class_type = u/12[14]; ci_id_object = u/11[14];
ci_id_typehash = #u/10[14];
For a dotted path though, we have to strip the # off manually here, so
[read_class_type] and [read_type] both need the following function.
*)letstrip_hashs=ifs.[0]='#'thenString.subs1(String.lengths-1)elsesletrecread_module:t->Path.t->Paths.Path.Module.t=funenv->function|Path.Pidentid->read_module_identenvid#ifOCAML_VERSION>=(4,8,0)|Path.Pdot(p,s)->`Dot(read_moduleenvp,ModuleName.make_stds)#else|Path.Pdot(p,s,_)->`Dot(read_moduleenvp,ModuleName.make_stds)#endif|Path.Papply(p,arg)->`Apply(read_moduleenvp,read_moduleenvarg)#ifOCAML_VERSION>=(5,1,0)|Path.Pextra_ty_->assertfalse#endifletread_module_typeenv=function|Path.Pidentid->read_module_type_identenvid#ifOCAML_VERSION>=(4,8,0)|Path.Pdot(p,s)->`DotMT(read_moduleenvp,ModuleTypeName.make_stds)#else|Path.Pdot(p,s,_)->`DotMT(read_moduleenvp,ModuleTypeName.make_stds)#endif|Path.Papply(_,_)->assertfalse#ifOCAML_VERSION>=(5,1,0)|Path.Pextra_ty_->assertfalse#endifletread_class_typeenv=function|Path.Pidentid->read_class_type_identenvid#ifOCAML_VERSION>=(4,8,0)|Path.Pdot(p,s)->`DotT(read_moduleenvp,TypeName.make_std(strip_hashs))#else|Path.Pdot(p,s,_)->`DotT(read_moduleenvp,TypeName.make_std(strip_hashs))#endif|Path.Papply(_,_)->assertfalse#ifOCAML_VERSION>=(5,1,0)|Path.Pextra_ty_->assertfalse#endif#ifOCAML_VERSION<(5,1,0)letread_typeenv=function#elseletrecread_typeenv=function#endif|Path.Pidentid->read_type_identenvid#ifOCAML_VERSION>=(4,8,0)|Path.Pdot(p,s)->`DotT(read_moduleenvp,TypeName.make_std(strip_hashs))#else|Path.Pdot(p,s,_)->`DotT(read_moduleenvp,TypeName.make_std(strip_hashs))#endif|Path.Papply(_,_)->assertfalse#ifOCAML_VERSION>=(5,1,0)|Path.Pextra_ty(p,_)->read_typeenvp#endifletread_valueenv=function|Path.Pidentid->read_value_identenvid#ifOCAML_VERSION>=(4,8,0)|Path.Pdot(p,s)->`DotV(read_moduleenvp,ValueName.make_stds)#else|Path.Pdot(p,s,_)->`DotV(read_moduleenvp,ValueName.make_stds)#endif|Path.Papply(_,_)->assertfalse#ifOCAML_VERSION>=(5,1,0)|Path.Pextra_ty_->assertfalse#endifendmoduleFragment=structletlmapread_module=function|Longident.Lidents->`Dot(`Root,s)#ifOCAML_VERSION>=(5,4,0)|Longident.Ldot(p,s)->`Dot(read_modulep.txt,s.txt)#else|Longident.Ldot(p,s)->`Dot(read_modulep,s)#endif|_->assertfalseletrecread_module:Longident.t->Paths.Fragment.Module.t=funl->lmap(funp->(read_modulep:>Paths.Fragment.Signature.t))lletread_module_type:Longident.t->Paths.Fragment.ModuleType.t=lmap(funp->(read_modulep:>Paths.Fragment.Signature.t))letread_type=lmap(funp->(read_modulep:>Paths.Fragment.Signature.t))end