123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793# 1 "src/loader/ident_env.cppo.ml"(*
* 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=l2let hash=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;}let empty()={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|`ModuleType ofIdent.t*bool*Location.toption|`Type ofIdent.t*bool*Location.toption|`Constructor ofIdent.t*Ident.t*Location.toption(* Second ident.t is for the type parent *)|`ValueofIdent.t*bool*Location.toption|`Class ofIdent.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=letopen Compatinfunction|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=letopenCompatinmatchitems with|item::rest->letvis'=extract_visibilityiteminifvis=vis'thenlethidden=vis'=Hiddeninextract_signature_type_items_extractvis~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=match td.type_kindwith# 119 "src/loader/ident_env.cppo.ml"|Types.Type_abstract_->[]# 121 "src/loader/ident_env.cppo.ml"|Type_record(_,_)->[]# 125 "src/loader/ident_env.cppo.ml"|Type_variant(cstrs,_)-># 127 "src/loader/ident_env.cppo.ml"List.map(func->`Constructor(c.Types.cd_id,id,Somec.cd_loc))cstrs|Type_open->[]in`Type(id,hidden,None)::constrs@extract_signature_type_itemsvisrest|Sig_module(id,_,_,_,_),_->`Module(id,hidden,None)::extract_signature_type_itemsvisrest|Sig_modtype(id,_,_),_->`ModuleType(id,hidden,None)::extract_signature_type_items visrest|Sig_value(id,_,_),_->`Value(id,hidden,None)::extract_signature_type_itemsvisrest# 152 "src/loader/ident_env.cppo.ml"|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# 162 "src/loader/ident_env.cppo.ml"|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_skip visitemrest=letopenCompatinmatchitem,restwith|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# 190 "src/loader/ident_env.cppo.ml"letextract_extended_openo=letopenTypedtreeinextract_signature_type_itemsHidden(Compat.signatureo.open_bound_items)# 196 "src/loader/ident_env.cppo.ml"letrecextract_signature_tree_items:bool->Typedtree.signature_itemlist->itemslist=funhide_itemitems->letopenTypedtreeinmatchitemswith# 202 "src/loader/ident_env.cppo.ml"|{sig_desc=Tsig_type(_,decls);_}::rest-># 204 "src/loader/ident_env.cppo.ml"Odoc_utils.List.concat_map(fundecl->ifBtype.is_row_name(Ident.namedecl.typ_id)then[]else`Type(decl.typ_id,hide_item,Somedecl.typ_loc)::match decl.typ_kindwithTtype_abstract->[]|Ttype_variantconstrs->List.map(func->`Constructor(c.cd_id,decl.typ_id,Somec.cd_loc))constrs|Ttype_record_->[]|Ttype_open->[])decls@extract_signature_tree_itemshide_itemrest# 220 "src/loader/ident_env.cppo.ml"|{sig_desc=Tsig_exception{tyexn_constructor;_};_}::rest-># 222 "src/loader/ident_env.cppo.ml"`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# 230 "src/loader/ident_env.cppo.ml"|{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_itemshide_itemrest|{sig_desc=Tsig_recmodule mds;_}::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# 248 "src/loader/ident_env.cppo.ml"|{sig_desc=Tsig_value{val_id;_};sig_loc;_}::rest->[`Value(val_id,hide_item,Some sig_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|{sig_desc =Tsig_include incl;_}::rest->[`Include (extract_signature_type_itemsExported(Compat.signatureincl.incl_type))]@extract_signature_tree_itemshide_itemrest|{sig_desc=Tsig_attributeattr;_}::rest->let hide_item=ifDoc_attr.is_stop_commentattrthennothide_itemelsehide_iteminextract_signature_tree_itemshide_itemrest|{sig_desc=Tsig_classcls;_}::rest->List.map(funcld->lettypehash =# 266 "src/loader/ident_env.cppo.ml"None# 268 "src/loader/ident_env.cppo.ml"in`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(funclty->lettypehash=# 280 "src/loader/ident_env.cppo.ml"None# 282 "src/loader/ident_env.cppo.ml"in`ClassType (clty.ci_id_class_type,clty.ci_id_object,typehash,hide_item,Someclty.ci_id_name.loc))cltyps@extract_signature_tree_itemshide_itemrest# 287 "src/loader/ident_env.cppo.ml"|{sig_desc=Tsig_modsubstms;sig_loc;_}::rest->[`Module(ms.ms_id,hide_item,Somesig_loc)]@extract_signature_tree_itemshide_itemrest|{sig_desc =Tsig_typesubst ts;sig_loc;_}::rest->List.map(fundecl->`Type(decl.typ_id,hide_item,Somesig_loc))ts@extract_signature_tree_itemshide_itemrest# 294 "src/loader/ident_env.cppo.ml"|{sig_desc=Tsig_modtypesubstmtd;sig_loc;_}::rest->[`ModuleType(mtd.mtd_id,hide_item,Somesig_loc)]@extract_signature_tree_itemshide_itemrest# 297 "src/loader/ident_env.cppo.ml"|{sig_desc=Tsig_open_;_}::rest->extract_signature_tree_itemshide_itemrest|[]->[]letrecread_patternhide_itempat=letopenTypedtreeinmatchpat.pat_descwith# 306 "src/loader/ident_env.cppo.ml"|Tpat_var(id,loc,_)-># 308 "src/loader/ident_env.cppo.ml"[`Value(id,hide_item,Someloc.loc)]# 312 "src/loader/ident_env.cppo.ml"|Tpat_alias(pat,id,loc,_)-># 316 "src/loader/ident_env.cppo.ml"`Value(id,hide_item,Someloc.loc)::read_patternhide_item pat|Tpat_record(pats,_)->List.concat(List.map(fun(_,_,pat)->read_patternhide_itempat)pats)# 322 "src/loader/ident_env.cppo.ml"|Tpat_construct(_,_,pats,_)# 325 "src/loader/ident_env.cppo.ml"|Tpat_arraypats->List.concat(List.map(funpat->read_patternhide_itempat)pats)# 331 "src/loader/ident_env.cppo.ml"|Tpat_tuple pats-># 333 "src/loader/ident_env.cppo.ml"List.concat(List.map(funpat->read_patternhide_itempat)pats)# 337 "src/loader/ident_env.cppo.ml"|Tpat_or(pat,_,_)|Tpat_variant(_,Somepat,_)|Tpat_lazypat->read_patternhide_itempat|Tpat_any|Tpat_constant_|Tpat_variant(_,None,_)->[]# 345 "src/loader/ident_env.cppo.ml"letrecextract_structure_tree_items:bool->Typedtree.structure_itemlist->itemslist=funhide_itemitems->letopenTypedtreeinmatchitemswith# 351 "src/loader/ident_env.cppo.ml"|{str_desc=Tstr_type(_,decls);_}::rest->(* TODO: handle rec_flag *)# 353 "src/loader/ident_env.cppo.ml"Odoc_utils.List.concat_map(fundecl->`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_->[]|Ttype_open->[]))decls@extract_structure_tree_itemshide_itemrest# 366 "src/loader/ident_env.cppo.ml"|{str_desc =Tstr_exception {tyexn_constructor;_};_}::rest-># 368 "src/loader/ident_env.cppo.ml"`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# 377 "src/loader/ident_env.cppo.ml"|{str_desc=Tstr_value(_,vbs);_}::rest->(*TODO: handle rec_flag *)# 379 "src/loader/ident_env.cppo.ml"(List.map(funvb->read_patternhide_itemvb.vb_pat)vbs|>List.flatten)@extract_structure_tree_itemshide_itemrest# 383 "src/loader/ident_env.cppo.ml"|{str_desc=Tstr_module{mb_id=Someid;mb_loc;_};_}::rest->[`Module(id,hide_item,Somemb_loc)]@extract_structure_tree_itemshide_itemrest|{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# 399 "src/loader/ident_env.cppo.ml"|{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_comment attrthennothide_itemelsehide_iteminextract_structure_tree_itemshide_itemrest|{str_desc=Tstr_classcls;_}::rest->List.map# 411 "src/loader/ident_env.cppo.ml"(fun(cld,_)-># 413 "src/loader/ident_env.cppo.ml"`Class(cld.ci_id_class,cld.ci_id_class_type,cld.ci_id_object,# 420 "src/loader/ident_env.cppo.ml"None,# 422 "src/loader/ident_env.cppo.ml"hide_item,Somecld.ci_id_name.loc))cls@extract_structure_tree_itemshide_itemrest|{str_desc=Tstr_class_typecltyps;_}::rest->List.map(fun(_,_,clty)->`ClassType (clty.ci_id_class_type,clty.ci_id_object,# 434 "src/loader/ident_env.cppo.ml"None,# 436 "src/loader/ident_env.cppo.ml"hide_item,Someclty.ci_id_name.loc))cltyps@extract_structure_tree_itemshide_itemrest# 441 "src/loader/ident_env.cppo.ml"|{str_desc=Tstr_openo;_}::rest->((extract_extended_openo):>itemslist)@extract_structure_tree_itemshide_itemrest# 444 "src/loader/ident_env.cppo.ml"|{str_desc=Tstr_primitive{val_id;_};str_loc;_}::rest->[`Value (val_id,false,Somestr_loc)]@extract_structure_tree_itemshide_itemrest|{str_desc=Tstr_eval_;_}::rest->extract_structure_tree_itemshide_itemrest|[]->[]letflatten_includes:items list->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_existsnameitems=List.exists(function|`Module(id',_,_)when Ident.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_existsnameitems=List.exists(function |`ClassType(id',_,_,_,_)when Ident.nameid'=name->true|_->false)itemsletadd_items :Id.Signature.t->itemlist->t->t=funparentitemsenv->letopenOdoc_model.Paths.Identifierinletrecinneritemsenv=matchitemswith|`Type(t,is_hidden_item,loc)::rest->letname=Ident.nametinletis_shadowed=type_name_existsnamerestinletidentifier,shadowed=ifis_shadowedthenMk.type_(parent,TypeName.shadowed_of_stringname),t::env.shadowedelseMk.type_(parent,(ifis_hidden_itemthenTypeName.hidden_of_stringelseTypeName.make_std)name),env.shadowedinlettypes =Ident.addtidentifierenv.typesin(match locwith|Somel->LocHashtbl.addenv.loc_to_identl(identifier:>Id.any)|_->());innerrest{envwithtypes;shadowed}|`Constructor(t,t_parent,loc)::rest->let name=Ident.nametinletidentifier =letparent=Ident.find_samet_parentenv.typesinMk.constructor(parent,ConstructorName.make_stdname)inletconstructors=Ident.addtidentifierenv.constructorsin(matchlocwith|Somel->LocHashtbl.addenv.loc_to_identl(identifier:>Id.any)|_->());innerrest{envwithconstructors}|`Exception(t,loc)::rest->let name=Ident.nametinletidentifier =Mk.exception_(parent,ExceptionName.make_stdname)in(match locwith |Somel->LocHashtbl.addenv.loc_to_identl(identifier:>Id.any)|_->());letexceptions=Ident.addtidentifierenv.exceptionsininnerrest{envwithexceptions}|`Extension(t,loc)::rest->letname=Ident.nametinlet identifier =Mk.extension(parent,ExtensionName.make_stdname)in(match locwith|Some l->LocHashtbl.addenv.loc_to_identl(identifier:>Id.any)|_->());letextensions=Ident.addtidentifier env.extensionsininnerrest{envwithextensions}|`Value(t,is_hidden_item,loc)::rest->letname=Ident.nametinlet is_shadowed=value_name_existsnamerestinletidentifier,shadowed=ifis_shadowedthenMk.value(parent,ValueName.shadowed_of_stringname),t::env.shadowedelseMk.value(parent,(ifis_hidden_item thenValueName.hidden_of_stringelseValueName.make_std)name),env.shadowedinletvalues=Ident.addtidentifier env.valuesin(matchlocwith|Somel->LocHashtbl.addenv.loc_to_identl(identifier:>Id.any)|_->());innerrest{envwithvalues;shadowed}|`ModuleType(t,is_hidden_item,loc)::rest->letname=Ident.nametinletis_shadowed=module_type_name_exists namerestinletidentifier,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.addtidentifierenv.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_shadowedthenMk.module_(parent,ModuleName.shadowed_of_string name),t::env.shadowedelseMk.module_(parent,(ifis_hidden_itemthenModuleName.hidden_of_stringelseModuleName.make_std)name),env.shadowedinletpath =`Identifier(identifier,is_hidden_item||is_shadowed)inletmodules=Ident.addtidentifierenv.modulesinletmodule_paths=Ident.addtpathenv.module_paths in(matchlocwith|Somel->LocHashtbl.addenv.loc_to_identl(identifier:>Id.any)|_->());inner rest{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]inletidentifier,shadowed=ifis_shadowedthenMk.class_(parent,TypeName.shadowed_of_stringname),class_types@env.shadowedelseMk.class_(parent,(ifis_hidden_item thenTypeName.hidden_of_stringelseTypeName.make_std)name),env.shadowedinletclasses=List.fold_right(funidclasses->Ident.addididentifierclasses)class_types env.classesin(matchlocwith|Somel->LocHashtbl.addenv.loc_to_identl(identifier :>Id.any)|_->());inner rest{envwithclasses;shadowed }|`ClassType(t,t2,t3,is_hidden_item,loc)::rest ->letname=Ident.nametinletis_shadowed=class_type_name_exists name restinletclass_types=matcht3with|None ->[t;t2]|Somet3->[t;t2;t3]inletidentifier,shadowed=ifis_shadowedthen Mk.class_type(parent,TypeName.shadowed_of_stringname),class_types @env.shadowedelseMk.class_type(parent,(ifis_hidden_itemthenTypeName.hidden_of_stringelseTypeName.make_std)name),env.shadowedinletclass_types=List.fold_right(funidclass_types->Ident.addid identifierclass_types)class_typesenv.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->Nonelet iter_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=funparentsgenv ->letitems=extract_signature_tree_itemsfalse sg.sig_items|>flatten_includesinadd_itemsparentitemsenvletadd_structure_tree_items:Paths.Identifier.Signature.t->Typedtree.structure->t->t=fun parentsgenv->letitems=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 parentidname env=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.addidoidenv.parametersin{envwithmodule_paths;modules;parameters }letfind_module envid=Ident.find_sameidenv.module_pathsletfind_module_identifierenvid=Ident.find_sameidenv.modulesletfind_parameter_identifierenvid=Ident.find_same idenv.parametersletfind_module_type envid=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_sameidenv.extensionsletfind_value_identifierenvid=Ident.find_sameidenv.values(** Lookup a type in the environment. If it isn't found, it means it's a coretype. *)letfind_typeenvid=trySome(Ident.find_sameidenv.types:>Id.Path.Type.t)with Not_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_same idenv.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_typesletis_shadowedenvid=List.memidenv.shadowedmodulePath=structletread_module_identenvid=ifIdent.persistentidthen`Root(ModuleName.of_identid)elsetryfind_module envidwithNot_found ->assertfalseletread_module_type_identenvid=try`Identifier(find_module_typeenvid,false)withNot_found->assertfalseletread_type_ident envid=matchfind_type envidwith|Someid->`Identifier(id,false)|None->`Resolved(`CoreType(TypeName.of_identid))letread_value_identenvid:Paths.Path.Value.t=`Identifier(find_value_identifierenvid,false)letread_class_type_ident envid: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 fix for PR#6650
is in the OCaml release *)(* When a type is a classtype path (with a #), the# is stripped off because
each ident is mapped to the identifier namedfor 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# 733 "src/loader/ident_env.cppo.ml"|Path.Pdot(p,s)->`Dot(read_moduleenvp,ModuleName.make_stds)# 737 "src/loader/ident_env.cppo.ml"|Path.Papply(p,arg)->`Apply(read_moduleenvp,read_module env arg)# 739"src/loader/ident_env.cppo.ml"|Path.Pextra_ty_->assertfalse# 742 "src/loader/ident_env.cppo.ml"letread_module_type env=function|Path.Pidentid-> read_module_type_identenvid# 745 "src/loader/ident_env.cppo.ml"|Path.Pdot(p,s)->`DotMT(read_moduleenvp,ModuleTypeName.make_stds)# 749 "src/loader/ident_env.cppo.ml"|Path.Papply(_,_)->assertfalse# 751 "src/loader/ident_env.cppo.ml"|Path.Pextra_ty_->assertfalse# 754 "src/loader/ident_env.cppo.ml"letread_class_type env=function|Path.Pidentid->read_class_type_identenvid# 757 "src/loader/ident_env.cppo.ml"|Path.Pdot(p,s)->`DotT(read_moduleenvp,TypeName.make_std(strip_hashs))# 761 "src/loader/ident_env.cppo.ml"|Path.Papply(_,_)->assertfalse# 763 "src/loader/ident_env.cppo.ml"|Path.Pextra_ty_->assertfalse# 769 "src/loader/ident_env.cppo.ml"letrecread_typeenv=function# 771 "src/loader/ident_env.cppo.ml"|Path.Pidentid->read_type_identenvid# 773 "src/loader/ident_env.cppo.ml"|Path.Pdot(p,s)->`DotT(read_moduleenvp,TypeName.make_std(strip_hashs))# 777 "src/loader/ident_env.cppo.ml"|Path.Papply(_,_)->assertfalse# 779 "src/loader/ident_env.cppo.ml"|Path.Pextra_ty(p,_)->read_typeenvp# 782 "src/loader/ident_env.cppo.ml"letread_valueenv=function|Path.Pidentid->read_value_identenvid# 785 "src/loader/ident_env.cppo.ml"|Path.Pdot(p,s)->`DotV(read_moduleenvp,ValueName.make_stds)# 789 "src/loader/ident_env.cppo.ml"|Path.Papply(_,_)->assertfalse# 791 "src/loader/ident_env.cppo.ml"|Path.Pextra_ty_->assertfalse# 794 "src/loader/ident_env.cppo.ml"endmoduleFragment=structletlmapread_module=function|Longident.Lidents->`Dot(`Root,s)# 803 "src/loader/ident_env.cppo.ml"|Longident.Ldot(p,s)->`Dot(read_modulep,s)# 805 "src/loader/ident_env.cppo.ml"|_->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