123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747# 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.Pathtypetype_ident =Paths.Identifier.Path.Type.tmoduleLocHashtbl=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;hidden:Ident.tlist;(* we use term hidden to mean shadowed and idents_in_doc_off_mode items*)}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;hidden=[];}(* 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]letrecextract_signature_type_itemsvisitems=letopenCompatinmatch items with|Sig_type(id,td,_,vis')::restwhenvis=vis'->ifBtype.is_row_name (Ident.nameid)thenextract_signature_type_items visrestelseletconstrs=match td.type_kindwith# 97 "src/loader/ident_env.cppo.ml"|Types.Type_abstract_->[]# 99 "src/loader/ident_env.cppo.ml"|Type_record(_,_)->[]# 103 "src/loader/ident_env.cppo.ml"|Type_variant(cstrs,_)-># 105 "src/loader/ident_env.cppo.ml"List.map(func->`Constructor(c.Types.cd_id,id,Somec.cd_loc))cstrs|Type_open->[]in`Type(id,vis'=Hidden,None)::constrs@extract_signature_type_itemsvisrest|Sig_module(id,_,_,_,vis')::restwhenvis=vis'->`Module(id,vis'=Hidden,None)::extract_signature_type_itemsvisrest|Sig_modtype(id,_,vis')::restwhenvis=vis'->`ModuleType(id,vis'=Hidden,None)::extract_signature_type_itemsvisrest|Sig_value(id,_,vis')::restwhenvis=vis'->`Value(id,vis'=Hidden,None)::extract_signature_type_itemsvisrest# 126 "src/loader/ident_env.cppo.ml"|Sig_class(id,_,_,vis')::Sig_class_type(ty_id,_,_,_)::Sig_type(obj_id,_,_,_)::restwhenvis=vis'->`Class(id,ty_id,obj_id,None,vis'=Hidden,None)::extract_signature_type_itemsvisrest|Sig_class_type(id,_,_,vis')::Sig_type(obj_id,_,_,_)::restwhenvis=vis'->`ClassType (id,obj_id,None,vis'=Hidden,None)::extract_signature_type_itemsvisrest# 134 "src/loader/ident_env.cppo.ml"|Sig_typext(id,constr,Text_exception,vis')::restwhenvis=vis'->`Exception(id,Someconstr.ext_loc)::extract_signature_type_items visrest|Sig_typext (id,constr,_,vis')::restwhenvis=vis'->`Extension(id,Someconstr.ext_loc)::extract_signature_type_itemsvisrest|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|[]->[]# 160 "src/loader/ident_env.cppo.ml"let extract_extended_openo=letopenTypedtreeinextract_signature_type_itemsHidden(Compat.signatureo.open_bound_items)# 166 "src/loader/ident_env.cppo.ml"letconcat_mapfl=let recauxfacc=function|[]->List.revacc|x::l->letxs=fxinauxf(List.rev_appendxsacc)linauxf[]lletrecextract_signature_tree_items:bool->Typedtree.signature_itemlist->itemslist=funhide_itemitems->letopen Typedtreeinmatchitemswith# 180 "src/loader/ident_env.cppo.ml"|{sig_desc=Tsig_type(_,decls);_}::rest-># 182 "src/loader/ident_env.cppo.ml"concat_map(fundecl->ifBtype.is_row_name(Ident.namedecl.typ_id)then[]else`Type(decl.typ_id,hide_item,Somedecl.typ_loc)::matchdecl.typ_kind withTtype_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# 198 "src/loader/ident_env.cppo.ml"|{sig_desc=Tsig_exception{tyexn_constructor;_};_}::rest-># 200 "src/loader/ident_env.cppo.ml"`Exception(tyexn_constructor.ext_id,Sometyexn_constructor.ext_loc)::extract_signature_tree_itemshide_item rest|{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_items hide_itemrest# 208 "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_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# 226 "src/loader/ident_env.cppo.ml"|{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_items hide_itemrest|{sig_desc=Tsig_includeincl;_}::rest->[`Include (extract_signature_type_itemsExported(Compat.signatureincl.incl_type))]@extract_signature_tree_items hide_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 =# 244 "src/loader/ident_env.cppo.ml"None# 246 "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_items hide_itemrest|{sig_desc=Tsig_class_typecltyps;_}::rest->List.map(funclty ->lettypehash =# 258 "src/loader/ident_env.cppo.ml"None# 260 "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# 265 "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_typesubstts;sig_loc;_}::rest->List.map(fundecl->`Type(decl.typ_id,hide_item,Somesig_loc))ts@extract_signature_tree_itemshide_itemrest# 272 "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# 275 "src/loader/ident_env.cppo.ml"|{sig_desc=Tsig_open_;_}::rest->extract_signature_tree_itemshide_itemrest|[]->[]let recread_patternhide_itempat=letopenTypedtreeinmatchpat.pat_descwith#284 "src/loader/ident_env.cppo.ml"|Tpat_var(id,loc,_)-># 286 "src/loader/ident_env.cppo.ml"[`Value(id,hide_item,Someloc.loc)]# 290 "src/loader/ident_env.cppo.ml"|Tpat_alias(pat,id,loc,_)-># 292 "src/loader/ident_env.cppo.ml"`Value(id,hide_item,Someloc.loc)::read_patternhide_itempat|Tpat_record(pats,_)->List.concat(List.map(fun(_,_,pat)->read_patternhide_itempat)pats)# 298 "src/loader/ident_env.cppo.ml"|Tpat_construct(_,_,pats,_)# 300 "src/loader/ident_env.cppo.ml"|Tpat_arraypats|Tpat_tuplepats->List.concat(List.map(funpat->read_patternhide_itempat)pats)|Tpat_or(pat,_,_)|Tpat_variant(_,Somepat,_)|Tpat_lazypat->read_patternhide_itempat|Tpat_any|Tpat_constant_|Tpat_variant(_,None,_)->[]# 310 "src/loader/ident_env.cppo.ml"letrecextract_structure_tree_items:bool->Typedtree.structure_itemlist->itemslist=funhide_itemitems->letopenTypedtreeinmatchitemswith# 316 "src/loader/ident_env.cppo.ml"|{str_desc=Tstr_type(_,decls);_}::rest->(* TODO: handle rec_flag *)# 318 "src/loader/ident_env.cppo.ml"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,Somec.cd_loc))constrs|Ttype_record_->[]|Ttype_open->[]))decls@extract_structure_tree_itemshide_itemrest# 331 "src/loader/ident_env.cppo.ml"|{str_desc=Tstr_exception{tyexn_constructor;_};_}::rest-># 333 "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# 342 "src/loader/ident_env.cppo.ml"|{str_desc=Tstr_value(_,vbs);_}::rest->(*TODO: handle rec_flag *)# 344 "src/loader/ident_env.cppo.ml"(List.map(funvb->read_patternhide_itemvb.vb_pat)vbs|>List.flatten)@extract_structure_tree_itemshide_itemrest# 348 "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# 364 "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_commentattrthennothide_itemelsehide_iteminextract_structure_tree_itemshide_itemrest|{str_desc=Tstr_classcls;_}::rest->List.map# 376 "src/loader/ident_env.cppo.ml"(fun(cld,_)-># 378 "src/loader/ident_env.cppo.ml"`Class (cld.ci_id_class,cld.ci_id_class_type,cld.ci_id_object,# 385 "src/loader/ident_env.cppo.ml"None,# 387 "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,# 399 "src/loader/ident_env.cppo.ml"None,# 401 "src/loader/ident_env.cppo.ml"hide_item,Someclty.ci_id_name.loc))cltyps@extract_structure_tree_itemshide_itemrest# 406 "src/loader/ident_env.cppo.ml"|{str_desc=Tstr_openo;_}::rest->((extract_extended_openo):>itemslist)@extract_structure_tree_itemshide_itemrest# 409 "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: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_existsnameitems=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',_,_,_,_,_)when Ident.nameid'=name->true|_->false)itemsletclass_type_name_existsnameitems=List.exists(function|`ClassType(id',_,_,_,_)whenIdent.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_hidden=is_hidden_item||type_name_existsnamerestinletidentifier,hidden=ifis_hiddenthenMk.type_(parent,TypeName.internal_of_stringname),t::env.hiddenelseMk.type_(parent,TypeName.make_stdname),env.hiddeninlettypes=Ident.addtidentifierenv.typesin(matchlocwith|Somel->LocHashtbl.addenv.loc_to_identl(identifier:>Id.any)|_->());innerrest{envwithtypes;hidden}|`Constructor(t,t_parent,loc)::rest->letname=Ident.nametinletidentifier=let parent=Ident.find_samet_parentenv.typesinMk.constructor(parent,ConstructorName.make_stdname)inletconstructors=Ident.addtidentifierenv.constructorsin(matchlocwith|Somel->LocHashtbl.addenv.loc_to_identl(identifier:>Id.any)|_->());inner rest{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.addtidentifier env.exceptions ininnerrest{envwithexceptions}|`Extension (t,loc)::rest->letname=Ident.nametinletidentifier=Mk.extension(parent,ExtensionName.make_stdname)in(match locwith|Somel->LocHashtbl.addenv.loc_to_ident l(identifier :>Id.any)|_->());letextensions=Ident.addtidentifierenv.extensionsininnerrest{envwithextensions}|`Value (t,is_hidden_item,loc)::rest->letname=Ident.nametinlet is_hidden=is_hidden_item||value_name_existsnamerestinletidentifier,hidden=ifis_hiddenthenMk.value(parent,ValueName.internal_of_stringname),t::env.hiddenelseMk.value(parent,ValueName.make_stdname),env.hiddeninletvalues=Ident.add tidentifierenv.values in(matchlocwith|Somel->LocHashtbl.addenv.loc_to_identl(identifier :>Id.any)|_->());innerrest{envwithvalues;hidden}|`ModuleType(t,is_hidden_item,loc)::rest->letname =Ident.nametinletis_hidden =is_hidden_item||module_type_name_existsname restinletidentifier,hidden=ifis_hiddenthen Mk.module_type(parent,ModuleTypeName.internal_of_stringname),t::env.hiddenelseMk.module_type(parent,ModuleTypeName.make_std name),env.hiddeninletmodule_types =Ident.addtidentifier env.module_typesin(matchlocwith|Somel->LocHashtbl.add env.loc_to_identl(identifier:>Id.any)|_->());innerrest{envwithmodule_types;hidden}|`Module(t,is_hidden_item,loc)::rest->letname=Ident.nametinletdouble_underscore =Odoc_model.Root.contains_double_underscorenameinletis_hidden=is_hidden_item||module_name_existsnamerest||double_underscoreinletidentifier,hidden =ifis_hiddenthenMk.module_(parent,ModuleName.internal_of_stringname),t::env.hiddenelseMk.module_(parent,ModuleName.make_std name),env.hiddeninletpath=`Identifier(identifier,is_hidden)inletmodules=Ident.addtidentifierenv.modulesinletmodule_paths=Ident.addtpathenv.module_pathsin(matchlocwith|Somel->LocHashtbl.addenv.loc_to_ident l(identifier:>Id.any)|_->());innerrest {envwithmodules;module_paths;hidden}|`Class (t,t2,t3,t4,is_hidden_item,loc)::rest->letname=Ident.nametinletis_hidden=is_hidden_item||class_name_existsnamerestinletclass_types=matcht4with|None->[t;t2;t3]|Some t4->[t;t2;t3;t4]inletidentifier,hidden=ifis_hiddenthenMk.class_(parent,ClassName.internal_of_stringname),class_types@env.hiddenelseMk.class_(parent,ClassName.make_stdname),env.hiddeninletclasses=List.fold_right(funidclasses->Ident.addididentifierclasses)class_typesenv.classesin(matchlocwith|Somel->LocHashtbl.addenv.loc_to_identl(identifier:>Id.any)|_->());innerrest{envwithclasses;hidden}|`ClassType (t,t2,t3,is_hidden_item,loc)::rest->letname=Ident.nametinletis_hidden=is_hidden_item||class_type_name_existsnamerestinlet class_types=matcht3with|None->[t;t2]|Some t3->[t;t2;t3]inletidentifier,hidden=ifis_hiddenthenMk.class_type(parent,ClassTypeName.internal_of_stringname),class_types @env.hiddenelseMk.class_type(parent,ClassTypeName.make_stdname),env.hiddeninletclass_types =List.fold_right(funidclass_types ->Ident.addididentifier class_types)class_typesenv.class_typesin(matchlocwith|Somel->LocHashtbl.addenv.loc_to_identl(identifier:>Id.any)|_->());innerrest{envwith class_types;hidden}|[]->envininneritemsenvletidentifier_of_loc:t->Location.t->Odoc_model.Paths.Identifier.toption=funenvloc->trySome(LocHashtbl.findenv.loc_to_ident loc)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=fun parentsgenv->letitems=extract_signature_tree_itemsfalsesg.sig_items|>flatten_includesinadd_items parentitemsenvletadd_structure_tree_items:Paths.Identifier.Signature.t->Typedtree.structure ->t->t=funparentsgenv->letitems=extract_structure_tree_items false sg.str_items|>flatten_includesinadd_itemsparentitemsenvlethandle_signature_type_items:Paths.Identifier.Signature.t->Compat.signature->t->t=funparentsgenv->letitems=extract_signature_type_itemsExportedsginadd_itemsparentitemsenvletadd_parameterparentidnameenv=lethidden=ModuleName.is_hiddennameinletoid=Odoc_model.Paths.Identifier.Mk.parameter(parent,name)inletpath=`Identifier(oid,hidden)inletmodule_paths=Ident.addidpath env.module_pathsinletmodules=Ident.addidoidenv.modulesinletparameters=Ident.addidoidenv.parameters in{envwithmodule_paths;modules;parameters}let find_moduleenvid=Ident.find_sameidenv.module_pathsletfind_module_identifierenvid=Ident.find_same idenv.modulesletfind_parameter_identifierenvid=Ident.find_sameidenv.parametersletfind_module_typeenvid=Ident.find_sameidenv.module_typesletfind_type_identifierenvid=Ident.find_sameidenv.typesletfind_constructor_identifierenvid=Ident.find_same idenv.constructorslet find_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's assumed to be a
core type. *)letfind_typeenvid=try(Ident.find_sameidenv.types:>Id.Path.Type.t)withNot_found->(try(Ident.find_sameidenv.classes:>Id.Path.Type.t)withNot_found ->(try(Ident.find_sameidenv.class_types:>Id.Path.Type.t)withNot_found ->(Paths.Identifier.Mk.core_type(Ident.nameid):>type_ident)))letfind_class_typeenvid=try(Ident.find_sameidenv.classes:>Id.Path.ClassType.t)withNot_found ->(Ident.find_sameid env.class_types:>Id.Path.ClassType.t)letfind_class_identifier env id=Ident.find_sameidenv.classesletfind_class_type_identifierenvid=Ident.find_sameidenv.class_typesletis_shadowedenvid=List.memidenv.hiddenmodulePath=structletread_module_identenvid=ifIdent.persistentidthen`Root(Ident.nameid)elsetryfind_moduleenvidwithNot_found->assertfalseletread_module_type_ident env id=try`Identifier(find_module_typeenvid,false)with Not_found->assertfalseletread_type_identenvid=`Identifier(find_typeenv id,false)letread_class_type_identenvid:Paths.Path.ClassType.t=try`Identifier(find_class_type envid,false)withNot_found ->`Dot(`Root"*",(Ident.nameid))(* 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 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] willmap 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# 695 "src/loader/ident_env.cppo.ml"|Path.Pdot(p,s)->`Dot(read_moduleenvp,s)# 699 "src/loader/ident_env.cppo.ml"|Path.Papply(p,arg)->`Apply(read_moduleenvp,read_moduleenvarg)# 701 "src/loader/ident_env.cppo.ml"|Path.Pextra_ty_->assertfalse# 704 "src/loader/ident_env.cppo.ml"let read_module_typeenv =function|Path.Pidentid->read_module_type_identenvid# 707 "src/loader/ident_env.cppo.ml"|Path.Pdot(p,s)->`Dot(read_moduleenvp,s)# 711 "src/loader/ident_env.cppo.ml"|Path.Papply(_,_)->assertfalse# 713 "src/loader/ident_env.cppo.ml"|Path.Pextra_ty_->assertfalse# 716 "src/loader/ident_env.cppo.ml"letread_class_typeenv=function|Path.Pidentid->read_class_type_identenvid# 719 "src/loader/ident_env.cppo.ml"|Path.Pdot(p,s)->`Dot(read_moduleenvp,strip_hashs)# 723 "src/loader/ident_env.cppo.ml"|Path.Papply(_,_)->assertfalse# 725 "src/loader/ident_env.cppo.ml"|Path.Pextra_ty_->assertfalse# 731 "src/loader/ident_env.cppo.ml"letrecread_typeenv=function# 733 "src/loader/ident_env.cppo.ml"|Path.Pidentid->read_type_identenvid# 735 "src/loader/ident_env.cppo.ml"|Path.Pdot(p,s)->`Dot(read_moduleenvp,strip_hashs)# 739 "src/loader/ident_env.cppo.ml"|Path.Papply(_,_)->assertfalse# 741 "src/loader/ident_env.cppo.ml"|Path.Pextra_ty(p,_)->read_typeenvp# 744 "src/loader/ident_env.cppo.ml"endmoduleFragment=structletrecread_module:Longident.t->Paths.Fragment.Module.t=function|Longident.Lidents->`Dot(`Root,s)|Longident.Ldot(p,s)->`Dot((read_modulep:>Paths.Fragment.Signature.t),s)|Longident.Lapply_->assertfalseletread_module_type :Longident.t->Paths.Fragment.ModuleType.t=function|Longident.Lidents->`Dot(`Root,s)|Longident.Ldot(p,s)->`Dot((read_modulep:>Paths.Fragment.Signature.t),s)|Longident.Lapply_->assertfalseletread_type=function|Longident.Lidents->`Dot(`Root,s)|Longident.Ldot(p,s)->`Dot((read_modulep:>Paths.Fragment.Signature.t),s)|Longident.Lapply_->assertfalseend