123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178open!ImportincludeClause_syntax_intfmoduleVariant=structtypeast=constructor_declarationtypet={ast:ast;position:int}letcreate_listlist=List.mapilist~f:(funpositionast->letloc=ast.pcd_locinmatchast.pcd_reswith|Some_->unsupported~loc"GADT"|None->{ast;position});;letsaltt=Somet.positionletlocationt=t.ast.pcd_locletweight_attribute=Attribute.declare"quickcheck.weight"Attribute.Context.constructor_declarationAst_pattern.(pstr(pstr_eval__nil^::nil))(funx->x);;letdo_not_generate_attribute=Attribute.declare"quickcheck.do_not_generate"Attribute.Context.constructor_declarationAst_pattern.(pstrnil)();;letweightt=matchAttribute.getdo_not_generate_attributet.astwith|Some()->None|None->Some(matchAttribute.getweight_attributet.astwith|Someexpr->expr|None->efloat~loc:{(locationt)withloc_ghost=true}"1.");;letcore_type_listt=matcht.ast.pcd_argswith|Pcstr_tuplelist->list|Pcstr_recordlabel_decl_list->List.maplabel_decl_list~f:(funlabel_decl->label_decl.pld_type);;letpatternt~locpat_list=letarg=matcht.ast.pcd_argswith|Pcstr_tuple_->(matchpat_listwith|[]->None|[pat]->Somepat|_->Some(ppat_tuple~locpat_list))|Pcstr_recordlabel_decl_list->letalist=List.map2_exnlabel_decl_listpat_list~f:(funlabel_declpat->lident_loclabel_decl.pld_name,pat)inSome(ppat_record~localistClosed)inppat_construct~loc(lident_loct.ast.pcd_name)arg;;letexpressiont~loc_expr_list=letarg=matcht.ast.pcd_argswith|Pcstr_tuple_->(matchexpr_listwith|[]->None|[expr]->Someexpr|_->Some(pexp_tuple~locexpr_list))|Pcstr_recordlabel_decl_list->letalist=List.map2_exnlabel_decl_listexpr_list~f:(funlabel_declexpr->lident_loclabel_decl.pld_name,expr)inSome(pexp_record~localistNone)inpexp_construct~loc(lident_loct.ast.pcd_name)arg;;endmodulePolymorphic_variant=structtypeast=row_fieldtypet=astletcreate_list=Fn.idletsaltt=matcht.prf_descwith|Rtag(label,_,_)->Some(Ocaml_common.Btype.hash_variantlabel.txt)|Rinherit_->None;;letlocationt=t.prf_locletweight_attribute=Attribute.declare"quickcheck.weight"Attribute.Context.rtagAst_pattern.(pstr(pstr_eval__nil^::nil))(funx->x);;letdo_not_generate_attribute=Attribute.declare"quickcheck.do_not_generate"Attribute.Context.rtagAst_pattern.(pstrnil)();;letweightt=matchAttribute.getdo_not_generate_attributetwith|Some()->None|None->Some(matchAttribute.getweight_attributetwith|Someexpr->expr|None->efloat~loc:{(locationt)withloc_ghost=true}"1.");;letcore_type_listt=matcht.prf_descwith|Rtag(_,_,core_type_list)->core_type_list|Rinheritcore_type->[core_type];;letpatternt~locpat_list=matcht.prf_desc,pat_listwith|Rtag(label,true,[]),[]->ppat_variant~loclabel.txtNone|Rtag(label,false,[_]),[pat]->ppat_variant~loclabel.txt(Somepat)|Rtag(label,false,[_]),_::_::_->ppat_variant~loclabel.txt(Some(ppat_tuple~locpat_list))|Rinherit{ptyp_desc;_},[{ppat_desc;_}]->(matchptyp_descwith|Ptyp_constr(id,[])->(matchppat_descwith|Ppat_varvar->ppat_alias~loc(ppat_type~locid)var|_->internal_error~loc"cannot bind a #<type> pattern to anything other than a variable")|_->unsupported~loc"inherited polymorphic variant type that is not a type name")|Rtag(_,true,_::_),_|Rtag(_,false,([]|_::_::_)),_->unsupported~loc"intersection type"|Rtag(_,true,[]),_::_|Rtag(_,false,[_]),[]|Rinherit_,([]|_::_::_)->internal_error~loc"wrong number of arguments for variant clause";;letexpressiont~loccore_typeexpr_list=matcht.prf_desc,expr_listwith|Rtag(label,true,[]),[]->pexp_variant~loclabel.txtNone|Rtag(label,false,[_]),[expr]->pexp_variant~loclabel.txt(Someexpr)|Rtag(label,false,[_]),_::_::_->pexp_variant~loclabel.txt(Some(pexp_tuple~locexpr_list))|Rinheritinherited_type,[expr]->pexp_coerce~locexpr(Someinherited_type)core_type|Rtag(_,true,_::_),_|Rtag(_,false,([]|_::_::_)),_->unsupported~loc"intersection type"|Rtag(_,true,[]),_::_|Rtag(_,false,[_]),[]|Rinherit_,([]|_::_::_)->internal_error~loc"wrong number of arguments for variant clause";;end