123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540(*
* 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.
*)openPaths(** {3 Modules} *)moduleSource_info=structtypeannotation=|DefinitionofPaths.Identifier.SourceLocation.t|ValueofPaths.Identifier.SourceLocation.ttype'awith_pos='a*(int*int)typeinfos=annotationwith_poslisttypet={id:Identifier.SourcePage.t;infos:infos}endmodulerecModule:sigtypedecl=|Aliasof(Path.Module.t*ModuleType.simple_expansionoption)|ModuleTypeofModuleType.exprtypet={id:Identifier.Module.t;locs:Identifier.SourceLocation.toption;(** Identifier.SourceLocation might not be set when the module is artificially constructed from a functor argument. *)doc:Comment.docs;type_:decl;canonical:Path.Module.toption;hidden:bool;}moduleEquation:sigtypet=declendend=ModuleandFunctorParameter:sigtypeparameter={id:Identifier.FunctorParameter.t;expr:ModuleType.expr;}typet=Unit|Namedofparameterend=FunctorParameter(** {3 Modules Types} *)andModuleType:sigtypesubstitution=|ModuleEqofFragment.Module.t*Module.Equation.t|ModuleTypeEqofFragment.ModuleType.t*ModuleType.expr|TypeEqofFragment.Type.t*TypeDecl.Equation.t|ModuleSubstofFragment.Module.t*Path.Module.t|ModuleTypeSubstofFragment.ModuleType.t*ModuleType.expr|TypeSubstofFragment.Type.t*TypeDecl.Equation.ttypetype_of_desc=|ModPathofPath.Module.t|StructIncludeofPath.Module.ttypesimple_expansion=|SignatureofSignature.t|FunctorofFunctorParameter.t*simple_expansiontypetypeof_t={t_desc:type_of_desc;t_expansion:simple_expansionoption;}moduleU:sigtypeexpr=|PathofPath.ModuleType.t|SignatureofSignature.t|Withofsubstitutionlist*expr|TypeOfoftypeof_t(* Nb. this may have an expansion! *)endtypepath_t={p_expansion:simple_expansionoption;p_path:Path.ModuleType.t;}typewith_t={w_substitutions:substitutionlist;w_expansion:simple_expansionoption;w_expr:U.expr;}typeexpr=|Pathofpath_t|SignatureofSignature.t|FunctorofFunctorParameter.t*expr|Withofwith_t|TypeOfoftypeof_ttypet={id:Identifier.ModuleType.t;locs:Identifier.SourceLocation.toption;(** Can be [None] for module types created by a type substitution. *)doc:Comment.docs;canonical:Path.ModuleType.toption;expr:exproption;}end=ModuleTypeandModuleSubstitution:sigtypet={id:Identifier.Module.t;doc:Comment.docs;manifest:Path.Module.t;}end=ModuleSubstitutionandModuleTypeSubstitution:sigtypet={id:Identifier.ModuleType.t;doc:Comment.docs;manifest:ModuleType.expr;}end=ModuleTypeSubstitution(** {3 Signatures} *)andSignature:sigtyperecursive=Ordinary|And|Nonrec|Rectypeitem=|Moduleofrecursive*Module.t|ModuleTypeofModuleType.t|ModuleSubstitutionofModuleSubstitution.t|ModuleTypeSubstitutionofModuleTypeSubstitution.t|OpenofOpen.t|Typeofrecursive*TypeDecl.t|TypeSubstitutionofTypeDecl.t|TypExtofExtension.t|ExceptionofException.t|ValueofValue.t|Classofrecursive*Class.t|ClassTypeofrecursive*ClassType.t|IncludeofInclude.t|CommentofComment.docs_or_stoptypet={items:itemlist;compiled:bool;doc:Comment.docs;(** The top comment. *)}end=SignatureandOpen:sigtypet={expansion:Signature.t;doc:Comment.docs}end=Open(** {3 Includes} *)andInclude:sigtypeshadowed={s_modules:stringlist;s_module_types:stringlist;s_values:stringlist;s_types:stringlist;s_classes:stringlist;s_class_types:stringlist;}typeexpansion={shadowed:shadowed;content:Signature.t}(* Explicitly unexpanded decl *)typedecl=AliasofPath.Module.t|ModuleTypeofModuleType.U.exprtypet={loc:Location_.span;parent:Identifier.Signature.t;strengthened:Path.Module.toption;doc:Comment.docs;status:[`Inline|`Closed|`Open|`Default];decl:decl;expansion:expansion;}end=Include(** {3 Type Declarations} *)andTypeDecl:sigmoduleField:sigtypet={id:Identifier.Field.t;doc:Comment.docs;mutable_:bool;type_:TypeExpr.t;}endmoduleConstructor:sigtypeargument=TupleofTypeExpr.tlist|RecordofField.tlisttypet={id:Identifier.Constructor.t;doc:Comment.docs;args:argument;res:TypeExpr.toption;}endmoduleRepresentation:sigtypet=|VariantofConstructor.tlist|RecordofField.tlist|Extensibleendtypevariance=Pos|Negtypeparam_desc=Any|Varofstringtypeparam={desc:param_desc;variance:varianceoption;injectivity:bool;}moduleEquation:sigtypet={params:paramlist;private_:bool;manifest:TypeExpr.toption;constraints:(TypeExpr.t*TypeExpr.t)list;}endtypet={id:Identifier.Type.t;locs:Identifier.SourceLocation.toption;doc:Comment.docs;canonical:Path.Type.toption;equation:Equation.t;representation:Representation.toption;}end=TypeDecl(** {3 Type extensions} *)andExtension:sigmoduleConstructor:sigtypet={id:Identifier.Extension.t;locs:Identifier.SourceLocation.toption;doc:Comment.docs;args:TypeDecl.Constructor.argument;res:TypeExpr.toption;}endtypet={parent:Identifier.Signature.t;type_path:Path.Type.t;doc:Comment.docs;type_params:TypeDecl.paramlist;private_:bool;constructors:Constructor.tlist;}end=Extension(** {3 Exception} *)andException:sigtypet={id:Identifier.Exception.t;locs:Identifier.SourceLocation.toption;doc:Comment.docs;args:TypeDecl.Constructor.argument;res:TypeExpr.toption;}end=Exception(** {3 Values} *)andValue:sigtypevalue=Abstract|Externalofstringlisttypet={id:Identifier.Value.t;locs:Identifier.SourceLocation.toption;value:value;doc:Comment.docs;type_:TypeExpr.t;}end=Value(** {3 Classes} *)andClass:sigtypedecl=|ClassTypeofClassType.expr|ArrowofTypeExpr.labeloption*TypeExpr.t*decltypet={id:Identifier.Class.t;locs:Identifier.SourceLocation.toption;doc:Comment.docs;virtual_:bool;params:TypeDecl.paramlist;type_:decl;expansion:ClassSignature.toption;}end=Class(** {3 Class Types} *)andClassType:sigtypeexpr=|ConstrofPath.ClassType.t*TypeExpr.tlist|SignatureofClassSignature.ttypet={id:Identifier.ClassType.t;locs:Identifier.SourceLocation.toption;doc:Comment.docs;virtual_:bool;params:TypeDecl.paramlist;expr:expr;expansion:ClassSignature.toption;}end=ClassType(** {3 Class Signatures} *)andClassSignature:sigmoduleConstraint:sigtypet={left:TypeExpr.t;right:TypeExpr.t;doc:Comment.docs}endmoduleInherit:sigtypet={expr:ClassType.expr;doc:Comment.docs}endtypeitem=|MethodofMethod.t|InstanceVariableofInstanceVariable.t|ConstraintofConstraint.t|InheritofInherit.t|CommentofComment.docs_or_stoptypet={self:TypeExpr.toption;items:itemlist;doc:Comment.docs}end=ClassSignature(** {3 Methods} *)andMethod:sigtypet={id:Identifier.Method.t;doc:Comment.docs;private_:bool;virtual_:bool;type_:TypeExpr.t;}end=Method(** {3 Instance variables} *)andInstanceVariable:sigtypet={id:Identifier.InstanceVariable.t;doc:Comment.docs;mutable_:bool;virtual_:bool;type_:TypeExpr.t;}end=InstanceVariable(** {3 Type expressions} *)andTypeExpr:sigmodulePolymorphic_variant:sigtypekind=Fixed|Closedofstringlist|OpenmoduleConstructor:sigtypet={name:string;constant:bool;arguments:TypeExpr.tlist;doc:Comment.docs;}endtypeelement=TypeofTypeExpr.t|ConstructorofConstructor.ttypet={kind:kind;elements:elementlist}endmoduleObject:sigtypemethod_={name:string;type_:TypeExpr.t}typefield=Methodofmethod_|InheritofTypeExpr.ttypet={fields:fieldlist;open_:bool}endmodulePackage:sigtypesubstitution=Fragment.Type.t*TypeExpr.ttypet={path:Path.ModuleType.t;substitutions:substitutionlist}endtypelabel=Labelofstring|Optionalofstringtypet=|Varofstring|Any|Aliasoft*string|Arrowoflabeloption*t*t|Tupleoftlist|ConstrofPath.Type.t*tlist|Polymorphic_variantofTypeExpr.Polymorphic_variant.t|ObjectofTypeExpr.Object.t|ClassofPath.ClassType.t*tlist|Polyofstringlist*t|PackageofTypeExpr.Package.tend=TypeExpr(** {3 Compilation units} *)modulerecCompilation_unit:sigmoduleImport:sigtypet=|Unresolvedofstring*Digest.toption|ResolvedofRoot.t*Names.ModuleName.tendmoduleSource:sigtypet={file:string;build_dir:string;digest:Digest.t}endmodulePacked:sigtypeitem={id:Identifier.Module.t;path:Path.Module.t}typet=itemlistendtypecontent=ModuleofSignature.t|PackofPacked.ttypet={id:Identifier.RootModule.t;root:Root.t;digest:Digest.t;imports:Import.tlist;source:Source.toption;interface:bool;hidden:bool;content:content;expansion:Signature.toption;linked:bool;(** Whether this unit has been linked. *)canonical:Path.Module.toption;source_info:Source_info.toption;shape_info:(Compat.shape*Paths.Identifier.SourceLocation.tCompat.shape_uid_map)option;}end=Compilation_unitmodulerecPage:sigtypechild=|Page_childofstring|Module_childofstring|Source_tree_childofstring|Asset_childofstringtypet={name:Identifier.Page.t;root:Root.t;content:Comment.docs;children:childlist;digest:Digest.t;linked:bool;}end=PagemodulerecSourceTree:sigtypet={name:Identifier.Page.t;root:Root.t;source_children:Identifier.SourcePage.tlist;digest:Digest.t;}end=SourceTreeletumty_of_mty:ModuleType.expr->ModuleType.U.exproption=function|Signaturesg->Some(Signaturesg)|Path{p_path;_}->Some(Pathp_path)|Functor_->None|TypeOft->Some(TypeOft)|With{w_substitutions;w_expr;_}->Some(With(w_substitutions,w_expr))(** Query the top-comment of a signature. This is [s.doc] most of the time with
an exception for signature starting with an inline includes. *)letextract_signature_doc(s:Signature.t)=match(s.doc,s.items)with|[],Include{expansion;status=`Inline;_}::_->(* A signature that starts with an [@inline] include inherits the
top-comment from the expansion. This comment is not rendered for
[include] items. *)expansion.content.doc|doc,_->doc