123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374(*
* 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_modelopenPathsopenNamesclasstypet=objectmethodroot:Root.t->Root.tinheritMaps.pathsmethodoffset_identifier_signature:Identifier.Signature.t*int->Identifier.Signature.t*intinheritMaps.typesendletsignaturessg=s#signaturesgletclass_signaturescsig=s#class_signaturecsigletdatatypesdecl=s#type_decl_representationdeclletmodule_smd=s#module_mdletmodule_typesmty=s#module_typemtylettype_declsdecl=s#type_decldeclletconstructorscstr=s#type_decl_constructorcstrletfieldsfield=s#type_decl_fieldfieldletextensionsext=s#extensionextletexception_sexn=s#exception_exnletvaluesv=s#valuevletclass_scl=s#class_clletclass_typescty=s#class_typectyletmethod_smeth=s#method_methletinstance_variablesinst=s#instance_variableinstletcommentscom=s#documentation_commentcomletdocumentationsdoc=s#documentationdocletidentifier_signaturesid=s#identifier_signatureidletoffset_identifier_signaturesidoff=s#offset_identifier_signatureidoff(* TODO either expose more maps or expose argument map directly *)letidentifier_modulesid=s#identifier_moduleidletmodule_type_exprsexpr=s#module_type_exprexprletmodule_expansionsexpr=s#module_expansionexprclassrename_signature~equal:_(x:Identifier.Signature.t)(y:Identifier.Signature.t)offset:t=objectinheritMaps.pathsassupermethodrootx=xmethod!identifier_signatureid=ifIdentifier.Signature.equalidxthenyelsesuper#identifier_signatureidmethod!identifier(id:Identifier.t):Identifier.t=matchidwith|`Argument(parent,pos,name)->ifIdentifier.Signature.equalparentxthen`Argument(y,pos+offset,name)elsesuper#identifierid|id->super#identifieridmethodoffset_identifier_signature(id,offset')=ifIdentifier.Signature.equalidxthen(y,offset+offset')else(super#identifier_signatureid,offset')inheritMaps.typesendletrename_signature~equalxyoffset=newrename_signature~equalxyoffsetclassrename_class_signature~equal:_(x:Identifier.ClassSignature.t)(y:Identifier.ClassSignature.t):t=object(self)inheritMaps.pathsassupermethodrootx=xmethod!identifier_class_signatureid=ifIdentifier.ClassSignature.equalidxthenyelsesuper#identifier_class_signatureidinheritMaps.typesmethodoffset_identifier_signature(id,offset)=(self#identifier_signatureid,offset)endletrename_class_signature~equalxy=newrename_class_signature~equalxyclassrename_datatype~equal:_(x:Identifier.DataType.t)(y:Identifier.DataType.t):t=object(self)inheritMaps.pathsassupermethodrootx=xmethod!identifier_datatypeid=ifIdentifier.DataType.equalidxthenyelsesuper#identifier_datatypeidinheritMaps.typesmethodoffset_identifier_signature(id,offset)=(self#identifier_signatureid,offset)endletrename_datatype~equalxy=newrename_datatype~equalxy(*let module_id_path (type k) (Witness : k is_path_kind)
(id : ('a, k) Identifier.t) name =
let open Path.Resolved in
(Module(Identifier id, name))*)classprefix~equal:_~canonicalid:t=objectinheritMaps.pathsassupermethodrootx=xmethod!identifierx=xmethod!path_resolved:Path.Resolved.t->Path.Resolved.t=funp->letmatchesid'=Identifier.Signature.equal(id:>Identifier.Signature.t)id'inletreplacement=matchcanonicalwith|None->`Identifierid|Some(path,_)->`Canonical(`Identifierid,path)inmatchpwith|`Identifier(`Module(parent,name))->ifmatchesparentthen`Module(replacement,name)elsesuper#path_resolvedp|`Identifier(`ModuleType(parent,name))->ifmatchesparentthen(`ModuleType(replacement,name))elsesuper#path_resolvedp|`Identifier(`Type(parent,name))->ifmatchesparentthen(`Type(replacement,name))elsesuper#path_resolvedp|`Identifier(`Class(parent,name))->ifmatchesparentthen(`Class(replacement,name))elsesuper#path_resolvedp|`Identifier(`ClassType(parent,name))->ifmatchesparentthen(`ClassType(replacement,name))elsesuper#path_resolvedp|_->super#path_resolvedpmethod!reference_resolved:Reference.Resolved.t->Reference.Resolved.t=funr->letsid=(id:>Identifier.Signature.t)inletmatchesid'=Identifier.Signature.equalsidid'inletopenReference.Resolvedinletreplacement=matchcanonicalwith|None->`Identifierid|Some(_,reference)->`Canonical(`Identifierid,reference)inletsreplacement=(replacement:>Signature.t)inletlreplacement=(replacement:>LabelParent.t)inmatchrwith|`Identifier(`Module(parent,name))->ifmatchesparentthen`Module(sreplacement,name)elsesuper#reference_resolvedr|`Identifier(`ModuleType(parent,name))->ifmatchesparentthen`ModuleType(sreplacement,name)elsesuper#reference_resolvedr|`Identifier(`Type(parent,name))->ifmatchesparentthen`Type(sreplacement,name)elsesuper#reference_resolvedr|`Identifier(`Extension(parent,name))->ifmatchesparentthen`Extension(sreplacement,name)elsesuper#reference_resolvedr|`Identifier(`Exception(parent,name))->ifmatchesparentthen`Exception(sreplacement,name)elsesuper#reference_resolvedr|`Identifier(`Value(parent,name))->ifmatchesparentthen`Value(sreplacement,name)elsesuper#reference_resolvedr|`Identifier(`Class(parent,name))->ifmatchesparentthen`Class(sreplacement,name)elsesuper#reference_resolvedr|`Identifier(`ClassType(parent,name))->ifmatchesparentthen`ClassType(sreplacement,name)elsesuper#reference_resolvedr|`Identifier(`Label(parent,name))->beginmatchparentwith|`Root_|`Argument_|`Module_|`ModuleType_asparent->ifmatchesparentthen`Label(lreplacement,name)elsesuper#reference_resolvedr|_->super#reference_resolvedrend|_->super#reference_resolvedrinheritMaps.typesmethodoffset_identifier_signaturex=xendletprefix~equal~canonicalid=newprefix~equal~canonicalidclassstrengthenpath:t=objectinheritMaps.typesmethodrootx=xmethod!documentation_commentx=xmethod!module_md=ifPath.Resolved.Module.is_hiddenpaththenmdelsebeginletopenLang.Moduleinmatchmd.type_with|Aliaspwhennot(Path.Module.is_hiddenp)->md|_->letname=Identifier.namemd.idinletpath=`Resolved(`Module(path,ModuleName.of_stringname))inlettype_=Aliaspathinletexpansion=Nonein{mdwithtype_;expansion}endmethod!module_typex=xmethod!type_declx=xmethod!extensionx=xmethod!exception_x=xmethod!valuex=xmethod!external_x=xmethod!class_x=xmethod!class_typex=xmethod!include_x=xinheritMaps.pathsmethodoffset_identifier_signaturex=xmethod!module_type_exprx=xendletstrengthenpath=newstrengthenpathletmake_lookup~equal:_~hash:_(items:(Identifier.Module.t*Identifier.Module.t)list)=letmoduleHash=structtypet=Identifier.Module.tletequal=Identifier.Module.equallethash=Identifier.Module.hashendinletmoduleTbl=Hashtbl.Make(Hash)inlettbl=Tbl.create13inList.iter(fun(id1,id2)->Tbl.addtblid1id2)items;funid->matchTbl.findtblidwith|id->Someid|exceptionNot_found->Noneclasspack~equal~hash(items:(Identifier.Module.t*Identifier.Module.t)list):t=object(self)vallookup=make_lookup~equal~hashitemsmethodrootx=xinheritMaps.pathsassupermethod!identifier:Identifier.t->Identifier.t=funid->matchidwith|`Root_asid->beginmatchlookupidwith|Some(`Root_|`Module_|`Argument_asid)->id|None->super#identifieridend|`Module_asid->beginmatchlookupidwith|Some(`Root_|`Module_|`Argument_asid)->id|None->super#identifieridend|`Argument_asid->beginmatchlookupidwith|Some(`Root_|`Module_|`Argument_asid)->id|None->super#identifieridend|_->super#identifieridinheritMaps.typesmethodoffset_identifier_signature(id,offset)=(self#identifier_signatureid,offset)endletpack~equal~hashitems=newpack~equal~hashitems