123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974(**************************************************************************)(* *)(* OCaml *)(* *)(* Thomas Gazagnaire (OCamlPro), Fabrice Le Fessant (INRIA Saclay) *)(* *)(* Copyright 2007 Institut National de Recherche en Informatique et *)(* en Automatique. *)(* *)(* 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. *)(* *)(**************************************************************************)[@@@ocaml.warning"-60"]moduleStr=Ast_helper.Str(* For ocamldep *)[@@@ocaml.warning"+60"]openAsttypesopenParsetreeopenAst_helpermoduleT=Typedtreetypemapper={attribute:mapper->T.attribute->attribute;attributes:mapper->T.attributelist->attributelist;binding_op:mapper->T.binding_op->T.pattern->binding_op;case:'k.mapper->'kT.case->case;class_declaration:mapper->T.class_declaration->class_declaration;class_description:mapper->T.class_description->class_description;class_expr:mapper->T.class_expr->class_expr;class_field:mapper->T.class_field->class_field;class_signature:mapper->T.class_signature->class_signature;class_structure:mapper->T.class_structure->class_structure;class_type:mapper->T.class_type->class_type;class_type_declaration:mapper->T.class_type_declaration->class_type_declaration;class_type_field:mapper->T.class_type_field->class_type_field;constructor_declaration:mapper->T.constructor_declaration->constructor_declaration;expr:mapper->T.expression->expression;extension_constructor:mapper->T.extension_constructor->extension_constructor;include_declaration:mapper->T.include_declaration->include_declaration;include_description:mapper->T.include_description->include_description;label_declaration:mapper->T.label_declaration->label_declaration;location:mapper->Location.t->Location.t;module_binding:mapper->T.module_binding->module_binding;module_declaration:mapper->T.module_declaration->module_declaration;module_substitution:mapper->T.module_substitution->module_substitution;module_expr:mapper->T.module_expr->module_expr;module_type:mapper->T.module_type->module_type;module_type_declaration:mapper->T.module_type_declaration->module_type_declaration;package_type:mapper->T.package_type->package_type;open_declaration:mapper->T.open_declaration->open_declaration;open_description:mapper->T.open_description->open_description;pat:'k.mapper->'kT.general_pattern->pattern;row_field:mapper->T.row_field->row_field;object_field:mapper->T.object_field->object_field;signature:mapper->T.signature->signature;signature_item:mapper->T.signature_item->signature_item;structure:mapper->T.structure->structure;structure_item:mapper->T.structure_item->structure_item;typ:mapper->T.core_type->core_type;type_declaration:mapper->T.type_declaration->type_declaration;type_extension:mapper->T.type_extension->type_extension;type_exception:mapper->T.type_exception->type_exception;type_kind:mapper->T.type_kind->type_kind;value_binding:mapper->T.value_binding->value_binding;value_description:mapper->T.value_description->value_description;with_constraint:mapper->(Path.t*Longident.tLocation.loc*T.with_constraint)->with_constraint;}openT(*
Some notes:
* For Pexp_apply, it is unclear whether arguments are reordered, especially
when there are optional arguments.
*)(** Utility functions. *)letstring_is_prefixsubstr=letsublen=String.lengthsubinString.lengthstr>=sublen&&String.substr0sublen=subletreclident_of_path=function|Path.Pidentid->Longident.Lident(Ident.nameid)|Path.Papply(p1,p2)->Longident.Lapply(lident_of_pathp1,lident_of_pathp2)|Path.Pdot(p,s)|Path.Pextra_ty(p,Pcstr_tys)->Longident.Ldot(lident_of_pathp,s)|Path.Pextra_ty(p,_)->lident_of_pathpletmap_locsub{loc;txt}={loc=sub.locationsubloc;txt}(** Extract the [n] patterns from the case of a letop *)letrecextract_letop_patternsnpat=ifn=0thenpat,[]elsebeginmatchpat.pat_descwith|Tpat_tuple([first;rest])->letnext,others=extract_letop_patterns(n-1)restinfirst,next::others|_->letrecanysn=ifn=0then[]else{patwithpat_desc=Tpat_any}::anys(n-1)in{patwithpat_desc=Tpat_any},anys(n-1)end(** Mapping functions. *)letconstant=function|Const_charc->Const.charc|Const_string(s,loc,d)->Const.string?quotation_delimiter:d~locs|Const_inti->Const.integer(Int.to_stringi)|Const_int32i->Const.integer~suffix:'l'(Int32.to_stringi)|Const_int64i->Const.integer~suffix:'L'(Int64.to_stringi)|Const_nativeinti->Const.integer~suffix:'n'(Nativeint.to_stringi)|Const_floatf->Const.floatfletattributesuba={attr_name=map_locsuba.attr_name;attr_payload=a.attr_payload;attr_loc=a.attr_loc}letattributessubl=List.map(sub.attributesub)lletstructuresubstr=List.map(sub.structure_itemsub)str.str_itemsletopen_descriptionsubod=letloc=sub.locationsubod.open_locinletattrs=sub.attributessubod.open_attributesinOpn.mk~loc~attrs~override:od.open_override(sndod.open_expr)letopen_declarationsubod=letloc=sub.locationsubod.open_locinletattrs=sub.attributessubod.open_attributesinOpn.mk~loc~attrs~override:od.open_override(sub.module_exprsubod.open_expr)letstructure_itemsubitem=letloc=sub.locationsubitem.str_locinletdesc=matchitem.str_descwithTstr_eval(exp,attrs)->Pstr_eval(sub.exprsubexp,attrs)|Tstr_value(rec_flag,list)->Pstr_value(rec_flag,List.map(sub.value_bindingsub)list)|Tstr_primitivevd->Pstr_primitive(sub.value_descriptionsubvd)|Tstr_type(rec_flag,list)->Pstr_type(rec_flag,List.map(sub.type_declarationsub)list)|Tstr_typexttyext->Pstr_typext(sub.type_extensionsubtyext)|Tstr_exceptionext->Pstr_exception(sub.type_exceptionsubext)|Tstr_modulemb->Pstr_module(sub.module_bindingsubmb)|Tstr_recmodulelist->Pstr_recmodule(List.map(sub.module_bindingsub)list)|Tstr_modtypemtd->Pstr_modtype(sub.module_type_declarationsubmtd)|Tstr_openod->Pstr_open(sub.open_declarationsubod)|Tstr_classlist->Pstr_class(List.map(fun(ci,_)->sub.class_declarationsubci)list)|Tstr_class_typelist->Pstr_class_type(List.map(fun(_id,_name,ct)->sub.class_type_declarationsubct)list)|Tstr_includeincl->Pstr_include(sub.include_declarationsubincl)|Tstr_attributex->Pstr_attributexinStr.mk~locdescletvalue_descriptionsubv=letloc=sub.locationsubv.val_locinletattrs=sub.attributessubv.val_attributesinVal.mk~loc~attrs~prim:v.val_prim(map_locsubv.val_name)(sub.typsubv.val_desc)letmodule_bindingsubmb=letloc=sub.locationsubmb.mb_locinletattrs=sub.attributessubmb.mb_attributesinMb.mk~loc~attrs(map_locsubmb.mb_name)(sub.module_exprsubmb.mb_expr)lettype_parametersub(ct,v)=(sub.typsubct,v)lettype_declarationsubdecl=letloc=sub.locationsubdecl.typ_locinletattrs=sub.attributessubdecl.typ_attributesinType.mk~loc~attrs~params:(List.map(type_parametersub)decl.typ_params)~cstrs:(List.map(fun(ct1,ct2,loc)->(sub.typsubct1,sub.typsubct2,sub.locationsubloc))decl.typ_cstrs)~kind:(sub.type_kindsubdecl.typ_kind)~priv:decl.typ_private?manifest:(Option.map(sub.typsub)decl.typ_manifest)(map_locsubdecl.typ_name)lettype_kindsubtk=matchtkwith|Ttype_abstract->Ptype_abstract|Ttype_variantlist->Ptype_variant(List.map(sub.constructor_declarationsub)list)|Ttype_recordlist->Ptype_record(List.map(sub.label_declarationsub)list)|Ttype_open->Ptype_openletconstructor_argumentssub=function|Cstr_tuplel->Pcstr_tuple(List.map(sub.typsub)l)|Cstr_recordl->Pcstr_record(List.map(sub.label_declarationsub)l)letconstructor_declarationsubcd=letloc=sub.locationsubcd.cd_locinletattrs=sub.attributessubcd.cd_attributesinType.constructor~loc~attrs~vars:cd.cd_vars~args:(constructor_argumentssubcd.cd_args)?res:(Option.map(sub.typsub)cd.cd_res)(map_locsubcd.cd_name)letlabel_declarationsubld=letloc=sub.locationsubld.ld_locinletattrs=sub.attributessubld.ld_attributesinType.field~loc~attrs~mut:ld.ld_mutable(map_locsubld.ld_name)(sub.typsubld.ld_type)lettype_extensionsubtyext=letattrs=sub.attributessubtyext.tyext_attributesinTe.mk~attrs~params:(List.map(type_parametersub)tyext.tyext_params)~priv:tyext.tyext_private(map_locsubtyext.tyext_txt)(List.map(sub.extension_constructorsub)tyext.tyext_constructors)lettype_exceptionsubtyexn=letattrs=sub.attributessubtyexn.tyexn_attributesinTe.mk_exception~attrs(sub.extension_constructorsubtyexn.tyexn_constructor)letextension_constructorsubext=letloc=sub.locationsubext.ext_locinletattrs=sub.attributessubext.ext_attributesinTe.constructor~loc~attrs(map_locsubext.ext_name)(matchext.ext_kindwith|Text_decl(vs,args,ret)->Pext_decl(vs,constructor_argumentssubargs,Option.map(sub.typsub)ret)|Text_rebind(_p,lid)->Pext_rebind(map_locsublid))letpattern:typek._->kT.general_pattern->_=funsubpat->letloc=sub.locationsubpat.pat_locin(* todo: fix attributes on extras *)letattrs=sub.attributessubpat.pat_attributesinletdesc=matchpatwith{pat_extra=[Tpat_unpack,loc,_attrs];pat_desc=Tpat_any;_}->Ppat_unpack{txt=None;loc}|{pat_extra=[Tpat_unpack,_,_attrs];pat_desc=Tpat_var(_,name,_);_}->Ppat_unpack{namewithtxt=Somename.txt}|{pat_extra=[Tpat_type(_path,lid),_,_attrs];_}->Ppat_type(map_locsublid)|{pat_extra=(Tpat_constraintct,_,_attrs)::rem;_}->Ppat_constraint(sub.patsub{patwithpat_extra=rem},sub.typsubct)|_->matchpat.pat_descwithTpat_any->Ppat_any|Tpat_var(id,name,_)->beginmatch(Ident.nameid).[0]with'A'..'Z'->Ppat_unpack{namewithtxt=Somename.txt}|_->Ppat_varnameend(* We transform (_ as x) in x if _ and x have the same location.
The compiler transforms (x:t) into (_ as x : t).
This avoids transforming a warning 27 into a 26.
*)|Tpat_alias({pat_desc=Tpat_any;pat_loc},_id,name,_)whenpat_loc=pat.pat_loc->Ppat_varname|Tpat_alias(pat,_id,name,_)->Ppat_alias(sub.patsubpat,name)|Tpat_constantcst->Ppat_constant(constantcst)|Tpat_tuplelist->Ppat_tuple(List.map(sub.patsub)list)|Tpat_construct(lid,_,args,vto)->lettyo=matchvtowithNone->None|Some(vl,ty)->letvl=List.map(funx->{xwithtxt=Ident.namex.txt})vlinSome(vl,sub.typsubty)inletarg=matchargswith[]->None|[arg]->Some(sub.patsubarg)|args->Some(Pat.tuple~loc(List.map(sub.patsub)args))inPpat_construct(map_locsublid,matchtyo,argwith|Some(vl,ty),Somearg->Some(vl,Pat.mk~loc(Ppat_constraint(arg,ty)))|None,Somearg->Some([],arg)|_,None->None)|Tpat_variant(label,pato,_)->Ppat_variant(label,Option.map(sub.patsub)pato)|Tpat_record(list,closed)->Ppat_record(List.map(fun(lid,_,pat)->map_locsublid,sub.patsubpat)list,closed)|Tpat_arraylist->Ppat_array(List.map(sub.patsub)list)|Tpat_lazyp->Ppat_lazy(sub.patsubp)|Tpat_exceptionp->Ppat_exception(sub.patsubp)|Tpat_valuep->(sub.patsub(p:>pattern)).ppat_desc|Tpat_or(p1,p2,_)->Ppat_or(sub.patsubp1,sub.patsubp2)inPat.mk~loc~attrsdescletexp_extrasub(extra,loc,attrs)sexp=letloc=sub.locationsublocinletattrs=sub.attributessubattrsinletdesc=matchextrawithTexp_coerce(cty1,cty2)->Pexp_coerce(sexp,Option.map(sub.typsub)cty1,sub.typsubcty2)|Texp_constraintcty->Pexp_constraint(sexp,sub.typsubcty)|Texp_polycto->Pexp_poly(sexp,Option.map(sub.typsub)cto)|Texp_newtypes->Pexp_newtype(mklocsloc,sexp)|Texp_newtype'(_id,label_loc,_)->Pexp_newtype(label_loc,sexp)inExp.mk~loc~attrsdescletcase:typek.mapper->kcase->_=funsub{c_lhs;c_guard;c_rhs}->{pc_lhs=sub.patsubc_lhs;pc_guard=Option.map(sub.exprsub)c_guard;pc_rhs=sub.exprsubc_rhs;}letvalue_bindingsubvb=letloc=sub.locationsubvb.vb_locinletattrs=sub.attributessubvb.vb_attributesinVb.mk~loc~attrs(sub.patsubvb.vb_pat)(sub.exprsubvb.vb_expr)letexpressionsubexp=letloc=sub.locationsubexp.exp_locinletattrs=sub.attributessubexp.exp_attributesinletdesc=matchexp.exp_descwithTexp_ident(_path,lid,_)->Pexp_ident(map_locsublid)|Texp_constantcst->Pexp_constant(constantcst)|Texp_let(rec_flag,list,exp)->Pexp_let(rec_flag,List.map(sub.value_bindingsub)list,sub.exprsubexp)|Texp_function(params,body)->letbody,constraint_=matchbodywith|Tfunction_bodybody->(* Unlike function cases, the [exp_extra] is placed on the body
itself. *)Pfunction_body(sub.exprsubbody),None|Tfunction_cases{cases;loc;exp_extra;attributes;_}->letcases=List.map(sub.casesub)casesinletconstraint_=matchexp_extrawith|Some(Texp_coerce(ty1,ty2))->Some(Pcoerce(Option.map(sub.typsub)ty1,sub.typsubty2))|Some(Texp_constraintty)->Some(Pconstraint(sub.typsubty))|Some(Texp_poly_|Texp_newtype_|Texp_newtype'_)|None->NoneinPfunction_cases(cases,loc,attributes),constraint_inletparams=List.concat_map(funfp->letpat,default_arg=matchfp.fp_kindwith|Tparam_patpat->pat,None|Tparam_optional_default(pat,expr)->pat,Someexprinletpat=sub.patsubpatinletdefault_arg=Option.map(sub.exprsub)default_arginletnewtypes=List.map(funx->{pparam_desc=Pparam_newtypex;pparam_loc=x.loc;})fp.fp_newtypesinletpparam_desc=Pparam_val(fp.fp_arg_label,default_arg,pat)in{pparam_desc;pparam_loc=fp.fp_loc}::newtypes)paramsinPexp_function(params,constraint_,body)|Texp_apply(exp,list)->Pexp_apply(sub.exprsubexp,List.fold_right(fun(label,expo)list->matchexpowithNone->list|Someexp->(label,sub.exprsubexp)::list)list[])|Texp_match(exp,cases,eff_cases,_)->letmerged_cases=List.map(sub.casesub)cases@List.map(func->letuc=sub.casesubcinletpat={uc.pc_lhs(* XXX KC: The 2nd argument of Ppat_effect is wrong *)withppat_desc=Ppat_effect(uc.pc_lhs,uc.pc_lhs)}in{ucwithpc_lhs=pat})eff_casesinPexp_match(sub.exprsubexp,merged_cases)|Texp_try(exp,exn_cases,eff_cases)->letmerged_cases=List.map(sub.casesub)exn_cases@List.map(func->letuc=sub.casesubcinletpat={uc.pc_lhs(* XXX KC: The 2nd argument of Ppat_effect is wrong *)withppat_desc=Ppat_effect(uc.pc_lhs,uc.pc_lhs)}in{ucwithpc_lhs=pat})eff_casesinPexp_try(sub.exprsubexp,merged_cases)|Texp_tuplelist->Pexp_tuple(List.map(sub.exprsub)list)|Texp_construct(lid,_,args)->Pexp_construct(map_locsublid,(matchargswith[]->None|[arg]->Some(sub.exprsubarg)|args->Some(Exp.tuple~loc(List.map(sub.exprsub)args))))|Texp_variant(label,expo)->Pexp_variant(label,Option.map(sub.exprsub)expo)|Texp_record{fields;extended_expression;_}->letlist=Array.fold_left(funl->function|_,Kept_->l|_,Overridden(lid,exp)->(lid,sub.exprsubexp)::l)[]fieldsinPexp_record(list,Option.map(sub.exprsub)extended_expression)|Texp_field(exp,lid,_label)->Pexp_field(sub.exprsubexp,map_locsublid)|Texp_setfield(exp1,lid,_label,exp2)->Pexp_setfield(sub.exprsubexp1,map_locsublid,sub.exprsubexp2)|Texp_arraylist->Pexp_array(List.map(sub.exprsub)list)|Texp_ifthenelse(exp1,exp2,expo)->Pexp_ifthenelse(sub.exprsubexp1,sub.exprsubexp2,Option.map(sub.exprsub)expo)|Texp_sequence(exp1,exp2)->Pexp_sequence(sub.exprsubexp1,sub.exprsubexp2)|Texp_while(exp1,exp2)->Pexp_while(sub.exprsubexp1,sub.exprsubexp2)|Texp_for(_id,name,exp1,exp2,dir,exp3)->Pexp_for(name,sub.exprsubexp1,sub.exprsubexp2,dir,sub.exprsubexp3)|Texp_send(exp,meth)->Pexp_send(sub.exprsubexp,matchmethwithTmeth_namename->mklocnameloc|Tmeth_valid->mkloc(Ident.nameid)loc|Tmeth_ancestor(id,_)->mkloc(Ident.nameid)loc)|Texp_new(_path,lid,_)->Pexp_new(map_locsublid)|Texp_instvar(_,path,name)->Pexp_ident({loc=sub.locationsubname.loc;txt=lident_of_pathpath})|Texp_setinstvar(_,_path,lid,exp)->Pexp_setinstvar(map_locsublid,sub.exprsubexp)|Texp_override(_,list)->Pexp_override(List.map(fun(_path,lid,exp)->(map_locsublid,sub.exprsubexp))list)|Texp_letmodule(_id,name,_pres,mexpr,exp)->Pexp_letmodule(name,sub.module_exprsubmexpr,sub.exprsubexp)|Texp_letexception(ext,exp)->Pexp_letexception(sub.extension_constructorsubext,sub.exprsubexp)|Texp_assert(exp,_)->Pexp_assert(sub.exprsubexp)|Texp_lazyexp->Pexp_lazy(sub.exprsubexp)|Texp_object(cl,_)->Pexp_object(sub.class_structuresubcl)|Texp_pack(mexpr)->Pexp_pack(sub.module_exprsubmexpr)|Texp_letop{let_;ands;body;_}->letpat,and_pats=extract_letop_patterns(List.lengthands)body.c_lhsinletlet_=sub.binding_opsublet_patinletands=List.map2(sub.binding_opsub)andsand_patsinletbody=sub.exprsubbody.c_rhsinPexp_letop{let_;ands;body}|Texp_unreachable->Pexp_unreachable|Texp_extension_constructor(lid,_)->Pexp_extension({txt="ocaml.extension_constructor";loc},PStr[Str.eval~loc(Exp.construct~loc(map_locsublid)None)])|Texp_open(od,exp)->Pexp_open(sub.open_declarationsubod,sub.exprsubexp)|Texp_typed_hole->letid=Location.mklochole_txtlocinPexp_extension(id,PStr[])inList.fold_right(exp_extrasub)exp.exp_extra(Exp.mk~loc~attrsdesc)letbinding_opsubboppat=letpbop_op=bop.bop_op_nameinletpbop_pat=sub.patsubpatinletpbop_exp=sub.exprsubbop.bop_expinletpbop_loc=bop.bop_locin{pbop_op;pbop_pat;pbop_exp;pbop_loc}letpackage_typesubpack=(map_locsubpack.pack_txt,List.map(fun(s,ct)->(s,sub.typsubct))pack.pack_fields)letmodule_type_declarationsubmtd=letloc=sub.locationsubmtd.mtd_locinletattrs=sub.attributessubmtd.mtd_attributesinMtd.mk~loc~attrs?typ:(Option.map(sub.module_typesub)mtd.mtd_type)(map_locsubmtd.mtd_name)letsignaturesubsg=List.map(sub.signature_itemsub)sg.sig_itemsletsignature_itemsubitem=letloc=sub.locationsubitem.sig_locinletdesc=matchitem.sig_descwithTsig_valuev->Psig_value(sub.value_descriptionsubv)|Tsig_type(rec_flag,list)->Psig_type(rec_flag,List.map(sub.type_declarationsub)list)|Tsig_typesubstlist->Psig_typesubst(List.map(sub.type_declarationsub)list)|Tsig_typexttyext->Psig_typext(sub.type_extensionsubtyext)|Tsig_exceptionext->Psig_exception(sub.type_exceptionsubext)|Tsig_modulemd->Psig_module(sub.module_declarationsubmd)|Tsig_modsubstms->Psig_modsubst(sub.module_substitutionsubms)|Tsig_recmodulelist->Psig_recmodule(List.map(sub.module_declarationsub)list)|Tsig_modtypemtd->Psig_modtype(sub.module_type_declarationsubmtd)|Tsig_modtypesubstmtd->Psig_modtypesubst(sub.module_type_declarationsubmtd)|Tsig_openod->Psig_open(sub.open_descriptionsubod)|Tsig_includeincl->Psig_include(sub.include_descriptionsubincl)|Tsig_classlist->Psig_class(List.map(sub.class_descriptionsub)list)|Tsig_class_typelist->Psig_class_type(List.map(sub.class_type_declarationsub)list)|Tsig_attributex->Psig_attributexinSig.mk~locdescletmodule_declarationsubmd=letloc=sub.locationsubmd.md_locinletattrs=sub.attributessubmd.md_attributesinMd.mk~loc~attrs(map_locsubmd.md_name)(sub.module_typesubmd.md_type)letmodule_substitutionsubms=letloc=sub.locationsubms.ms_locinletattrs=sub.attributessubms.ms_attributesinMs.mk~loc~attrs(map_locsubms.ms_name)(map_locsubms.ms_txt)letinclude_infosfsubincl=letloc=sub.locationsubincl.incl_locinletattrs=sub.attributessubincl.incl_attributesinIncl.mk~loc~attrs(fsubincl.incl_mod)letinclude_declarationsub=include_infossub.module_exprsubletinclude_descriptionsub=include_infossub.module_typesubletclass_infosfsubci=letloc=sub.locationsubci.ci_locinletattrs=sub.attributessubci.ci_attributesinCi.mk~loc~attrs~virt:ci.ci_virt~params:(List.map(type_parametersub)ci.ci_params)(map_locsubci.ci_id_name)(fsubci.ci_expr)letclass_declarationsub=class_infossub.class_exprsubletclass_descriptionsub=class_infossub.class_typesubletclass_type_declarationsub=class_infossub.class_typesubletfunctor_parametersub:functor_parameter->Parsetree.functor_parameter=function|Unit->Unit|Named(_,name,mtype)->Named(name,sub.module_typesubmtype)letmodule_type(sub:mapper)mty=letloc=sub.locationsubmty.mty_locinletattrs=sub.attributessubmty.mty_attributesinletdesc=matchmty.mty_descwithTmty_ident(_path,lid)->Pmty_ident(map_locsublid)|Tmty_alias(_path,lid)->Pmty_alias(map_locsublid)|Tmty_signaturesg->Pmty_signature(sub.signaturesubsg)|Tmty_functor(arg,mtype2)->Pmty_functor(functor_parametersubarg,sub.module_typesubmtype2)|Tmty_with(mtype,list)->Pmty_with(sub.module_typesubmtype,List.map(sub.with_constraintsub)list)|Tmty_typeofmexpr->Pmty_typeof(sub.module_exprsubmexpr)inMty.mk~loc~attrsdescletwith_constraintsub(_path,lid,cstr)=matchcstrwith|Twith_typedecl->Pwith_type(map_locsublid,sub.type_declarationsubdecl)|Twith_module(_path,lid2)->Pwith_module(map_locsublid,map_locsublid2)|Twith_modtypemty->letmty=sub.module_typesubmtyinPwith_modtype(map_locsublid,mty)|Twith_typesubstdecl->Pwith_typesubst(map_locsublid,sub.type_declarationsubdecl)|Twith_modsubst(_path,lid2)->Pwith_modsubst(map_locsublid,map_locsublid2)|Twith_modtypesubstmty->letmty=sub.module_typesubmtyinPwith_modtypesubst(map_locsublid,mty)letmodule_expr(sub:mapper)mexpr=letloc=sub.locationsubmexpr.mod_locinletattrs=sub.attributessubmexpr.mod_attributesinmatchmexpr.mod_descwithTmod_constraint(m,_,Tmodtype_implicit,_)->sub.module_exprsubm|_->letdesc=matchmexpr.mod_descwithTmod_ident(_p,lid)->Pmod_ident(map_locsublid)|Tmod_structurest->Pmod_structure(sub.structuresubst)|Tmod_functor(arg,mexpr)->Pmod_functor(functor_parametersubarg,sub.module_exprsubmexpr)|Tmod_apply(mexp1,mexp2,_)->Pmod_apply(sub.module_exprsubmexp1,sub.module_exprsubmexp2)|Tmod_apply_unitmexp1->Pmod_apply_unit(sub.module_exprsubmexp1)|Tmod_constraint(mexpr,_,Tmodtype_explicitmtype,_)->Pmod_constraint(sub.module_exprsubmexpr,sub.module_typesubmtype)|Tmod_constraint(_mexpr,_,Tmodtype_implicit,_)->assertfalse|Tmod_unpack(exp,_pack)->Pmod_unpack(sub.exprsubexp)(* TODO , sub.package_type sub pack) *)|Tmod_typed_hole->letid=Location.mklochole_txtlocinPmod_extension(id,PStr[])inMod.mk~loc~attrsdescletclass_exprsubcexpr=letloc=sub.locationsubcexpr.cl_locinletattrs=sub.attributessubcexpr.cl_attributesinletdesc=matchcexpr.cl_descwith|Tcl_constraint({cl_desc=Tcl_ident(_path,lid,tyl);_},None,_,_,_)->Pcl_constr(map_locsublid,List.map(sub.typsub)tyl)|Tcl_structureclstr->Pcl_structure(sub.class_structuresubclstr)|Tcl_fun(label,pat,_pv,cl,_partial)->Pcl_fun(label,None,sub.patsubpat,sub.class_exprsubcl)|Tcl_apply(cl,args)->Pcl_apply(sub.class_exprsubcl,List.fold_right(fun(label,expo)list->matchexpowithNone->list|Someexp->(label,sub.exprsubexp)::list)args[])|Tcl_let(rec_flat,bindings,_ivars,cl)->Pcl_let(rec_flat,List.map(sub.value_bindingsub)bindings,sub.class_exprsubcl)|Tcl_constraint(cl,Someclty,_vals,_meths,_concrs)->Pcl_constraint(sub.class_exprsubcl,sub.class_typesubclty)|Tcl_open(od,e)->Pcl_open(sub.open_descriptionsubod,sub.class_exprsube)|Tcl_ident_->assertfalse|Tcl_constraint(_,None,_,_,_)->assertfalseinCl.mk~loc~attrsdescletclass_typesubct=letloc=sub.locationsubct.cltyp_locinletattrs=sub.attributessubct.cltyp_attributesinletdesc=matchct.cltyp_descwithTcty_signaturecsg->Pcty_signature(sub.class_signaturesubcsg)|Tcty_constr(_path,lid,list)->Pcty_constr(map_locsublid,List.map(sub.typsub)list)|Tcty_arrow(label,ct,cl)->Pcty_arrow(label,sub.typsubct,sub.class_typesubcl)|Tcty_open(od,e)->Pcty_open(sub.open_descriptionsubod,sub.class_typesube)inCty.mk~loc~attrsdescletclass_signaturesubcs={pcsig_self=sub.typsubcs.csig_self;pcsig_fields=List.map(sub.class_type_fieldsub)cs.csig_fields;}letclass_type_fieldsubctf=letloc=sub.locationsubctf.ctf_locinletattrs=sub.attributessubctf.ctf_attributesinletdesc=matchctf.ctf_descwithTctf_inheritct->Pctf_inherit(sub.class_typesubct)|Tctf_val(s,mut,virt,ct)->Pctf_val(mklocsloc,mut,virt,sub.typsubct)|Tctf_method(s,priv,virt,ct)->Pctf_method(mklocsloc,priv,virt,sub.typsubct)|Tctf_constraint(ct1,ct2)->Pctf_constraint(sub.typsubct1,sub.typsubct2)|Tctf_attributex->Pctf_attributexinCtf.mk~loc~attrsdescletcore_typesubct=letloc=sub.locationsubct.ctyp_locinletattrs=sub.attributessubct.ctyp_attributesinletdesc=matchct.ctyp_descwithTtyp_any->Ptyp_any|Ttyp_vars->Ptyp_vars|Ttyp_arrow(label,ct1,ct2)->Ptyp_arrow(label,sub.typsubct1,sub.typsubct2)|Ttyp_tuplelist->Ptyp_tuple(List.map(sub.typsub)list)|Ttyp_constr(_path,lid,list)->Ptyp_constr(map_locsublid,List.map(sub.typsub)list)|Ttyp_object(list,o)->Ptyp_object(List.map(sub.object_fieldsub)list,o)|Ttyp_class(_path,lid,list)->Ptyp_class(map_locsublid,List.map(sub.typsub)list)|Ttyp_alias(ct,s)->Ptyp_alias(sub.typsubct,s)|Ttyp_variant(list,bool,labels)->Ptyp_variant(List.map(sub.row_fieldsub)list,bool,labels)|Ttyp_poly(list,ct)->letlist=List.map(funv->mklocvloc)listinPtyp_poly(list,sub.typsubct)|Ttyp_packagepack->Ptyp_package(sub.package_typesubpack)|Ttyp_open(_path,mod_ident,t)->Ptyp_open(mod_ident,sub.typsubt)inTyp.mk~loc~attrsdescletclass_structuresubcs=letrecremove_self=function|{pat_desc=Tpat_alias(p,id,_s,_)}whenstring_is_prefix"selfpat-"(Ident.nameid)->remove_selfp|p->pin{pcstr_self=sub.patsub(remove_selfcs.cstr_self);pcstr_fields=List.map(sub.class_fieldsub)cs.cstr_fields;}letrow_fieldsub{rf_loc;rf_desc;rf_attributes;}=letloc=sub.locationsubrf_locinletattrs=sub.attributessubrf_attributesinletdesc=matchrf_descwith|Ttag(label,bool,list)->Rtag(label,bool,List.map(sub.typsub)list)|Tinheritct->Rinherit(sub.typsubct)inRf.mk~loc~attrsdescletobject_fieldsub{of_loc;of_desc;of_attributes;}=letloc=sub.locationsubof_locinletattrs=sub.attributessubof_attributesinletdesc=matchof_descwith|OTtag(label,ct)->Otag(label,sub.typsubct)|OTinheritct->Oinherit(sub.typsubct)inOf.mk~loc~attrsdescandis_self_pat=function|{pat_desc=Tpat_alias(_pat,id,_,_)}->string_is_prefix"self-"(Ident.nameid)|_->false(* [Typeclass] adds a [self] parameter to initializers and methods that isn't
present in the source program.
*)letremove_fun_selfexp=matchexpwith|{exp_desc=Texp_function({fp_arg_label=Nolabel;fp_kind=Tparam_patpat}::params,body)}whenis_self_patpat->(matchparams,bodywith|[],Tfunction_bodybody->body|_,_->{expwithexp_desc=Texp_function(params,body)})|e->eletclass_fieldsubcf=letloc=sub.locationsubcf.cf_locinletattrs=sub.attributessubcf.cf_attributesinletdesc=matchcf.cf_descwithTcf_inherit(ovf,cl,super,_vals,_meths)->Pcf_inherit(ovf,sub.class_exprsubcl,Option.map(funv->mklocvloc)super)|Tcf_constraint(cty,cty')->Pcf_constraint(sub.typsubcty,sub.typsubcty')|Tcf_val(lab,mut,_,Tcfk_virtualcty,_)->Pcf_val(lab,mut,Cfk_virtual(sub.typsubcty))|Tcf_val(lab,mut,_,Tcfk_concrete(o,exp),_)->Pcf_val(lab,mut,Cfk_concrete(o,sub.exprsubexp))|Tcf_method(lab,priv,Tcfk_virtualcty)->Pcf_method(lab,priv,Cfk_virtual(sub.typsubcty))|Tcf_method(lab,priv,Tcfk_concrete(o,exp))->letexp=remove_fun_selfexpinPcf_method(lab,priv,Cfk_concrete(o,sub.exprsubexp))|Tcf_initializerexp->letexp=remove_fun_selfexpinPcf_initializer(sub.exprsubexp)|Tcf_attributex->Pcf_attributexinCf.mk~loc~attrsdescletlocation_subl=lletdefault_mapper={attribute=attribute;attributes=attributes;binding_op=binding_op;structure=structure;structure_item=structure_item;module_expr=module_expr;signature=signature;signature_item=signature_item;module_type=module_type;with_constraint=with_constraint;class_declaration=class_declaration;class_expr=class_expr;class_field=class_field;class_structure=class_structure;class_type=class_type;class_type_field=class_type_field;class_signature=class_signature;class_type_declaration=class_type_declaration;class_description=class_description;type_declaration=type_declaration;type_kind=type_kind;typ=core_type;type_extension=type_extension;type_exception=type_exception;extension_constructor=extension_constructor;value_description=value_description;pat=pattern;expr=expression;module_declaration=module_declaration;module_substitution=module_substitution;module_type_declaration=module_type_declaration;module_binding=module_binding;package_type=package_type;open_declaration=open_declaration;open_description=open_description;include_description=include_description;include_declaration=include_declaration;value_binding=value_binding;constructor_declaration=constructor_declaration;label_declaration=label_declaration;case=case;location=location;row_field=row_field;object_field=object_field;}letuntype_structure?(mapper:mapper=default_mapper)structure=mapper.structuremapperstructureletuntype_signature?(mapper:mapper=default_mapper)signature=mapper.signaturemappersignature(* Merlin *)letuntype_patternpat=default_mapper.patdefault_mapperpatletuntype_expressionexp=default_mapper.exprdefault_mapperexp