123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881#0 "ast_converter.mlp"moduleL=LongidentmoduleLc=Longident_convertermoduleB=M2l.BuildmoduleM=ModulemoduleAnnot=M2l.AnnotmoduleArg=M.Arglettxtx=x.Location.txt#13 "ast_converter.mlp"letlid_txtx=txtx#15 "ast_converter.mlp"#17 "ast_converter.mlp"letrecsimplify_lid=letfrom_lid'x=simplify_lid(lid_txtx)infunction|L.Lidents->Lc.Idents|L.Lapply(f,x)->Lc.App(from_lid'f,from_lid'x)|L.Ldot(p,s)->Lc.Dot(from_lid'p,lid_txts)letfrom_lidx=Longident_converter.(from_lid@@simplify_lidx)letme_from_lidlid=Longident_converter.me_from_lid(simplify_lid@@txtlid)#31 "ast_converter.mlp"letbound_namex=x#33 "ast_converter.mlp"#35 "ast_converter.mlp"letdummy_locloc=letopenLocationinloc.loc_ghost&&(loc.loc_start.pos_cnum=-1||loc.loc_end.pos_cnum=-1)letfrom_locl=letopenLocationinletextrlex=letopenLexinginlex.pos_lnum,lex.pos_cnum-lex.pos_bolinletl1,c1ass=extrl.loc_startinletl2,c2ase=extrl.loc_endinifdummy_loclthenLoc.Nowhereelseifl1=l2thenLoc.Simple{line=l1;start=c1;stop=c2}elseLoc.Multiline{start=s;stop=e}letwith_locldata={Loc.loc=from_locl;data}moduleH=structletepathx=from_lid@@txtxletnpathx=Paths.Expr.concrete@@epathxletextract_loc(loc:_Location.loc)=from_locloc.Location.locletrecremove_simple_last=function|[]->[]|[_]->[]|a::q->a::remove_simple_lastqletremove_simple_last=function|[]|[_]->None|q->Some(remove_simple_lastq)letremove_last=function|Paths.E.Simplep->Option.fmapPaths.E.pure(remove_simple_lastp)|Apply{f;x;proj=Somep}->Some(Paths.E.appfx(remove_simple_lastp))|Apply{proj=None;_}asy->Someyletaccesslid=letx=remove_last@@from_lid@@txtlidinletloc=extract_loclidinmatchxwith|None->Annot.empty|Somedata->Annot.access{loc;data}letdo_openlocme=[{Loc.data=M2l.Openme;loc=from_locloc}]let(@%)ll'=letopenLocinletopenM2linmatchl,l'with|[{data=Minorm;loc}],{data=Minorm';loc=loc'}::q->Loc.fmap(funx->Minorx)(Annot.merge{data=m;loc}{data=m';loc=loc'})::q|_->l@l'letrecgen_mmap(@)f=function|[]->[]|a::q->(fa)@gen_mmap(@)fqletmmapf=gen_mmap(@%)flet(%)fgx=f(gx)endopenHlet(++)=Annot.(++)openM2lmodulePattern=struct(** {2 Pattern manipulation function} *)(** At module level, a pattern can only access modules or
bind a first class module *)typebind=module_exprM2l.bindLoc.exttypet={binds:bindlist;annot:Annot.t}letempty={annot=Annot.empty;binds=[]}letaccessp={emptywithannot=accessp}letof_annotannot={emptywithannot}letto_annote=e.annotletmergee1e2={annot=Annot.(e1.annot++e2.annot);binds=e1.binds@e2.binds}let(++)=mergeletunion_mapf=List.fold_left(funpx->p++fx)emptyletoptfx=Option.(x>>|f><empty)letbindlocnamesign={emptywithbinds=[Loc.createloc{M2l.name=bound_namename;expr=sign}]}letopen_m{annot={data;loc};binds}=#147 "ast_converter.mlp"letme_open{name;expr}={name;expr=M2l.Open_me{opens=[m];expr}}inletmd:module_expr=Identm.Loc.datainletdata=matchdata,bindswith|[],[]->[M2l.Pack{data=md;loc=m.loc}](* [M.(...nothing)] becomes (module M) *)|data,_->[M2l.Local_open(m.loc,Identm.Loc.data,data)]in{annot={data;loc};binds=List.map(Loc.fmapme_open)binds}letbind_fmodpinner=#155 "ast_converter.mlp"letbindedx=letbinderinnerb=[Local_bind(b.Loc.loc,b.Loc.data,inner)]inList.fold_leftbinderxp.bindsinAnnot.(p.annot++Loc.fmapbindedinner)letextensionext=of_annot(Annot.extext)endletrecfold2faccl1l2=matchl1,l2with|a::q,a'::q'->fold2f(faccaa')qq'|[],[]->acc|[],_::_|_::_,[]->accletminorlocx=ifAnnot.is_empty(Loc.nowherex)then[]else[with_locloc@@Minorx]letminor'x=ifAnnot.is_emptyxthen[]else[Loc.fmap(funx->Minorx)x](** {2 From OCaml ast to m2l } *)openParsetreeletdatax=x.Loc.data#191 "ast_converter.mlp"#193 "ast_converter.mlp"letcore_field{pof_desc=(Otag(_,t)|Oinheritt);_}=t#195 "ast_converter.mlp"#197 "ast_converter.mlp"#199 "ast_converter.mlp"letexncx=x.ptyexn_constructor#204 "ast_converter.mlp"letrow_field_corex=matchx.prf_descwith|Rtag(_,_,cts)->cts|Rinheritct->[ct]#209 "ast_converter.mlp"#211 "ast_converter.mlp"letsubst_path=H.npath#213 "ast_converter.mlp"#215 "ast_converter.mlp"letrecstructurestr=mmapstructure_itemstrandstructure_itemitem=letloc=item.pstr_locinletminor=minorlocinmatchitem.pstr_descwith|Pstr_eval(exp,_attrs)->minor@@data@@exprexp(* ;; exp [@@_attrs ] *)|Pstr_value(_rec_flag,vals)(* let P1 = E1 and ... and Pn = EN (flag = Nonrecursive)
let rec P1 = E1 and ... and Pn = EN (flag = Recursive)
*)->minor@@data@@Annot.union_map(Pattern.to_annot%val_binding%vb_triple)vals|Pstr_primitivedesc(* val x: T
external x: T = "s1" ... "sn" *)->minor(Externaldesc.pval_prim::data(core_typedesc.pval_type);)|Pstr_type(_rec_flag,type_declarations)(* type t1 = ... and ... and tn = ... *)->minor@@data@@Annot.union_maptype_declarationtype_declarations|Pstr_typexta_type_extension(* type t1 += ... *)->minor@@data@@type_extensiona_type_extension|Pstr_exceptionan_extension_constructor(* exception C of T
exception C = M.X *)->minor@@data@@extension_constructor@@exncan_extension_constructor|Pstr_modulemb(* module X = ME *)->[with_locloc@@Bind(module_binding_rawmb)]|Pstr_recmodulemodule_bindings(* module rec X1 = ME1 and ... and Xn = MEn *)->recmodulesmodule_bindings|Pstr_modtypea_module_type_declaration(*module type s = .. *)->[with_locloc@@Bind_sig(module_type_declarationa_module_type_declaration)]|Pstr_openopen_desc(* open M *)->simple_openopen_desc|Pstr_classclass_declarations(* class c1 = ... and ... and cn = ... *)->minor'@@Annot.union_mapclass_declarationclass_declarations|Pstr_class_typeclass_type_declarations(* class type ct1 = ... and ... and ctn = ... *)->minor'@@Annot.union_mapclass_type_declarationclass_type_declarations|Pstr_includeinclude_dec(* include M *)->do_includeinclude_dec|Pstr_attribute_attribute(* [@@@id] *)->[]|Pstr_extension(ext,_attributes)(* [%%id] *)->[with_locloc@@extensionext]andexprexp=letloc=exp.pexp_locinmatchexp.pexp_descwith|Pexp_identname(* x, M.x *)->accessname|Pexp_let(_rec_flag,vbs,exp)(* let P1 = E1 and ... and Pn = EN in E (flag = Nonrecursive)
let rec P1 = E1 and ... and Pn = EN in E (flag = Recursive)
*)->with_locloc@@data@@value_bindingsvbs@@exprexp#276 "ast_converter.mlp"|Pexp_function(params,cty,body)(* function P1 -> E1 | ... | Pn -> En *)->#292 "ast_converter.mlp"Annot.optfconstraintcty++Pattern.bind_fmod(Pattern.union_mapfparamparams)(fbodybody)|Pexp_apply(expression,args)#298 "ast_converter.mlp"(* E0 ~l1:E1 ... ~ln:En
li can be empty (non labeled argument) or start with '?'
(optional argument).
Invariant: n > 0
*)->Annot.(exprexpression++union_map(expr%snd)args)|Pexp_match(expression,cases)(* match E0 with P1 -> E1 | ... | Pn -> En *)|Pexp_try(expression,cases)(* try E0 with P1 -> E1 | ... | Pn -> En *)->Annot.(exprexpression++Annot.union_mapcasecases)|Pexp_tupleexpressions(* (E1, ..., En) Invariant: n >= 2 *)->letexpressions=List.mapsndexpressionsin#317 "ast_converter.mlp"Annot.union_mapexprexpressions#319 "ast_converter.mlp"|Pexp_construct(constr,expr_opt)(* C None
C E Some E
C (E1, ..., En) Some (Pexp_tuple[E1;...;En])
*)->beginmatchexpr_optwith|Somee->Annot.merge(accessconstr)(expre)|None->accessconstrend|Pexp_variant(_label,eo)(* `A (None)
`A E (Some E)
*)->Annot.optexpreo|Pexp_record(labels,expression_opt)(* { l1=P1; ...; ln=Pn } (None)
{ E0 with l1=P1; ...; ln=Pn } (Some E0)
Invariant: n > 0
*)->Annot.(optexprexpression_opt++union_map(fun(labl,expression)->H.accesslabl++exprexpression)labels)|Pexp_field(expression,field)(* E.l *)->H.accessfield++exprexpression|Pexp_setfield(e1,field,e2)(* E1.l <- E2 *)->accessfield++expre1++expre2|Pexp_arrayexpressions(* [| E1; ...; En |] *)->Annot.union_mapexprexpressions|Pexp_ifthenelse(e1,e2,e3)(* if E1 then E2 else E3 *)->expre1++expre2++Annot.optexpre3|Pexp_sequence(e1,e2)(* E1; E2 *)->expre1++expre2|Pexp_while(e1,e2)(* while E1 do E2 done *)->expre1++expre2|Pexp_for(pat,e1,e2,_,e3)(* for pat = E1 to E2 do E3 done (flag = Upto)
for pat = E1 downto E2 do E3 done (flag = Downto)
*)->(Pattern.to_annot@@patternpat)++expre1++expre2++expre3|Pexp_constraint(e,t)(* (E : T) *)->expre++core_typet|Pexp_coerce(e,t_opt,coer)(* (E :> T) (None, T)
(E : T0 :> T) (Some T0, T)
*)->expre++Annot.optcore_typet_opt++core_typecoer|Pexp_newname(* new M.c *)->H.accessname|Pexp_setinstvar(_x,e)(* x <- e *)->expre|Pexp_overridelabels(* {< x1 = E1; ...; Xn = En >} *)->Annot.union_map(expr%snd)labels|Pexp_letmodule(m,me,e)(* let module M = ME in E *)->with_loce.pexp_loc[Local_bind(from_locloc,module_binding(m,me),data@@expre)]|Pexp_letexception(_c,e)(* let exception C in E *)->#382 "ast_converter.mlp"expre|Pexp_send(e,_)(* E # m *)#385 "ast_converter.mlp"|Pexp_asserte(* assert E *)|Pexp_newtype(_,e)(* fun (type t) -> E *)|Pexp_lazye(* lazy E *)->expre|Pexp_poly(e,ct_opt)->expre++Annot.optcore_typect_opt|Pexp_objectclstr(* object ... end *)->class_structureclstr#395 "ast_converter.mlp"|Pexp_pack(me,ty)->#398 "ast_converter.mlp"(*Warning.first_class_module (); *)#400 "ast_converter.mlp"(* todo: are all cases caught by the Module.approximation mechanism? *)letty=matchtywithNone->Annot.empty|Somety->package_typetyinty++(Annot.pack@@with_locloc@@module_exprme)#405 "ast_converter.mlp"|Pexp_open(me,e)#408 "ast_converter.mlp"(* M.(E), let open M in E, let! open M in E *)->Annot.local_open(from_locme.popen_loc)(local_open_argme)@@expre|Pexp_constant_|Pexp_unreachable(* . *)#412 "ast_converter.mlp"->Annot.empty|Pexp_extensionext(* [%ext] *)->Annot.ext@@with_locloc@@extension_coreext|Pexp_letopb->#417 "ast_converter.mlp"val_bindings(funbop->bop.pbop_pat,[],bop.pbop_exp)(b.let_::b.ands)(exprb.body)andfconstraint=function#423 "ast_converter.mlp"|Pconstraintcty->core_typecty|Pcoerce(base,cty)->Annot.optcore_typebase++core_typectyandfparamx=matchx.pparam_descwith|Pparam_newtype_->Pattern.empty|Pparam_val(_,e,p)->letdefault=Pattern.of_annot(Annot.optexpre)inPattern.mergedefault(patternp)andfbody=function|Pfunction_bodye->expre|Pfunction_cases(cases,_,_)->Annot.union_mapcasecasesandpatternpat=#436 "ast_converter.mlp"letloc=pat.ppat_locinmatchpat.ppat_descwith|Ppat_constant_(* 1, 'a', "true", 1.0, 1l, 1L, 1n *)|Ppat_interval_(* 'a'..'z'*)|Ppat_any|Ppat_var_(* x *)->Pattern.empty|Ppat_extensionext->Pattern.extension@@with_locloc@@extension_coreext|Ppat_exceptionpat(* exception P *)|Ppat_lazypat(* lazy P *)|Ppat_alias(pat,_)(* P as 'a *)->patternpat#452 "ast_converter.mlp"|Ppat_arraypatterns(* [| P1; ...; Pn |] *)->Pattern.union_mappatternpatterns#455 "ast_converter.mlp"|Ppat_tuple(patterns,_)(* (P1, ..., Pn, ... ) *)->letpatterns=List.mapsndpatternsinPattern.union_mappatternpatterns#461 "ast_converter.mlp"|Ppat_construct(c,p)->#468 "ast_converter.mlp"(* C None
C P Some ([], P)
C (P1, ..., Pn) Some ([], Ppat_tuple [P1; ...; Pn])
C (type a b) P Some ([a; b], P)
*)Pattern.(accessc++Pattern.optpattern(Option.fmapsndp))|Ppat_variant(_,p)(*`A (None), `A P(Some P)*)->#476 "ast_converter.mlp"Pattern.optpatternp|Ppat_record(fields,_flag)(* { l1=P1; ...; ln=Pn } (flag = Closed)
{ l1=P1; ...; ln=Pn; _} (flag = Open)
*)->Pattern.union_mapPattern.(fun(lbl,p)->patternp++accesslbl)fields|Ppat_or(p1,p2)(* P1 | P2 *)->Pattern.(patternp1++patternp2)|Ppat_constraint({ppat_desc=Ppat_unpackname;_},{ptyp_desc=Ptyp_packages;_})->letname=txtnameinletmt,others=full_package_typesinletbind={M2l.name=bound_namename;expr=M2l.Constraint(Unpacked,mt)}in{otherswithbinds=[with_loclocbind]}(* todo : catch higher up *)|Ppat_constraint(pat,ct)(* (P : T) *)->Pattern.(patternpat++of_annot(core_typect))|Ppat_typename(* #tconst *)->Pattern.accessname|Ppat_unpackm->(* Warning.first_class_module(); todo: test coverage *)Pattern.bind(from_locloc)(txtm)Unpacked(* (module P)
Note: (module P : S) is represented as
Ppat_constraint(Ppat_unpack, Ptyp_package)
*)|Ppat_open(m,p)(* M.(P) *)->#504 "ast_converter.mlp"Pattern.open_(with_locm.loc@@H.npathm)@@patternp|Ppat_effect(e,k)(* effect P, k *)->#508 "ast_converter.mlp"Pattern.(patterne++patternk)#511 "ast_converter.mlp"andtype_declarationtd:M2l.Annot.t=Annot.union_map(fun(_,t,_)->core_typet)td.ptype_cstrs++iftd.ptype_kind=Ptype_abstractthenAnnot.opt(Annot.epsilon_promote%core_type)td.ptype_manifestelsetype_kindtd.ptype_kind++Annot.optcore_typetd.ptype_manifestandtype_kind=function|Ptype_abstract|Ptype_open->Annot.empty|Ptype_variantconstructor_declarations->Annot.union_mapconstructor_declarationconstructor_declarations|Ptype_recordlabel_declarations->Annot.union_maplabel_declarationlabel_declarationsandconstructor_declarationcd=Annot.optcore_typecd.pcd_res++constructor_argscd.pcd_argsandconstructor_args=function|Pcstr_tuplects->Annot.union_mapcore_typects|Pcstr_recordlds->Annot.union_maplabel_declarationldsandlabel_declarationld=core_typeld.pld_typeandtype_extensiontyext:M2l.Annot.t=accesstyext.ptyext_path++Annot.union_mapextension_constructortyext.ptyext_constructorsandcore_typect:M2l.Annot.t=letloc=ct.ptyp_locinmatchct.ptyp_descwith|Ptyp_extensionext(* [%id] *)->Annot.ext@@with_locloc@@extension_coreext|Ptyp_any(* _ *)|Ptyp_var_(* 'a *)->Annot.empty|Ptyp_arrow(_,t1,t2)(* [~? ]T1->T2 *)->core_typet1++core_typet2|Ptyp_tuplects(* T1 * ... * Tn *)->letcts=List.mapsndctsin#546 "ast_converter.mlp"Annot.union_mapcore_typects#548 "ast_converter.mlp"|Ptyp_class(name,cts)|Ptyp_constr(name,cts)(*[|T|(T1n ..., Tn)] tconstr *)->accessname++Annot.union_mapcore_typects|Ptyp_object(lbls,_)(* < l1:T1; ...; ln:Tn[; ..] > *)->Annot.union_map(core_type%core_field)lbls|Ptyp_poly(_,ct)|Ptyp_alias(ct,_)(* T as 'a *)->core_typect|Ptyp_variant(row_fields,_,_labels)->Annot.union_maprow_fieldrow_fields|Ptyp_packages(* (module S) *)->package_types|Ptyp_open(l,ty)->#563 "ast_converter.mlp"Annot.local_open(from_locl.loc)(Ident(npathl))(core_typety)androw_fieldx=Annot.union_mapcore_type(row_field_corex)#569 "ast_converter.mlp"andpackage_convertpty=#572 "ast_converter.mlp"pty.ppt_path,pty.ppt_cstrs#574 "ast_converter.mlp"andpackage_typepty=#576 "ast_converter.mlp"lets,constraints=package_convertptyinAnnot.merge(accesss)(Annot.union_map(core_type%snd)constraints)andfull_package_typepty=lets,constraints=package_convertptyinIdent(epaths),Pattern.of_annot@@Annot.union_map(core_type%snd)constraintsandcasecs=(Annot.optexprcs.pc_guard)++(Pattern.bind_fmod(patterncs.pc_lhs)@@exprcs.pc_rhs)anddo_includeincl=[with_locincl.pincl_loc@@Include(module_exprincl.pincl_mod)]andextension_constructorextc:M2l.Annot.t=matchextc.pext_kindwith|Pext_decl(_vars,args,cto)->#592 "ast_converter.mlp"#594 "ast_converter.mlp"constructor_argsargs#596 "ast_converter.mlp"++Annot.optcore_typecto|Pext_rebindname->accessnameandclass_typect=matchct.pcty_descwith|Pcty_constr(name,cts)(* c ['a1, ..., 'an] c *)->Annot.merge(accessname)(Annot.union_mapcore_typects)|Pcty_signaturecs(* object ... end *)->class_signaturecs|Pcty_arrow(_arg_label,ct,clt)(* ^T -> CT *)->Annot.(class_typeclt++core_typect)|Pcty_extensionext(* [%ext] *)->Annot.ext@@with_locct.pcty_loc@@extension_coreext#609 "ast_converter.mlp"|Pcty_open(module',cty)->#613 "ast_converter.mlp"Annot.local_open(from_locmodule'.popen_loc)(Ident(npathmodule'.popen_expr))(class_typecty)andclass_signaturecs=Annot.union_mapclass_type_fieldcs.pcsig_fields#617 "ast_converter.mlp"andclass_type_fieldctf=matchctf.pctf_descwith|Pctf_inheritct->class_typect|Pctf_val(_,_,_,ct)(*val x : T *)|Pctf_method(_,_,_,ct)(* method x: T *)->core_typect|Pctf_constraint(t1,t2)(* constraint T1 = T2 *)->Annot.(core_typet2++core_typet1)|Pctf_attribute_->Annot.empty|Pctf_extensionext->Annot.ext@@with_locctf.pctf_loc@@extension_coreextandclass_structurect=Annot.union_mapclass_fieldct.pcstr_fieldsandclass_fieldfield=matchfield.pcf_descwith|Pcf_inherit(_override_flag,ce,_)(* inherit CE *)->class_exprce|Pcf_method(_,_,cfk)|Pcf_val(_,_,cfk)(* val x = E *)->class_field_kindcfk|Pcf_constraint(_,ct)(* constraint T1 = T2 *)->core_typect|Pcf_initializere(* initializer E *)->expre|Pcf_attribute_->Annot.empty|Pcf_extensionext->Annot.ext@@with_locfield.pcf_loc@@extension_coreextandclass_exprce=letloc=ce.pcl_locinmatchce.pcl_descwith|Pcl_constr(name,cts)(* ['a1, ..., 'an] c *)->accessname++Annot.union_mapcore_typects|Pcl_structurecs(* object ... end *)->class_structurecs|Pcl_fun(_arg_label,eo,pat,ce)(* 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)
*)->Annot.merge(Annot.optexpreo)(Pattern.bind_fmod(patternpat)(class_exprce))|Pcl_apply(ce,les)(* CE ~l1:E1 ... ~ln:En
li can be empty (non labeled argument) or start with '?'
(optional argument).
Invariant: n > 0
*)->Annot.union_map(expr%snd)les++class_exprce|Pcl_let(_,vbs,ce)(* let P1 = E1 and ... and Pn = EN in CE *)->with_locloc@@data@@value_bindingsvbs(class_exprce)|Pcl_constraint(ce,ct)->class_typect++class_exprce|Pcl_extensionext->Annot.ext@@with_locloc@@extension_coreext#672 "ast_converter.mlp"|Pcl_open(module',cl)->#676 "ast_converter.mlp"Annot.local_open(from_locmodule'.popen_loc)(Ident(npathmodule'.popen_expr))@@class_exprclandclass_field_kind=function#680 "ast_converter.mlp"|Cfk_virtualct->core_typect|Cfk_concrete(_,e)->expreandclass_declarationcd:M2l.Annot.t=class_exprcd.pci_exprandclass_type_declarationctd:M2l.Annot.t=class_typectd.pci_exprandmodule_exprmexpr:M2l.module_expr=matchmexpr.pmod_descwith|Pmod_identname(* A *)->Ident(npathname)|Pmod_structurestr(* struct ... end *)->Str(structurestr)#692 "ast_converter.mlp"|Pmod_functor(Unit,mex)->#697 "ast_converter.mlp"Fun{arg=None;body=module_exprmex}|Pmod_functor(Named(name,mt),mex)->letname=txtnameinletarg=Some{Arg.name;signature=module_typemt}inFun{arg;body=module_exprmex}|Pmod_apply(f,x)(* ME1(ME2) *)->#704 "ast_converter.mlp"Apply{f=module_exprf;x=module_exprx}|Pmod_apply_unitf(* F() *)->#707 "ast_converter.mlp"Apply{f=module_exprf;x=Abstract}|Pmod_constraint(me,mt)->#710 "ast_converter.mlp"Constraint(module_exprme,module_typemt)|Pmod_unpack{pexp_desc=Pexp_constraint(inner,{ptyp_desc=Ptyp_packages;_});_}(* (val E : S ) *)->Constraint(Val(data@@exprinner),fst@@full_package_types)|Pmod_unpacke(* (val E) *)->Val(data@@expre)|Pmod_extensionext->Extension_node(extension_coreext)(* [%id] *)andval_binding(patt,type_constraints,expr):Pattern.t=letp,e=matched_patt_exprpattexprinletwith_tyc=List.fold_left(funannotx->annot++core_typex)etype_constraintsinPattern.(p++of_annotwith_tyc)andval_bindings:'a.('a->pattern*core_typelist*Parsetree.expression)->'alist->_=funprojvbsexpr->letp=Pattern.union_map(val_binding%proj)vbsinletv=letbinderinnerb=[Local_bind(b.Loc.loc,b.Loc.data,inner)]inList.fold_leftbinderexpr.Loc.datap.bindsinPattern.to_annotp++Loc.createexpr.Loc.locvandvb_triplex=letconstraints=#736 "ast_converter.mlp"matchx.pvb_constraintwith#738 "ast_converter.mlp"|None->[]|Some(Pvc_constraint{locally_abstract_univars=_;typ=t}|Pvc_coercion{ground=None;coercion=t})->[t]|Some(Pvc_coercion{ground=Someg;coercion})->[g;coercion]in#744 "ast_converter.mlp"x.pvb_pat,constraints,x.pvb_exprandvalue_bindingsx=val_bindingsvb_triplexandmodule_binding_rawmb=module_binding(mb.pmb_name,mb.pmb_expr)andmodule_binding(pmb_name,pmb_expr)={name=bound_name(txtpmb_name);expr=module_exprpmb_expr}andmodule_type(mt:Parsetree.module_type)=matchmt.pmty_descwith|Pmty_signatures(* sig ... end *)->Sig(signatures)#756 "ast_converter.mlp"|Pmty_functor(Unit,res)(* functor(X : MT1) -> MT2 *)->#761 "ast_converter.mlp"Fun{arg=None;body=module_typeres}|Pmty_functor(Named(name,s),res)(* functor(X : MT1) -> MT2 *)->letarg=Some({Arg.name=txtname;signature=module_types})inFun{arg;body=module_typeres}|Pmty_with(mt,with_c)(* MT with ... *)->#767 "ast_converter.mlp"With{body=module_typemt;with_constraints=List.mapwith_constraintwith_c}|Pmty_typeofme(* module type of ME *)->Of(module_exprme)|Pmty_extensionext(* [%id] *)->Extension_node(extension_coreext)|Pmty_aliaslid->Alias(npathlid)|Pmty_identlid(* S *)->Ident(epathlid)andmodule_declarationmdec=lets=module_typemdec.pmd_typein{name=bound_name(txtmdec.pmd_name);expr=Constraint(Abstract,s)}andmodule_type_declarationmdec=letopenOptioninletname=txtmdec.pmtd_nameinlets=((mdec.pmtd_type>>|module_type)><Abstract)in{name=Somename;expr=s}andsignaturesign=mmapsignature_itemsignandsignature_itemitem=letloc=item.psig_locinletminorx=minorloc@@dataxinmatchitem.psig_descwith|Psig_valuevd(* val x: T *)->minor(core_typevd.pval_type)|Psig_type(_rec_flag,tds)(* type t1 = ... and ... and tn = ... *)->minor@@Annot.union_maptype_declarationtds|Psig_typextte(* type t1 += ... *)->minor@@type_extensionte|Psig_exceptionec(* exception C of T *)->minor@@extension_constructor@@exncec|Psig_modulemd(* module X : MT *)->[with_locloc@@Bind(module_declarationmd)]|Psig_recmodulemds(* module rec X1 : MT1 and ... and Xn : MTn *)->[with_locloc@@Bind_rec(List.mapmodule_declarationmds)](* Warning.confused "Psig_recmodule"; (* todo coverage*) *)|Psig_modtypemtd(* module type S = MT *)->[with_locloc@@Bind_sig(module_type_declarationmtd)]|Psig_openod(* open X *)->ident_openod|Psig_includeid(* include MT *)->[with_locloc@@SigInclude(module_typeid.pincl_mod)]|Psig_classcds(* class c1 : ... and ... and cn : ... *)->minor@@Annot.union_mapclass_descriptioncds|Psig_class_typectds->minor@@Annot.union_mapclass_type_declarationctds|Psig_attribute_->[]|Psig_extension(ext,_)->[with_locloc@@extensionext]|Psig_typesubsttds->minor@@Annot.union_maptype_declarationtds#814 "ast_converter.mlp"|Psig_modsubstmsub->letghost=Bind{name=Somemsub.pms_name.txt;expr=Ident(npathmsub.pms_manifest)}indo_openmsub.pms_loc(Str[with_locmsub.pms_locghost])|Psig_modtypesubstmtsub->#821 "ast_converter.mlp"letghost=module_type_declarationmtsubindo_openmtsub.pmtd_loc(Str[with_locmtsub.pmtd_loc(Bind_sigghost)])andclass_descriptionx=class_type_declarationx#825 "ast_converter.mlp"andrecmodulesmbs=letloc=List.fold_leftLoc.keep_oneNowhere@@List.map(funmb->from_locmb.pmb_loc)mbsin[Loc.createloc@@Bind_rec(List.mapmodule_binding_rawmbs)]andwith_constraint=function#833 "ast_converter.mlp"|Pwith_typesubst(l,td)(* with type X.t := ... *)->#836 "ast_converter.mlp"{delete=true;lhs=subst_pathl;rhs=Type(data@@type_declarationtd)}|Pwith_type(lhs,td)(* with type X.t = ... *)->#839 "ast_converter.mlp"{delete=false;lhs=H.npathlhs;rhs=Type(data@@type_declarationtd)}|Pwith_module(l,rhs)(* with module X.Y = Z *)->letloc=rhs.Location.locin{delete=false;lhs=H.npathl;rhs=Module(with_locloc(H.npathrhs))}|Pwith_modsubst(l,rhs)->letloc=rhs.Location.locin{delete=true;lhs=subst_pathl;rhs=Module(with_locloc(H.npathrhs))}|Pwith_modtype(l,rhs)(* with module X.Y = Z *)->#848 "ast_converter.mlp"{delete=false;lhs=subst_pathl;rhs=Module_type(module_typerhs)}|Pwith_modtypesubst(l,rhs)->{delete=true;lhs=subst_pathl;rhs=Module_type(module_typerhs)}#853 "ast_converter.mlp"andextensionn=Extension_node(extension_coren)andextension_core(name,payload)=letopenM2linletname=txtnameinmatchpayloadwith|PSigs->{extension=Module(signatures);name}|PStrs->{extension=Module(structures);name}|PTypc->{extension=Val(data@@core_typec);name}|PPat(p,eo)->{extension=Val(data@@Pattern.to_annot(patternp)++Annot.optexpreo);name}andmatched_patt_exprxy=(* matched_patt_expr is used to catch some case of packed module
where the module signature is provided not on the pattern side
but on the expression side
*)matchx.ppat_desc,y.pexp_descwith|Ppat_constraint_,Pexp_constraint_->patternx,expry|_,Pexp_constraint(_,t)->pattern{xwithppat_desc=Ppat_constraint(x,t)},expry|_,Pexp_pack(_,Somety)->#877 "ast_converter.mlp"letpty={ptyp_loc=y.pexp_loc;ptyp_desc=Ptyp_packagety;ptyp_attributes=[];ptyp_loc_stack=[]}inletpat={xwithppat_desc=Ppat_constraint(x,pty)}inpatternpat,expry|Ppat_construct(_,po),Pexp_construct(_,eo)->#886 "ast_converter.mlp"letpo=Option.fmapsndpoin#888 "ast_converter.mlp"Option.((po>>=funp->eo>>|fune->matched_patt_exprpe)><#890 "ast_converter.mlp"(Pattern.optpatternpo,Annot.optexpreo))|Ppat_variant(_,po),Pexp_variant(_,eo)->Option.((po>>=funp->eo>>|fune->matched_patt_exprpe)><(Pattern.optpatternpo,Annot.optexpreo))#898 "ast_converter.mlp"|Ppat_tuple(pt,_),Pexp_tupleet->#900 "ast_converter.mlp"(* FIXME: labels matching *)letpt=List.mapsndptandet=List.mapsndetinfold2#904 "ast_converter.mlp"(fun(p,e)xy->letp',e'=matched_patt_exprxyinPattern.(p++p'),e++e')(Pattern.empty,Annot.empty)ptet|Ppat_arraypt,Pexp_arrayet(* todo use homogeneity *)->fold2(fun(p,e)xy->letp',e'=matched_patt_exprxyinPattern.(p++p'),e++e')(Pattern.empty,Annot.empty)ptet|Ppat_record(pr,_),Pexp_record(er,eo)->(* First, gather together pattern and expression with the same label *)letm=Paths.Simple.Map.emptyinletaltax=matchxwithNone->Somea|_->xinletadd_pp'(p,e)=altp'p,einletadd_ee'(p,e)=p,alte'einletfolderaddm(key,x)=letkey=H.npathkeyinletv=tryaddx@@Paths.Simple.Map.findkeymwith|Not_found->None,NoneinPaths.Simple.Map.addkeyvminletm=List.fold_left(folderadd_p)mprinletm=List.fold_left(folderadd_e)merin(* Then use matched pattern expression analyse, when both pattern
and expression are available *)Paths.Simple.Map.fold(fun_elt(acc_p,acc_e)->matcheltwith|Somep,Somee->letp,e=matched_patt_exprpeinPattern.(acc_p++p),acc_e++e|None,None->acc_p,acc_e|Somep,None->Pattern.(acc_p++patternp),acc_e|None,Somee->acc_p,acc_e++expre)m(Pattern.empty,Annot.optexpreo)|_,_->patternx,expry#936 "ast_converter.mlp"andlocal_open_argo=module_expro.popen_expr#940 "ast_converter.mlp"andident_openo=do_openo.popen_loc(me_from_lido.popen_expr)andsimple_openo=do_openo.popen_loc(module_expro.popen_expr)