123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585(* Yoann Padioleau
*
* Copyright (C) 2010 Facebook
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation, with the
* special exception on linking described in file license.txt.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the file
* license.txt for more details.
*)openCst_ml(*****************************************************************************)(* Prelude *)(*****************************************************************************)(*
* TODO: do a kmodule_name that is called by kqualifier and
* a few other places where the name in the long_name is actually
* also a module name
*)(*****************************************************************************)(* Types *)(*****************************************************************************)(* hooks *)typevisitor_in={kitem:itemvin;ktoplevel:toplevelvin;kexpr:exprvin;kpattern:patternvin;kty:tyvin;kfield_decl:field_declarationvin;kfield_expr:field_and_exprvin;kfield_pat:field_patternvin;ktype_declaration:type_declarationvin;klet_def:let_defvin;klet_binding:let_bindingvin;kqualifier:qualifiervin;kmodule_expr:module_exprvin;kparameter:parametervin;kargument:argumentvin;kinfo:tokvin;}and'avin=('a->unit)*visitor_out->'a->unitandvisitor_out=any->unitletdefault_visitor={kinfo=(fun(k,_)x->kx);kexpr=(fun(k,_)x->kx);kfield_decl=(fun(k,_)x->kx);kfield_expr=(fun(k,_)x->kx);kty=(fun(k,_)x->kx);ktype_declaration=(fun(k,_)x->kx);kitem=(fun(k,_)x->kx);klet_def=(fun(k,_)x->kx);kpattern=(fun(k,_)x->kx);klet_binding=(fun(k,_)x->kx);kqualifier=(fun(k,_)x->kx);kmodule_expr=(fun(k,_)x->kx);ktoplevel=(fun(k,_)x->kx);kparameter=(fun(k,_)x->kx);kargument=(fun(k,_)x->kx);kfield_pat=(fun(k,_)x->kx);}let(mk_visitor:visitor_in->visitor_out)=funvin->(* start of auto generation *)letrecv_infox=letkx=matchxwith{Parse_info.token=_v_pinfox;transfo=_v_transfo}->(*
let _arg = Parse_info.v_pinfo v_pinfox in
let _arg = Ocaml.v_unit v_comments in
let _arg = Parse_info.v_transformation v_transfo in
*)()invin.kinfo(k,all_functions)xandv_tokv=v_infovandv_wrap:'a.('a->unit)->'awrap->unit=fun_of_a(v1,v2)->letv1=_of_av1andv2=v_infov2in()andv_wrap1_of_a(v1,v2)=letv1=_of_av1andv2=v_infov2in()andv_wrap2_of_a(v1,v2)=letv1=_of_av1andv2=v_infov2in()andv_wrap11_of_a(v1,v2)=letv1=_of_av1andv2=v_infov2in()andv_wrap12_of_a(v1,v2)=letv1=_of_av1andv2=v_infov2in()andv_wrap13_of_a(v1,v2)=letv1=_of_av1andv2=v_infov2in()andv_wrap14_of_a(v1,v2)=letv1=_of_av1andv2=v_infov2in()andv_wrap15_of_a(v1,v2)=letv1=_of_av1andv2=v_infov2in()andv_wrap16_of_a(v1,v2)=letv1=_of_av1andv2=v_infov2in()andv_wrap17_of_a(v1,v2)=letv1=_of_av1andv2=v_infov2in()andv_wrap18_of_a(v1,v2)=letv1=_of_av1andv2=v_infov2in()andv_paren_of_a(v1,v2,v3)=letv1=v_tokv1andv2=_of_av2andv3=v_tokv3in()andv_paren1_of_a(v1,v2,v3)=letv1=v_tokv1andv2=_of_av2andv3=v_tokv3in()andv_paren2_of_a(v1,v2,v3)=letv1=v_tokv1andv2=_of_av2andv3=v_tokv3in()andv_paren11_of_a(v1,v2,v3)=letv1=v_tokv1andv2=_of_av2andv3=v_tokv3in()andv_paren12_of_a(v1,v2,v3)=letv1=v_tokv1andv2=_of_av2andv3=v_tokv3in()andv_paren13_of_a(v1,v2,v3)=letv1=v_tokv1andv2=_of_av2andv3=v_tokv3in()andv_brace_of_a(v1,v2,v3)=letv1=v_tokv1andv2=_of_av2andv3=v_tokv3in()andv_brace1_of_a(v1,v2,v3)=letv1=v_tokv1andv2=_of_av2andv3=v_tokv3in()andv_brace11_of_a(v1,v2,v3)=letv1=v_tokv1andv2=_of_av2andv3=v_tokv3in()andv_bracket:'a.('a->unit)->'abracket->unit=fun_of_a(v1,v2,v3)->letv1=v_tokv1andv2=_of_av2andv3=v_tokv3in()andv_comma_list_of_a=Ocaml.v_list(Ocaml.v_either_of_av_tok)andv_comma_list1_of_a=Ocaml.v_list(Ocaml.v_either_of_av_tok)andv_comma_list2_of_a=Ocaml.v_list(Ocaml.v_either_of_av_tok)andv_comma_list11_of_a=Ocaml.v_list(Ocaml.v_either_of_av_tok)andv_comma_list12_of_a=Ocaml.v_list(Ocaml.v_either_of_av_tok)andv_and_list_of_a=Ocaml.v_list(Ocaml.v_either_of_av_tok)andv_and_list1_of_a=Ocaml.v_list(Ocaml.v_either_of_av_tok)andv_and_list2_of_a=Ocaml.v_list(Ocaml.v_either_of_av_tok)andv_and_list13_of_a=Ocaml.v_list(Ocaml.v_either_of_av_tok)andv_pipe_list_of_a=Ocaml.v_list(Ocaml.v_either_of_av_tok)andv_pipe_list1_of_a=Ocaml.v_list(Ocaml.v_either_of_av_tok)andv_pipe_list11_of_a=Ocaml.v_list(Ocaml.v_either_of_av_tok)andv_pipe_list12_of_a=Ocaml.v_list(Ocaml.v_either_of_av_tok)andv_pipe_list13_of_a=Ocaml.v_list(Ocaml.v_either_of_av_tok)andv_semicolon_list:'a.('a->unit)->'asemicolon_list->unit=fun_of_a->Ocaml.v_list(Ocaml.v_either_of_av_tok)andv_semicolon_list1_of_a=Ocaml.v_list(Ocaml.v_either_of_av_tok)andv_semicolon_list2_of_a=Ocaml.v_list(Ocaml.v_either_of_av_tok)andv_semicolon_list11_of_a=Ocaml.v_list(Ocaml.v_either_of_av_tok)andv_semicolon_list12_of_a=Ocaml.v_list(Ocaml.v_either_of_av_tok)andv_star_list_of_a=Ocaml.v_list(Ocaml.v_either_of_av_tok)andv_star_list1_of_a=Ocaml.v_list(Ocaml.v_either_of_av_tok)andv_star_list2_of_a=Ocaml.v_list(Ocaml.v_either_of_av_tok)andv_name=function|Namev1->letv1=v_wrap1Ocaml.v_stringv1in()andv_lnamev=v_namevandv_unamev=v_namevandv_long_name(v1,v2)=letv1=v_qualifierv1andv2=v_namev2in()andv_qualifierv=letk_x=Ocaml.v_list(fun(v1,v2)->letv1=v_namev1andv2=v_tokv2in())vinvin.kqualifier(k,all_functions)vandv_tyx=letkx=matchxwith|TyNamev1->letv1=v_long_namev1in()|TyVar((v1,v2))->letv1=v_tokv1andv2=v_namev2in()|TyTuplev1->letv1=v_star_list2v_tyv1in()|TyTuple2v1->letv1=v_paren(v_star_list2v_ty)v1in()|TyFunction((v1,v2,v3))->letv1=v_tyv1andv2=v_tokv2andv3=v_tyv3in()|TyApp((v1,v2))->letv1=v_ty_argsv1andv2=v_long_namev2in()|TyTodo->()invin.kty(k,all_functions)xandv_type_declarationx=letkx=matchxwith|TyAbstract((v1,v2))->letv1=v_ty_paramsv1andv2=v_namev2in()|TyDef((v1,v2,v3,v4))->letv1=v_ty_paramsv1andv2=v_namev2andv3=v_tokv3andv4=v_type_def_kindv4in()invin.ktype_declaration(k,all_functions)xandv_type_def_kind=function|TyCorev1->letv1=v_tyv1in()|TyAlgebricv1->letv1=v_pipe_list1v_constructor_declarationv1in()|TyRecordv1->letv1=v_brace1(v_semicolon_list2v_label_declaration)v1in()andv_constructor_declaration(v1,v2)=letv1=v_namev1andv2=v_constructor_argumentsv2in()andv_constructor_arguments=function|NoConstrArg->()|Of((v1,v2))->letv1=v_tokv1andv2=v_star_list1v_tyv2in()andv_label_declarationx=letkx=matchxwith{fld_mutable=v_fld_mutable;fld_name=v_fld_name;fld_tok=v_fld_tok;fld_type=v_fld_type}->letarg=Ocaml.v_optionv_tokv_fld_mutableinletarg=v_namev_fld_nameinletarg=v_tokv_fld_tokinletarg=v_tyv_fld_typein()invin.kfield_decl(k,all_functions)xandv_ty_args=function|TyArg1v1->letv1=v_tyv1in()|TyArgMultiv1->letv1=v_paren2(v_comma_list2v_ty)v1in()andv_ty_params=function|TyNoParam->()|TyParam1v1->letv1=v_ty_parameterv1in()|TyParamMultiv1->letv1=v_paren1(v_comma_list1v_ty_parameter)v1in()andv_ty_parameter(v1,v2)=letv1=v_tokv1andv2=v_namev2in()andv_exprv=letkx=matchxwith|Cv1->letv1=v_constantv1in()|Lv1->letv1=v_long_namev1in()|Constr((v1,v2))->letv1=v_long_namev1andv2=Ocaml.v_optionv_exprv2in()|Tuplev1->letv1=v_comma_list12v_exprv1in()|Listv1->letv1=v_bracket(v_semicolon_listv_expr)v1in()|ParenExprv1->letv1=v_paren12v_exprv1in()|Sequencev1->letv1=v_paren11v_seq_exprv1in()|Prefix((v1,v2))->letv1=v_wrap18Ocaml.v_stringv1andv2=v_exprv2in()|Infix((v1,v2,v3))->letv1=v_exprv1andv2=v_wrap17Ocaml.v_stringv2andv3=v_exprv3in()|FunCallSimple((v1,v2))->letv1=v_long_namev1andv2=Ocaml.v_listv_argumentv2in()|FunCall((v1,v2))->letv1=v_exprv1andv2=Ocaml.v_listv_argumentv2in()|RefAccess((v1,v2))->letv1=v_tokv1andv2=v_exprv2in()|RefAssign((v1,v2,v3))->letv1=v_exprv1andv2=v_tokv2andv3=v_exprv3in()|FieldAccess((v1,v2,v3))->letv1=v_exprv1andv2=v_tokv2andv3=v_long_namev3in()|FieldAssign((v1,v2,v3,v4,v5))->letv1=v_exprv1andv2=v_tokv2andv3=v_long_namev3andv4=v_tokv4andv5=v_exprv5in()|Recordv1->letv1=v_brace11v_record_exprv1in()|ObjAccess((v1,v2,v3))->letv1=v_exprv1andv2=v_tokv2andv3=v_namev3in()|New((v1,v2))->letv1=v_tokv1andv2=v_long_namev2in()|LetIn((v1,v2,v3,v4,v5))->letv1=v_tokv1andv2=v_rec_optv2andv3=v_and_list13v_let_bindingv3andv4=v_tokv4andv5=v_seq_exprv5in()|Fun((v1,v2,v3))->letv1=v_tokv1andv2=Ocaml.v_listv_parameterv2andv3=v_match_actionv3in()|Function((v1,v2))->letv1=v_tokv1andv2=v_pipe_list13v_match_casev2in()|If((v1,v2,v3,v4,v5))->letv1=v_tokv1andv2=v_seq_exprv2andv3=v_tokv3andv4=v_exprv4andv5=Ocaml.v_option(fun(v1,v2)->letv1=v_tokv1andv2=v_exprv2in())v5in()|Match((v1,v2,v3,v4))->letv1=v_tokv1andv2=v_seq_exprv2andv3=v_tokv3andv4=v_pipe_list12v_match_casev4in()|Try((v1,v2,v3,v4))->letv1=v_tokv1andv2=v_seq_exprv2andv3=v_tokv3andv4=v_pipe_list11v_match_casev4in()|While((v1,v2,v3,v4,v5))->letv1=v_tokv1andv2=v_seq_exprv2andv3=v_tokv3andv4=v_seq_exprv4andv5=v_tokv5in()|For((v1,v2,v3,v4,v5,v6,v7,v8,v9))->letv1=v_tokv1andv2=v_namev2andv3=v_tokv3andv4=v_seq_exprv4andv5=v_for_directionv5andv6=v_seq_exprv6andv7=v_tokv7andv8=v_seq_exprv8andv9=v_tokv9in()|ExprTodo->()invin.kexpr(k,all_functions)vandv_constant=function|Intv1->letv1=v_wrap16Ocaml.v_stringv1in()|Floatv1->letv1=v_wrap15Ocaml.v_stringv1in()|Charv1->letv1=v_wrap14Ocaml.v_stringv1in()|Stringv1->letv1=v_wrap13Ocaml.v_stringv1in()andv_record_expr=function|RecordNormalv1->letv1=v_semicolon_list12v_field_and_exprv1in()|RecordWith((v1,v2,v3))->letv1=v_exprv1andv2=v_tokv2andv3=v_semicolon_list11v_field_and_exprv3in()andv_field_and_exprv=letkx=matchxwith|FieldExpr((v1,v2,v3))->letv1=v_long_namev1andv2=v_tokv2andv3=v_exprv3in()|FieldImplicitExprv1->letv1=v_long_namev1in()invin.kfield_expr(k,all_functions)vandv_argumentv=letkx=matchxwith|ArgExprv1->letv1=v_exprv1in()|ArgLabelTilde((v1,v2))->letv1=v_namev1andv2=v_exprv2in()|ArgImplicitTildeExpr((v1,v2))->letv1=v_tokv1andv2=v_namev2in()|ArgImplicitQuestionExpr((v1,v2))->letv1=v_tokv1andv2=v_namev2in()|ArgLabelQuestion((v1,v2))->letv1=v_namev1andv2=v_exprv2in()invin.kargument(k,all_functions)vandv_match_action=function|Action((v1,v2))->letv1=v_tokv1andv2=v_seq_exprv2in()|WhenAction((v1,v2,v3,v4))->letv1=v_tokv1andv2=v_seq_exprv2andv3=v_tokv3andv4=v_seq_exprv4in()andv_match_case(v1,v2)=letv1=v_patternv1andv2=v_match_actionv2in()andv_for_direction=function|Tov1->letv1=v_tokv1in()|Downtov1->letv1=v_tokv1in()andv_seq_exprv=v_semicolon_list1v_exprvandv_patternx=letkx=matchxwith|PatVarv1->letv1=v_namev1in()|PatConstantv1->letv1=v_signed_constantv1in()|PatConstr((v1,v2))->letv1=v_long_namev1andv2=Ocaml.v_optionv_patternv2in()|PatConsInfix((v1,v2,v3))->letv1=v_patternv1andv2=v_tokv2andv3=v_patternv3in()|PatTuplev1->letv1=v_comma_list11v_patternv1in()|PatListv1->letv1=v_bracket(v_semicolon_listv_pattern)v1in()|PatUnderscorev1->letv1=v_tokv1in()|PatRecordv1->letv1=v_brace(v_semicolon_listv_field_pattern)v1in()|PatAs((v1,v2,v3))->letv1=v_patternv1andv2=v_tokv2andv3=v_namev3in()|PatDisj((v1,v2,v3))->letv1=v_patternv1andv2=v_tokv2andv3=v_patternv3in()|PatTyped((v1,v2,v3,v4,v5))->letv1=v_tokv1andv2=v_patternv2andv3=v_tokv3andv4=v_tyv4andv5=v_tokv5in()|ParenPatv1->letv1=v_paren13v_patternv1in()|PatTodo->()invin.kpattern(k,all_functions)xandv_simple_patternv=Ocaml.v_unitvandv_labeled_simple_patternv=v_parametervandv_parameterx=letkx=matchxwith|ParamPatv1->letv1=v_patternv1in()|ParamTodo->()invin.kparameter(k,all_functions)xandv_field_patternx=letkx=matchxwith|PatField((v1,v2,v3))->letv1=v_long_namev1andv2=v_tokv2andv3=v_patternv3in()|PatImplicitFieldv1->letv1=v_long_namev1in()invin.kfield_pat(k,all_functions)xandv_signed_constant=function|C2v1->letv1=v_constantv1in()|CMinus((v1,v2))->letv1=v_tokv1andv2=v_constantv2in()|CPlus((v1,v2))->letv1=v_tokv1andv2=v_constantv2in()andv_let_bindingx=letkx=matchxwith|LetClassicv1->letv1=v_let_defv1in()|LetPattern((v1,v2,v3))->letv1=v_patternv1andv2=v_tokv2andv3=v_seq_exprv3in()invin.klet_binding(k,all_functions)xandv_let_defx=letkx=matchxwith{l_name=v_l_name;l_params=v_l_args;l_tok=v_l_tok;l_body=v_l_body}->letarg=v_namev_l_nameinletarg=Ocaml.v_listv_labeled_simple_patternv_l_argsinletarg=v_tokv_l_tokinletarg=v_seq_exprv_l_bodyin()invin.klet_def(k,all_functions)xandv_function_defv=Ocaml.v_unitvandv_module_typev=Ocaml.v_unitvandv_module_exprv=letkv=matchvwith|ModuleNamev1->letv1=v_long_namev1in()|ModuleStruct(v1,v2,v3)->letv1=v_tokv1inletv2=Ocaml.v_listv_itemv2inletv3=v_tokv3in()|ModuleTodo->()invin.kmodule_expr(k,all_functions)vandv_itemx=letkx=matchxwith|Type((v1,v2))->letv1=v_tokv1andv2=v_and_list2v_type_declarationv2in()|Exception((v1,v2,v3))->letv1=v_tokv1andv2=v_namev2andv3=v_constructor_argumentsv3in()|External((v1,v2,v3,v4,v5,v6))->letv1=v_tokv1andv2=v_namev2andv3=v_tokv3andv4=v_tyv4andv5=v_tokv5andv6=Ocaml.v_list(v_wrap2Ocaml.v_string)v6in()|Open((v1,v2))->letv1=v_tokv1andv2=v_long_namev2in()|Val((v1,v2,v3,v4))->letv1=v_tokv1andv2=v_namev2andv3=v_tokv3andv4=v_tyv4in()|Let((v1,v2,v3))->letv1=v_tokv1andv2=v_rec_optv2andv3=v_and_list1v_let_bindingv3in()|Module((v1,v2,v3,v4))->letv1=v_tokv1andv2=v_unamev2andv3=v_tokv3andv4=v_module_exprv4in()|ItemTodov->v_infovinvin.kitem(k,all_functions)xandv_sig_itemv=v_itemvandv_struct_itemv=v_itemvandv_rec_optv=Ocaml.v_optionv_tokvandv_toplevelx=letk=function|TopItemv1->letv1=v_itemv1in()|ScScv1->letv1=v_infov1in()|TopSeqExprv1->letv1=v_seq_exprv1in()|TopDirectivev1->letv1=v_infov1in()invin.ktoplevel(k,all_functions)xandv_programv=Ocaml.v_listv_toplevelvandv_any=function|Tyv1->letv1=v_tyv1in()|Exprv1->letv1=v_exprv1in()|Patternv1->letv1=v_patternv1in()|Itemv1->letv1=v_itemv1in()|Toplevelv1->letv1=v_toplevelv1in()|Programv1->letv1=v_programv1in()|TypeDeclarationv1->letv1=v_type_declarationv1in()|TypeDefKindv1->letv1=v_type_def_kindv1in()|MatchCasev1->letv1=v_match_casev1in()|FieldDeclarationv1->letv1=v_label_declarationv1in()|LetBindingv1->letv1=v_let_bindingv1in()|Constantv1->letv1=v_constantv1in()|Argumentv1->letv1=v_argumentv1in()|Bodyv1->letv1=v_seq_exprv1in()|Infov1->letv1=v_infov1in()|InfoListv1->letv1=Ocaml.v_listv_infov1in()andall_functionsx=v_anyxinv_any(*****************************************************************************)(* Helpers *)(*****************************************************************************)(*
let do_visit_with_ref mk_hooks = fun any ->
let res = ref [] in
let hooks = mk_hooks res in
let vout = mk_visitor hooks in
vout any;
List.rev !res
*)