123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879(**************************************************************************)(* *)(* OCaml *)(* *)(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)(* *)(* Copyright 1996 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. *)(* *)(**************************************************************************)(* Abstract syntax tree after typing *)openAsttypesopenTypes(* Value expressions for the core language *)typepartial=Partial|Totaltypeattribute=Parsetree.attributetypeattributes=attributelisttypevalue=Value_patterntypecomputation=Computation_patterntype_pattern_category=|Value:valuepattern_category|Computation:computationpattern_categorytypepattern=valuegeneral_patternand'kgeneral_pattern='kpattern_descpattern_dataand'apattern_data={pat_desc:'a;pat_loc:Location.t;pat_extra:(pat_extra*Location.t*attributelist)list;pat_type:type_expr;pat_env:Env.t;pat_attributes:attributelist;}andpat_extra=|Tpat_constraintofcore_type|Tpat_typeofPath.t*Longident.tloc|Tpat_openofPath.t*Longident.tloc*Env.t|Tpat_unpackand'kpattern_desc=(* value patterns *)|Tpat_any:valuepattern_desc|Tpat_var:Ident.t*stringloc->valuepattern_desc|Tpat_alias:valuegeneral_pattern*Ident.t*stringloc->valuepattern_desc|Tpat_constant:constant->valuepattern_desc|Tpat_tuple:valuegeneral_patternlist->valuepattern_desc|Tpat_construct:Longident.tloc*constructor_description*valuegeneral_patternlist*(Ident.tloclist*core_type)option->valuepattern_desc|Tpat_variant:label*valuegeneral_patternoption*row_descref->valuepattern_desc|Tpat_record:(Longident.tloc*label_description*valuegeneral_pattern)list*closed_flag->valuepattern_desc|Tpat_array:valuegeneral_patternlist->valuepattern_desc|Tpat_lazy:valuegeneral_pattern->valuepattern_desc(* computation patterns *)|Tpat_value:tpat_value_argument->computationpattern_desc|Tpat_exception:valuegeneral_pattern->computationpattern_desc(* generic constructions *)|Tpat_or:'kgeneral_pattern*'kgeneral_pattern*row_descoption->'kpattern_descandtpat_value_argument=valuegeneral_patternandexpression={exp_desc:expression_desc;exp_loc:Location.t;exp_extra:(exp_extra*Location.t*attributelist)list;exp_type:type_expr;exp_env:Env.t;exp_attributes:attributelist;}andexp_extra=|Texp_constraintofcore_type|Texp_coerceofcore_typeoption*core_type|Texp_polyofcore_typeoption|Texp_newtypeofstring|Texp_newtype'ofIdent.t*labellocandexpression_desc=Texp_identofPath.t*Longident.tloc*Types.value_description|Texp_constantofconstant|Texp_letofrec_flag*value_bindinglist*expression|Texp_functionof{arg_label:arg_label;param:Ident.t;cases:valuecaselist;partial:partial;}|Texp_applyofexpression*(arg_label*expressionoption)list|Texp_matchofexpression*computationcaselist*partial|Texp_tryofexpression*valuecaselist|Texp_tupleofexpressionlist|Texp_constructofLongident.tloc*constructor_description*expressionlist|Texp_variantoflabel*expressionoption|Texp_recordof{fields:(Types.label_description*record_label_definition)array;representation:Types.record_representation;extended_expression:expressionoption;}|Texp_fieldofexpression*Longident.tloc*label_description|Texp_setfieldofexpression*Longident.tloc*label_description*expression|Texp_arrayofexpressionlist|Texp_ifthenelseofexpression*expression*expressionoption|Texp_sequenceofexpression*expression|Texp_whileofexpression*expression|Texp_forofIdent.t*Parsetree.pattern*expression*expression*direction_flag*expression|Texp_sendofexpression*meth|Texp_newofPath.t*Longident.tloc*Types.class_declaration|Texp_instvarofPath.t*Path.t*stringloc|Texp_setinstvarofPath.t*Path.t*stringloc*expression|Texp_overrideofPath.t*(Ident.t*stringloc*expression)list|Texp_letmoduleofIdent.toption*stringoptionloc*Types.module_presence*module_expr*expression|Texp_letexceptionofextension_constructor*expression|Texp_assertofexpression*Location.t|Texp_lazyofexpression|Texp_objectofclass_structure*stringlist|Texp_packofmodule_expr|Texp_letopof{let_:binding_op;ands:binding_oplist;param:Ident.t;body:valuecase;partial:partial;}|Texp_unreachable|Texp_extension_constructorofLongident.tloc*Path.t|Texp_openofopen_declaration*expression|Texp_holeandmeth=|Tmeth_nameofstring|Tmeth_valofIdent.t|Tmeth_ancestorofIdent.t*Path.tand'kcase={c_lhs:'kgeneral_pattern;c_guard:expressionoption;c_rhs:expression;}andrecord_label_definition=|KeptofTypes.type_expr*mutable_flag|OverriddenofLongident.tloc*expressionandbinding_op={bop_op_path:Path.t;bop_op_name:stringloc;bop_op_val:Types.value_description;bop_op_type:Types.type_expr;bop_exp:expression;bop_loc:Location.t;}(* Value expressions for the class language *)andclass_expr={cl_desc:class_expr_desc;cl_loc:Location.t;cl_type:Types.class_type;cl_env:Env.t;cl_attributes:attributelist;}andclass_expr_desc=Tcl_identofPath.t*Longident.tloc*core_typelist|Tcl_structureofclass_structure|Tcl_funofarg_label*pattern*(Ident.t*expression)list*class_expr*partial|Tcl_applyofclass_expr*(arg_label*expressionoption)list|Tcl_letofrec_flag*value_bindinglist*(Ident.t*expression)list*class_expr|Tcl_constraintofclass_expr*class_typeoption*stringlist*stringlist*MethSet.t(* Visible instance variables, methods and concrete methods *)|Tcl_openofopen_description*class_exprandclass_structure={cstr_self:pattern;cstr_fields:class_fieldlist;cstr_type:Types.class_signature;cstr_meths:Ident.tMeths.t;}andclass_field={cf_desc:class_field_desc;cf_loc:Location.t;cf_attributes:attributelist;}andclass_field_kind=|Tcfk_virtualofcore_type|Tcfk_concreteofoverride_flag*expressionandclass_field_desc=Tcf_inheritofoverride_flag*class_expr*stringoption*(string*Ident.t)list*(string*Ident.t)list(* Inherited instance variables and concrete methods *)|Tcf_valofstringloc*mutable_flag*Ident.t*class_field_kind*bool|Tcf_methodofstringloc*private_flag*class_field_kind|Tcf_constraintofcore_type*core_type|Tcf_initializerofexpression|Tcf_attributeofattribute(* Value expressions for the module language *)andmodule_expr={mod_desc:module_expr_desc;mod_loc:Location.t;mod_type:Types.module_type;mod_env:Env.t;mod_attributes:attributelist;}andmodule_type_constraint=Tmodtype_implicit|Tmodtype_explicitofmodule_typeandfunctor_parameter=|Unit|NamedofIdent.toption*stringoptionloc*module_typeandmodule_expr_desc=Tmod_identofPath.t*Longident.tloc|Tmod_structureofstructure|Tmod_functoroffunctor_parameter*module_expr|Tmod_applyofmodule_expr*module_expr*module_coercion|Tmod_apply_unitofmodule_expr|Tmod_constraintofmodule_expr*Types.module_type*module_type_constraint*module_coercion|Tmod_unpackofexpression*Types.module_type|Tmod_holeandstructure={str_items:structure_itemlist;str_type:Types.signature;str_final_env:Env.t;}andstructure_item={str_desc:structure_item_desc;str_loc:Location.t;str_env:Env.t}andstructure_item_desc=Tstr_evalofexpression*attributes|Tstr_valueofrec_flag*value_bindinglist|Tstr_primitiveofvalue_description|Tstr_typeofrec_flag*type_declarationlist|Tstr_typextoftype_extension|Tstr_exceptionoftype_exception|Tstr_moduleofmodule_binding|Tstr_recmoduleofmodule_bindinglist|Tstr_modtypeofmodule_type_declaration|Tstr_openofopen_declaration|Tstr_classof(class_declaration*stringlist)list|Tstr_class_typeof(Ident.t*stringloc*class_type_declaration)list|Tstr_includeofinclude_declaration|Tstr_attributeofattributeandmodule_binding={mb_id:Ident.toption;mb_name:stringoptionloc;mb_presence:module_presence;mb_expr:module_expr;mb_attributes:attributelist;mb_loc:Location.t;}andvalue_binding={vb_pat:pattern;vb_expr:expression;vb_attributes:attributes;vb_loc:Location.t;}andmodule_coercion=Tcoerce_none|Tcoerce_structureof(int*module_coercion)list*(Ident.t*int*module_coercion)list|Tcoerce_functorofmodule_coercion*module_coercion|Tcoerce_primitiveofprimitive_coercion|Tcoerce_aliasofEnv.t*Path.t*module_coercionandmodule_type={mty_desc:module_type_desc;mty_type:Types.module_type;mty_env:Env.t;mty_loc:Location.t;mty_attributes:attributelist;}andmodule_type_desc=Tmty_identofPath.t*Longident.tloc|Tmty_signatureofsignature|Tmty_functoroffunctor_parameter*module_type|Tmty_withofmodule_type*(Path.t*Longident.tloc*with_constraint)list|Tmty_typeofofmodule_expr|Tmty_aliasofPath.t*Longident.tloc(* Keep primitive type information for type-based lambda-code specialization *)andprimitive_coercion={pc_desc:Primitive.description;pc_type:type_expr;pc_env:Env.t;pc_loc:Location.t;}andsignature={sig_items:signature_itemlist;sig_type:Types.signature;sig_final_env:Env.t;}andsignature_item={sig_desc:signature_item_desc;sig_env:Env.t;(* BINANNOT ADDED *)sig_loc:Location.t}andsignature_item_desc=Tsig_valueofvalue_description|Tsig_typeofrec_flag*type_declarationlist|Tsig_typesubstoftype_declarationlist|Tsig_typextoftype_extension|Tsig_exceptionoftype_exception|Tsig_moduleofmodule_declaration|Tsig_modsubstofmodule_substitution|Tsig_recmoduleofmodule_declarationlist|Tsig_modtypeofmodule_type_declaration|Tsig_modtypesubstofmodule_type_declaration|Tsig_openofopen_description|Tsig_includeofinclude_description|Tsig_classofclass_descriptionlist|Tsig_class_typeofclass_type_declarationlist|Tsig_attributeofattributeandmodule_declaration={md_id:Ident.toption;md_name:stringoptionloc;md_presence:module_presence;md_type:module_type;md_attributes:attributelist;md_loc:Location.t;}andmodule_substitution={ms_id:Ident.t;ms_name:stringloc;ms_manifest:Path.t;ms_txt:Longident.tloc;ms_attributes:attributes;ms_loc:Location.t;}andmodule_type_declaration={mtd_id:Ident.t;mtd_name:stringloc;mtd_type:module_typeoption;mtd_attributes:attributelist;mtd_loc:Location.t;}and'aopen_infos={open_expr:'a;open_bound_items:Types.signature;open_override:override_flag;open_env:Env.t;open_loc:Location.t;open_attributes:attributelist;}andopen_description=(Path.t*Longident.tloc)open_infosandopen_declaration=module_expropen_infosand'ainclude_infos={incl_mod:'a;incl_type:Types.signature;incl_loc:Location.t;incl_attributes:attributelist;}andinclude_description=module_typeinclude_infosandinclude_declaration=module_exprinclude_infosandwith_constraint=Twith_typeoftype_declaration|Twith_moduleofPath.t*Longident.tloc|Twith_modtypeofmodule_type|Twith_typesubstoftype_declaration|Twith_modsubstofPath.t*Longident.tloc|Twith_modtypesubstofmodule_typeandcore_type=(* mutable because of [Typeclass.declare_method] *){mutablectyp_desc:core_type_desc;mutablectyp_type:type_expr;ctyp_env:Env.t;(* BINANNOT ADDED *)ctyp_loc:Location.t;ctyp_attributes:attributelist;}andcore_type_desc=Ttyp_any|Ttyp_varofstring|Ttyp_arrowofarg_label*core_type*core_type|Ttyp_tupleofcore_typelist|Ttyp_constrofPath.t*Longident.tloc*core_typelist|Ttyp_objectofobject_fieldlist*closed_flag|Ttyp_classofPath.t*Longident.tloc*core_typelist|Ttyp_aliasofcore_type*string|Ttyp_variantofrow_fieldlist*closed_flag*labellistoption|Ttyp_polyofstringlist*core_type|Ttyp_packageofpackage_typeandpackage_type={pack_path:Path.t;pack_fields:(Longident.tloc*core_type)list;pack_type:Types.module_type;pack_txt:Longident.tloc;}androw_field={rf_desc:row_field_desc;rf_loc:Location.t;rf_attributes:attributes;}androw_field_desc=Ttagofstringloc*bool*core_typelist|Tinheritofcore_typeandobject_field={of_desc:object_field_desc;of_loc:Location.t;of_attributes:attributes;}andobject_field_desc=|OTtagofstringloc*core_type|OTinheritofcore_typeandvalue_description={val_id:Ident.t;val_name:stringloc;val_desc:core_type;val_val:Types.value_description;val_prim:stringlist;val_loc:Location.t;val_attributes:attributelist;}andtype_declaration={typ_id:Ident.t;typ_name:stringloc;typ_params:(core_type*(variance*injectivity))list;typ_type:Types.type_declaration;typ_cstrs:(core_type*core_type*Location.t)list;typ_kind:type_kind;typ_private:private_flag;typ_manifest:core_typeoption;typ_loc:Location.t;typ_attributes:attributelist;}andtype_kind=Ttype_abstract|Ttype_variantofconstructor_declarationlist|Ttype_recordoflabel_declarationlist|Ttype_openandlabel_declaration={ld_id:Ident.t;ld_name:stringloc;ld_mutable:mutable_flag;ld_type:core_type;ld_loc:Location.t;ld_attributes:attributelist;}andconstructor_declaration={cd_id:Ident.t;cd_name:stringloc;cd_vars:stringloclist;cd_args:constructor_arguments;cd_res:core_typeoption;cd_loc:Location.t;cd_attributes:attributelist;}andconstructor_arguments=|Cstr_tupleofcore_typelist|Cstr_recordoflabel_declarationlistandtype_extension={tyext_path:Path.t;tyext_txt:Longident.tloc;tyext_params:(core_type*(variance*injectivity))list;tyext_constructors:extension_constructorlist;tyext_private:private_flag;tyext_loc:Location.t;tyext_attributes:attributelist;}andtype_exception={tyexn_constructor:extension_constructor;tyexn_loc:Location.t;tyexn_attributes:attributelist;}andextension_constructor={ext_id:Ident.t;ext_name:stringloc;ext_type:Types.extension_constructor;ext_kind:extension_constructor_kind;ext_loc:Location.t;ext_attributes:attributelist;}andextension_constructor_kind=Text_declofstringloclist*constructor_arguments*core_typeoption|Text_rebindofPath.t*Longident.tlocandclass_type={cltyp_desc:class_type_desc;cltyp_type:Types.class_type;cltyp_env:Env.t;cltyp_loc:Location.t;cltyp_attributes:attributelist;}andclass_type_desc=Tcty_constrofPath.t*Longident.tloc*core_typelist|Tcty_signatureofclass_signature|Tcty_arrowofarg_label*core_type*class_type|Tcty_openofopen_description*class_typeandclass_signature={csig_self:core_type;csig_fields:class_type_fieldlist;csig_type:Types.class_signature;}andclass_type_field={ctf_desc:class_type_field_desc;ctf_loc:Location.t;ctf_attributes:attributelist;}andclass_type_field_desc=|Tctf_inheritofclass_type|Tctf_valof(string*mutable_flag*virtual_flag*core_type)|Tctf_methodof(string*private_flag*virtual_flag*core_type)|Tctf_constraintof(core_type*core_type)|Tctf_attributeofattributeandclass_declaration=class_exprclass_infosandclass_description=class_typeclass_infosandclass_type_declaration=class_typeclass_infosand'aclass_infos={ci_virt:virtual_flag;ci_params:(core_type*(variance*injectivity))list;ci_id_name:stringloc;ci_id_class:Ident.t;ci_id_class_type:Ident.t;ci_id_object:Ident.t;ci_expr:'a;ci_decl:Types.class_declaration;ci_type_decl:Types.class_type_declaration;ci_loc:Location.t;ci_attributes:attributelist;}typeimplementation={structure:structure;coercion:module_coercion;signature:Types.signature;shape:Shape.t;}(* Auxiliary functions over the a.s.t. *)letas_computation_pattern(p:pattern):computationgeneral_pattern={pat_desc=Tpat_valuep;pat_loc=p.pat_loc;pat_extra=[];pat_type=p.pat_type;pat_env=p.pat_env;pat_attributes=[];}letrecclassify_pattern_desc:typek.kpattern_desc->kpattern_category=function|Tpat_alias_->Value|Tpat_tuple_->Value|Tpat_construct_->Value|Tpat_variant_->Value|Tpat_record_->Value|Tpat_array_->Value|Tpat_lazy_->Value|Tpat_any->Value|Tpat_var_->Value|Tpat_constant_->Value|Tpat_value_->Computation|Tpat_exception_->Computation|Tpat_or(p1,p2,_)->beginmatchclassify_patternp1,classify_patternp2with|Value,Value->Value|Computation,Computation->Computationendandclassify_pattern:typek.kgeneral_pattern->kpattern_category=funpat->classify_pattern_descpat.pat_desctypepattern_action={f:'k.'kgeneral_pattern->unit}letshallow_iter_pattern_desc:typek.pattern_action->kpattern_desc->unit=funf->function|Tpat_alias(p,_,_)->f.fp|Tpat_tuplepatl->List.iterf.fpatl|Tpat_construct(_,_,patl,_)->List.iterf.fpatl|Tpat_variant(_,pat,_)->Option.iterf.fpat|Tpat_record(lbl_pat_list,_)->List.iter(fun(_,_,pat)->f.fpat)lbl_pat_list|Tpat_arraypatl->List.iterf.fpatl|Tpat_lazyp->f.fp|Tpat_any|Tpat_var_|Tpat_constant_->()|Tpat_valuep->f.fp|Tpat_exceptionp->f.fp|Tpat_or(p1,p2,_)->f.fp1;f.fp2typepattern_transformation={f:'k.'kgeneral_pattern->'kgeneral_pattern}letshallow_map_pattern_desc:typek.pattern_transformation->kpattern_desc->kpattern_desc=funfd->matchdwith|Tpat_alias(p1,id,s)->Tpat_alias(f.fp1,id,s)|Tpat_tuplepats->Tpat_tuple(List.mapf.fpats)|Tpat_record(lpats,closed)->Tpat_record(List.map(fun(lid,l,p)->lid,l,f.fp)lpats,closed)|Tpat_construct(lid,c,pats,ty)->Tpat_construct(lid,c,List.mapf.fpats,ty)|Tpat_arraypats->Tpat_array(List.mapf.fpats)|Tpat_lazyp1->Tpat_lazy(f.fp1)|Tpat_variant(x1,Somep1,x2)->Tpat_variant(x1,Some(f.fp1),x2)|Tpat_var_|Tpat_constant_|Tpat_any|Tpat_variant(_,None,_)->d|Tpat_valuep->Tpat_value(f.fp)|Tpat_exceptionp->Tpat_exception(f.fp)|Tpat_or(p1,p2,path)->Tpat_or(f.fp1,f.fp2,path)letreciter_general_pattern:typek.pattern_action->kgeneral_pattern->unit=funfp->f.fp;shallow_iter_pattern_desc{f=funp->iter_general_patternfp}p.pat_descletiter_pattern(f:pattern->unit)=iter_general_pattern{f=fun(typek)(p:kgeneral_pattern)->matchclassify_patternpwith|Value->fp|Computation->()}typepattern_predicate={f:'k.'kgeneral_pattern->bool}letexists_general_pattern(f:pattern_predicate)p=letexceptionFoundinmatchiter_general_pattern{f=funp->iff.fpthenraiseFoundelse()}pwith|exceptionFound->true|()->falseletexists_pattern(f:pattern->bool)=exists_general_pattern{f=fun(typek)(p:kgeneral_pattern)->matchclassify_patternpwith|Value->fp|Computation->false}(* List the identifiers bound by a pattern or a let *)letreciter_bound_idents:typek._->kgeneral_pattern->_=funfpat->matchpat.pat_descwith|Tpat_var(id,s)->f(id,s,pat.pat_type)|Tpat_alias(p,id,s)->iter_bound_identsfp;f(id,s,pat.pat_type)|Tpat_or(p1,_,_)->(* Invariant : both arguments bind the same variables *)iter_bound_identsfp1|d->shallow_iter_pattern_desc{f=funp->iter_bound_identsfp}dletrev_pat_bound_idents_fullpat=letidents_full=ref[]inletaddid_full=idents_full:=id_full::!idents_fulliniter_bound_identsaddpat;!idents_fullletrev_only_identsidents_full=List.rev_map(fun(id,_,_)->id)idents_fullletpat_bound_idents_fullpat=List.rev(rev_pat_bound_idents_fullpat)letpat_bound_identspat=rev_only_idents(rev_pat_bound_idents_fullpat)letrev_let_bound_idents_fullbindings=letidents_full=ref[]inletaddid_full=idents_full:=id_full::!idents_fullinList.iter(funvb->iter_bound_identsaddvb.vb_pat)bindings;!idents_fullletlet_bound_idents_fullbindings=List.rev(rev_let_bound_idents_fullbindings)letlet_bound_identspat=rev_only_idents(rev_let_bound_idents_fullpat)letalpha_varenvid=List.associdenvletrecalpha_pat:typek._->kgeneral_pattern->kgeneral_pattern=funenvp->matchp.pat_descwith|Tpat_var(id,s)->(* note the ``Not_found'' case *){pwithpat_desc=tryTpat_var(alpha_varenvid,s)with|Not_found->Tpat_any}|Tpat_alias(p1,id,s)->letnew_p:kgeneral_pattern=alpha_patenvp1inbegintry{pwithpat_desc=Tpat_alias(new_p,alpha_varenvid,s)}with|Not_found->new_pend|d->letpat_desc=shallow_map_pattern_desc{f=funp->alpha_patenvp}din{pwithpat_desc}letmkloc=Location.mklocletmknoloc=Location.mknolocletsplit_patternpat=letcombine_optsmergep1p2=matchp1,p2with|None,None->None|Somep,None|None,Somep->Somep|Somep1,Somep2->Some(mergep1p2)inletintopatp1p2=(* The third parameter of [Tpat_or] is [Some _] only for "#typ"
patterns, which we do *not* expand. Hence we can put [None] here. *){patwithpat_desc=Tpat_or(p1,p2,None)}inletrecsplit_patterncpat=matchcpat.pat_descwith|Tpat_valuep->Somep,None|Tpat_exceptionp->None,Somep|Tpat_or(cp1,cp2,_)->letvals1,exns1=split_patterncp1inletvals2,exns2=split_patterncp2incombine_opts(intocpat)vals1vals2,(* We could change the pattern type for exception patterns to
[Predef.exn], but it doesn't really matter. *)combine_opts(intocpat)exns1exns2insplit_patternpat(* Expressions are considered nominal if they can be used as the subject of a
sentence or action. In practice, we consider that an expression is nominal
if they satisfy one of:
- Similar to an identifier: words separated by '.' or '#'.
- Do not contain spaces when printed.
*)letrecexp_is_nominalexp=matchexp.exp_descwith|_whenexp.exp_attributes<>[]->false|Texp_ident_|Texp_instvar_|Texp_constant_|Texp_variant(_,None)|Texp_construct(_,_,[])->true|Texp_field(parent,_,_)|Texp_send(parent,_)->exp_is_nominalparent|_->false(* Merlin specific *)letunpack_functor_meme=matchme.mod_descwith|Tmod_functor(fp,mty)->fp,mty|_->invalid_arg"Typedtree.unpack_functor_me (merlin)"letunpack_functor_mtymty=matchmty.mty_descwith|Tmty_functor(fp,mty)->fp,mty|_->invalid_arg"Typedtree.unpack_functor_mty (merlin)"