123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428openOdoc_model.NamesopenOdoc_model.Paths(* For simplicity keep a global counter *)letcounter=ref0typesignature=[`LRootofModuleName.t*int|`LModuleofModuleName.t*int|`LResultofsignature*int|`LParameterofModuleName.t*int|`LModuleTypeofModuleTypeName.t*int]typeclass_signature=[`LClassofClassName.t*int|`LClassTypeofClassTypeName.t*int]typedatatype=[`LTypeofTypeName.t*int]typeparent=[signature|datatype]typelabel_parent=[parent|`LPageofPageName.t*int|`LLeafPageofPageName.t*int|class_signature]typemodule_=[`LRootofModuleName.t*int|`LModuleofModuleName.t*int|`LParameterofModuleName.t*int]typefunctor_parameter=[`LParameterofModuleName.t*int]typepath_module=[module_|`LResultofsignature*int|functor_parameter]typemodule_type=[`LModuleTypeofModuleTypeName.t*int]typetype_=datatypetypeconstructor=[`LConstructorofConstructorName.t*int]typefield=[`LFieldofFieldName.t*int]typeextension=[`LExtensionofExtensionName.t*int]typeexception_=[`LExceptionofExceptionName.t*int]typevalue=[`LValueofValueName.t*int]typeclass_=[`LClassofClassName.t*int]typeclass_type=[`LClassTypeofClassTypeName.t*int]typepath_type=[type_|class_|class_type]typepath_datatype=type_typepath_value=valuetypepath_class_type=[class_|class_type]typemethod_=[`LMethodofMethodName.t*int]typeinstance_variable=[`LInstanceVariableofInstanceVariableName.t*int]typelabel=[`LLabelofLabelName.t*int]typepage=[`LPageofPageName.t*int|`LLeafPageofPageName.t*int]typeany=[signature|class_signature|datatype|parent|label_parent|path_module|module_type|type_|constructor|field|extension|exception_|value|class_|class_type|method_|instance_variable|label|page]letfresh_int()=letn=!counterinincrcounter;nletint_of_any:any->int=function|`LRoot(_,i)|`LModule(_,i)|`LException(_,i)|`LConstructor(_,i)|`LClassType(_,i)|`LMethod(_,i)|`LClass(_,i)|`LType(_,i)|`LValue(_,i)|`LInstanceVariable(_,i)|`LParameter(_,i)|`LField(_,i)|`LResult(_,i)|`LLabel(_,i)|`LModuleType(_,i)|`LPage(_,i)|`LLeafPage(_,i)|`LExtension(_,i)->imoduleOf_Identifier=structopenIdentifierletrecsignature:Signature.t->signature=funsg->leti=fresh_int()inmatchsg.ivwith|`Root(_,n)->`LRoot(n,i)|`Module(_,n)->`LModule(n,i)|`Parameter(_,n)->`LParameter(n,i)|`ModuleType(_,n)->`LModuleType(n,i)|`Results->`LResult(signatures,i)letclass_signature:ClassSignature.t->class_signature=funsg->leti=fresh_int()inmatchsg.ivwith|`Class(_,n)->`LClass(n,i)|`ClassType(_,n)->`LClassType(n,i)letdatatype:DataType.t->datatype=funt->leti=fresh_int()inmatcht.ivwith|`Type(_,n)->`LType(n,i)|`CoreType_n->failwith"Bad"letfield_parent:FieldParent.t->parent=funp->matchpwith|{iv=#Signature.t_pv;_}ass->(signatures:>parent)|{iv=#DataType.t_pv;_}ass->(datatypes:>parent)letlabel_parent:LabelParent.t->label_parent=funp->matchpwith|{iv=#ClassSignature.t_pv;_}ass->(class_signatures:>label_parent)|{iv=#FieldParent.t_pv;_}ass->(field_parents:>label_parent)|{iv=`Page(_,n);_}->`LPage(n,fresh_int())|{iv=`LeafPage(_,n);_}->`LLeafPage(n,fresh_int())letmodule_:Odoc_model.Paths.Identifier.Module.t->module_=function|{iv=`Module(_,n)|`Root(_,n);_}->leti=fresh_int()in`LModule(n,i)|{iv=`Parameter(_,n);_}->leti=fresh_int()in`LParameter(n,i)letfunctor_parameter:Odoc_model.Paths.Identifier.FunctorParameter.t->functor_parameter=fun{iv=`Parameter(_,n);_}->`LParameter(n,fresh_int())letpath_module:Path.Module.t->path_module=funm->leti=fresh_int()inmatchm.ivwith|`Root(_,n)->`LRoot(n,i)|`Module(_,n)->`LModule(n,i)|`Parameter(_,n)->`LParameter(n,i)|`Resultx->`LResult(signaturex,i)letmodule_type:ModuleType.t->module_type=funm->leti=fresh_int()inmatchm.ivwith`ModuleType(_,n)->`LModuleType(n,i)lettype_:Type.t->type_=datatypeletconstructor:Constructor.t->constructor=func->matchc.ivwith`Constructor(_,n)->`LConstructor(n,fresh_int())letfield:Field.t->field=funf->matchf.ivwith`Field(_,n)->`LField(n,fresh_int())letextension:Extension.t->extension=fune->matche.ivwith`Extension(_,n)->`LExtension(n,fresh_int())letexception_:Exception.t->exception_=fune->matche.ivwith|`Exception(_,n)->`LException(n,fresh_int())|`CoreException_->failwith"Bad"letvalue:Value.t->value=funv->matchv.ivwith`Value(_,n)->`LValue(n,fresh_int())letclass_:Class.t->class_=func->matchc.ivwith`Class(_,n)->`LClass(n,fresh_int())letclass_type:ClassType.t->class_type=func->matchc.ivwith`ClassType(_,n)->`LClassType(n,fresh_int())letmethod_:Method.t->method_=func->matchc.ivwith`Method(_,n)->`LMethod(n,fresh_int())letinstance_variable:InstanceVariable.t->instance_variable=funi->matchi.ivwith|`InstanceVariable(_,n)->`LInstanceVariable(n,fresh_int())letlabel:Label.t->label=funl->matchl.ivwith`Label(_,n)->`LLabel(n,fresh_int())letpage:Page.t->page=funp->matchp.ivwith|`Page(_,n)->`LPage(n,fresh_int())|`LeafPage(_,n)->`LLeafPage(n,fresh_int())endmoduleName=structletrecsignature:signature->string=function|`LRoot(n,_)->ModuleName.to_stringn|`LModule(n,_)->ModuleName.to_stringn|`LResult(x,_)->signaturex|`LParameter(n,_)->ModuleName.to_stringn|`LModuleType(n,_)->ModuleTypeName.to_stringnlettyped_module:module_->ModuleName.t=function|`LRoot(n,_)|`LModule(n,_)|`LParameter(n,_)->nletmodule':module_->ModuleName.t=function|`LRoot(n,_)|`LModule(n,_)|`LParameter(n,_)->nletmodule_m=ModuleName.to_string(module'm)letunsafe_modulem=ModuleName.to_string_unsafe(module'm)letpath_module:path_module->string=function|`LRoot(n,_)->ModuleName.to_stringn|`LModule(n,_)->ModuleName.to_stringn|`LResult(x,_)->signaturex|`LParameter(n,_)->ModuleName.to_stringnlettyped_functor_parameter:functor_parameter->ModuleName.t=fun(`LParameter(n,_))->nletfunctor_parameter:functor_parameter->string=fun(`LParameter(n,_))->ModuleName.to_stringnlettype':type_->TypeName.t=function`LType(n,_)->nlettype_t=TypeName.to_string(type't)letunsafe_type:type_->string=function|`LType(n,_)->TypeName.to_string_unsafenlettyped_type:type_->TypeName.t=function`LType(n,_)->nletpath_type:path_type->string=function|`LClassType(n,_)->ClassTypeName.to_stringn|`LClass(n,_)->ClassName.to_stringn|`LType(n,_)->TypeName.to_stringnletclass':class_->ClassName.t=function`LClass(n,_)->nletclass_c=ClassName.to_string(class'c)letunsafe_classc=ClassName.to_string_unsafe(class'c)lettyped_class:class_->ClassName.t=function`LClass(n,_)->nletmodule_type:module_type->string=function|`LModuleType(n,_)->ModuleTypeName.to_stringnletunsafe_module_type:module_type->string=function|`LModuleType(n,_)->ModuleTypeName.to_string_unsafenlettyped_module_type:module_type->ModuleTypeName.t=function|`LModuleType(n,_)->nletpath_class_type:path_class_type->string=function|`LClass(n,_)->ClassName.to_stringn|`LClassType(n,_)->ClassTypeName.to_stringnletclass_type':class_type->ClassTypeName.t=function|`LClassType(n,_)->nletclass_typec=ClassTypeName.to_string(class_type'c)letunsafe_class_typec=ClassTypeName.to_string_unsafe(class_type'c)lettyped_class_type:class_type->ClassTypeName.t=function|`LClassType(n,_)->nletexception_:exception_->string=function|`LException(n,_)->ExceptionName.to_stringnlettyped_exception:exception_->ExceptionName.t=function|`LException(n,_)->nletvalue:value->string=function|`LValue(n,_)->ValueName.to_stringnlettyped_value:value->ValueName.t=function`LValue(n,_)->nletlabel:label->string=function|`LLabel(n,_)->LabelName.to_stringnlettyped_label:label->LabelName.t=function`LLabel(n,_)->nletmethod_:method_->string=function|`LMethod(n,_)->MethodName.to_stringnlettyped_method:method_->MethodName.t=function`LMethod(n,_)->nletinstance_variable:instance_variable->string=function|`LInstanceVariable(n,_)->InstanceVariableName.to_stringnlettyped_instance_variable:instance_variable->InstanceVariableName.t=function|`LInstanceVariable(n,_)->nendmoduleRename=structletrecsignature:signature->signature=function|`LRoot(n,_)->`LRoot(n,fresh_int())|`LModule(n,_)->`LModule(n,fresh_int())|`LResult(x,_)->`LResult(signaturex,fresh_int())|`LParameter(n,_)->`LParameter(n,fresh_int())|`LModuleType(n,_)->`LModuleType(n,fresh_int())letmodule_:module_->module_=function|`LRoot(n,_)->`LRoot(n,fresh_int())|`LModule(n,_)->`LModule(n,fresh_int())|`LParameter(n,_)->`LParameter(n,fresh_int())letpath_module:path_module->path_module=function|`LRoot(n,_)->`LRoot(n,fresh_int())|`LModule(n,_)->`LModule(n,fresh_int())|`LResult(x,_)->`LResult(signaturex,fresh_int())|`LParameter(n,_)->`LParameter(n,fresh_int())letmodule_type:module_type->module_type=function|`LModuleType(n,_)->`LModuleType(n,fresh_int())lettype_:type_->type_=function|`LType(n,_)->`LType(n,fresh_int())letexception_:exception_->exception_=function|`LException(n,_)->`LException(n,fresh_int())letvalue:value->value=function|`LValue(n,_)->`LValue(n,fresh_int())letclass_:class_->class_=function|`LClass(n,_)->`LClass(n,fresh_int())letclass_type:class_type->class_type=function|`LClassType(n,_)->`LClassType(n,fresh_int())endlethash:any->int=Hashtbl.hashletcompare:any->any->int=funab->int_of_anya-int_of_anybmoduleMaps=structmoduleModule=Map.Make(structtypet=module_letcomparexy=compare(x:t:>any)(y:t:>any)end)moduleModuleType=Map.Make(structtypet=module_typeletcomparexy=compare(x:t:>any)(y:t:>any)end)moduleType=Map.Make(structtypet=type_letcomparexy=compare(x:t:>any)(y:t:>any)end)endletreset()=counter:=0letrecfmt_auxppf(id:any)=matchidwith|`LRoot(n,i)->Format.fprintfppf"%s/%d"(ModuleName.to_stringn)i|`LModule(n,i)->Format.fprintfppf"%s/%d"(ModuleName.to_stringn)i|`LParameter(n,i)->Format.fprintfppf"%s/%d"(ModuleName.to_stringn)i|`LResult(x,_)->Format.fprintfppf"result(%a)"fmt_aux(x:>any)|`LModuleType(n,i)->Format.fprintfppf"%s/%d"(ModuleTypeName.to_stringn)i|`LType(n,i)->Format.fprintfppf"%s/%d"(TypeName.to_stringn)i|`LConstructor(n,i)->Format.fprintfppf"%s/%d"(ConstructorName.to_stringn)i|`LField(n,i)->Format.fprintfppf"%s/%d"(FieldName.to_stringn)i|`LExtension(n,i)->Format.fprintfppf"%s/%d"(ExtensionName.to_stringn)i|`LException(n,i)->Format.fprintfppf"%s/%d"(ExceptionName.to_stringn)i|`LValue(n,i)->Format.fprintfppf"%s/%d"(ValueName.to_stringn)i|`LClass(n,i)->Format.fprintfppf"%s/%d"(ClassName.to_stringn)i|`LClassType(n,i)->Format.fprintfppf"%s/%d"(ClassTypeName.to_stringn)i|`LMethod(n,i)->Format.fprintfppf"%s/%d"(MethodName.to_stringn)i|`LInstanceVariable(n,i)->Format.fprintfppf"%s/%d"(InstanceVariableName.to_stringn)i|`LLabel(n,i)->Format.fprintfppf"%s/%d"(LabelName.to_stringn)i|`LPage(n,i)->Format.fprintfppf"%s/%d"(PageName.to_stringn)i|`LLeafPage(n,i)->Format.fprintfppf"%s/%d"(PageName.to_stringn)iletfmt:Format.formatter->[<any]->unit=funppfid->fmt_auxppf(id:>any)letrename(s,_)=(s,fresh_int())