Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file common.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211open!ImportopenAst_builder.DefaultmoduleBuffer=Caml.BuffermoduleFormat=Caml.Formatletlidentx=Longident.Lidentxletcore_type_of_type_declarationtd=letloc=td.ptype_name.locinptyp_constr~loc(Located.maplidenttd.ptype_name)(List.maptd.ptype_params~f:fst);;letgen_symbol=letcnt=ref0infun?(prefix="_x")()->cnt:=!cnt+1;Printf.sprintf"%s__%03i_"prefix!cnt;;letname_type_params_in_td(td:type_declaration):type_declaration=letname_param(tp,variance)=letptyp_desc=matchtp.ptyp_descwith|Ptyp_any->Ptyp_var("v"^gen_symbol())|Ptyp_var_asv->v|_->Location.raise_errorf~loc:tp.ptyp_loc"not a type parameter"in({tpwithptyp_desc},variance)in{tdwithptype_params=List.maptd.ptype_params~f:name_param};;letcombinator_type_of_type_declarationtd~f=lettd=name_type_params_in_tdtdinletresult_type=f~loc:td.ptype_name.loc(core_type_of_type_declarationtd)inList.fold_righttd.ptype_params~init:result_type~f:(fun(tp,_variance)acc->letloc=tp.ptyp_locinptyp_arrow~locNolabel(f~loctp)acc);;letstring_of_core_typect=letbuf=Buffer.create128inletppf=Format.formatter_of_bufferbufinPprintast.core_typeppfct;Format.pp_print_flushppf();Buffer.contentsbuf;;letget_type_param_name(ty,_)=letloc=ty.ptyp_locinmatchty.ptyp_descwith|Ptyp_varname->Located.mk~locname|_->Location.raise_errorf~loc"not a type parameter"exceptionType_is_recursiveclasstype_is_recursiverec_flagtds=object(self)inheritAst_traverse.iterassupervaltype_names:stringlist=List.maptds~f:(funtd->td.ptype_name.txt)methodreturn_true()=Exn.raise_without_backtraceType_is_recursivemethod!core_typectype=matchctype.ptyp_descwith|Ptyp_arrow_->()|Ptyp_constr({txt=Longident.Lidentid;_},_)whenList.mem~equal:String.equaltype_namesid->self#return_true()|_->super#core_typectypemethod!constructor_declarationcd=(* Don't recurse through cd.pcd_res *)matchcd.pcd_argswith|Pcstr_tupleargs->List.iterargs~f:self#core_type|Pcstr_recordfields->List.iterfields~f:self#label_declarationmethodgo()=matchrec_flagwith|Nonrecursive->Nonrecursive|Recursive->matchList.itertds~f:self#type_declarationwith|exceptionType_is_recursive->Recursive|()->Nonrecursiveendletreally_recursiverec_flagtds=(newtype_is_recursiverec_flagtds)#go()letreclastxl=matchlwith|[]->x|x::l->lastxl;;letloc_of_name_and_payloadnamepayload=matchpayloadwith|PStr[]->name.loc|PStr(x::l)->{x.pstr_locwithloc_end=(lastxl).pstr_loc.loc_end}|PSig[]->name.loc|PSig(x::l)->{x.psig_locwithloc_end=(lastxl).psig_loc.loc_end}|PTypt->t.ptyp_loc|PPat(x,None)->x.ppat_loc|PPat(x,Somee)->{x.ppat_locwithloc_end=e.pexp_loc.loc_end};;letloc_of_payload{attr_name;attr_payload;attr_loc=_;}=loc_of_name_and_payloadattr_nameattr_payloadletloc_of_attribute{attr_name;attr_payload;attr_loc=_;}=(* TODO: fix this in the compiler, and move the logic to omp when converting
from older asts. *)(* "ocaml.doc" attributes are generated with [Location.none], which is not helpful for
error messages. *)ifPoly.(=)attr_name.locLocation.nonethenloc_of_name_and_payloadattr_nameattr_payloadelse{attr_name.locwithloc_end=(loc_of_name_and_payloadattr_nameattr_payload).loc_end};;letloc_of_extension(name,payload)=ifPoly.(=)name.locLocation.nonethenloc_of_name_and_payloadnamepayloadelse{name.locwithloc_end=(loc_of_name_and_payloadnamepayload).loc_end};;letcurry_applicationsexpr=letopenAst_builder_generated.Minmatchexpr.pexp_descwith|Pexp_apply(f,orig_forward_args)->letloc=expr.pexp_locinletrecloop=function|[]->f|last_arg::rev_front_args->pexp_apply~loc(looprev_front_args)[last_arg]inloop(List.revorig_forward_args)|_->expr;;letrecassert_no_attributes=function|[]->()|{attr_name=name;attr_loc=_;attr_payload=_;}::restwhenName.ignore_checksname.Location.txt->assert_no_attributesrest|attr::_->letloc=loc_of_attributeattrinLocation.raise_errorf~loc"Attributes not allowed here"letassert_no_attributes_in=objectinheritAst_traverse.itermethod!attributea=assert_no_attributes[a]endletattribute_of_warninglocs={attr_name={loc;txt="ocaml.ppwarning"};attr_payload=PStr([pstr_eval~loc(estring~locs)[]]);attr_loc=loc;}letis_polymorphic_variant=letreccheck=function|{ptyp_desc=Ptyp_variant_;_}->`Definitely|{ptyp_desc=Ptyp_alias(typ,_);_}->checktyp|{ptyp_desc=Ptyp_constr_;_}->`Maybe|_->`Surely_not(* Type vars go here even though they could be polymorphic
variants, however we don't handle it if they get substituted
by a polymorphic variant that is then included. *)infuntd~sig_->matchtd.ptype_kindwith|Ptype_variant_|Ptype_record_|Ptype_open->`Surely_not|Ptype_abstract->matchtd.ptype_manifestwith|None->ifsig_then`Maybeelse`Surely_not|Sometyp->checktypletmk_named_sig~loc~sg_name~handle_polymorphic_variant=function|[td]whenString.equaltd.ptype_name.txt"t"&&List.is_emptytd.ptype_cstrs->ifnothandle_polymorphic_variant&&Poly.(=)(is_polymorphic_varianttd~sig_:true)`DefinitelythenNoneelseletarity=List.lengthtd.ptype_paramsinifarity>=4thenNoneelseletmty=ifarity=0thensg_nameelsePrintf.sprintf"%s%d"sg_namearityinlettd=name_type_params_in_tdtdinletfor_subst=Ast_helper.Type.mk~loctd.ptype_name~params:td.ptype_params~manifest:(ptyp_constr~loc(Located.map_lidenttd.ptype_name)(List.map~f:fsttd.ptype_params))inSome(include_infos~loc(pmty_with~loc(pmty_ident~loc(Located.lidentmty~loc))[Pwith_typesubst(Located.lident~loc"t",for_subst)]))|_->None