Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file attributes.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243openPpxlibincludeAttributeopenRuntimeopenTymoduleState_monad=structtype('node,'state)t='node->'state->'node*'statemoduleSyntax=structlet(let*)xfctstate=letct,state=xctstateinf()ctstateletreturnctstate=(ct,state)endendletget_attributeattributenoderuntime=matchAttribute.consume_resattributenodewith|Error_->(node,runtime)|Ok (Some(ct,attribute))->(ct,attributeruntime)|OkNone->(node,runtime)letupdate:('node,'state->'state)Attribute.tlist->('node,'state)State_monad.t=funattributes->letopenState_monad.Syntaxinletbasenoderuntime=(node,runtime)inList.fold_left(funaccattr->let*()=accinlet*()=get_attributeattrinreturn)baseattributesmoduleGeneric:sig(* This module declares a set of attributes that can be included at any context. Any of those attributes can modify the runtime environment. *)valattributes:'nodeContext.t->('node,Runtime.t->Runtime.t)Attribute.tlistend=structletmincontext=Attribute.declare"gen.min"contextAst_pattern.(single_expr_payload(eint__))(funminruntime->{runtimewithlimits={runtime.limitswithmin=Somemin}})letmaxcontext=Attribute.declare"gen.max"contextAst_pattern.(single_expr_payload(eint__))(funmaxruntime->{runtimewithlimits={runtime.limitswithmax=Somemax}})letint_mincontext=Attribute.declare"gen.int.min"contextAst_pattern.(single_expr_payload(eint__))(funminruntime->{runtimewithlimits={runtime.limitswithranged_min=Ranged_dmap.addIntminruntime.limits.ranged_min}})letint_maxcontext=Attribute.declare"gen.int.max"contextAst_pattern.(single_expr_payload(eint__))(funmaxruntime->{runtimewithlimits={runtime.limitswithranged_max=Ranged_dmap.addIntmaxruntime.limits.ranged_max}})letint32_mincontext=Attribute.declare"gen.int32.min"contextAst_pattern.(single_expr_payload(eint32__))(funminruntime->{runtimewithlimits={runtime.limitswithranged_min=Ranged_dmap.addInt32minruntime.limits.ranged_min}})letint32_maxcontext=Attribute.declare"gen.int32.max"contextAst_pattern.(single_expr_payload(eint32__))(funmaxruntime->{runtimewithlimits={runtime.limitswithranged_max=Ranged_dmap.addInt32maxruntime.limits.ranged_max}})letint64_mincontext=Attribute.declare"gen.int64.min"contextAst_pattern.(single_expr_payload(eint64__))(funminruntime->{runtimewithlimits={runtime.limitswithranged_min=Ranged_dmap.addInt64minruntime.limits.ranged_min}})letint64_maxcontext=Attribute.declare"gen.int64.max"contextAst_pattern.(single_expr_payload(eint64__))(funmaxruntime->{runtimewithlimits={runtime.limitswithranged_max=Ranged_dmap.addInt64maxruntime.limits.ranged_max}})letsize_mincontext=Attribute.declare"gen.size.min"contextAst_pattern.(single_expr_payload(eint__))(funsize_minruntime->{runtimewithlimits={runtime.limitswithsize_min=Some(Int.max0size_min)}})letsize_maxcontext=Attribute.declare"gen.size.max"contextAst_pattern.(single_expr_payload(eint__))(funsize_maxruntime->{runtimewithlimits={runtime.limitswithsize_max=Somesize_max}})letstring_size_mincontext=Attribute.declare"gen.string.size.min"contextAst_pattern.(single_expr_payload(eint__))(funsize_minruntime->{runtimewithlimits={runtime.limitswithsized_min=Sized_map.add(EString)(Int.max0size_min)runtime.limits.sized_min}})letstring_size_maxcontext=Attribute.declare"gen.string.size.max"contextAst_pattern.(single_expr_payload(eint__))(funsize_maxruntime->{runtimewithlimits={runtime.limitswithsized_max=Sized_map.add(EString)(Int.max0size_max)runtime.limits.sized_max}})letoverrides=[("unit",EUnit);("bool",EBool);("char",EChar);("int",E(RangedInt));("int32",E(RangedInt32));("int64",E(RangedInt64));("string",E(SizedString));("bytes",E(SizedBytes));("list",E(SizedList));("array",E(SizedArray));("seq",E(SizedSeq));("option",EOption);("any",EAny)]letgen_overridecontext(name,ty)=Attribute.declare("gen."^name)contextAst_pattern.(single_expr_payload__)(fungenruntime->{runtimewithoverride=Ty.Map.addtygenruntime.override})letgen_overridescontext=overrides|>List.map(gen_overridecontext)letgencontext=Attribute.declare"gen.gen"contextAst_pattern.(single_expr_payload__)(fungenruntime->{runtimewithgen=Somegen})letattributescontext=[mincontext;maxcontext;int_mincontext;int_maxcontext;int32_mincontext;int32_maxcontext;int64_mincontext;int64_maxcontext;size_mincontext;size_maxcontext;string_size_mincontext;string_size_maxcontext;gencontext]@gen_overridescontextendmoduleType_declaration:sigvalupdate:(type_declaration,Runtime.t)State_monad.tend=structletattributes=Generic.attributesAttribute.Context.type_declaration(* This one can be used for variants only.*)letshrinker=Attribute.declare"gen.shrinker"Attribute.Context.type_declarationAst_pattern.(single_expr_payload__)(funshrinkerruntime->{runtimewithshrinker=Someshrinker})letupdate=update(shrinker::attributes)endmoduleLabel_declaration:sigvalupdate:(label_declaration,Runtime.t)State_monad.tend=structletattributes=Generic.attributesAttribute.Context.label_declarationletupdate=updateattributesendmoduleConstructor_declaration:sigvalupdate:(constructor_declaration,Runtime.t)State_monad.tend=structletattributes=Generic.attributesAttribute.Context.constructor_declarationletweight=Attribute.declare"gen.weight"Attribute.Context.constructor_declarationAst_pattern.(single_expr_payload(eint__))(funweightruntime->{runtimewithweight=Someweight})letupdate=update(weight::attributes)endmoduleCore_type:sigvalupdate:(core_type,Runtime.t)State_monad.tend=structletattributes=Generic.attributesAttribute.Context.core_typeletshrinker=Attribute.declare"gen.shrinker"Attribute.Context.core_typeAst_pattern.(single_expr_payload__)(funshrinkerruntime->{runtimewithshrinker=Someshrinker})letupdate=update(shrinker::attributes)end