12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145(*
* 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.
*)openAsttypesopenTypedtreemoduleOCamlPath =PathopenOdoc_model.Pathsopen Odoc_model.LangopenOdoc_model.NamesmoduleEnv=Ident_envmodulePaths=Odoc_model.Pathstypeenv=Cmi.env={ident_env:Ident_env.t;warnings_tag:stringoption;}letcmti_builddir:string ref=ref""letread_module_expr:(env->Identifier.Signature.t->Identifier.LabelParent.t->Typedtree.module_expr->ModuleType.expr)ref=ref(fun____->failwith"unset")letopt_mapf=function|None->None|Somex->Some(fx)letgenerate_wrapper_module=letwrapper_counter=ref0infunparent~prefix~hidden->incr wrapper_counter;letdummy_id=letdummy_name=letsep=match hiddenwith|true ->"__"|false->"_"inletname=Printf.sprintf"%s%s%d"prefixsep!wrapper_counterinmatchhiddenwith|false->Odoc_model.Names.ModuleName.make_stdname|true->Odoc_model.Names.ModuleName.hidden_of_stringnameinIdentifier.Mk.module_(parent,dummy_name)inletdummy_path=`Identifier(dummy_id,hidden)in(dummy_id,dummy_path)letno_doc:Odoc_model.Comment.docs={elements=[];warnings_tag =None}(* [include functor F] is modelled as the application of [F] to a synthetic,
hidden module holding the items that precede the include.
That module's items are *aliases* of the real ones rather than copies: the
expansion of [F(BODY__n)] refers to the functor argument, so a copy would
leave the expansion mentioning [BODY__n.t], a hidden path, which the
generator renders as an abstract [type t]. With an alias, [BODY__n.t]
reduces to the enclosing signature's own [t] and is rendered, and linked, as
such. *)letwrapper_itemsdummy_iditems=letmoduleId=Identifier inletnameid=Id.name idinletparent=(dummy_id:Id.Module.t:>Id.Signature.t)in(* Anonymous parameters ([_]) have to be named so that the alias can pass
them on to the item it aliases. *)letalias_paramsparams=List.split(List.mapi(funi(p:TypeDecl.param)->letv=match p.descwithVarv->v|Any->Printf.sprintf"a%d"iin({pwithTypeDecl.desc=TypeDecl.Varv},TypeExpr.Varv))params)inletrecwrapper_itemitemacc=match(item :Signature.item)with|Type(rec_,td)->letparams,args=alias_paramstd.equation.paramsinletmanifest=Some(TypeExpr.Constr(`Identifier((td.id:>Id.Path.Type.t),false),args))inletequation ={td.equationwithTypeDecl.Equation.params;manifest;constraints=[];private_ =false}inletid=Id.Mk.type_(parent,Odoc_model.Names.TypeName.make_std(nametd.id))inSignature.Type(rec_,{tdwithTypeDecl.id;equation;representation=None;canonical=None;source_loc=None})::acc|Module(rec_,m)->letid=Id.Mk.module_(parent,Odoc_model.Names.ModuleName.make_std(namem.id))inlettype_=Module.Alias(`Identifier((m.id:>Id.Path.Module.t),false),None)inSignature.Module(rec_,{mwithModule.id;type_;canonical=None;hidden=false;source_loc=None})::acc|ModuleTypemt->letid=Id.Mk.module_type(parent,Odoc_model.Names.ModuleTypeName.make_std(namemt.id))inletexpr=Some(ModuleType.Path{p_path=`Identifier((mt.id:>Id.Path.ModuleType.t),false);p_expansion=None})inSignature.ModuleType{mtwithModuleType.id;expr;canonical=None;source_loc=None}::acc|Includeincl->(* The items an [include] brings in are visible to the functor too. *)List.fold_left(funaccitem->wrapper_itemitemacc)accincl.Include.expansion.content.items|Value_|ModuleSubstitution_|ModuleTypeSubstitution_|Open_|TypeSubstitution_|TypExt_|Exception_|Comment_->(* Nothing in the expansion of [F(BODY__n)] can refer to these. *)acc|Class(rec_,cls)->letid=Id.Mk.class_(parent,Odoc_model.Names.TypeName.make_std(namecls.id))inlettype_=Class.ClassType(ClassType.Constr(`Identifier((cls.id:>Id.Path.ClassType.t),false),[]))inletcls={clswithid;type_}inSignature.Class(rec_,cls)::acc|ClassType(rec_,clsty)->letid=Id.Mk.class_type(parent,Odoc_model.Names.TypeName.make_std(nameclsty.id))inletexpr=ClassType.Constr(`Identifier ((clsty.id:>Id.Path.ClassType.t),false),[])inletclsty={clstywithid;expr}inSignature.ClassType (rec_,clsty)::accinList.rev(List.fold_left (funaccitem->wrapper_itemitemacc)[]items)letwrapper_module(dummy_id,_dummy_path)~hiddenitems=letitems=wrapper_itemsdummy_iditemsinletsig_:Signature.t={items;compiled=true;removed=[];doc=no_doc}inlettype_:Module.decl=ModuleType(Signaturesig_)inletmodule_:Module.t={id=dummy_id;source_loc=None;doc=no_doc;type_;canonical=None;hidden}inSignature.Module(Ordinary,module_)letread_label=Cmi.read_labelletrec read_core_typeenvcontainerctyp=read_core_type_modalenvCmi.legacy_modescontainerctypandread_core_type_modalenvmodescontainerctyp=letopen TypeExpr inmatchctyp.ctyp_descwith#ifdefinedOXCAML(* TODO: presumably we want the layout in these first two cases,
eventually *)|Ttyp_var(None,_layout)->Any|Ttyp_var(Somes,_layout)->Vars#else|Ttyp_any->Any|Ttyp_vars->Vars#endif#ifdefinedOXCAML|Ttyp_arrow(lbl,arg,_,res,_)->#else|Ttyp_arrow(lbl,arg,res)->#endifletlbl=read_labellblinletarg=read_core_typeenvcontainerarginletarg_modes,res_modes,modes=Cmi.read_arrow_modes modes ctyp.ctyp_typeinletres=read_core_type_modalenvmodescontainerresinArrow(lbl,(arg,arg_modes),(res,res_modes))|Ttyp_tupletyps->#ifOCAML_VERSION>=(5,4,0)||definedOXCAMLlettyps=List.map(fun(lbl,x)->lbl,read_core_typeenvcontainerx)typsin#elselettyps=List.map(funx->None,read_core_typeenvcontainer x)typsin#endifTupletyps#ifdefinedOXCAML|Ttyp_unboxed_tupletyps->lettyps=List.map(fun(l,t)->l,read_core_typeenvcontainert)typsinUnboxed_tupletyps#endif|Ttyp_constr(p,_,params)->letp=Env.Path.read_typeenv.ident_envpinletparams=List.map(read_core_typeenvcontainer)paramsinConstr(p,params)|Ttyp_object(methods,closed)->letopenTypeExpr.Objectinletfields=List.map(function|{of_desc=OTtag(name,typ);_}->Method{name=name.txt;type_ =read_core_typeenvcontainer typ;}|{of_desc=OTinherittyp;_}->Inherit(read_core_typeenvcontainertyp))methodsinObject{fields;open_=(closed=Asttypes.Open)}|Ttyp_class(p,_,params)->letp=Env.Path.read_class_typeenv.ident_envpinletparams=List.map(read_core_typeenvcontainer)paramsinClass(p,params)#ifdefinedOXCAML|Ttyp_alias(typ,var,_layout)->((* TODO: presumably we want the layout, eventually *)#else|Ttyp_alias(typ,var)->(#endiflettyp=read_core_type env containertypin#ifdefinedOXCAMLmatchvarwith|None->typ|Somevar->#endif#ifOCAML_VERSION>=(5,2,0)Alias(typ,var.txt)#elseAlias(typ,var)#endif)|Ttyp_variant(fields,closed,present)->letopenTypeExpr.Polymorphic_variant inletelements=fields|>List.mapbeginfunfield->matchfield.rf_descwith|Ttag(name,constant,arguments)->letattributes =field.rf_attributesinletarguments=List.map(read_core_typeenvcontainer)argumentsinletname=name.txtinletdoc=Doc_attr.attached_no_tag ~warnings_tag:env.warnings_tagcontainerattributes inConstructor{name;constant;arguments;doc}|Tinherittyp->Type(read_core_typeenvcontainertyp)endinletkind=ifclosed=Asttypes.OpenthenOpenelsematchpresentwith|None->Fixed|Somenames->ClosednamesinPolymorphic_variant{kind;elements}|Ttyp_poly([],typ)->read_core_typeenvcontainertyp#ifdefinedOXCAML|Ttyp_poly(vars,typ)->Poly(List.map(fun(name,jk)->(name,Cmi.read_jkind_annotationjk))vars,read_core_typeenvcontainertyp)#else|Ttyp_poly(vars,typ)->Poly(List.map(funv->(v,Kind.Default))vars,read_core_typeenvcontainertyp)#endif#ifOCAML_VERSION>=(5,5,0)|Ttyp_package{tpt_path=pack_path;tpt_constraints=pack_fields;_}->#elifOCAML_VERSION>=(5,4,0)|Ttyp_package{tpt_path=pack_path;tpt_cstrs=pack_fields;_}->#else|Ttyp_package{pack_path;pack_fields;_}->#endifletpkg=read_packageenvcontainerpack_pathpack_fieldsinPackagepkg#ifOCAML_VERSION>=(5,2,0)|Ttyp_open (_p,_l,t)->(* TODO: adjust model *)read_core_typeenvcontainert#endif#ifdefinedOXCAML|Ttyp_quotetyp->Quote(read_core_type envcontainertyp)|Ttyp_splicetyp->Splice(read_core_typeenvcontainertyp)|Ttyp_call_pos->Constr(Env.Path.read_typeenv.ident_envPredef.path_lexing_position,[])|Ttyp_of_kind_->assertfalse|Ttyp_repr_->Any(* oxcaml: representation annotations are ignored *)|Ttyp_newlayout(_,ct)->(* oxcaml: layout-variable binder; odoc ignores the layout vars *)read_core_typeenvcontainerct#elifOCAML_VERSION>=(5,5,0)|Ttyp_functor(lbl,id,pkg,ret_type)->letlbl=read_label lblinletparent=Identifier.fresh_module_arg_parent()inlet e',id=Env.add_module_argparentid.txt(ModuleName.hidden_of_identid.txt)env.ident_envinletenv={envwithident_env=e'}inletret=read_core_typeenvcontainerret_typeinletpackage =read_package envcontainerpkg.tpt_pathpkg.tpt_constraintsinArrow_functor(lbl,{id;package},ret)#endifandread_packageenvcontainerpack_pathpack_fields=letopenTypeExpr.Packageinletpath=Env.Path.read_module_typeenv.ident_envpack_pathinletsubstitutions=List.map(fun(frag,typ)->letfrag=Env.Fragment.read_typefrag.Location.txtinlettyp=read_core_typeenvcontainertypin(frag,typ))pack_fieldsin{path;substitutions}letread_value_descriptionenvparentvd=letopenSignatureinletid=Env.find_value_identifierenv.ident_envvd.val_idinletsource_loc=Noneinlet container=(parent:Identifier.Signature.t:>Identifier.LabelParent.t)inletdoc=Doc_attr.attached_no_tag~warnings_tag:env.warnings_tagcontainervd.val_attributes inlettype_=read_core_typeenvcontainervd.val_descinletvalue=#ifOCAML_VERSION>=(5,6,0)(* Since 5.6 externals have their own node, so a [val] is never one. *)Value.Abstract#elsematch vd.val_primwith|[]->Value.Abstract|primitives->Externalprimitives#endifinletext_attrs=Doc_attr.attrs_of_value_descriptionvd.val_valinletmodalities=Cmi.read_value_descr_modalitiesvd.val_valinValue{Value.id;source_loc;doc;type_;value;ext_attrs;modalities}#ifOCAML_VERSION>=(5,6,0)(* Since 5.6 (RFC 44) [external] declarations have their own Typedtree node,
because they can now also be written as an alias of an existing primitive:
[external x : t = M.y], or [external x = M.y] with the type left implicit.
An alias carries no primitive strings of its own, so recover them from the resolved [Types.value_description] the way the.cmi reader does. *)letread_primitive_descriptionenvparentpd=letopenSignatureinletid=Env.find_value_identifierenv.ident_envpd.prim_idinletsource_loc=Noneinletcontainer=(parent:Identifier.Signature.t:>Identifier.LabelParent.t)inletdoc=Doc_attr.attached_no_tag~warnings_tag:env.warnings_tag containerpd.prim_attributesinlettype_=matchpd.prim_kindwith|Tprim_decl(core_type,_)|Tprim_alias (Somecore_type,_,_)->read_core_type envcontainercore_type|Tprim_alias(None,_,_)->(* No type written at the declaration site: use the inferred one. *)Cmi.mark_type_exprpd.prim_val.val_type;Cmi.read_type_exprenvpd.prim_val.val_typeinletvalue=matchpd.prim_kindwith|Tprim_decl (_,primitives)->Value.Externalprimitives|Tprim_alias_->(matchpd.prim_val.val_kindwith|Val_prim desc->letopenPrimitive inValue.External(desc.prim_name::(matchdesc.prim_native_namewith|""->[]|name->[name]))|_->Value.Abstract)inletext_attrs=Doc_attr.attrs_of_value_descriptionpd.prim_valinletmodalities=Cmi.read_value_descr_modalitiespd.prim_valinValue{Value.id;source_loc;doc;type_;value;ext_attrs;modalities}#endifletread_type_parameter(ctyp,var_and_injectivity)=letopenTypeDeclinletdesc,kind=matchctyp.ctyp_descwith#ifdefinedOXCAML|Ttyp_var(None,layout)->Any,Cmi.read_jkind_annotationlayout|Ttyp_var(Somes,layout)->Vars,Cmi.read_jkind_annotation layout#else|Ttyp_any->Any,Kind.Default|Ttyp_vars->Vars,Kind.Default#endif|_->assertfalseinletvariance,injectivity=#ifOCAML_VERSION<(4,12,0)letvar=matchvar_and_injectivitywith|Covariant->SomePos|Contravariant->SomeNeg|Invariant->Noneinvar,false#elseletvar=matchfstvar_and_injectivitywith|Covariant->SomePos|Contravariant->SomeNeg#ifOCAML_VERSION>=(5,4,0)|Bivariant->SomeBivariant#endif|NoVariance->Noneinletinjectivity =matchsndvar_and_injectivitywith|Injective->true|NoInjectivity->falseinvar,injectivity#endifin{desc;variance;injectivity;kind}#ifdefinedOXCAMLletis_mutable=Types.is_mutableletread_typedtree_label_modalitiesld=Cmi.read_modalitiesld.ld_mutableld.ld_modalities.moda_modalitiesletread_constructor_argumentarg=arg.ca_type,Cmi.read_modalities Immutablearg.ca_modalities.moda_modalities#elseletis_mutable ld=ld=Mutableletread_typedtree_label_modalities_ld=[]letread_constructor_argumentarg=arg,[]#endifletread_label_declarationenvparentlabel_parentld=letopenTypeDecl.FieldinletopenOdoc_model.Namesinletname=Ident.nameld.ld_idinletid=Identifier.Mk.field(parent,FieldName.make_stdname)inletdoc=Doc_attr.attached_no_tag~warnings_tag:env.warnings_taglabel_parentld.ld_attributesinletmutable_=is_mutableld.ld_mutableinlettype_=read_core_type envlabel_parentld.ld_typeinletmodalities=read_typedtree_label_modalitiesldin{id;doc;mutable_;type_;modalities}letread_unboxed_label_declarationenvparent label_parentld=letopenTypeDecl.UnboxedField inletopenOdoc_model.Namesinletname=Ident.nameld.ld_idinletid=Identifier.Mk.unboxed_field(parent,UnboxedFieldName.make_stdname)inletdoc=Doc_attr.attached_no_tag~warnings_tag:env.warnings_taglabel_parentld.ld_attributesinletmutable_ =is_mutable ld.ld_mutableinlettype_=read_core_typeenvlabel_parentld.ld_type in{id;doc;mutable_;type_}letread_constructor_declaration_arguments envparentlabel_parentarg=letopenTypeDecl.Constructorinmatchargwith|Cstr_tupleargs->letargs=List.map(funarg->letarg_type,arg_modalities=read_constructor_argumentarginread_core_type envlabel_parentarg_type,arg_modalities)argsinTupleargs|Cstr_recordlds->Record(List.map(read_label_declarationenvparentlabel_parent)lds)letread_constructor_declarationenvparent cd=letopenTypeDecl.Constructorinletid=Ident_env.find_constructor_identifierenv.ident_envcd.cd_idinletcontainer=(parent:>Identifier.FieldParent.t)inletlabel_container=(container:>Identifier.LabelParent.t)inletdoc=Doc_attr.attached_no_tag ~warnings_tag:env.warnings_taglabel_containercd.cd_attributesinletargs=read_constructor_declaration_argumentsenvcontainerlabel_containercd.cd_argsinletres=opt_map(read_core_typeenvlabel_container)cd.cd_resin{id;doc;args;res}letread_type_kindenvparent=letopenTypeDecl.Representationinfunction|Ttype_abstract ->None|Ttype_variantcstrs ->letcstrs=List.map(read_constructor_declaration envparent)cstrsinSome(Variantcstrs)|Ttype_record lbls->letparent=(parent :>Identifier.FieldParent.t)inletlabel_parent=(parent:>Identifier.LabelParent.t)inletlbls=List.map(read_label_declarationenvparentlabel_parent)lblsinSome(Recordlbls)#ifdefined OXCAML|Ttype_record_unboxed_productlbls->let parent=(parent:>Identifier.UnboxedFieldParent.t)inletlabel_parent=(parent:>Identifier.LabelParent.t)inletlbls =List.map(read_unboxed_label_declaration envparentlabel_parent)lblsinSome(Record_unboxed_productlbls)#endif|Ttype_open->SomeExtensible#ifOCAML_VERSION>=(5,5,0)|Ttype_external _->None#endifletread_type_equationenvcontainerdecl=letopenTypeDecl.Equationinletparams=List.mapread_type_parameterdecl.typ_paramsinletprivate_=(decl.typ_private=Private)inletmanifest=opt_map(read_core_typeenvcontainer)decl.typ_manifestinletconstraints=List.map(fun(typ1,typ2,_)->(read_core_typeenvcontainertyp1,read_core_typeenvcontainertyp2))#ifOCAML_VERSION>=(5,5,0)decl.typ_constraints#elsedecl.typ_cstrs#endifinletkind =#ifdefinedOXCAMLCmi.read_jkind_annotationdecl.typ_jkind_annotation#elseKind.Default#endifin{params;private_;manifest;constraints;kind}letread_type_declarationenvparentdecl=letopenTypeDeclinletid=Env.find_type_identifierenv.ident_envdecl.typ_idinletsource_loc=Noneinletcontainer=(parent:Identifier.Signature.t:>Identifier.LabelParent.t)inletdoc,canonical=Doc_attr.attached~warnings_tag:env.warnings_tagOdoc_model.Semantics.Expect_canonicalcontainerdecl.typ_attributes inletcanonical =match canonicalwith|None->None|Somes->Doc_attr.conv_canonical_typesinletequation=read_type_equationenvcontainerdeclinletrepresentation=read_type_kindenviddecl.typ_kindin{id;source_loc;doc;canonical;equation;representation}letread_type_declarationsenvparentrec_flagdecls=letcontainer=(parent:Identifier.Signature.t:>Identifier.LabelParent.t)inletitems=letopenSignatureinList.fold_left(fun(acc,recursive)decl->ifBtype.is_row_name(Ident.namedecl.typ_id)then(acc,recursive)elsebeginletcomments=Doc_attr.standalone_multiplecontainer~warnings_tag:env.warnings_tagdecl.typ_attributesinlet comments=List.map(funcom->Commentcom)comments inletdecl=read_type_declarationenvparentdeclin((Type(recursive,decl))::(List.rev_append commentsacc),And)end)([],rec_flag)decls|>fstinList.revitemsletread_type_substitutionsenvparentdecls=List.map(fundecl->Odoc_model.Lang.Signature.TypeSubstitution(read_type_declarationenvparentdecl))declsletread_extension_constructorenvparentext=letopenExtension.Constructorinletid=Env.find_extension_identifierenv.ident_envext.ext_idinletsource_loc=Noneinletcontainer=(parent:Identifier.Signature.t:>Identifier.FieldParent.t)inletlabel_container =(container :>Identifier.LabelParent.t)inletdoc=Doc_attr.attached_no_tag~warnings_tag:env.warnings_taglabel_containerext.ext_attributes inmatchext.ext_kindwith|Text_rebind_->assertfalse#ifOCAML_VERSION>=(4,14,0)|Text_decl(_,args,res)->#else|Text_decl(args,res)->#endifletargs=read_constructor_declaration_argumentsenv containerlabel_container argsinletres=opt_map(read_core_typeenvlabel_container)resin{id;source_loc;doc;args;res}letread_type_extensionenvparenttyext=letopenExtensioninlettype_path=Env.Path.read_typeenv.ident_envtyext.tyext_pathinletcontainer=(parent:Identifier.Signature.t:>Identifier.LabelParent.t)inletdoc=Doc_attr.attached_no_tag~warnings_tag:env.warnings_tag containertyext.tyext_attributes inlettype_params=List.mapread_type_parametertyext.tyext_paramsinletprivate_=(tyext.tyext_private=Private)inlet constructors=List.map(read_extension_constructorenvparent)tyext.tyext_constructorsin{parent;type_path;doc;type_params;private_;constructors;}letread_exception envparent(ext:extension_constructor)=letopenExceptioninlet id=Env.find_exception_identifierenv.ident_env ext.ext_idinletsource_loc=Noneinletcontainer=(parent:Identifier.Signature.t:>Identifier.FieldParent.t)inletlabel_container=(container:>Identifier.LabelParent.t)inletdoc=Doc_attr.attached_no_tag~warnings_tag:env.warnings_taglabel_containerext.ext_attributesinmatchext.ext_kindwith|Text_rebind_->assertfalse#ifOCAML_VERSION >=(4,14,0)|Text_decl(_,args,res)->#else|Text_decl(args,res)->#endifletargs=read_constructor_declaration_argumentsenvcontainerlabel_containerargsinletres=opt_map(read_core_typeenvlabel_container)resin{id;source_loc;doc;args;res}letrecread_class_type_fieldenvparentctf=letopenClassSignatureinletopen Odoc_model.Namesinletcontainer=(parent:Identifier.ClassSignature.t:>Identifier.LabelParent.t)inletdoc=Doc_attr.attached_no_tag~warnings_tag:env.warnings_tagcontainerctf.ctf_attributesinmatchctf.ctf_desc with|Tctf_val(name,mutable_,virtual_,typ)->letopenInstanceVariableinletid=Identifier.Mk.instance_variable(parent,InstanceVariableName.make_stdname)inletmutable_=(mutable_=Mutable)inletvirtual_=(virtual_=Virtual)inlet type_=read_core_typeenvcontainertypinSome(InstanceVariable {id;doc;mutable_;virtual_;type_})|Tctf_method(name,private_,virtual_,typ)->letopenMethodinletid=Identifier.Mk.method_(parent,MethodName.make_stdname)inletprivate_=(private_ =Private)inletvirtual_=(virtual_=Virtual)inlettype_=read_core_typeenvcontainertypinSome(Method{id;doc;private_;virtual_;type_})|Tctf_constraint(typ1,typ2)->letleft=read_core_typeenv containertyp1inletright=read_core_type envcontainertyp2inSome(Constraint{left;right;doc})|Tctf_inheritcltyp->letexpr=read_class_signatureenvparentcontainercltyp inSome(Inherit{expr;doc})|Tctf_attributeattr->matchDoc_attr.standalonecontainer~warnings_tag:env.warnings_tagattrwith|None->None|Somedoc->Some(Commentdoc)andread_self_type envcontainertyp=matchtyp.ctyp_descwith#ifdefinedOXCAML|Ttyp_var (None,_)->None#else|Ttyp_any ->None#endif|_->Some(read_core_typeenvcontainertyp)and read_class_signatureenvparentlabel_parentcltyp=letopenClassTypeinmatch cltyp.cltyp_descwith|Tcty_constr(p,_,params)->letp=Env.Path.read_class_typeenv.ident_envpinletparams=List.map(read_core_typeenvlabel_parent)paramsinConstr(p,params)|Tcty_signaturecsig->letopenClassSignatureinletself=read_self_typeenvlabel_parentcsig.csig_selfinletitems=List.fold_left(funrestitem->matchread_class_type_fieldenvparentitemwith|None->rest|Some item->item::rest)[]csig.csig_fieldsinletitems=List.revitemsinletitems,(doc,doc_post)=Doc_attr.extract_top_comment_class itemsinletitems=matchdoc_postwith|{elements=[];_}->items|_->Comment(`Docsdoc_post)::itemsinSignature{self;items;doc}|Tcty_arrow_->assertfalse|Tcty_open(_,cty)->read_class_signatureenv parentlabel_parentctyletread_class_type_declarationenvparentcltd=letopenClassType inletid=Env.find_class_type_identifierenv.ident_envcltd.ci_id_class_typeinletsource_loc=Noneinletcontainer=(parent:Identifier.Signature.t:>Identifier.LabelParent.t)inletdoc=Doc_attr.attached_no_tagcontainer~warnings_tag:env.warnings_tagcltd.ci_attributesinletvirtual_=(cltd.ci_virt=Virtual)inletparams=List.mapread_type_parametercltd.ci_paramsinletexpr=read_class_signatureenv(id:>Identifier.ClassSignature.t)containercltd.ci_exprin{id;source_loc;doc;virtual_;params;expr;expansion=None}letread_class_type_declarationsenvparentcltds=letcontainer=(parent:Identifier.Signature.t:>Identifier.LabelParent.t)inletopenSignatureinList.fold_leftbeginfun(acc,recursive)cltd->letcomments=Doc_attr.standalone_multiplecontainer~warnings_tag:env.warnings_tagcltd.ci_attributesinletcomments =List.map(funcom->Commentcom)commentsinletcltd=read_class_type_declarationenvparentcltdin((ClassType(recursive,cltd))::(List.rev_appendcommentsacc),And)end([],Ordinary)cltds|>fst|>List.revletrecread_class_typeenvparent label_parentcty=let openClassinmatchcty.cltyp_descwith|Tcty_constr_|Tcty_signature _->ClassType(read_class_signatureenvparentlabel_parentcty)|Tcty_arrow(lbl,arg,res)->let lbl=read_labellblinletarg=read_core_typeenvlabel_parentarginletres =read_class_typeenvparentlabel_parentresinArrow(lbl,arg,res)|Tcty_open(_,cty)->read_class_typeenvparentlabel_parentctyletread_class_descriptionenvparentcld=letopenClassinletid=Env.find_class_identifierenv.ident_envcld.ci_id_classinletsource_loc =Noneinletcontainer=(parent:Identifier.Signature.t:>Identifier.LabelParent.t)inlet doc=Doc_attr.attached_no_tagcontainer~warnings_tag:env.warnings_tagcld.ci_attributesinletvirtual_=(cld.ci_virt=Virtual)inletparams=List.mapread_type_parametercld.ci_paramsinlettype_=read_class_typeenv(id:>Identifier.ClassSignature.t)containercld.ci_exprin{id;source_loc;doc;virtual_;params;type_;expansion=None}letread_class_descriptionsenvparentclds=letcontainer=(parent:Identifier.Signature.t:>Identifier.LabelParent.t)inletopenSignatureinList.fold_leftbeginfun(acc,recursive)cld->letcomments =Doc_attr.standalone_multiplecontainer~warnings_tag:env.warnings_tagcld.ci_attributesinletcomments=List.map(funcom->Commentcom)commentsinletcld=read_class_descriptionenvparentcldin((Class(recursive,cld))::(List.rev_appendcommentsacc),And)end([],Ordinary)clds|>fst|>List.revletrecread_with_constraintenvglobal_parentparent(_,frag,constr)=let_=global_parentinletopenModuleTypeinmatchconstrwith|Twith_typedecl->letfrag=Env.Fragment.read_typefrag.Location.txtinleteq=read_type_equationenvparentdeclinSome(TypeEq(frag,eq))|Twith_module(p,_)->letfrag=Env.Fragment.read_modulefrag.Location.txtinleteq=read_module_equationenvpinSome (ModuleEq(frag,eq))|Twith_typesubstdecl->letfrag =Env.Fragment.read_typefrag.Location.txtinleteq=read_type_equationenvparentdeclinSome(TypeSubst(frag,eq))|Twith_modsubst(p,_)->letfrag=Env.Fragment.read_modulefrag.Location.txtinletp=Env.Path.read_moduleenv.ident_env pinSome(ModuleSubst(frag,p))#ifOCAML_VERSION>=(4,13,0)|Twith_modtype mty->let frag=Env.Fragment.read_module_typefrag.Location.txtinletmty=read_module_typeenvglobal_parentparentmtyinSome(ModuleTypeEq(frag,mty))|Twith_modtypesubstmty->letfrag=Env.Fragment.read_module_typefrag.Location.txtinletmty=read_module_typeenvglobal_parentparentmtyinSome(ModuleTypeSubst(frag,mty))#endif#ifdefinedOXCAML(* oxcaml: [with kind] constraints have no representation in odoc's
model,so they are dropped. *)|Twith_jkind_|Twith_jkindsubst_->None#endifandread_module_typeenvparentlabel_parentmty=letopenModuleTypeinmatchmty.mty_descwith|Tmty_ident(p,_)->(matchmty.mty_typewith#ifdefinedOXCAML|Mty_signaturesg->(* For modules with modalities (e.g. [module M : S @@ portable]),
the mty_desc stores only [Tmty_ident S] so we use the mty_type
for the expanded signature with modalities applied to each value. *)letmty_type=Odoc_model.Compat.module_typemty.mty_typeinCmi.read_module_typeenvparentmty_type#endif|_->Path{p_path=Env.Path.read_module_typeenv.ident_envp;p_expansion=None})|Tmty_signaturesg->letsg,()=read_signatureOdoc_model.Semantics.Expect_noneenvparentsginSignaturesg#ifOCAML_VERSION>=(4,10,0)#ifdefinedOXCAML|Tmty_functor(parameter,res,_)->#else|Tmty_functor(parameter,res)->#endifletf_parameter,env=matchparameterwith|Unit ->FunctorParameter.Unit,env#ifdefinedOXCAML|Named(id_opt,_,arg,_)->#else|Named(id_opt,_,arg)->#endifletid,env=matchid_optwith|None->Identifier.Mk.parameter(parent,ModuleName.make_std "_"),env|Someid->lete'=Env.add_parameterparentid(ModuleName.of_identid)env.ident_env inlet env={envwithident_env =e'}inEnv.find_parameter_identifiere'id,envinletarg=read_module_typeenv(id:>Identifier.Signature.t)label_parentarginNamed {id;expr=arg;},envinletres=read_module_typeenv(Identifier.Mk.resultparent)label_parent resinFunctor (f_parameter,res)#else|Tmty_functor(id,_,arg,res)->letnew_env =Env.add_parameterparentid(ModuleName.of_identid)env.ident_envinletnew_env={envwithident_env=new_env}inletf_parameter=match argwith|None->Odoc_model.Lang.FunctorParameter.Unit|Somearg->letid=Ident_env.find_parameter_identifiernew_env.ident_envidinletarg=read_module_typeenv(id:>Identifier.Signature.t)label_parentarginNamed{FunctorParameter.id;expr=arg}inlet res=read_module_typenew_env(Identifier.Mk.resultparent)label_parentresinFunctor(f_parameter,res)#endif|Tmty_with(body,subs)->(letbody=read_module_typeenvparentlabel_parentbodyinletsubs=List.filter_map(read_with_constraintenvparentlabel_parent)subsinmatchOdoc_model.Lang.umty_of_mtybodywith|Somew_expr->With{w_substitutions=subs;w_expansion=None;w_expr }|None->failwith"error")|Tmty_typeof mexpr->letdecl=matchmexpr.mod_descwith|Tmod_ident(p,_)->letp=Env.Path.read_moduleenv.ident_envpinTypeOf{t_desc=ModPathp;t_original_path=p;t_expansion=None}|Tmod_structure{str_items=[{str_desc =Tstr_include{incl_mod;_};_}];_}->begin#ifOCAML_VERSION>=(5,5,0)matchTypedtree.path_of_moduleincl_modwith#elsematch Typemod.path_of_module incl_modwith#endif|Somep->letp=Env.Path.read_moduleenv.ident_envpinTypeOf{t_desc=StructIncludep;t_original_path =p;t_expansion=None}|None->!read_module_exprenvparentlabel_parentmexprend|_->!read_module_exprenvparent label_parentmexprindecl|Tmty_alias_->assertfalse#ifdefinedOXCAML|Tmty_strengthen(mty,path,_)->letmty=read_module_typeenvparentlabel_parentmtyinlets_path =Env.Path.read_moduleenv.ident_envpathinmatchOdoc_model.Lang.umty_of_mty mtywith|Somes_expr->(* We always strengthen with aliases *)Strengthen{s_expr;s_path;s_aliasable =true;s_expansion=None}|None->failwith"invalid Tmty_strengthen"#endif(** Like [read_module_type] but handle the canonical tag in the top-comment. If [canonical] is [Some _], no tag is expected in the top-comment. *)andread_module_type_maybe_canonicalenvparentcontainer~canonicalmty=match(canonical,mty.mty_desc)with|None,Tmty_signaturesg->letsg,canonical=read_signatureOdoc_model.Semantics.Expect_canonical envparent sgin(ModuleType.Signaturesg,canonical)|_,_->(read_module_type envparentcontainermty,canonical)andread_module_type_declarationenvparentmtd=letopenModuleTypeinletid=Env.find_module_typeenv.ident_envmtd.mtd_idinletsource_loc=None inletcontainer=(parent:Identifier.Signature.t:>Identifier.LabelParent.t)inletdoc,canonical=Doc_attr.attached~warnings_tag:env.warnings_tagOdoc_model.Semantics.Expect_canonical containermtd.mtd_attributes inlet expr,canonical=matchmtd.mtd_typewith|Somemty->letexpr,canonical=read_module_type_maybe_canonical env(id:>Identifier.Signature.t)container~canonicalmtyin(Someexpr,canonical)|None->(None,canonical)inletcanonical=matchcanonicalwith|None->None|Somes->Doc_attr.conv_canonical_module_typesin{id;source_loc;doc;canonical;expr}andread_module_declarationenvparentmd=letopenModulein#ifOCAML_VERSION>=(4,10,0)matchmd.md_idwith|None->None|Someid->letmid=Env.find_module_identifierenv.ident_envidin#elseletmid=Env.find_module_identifierenv.ident_envmd.md_idin#endifletid=(mid:>Identifier.Module.t)inletsource_loc =None inletcontainer=(parent:Identifier.Signature.t:>Identifier.LabelParent.t)inletdoc,canonical=Doc_attr.attached~warnings_tag:env.warnings_tagOdoc_model.Semantics.Expect_canonicalcontainermd.md_attributesinlettype_,canonical =matchmd.md_type.mty_descwith|Tmty_alias (p,_)->(Alias(Env.Path.read_moduleenv.ident_envp,None),canonical)|_->letexpr,canonical=read_module_type_maybe_canonical env(id:>Identifier.Signature.t)container~canonicalmd.md_typein(ModuleTypeexpr,canonical)inletcanonical=matchcanonicalwith|None->None|Somes->Some (Doc_attr.conv_canonical_modules)inlethidden =#ifOCAML_VERSION>=(4,10,0)matchcanonical,midwith|None,(`Module(_,n)|`Parameter(_,n)|`Root(_,n))->Odoc_model.Names.ModuleName.is_hidden n|_,_->false#elsematchcanonical,midwith|None,(`Module(_,n)|`Parameter(_,n)|`Root(_,n))->Odoc_model.Names.ModuleName.is_hiddenn|_->false#endifinSome{id;source_loc;doc;type_;canonical;hidden}andread_module_declarationsenv parentmds =letcontainer=(parent:Identifier.Signature.t:>Identifier.LabelParent.t)inlet openSignatureinList.fold_left(fun(acc,recursive)md->letcomments=Doc_attr.standalone_multiplecontainer~warnings_tag:env.warnings_tagmd.md_attributesinletcomments=List.map(funcom->Commentcom)commentsinmatchread_module_declaration envparentmdwith|Some md->((Module(recursive,md))::(List.rev_append commentsacc),And)|None->acc,recursive)([],Rec)mds|>fst|>List.revand read_module_equationenvp=let openModuleinAlias (Env.Path.read_moduleenv.ident_envp,None)andread_signature_itemenvparentitem=letopenSignature inmatchitem.sig_descwith|Tsig_valuevd->[read_value_descriptionenvparentvd]#ifOCAML_VERSION>=(5,6,0)|Tsig_primitive pd->[read_primitive_descriptionenvparentpd]#endif|Tsig_type(rec_flag,decls)->letrec_flag=matchrec_flagwith|Recursive->Ordinary|Nonrecursive->Nonrecinread_type_declarationsenvparentrec_flagdecls|Tsig_typexttyext->[TypExt(read_type_extensionenvparenttyext)]|Tsig_exceptionext->[Exception(read_exceptionenvparentext.tyexn_constructor)]|Tsig_modulemd->beginmatchread_module_declarationenvparentmdwith|Somem->[Module(Ordinary,m)]|None->[]end|Tsig_recmodulemds->read_module_declarationsenvparentmds|Tsig_modtypemtd->[ModuleType(read_module_type_declarationenvparentmtd)]|Tsig_openo->[Open(read_openenvparento)]#ifdefinedOXCAML|Tsig_include(incl,_)->#else|Tsig_includeincl->#endifread_includeenvparentincl|Tsig_classcls->read_class_descriptionsenvparentcls|Tsig_class_typecltyps->read_class_type_declarationsenvparentcltyps|Tsig_attributeattr->beginletcontainer=(parent:Identifier.Signature.t:>Identifier.LabelParent.t)inmatchDoc_attr.standalonecontainer~warnings_tag:env.warnings_tagattrwith|None->[]|Somedoc->[Commentdoc]end|Tsig_typesubsttst->read_type_substitutionsenvparenttst|Tsig_modsubstmst->[ModuleSubstitution(read_module_substitutionenvparentmst)]#ifOCAML_VERSION>=(4,13,0)|Tsig_modtypesubstmtst->[ModuleTypeSubstitution(read_module_type_substitutionenvparentmtst)]#endif#ifdefinedOXCAML|Tsig_jkind_->[]#endifandread_module_substitutionenvparentms=letopenModuleSubstitutioninletid=Env.find_module_identifierenv.ident_envms.ms_idinletcontainer=(parent:Identifier.Signature.t:>Identifier.LabelParent.t)inletdoc,()=Doc_attr.attached~warnings_tag:env.warnings_tagOdoc_model.Semantics.Expect_nonecontainerms.ms_attributesinletmanifest=Env.Path.read_moduleenv.ident_envms.ms_manifestin{id;doc;manifest}#ifOCAML_VERSION>=(4,13,0)andread_module_type_substitutionenvparentmtd=letopenModuleTypeSubstitutioninletid=Env.find_module_typeenv.ident_envmtd.mtd_idinletcontainer=(parent:Identifier.Signature.t:>Identifier.LabelParent.t)inletdoc,()=Doc_attr.attached~warnings_tag:env.warnings_tagOdoc_model.Semantics.Expect_nonecontainermtd.mtd_attributesinletexpr=matchopt_map(read_module_typeenv(id:>Identifier.Signature.t)container)mtd.mtd_typewith|None->assertfalse|Somex->xin{id;doc;manifest=expr;}#endifandread_includeenvparentincl=letopenIncludeinletloc=Doc_attr.read_locationincl.incl_locinletcontainer=(parent:Identifier.Signature.t:>Identifier.LabelParent.t)inletdoc,status=Doc_attr.attached~warnings_tag:env.warnings_tagOdoc_model.Semantics.Expect_statuscontainerincl.incl_attributesinletcontent,shadowed=Cmi.read_signature_noenvenvparent(Odoc_model.Compat.signatureincl.incl_type)in(* Use a synthetic parent for the include's module type expression to avoid
identifier conflicts with items in the enclosing signature. Items inside
the include expression (like TypeSubstitutions) will get identifiers under
this synthetic parent, which won't clash with the real parent's items. *)letinclude_parent=Identifier.fresh_include_parentparentinletinclude_container=(include_parent:>Identifier.LabelParent.t)inletexpr=read_module_typeenvinclude_parentinclude_containerincl.incl_modinletexpansion={content;shadowed;authoritative=false}inmatchOdoc_model.Lang.umty_of_mtyexprwith|Someuexpr->letdecl=Include.ModuleTypeuexprin[Include{parent;doc;decl;expansion;status;strengthened=None;loc}]|None->content.items#ifdefinedOXCAML(* [include functor F] applies [F] to [wrapper], a synthetic module holding
everything defined before the include. A signature never has a path to [F]
-- only its module type -- so [F] is bound to a module to obtain one. *)andread_include_functorenvparentwrapperincl=letopenIncludeinletloc=Doc_attr.read_locationincl.incl_locinletcontainer=(parent:Identifier.Signature.t:>Identifier.LabelParent.t)inletdoc,status=Doc_attr.attached~warnings_tag:env.warnings_tagOdoc_model.Semantics.Expect_statuscontainerincl.incl_attributesinletcontent,shadowed=Cmi.read_signature_noenvenvparent(Odoc_model.Compat.signatureincl.incl_type)inletinclude_parent=Identifier.fresh_include_parentparentinletinclude_container=(include_parent:>Identifier.LabelParent.t)inletexpr=read_module_typeenvinclude_parentinclude_containerincl.incl_modinletexpansion={content;shadowed;authoritative=false}inlethidden=trueinletid,functor_path=generate_wrapper_moduleparent~prefix:"INCLUDE"~hiddeninletfunctor_:Module.t={id;source_loc=None;doc;type_=ModuleTypeexpr;canonical=None;hidden}inletdecl=Functor{target=Path(`Apply(functor_path,wrapper));original_ref=ModuleTypeexpr}in[Signature.Module(Ordinary,functor_);Include{parent;doc;decl;expansion;status;strengthened=None;loc}]#endifandread_openenvparento=letcontainer=(parent:Identifier.Signature.t:>Identifier.LabelParent.t)inletdoc=Doc_attr.attached_no_tagcontainer~warnings_tag:env.warnings_tago.open_attributesinletsignature=o.open_bound_itemsinletexpansion,_=Cmi.read_signature_noenvenvparent(Odoc_model.Compat.signaturesignature)in{expansion;doc}andread_itemsenvparentitems=List.fold_left(funaccitem->matchitem.sig_descwith#ifdefinedOXCAML|Tsig_include({incl_kind=(Tincl_functor_|Tincl_gen_functor_);incl_mod={mty_desc=(Tmty_typeof_|Tmty_ident_);_};_}asincl,_)->lethidden=trueinletwrapper=generate_wrapper_moduleparent~prefix:"BODY"~hiddeninletwrapper_module=wrapper_modulewrapper~hidden(List.revacc)inletitems=read_include_functorenvparent(sndwrapper)inclinList.rev_appenditems(wrapper_module::acc)#endif|_->List.rev_append(read_signature_itemenvparentitem)acc)[]items|>List.revandread_signature:'tags.'tagsOdoc_model.Semantics.handle_internal_tags->_->_->_->_*'tags=funinternal_tagsenvparentsg->lete'=Env.add_signature_tree_itemsparentsgenv.ident_envinletenv={envwithident_env=e'}inletitems,(doc,doc_post),tags=letclassifyitem=matchitem.sig_descwith|Tsig_attributeattr->Some(`Attributeattr)|Tsig_open_->Some`Open|_->NoneinDoc_attr.extract_top_commentinternal_tags~warnings_tag:env.warnings_tag~classifyparentsg.sig_itemsinletitems=read_itemsenvparentitemsinmatchdoc_postwith|{elements=[];_}->({Signature.items;compiled=false;removed=[];doc},tags)|_->({Signature.items=Comment(`Docsdoc_post)::items;compiled=false;removed=[];doc},tags)letread_interfacerootname~warnings_tagintf=letid=Identifier.Mk.root(root,Odoc_model.Names.ModuleName.make_stdname)inletsg,canonical=read_signatureOdoc_model.Semantics.Expect_canonical{ident_env=Env.empty();warnings_tag}idintfinletcanonical=matchcanonicalwith|None->None|Somes->Some(Doc_attr.conv_canonical_modules)in(id,sg,canonical)