123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424# 1 "src/model/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.
*)openPredefinedopenNamesmoduleId=Paths.IdentifiermoduleRp=Paths.Path.Resolvedtypetype_ident=Paths_types.Identifier.path_typetypeclass_type_ident=Paths_types.Identifier.path_class_typetypet={modules:Rp.Module.tIdent.tbl;module_types:Id.ModuleType.tIdent.tbl;types:type_identIdent.tbl;class_types:class_type_identIdent.tbl;}letempty={modules=Ident.empty;module_types=Ident.empty;types=Ident.empty;class_types=Ident.empty;}letbuiltin_idents=List.mapsndPredef.builtin_idents# 42 "src/model/ident_env.cppo.ml"letmodule_name_of_openo=letloc_start=o.Typedtree.open_loc.Location.loc_startinPrintf.sprintf"Open__%d_%d"loc_start.Lexing.pos_lnumloc_start.pos_cnum# 47 "src/model/ident_env.cppo.ml"letadd_moduleparentidnameenv=letident=`Identifier(`Module(parent,name))inletmodule_=ifModuleName.is_hiddennamethen`Hiddenidentelseidentinletmodules=Ident.addidmodule_env.modulesin{envwithmodules}letadd_argumentparentargidnameenv=letident=`Identifier(`Argument(parent,arg,name))inletmodule_=ifArgumentName.is_hiddennamethen`Hiddenidentelseidentinletmodules=Ident.addidmodule_env.modulesin{envwithmodules}letadd_module_typeparentidnameenv=letidentifier=`ModuleType(parent,name)inletmodule_types=Ident.addididentifierenv.module_typesin{envwithmodule_types}letadd_typeparentidnameenv=letidentifier=`Type(parent,name)inlettypes=Ident.addididentifierenv.typesin{envwithtypes}letadd_classparentidty_idobj_idcl_idnameenv=letidentifier=`Class(parent,name)inletadd_identstbl=Ident.addididentifier(Ident.addty_ididentifier(Ident.addobj_ididentifier(Ident.addcl_ididentifiertbl)))inlettypes=add_identsenv.typesinletclass_types=add_identsenv.class_typesin{envwithtypes;class_types}letadd_class_typeparentidobj_idcl_idnameenv=letidentifier=`ClassType(parent,name)inletadd_identstbl=Ident.addididentifier(Ident.addobj_ididentifier(Ident.addcl_ididentifiertbl))inlettypes=add_identsenv.typesinletclass_types=add_identsenv.class_typesin{envwithtypes;class_types}letrecadd_signature_type_itemsparentitemsenv=letopenCompatinmatchitemswith|Sig_type(id,_,_,Exported)::rest->letenv=add_signature_type_itemsparentrestenvinifBtype.is_row_name(Ident.nameid)thenenvelseadd_typeparentid(TypeName.of_identid)env|Sig_module(id,_,_,_,Exported)::rest->letenv=add_signature_type_itemsparentrestenvinadd_moduleparentid(ModuleName.of_identid)env|Sig_modtype(id,_,Exported)::rest->letenv=add_signature_type_itemsparentrestenvinadd_module_typeparentid(ModuleTypeName.of_identid)env|Sig_class(id,_,_,Exported)::Sig_class_type(ty_id,_,_,_)::Sig_type(obj_id,_,_,_)::Sig_type(cl_id,_,_,_)::rest->letenv=add_signature_type_itemsparentrestenvinadd_classparentidty_idobj_idcl_id(ClassName.of_identid)env|Sig_class_type(id,_,_,Exported)::Sig_type(obj_id,_,_,_)::Sig_type(cl_id,_,_,_)::rest->letenv=add_signature_type_itemsparentrestenvinadd_class_typeparentidobj_idcl_id(ClassTypeName.of_identid)env|(Sig_value_|Sig_typext_)::rest->add_signature_type_itemsparentrestenv|Sig_class_type(_,_,_,Hidden)::Sig_type(_,_,_,_)::Sig_type(_,_,_,_)::rest|Sig_class(_,_,_,Hidden)::Sig_class_type(_,_,_,_)::Sig_type(_,_,_,_)::Sig_type(_,_,_,_)::rest|Sig_modtype(_,_,Hidden)::rest|Sig_module(_,_,_,_,Hidden)::rest|Sig_type(_,_,_,Hidden)::rest->add_signature_type_itemsparentrestenv|Sig_class_::_|Sig_class_type_::_->assertfalse|[]->env# 133 "src/model/ident_env.cppo.ml"letrecunwrap_module_expr_desc=function|Typedtree.Tmod_constraint(mexpr,_,Tmodtype_implicit,_)->unwrap_module_expr_descmexpr.mod_desc|desc->descletrecadd_extended_open_itemsparentitemsenv=letopenTypesinmatchitemswith|Sig_type(id,_,_,_)::rest->letenv=add_extended_open_itemsparentrestenvinifBtype.is_row_name(Ident.nameid)thenenvelseadd_typeparentid(TypeName.internal_of_identid)env|Sig_module(id,_,_,_,_)::rest->letenv=add_extended_open_itemsparentrestenvinadd_moduleparentid(ModuleName.internal_of_identid)env|Sig_modtype(id,_,_)::rest->letenv=add_extended_open_itemsparentrestenvinadd_module_typeparentid(ModuleTypeName.internal_of_identid)env|Sig_class(id,_,_,_)::Sig_class_type(ty_id,_,_,_)::Sig_type(obj_id,_,_,_)::Sig_type(cl_id,_,_,_)::rest->letenv=add_extended_open_itemsparentrestenvinadd_classparentidty_idobj_idcl_id(ClassName.internal_of_identid)env|Sig_class_type(id,_,_,_)::Sig_type(obj_id,_,_,_)::Sig_type(cl_id,_,_,_)::rest->letenv=add_extended_open_itemsparentrestenvinadd_class_typeparentidobj_idcl_id(ClassTypeName.internal_of_identid)env|(Sig_value_|Sig_typext_)::rest->add_extended_open_itemsparentrestenv|Sig_class_::_|Sig_class_type_::_->assertfalse|[]->envletadd_extended_openparentoenv=letopenTypedtreeinmatchunwrap_module_expr_desco.open_expr.mod_descwith|Tmod_ident(_,_)->env|_->letparent=`Module(parent,ModuleName.internal_of_string(module_name_of_openo))inadd_extended_open_itemsparento.open_bound_itemsenv# 177 "src/model/ident_env.cppo.ml"letadd_signature_tree_itemparentitemenv=letopenTypedtreeinmatchitem.sig_descwith# 183 "src/model/ident_env.cppo.ml"|Tsig_type(_rec_flag,decls)->(* TODO: handle rec_flag *)# 185 "src/model/ident_env.cppo.ml"List.fold_right(fundeclenv->add_typeparentdecl.typ_id(TypeName.of_identdecl.typ_id)env)declsenv# 189 "src/model/ident_env.cppo.ml"|Tsig_module{md_id=Someid;_}->add_moduleparentid(ModuleName.of_identid)env|Tsig_module_->env|Tsig_recmodulemds->List.fold_right(funmdenv->matchmd.md_idwith|Someid->add_moduleparentid(ModuleName.of_identid)env|None->env)mdsenv# 209 "src/model/ident_env.cppo.ml"|Tsig_modtypemtd->add_module_typeparentmtd.mtd_id(ModuleTypeName.of_identmtd.mtd_id)env|Tsig_includeincl->add_signature_type_itemsparent(Compat.signatureincl.incl_type)env|Tsig_classcls->List.fold_right(funcldenv->add_classparentcld.ci_id_classcld.ci_id_class_typecld.ci_id_object# 221 "src/model/ident_env.cppo.ml"cld.ci_id_typehash# 223 "src/model/ident_env.cppo.ml"(ClassName.of_identcld.ci_id_class)env)clsenv|Tsig_class_typecltyps->List.fold_right(funcltyenv->add_class_typeparentclty.ci_id_class_typeclty.ci_id_object# 234 "src/model/ident_env.cppo.ml"clty.ci_id_typehash# 236 "src/model/ident_env.cppo.ml"(ClassTypeName.of_identclty.ci_id_class_type)env)cltypsenv# 240 "src/model/ident_env.cppo.ml"|Tsig_modsubstms->add_moduleparentms.ms_id(ModuleName.of_identms.ms_id)env|Tsig_typesubstts->List.fold_right(fundeclenv->add_typeparentdecl.typ_id(TypeName.of_identdecl.typ_id)env)tsenv# 251 "src/model/ident_env.cppo.ml"|Tsig_value_|Tsig_typext_|Tsig_exception_|Tsig_open_|Tsig_attribute_->envletadd_signature_tree_itemsparentsgenv=letopenTypedtreeinList.fold_right(add_signature_tree_itemparent)sg.sig_itemsenvletadd_structure_tree_itemparentitemenv=letopenTypedtreeinmatchitem.str_descwith# 267 "src/model/ident_env.cppo.ml"|Tstr_type(_rec_flag,decls)->(* TODO: handle rec_flag *)# 269 "src/model/ident_env.cppo.ml"List.fold_right(fundeclenv->add_typeparentdecl.typ_id(TypeName.of_identdecl.typ_id)env)declsenv# 273 "src/model/ident_env.cppo.ml"|Tstr_module{mb_id=Someid;_}->add_moduleparentid(ModuleName.of_identid)env|Tstr_module_->env|Tstr_recmodulembs->List.fold_right(funmbenv->matchmb.mb_idwith|Someid->add_moduleparentid(ModuleName.of_identid)env|None->env)mbsenv# 289 "src/model/ident_env.cppo.ml"|Tstr_modtypemtd->add_module_typeparentmtd.mtd_id(ModuleTypeName.of_identmtd.mtd_id)env|Tstr_includeincl->add_signature_type_itemsparent(Compat.signatureincl.incl_type)env|Tstr_classcls->List.fold_right# 298 "src/model/ident_env.cppo.ml"(fun(cld,_)env-># 300 "src/model/ident_env.cppo.ml"add_classparentcld.ci_id_classcld.ci_id_class_typecld.ci_id_object# 305 "src/model/ident_env.cppo.ml"cld.ci_id_typehash# 307 "src/model/ident_env.cppo.ml"(ClassName.of_identcld.ci_id_class)env)clsenv|Tstr_class_typecltyps->List.fold_right(fun(_,_,clty)env->add_class_typeparentclty.ci_id_class_typeclty.ci_id_object# 318 "src/model/ident_env.cppo.ml"clty.ci_id_typehash# 320 "src/model/ident_env.cppo.ml"(ClassTypeName.of_identclty.ci_id_class_type)env)cltypsenv# 326 "src/model/ident_env.cppo.ml"|Tstr_openo->add_extended_openparentoenv# 329 "src/model/ident_env.cppo.ml"|Tstr_eval_|Tstr_value_|Tstr_primitive_|Tstr_typext_|Tstr_exception_|Tstr_attribute_->envletadd_structure_tree_itemsparentstrenv=letopenTypedtreeinList.fold_right(add_structure_tree_itemparent)str.str_itemsenvletfind_moduleenvid=Ident.find_sameidenv.modulesletfind_module_typeenvid=Ident.find_sameidenv.module_typesletfind_typeenvid=tryIdent.find_sameidenv.typeswithNot_found->ifList.memidbuiltin_identsthenmatchcore_type_identifier(Ident.nameid)with|Someid->(id:>type_ident)|None->raiseNot_foundelseraiseNot_foundletfind_class_typeenvid=Ident.find_sameidenv.class_typesmodulePath=structletread_module_identenvid=ifIdent.persistentidthen`Root(Ident.nameid)elsetry`Resolved(find_moduleenvid)withNot_found->assertfalseletread_module_type_identenvid=try`Resolved(`Identifier(find_module_typeenvid))withNot_found->assertfalseletread_type_identenvid=try`Resolved(`Identifier(find_typeenvid))withNot_found->assertfalseletread_class_type_identenvid:Paths.Path.ClassType.t=try`Resolved(`Identifier(find_class_typeenvid))withNot_found->`Dot(`Root"*",(Ident.nameid))(* TODO remove this hack once the fix for PR#6650
is in the OCaml release *)letrecread_module:t->Path.t->Paths.Path.Module.t=funenv->function|Path.Pidentid->read_module_identenvid# 388 "src/model/ident_env.cppo.ml"|Path.Pdot(p,s)->`Dot(read_moduleenvp,s)# 392 "src/model/ident_env.cppo.ml"|Path.Papply(p,arg)->`Apply(read_moduleenvp,read_moduleenvarg)letread_module_typeenv=function|Path.Pidentid->read_module_type_identenvid# 397 "src/model/ident_env.cppo.ml"|Path.Pdot(p,s)->`Dot(read_moduleenvp,s)# 401 "src/model/ident_env.cppo.ml"|Path.Papply(_,_)->assertfalseletread_class_typeenv=function|Path.Pidentid->read_class_type_identenvid# 406 "src/model/ident_env.cppo.ml"|Path.Pdot(p,s)->`Dot(read_moduleenvp,s)# 410 "src/model/ident_env.cppo.ml"|Path.Papply(_,_)->assertfalseletread_typeenv=function|Path.Pidentid->read_type_identenvid# 415 "src/model/ident_env.cppo.ml"|Path.Pdot(p,s)->`Dot(read_moduleenvp,s)# 419 "src/model/ident_env.cppo.ml"|Path.Papply(_,_)->assertfalseendmoduleFragment=structletrecread_module:Longident.t->Paths.Fragment.Module.t=function|Longident.Lidents->`Dot(`Resolved`Root,s)|Longident.Ldot(p,s)->`Dot((read_modulep:>Paths.Fragment.Signature.t),s)|Longident.Lapply_->assertfalseletread_type=function|Longident.Lidents->`Dot(`Resolved`Root,s)|Longident.Ldot(p,s)->`Dot((read_modulep:>Paths.Fragment.Signature.t),s)|Longident.Lapply_->assertfalseend