123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124openMigrate_parsetree.Ast_406(* This file is part of the ppx_tools package. It is released *)(* under the terms of the MIT license (see LICENSE file). *)(* Copyright 2013 Alain Frisch and LexiFi *)openParsetreeopenAsttypesopenLocationopenAst_helpermoduleLabel=structtypet=Asttypes.arg_labeltypedesc=Asttypes.arg_label=Nolabel|Labelledofstring|Optionalofstringletexplodex=xletnolabel=Nolabelletlabelledx=Labelledxletoptionalx=OptionalxendmoduleConstant=structtypet=Parsetree.constant=Pconst_integerofstring*charoption|Pconst_charofchar|Pconst_stringofstring*stringoption|Pconst_floatofstring*charoptionletof_constantx=xletto_constantx=xendletmay_tuple?loctup=function|[]->None|[x]->Somex|l->Some(tup?loc?attrs:Nonel)letlid?(loc=!default_loc)s=mkloc(Longident.parses)locletconstr?loc?attrssargs=Exp.construct?loc?attrs(lid?locs)(may_tuple?locExp.tupleargs)letnil?loc?attrs()=constr?loc?attrs"[]"[]letunit?loc?attrs()=constr?loc?attrs"()"[]lettuple?loc?attrs=function|[]->unit?loc?attrs()|[x]->x|xs->Exp.tuple?loc?attrsxsletcons?loc?attrshdtl=constr?loc?attrs"::"[hd;tl]letlist?loc?attrsl=List.fold_right(cons?loc?attrs)l(nil?loc?attrs())letstr?loc?attrss=Exp.constant?loc?attrs(Pconst_string(s,None))letint?loc?attrsx=Exp.constant?loc?attrs(Pconst_integer(string_of_intx,None))letint32?loc?attrsx=Exp.constant?loc?attrs(Pconst_integer(Int32.to_stringx,Some'l'))letint64?loc?attrsx=Exp.constant?loc?attrs(Pconst_integer(Int64.to_stringx,Some'L'))letchar?loc?attrsx=Exp.constant?loc?attrs(Pconst_charx)letfloat?loc?attrsx=Exp.constant?loc?attrs(Pconst_float(string_of_floatx,None))letrecord?loc?attrs?overl=Exp.record?loc?attrs(List.map(fun(s,e)->(lid~loc:e.pexp_locs,e))l)overletfunc?loc?attrsl=Exp.function_?loc?attrs(List.map(fun(p,e)->Exp.casepe)l)letlam?loc?attrs?(label=Label.nolabel)?defaultpatexp=Exp.fun_?loc?attrslabeldefaultpatexpletapp?loc?attrsfl=ifl=[]thenfelseExp.apply?loc?attrsf(List.map(funa->Label.nolabel,a)l)letevar?loc?attrss=Exp.ident?loc?attrs(lid?locs)letlet_in?loc?attrs?(recursive=false)bbody=Exp.let_?loc?attrs(ifrecursivethenRecursiveelseNonrecursive)bbodyletsequence?loc?attrs=function|[]->unit?loc?attrs()|hd::tl->List.fold_left(fune1e2->Exp.sequence?loc?attrse1e2)hdtlletpvar?(loc=!default_loc)?attrss=Pat.var~loc?attrs(mklocsloc)letpconstr?loc?attrssargs=Pat.construct?loc?attrs(lid?locs)(may_tuple?locPat.tupleargs)letprecord?loc?attrs?(closed=Open)l=Pat.record?loc?attrs(List.map(fun(s,e)->(lid~loc:e.ppat_locs,e))l)closedletpnil?loc?attrs()=pconstr?loc?attrs"[]"[]letpcons?loc?attrshdtl=pconstr?loc?attrs"::"[hd;tl]letpunit?loc?attrs()=pconstr?loc?attrs"()"[]letptuple?loc?attrs=function|[]->punit?loc?attrs()|[x]->x|xs->Pat.tuple?loc?attrsxsletplist?loc?attrsl=List.fold_right(pcons?loc?attrs)l(pnil?loc?attrs())letpstr?loc?attrss=Pat.constant?loc?attrs(Pconst_string(s,None))letpint?loc?attrsx=Pat.constant?loc?attrs(Pconst_integer(string_of_intx,None))letpchar?loc?attrsx=Pat.constant?loc?attrs(Pconst_charx)letpfloat?loc?attrsx=Pat.constant?loc?attrs(Pconst_float(string_of_floatx,None))lettconstr?loc?attrscl=Typ.constr?loc?attrs(lid?locc)lletget_str=function|{pexp_desc=Pexp_constant(Pconst_string(s,_));_}->Somes|_->Noneletget_str_with_quotation_delimiter=function|{pexp_desc=Pexp_constant(Pconst_string(s,d));_}->Some(s,d)|_->Noneletget_lid=function|{pexp_desc=Pexp_ident{txt=id;_};_}->Some(String.concat"."(Longident.flattenid))|_->Noneletfind_attrsattrs=trySome(snd(List.find(fun(x,_)->x.txt=s)attrs))withNot_found->Noneletexpr_of_payload=function|PStr[{pstr_desc=Pstr_eval(e,_);_}]->Somee|_->Noneletfind_attr_exprsattrs=matchfind_attrsattrswith|Somee->expr_of_payloade|None->Nonelethas_attrsattrs=find_attrsattrs<>None