Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file ppx_generator_expander.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174open!Importletarrow~generator_of_core_type~observer_of_core_type~loc~arg_label~input_type~output_type=letinput_observer=matcharg_labelwith|Nolabel|Labelled_->observer_of_core_typeinput_type|Optional_->[%exprPpx_quickcheck_runtime.Base_quickcheck.Observer.option[%eobserver_of_core_typeinput_type]]inletoutput_generator=generator_of_core_typeoutput_typeinletunlabelled=[%exprPpx_quickcheck_runtime.Base_quickcheck.Generator.fn[%einput_observer][%eoutput_generator]]inmatcharg_labelwith|Nolabel->unlabelled|Labelled_|Optional_->[%exprPpx_quickcheck_runtime.Base_quickcheck.Generator.map~f:[%efn_map_label~loc~from:Nolabel~to_:arg_label][%eunlabelled]];;letcompound_generator~loc~make_compound_exprgenerator_list=letloc={locwithloc_ghost=true}inletsize_pat,size_expr=gensym"size"locinletrandom_pat,random_expr=gensym"random"locin[%exprPpx_quickcheck_runtime.Base_quickcheck.Generator.create(fun~size:[%psize_pat]~random:[%prandom_pat]->[%emake_compound_expr~loc(List.mapgenerator_list~f:(fungenerator->letloc={generator.pexp_locwithloc_ghost=true}in[%exprPpx_quickcheck_runtime.Base_quickcheck.Generator.generate[%egenerator]~size:[%esize_expr]~random:[%erandom_expr]]))])];;letcompound(typefield)~generator_of_core_type~loc~fields(moduleField:Field_syntax.Swithtypeast=field)=letfields=List.mapfields~f:Field.createincompound_generator~loc~make_compound_expr:(Field.expressionfields)(List.mapfields~f:(funfield->generator_of_core_type(Field.core_typefield)));;letdoes_refer_toname_set=object(self)inherit[bool]Ast_traverse.foldassupermethod!core_typetyacc=matchty.ptyp_descwith|Ptyp_constr(name,args)->acc||Set.memname_set(Longident.namename.txt)||List.existsargs~f:(funarg->self#core_typeargfalse)|_->super#core_typetyaccend;;letclause_is_recursive(typeclause)~clause~rec_names(moduleClause:Clause_syntax.Swithtypet=clause)=List.exists(Clause.core_type_listclause)~f:(funty->(does_refer_torec_names)#core_typetyfalse);;letvariant(typeclause)~generator_of_core_type~loc~variant_type~clauses~rec_names(moduleClause:Clause_syntax.Swithtypeast=clause)=letclauses=Clause.create_listclausesinletmake_generatorclause=compound_generator~loc:(Clause.locationclause)~make_compound_expr:(Clause.expressionclausevariant_type)(List.map(Clause.core_type_listclause)~f:generator_of_core_type)inletmake_pairclause=Option.map(Clause.weightclause)~f:(funweight->pexp_tuple~loc:{(Clause.locationclause)withloc_ghost=true}[weight;make_generatorclause])in(* We filter out clauses with weight None now. If we don't, then we can get code in
[body] below that relies on bindings that don't get generated. *)letclauses=List.filterclauses~f:(funclause->Option.is_some(Clause.weightclause))inmatchList.partition_tfclauses~f:(funclause->clause_is_recursive~clause~rec_names(moduleClause))with|[],clauses|clauses,[]->letpairs=List.filter_mapclauses~f:make_pairin[%exprPpx_quickcheck_runtime.Base_quickcheck.Generator.weighted_union[%eelist~locpairs]]|recursive_clauses,nonrecursive_clauses->letsize_pat,size_expr=gensym"size"locinletnonrec_pat,nonrec_expr=gensym"gen"locinletrec_pat,rec_expr=gensym"gen"locinletnonrec_pats,nonrec_exprs=gensyms"pair"(List.mapnonrecursive_clauses~f:Clause.location)inletrec_pats,rec_exprs=gensyms"pair"(List.maprecursive_clauses~f:Clause.location)inletbindings=List.filter_opt(List.map2_exnnonrec_patsnonrecursive_clauses~f:(funpatclause->letloc={(Clause.locationclause)withloc_ghost=true}inOption.map(make_pairclause)~f:(funexpr->value_binding~loc~pat~expr))@List.map2_exnrec_patsrecursive_clauses~f:(funpatclause->Option.map(Clause.weightclause)~f:(funweight_expr->letloc={(Clause.locationclause)withloc_ghost=true}inletgen_expr=[%exprPpx_quickcheck_runtime.Base_quickcheck.Generator.bindPpx_quickcheck_runtime.Base_quickcheck.Generator.size~f:(fun[%psize_pat]->Ppx_quickcheck_runtime.Base_quickcheck.Generator.with_size~size:(Ppx_quickcheck_runtime.Base.Int.pred[%esize_expr])[%emake_generatorclause])]inletexpr=pexp_tuple~loc[weight_expr;gen_expr]invalue_binding~loc~pat~expr)))inletbody=[%exprlet[%pnonrec_pat]=Ppx_quickcheck_runtime.Base_quickcheck.Generator.weighted_union[%eelist~locnonrec_exprs]and[%prec_pat]=Ppx_quickcheck_runtime.Base_quickcheck.Generator.weighted_union[%eelist~loc(nonrec_exprs@rec_exprs)]inPpx_quickcheck_runtime.Base_quickcheck.Generator.bindPpx_quickcheck_runtime.Base_quickcheck.Generator.size~f:(function|0->[%enonrec_expr]|_->[%erec_expr])]inpexp_let~locNonrecursivebindingsbody;;