1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968(**************************************************************************)(* *)(* OCaml Migrate Parsetree *)(* *)(* Frédéric Bour *)(* Jérémie Dimino and Leo White, Jane Street Europe *)(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)(* Alain Frisch, LexiFi *)(* Daniel de Rauglaudre, projet Cristal, INRIA Rocquencourt *)(* *)(* Copyright 2017 Institut National de Recherche en Informatique et *)(* en Automatique (INRIA). *)(* *)(* All rights reserved. This file is distributed under the terms of *)(* the GNU Lesser General Public License version 2.1, with the *)(* special exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)moduleLocation=LocationmoduleLongident=LongidentmoduleAsttypes=struct(** Auxiliary AST types used by parsetree and typedtree. *)typeconstant(*IF_CURRENT = Asttypes.constant *)=Const_intofint|Const_charofchar|Const_stringofstring*stringoption|Const_floatofstring|Const_int32ofint32|Const_int64ofint64|Const_nativeintofnativeinttyperec_flag(*IF_CURRENT = Asttypes.rec_flag *)=Nonrecursive|Recursivetypedirection_flag(*IF_CURRENT = Asttypes.direction_flag *)=Upto|Downto(* Order matters, used in polymorphic comparison *)typeprivate_flag(*IF_CURRENT = Asttypes.private_flag *)=Private|Publictypemutable_flag(*IF_CURRENT = Asttypes.mutable_flag *)=Immutable|Mutabletypevirtual_flag(*IF_CURRENT = Asttypes.virtual_flag *)=Virtual|Concretetypeoverride_flag(*IF_CURRENT = Asttypes.override_flag *)=Override|Freshtypeclosed_flag(*IF_CURRENT = Asttypes.closed_flag *)=Closed|Opentypelabel=stringtypearg_label(*IF_CURRENT = Asttypes.arg_label *)=Nolabel|Labelledofstring(* label:T -> ... *)|Optionalofstring(* ?label:T -> ... *)type'aloc='aLocation.loc={txt:'a;loc:Location.t;}typevariance(*IF_CURRENT = Asttypes.variance *)=|Covariant|Contravariant|InvariantendmoduleParsetree=struct(** Abstract syntax tree produced by parsing *)openAsttypestypeconstant(*IF_CURRENT = Parsetree.constant *)=Pconst_integerofstring*charoption(* 3 3l 3L 3n
Suffixes [g-z][G-Z] are accepted by the parser.
Suffixes except 'l', 'L' and 'n' are rejected by the typechecker
*)|Pconst_charofchar(* 'c' *)|Pconst_stringofstring*stringoption(* "constant"
{delim|other constant|delim}
*)|Pconst_floatofstring*charoption(* 3.4 2e5 1.4e-4
Suffixes [g-z][G-Z] are accepted by the parser.
Suffixes are rejected by the typechecker.
*)(** {2 Extension points} *)typeattribute=stringloc*payload(* [@id ARG]
[@@id ARG]
Metadata containers passed around within the AST.
The compiler ignores unknown attributes.
*)andextension=stringloc*payload(* [%id ARG]
[%%id ARG]
Sub-language placeholder -- rejected by the typechecker.
*)andattributes=attributelistandpayload(*IF_CURRENT = Parsetree.payload *)=|PStrofstructure|PSigofsignature(* : SIG *)|PTypofcore_type(* : T *)|PPatofpattern*expressionoption(* ? P or ? P when E *)(** {2 Core language} *)(* Type expressions *)andcore_type(*IF_CURRENT = Parsetree.core_type *)={ptyp_desc:core_type_desc;ptyp_loc:Location.t;ptyp_attributes:attributes;(* ... [@id1] [@id2] *)}andcore_type_desc(*IF_CURRENT = Parsetree.core_type_desc *)=|Ptyp_any(* _ *)|Ptyp_varofstring(* 'a *)|Ptyp_arrowofarg_label*core_type*core_type(* T1 -> T2 Simple
~l:T1 -> T2 Labelled
?l:T1 -> T2 Otional
*)|Ptyp_tupleofcore_typelist(* T1 * ... * Tn
Invariant: n >= 2
*)|Ptyp_constrofLongident.tloc*core_typelist(* tconstr
T tconstr
(T1, ..., Tn) tconstr
*)|Ptyp_objectof(string*attributes*core_type)list*closed_flag(* < l1:T1; ...; ln:Tn > (flag = Closed)
< l1:T1; ...; ln:Tn; .. > (flag = Open)
*)|Ptyp_classofLongident.tloc*core_typelist(* #tconstr
T #tconstr
(T1, ..., Tn) #tconstr
*)|Ptyp_aliasofcore_type*string(* T as 'a *)|Ptyp_variantofrow_fieldlist*closed_flag*labellistoption(* [ `A|`B ] (flag = Closed; labels = None)
[> `A|`B ] (flag = Open; labels = None)
[< `A|`B ] (flag = Closed; labels = Some [])
[< `A|`B > `X `Y ](flag = Closed; labels = Some ["X";"Y"])
*)|Ptyp_polyofstringlist*core_type(* 'a1 ... 'an. T
Can only appear in the following context:
- As the core_type of a Ppat_constraint node corresponding
to a constraint on a let-binding: let x : 'a1 ... 'an. T
= e ...
- Under Cfk_virtual for methods (not values).
- As the core_type of a Pctf_method node.
- As the core_type of a Pexp_poly node.
- As the pld_type field of a label_declaration.
- As a core_type of a Ptyp_object node.
*)|Ptyp_packageofpackage_type(* (module S) *)|Ptyp_extensionofextension(* [%id] *)andpackage_type=Longident.tloc*(Longident.tloc*core_type)list(*
(module S)
(module S with type t1 = T1 and ... and tn = Tn)
*)androw_field(*IF_CURRENT = Parsetree.row_field *)=|Rtagoflabel*attributes*bool*core_typelist(* [`A] ( true, [] )
[`A of T] ( false, [T] )
[`A of T1 & .. & Tn] ( false, [T1;...Tn] )
[`A of & T1 & .. & Tn] ( true, [T1;...Tn] )
- The 2nd field is true if the tag contains a
constant (empty) constructor.
- '&' occurs when several types are used for the same constructor
(see 4.2 in the manual)
- TODO: switch to a record representation, and keep location
*)|Rinheritofcore_type(* [ T ] *)(* Patterns *)andpattern(*IF_CURRENT = Parsetree.pattern *)={ppat_desc:pattern_desc;ppat_loc:Location.t;ppat_attributes:attributes;(* ... [@id1] [@id2] *)}andpattern_desc(*IF_CURRENT = Parsetree.pattern_desc *)=|Ppat_any(* _ *)|Ppat_varofstringloc(* x *)|Ppat_aliasofpattern*stringloc(* P as 'a *)|Ppat_constantofconstant(* 1, 'a', "true", 1.0, 1l, 1L, 1n *)|Ppat_intervalofconstant*constant(* 'a'..'z'
Other forms of interval are recognized by the parser
but rejected by the type-checker. *)|Ppat_tupleofpatternlist(* (P1, ..., Pn)
Invariant: n >= 2
*)|Ppat_constructofLongident.tloc*patternoption(* C None
C P Some P
C (P1, ..., Pn) Some (Ppat_tuple [P1; ...; Pn])
*)|Ppat_variantoflabel*patternoption(* `A (None)
`A P (Some P)
*)|Ppat_recordof(Longident.tloc*pattern)list*closed_flag(* { l1=P1; ...; ln=Pn } (flag = Closed)
{ l1=P1; ...; ln=Pn; _} (flag = Open)
Invariant: n > 0
*)|Ppat_arrayofpatternlist(* [| P1; ...; Pn |] *)|Ppat_orofpattern*pattern(* P1 | P2 *)|Ppat_constraintofpattern*core_type(* (P : T) *)|Ppat_typeofLongident.tloc(* #tconst *)|Ppat_lazyofpattern(* lazy P *)|Ppat_unpackofstringloc(* (module P)
Note: (module P : S) is represented as
Ppat_constraint(Ppat_unpack, Ptyp_package)
*)|Ppat_exceptionofpattern(* exception P *)|Ppat_extensionofextension(* [%id] *)|Ppat_openofLongident.tloc*pattern(* Value expressions *)andexpression(*IF_CURRENT = Parsetree.expression *)={pexp_desc:expression_desc;pexp_loc:Location.t;pexp_attributes:attributes;(* ... [@id1] [@id2] *)}andexpression_desc(*IF_CURRENT = Parsetree.expression_desc *)=|Pexp_identofLongident.tloc(* x
M.x
*)|Pexp_constantofconstant(* 1, 'a', "true", 1.0, 1l, 1L, 1n *)|Pexp_letofrec_flag*value_bindinglist*expression(* let P1 = E1 and ... and Pn = EN in E (flag = Nonrecursive)
let rec P1 = E1 and ... and Pn = EN in E (flag = Recursive)
*)|Pexp_functionofcaselist(* function P1 -> E1 | ... | Pn -> En *)|Pexp_funofarg_label*expressionoption*pattern*expression(* fun P -> E1 (Simple, None)
fun ~l:P -> E1 (Labelled l, None)
fun ?l:P -> E1 (Optional l, None)
fun ?l:(P = E0) -> E1 (Optional l, Some E0)
Notes:
- If E0 is provided, only Optional is allowed.
- "fun P1 P2 .. Pn -> E1" is represented as nested Pexp_fun.
- "let f P = E" is represented using Pexp_fun.
*)|Pexp_applyofexpression*(arg_label*expression)list(* E0 ~l1:E1 ... ~ln:En
li can be empty (non labeled argument) or start with '?'
(optional argument).
Invariant: n > 0
*)|Pexp_matchofexpression*caselist(* match E0 with P1 -> E1 | ... | Pn -> En *)|Pexp_tryofexpression*caselist(* try E0 with P1 -> E1 | ... | Pn -> En *)|Pexp_tupleofexpressionlist(* (E1, ..., En)
Invariant: n >= 2
*)|Pexp_constructofLongident.tloc*expressionoption(* C None
C E Some E
C (E1, ..., En) Some (Pexp_tuple[E1;...;En])
*)|Pexp_variantoflabel*expressionoption(* `A (None)
`A E (Some E)
*)|Pexp_recordof(Longident.tloc*expression)list*expressionoption(* { l1=P1; ...; ln=Pn } (None)
{ E0 with l1=P1; ...; ln=Pn } (Some E0)
Invariant: n > 0
*)|Pexp_fieldofexpression*Longident.tloc(* E.l *)|Pexp_setfieldofexpression*Longident.tloc*expression(* E1.l <- E2 *)|Pexp_arrayofexpressionlist(* [| E1; ...; En |] *)|Pexp_ifthenelseofexpression*expression*expressionoption(* if E1 then E2 else E3 *)|Pexp_sequenceofexpression*expression(* E1; E2 *)|Pexp_whileofexpression*expression(* while E1 do E2 done *)|Pexp_forofpattern*expression*expression*direction_flag*expression(* for i = E1 to E2 do E3 done (flag = Upto)
for i = E1 downto E2 do E3 done (flag = Downto)
*)|Pexp_constraintofexpression*core_type(* (E : T) *)|Pexp_coerceofexpression*core_typeoption*core_type(* (E :> T) (None, T)
(E : T0 :> T) (Some T0, T)
*)|Pexp_sendofexpression*string(* E # m *)|Pexp_newofLongident.tloc(* new M.c *)|Pexp_setinstvarofstringloc*expression(* x <- 2 *)|Pexp_overrideof(stringloc*expression)list(* {< x1 = E1; ...; Xn = En >} *)|Pexp_letmoduleofstringloc*module_expr*expression(* let module M = ME in E *)|Pexp_letexceptionofextension_constructor*expression(* let exception C in E *)|Pexp_assertofexpression(* assert E
Note: "assert false" is treated in a special way by the
type-checker. *)|Pexp_lazyofexpression(* lazy E *)|Pexp_polyofexpression*core_typeoption(* Used for method bodies.
Can only be used as the expression under Cfk_concrete
for methods (not values). *)|Pexp_objectofclass_structure(* object ... end *)|Pexp_newtypeofstring*expression(* fun (type t) -> E *)|Pexp_packofmodule_expr(* (module ME)
(module ME : S) is represented as
Pexp_constraint(Pexp_pack, Ptyp_package S) *)|Pexp_openofoverride_flag*Longident.tloc*expression(* let open M in E
let! open M in E
*)|Pexp_extensionofextension(* [%id] *)|Pexp_unreachable(* . *)andcase(*IF_CURRENT = Parsetree.case *)=(* (P -> E) or (P when E0 -> E) *){pc_lhs:pattern;pc_guard:expressionoption;pc_rhs:expression;}(* Value descriptions *)andvalue_description(*IF_CURRENT = Parsetree.value_description *)={pval_name:stringloc;pval_type:core_type;pval_prim:stringlist;pval_attributes:attributes;(* ... [@@id1] [@@id2] *)pval_loc:Location.t;}(*
val x: T (prim = [])
external x: T = "s1" ... "sn" (prim = ["s1";..."sn"])
*)(* Type declarations *)andtype_declaration(*IF_CURRENT = Parsetree.type_declaration *)={ptype_name:stringloc;ptype_params:(core_type*variance)list;(* ('a1,...'an) t; None represents _*)ptype_cstrs:(core_type*core_type*Location.t)list;(* ... constraint T1=T1' ... constraint Tn=Tn' *)ptype_kind:type_kind;ptype_private:private_flag;(* = private ... *)ptype_manifest:core_typeoption;(* = T *)ptype_attributes:attributes;(* ... [@@id1] [@@id2] *)ptype_loc:Location.t;}(*
type t (abstract, no manifest)
type t = T0 (abstract, manifest=T0)
type t = C of T | ... (variant, no manifest)
type t = T0 = C of T | ... (variant, manifest=T0)
type t = {l: T; ...} (record, no manifest)
type t = T0 = {l : T; ...} (record, manifest=T0)
type t = .. (open, no manifest)
*)andtype_kind(*IF_CURRENT = Parsetree.type_kind *)=|Ptype_abstract|Ptype_variantofconstructor_declarationlist(* Invariant: non-empty list *)|Ptype_recordoflabel_declarationlist(* Invariant: non-empty list *)|Ptype_openandlabel_declaration(*IF_CURRENT = Parsetree.label_declaration *)={pld_name:stringloc;pld_mutable:mutable_flag;pld_type:core_type;pld_loc:Location.t;pld_attributes:attributes;(* l [@id1] [@id2] : T *)}(* { ...; l: T; ... } (mutable=Immutable)
{ ...; mutable l: T; ... } (mutable=Mutable)
Note: T can be a Ptyp_poly.
*)andconstructor_declaration(*IF_CURRENT = Parsetree.constructor_declaration *)={pcd_name:stringloc;pcd_args:constructor_arguments;pcd_res:core_typeoption;pcd_loc:Location.t;pcd_attributes:attributes;(* C [@id1] [@id2] of ... *)}andconstructor_arguments(*IF_CURRENT = Parsetree.constructor_arguments *)=|Pcstr_tupleofcore_typelist|Pcstr_recordoflabel_declarationlist(*
| C of T1 * ... * Tn (res = None, args = Pcstr_tuple [])
| C: T0 (res = Some T0, args = [])
| C: T1 * ... * Tn -> T0 (res = Some T0, args = Pcstr_tuple)
| C of {...} (res = None, args = Pcstr_record)
| C: {...} -> T0 (res = Some T0, args = Pcstr_record)
| C of {...} as t (res = None, args = Pcstr_record)
*)andtype_extension(*IF_CURRENT = Parsetree.type_extension *)={ptyext_path:Longident.tloc;ptyext_params:(core_type*variance)list;ptyext_constructors:extension_constructorlist;ptyext_private:private_flag;ptyext_attributes:attributes;(* ... [@@id1] [@@id2] *)}(*
type t += ...
*)andextension_constructor(*IF_CURRENT = Parsetree.extension_constructor *)={pext_name:stringloc;pext_kind:extension_constructor_kind;pext_loc:Location.t;pext_attributes:attributes;(* C [@id1] [@id2] of ... *)}andextension_constructor_kind(*IF_CURRENT = Parsetree.extension_constructor_kind *)=Pext_declofconstructor_arguments*core_typeoption(*
| C of T1 * ... * Tn ([T1; ...; Tn], None)
| C: T0 ([], Some T0)
| C: T1 * ... * Tn -> T0 ([T1; ...; Tn], Some T0)
*)|Pext_rebindofLongident.tloc(*
| C = D
*)(** {2 Class language} *)(* Type expressions for the class language *)andclass_type(*IF_CURRENT = Parsetree.class_type *)={pcty_desc:class_type_desc;pcty_loc:Location.t;pcty_attributes:attributes;(* ... [@id1] [@id2] *)}andclass_type_desc(*IF_CURRENT = Parsetree.class_type_desc *)=|Pcty_constrofLongident.tloc*core_typelist(* c
['a1, ..., 'an] c *)|Pcty_signatureofclass_signature(* object ... end *)|Pcty_arrowofarg_label*core_type*class_type(* T -> CT Simple
~l:T -> CT Labelled l
?l:T -> CT Optional l
*)|Pcty_extensionofextension(* [%id] *)andclass_signature(*IF_CURRENT = Parsetree.class_signature *)={pcsig_self:core_type;pcsig_fields:class_type_fieldlist;}(* object('selfpat) ... end
object ... end (self = Ptyp_any)
*)andclass_type_field(*IF_CURRENT = Parsetree.class_type_field *)={pctf_desc:class_type_field_desc;pctf_loc:Location.t;pctf_attributes:attributes;(* ... [@@id1] [@@id2] *)}andclass_type_field_desc(*IF_CURRENT = Parsetree.class_type_field_desc *)=|Pctf_inheritofclass_type(* inherit CT *)|Pctf_valof(string*mutable_flag*virtual_flag*core_type)(* val x: T *)|Pctf_methodof(string*private_flag*virtual_flag*core_type)(* method x: T
Note: T can be a Ptyp_poly.
*)|Pctf_constraintof(core_type*core_type)(* constraint T1 = T2 *)|Pctf_attributeofattribute(* [@@@id] *)|Pctf_extensionofextension(* [%%id] *)and'aclass_infos(*IF_CURRENT = 'a Parsetree.class_infos *)={pci_virt:virtual_flag;pci_params:(core_type*variance)list;pci_name:stringloc;pci_expr:'a;pci_loc:Location.t;pci_attributes:attributes;(* ... [@@id1] [@@id2] *)}(* class c = ...
class ['a1,...,'an] c = ...
class virtual c = ...
Also used for "class type" declaration.
*)andclass_description=class_typeclass_infosandclass_type_declaration=class_typeclass_infos(* Value expressions for the class language *)andclass_expr(*IF_CURRENT = Parsetree.class_expr *)={pcl_desc:class_expr_desc;pcl_loc:Location.t;pcl_attributes:attributes;(* ... [@id1] [@id2] *)}andclass_expr_desc(*IF_CURRENT = Parsetree.class_expr_desc *)=|Pcl_constrofLongident.tloc*core_typelist(* c
['a1, ..., 'an] c *)|Pcl_structureofclass_structure(* object ... end *)|Pcl_funofarg_label*expressionoption*pattern*class_expr(* fun P -> CE (Simple, None)
fun ~l:P -> CE (Labelled l, None)
fun ?l:P -> CE (Optional l, None)
fun ?l:(P = E0) -> CE (Optional l, Some E0)
*)|Pcl_applyofclass_expr*(arg_label*expression)list(* CE ~l1:E1 ... ~ln:En
li can be empty (non labeled argument) or start with '?'
(optional argument).
Invariant: n > 0
*)|Pcl_letofrec_flag*value_bindinglist*class_expr(* let P1 = E1 and ... and Pn = EN in CE (flag = Nonrecursive)
let rec P1 = E1 and ... and Pn = EN in CE (flag = Recursive)
*)|Pcl_constraintofclass_expr*class_type(* (CE : CT) *)|Pcl_extensionofextension(* [%id] *)andclass_structure(*IF_CURRENT = Parsetree.class_structure *)={pcstr_self:pattern;pcstr_fields:class_fieldlist;}(* object(selfpat) ... end
object ... end (self = Ppat_any)
*)andclass_field(*IF_CURRENT = Parsetree.class_field *)={pcf_desc:class_field_desc;pcf_loc:Location.t;pcf_attributes:attributes;(* ... [@@id1] [@@id2] *)}andclass_field_desc(*IF_CURRENT = Parsetree.class_field_desc *)=|Pcf_inheritofoverride_flag*class_expr*stringoption(* inherit CE
inherit CE as x
inherit! CE
inherit! CE as x
*)|Pcf_valof(stringloc*mutable_flag*class_field_kind)(* val x = E
val virtual x: T
*)|Pcf_methodof(stringloc*private_flag*class_field_kind)(* method x = E (E can be a Pexp_poly)
method virtual x: T (T can be a Ptyp_poly)
*)|Pcf_constraintof(core_type*core_type)(* constraint T1 = T2 *)|Pcf_initializerofexpression(* initializer E *)|Pcf_attributeofattribute(* [@@@id] *)|Pcf_extensionofextension(* [%%id] *)andclass_field_kind(*IF_CURRENT = Parsetree.class_field_kind *)=|Cfk_virtualofcore_type|Cfk_concreteofoverride_flag*expressionandclass_declaration=class_exprclass_infos(** {2 Module language} *)(* Type expressions for the module language *)andmodule_type(*IF_CURRENT = Parsetree.module_type *)={pmty_desc:module_type_desc;pmty_loc:Location.t;pmty_attributes:attributes;(* ... [@id1] [@id2] *)}andmodule_type_desc(*IF_CURRENT = Parsetree.module_type_desc *)=|Pmty_identofLongident.tloc(* S *)|Pmty_signatureofsignature(* sig ... end *)|Pmty_functorofstringloc*module_typeoption*module_type(* functor(X : MT1) -> MT2 *)|Pmty_withofmodule_type*with_constraintlist(* MT with ... *)|Pmty_typeofofmodule_expr(* module type of ME *)|Pmty_extensionofextension(* [%id] *)|Pmty_aliasofLongident.tloc(* (module M) *)andsignature=signature_itemlistandsignature_item(*IF_CURRENT = Parsetree.signature_item *)={psig_desc:signature_item_desc;psig_loc:Location.t;}andsignature_item_desc(*IF_CURRENT = Parsetree.signature_item_desc *)=|Psig_valueofvalue_description(*
val x: T
external x: T = "s1" ... "sn"
*)|Psig_typeofrec_flag*type_declarationlist(* type t1 = ... and ... and tn = ... *)|Psig_typextoftype_extension(* type t1 += ... *)|Psig_exceptionofextension_constructor(* exception C of T *)|Psig_moduleofmodule_declaration(* module X : MT *)|Psig_recmoduleofmodule_declarationlist(* module rec X1 : MT1 and ... and Xn : MTn *)|Psig_modtypeofmodule_type_declaration(* module type S = MT
module type S *)|Psig_openofopen_description(* open X *)|Psig_includeofinclude_description(* include MT *)|Psig_classofclass_descriptionlist(* class c1 : ... and ... and cn : ... *)|Psig_class_typeofclass_type_declarationlist(* class type ct1 = ... and ... and ctn = ... *)|Psig_attributeofattribute(* [@@@id] *)|Psig_extensionofextension*attributes(* [%%id] *)andmodule_declaration(*IF_CURRENT = Parsetree.module_declaration *)={pmd_name:stringloc;pmd_type:module_type;pmd_attributes:attributes;(* ... [@@id1] [@@id2] *)pmd_loc:Location.t;}(* S : MT *)andmodule_type_declaration(*IF_CURRENT = Parsetree.module_type_declaration *)={pmtd_name:stringloc;pmtd_type:module_typeoption;pmtd_attributes:attributes;(* ... [@@id1] [@@id2] *)pmtd_loc:Location.t;}(* S = MT
S (abstract module type declaration, pmtd_type = None)
*)andopen_description(*IF_CURRENT = Parsetree.open_description *)={popen_lid:Longident.tloc;popen_override:override_flag;popen_loc:Location.t;popen_attributes:attributes;}(* open! X - popen_override = Override (silences the 'used identifier
shadowing' warning)
open X - popen_override = Fresh
*)and'ainclude_infos(*IF_CURRENT = 'a Parsetree.include_infos *)={pincl_mod:'a;pincl_loc:Location.t;pincl_attributes:attributes;}andinclude_description=module_typeinclude_infos(* include MT *)andinclude_declaration=module_exprinclude_infos(* include ME *)andwith_constraint(*IF_CURRENT = Parsetree.with_constraint *)=|Pwith_typeofLongident.tloc*type_declaration(* with type X.t = ...
Note: the last component of the longident must match
the name of the type_declaration. *)|Pwith_moduleofLongident.tloc*Longident.tloc(* with module X.Y = Z *)|Pwith_typesubstoftype_declaration(* with type t := ... *)|Pwith_modsubstofstringloc*Longident.tloc(* with module X := Z *)(* Value expressions for the module language *)andmodule_expr(*IF_CURRENT = Parsetree.module_expr *)={pmod_desc:module_expr_desc;pmod_loc:Location.t;pmod_attributes:attributes;(* ... [@id1] [@id2] *)}andmodule_expr_desc(*IF_CURRENT = Parsetree.module_expr_desc *)=|Pmod_identofLongident.tloc(* X *)|Pmod_structureofstructure(* struct ... end *)|Pmod_functorofstringloc*module_typeoption*module_expr(* functor(X : MT1) -> ME *)|Pmod_applyofmodule_expr*module_expr(* ME1(ME2) *)|Pmod_constraintofmodule_expr*module_type(* (ME : MT) *)|Pmod_unpackofexpression(* (val E) *)|Pmod_extensionofextension(* [%id] *)andstructure=structure_itemlistandstructure_item(*IF_CURRENT = Parsetree.structure_item *)={pstr_desc:structure_item_desc;pstr_loc:Location.t;}andstructure_item_desc(*IF_CURRENT = Parsetree.structure_item_desc *)=|Pstr_evalofexpression*attributes(* E *)|Pstr_valueofrec_flag*value_bindinglist(* let P1 = E1 and ... and Pn = EN (flag = Nonrecursive)
let rec P1 = E1 and ... and Pn = EN (flag = Recursive)
*)|Pstr_primitiveofvalue_description(* val x: T
external x: T = "s1" ... "sn" *)|Pstr_typeofrec_flag*type_declarationlist(* type t1 = ... and ... and tn = ... *)|Pstr_typextoftype_extension(* type t1 += ... *)|Pstr_exceptionofextension_constructor(* exception C of T
exception C = M.X *)|Pstr_moduleofmodule_binding(* module X = ME *)|Pstr_recmoduleofmodule_bindinglist(* module rec X1 = ME1 and ... and Xn = MEn *)|Pstr_modtypeofmodule_type_declaration(* module type S = MT *)|Pstr_openofopen_description(* open X *)|Pstr_classofclass_declarationlist(* class c1 = ... and ... and cn = ... *)|Pstr_class_typeofclass_type_declarationlist(* class type ct1 = ... and ... and ctn = ... *)|Pstr_includeofinclude_declaration(* include ME *)|Pstr_attributeofattribute(* [@@@id] *)|Pstr_extensionofextension*attributes(* [%%id] *)andvalue_binding(*IF_CURRENT = Parsetree.value_binding *)={pvb_pat:pattern;pvb_expr:expression;pvb_attributes:attributes;pvb_loc:Location.t;}andmodule_binding(*IF_CURRENT = Parsetree.module_binding *)={pmb_name:stringloc;pmb_expr:module_expr;pmb_attributes:attributes;pmb_loc:Location.t;}(* X = ME *)(** {2 Toplevel} *)(* Toplevel phrases *)typetoplevel_phrase(*IF_CURRENT = Parsetree.toplevel_phrase *)=|Ptop_defofstructure|Ptop_dirofstring*directive_argument(* #use, #load ... *)anddirective_argument(*IF_CURRENT = Parsetree.directive_argument *)=|Pdir_none|Pdir_stringofstring|Pdir_intofstring*charoption|Pdir_identofLongident.t|Pdir_boolofboolendmoduleDocstrings:sig(** {3 Docstrings} *)(** Documentation comments *)typedocstring(** Create a docstring *)valdocstring:string->Location.t->docstring(** Get the text of a docstring *)valdocstring_body:docstring->string(** Get the location of a docstring *)valdocstring_loc:docstring->Location.t(** {3 Items}
The {!docs} type represents documentation attached to an item. *)typedocs={docs_pre:docstringoption;docs_post:docstringoption;}valempty_docs:docsvaldocs_attr:docstring->Parsetree.attribute(** Convert item documentation to attributes and add them to an
attribute list *)valadd_docs_attrs:docs->Parsetree.attributes->Parsetree.attributes(** {3 Fields and constructors}
The {!info} type represents documentation attached to a field or
constructor. *)typeinfo=docstringoptionvalempty_info:infovalinfo_attr:docstring->Parsetree.attribute(** Convert field info to attributes and add them to an
attribute list *)valadd_info_attrs:info->Parsetree.attributes->Parsetree.attributes(** {3 Unattached comments}
The {!text} type represents documentation which is not attached to
anything. *)typetext=docstringlistvalempty_text:textvaltext_attr:docstring->Parsetree.attribute(** Convert text to attributes and add them to an attribute list *)valadd_text_attrs:text->Parsetree.attributes->Parsetree.attributesend=structopenLocation(* Docstrings *)typedocstring={ds_body:string;ds_loc:Location.t;}(* Docstring constructors and destructors *)letdocstringbodyloc=letds={ds_body=body;ds_loc=loc;}indsletdocstring_bodyds=ds.ds_bodyletdocstring_locds=ds.ds_loc(* Docstrings attached to items *)typedocs={docs_pre:docstringoption;docs_post:docstringoption;}letempty_docs={docs_pre=None;docs_post=None}letdoc_loc={txt="ocaml.doc";loc=Location.none}letdocs_attrds=letopenParsetreeinletexp={pexp_desc=Pexp_constant(Pconst_string(ds.ds_body,None));pexp_loc=ds.ds_loc;pexp_attributes=[];}inletitem={pstr_desc=Pstr_eval(exp,[]);pstr_loc=exp.pexp_loc}in(doc_loc,PStr[item])letadd_docs_attrsdocsattrs=letattrs=matchdocs.docs_prewith|None|Some{ds_body="";_}->attrs|Someds->docs_attrds::attrsinletattrs=matchdocs.docs_postwith|None|Some{ds_body="";_}->attrs|Someds->attrs@[docs_attrds]inattrs(* Docstrings attached to constructors or fields *)typeinfo=docstringoptionletempty_info=Noneletinfo_attr=docs_attrletadd_info_attrsinfoattrs=matchinfowith|None|Some{ds_body="";_}->attrs|Someds->attrs@[info_attrds](* Docstrings not attached to a specific item *)typetext=docstringlistletempty_text=[]lettext_loc={txt="ocaml.text";loc=Location.none}lettext_attrds=letopenParsetreeinletexp={pexp_desc=Pexp_constant(Pconst_string(ds.ds_body,None));pexp_loc=ds.ds_loc;pexp_attributes=[];}inletitem={pstr_desc=Pstr_eval(exp,[]);pstr_loc=exp.pexp_loc}in(text_loc,PStr[item])letadd_text_attrsdslattrs=letfdsl=List.filter(function{ds_body="";_}->false|_->true)dslin(List.maptext_attrfdsl)@attrsendmoduleAst_helper:sig(** Helpers to produce Parsetree fragments *)openAsttypesopenDocstringsopenParsetreetypelid=Longident.tloctypestr=stringloctypeloc=Location.ttypeattrs=attributelist(** {2 Default locations} *)valdefault_loc:locref(** Default value for all optional location arguments. *)valwith_default_loc:loc->(unit->'a)->'a(** Set the [default_loc] within the scope of the execution
of the provided function. *)(** {2 Constants} *)moduleConst:sigvalchar:char->constantvalstring:?quotation_delimiter:string->string->constantvalinteger:?suffix:char->string->constantvalint:?suffix:char->int->constantvalint32:?suffix:char->int32->constantvalint64:?suffix:char->int64->constantvalnativeint:?suffix:char->nativeint->constantvalfloat:?suffix:char->string->constantend(** {2 Core language} *)(** Type expressions *)moduleTyp:sigvalmk:?loc:loc->?attrs:attrs->core_type_desc->core_typevalattr:core_type->attribute->core_typevalany:?loc:loc->?attrs:attrs->unit->core_typevalvar:?loc:loc->?attrs:attrs->string->core_typevalarrow:?loc:loc->?attrs:attrs->arg_label->core_type->core_type->core_typevaltuple:?loc:loc->?attrs:attrs->core_typelist->core_typevalconstr:?loc:loc->?attrs:attrs->lid->core_typelist->core_typevalobject_:?loc:loc->?attrs:attrs->(string*attributes*core_type)list->closed_flag->core_typevalclass_:?loc:loc->?attrs:attrs->lid->core_typelist->core_typevalalias:?loc:loc->?attrs:attrs->core_type->string->core_typevalvariant:?loc:loc->?attrs:attrs->row_fieldlist->closed_flag->labellistoption->core_typevalpoly:?loc:loc->?attrs:attrs->stringlist->core_type->core_typevalpackage:?loc:loc->?attrs:attrs->lid->(lid*core_type)list->core_typevalextension:?loc:loc->?attrs:attrs->extension->core_typevalforce_poly:core_type->core_typeend(** Patterns *)modulePat:sigvalmk:?loc:loc->?attrs:attrs->pattern_desc->patternvalattr:pattern->attribute->patternvalany:?loc:loc->?attrs:attrs->unit->patternvalvar:?loc:loc->?attrs:attrs->str->patternvalalias:?loc:loc->?attrs:attrs->pattern->str->patternvalconstant:?loc:loc->?attrs:attrs->constant->patternvalinterval:?loc:loc->?attrs:attrs->constant->constant->patternvaltuple:?loc:loc->?attrs:attrs->patternlist->patternvalconstruct:?loc:loc->?attrs:attrs->lid->patternoption->patternvalvariant:?loc:loc->?attrs:attrs->label->patternoption->patternvalrecord:?loc:loc->?attrs:attrs->(lid*pattern)list->closed_flag->patternvalarray:?loc:loc->?attrs:attrs->patternlist->patternvalor_:?loc:loc->?attrs:attrs->pattern->pattern->patternvalconstraint_:?loc:loc->?attrs:attrs->pattern->core_type->patternvaltype_:?loc:loc->?attrs:attrs->lid->patternvallazy_:?loc:loc->?attrs:attrs->pattern->patternvalunpack:?loc:loc->?attrs:attrs->str->patternvalopen_:?loc:loc->?attrs:attrs->lid->pattern->patternvalexception_:?loc:loc->?attrs:attrs->pattern->patternvalextension:?loc:loc->?attrs:attrs->extension->patternend(** Expressions *)moduleExp:sigvalmk:?loc:loc->?attrs:attrs->expression_desc->expressionvalattr:expression->attribute->expressionvalident:?loc:loc->?attrs:attrs->lid->expressionvalconstant:?loc:loc->?attrs:attrs->constant->expressionvallet_:?loc:loc->?attrs:attrs->rec_flag->value_bindinglist->expression->expressionvalfun_:?loc:loc->?attrs:attrs->arg_label->expressionoption->pattern->expression->expressionvalfunction_:?loc:loc->?attrs:attrs->caselist->expressionvalapply:?loc:loc->?attrs:attrs->expression->(arg_label*expression)list->expressionvalmatch_:?loc:loc->?attrs:attrs->expression->caselist->expressionvaltry_:?loc:loc->?attrs:attrs->expression->caselist->expressionvaltuple:?loc:loc->?attrs:attrs->expressionlist->expressionvalconstruct:?loc:loc->?attrs:attrs->lid->expressionoption->expressionvalvariant:?loc:loc->?attrs:attrs->label->expressionoption->expressionvalrecord:?loc:loc->?attrs:attrs->(lid*expression)list->expressionoption->expressionvalfield:?loc:loc->?attrs:attrs->expression->lid->expressionvalsetfield:?loc:loc->?attrs:attrs->expression->lid->expression->expressionvalarray:?loc:loc->?attrs:attrs->expressionlist->expressionvalifthenelse:?loc:loc->?attrs:attrs->expression->expression->expressionoption->expressionvalsequence:?loc:loc->?attrs:attrs->expression->expression->expressionvalwhile_:?loc:loc->?attrs:attrs->expression->expression->expressionvalfor_:?loc:loc->?attrs:attrs->pattern->expression->expression->direction_flag->expression->expressionvalcoerce:?loc:loc->?attrs:attrs->expression->core_typeoption->core_type->expressionvalconstraint_:?loc:loc->?attrs:attrs->expression->core_type->expressionvalsend:?loc:loc->?attrs:attrs->expression->string->expressionvalnew_:?loc:loc->?attrs:attrs->lid->expressionvalsetinstvar:?loc:loc->?attrs:attrs->str->expression->expressionvaloverride:?loc:loc->?attrs:attrs->(str*expression)list->expressionvalletmodule:?loc:loc->?attrs:attrs->str->module_expr->expression->expressionvalletexception:?loc:loc->?attrs:attrs->extension_constructor->expression->expressionvalassert_:?loc:loc->?attrs:attrs->expression->expressionvallazy_:?loc:loc->?attrs:attrs->expression->expressionvalpoly:?loc:loc->?attrs:attrs->expression->core_typeoption->expressionvalobject_:?loc:loc->?attrs:attrs->class_structure->expressionvalnewtype:?loc:loc->?attrs:attrs->string->expression->expressionvalpack:?loc:loc->?attrs:attrs->module_expr->expressionvalopen_:?loc:loc->?attrs:attrs->override_flag->lid->expression->expressionvalextension:?loc:loc->?attrs:attrs->extension->expressionvalunreachable:?loc:loc->?attrs:attrs->unit->expressionvalcase:pattern->?guard:expression->expression->caseend(** Value declarations *)moduleVal:sigvalmk:?loc:loc->?attrs:attrs->?docs:docs->?prim:stringlist->str->core_type->value_descriptionend(** Type declarations *)moduleType:sigvalmk:?loc:loc->?attrs:attrs->?docs:docs->?text:text->?params:(core_type*variance)list->?cstrs:(core_type*core_type*loc)list->?kind:type_kind->?priv:private_flag->?manifest:core_type->str->type_declarationvalconstructor:?loc:loc->?attrs:attrs->?info:info->?args:constructor_arguments->?res:core_type->str->constructor_declarationvalfield:?loc:loc->?attrs:attrs->?info:info->?mut:mutable_flag->str->core_type->label_declarationend(** Type extensions *)moduleTe:sigvalmk:?attrs:attrs->?docs:docs->?params:(core_type*variance)list->?priv:private_flag->lid->extension_constructorlist->type_extensionvalconstructor:?loc:loc->?attrs:attrs->?docs:docs->?info:info->str->extension_constructor_kind->extension_constructorvaldecl:?loc:loc->?attrs:attrs->?docs:docs->?info:info->?args:constructor_arguments->?res:core_type->str->extension_constructorvalrebind:?loc:loc->?attrs:attrs->?docs:docs->?info:info->str->lid->extension_constructorend(** {2 Module language} *)(** Module type expressions *)moduleMty:sigvalmk:?loc:loc->?attrs:attrs->module_type_desc->module_typevalattr:module_type->attribute->module_typevalident:?loc:loc->?attrs:attrs->lid->module_typevalalias:?loc:loc->?attrs:attrs->lid->module_typevalsignature:?loc:loc->?attrs:attrs->signature->module_typevalfunctor_:?loc:loc->?attrs:attrs->str->module_typeoption->module_type->module_typevalwith_:?loc:loc->?attrs:attrs->module_type->with_constraintlist->module_typevaltypeof_:?loc:loc->?attrs:attrs->module_expr->module_typevalextension:?loc:loc->?attrs:attrs->extension->module_typeend(** Module expressions *)moduleMod:sigvalmk:?loc:loc->?attrs:attrs->module_expr_desc->module_exprvalattr:module_expr->attribute->module_exprvalident:?loc:loc->?attrs:attrs->lid->module_exprvalstructure:?loc:loc->?attrs:attrs->structure->module_exprvalfunctor_:?loc:loc->?attrs:attrs->str->module_typeoption->module_expr->module_exprvalapply:?loc:loc->?attrs:attrs->module_expr->module_expr->module_exprvalconstraint_:?loc:loc->?attrs:attrs->module_expr->module_type->module_exprvalunpack:?loc:loc->?attrs:attrs->expression->module_exprvalextension:?loc:loc->?attrs:attrs->extension->module_exprend(** Signature items *)moduleSig:sigvalmk:?loc:loc->signature_item_desc->signature_itemvalvalue:?loc:loc->value_description->signature_itemvaltype_:?loc:loc->rec_flag->type_declarationlist->signature_itemvaltype_extension:?loc:loc->type_extension->signature_itemvalexception_:?loc:loc->extension_constructor->signature_itemvalmodule_:?loc:loc->module_declaration->signature_itemvalrec_module:?loc:loc->module_declarationlist->signature_itemvalmodtype:?loc:loc->module_type_declaration->signature_itemvalopen_:?loc:loc->open_description->signature_itemvalinclude_:?loc:loc->include_description->signature_itemvalclass_:?loc:loc->class_descriptionlist->signature_itemvalclass_type:?loc:loc->class_type_declarationlist->signature_itemvalextension:?loc:loc->?attrs:attrs->extension->signature_itemvalattribute:?loc:loc->attribute->signature_itemvaltext:text->signature_itemlistend(** Structure items *)moduleStr:sigvalmk:?loc:loc->structure_item_desc->structure_itemvaleval:?loc:loc->?attrs:attributes->expression->structure_itemvalvalue:?loc:loc->rec_flag->value_bindinglist->structure_itemvalprimitive:?loc:loc->value_description->structure_itemvaltype_:?loc:loc->rec_flag->type_declarationlist->structure_itemvaltype_extension:?loc:loc->type_extension->structure_itemvalexception_:?loc:loc->extension_constructor->structure_itemvalmodule_:?loc:loc->module_binding->structure_itemvalrec_module:?loc:loc->module_bindinglist->structure_itemvalmodtype:?loc:loc->module_type_declaration->structure_itemvalopen_:?loc:loc->open_description->structure_itemvalclass_:?loc:loc->class_declarationlist->structure_itemvalclass_type:?loc:loc->class_type_declarationlist->structure_itemvalinclude_:?loc:loc->include_declaration->structure_itemvalextension:?loc:loc->?attrs:attrs->extension->structure_itemvalattribute:?loc:loc->attribute->structure_itemvaltext:text->structure_itemlistend(** Module declarations *)moduleMd:sigvalmk:?loc:loc->?attrs:attrs->?docs:docs->?text:text->str->module_type->module_declarationend(** Module type declarations *)moduleMtd:sigvalmk:?loc:loc->?attrs:attrs->?docs:docs->?text:text->?typ:module_type->str->module_type_declarationend(** Module bindings *)moduleMb:sigvalmk:?loc:loc->?attrs:attrs->?docs:docs->?text:text->str->module_expr->module_bindingend(** Opens *)moduleOpn:sigvalmk:?loc:loc->?attrs:attrs->?docs:docs->?override:override_flag->lid->open_descriptionend(** Includes *)moduleIncl:sigvalmk:?loc:loc->?attrs:attrs->?docs:docs->'a->'ainclude_infosend(** Value bindings *)moduleVb:sigvalmk:?loc:loc->?attrs:attrs->?docs:docs->?text:text->pattern->expression->value_bindingend(** {2 Class language} *)(** Class type expressions *)moduleCty:sigvalmk:?loc:loc->?attrs:attrs->class_type_desc->class_typevalattr:class_type->attribute->class_typevalconstr:?loc:loc->?attrs:attrs->lid->core_typelist->class_typevalsignature:?loc:loc->?attrs:attrs->class_signature->class_typevalarrow:?loc:loc->?attrs:attrs->arg_label->core_type->class_type->class_typevalextension:?loc:loc->?attrs:attrs->extension->class_typeend(** Class type fields *)moduleCtf:sigvalmk:?loc:loc->?attrs:attrs->?docs:docs->class_type_field_desc->class_type_fieldvalattr:class_type_field->attribute->class_type_fieldvalinherit_:?loc:loc->?attrs:attrs->class_type->class_type_fieldvalval_:?loc:loc->?attrs:attrs->string->mutable_flag->virtual_flag->core_type->class_type_fieldvalmethod_:?loc:loc->?attrs:attrs->string->private_flag->virtual_flag->core_type->class_type_fieldvalconstraint_:?loc:loc->?attrs:attrs->core_type->core_type->class_type_fieldvalextension:?loc:loc->?attrs:attrs->extension->class_type_fieldvalattribute:?loc:loc->attribute->class_type_fieldvaltext:text->class_type_fieldlistend(** Class expressions *)moduleCl:sigvalmk:?loc:loc->?attrs:attrs->class_expr_desc->class_exprvalattr:class_expr->attribute->class_exprvalconstr:?loc:loc->?attrs:attrs->lid->core_typelist->class_exprvalstructure:?loc:loc->?attrs:attrs->class_structure->class_exprvalfun_:?loc:loc->?attrs:attrs->arg_label->expressionoption->pattern->class_expr->class_exprvalapply:?loc:loc->?attrs:attrs->class_expr->(arg_label*expression)list->class_exprvallet_:?loc:loc->?attrs:attrs->rec_flag->value_bindinglist->class_expr->class_exprvalconstraint_:?loc:loc->?attrs:attrs->class_expr->class_type->class_exprvalextension:?loc:loc->?attrs:attrs->extension->class_exprend(** Class fields *)moduleCf:sigvalmk:?loc:loc->?attrs:attrs->?docs:docs->class_field_desc->class_fieldvalattr:class_field->attribute->class_fieldvalinherit_:?loc:loc->?attrs:attrs->override_flag->class_expr->stringoption->class_fieldvalval_:?loc:loc->?attrs:attrs->str->mutable_flag->class_field_kind->class_fieldvalmethod_:?loc:loc->?attrs:attrs->str->private_flag->class_field_kind->class_fieldvalconstraint_:?loc:loc->?attrs:attrs->core_type->core_type->class_fieldvalinitializer_:?loc:loc->?attrs:attrs->expression->class_fieldvalextension:?loc:loc->?attrs:attrs->extension->class_fieldvalattribute:?loc:loc->attribute->class_fieldvaltext:text->class_fieldlistvalvirtual_:core_type->class_field_kindvalconcrete:override_flag->expression->class_field_kindend(** Classes *)moduleCi:sigvalmk:?loc:loc->?attrs:attrs->?docs:docs->?text:text->?virt:virtual_flag->?params:(core_type*variance)list->str->'a->'aclass_infosend(** Class signatures *)moduleCsig:sigvalmk:core_type->class_type_fieldlist->class_signatureend(** Class structures *)moduleCstr:sigvalmk:pattern->class_fieldlist->class_structureendend=struct(** Helpers to produce Parsetree fragments *)openAsttypesopenParsetreeopenDocstringstypelid=Longident.tloctypestr=stringloctypeloc=Location.ttypeattrs=attributelistletdefault_loc=refLocation.noneletwith_default_loclf=letold=!default_locindefault_loc:=l;tryletr=f()indefault_loc:=old;rwithexn->default_loc:=old;raiseexnmoduleConst=structletinteger?suffixi=Pconst_integer(i,suffix)letint?suffixi=integer?suffix(string_of_inti)letint32?(suffix='l')i=integer~suffix(Int32.to_stringi)letint64?(suffix='L')i=integer~suffix(Int64.to_stringi)letnativeint?(suffix='n')i=integer~suffix(Nativeint.to_stringi)letfloat?suffixf=Pconst_float(f,suffix)letcharc=Pconst_charcletstring?quotation_delimiters=Pconst_string(s,quotation_delimiter)endmoduleTyp=structletmk?(loc=!default_loc)?(attrs=[])d={ptyp_desc=d;ptyp_loc=loc;ptyp_attributes=attrs}letattrda={dwithptyp_attributes=d.ptyp_attributes@[a]}letany?loc?attrs()=mk?loc?attrsPtyp_anyletvar?loc?attrsa=mk?loc?attrs(Ptyp_vara)letarrow?loc?attrsabc=mk?loc?attrs(Ptyp_arrow(a,b,c))lettuple?loc?attrsa=mk?loc?attrs(Ptyp_tuplea)letconstr?loc?attrsab=mk?loc?attrs(Ptyp_constr(a,b))letobject_?loc?attrsab=mk?loc?attrs(Ptyp_object(a,b))letclass_?loc?attrsab=mk?loc?attrs(Ptyp_class(a,b))letalias?loc?attrsab=mk?loc?attrs(Ptyp_alias(a,b))letvariant?loc?attrsabc=mk?loc?attrs(Ptyp_variant(a,b,c))letpoly?loc?attrsab=mk?loc?attrs(Ptyp_poly(a,b))letpackage?loc?attrsab=mk?loc?attrs(Ptyp_package(a,b))letextension?loc?attrsa=mk?loc?attrs(Ptyp_extensiona)letforce_polyt=matcht.ptyp_descwith|Ptyp_poly_->t|_->poly~loc:t.ptyp_loc[]t(* -> ghost? *)endmodulePat=structletmk?(loc=!default_loc)?(attrs=[])d={ppat_desc=d;ppat_loc=loc;ppat_attributes=attrs}letattrda={dwithppat_attributes=d.ppat_attributes@[a]}letany?loc?attrs()=mk?loc?attrsPpat_anyletvar?loc?attrsa=mk?loc?attrs(Ppat_vara)letalias?loc?attrsab=mk?loc?attrs(Ppat_alias(a,b))letconstant?loc?attrsa=mk?loc?attrs(Ppat_constanta)letinterval?loc?attrsab=mk?loc?attrs(Ppat_interval(a,b))lettuple?loc?attrsa=mk?loc?attrs(Ppat_tuplea)letconstruct?loc?attrsab=mk?loc?attrs(Ppat_construct(a,b))letvariant?loc?attrsab=mk?loc?attrs(Ppat_variant(a,b))letrecord?loc?attrsab=mk?loc?attrs(Ppat_record(a,b))letarray?loc?attrsa=mk?loc?attrs(Ppat_arraya)letor_?loc?attrsab=mk?loc?attrs(Ppat_or(a,b))letconstraint_?loc?attrsab=mk?loc?attrs(Ppat_constraint(a,b))lettype_?loc?attrsa=mk?loc?attrs(Ppat_typea)letlazy_?loc?attrsa=mk?loc?attrs(Ppat_lazya)letunpack?loc?attrsa=mk?loc?attrs(Ppat_unpacka)letopen_?loc?attrsab=mk?loc?attrs(Ppat_open(a,b))letexception_?loc?attrsa=mk?loc?attrs(Ppat_exceptiona)letextension?loc?attrsa=mk?loc?attrs(Ppat_extensiona)endmoduleExp=structletmk?(loc=!default_loc)?(attrs=[])d={pexp_desc=d;pexp_loc=loc;pexp_attributes=attrs}letattrda={dwithpexp_attributes=d.pexp_attributes@[a]}letident?loc?attrsa=mk?loc?attrs(Pexp_identa)letconstant?loc?attrsa=mk?loc?attrs(Pexp_constanta)letlet_?loc?attrsabc=mk?loc?attrs(Pexp_let(a,b,c))letfun_?loc?attrsabcd=mk?loc?attrs(Pexp_fun(a,b,c,d))letfunction_?loc?attrsa=mk?loc?attrs(Pexp_functiona)letapply?loc?attrsab=mk?loc?attrs(Pexp_apply(a,b))letmatch_?loc?attrsab=mk?loc?attrs(Pexp_match(a,b))lettry_?loc?attrsab=mk?loc?attrs(Pexp_try(a,b))lettuple?loc?attrsa=mk?loc?attrs(Pexp_tuplea)letconstruct?loc?attrsab=mk?loc?attrs(Pexp_construct(a,b))letvariant?loc?attrsab=mk?loc?attrs(Pexp_variant(a,b))letrecord?loc?attrsab=mk?loc?attrs(Pexp_record(a,b))letfield?loc?attrsab=mk?loc?attrs(Pexp_field(a,b))letsetfield?loc?attrsabc=mk?loc?attrs(Pexp_setfield(a,b,c))letarray?loc?attrsa=mk?loc?attrs(Pexp_arraya)letifthenelse?loc?attrsabc=mk?loc?attrs(Pexp_ifthenelse(a,b,c))letsequence?loc?attrsab=mk?loc?attrs(Pexp_sequence(a,b))letwhile_?loc?attrsab=mk?loc?attrs(Pexp_while(a,b))letfor_?loc?attrsabcde=mk?loc?attrs(Pexp_for(a,b,c,d,e))letconstraint_?loc?attrsab=mk?loc?attrs(Pexp_constraint(a,b))letcoerce?loc?attrsabc=mk?loc?attrs(Pexp_coerce(a,b,c))letsend?loc?attrsab=mk?loc?attrs(Pexp_send(a,b))letnew_?loc?attrsa=mk?loc?attrs(Pexp_newa)letsetinstvar?loc?attrsab=mk?loc?attrs(Pexp_setinstvar(a,b))letoverride?loc?attrsa=mk?loc?attrs(Pexp_overridea)letletmodule?loc?attrsabc=mk?loc?attrs(Pexp_letmodule(a,b,c))letletexception?loc?attrsab=mk?loc?attrs(Pexp_letexception(a,b))letassert_?loc?attrsa=mk?loc?attrs(Pexp_asserta)letlazy_?loc?attrsa=mk?loc?attrs(Pexp_lazya)letpoly?loc?attrsab=mk?loc?attrs(Pexp_poly(a,b))letobject_?loc?attrsa=mk?loc?attrs(Pexp_objecta)letnewtype?loc?attrsab=mk?loc?attrs(Pexp_newtype(a,b))letpack?loc?attrsa=mk?loc?attrs(Pexp_packa)letopen_?loc?attrsabc=mk?loc?attrs(Pexp_open(a,b,c))letextension?loc?attrsa=mk?loc?attrs(Pexp_extensiona)letunreachable?loc?attrs()=mk?loc?attrsPexp_unreachableletcaselhs?guardrhs={pc_lhs=lhs;pc_guard=guard;pc_rhs=rhs;}endmoduleMty=structletmk?(loc=!default_loc)?(attrs=[])d={pmty_desc=d;pmty_loc=loc;pmty_attributes=attrs}letattrda={dwithpmty_attributes=d.pmty_attributes@[a]}letident?loc?attrsa=mk?loc?attrs(Pmty_identa)letalias?loc?attrsa=mk?loc?attrs(Pmty_aliasa)letsignature?loc?attrsa=mk?loc?attrs(Pmty_signaturea)letfunctor_?loc?attrsabc=mk?loc?attrs(Pmty_functor(a,b,c))letwith_?loc?attrsab=mk?loc?attrs(Pmty_with(a,b))lettypeof_?loc?attrsa=mk?loc?attrs(Pmty_typeofa)letextension?loc?attrsa=mk?loc?attrs(Pmty_extensiona)endmoduleMod=structletmk?(loc=!default_loc)?(attrs=[])d={pmod_desc=d;pmod_loc=loc;pmod_attributes=attrs}letattrda={dwithpmod_attributes=d.pmod_attributes@[a]}letident?loc?attrsx=mk?loc?attrs(Pmod_identx)letstructure?loc?attrsx=mk?loc?attrs(Pmod_structurex)letfunctor_?loc?attrsargarg_tybody=mk?loc?attrs(Pmod_functor(arg,arg_ty,body))letapply?loc?attrsm1m2=mk?loc?attrs(Pmod_apply(m1,m2))letconstraint_?loc?attrsmmty=mk?loc?attrs(Pmod_constraint(m,mty))letunpack?loc?attrse=mk?loc?attrs(Pmod_unpacke)letextension?loc?attrsa=mk?loc?attrs(Pmod_extensiona)endmoduleSig=structletmk?(loc=!default_loc)d={psig_desc=d;psig_loc=loc}letvalue?loca=mk?loc(Psig_valuea)lettype_?locrec_flaga=mk?loc(Psig_type(rec_flag,a))lettype_extension?loca=mk?loc(Psig_typexta)letexception_?loca=mk?loc(Psig_exceptiona)letmodule_?loca=mk?loc(Psig_modulea)letrec_module?loca=mk?loc(Psig_recmodulea)letmodtype?loca=mk?loc(Psig_modtypea)letopen_?loca=mk?loc(Psig_opena)letinclude_?loca=mk?loc(Psig_includea)letclass_?loca=mk?loc(Psig_classa)letclass_type?loca=mk?loc(Psig_class_typea)letextension?loc?(attrs=[])a=mk?loc(Psig_extension(a,attrs))letattribute?loca=mk?loc(Psig_attributea)lettexttxt=letf_txt=List.filter(funds->docstring_bodyds<>"")txtinList.map(funds->attribute~loc:(docstring_locds)(text_attrds))f_txtendmoduleStr=structletmk?(loc=!default_loc)d={pstr_desc=d;pstr_loc=loc}leteval?loc?(attrs=[])a=mk?loc(Pstr_eval(a,attrs))letvalue?locab=mk?loc(Pstr_value(a,b))letprimitive?loca=mk?loc(Pstr_primitivea)lettype_?locrec_flaga=mk?loc(Pstr_type(rec_flag,a))lettype_extension?loca=mk?loc(Pstr_typexta)letexception_?loca=mk?loc(Pstr_exceptiona)letmodule_?loca=mk?loc(Pstr_modulea)letrec_module?loca=mk?loc(Pstr_recmodulea)letmodtype?loca=mk?loc(Pstr_modtypea)letopen_?loca=mk?loc(Pstr_opena)letclass_?loca=mk?loc(Pstr_classa)letclass_type?loca=mk?loc(Pstr_class_typea)letinclude_?loca=mk?loc(Pstr_includea)letextension?loc?(attrs=[])a=mk?loc(Pstr_extension(a,attrs))letattribute?loca=mk?loc(Pstr_attributea)lettexttxt=letf_txt=List.filter(funds->docstring_bodyds<>"")txtinList.map(funds->attribute~loc:(docstring_locds)(text_attrds))f_txtendmoduleCl=structletmk?(loc=!default_loc)?(attrs=[])d={pcl_desc=d;pcl_loc=loc;pcl_attributes=attrs;}letattrda={dwithpcl_attributes=d.pcl_attributes@[a]}letconstr?loc?attrsab=mk?loc?attrs(Pcl_constr(a,b))letstructure?loc?attrsa=mk?loc?attrs(Pcl_structurea)letfun_?loc?attrsabcd=mk?loc?attrs(Pcl_fun(a,b,c,d))letapply?loc?attrsab=mk?loc?attrs(Pcl_apply(a,b))letlet_?loc?attrsabc=mk?loc?attrs(Pcl_let(a,b,c))letconstraint_?loc?attrsab=mk?loc?attrs(Pcl_constraint(a,b))letextension?loc?attrsa=mk?loc?attrs(Pcl_extensiona)endmoduleCty=structletmk?(loc=!default_loc)?(attrs=[])d={pcty_desc=d;pcty_loc=loc;pcty_attributes=attrs;}letattrda={dwithpcty_attributes=d.pcty_attributes@[a]}letconstr?loc?attrsab=mk?loc?attrs(Pcty_constr(a,b))letsignature?loc?attrsa=mk?loc?attrs(Pcty_signaturea)letarrow?loc?attrsabc=mk?loc?attrs(Pcty_arrow(a,b,c))letextension?loc?attrsa=mk?loc?attrs(Pcty_extensiona)endmoduleCtf=structletmk?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)d={pctf_desc=d;pctf_loc=loc;pctf_attributes=add_docs_attrsdocsattrs;}letinherit_?loc?attrsa=mk?loc?attrs(Pctf_inherita)letval_?loc?attrsabcd=mk?loc?attrs(Pctf_val(a,b,c,d))letmethod_?loc?attrsabcd=mk?loc?attrs(Pctf_method(a,b,c,d))letconstraint_?loc?attrsab=mk?loc?attrs(Pctf_constraint(a,b))letextension?loc?attrsa=mk?loc?attrs(Pctf_extensiona)letattribute?loca=mk?loc(Pctf_attributea)lettexttxt=letf_txt=List.filter(funds->docstring_bodyds<>"")txtinList.map(funds->attribute~loc:(docstring_locds)(text_attrds))f_txtletattrda={dwithpctf_attributes=d.pctf_attributes@[a]}endmoduleCf=structletmk?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)d={pcf_desc=d;pcf_loc=loc;pcf_attributes=add_docs_attrsdocsattrs;}letinherit_?loc?attrsabc=mk?loc?attrs(Pcf_inherit(a,b,c))letval_?loc?attrsabc=mk?loc?attrs(Pcf_val(a,b,c))letmethod_?loc?attrsabc=mk?loc?attrs(Pcf_method(a,b,c))letconstraint_?loc?attrsab=mk?loc?attrs(Pcf_constraint(a,b))letinitializer_?loc?attrsa=mk?loc?attrs(Pcf_initializera)letextension?loc?attrsa=mk?loc?attrs(Pcf_extensiona)letattribute?loca=mk?loc(Pcf_attributea)lettexttxt=letf_txt=List.filter(funds->docstring_bodyds<>"")txtinList.map(funds->attribute~loc:(docstring_locds)(text_attrds))f_txtletvirtual_ct=Cfk_virtualctletconcreteoe=Cfk_concrete(o,e)letattrda={dwithpcf_attributes=d.pcf_attributes@[a]}endmoduleVal=structletmk?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)?(prim=[])nametyp={pval_name=name;pval_type=typ;pval_attributes=add_docs_attrsdocsattrs;pval_loc=loc;pval_prim=prim;}endmoduleMd=structletmk?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)?(text=[])nametyp={pmd_name=name;pmd_type=typ;pmd_attributes=add_text_attrstext(add_docs_attrsdocsattrs);pmd_loc=loc;}endmoduleMtd=structletmk?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)?(text=[])?typname={pmtd_name=name;pmtd_type=typ;pmtd_attributes=add_text_attrstext(add_docs_attrsdocsattrs);pmtd_loc=loc;}endmoduleMb=structletmk?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)?(text=[])nameexpr={pmb_name=name;pmb_expr=expr;pmb_attributes=add_text_attrstext(add_docs_attrsdocsattrs);pmb_loc=loc;}endmoduleOpn=structletmk?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)?(override=Fresh)lid={popen_lid=lid;popen_override=override;popen_loc=loc;popen_attributes=add_docs_attrsdocsattrs;}endmoduleIncl=structletmk?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)mexpr={pincl_mod=mexpr;pincl_loc=loc;pincl_attributes=add_docs_attrsdocsattrs;}endmoduleVb=structletmk?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)?(text=[])patexpr={pvb_pat=pat;pvb_expr=expr;pvb_attributes=add_text_attrstext(add_docs_attrsdocsattrs);pvb_loc=loc;}endmoduleCi=structletmk?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)?(text=[])?(virt=Concrete)?(params=[])nameexpr={pci_virt=virt;pci_params=params;pci_name=name;pci_expr=expr;pci_attributes=add_text_attrstext(add_docs_attrsdocsattrs);pci_loc=loc;}endmoduleType=structletmk?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)?(text=[])?(params=[])?(cstrs=[])?(kind=Ptype_abstract)?(priv=Public)?manifestname={ptype_name=name;ptype_params=params;ptype_cstrs=cstrs;ptype_kind=kind;ptype_private=priv;ptype_manifest=manifest;ptype_attributes=add_text_attrstext(add_docs_attrsdocsattrs);ptype_loc=loc;}letconstructor?(loc=!default_loc)?(attrs=[])?(info=empty_info)?(args=Pcstr_tuple[])?resname={pcd_name=name;pcd_args=args;pcd_res=res;pcd_loc=loc;pcd_attributes=add_info_attrsinfoattrs;}letfield?(loc=!default_loc)?(attrs=[])?(info=empty_info)?(mut=Immutable)nametyp={pld_name=name;pld_mutable=mut;pld_type=typ;pld_loc=loc;pld_attributes=add_info_attrsinfoattrs;}end(** Type extensions *)moduleTe=structletmk?(attrs=[])?(docs=empty_docs)?(params=[])?(priv=Public)pathconstructors={ptyext_path=path;ptyext_params=params;ptyext_constructors=constructors;ptyext_private=priv;ptyext_attributes=add_docs_attrsdocsattrs;}letconstructor?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)?(info=empty_info)namekind={pext_name=name;pext_kind=kind;pext_loc=loc;pext_attributes=add_docs_attrsdocs(add_info_attrsinfoattrs);}letdecl?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)?(info=empty_info)?(args=Pcstr_tuple[])?resname={pext_name=name;pext_kind=Pext_decl(args,res);pext_loc=loc;pext_attributes=add_docs_attrsdocs(add_info_attrsinfoattrs);}letrebind?(loc=!default_loc)?(attrs=[])?(docs=empty_docs)?(info=empty_info)namelid={pext_name=name;pext_kind=Pext_rebindlid;pext_loc=loc;pext_attributes=add_docs_attrsdocs(add_info_attrsinfoattrs);}endmoduleCsig=structletmkselffields={pcsig_self=self;pcsig_fields=fields;}endmoduleCstr=structletmkselffields={pcstr_self=self;pcstr_fields=fields;}endendmoduleAst_mapper:sig(** The interface of a -ppx rewriter
A -ppx rewriter is a program that accepts a serialized abstract syntax
tree and outputs another, possibly modified, abstract syntax tree.
This module encapsulates the interface between the compiler and
the -ppx rewriters, handling such details as the serialization format,
forwarding of command-line flags, and storing state.
{!mapper} allows to implement AST rewriting using open recursion.
A typical mapper would be based on {!default_mapper}, a deep
identity mapper, and will fall back on it for handling the syntax it
does not modify. For example:
{[
open Asttypes
open Parsetree
open Ast_mapper
let test_mapper argv =
{ default_mapper with
expr = fun mapper expr ->
match expr with
| { pexp_desc = Pexp_extension ({ txt = "test" }, PStr [])} ->
Ast_helper.Exp.constant (Const_int 42)
| other -> default_mapper.expr mapper other; }
let () =
register "ppx_test" test_mapper]}
This -ppx rewriter, which replaces [[%test]] in expressions with
the constant [42], can be compiled using
[ocamlc -o ppx_test -I +compiler-libs ocamlcommon.cma ppx_test.ml].
*)openParsetree(** {2 A generic Parsetree mapper} *)typemapper(*IF_CURRENT = Ast_mapper.mapper*)={attribute:mapper->attribute->attribute;attributes:mapper->attributelist->attributelist;case:mapper->case->case;cases:mapper->caselist->caselist;class_declaration:mapper->class_declaration->class_declaration;class_description:mapper->class_description->class_description;class_expr:mapper->class_expr->class_expr;class_field:mapper->class_field->class_field;class_signature:mapper->class_signature->class_signature;class_structure:mapper->class_structure->class_structure;class_type:mapper->class_type->class_type;class_type_declaration:mapper->class_type_declaration->class_type_declaration;class_type_field:mapper->class_type_field->class_type_field;constructor_declaration:mapper->constructor_declaration->constructor_declaration;expr:mapper->expression->expression;extension:mapper->extension->extension;extension_constructor:mapper->extension_constructor->extension_constructor;include_declaration:mapper->include_declaration->include_declaration;include_description:mapper->include_description->include_description;label_declaration:mapper->label_declaration->label_declaration;location:mapper->Location.t->Location.t;module_binding:mapper->module_binding->module_binding;module_declaration:mapper->module_declaration->module_declaration;module_expr:mapper->module_expr->module_expr;module_type:mapper->module_type->module_type;module_type_declaration:mapper->module_type_declaration->module_type_declaration;open_description:mapper->open_description->open_description;pat:mapper->pattern->pattern;payload:mapper->payload->payload;signature:mapper->signature->signature;signature_item:mapper->signature_item->signature_item;structure:mapper->structure->structure;structure_item:mapper->structure_item->structure_item;typ:mapper->core_type->core_type;type_declaration:mapper->type_declaration->type_declaration;type_extension:mapper->type_extension->type_extension;type_kind:mapper->type_kind->type_kind;value_binding:mapper->value_binding->value_binding;value_description:mapper->value_description->value_description;with_constraint:mapper->with_constraint->with_constraint;}(** A mapper record implements one "method" per syntactic category,
using an open recursion style: each method takes as its first
argument the mapper to be applied to children in the syntax
tree. *)valdefault_mapper:mapper(** A default mapper, which implements a "deep identity" mapping. *)(** {2 Convenience functions to write mappers} *)valmap_opt:('a->'b)->'aoption->'boptionvalextension_of_error:Locations.location_error->extension(** Encode an error into an 'ocaml.error' extension node which can be
inserted in a generated Parsetree. The compiler will be
responsible for reporting the error. *)valattribute_of_warning:Location.t->string->attribute(** Encode a warning message into an 'ocaml.ppwarning' attribute which can be
inserted in a generated Parsetree. The compiler will be
responsible for reporting the warning. *)includeLocations.Helpers_intfend=struct(* A generic Parsetree mapping class *)(*
[@@@ocaml.warning "+9"]
(* Ensure that record patterns don't miss any field. *)
*)openParsetreeopenAst_helperopenLocationtypemapper(*IF_CURRENT = Ast_mapper.mapper*)={attribute:mapper->attribute->attribute;attributes:mapper->attributelist->attributelist;case:mapper->case->case;cases:mapper->caselist->caselist;class_declaration:mapper->class_declaration->class_declaration;class_description:mapper->class_description->class_description;class_expr:mapper->class_expr->class_expr;class_field:mapper->class_field->class_field;class_signature:mapper->class_signature->class_signature;class_structure:mapper->class_structure->class_structure;class_type:mapper->class_type->class_type;class_type_declaration:mapper->class_type_declaration->class_type_declaration;class_type_field:mapper->class_type_field->class_type_field;constructor_declaration:mapper->constructor_declaration->constructor_declaration;expr:mapper->expression->expression;extension:mapper->extension->extension;extension_constructor:mapper->extension_constructor->extension_constructor;include_declaration:mapper->include_declaration->include_declaration;include_description:mapper->include_description->include_description;label_declaration:mapper->label_declaration->label_declaration;location:mapper->Location.t->Location.t;module_binding:mapper->module_binding->module_binding;module_declaration:mapper->module_declaration->module_declaration;module_expr:mapper->module_expr->module_expr;module_type:mapper->module_type->module_type;module_type_declaration:mapper->module_type_declaration->module_type_declaration;open_description:mapper->open_description->open_description;pat:mapper->pattern->pattern;payload:mapper->payload->payload;signature:mapper->signature->signature;signature_item:mapper->signature_item->signature_item;structure:mapper->structure->structure;structure_item:mapper->structure_item->structure_item;typ:mapper->core_type->core_type;type_declaration:mapper->type_declaration->type_declaration;type_extension:mapper->type_extension->type_extension;type_kind:mapper->type_kind->type_kind;value_binding:mapper->value_binding->value_binding;value_description:mapper->value_description->value_description;with_constraint:mapper->with_constraint->with_constraint;}letmap_fstf(x,y)=(fx,y)letmap_sndf(x,y)=(x,fy)letmap_tuplef1f2(x,y)=(f1x,f2y)letmap_tuple3f1f2f3(x,y,z)=(f1x,f2y,f3z)letmap_optf=functionNone->None|Somex->Some(fx)letmap_locsub{loc;txt}={loc=sub.locationsubloc;txt}moduleT=struct(* Type expressions for the core language *)letrow_fieldsub=function|Rtag(l,attrs,b,tl)->Rtag(l,sub.attributessubattrs,b,List.map(sub.typsub)tl)|Rinheritt->Rinherit(sub.typsubt)letmapsub{ptyp_desc=desc;ptyp_loc=loc;ptyp_attributes=attrs}=letopenTypinletloc=sub.locationsublocinletattrs=sub.attributessubattrsinmatchdescwith|Ptyp_any->any~loc~attrs()|Ptyp_vars->var~loc~attrss|Ptyp_arrow(lab,t1,t2)->arrow~loc~attrslab(sub.typsubt1)(sub.typsubt2)|Ptyp_tupletyl->tuple~loc~attrs(List.map(sub.typsub)tyl)|Ptyp_constr(lid,tl)->constr~loc~attrs(map_locsublid)(List.map(sub.typsub)tl)|Ptyp_object(l,o)->letf(s,a,t)=(s,sub.attributessuba,sub.typsubt)inobject_~loc~attrs(List.mapfl)o|Ptyp_class(lid,tl)->class_~loc~attrs(map_locsublid)(List.map(sub.typsub)tl)|Ptyp_alias(t,s)->alias~loc~attrs(sub.typsubt)s|Ptyp_variant(rl,b,ll)->variant~loc~attrs(List.map(row_fieldsub)rl)bll|Ptyp_poly(sl,t)->poly~loc~attrssl(sub.typsubt)|Ptyp_package(lid,l)->package~loc~attrs(map_locsublid)(List.map(map_tuple(map_locsub)(sub.typsub))l)|Ptyp_extensionx->extension~loc~attrs(sub.extensionsubx)letmap_type_declarationsub{ptype_name;ptype_params;ptype_cstrs;ptype_kind;ptype_private;ptype_manifest;ptype_attributes;ptype_loc}=Type.mk(map_locsubptype_name)~params:(List.map(map_fst(sub.typsub))ptype_params)~priv:ptype_private~cstrs:(List.map(map_tuple3(sub.typsub)(sub.typsub)(sub.locationsub))ptype_cstrs)~kind:(sub.type_kindsubptype_kind)?manifest:(map_opt(sub.typsub)ptype_manifest)~loc:(sub.locationsubptype_loc)~attrs:(sub.attributessubptype_attributes)letmap_type_kindsub=function|Ptype_abstract->Ptype_abstract|Ptype_variantl->Ptype_variant(List.map(sub.constructor_declarationsub)l)|Ptype_recordl->Ptype_record(List.map(sub.label_declarationsub)l)|Ptype_open->Ptype_openletmap_constructor_argumentssub=function|Pcstr_tuplel->Pcstr_tuple(List.map(sub.typsub)l)|Pcstr_recordl->Pcstr_record(List.map(sub.label_declarationsub)l)letmap_type_extensionsub{ptyext_path;ptyext_params;ptyext_constructors;ptyext_private;ptyext_attributes}=Te.mk(map_locsubptyext_path)(List.map(sub.extension_constructorsub)ptyext_constructors)~params:(List.map(map_fst(sub.typsub))ptyext_params)~priv:ptyext_private~attrs:(sub.attributessubptyext_attributes)letmap_extension_constructor_kindsub=functionPext_decl(ctl,cto)->Pext_decl(map_constructor_argumentssubctl,map_opt(sub.typsub)cto)|Pext_rebindli->Pext_rebind(map_locsubli)letmap_extension_constructorsub{pext_name;pext_kind;pext_loc;pext_attributes}=Te.constructor(map_locsubpext_name)(map_extension_constructor_kindsubpext_kind)~loc:(sub.locationsubpext_loc)~attrs:(sub.attributessubpext_attributes)endmoduleCT=struct(* Type expressions for the class language *)letmapsub{pcty_loc=loc;pcty_desc=desc;pcty_attributes=attrs}=letopenCtyinletloc=sub.locationsublocinletattrs=sub.attributessubattrsinmatchdescwith|Pcty_constr(lid,tys)->constr~loc~attrs(map_locsublid)(List.map(sub.typsub)tys)|Pcty_signaturex->signature~loc~attrs(sub.class_signaturesubx)|Pcty_arrow(lab,t,ct)->arrow~loc~attrslab(sub.typsubt)(sub.class_typesubct)|Pcty_extensionx->extension~loc~attrs(sub.extensionsubx)letmap_fieldsub{pctf_desc=desc;pctf_loc=loc;pctf_attributes=attrs}=letopenCtfinletloc=sub.locationsublocinletattrs=sub.attributessubattrsinmatchdescwith|Pctf_inheritct->inherit_~loc~attrs(sub.class_typesubct)|Pctf_val(s,m,v,t)->val_~loc~attrssmv(sub.typsubt)|Pctf_method(s,p,v,t)->method_~loc~attrsspv(sub.typsubt)|Pctf_constraint(t1,t2)->constraint_~loc~attrs(sub.typsubt1)(sub.typsubt2)|Pctf_attributex->attribute~loc(sub.attributesubx)|Pctf_extensionx->extension~loc~attrs(sub.extensionsubx)letmap_signaturesub{pcsig_self;pcsig_fields}=Csig.mk(sub.typsubpcsig_self)(List.map(sub.class_type_fieldsub)pcsig_fields)endmoduleMT=struct(* Type expressions for the module language *)letmapsub{pmty_desc=desc;pmty_loc=loc;pmty_attributes=attrs}=letopenMtyinletloc=sub.locationsublocinletattrs=sub.attributessubattrsinmatchdescwith|Pmty_idents->ident~loc~attrs(map_locsubs)|Pmty_aliass->alias~loc~attrs(map_locsubs)|Pmty_signaturesg->signature~loc~attrs(sub.signaturesubsg)|Pmty_functor(s,mt1,mt2)->functor_~loc~attrs(map_locsubs)(Migrate_parsetree_compiler_functions.may_map(sub.module_typesub)mt1)(sub.module_typesubmt2)|Pmty_with(mt,l)->with_~loc~attrs(sub.module_typesubmt)(List.map(sub.with_constraintsub)l)|Pmty_typeofme->typeof_~loc~attrs(sub.module_exprsubme)|Pmty_extensionx->extension~loc~attrs(sub.extensionsubx)letmap_with_constraintsub=function|Pwith_type(lid,d)->Pwith_type(map_locsublid,sub.type_declarationsubd)|Pwith_module(lid,lid2)->Pwith_module(map_locsublid,map_locsublid2)|Pwith_typesubstd->Pwith_typesubst(sub.type_declarationsubd)|Pwith_modsubst(s,lid)->Pwith_modsubst(map_locsubs,map_locsublid)letmap_signature_itemsub{psig_desc=desc;psig_loc=loc}=letopenSiginletloc=sub.locationsublocinmatchdescwith|Psig_valuevd->value~loc(sub.value_descriptionsubvd)|Psig_type(rf,l)->type_~locrf(List.map(sub.type_declarationsub)l)|Psig_typextte->type_extension~loc(sub.type_extensionsubte)|Psig_exceptioned->exception_~loc(sub.extension_constructorsubed)|Psig_modulex->module_~loc(sub.module_declarationsubx)|Psig_recmodulel->rec_module~loc(List.map(sub.module_declarationsub)l)|Psig_modtypex->modtype~loc(sub.module_type_declarationsubx)|Psig_openx->open_~loc(sub.open_descriptionsubx)|Psig_includex->include_~loc(sub.include_descriptionsubx)|Psig_classl->class_~loc(List.map(sub.class_descriptionsub)l)|Psig_class_typel->class_type~loc(List.map(sub.class_type_declarationsub)l)|Psig_extension(x,attrs)->extension~loc(sub.extensionsubx)~attrs:(sub.attributessubattrs)|Psig_attributex->attribute~loc(sub.attributesubx)endmoduleM=struct(* Value expressions for the module language *)letmapsub{pmod_loc=loc;pmod_desc=desc;pmod_attributes=attrs}=letopenModinletloc=sub.locationsublocinletattrs=sub.attributessubattrsinmatchdescwith|Pmod_identx->ident~loc~attrs(map_locsubx)|Pmod_structurestr->structure~loc~attrs(sub.structuresubstr)|Pmod_functor(arg,arg_ty,body)->functor_~loc~attrs(map_locsubarg)(Migrate_parsetree_compiler_functions.may_map(sub.module_typesub)arg_ty)(sub.module_exprsubbody)|Pmod_apply(m1,m2)->apply~loc~attrs(sub.module_exprsubm1)(sub.module_exprsubm2)|Pmod_constraint(m,mty)->constraint_~loc~attrs(sub.module_exprsubm)(sub.module_typesubmty)|Pmod_unpacke->unpack~loc~attrs(sub.exprsube)|Pmod_extensionx->extension~loc~attrs(sub.extensionsubx)letmap_structure_itemsub{pstr_loc=loc;pstr_desc=desc}=letopenStrinletloc=sub.locationsublocinmatchdescwith|Pstr_eval(x,attrs)->eval~loc~attrs:(sub.attributessubattrs)(sub.exprsubx)|Pstr_value(r,vbs)->value~locr(List.map(sub.value_bindingsub)vbs)|Pstr_primitivevd->primitive~loc(sub.value_descriptionsubvd)|Pstr_type(rf,l)->type_~locrf(List.map(sub.type_declarationsub)l)|Pstr_typextte->type_extension~loc(sub.type_extensionsubte)|Pstr_exceptioned->exception_~loc(sub.extension_constructorsubed)|Pstr_modulex->module_~loc(sub.module_bindingsubx)|Pstr_recmodulel->rec_module~loc(List.map(sub.module_bindingsub)l)|Pstr_modtypex->modtype~loc(sub.module_type_declarationsubx)|Pstr_openx->open_~loc(sub.open_descriptionsubx)|Pstr_classl->class_~loc(List.map(sub.class_declarationsub)l)|Pstr_class_typel->class_type~loc(List.map(sub.class_type_declarationsub)l)|Pstr_includex->include_~loc(sub.include_declarationsubx)|Pstr_extension(x,attrs)->extension~loc(sub.extensionsubx)~attrs:(sub.attributessubattrs)|Pstr_attributex->attribute~loc(sub.attributesubx)endmoduleE=struct(* Value expressions for the core language *)letmapsub{pexp_loc=loc;pexp_desc=desc;pexp_attributes=attrs}=letopenExpinletloc=sub.locationsublocinletattrs=sub.attributessubattrsinmatchdescwith|Pexp_identx->ident~loc~attrs(map_locsubx)|Pexp_constantx->constant~loc~attrsx|Pexp_let(r,vbs,e)->let_~loc~attrsr(List.map(sub.value_bindingsub)vbs)(sub.exprsube)|Pexp_fun(lab,def,p,e)->fun_~loc~attrslab(map_opt(sub.exprsub)def)(sub.patsubp)(sub.exprsube)|Pexp_functionpel->function_~loc~attrs(sub.casessubpel)|Pexp_apply(e,l)->apply~loc~attrs(sub.exprsube)(List.map(map_snd(sub.exprsub))l)|Pexp_match(e,pel)->match_~loc~attrs(sub.exprsube)(sub.casessubpel)|Pexp_try(e,pel)->try_~loc~attrs(sub.exprsube)(sub.casessubpel)|Pexp_tupleel->tuple~loc~attrs(List.map(sub.exprsub)el)|Pexp_construct(lid,arg)->construct~loc~attrs(map_locsublid)(map_opt(sub.exprsub)arg)|Pexp_variant(lab,eo)->variant~loc~attrslab(map_opt(sub.exprsub)eo)|Pexp_record(l,eo)->record~loc~attrs(List.map(map_tuple(map_locsub)(sub.exprsub))l)(map_opt(sub.exprsub)eo)|Pexp_field(e,lid)->field~loc~attrs(sub.exprsube)(map_locsublid)|Pexp_setfield(e1,lid,e2)->setfield~loc~attrs(sub.exprsube1)(map_locsublid)(sub.exprsube2)|Pexp_arrayel->array~loc~attrs(List.map(sub.exprsub)el)|Pexp_ifthenelse(e1,e2,e3)->ifthenelse~loc~attrs(sub.exprsube1)(sub.exprsube2)(map_opt(sub.exprsub)e3)|Pexp_sequence(e1,e2)->sequence~loc~attrs(sub.exprsube1)(sub.exprsube2)|Pexp_while(e1,e2)->while_~loc~attrs(sub.exprsube1)(sub.exprsube2)|Pexp_for(p,e1,e2,d,e3)->for_~loc~attrs(sub.patsubp)(sub.exprsube1)(sub.exprsube2)d(sub.exprsube3)|Pexp_coerce(e,t1,t2)->coerce~loc~attrs(sub.exprsube)(map_opt(sub.typsub)t1)(sub.typsubt2)|Pexp_constraint(e,t)->constraint_~loc~attrs(sub.exprsube)(sub.typsubt)|Pexp_send(e,s)->send~loc~attrs(sub.exprsube)s|Pexp_newlid->new_~loc~attrs(map_locsublid)|Pexp_setinstvar(s,e)->setinstvar~loc~attrs(map_locsubs)(sub.exprsube)|Pexp_overridesel->override~loc~attrs(List.map(map_tuple(map_locsub)(sub.exprsub))sel)|Pexp_letmodule(s,me,e)->letmodule~loc~attrs(map_locsubs)(sub.module_exprsubme)(sub.exprsube)|Pexp_letexception(cd,e)->letexception~loc~attrs(sub.extension_constructorsubcd)(sub.exprsube)|Pexp_asserte->assert_~loc~attrs(sub.exprsube)|Pexp_lazye->lazy_~loc~attrs(sub.exprsube)|Pexp_poly(e,t)->poly~loc~attrs(sub.exprsube)(map_opt(sub.typsub)t)|Pexp_objectcls->object_~loc~attrs(sub.class_structuresubcls)|Pexp_newtype(s,e)->newtype~loc~attrss(sub.exprsube)|Pexp_packme->pack~loc~attrs(sub.module_exprsubme)|Pexp_open(ovf,lid,e)->open_~loc~attrsovf(map_locsublid)(sub.exprsube)|Pexp_extensionx->extension~loc~attrs(sub.extensionsubx)|Pexp_unreachable->unreachable~loc~attrs()endmoduleP=struct(* Patterns *)letmapsub{ppat_desc=desc;ppat_loc=loc;ppat_attributes=attrs}=letopenPatinletloc=sub.locationsublocinletattrs=sub.attributessubattrsinmatchdescwith|Ppat_any->any~loc~attrs()|Ppat_vars->var~loc~attrs(map_locsubs)|Ppat_alias(p,s)->alias~loc~attrs(sub.patsubp)(map_locsubs)|Ppat_constantc->constant~loc~attrsc|Ppat_interval(c1,c2)->interval~loc~attrsc1c2|Ppat_tuplepl->tuple~loc~attrs(List.map(sub.patsub)pl)|Ppat_construct(l,p)->construct~loc~attrs(map_locsubl)(map_opt(sub.patsub)p)|Ppat_variant(l,p)->variant~loc~attrsl(map_opt(sub.patsub)p)|Ppat_record(lpl,cf)->record~loc~attrs(List.map(map_tuple(map_locsub)(sub.patsub))lpl)cf|Ppat_arraypl->array~loc~attrs(List.map(sub.patsub)pl)|Ppat_or(p1,p2)->or_~loc~attrs(sub.patsubp1)(sub.patsubp2)|Ppat_constraint(p,t)->constraint_~loc~attrs(sub.patsubp)(sub.typsubt)|Ppat_types->type_~loc~attrs(map_locsubs)|Ppat_lazyp->lazy_~loc~attrs(sub.patsubp)|Ppat_unpacks->unpack~loc~attrs(map_locsubs)|Ppat_open(lid,p)->open_~loc~attrs(map_locsublid)(sub.patsubp)|Ppat_exceptionp->exception_~loc~attrs(sub.patsubp)|Ppat_extensionx->extension~loc~attrs(sub.extensionsubx)endmoduleCE=struct(* Value expressions for the class language *)letmapsub{pcl_loc=loc;pcl_desc=desc;pcl_attributes=attrs}=letopenClinletloc=sub.locationsublocinletattrs=sub.attributessubattrsinmatchdescwith|Pcl_constr(lid,tys)->constr~loc~attrs(map_locsublid)(List.map(sub.typsub)tys)|Pcl_structures->structure~loc~attrs(sub.class_structuresubs)|Pcl_fun(lab,e,p,ce)->fun_~loc~attrslab(map_opt(sub.exprsub)e)(sub.patsubp)(sub.class_exprsubce)|Pcl_apply(ce,l)->apply~loc~attrs(sub.class_exprsubce)(List.map(map_snd(sub.exprsub))l)|Pcl_let(r,vbs,ce)->let_~loc~attrsr(List.map(sub.value_bindingsub)vbs)(sub.class_exprsubce)|Pcl_constraint(ce,ct)->constraint_~loc~attrs(sub.class_exprsubce)(sub.class_typesubct)|Pcl_extensionx->extension~loc~attrs(sub.extensionsubx)letmap_kindsub=function|Cfk_concrete(o,e)->Cfk_concrete(o,sub.exprsube)|Cfk_virtualt->Cfk_virtual(sub.typsubt)letmap_fieldsub{pcf_desc=desc;pcf_loc=loc;pcf_attributes=attrs}=letopenCfinletloc=sub.locationsublocinletattrs=sub.attributessubattrsinmatchdescwith|Pcf_inherit(o,ce,s)->inherit_~loc~attrso(sub.class_exprsubce)s|Pcf_val(s,m,k)->val_~loc~attrs(map_locsubs)m(map_kindsubk)|Pcf_method(s,p,k)->method_~loc~attrs(map_locsubs)p(map_kindsubk)|Pcf_constraint(t1,t2)->constraint_~loc~attrs(sub.typsubt1)(sub.typsubt2)|Pcf_initializere->initializer_~loc~attrs(sub.exprsube)|Pcf_attributex->attribute~loc(sub.attributesubx)|Pcf_extensionx->extension~loc~attrs(sub.extensionsubx)letmap_structuresub{pcstr_self;pcstr_fields}={pcstr_self=sub.patsubpcstr_self;pcstr_fields=List.map(sub.class_fieldsub)pcstr_fields;}letclass_infossubf{pci_virt;pci_params=pl;pci_name;pci_expr;pci_loc;pci_attributes}=Ci.mk~virt:pci_virt~params:(List.map(map_fst(sub.typsub))pl)(map_locsubpci_name)(fpci_expr)~loc:(sub.locationsubpci_loc)~attrs:(sub.attributessubpci_attributes)end(* Now, a generic AST mapper, to be extended to cover all kinds and
cases of the OCaml grammar. The default behavior of the mapper is
the identity. *)letdefault_mapper={structure=(funthisl->List.map(this.structure_itemthis)l);structure_item=M.map_structure_item;module_expr=M.map;signature=(funthisl->List.map(this.signature_itemthis)l);signature_item=MT.map_signature_item;module_type=MT.map;with_constraint=MT.map_with_constraint;class_declaration=(funthis->CE.class_infosthis(this.class_exprthis));class_expr=CE.map;class_field=CE.map_field;class_structure=CE.map_structure;class_type=CT.map;class_type_field=CT.map_field;class_signature=CT.map_signature;class_type_declaration=(funthis->CE.class_infosthis(this.class_typethis));class_description=(funthis->CE.class_infosthis(this.class_typethis));type_declaration=T.map_type_declaration;type_kind=T.map_type_kind;typ=T.map;type_extension=T.map_type_extension;extension_constructor=T.map_extension_constructor;value_description=(funthis{pval_name;pval_type;pval_prim;pval_loc;pval_attributes}->Val.mk(map_locthispval_name)(this.typthispval_type)~attrs:(this.attributesthispval_attributes)~loc:(this.locationthispval_loc)~prim:pval_prim);pat=P.map;expr=E.map;module_declaration=(funthis{pmd_name;pmd_type;pmd_attributes;pmd_loc}->Md.mk(map_locthispmd_name)(this.module_typethispmd_type)~attrs:(this.attributesthispmd_attributes)~loc:(this.locationthispmd_loc));module_type_declaration=(funthis{pmtd_name;pmtd_type;pmtd_attributes;pmtd_loc}->Mtd.mk(map_locthispmtd_name)?typ:(map_opt(this.module_typethis)pmtd_type)~attrs:(this.attributesthispmtd_attributes)~loc:(this.locationthispmtd_loc));module_binding=(funthis{pmb_name;pmb_expr;pmb_attributes;pmb_loc}->Mb.mk(map_locthispmb_name)(this.module_exprthispmb_expr)~attrs:(this.attributesthispmb_attributes)~loc:(this.locationthispmb_loc));open_description=(funthis{popen_lid;popen_override;popen_attributes;popen_loc}->Opn.mk(map_locthispopen_lid)~override:popen_override~loc:(this.locationthispopen_loc)~attrs:(this.attributesthispopen_attributes));include_description=(funthis{pincl_mod;pincl_attributes;pincl_loc}->Incl.mk(this.module_typethispincl_mod)~loc:(this.locationthispincl_loc)~attrs:(this.attributesthispincl_attributes));include_declaration=(funthis{pincl_mod;pincl_attributes;pincl_loc}->Incl.mk(this.module_exprthispincl_mod)~loc:(this.locationthispincl_loc)~attrs:(this.attributesthispincl_attributes));value_binding=(funthis{pvb_pat;pvb_expr;pvb_attributes;pvb_loc}->Vb.mk(this.patthispvb_pat)(this.exprthispvb_expr)~loc:(this.locationthispvb_loc)~attrs:(this.attributesthispvb_attributes));constructor_declaration=(funthis{pcd_name;pcd_args;pcd_res;pcd_loc;pcd_attributes}->Type.constructor(map_locthispcd_name)~args:(T.map_constructor_argumentsthispcd_args)?res:(map_opt(this.typthis)pcd_res)~loc:(this.locationthispcd_loc)~attrs:(this.attributesthispcd_attributes));label_declaration=(funthis{pld_name;pld_type;pld_loc;pld_mutable;pld_attributes}->Type.field(map_locthispld_name)(this.typthispld_type)~mut:pld_mutable~loc:(this.locationthispld_loc)~attrs:(this.attributesthispld_attributes));cases=(funthisl->List.map(this.casethis)l);case=(funthis{pc_lhs;pc_guard;pc_rhs}->{pc_lhs=this.patthispc_lhs;pc_guard=map_opt(this.exprthis)pc_guard;pc_rhs=this.exprthispc_rhs;});location=(fun_thisl->l);extension=(funthis(s,e)->(map_locthiss,this.payloadthise));attribute=(funthis(s,e)->(map_locthiss,this.payloadthise));attributes=(funthisl->List.map(this.attributethis)l);payload=(funthis->function|PStrx->PStr(this.structurethisx)|PSigx->PSig(this.signaturethisx)|PTypx->PTyp(this.typthisx)|PPat(x,g)->PPat(this.patthisx,map_opt(this.exprthis)g));}letextension_of_error(error:Locations.location_error):extension=Locations.extension_of_error~mk_pstr:(function|x::l->PStr(x::x::l)|l->PStrl)~mk_extension:(funx->Str.extensionx)~mk_string_constant:(funx->Str.eval(Exp.constant(Pconst_string(x,None))))errorletattribute_of_warninglocs={loc;txt="ocaml.ppwarning"},PStr([Str.eval~loc(Exp.constant(Pconst_string(s,None)))])includeLocations.Helpers_implendmoduleOutcometree=struct(* Module [Outcometree]: results displayed by the toplevel *)(* These types represent messages that the toplevel displays as normal
results or errors. The real displaying is customisable using the hooks:
[Toploop.print_out_value]
[Toploop.print_out_type]
[Toploop.print_out_sig_item]
[Toploop.print_out_phrase] *)typeout_ident(*IF_CURRENT = Outcometree.out_ident *)=|Oide_applyofout_ident*out_ident|Oide_dotofout_ident*string|Oide_identofstringtypeout_attribute(*IF_CURRENT = Outcometree.out_attribute *)={oattr_name:string}typeout_value(*IF_CURRENT = Outcometree.out_value *)=|Oval_arrayofout_valuelist|Oval_charofchar|Oval_constrofout_ident*out_valuelist|Oval_ellipsis|Oval_floatoffloat|Oval_intofint|Oval_int32ofint32|Oval_int64ofint64|Oval_nativeintofnativeint|Oval_listofout_valuelist|Oval_printerof(Format.formatter->unit)|Oval_recordof(out_ident*out_value)list|Oval_stringofstring|Oval_stuffofstring|Oval_tupleofout_valuelist|Oval_variantofstring*out_valueoptiontypeout_type(*IF_CURRENT = Outcometree.out_type *)=|Otyp_abstract|Otyp_open|Otyp_aliasofout_type*string|Otyp_arrowofstring*out_type*out_type|Otyp_classofbool*out_ident*out_typelist|Otyp_constrofout_ident*out_typelist|Otyp_manifestofout_type*out_type|Otyp_objectof(string*out_type)list*booloption|Otyp_recordof(string*bool*out_type)list|Otyp_stuffofstring|Otyp_sumof(string*out_typelist*out_typeoption)list|Otyp_tupleofout_typelist|Otyp_varofbool*string|Otyp_variantofbool*out_variant*bool*(stringlist)option|Otyp_polyofstringlist*out_type|Otyp_moduleofstring*stringlist*out_typelist|Otyp_attributeofout_type*out_attributeandout_variant(*IF_CURRENT = Outcometree.out_variant *)=|Ovar_fieldsof(string*bool*out_typelist)list|Ovar_nameofout_ident*out_typelisttypeout_class_type(*IF_CURRENT = Outcometree.out_class_type *)=|Octy_constrofout_ident*out_typelist|Octy_arrowofstring*out_type*out_class_type|Octy_signatureofout_typeoption*out_class_sig_itemlistandout_class_sig_item(*IF_CURRENT = Outcometree.out_class_sig_item *)=|Ocsg_constraintofout_type*out_type|Ocsg_methodofstring*bool*bool*out_type|Ocsg_valueofstring*bool*bool*out_typetypeout_module_type(*IF_CURRENT = Outcometree.out_module_type *)=|Omty_abstract|Omty_functorofstring*out_module_typeoption*out_module_type|Omty_identofout_ident|Omty_signatureofout_sig_itemlist|Omty_aliasofout_identandout_sig_item(*IF_CURRENT = Outcometree.out_sig_item *)=|Osig_classofbool*string*(string*(bool*bool))list*out_class_type*out_rec_status|Osig_class_typeofbool*string*(string*(bool*bool))list*out_class_type*out_rec_status|Osig_typextofout_extension_constructor*out_ext_status|Osig_modtypeofstring*out_module_type|Osig_moduleofstring*out_module_type*out_rec_status|Osig_typeofout_type_decl*out_rec_status|Osig_valueofout_val_decl|Osig_ellipsisandout_type_decl(*IF_CURRENT = Outcometree.out_type_decl *)={otype_name:string;otype_params:(string*(bool*bool))list;otype_type:out_type;otype_private:Asttypes.private_flag;otype_immediate:bool;otype_unboxed:bool;otype_cstrs:(out_type*out_type)list}andout_extension_constructor(*IF_CURRENT = Outcometree.out_extension_constructor *)={oext_name:string;oext_type_name:string;oext_type_params:stringlist;oext_args:out_typelist;oext_ret_type:out_typeoption;oext_private:Asttypes.private_flag}andout_type_extension(*IF_CURRENT = Outcometree.out_type_extension *)={otyext_name:string;otyext_params:stringlist;otyext_constructors:(string*out_typelist*out_typeoption)list;otyext_private:Asttypes.private_flag}andout_val_decl(*IF_CURRENT = Outcometree.out_val_decl *)={oval_name:string;oval_type:out_type;oval_prims:stringlist;oval_attributes:out_attributelist}andout_rec_status(*IF_CURRENT = Outcometree.out_rec_status *)=|Orec_not|Orec_first|Orec_nextandout_ext_status(*IF_CURRENT = Outcometree.out_ext_status *)=|Oext_first|Oext_next|Oext_exceptiontypeout_phrase(*IF_CURRENT = Outcometree.out_phrase *)=|Ophr_evalofout_value*out_type|Ophr_signatureof(out_sig_item*out_valueoption)list|Ophr_exceptionof(exn*out_value)endmoduleConfig=structletast_impl_magic_number="Caml1999M020"letast_intf_magic_number="Caml1999N018"endletmap_signaturemapper=mapper.Ast_mapper.signaturemapperletmap_structuremapper=mapper.Ast_mapper.structuremapperletshallow_identity=letid_x=xin{Ast_mapper.structure=id;structure_item=id;module_expr=id;signature=id;signature_item=id;module_type=id;with_constraint=id;class_declaration=id;class_expr=id;class_field=id;class_structure=id;class_type=id;class_type_field=id;class_signature=id;class_type_declaration=id;class_description=id;type_declaration=id;type_kind=id;typ=id;type_extension=id;extension_constructor=id;value_description=id;pat=id;expr=id;module_declaration=id;module_type_declaration=id;module_binding=id;open_description=id;include_description=id;include_declaration=id;value_binding=id;constructor_declaration=id;label_declaration=id;cases=id;case=id;location=id;extension=id;attribute=id;attributes=id;payload=id;}letfailing_mapper=letfail__=invalid_arg"failing_mapper: this mapper function should never get called"in{Ast_mapper.structure=fail;structure_item=fail;module_expr=fail;signature=fail;signature_item=fail;module_type=fail;with_constraint=fail;class_declaration=fail;class_expr=fail;class_field=fail;class_structure=fail;class_type=fail;class_type_field=fail;class_signature=fail;class_type_declaration=fail;class_description=fail;type_declaration=fail;type_kind=fail;typ=fail;type_extension=fail;extension_constructor=fail;value_description=fail;pat=fail;expr=fail;module_declaration=fail;module_type_declaration=fail;module_binding=fail;open_description=fail;include_description=fail;include_declaration=fail;value_binding=fail;constructor_declaration=fail;label_declaration=fail;cases=fail;case=fail;location=fail;extension=fail;attribute=fail;attributes=fail;payload=fail;}letmake_top_mapper~signature~structure={failing_mapperwithAst_mapper.signature=(fun_x->signaturex);structure=(fun_x->structurex)}