123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229(* Yoann Padioleau
*
* Copyright (C) 2014 Facebook
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License (GPL)
* version 2 as published by the Free Software Foundation.
*
* This program 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.
*)openOcamlopenAst_c(*****************************************************************************)(* Prelude *)(*****************************************************************************)(*****************************************************************************)(* Types *)(*****************************************************************************)(* hooks *)typevisitor_in={kexpr:Ast_c.exprvin;kinfo:Cst_cpp.tokvin;}andvisitor_out=any->unitand'avin=('a->unit)*visitor_out->'a->unitmoduleAst_cpp=structletv_assignOp_=()letv_fixOp_=()letv_unaryOp_=()letv_binaryOp_=()endletdefault_visitor={kinfo=(fun(k,_)x->kx);kexpr=(fun(k,_)x->kx);}let(mk_visitor:visitor_in->visitor_out)=funvin->letrecv_infox=letk_=()invin.kinfo(k,all_functions)xandv_wrap:'a.('a->unit)->'awrap->unit=fun_of_a(v1,v2)->letv1=_of_av1andv2=v_infov2in()andv_namev=v_wrapv_stringvandv_type_=function|TBasev1->letv1=v_namev1in()|TPointerv1->letv1=v_type_v1in()|TArray((v1,v2))->letv1=v_optionv_const_exprv1andv2=v_type_v2in()|TFunctionv1->letv1=v_function_typev1in()|TStructName((v1,v2))->letv1=v_struct_kindv1andv2=v_namev2in()|TEnumNamev1->letv1=v_namev1in()|TTypeNamev1->letv1=v_namev1in()andv_function_type(v1,v2)=letv1=v_type_v1andv2=v_listv_parameterv2in()andv_parameter{p_type=v_p_type;p_name=v_p_name}=letarg=v_type_v_p_typeinletarg=v_optionv_namev_p_namein()andv_struct_kind=function|Struct->()|Union->()andv_const_exprv=v_exprvandv_exprx=letkx=matchxwith|Intv1->letv1=v_wrapv_stringv1in()|Floatv1->letv1=v_wrapv_stringv1in()|Stringv1->letv1=v_wrapv_stringv1in()|Charv1->letv1=v_wrapv_stringv1in()|Idv1->letv1=v_namev1in()|Ellipsesv1->letv1=v_infov1in()|Call((v1,v2))->letv1=v_exprv1andv2=v_listv_argumentv2in()|Assign((v1,v2,v3))->letv1=v_wrapAst_cpp.v_assignOpv1andv2=v_exprv2andv3=v_exprv3in()|ArrayAccess((v1,v2))->letv1=v_exprv1andv2=v_exprv2in()|RecordPtAccess((v1,v2))->letv1=v_exprv1andv2=v_namev2in()|Cast((v1,v2))->letv1=v_type_v1andv2=v_exprv2in()|Postfix((v1,v2))->letv1=v_exprv1andv2=v_wrapAst_cpp.v_fixOpv2in()|Infix((v1,v2))->letv1=v_exprv1andv2=v_wrapAst_cpp.v_fixOpv2in()|Unary((v1,v2))->letv1=v_exprv1andv2=v_wrapAst_cpp.v_unaryOpv2in()|Binary((v1,v2,v3))->letv1=v_exprv1andv2=v_wrapAst_cpp.v_binaryOpv2andv3=v_exprv3in()|CondExpr((v1,v2,v3))->letv1=v_exprv1andv2=v_exprv2andv3=v_exprv3in()|Sequence((v1,v2))->letv1=v_exprv1andv2=v_exprv2in()|SizeOfv1->letv1=Ocaml.v_eitherv_exprv_type_v1in()|ArrayInitv1->letv1=v_list(fun(v1,v2)->letv1=v_optionv_exprv1andv2=v_exprv2in())v1in()|RecordInitv1->letv1=v_list(fun(v1,v2)->letv1=v_namev1andv2=v_exprv2in())v1in()|GccConstructor((v1,v2))->letv1=v_type_v1andv2=v_exprv2in()invin.kexpr(k,all_functions)xandv_argumentv=v_exprvandv_stmt=function|ExprStv1->letv1=v_exprv1in()|Blockv1->letv1=v_listv_stmtv1in()|If((v1,v2,v3))->letv1=v_exprv1andv2=v_stmtv2andv3=v_stmtv3in()|Switch((v1,v2))->letv1=v_exprv1andv2=v_listv_casev2in()|While((v1,v2))->letv1=v_exprv1andv2=v_stmtv2in()|DoWhile((v1,v2))->letv1=v_stmtv1andv2=v_exprv2in()|For((v1,v2,v3,v4))->letv1=v_optionv_exprv1andv2=v_optionv_exprv2andv3=v_optionv_exprv3andv4=v_stmtv4in()|Returnv1->letv1=v_optionv_exprv1in()|Continue->()|Break->()|Label((v1,v2))->letv1=v_namev1andv2=v_stmtv2in()|Gotov1->letv1=v_namev1in()|Varsv1->letv1=v_listv_var_declv1in()|Asmv1->letv1=v_listv_exprv1in()andv_case=function|Case((v1,v2))->letv1=v_exprv1andv2=v_listv_stmtv2in()|Defaultv1->letv1=v_listv_stmtv1in()andv_var_decl{v_name=v_v_name;v_type=v_v_type;v_storage=v_v_storage;v_init=v_v_init}=letarg=v_namev_v_nameinletarg=v_type_v_v_typeinletarg=v_storagev_v_storageinletarg=v_optionv_initialiserv_v_initin()andv_initialiserv=v_exprvandv_storage=function|Extern->()|Static->()|DefaultStorage->()andv_struct_def{s_name=v_s_name;s_kind=v_s_kind;s_flds=v_s_flds}=letarg=v_namev_s_nameinletarg=v_struct_kindv_s_kindinletarg=v_listv_field_defv_s_fldsin()andv_field_def{fld_name=v_fld_name;fld_type=v_fld_type}=letarg=v_optionv_namev_fld_nameinletarg=v_type_v_fld_typein()andv_func_def{f_name=v_f_name;f_type=v_f_type;f_body=v_f_body;f_static=v_f_static}=letarg=v_namev_f_nameinletarg=v_function_typev_f_typeinletarg=v_listv_stmtv_f_bodyinletarg=v_boolv_f_staticin()andv_define_body=function|CppExprv1->letv1=v_exprv1in()|CppStmtv1->letv1=v_stmtv1in()andv_toplevel=function|Includev1->letv1=v_wrapv_stringv1in()|Define((v1,v2))->letv1=v_namev1andv2=v_define_bodyv2in()|Macro((v1,v2,v3))->letv1=v_namev1andv2=v_listv_namev2andv3=v_define_bodyv3in()|StructDefv1->letv1=v_struct_defv1in()|TypeDefv1->letv1=v_type_defv1in()|EnumDefv1->letv1=v_enum_defv1in()|FuncDefv1->letv1=v_func_defv1in()|Globalv1->letv1=v_var_declv1in()|Prototypev1->letv1=v_func_defv1in()andv_type_def(v1,v2)=letv1=v_namev1andv2=v_type_v2in()andv_enum_def(v1,v2)=letv1=v_namev1andv2=v_list(fun(v1,v2)->letv1=v_namev1andv2=v_optionv_exprv2in())v2in()andv_any=function|Exprv1->letv1=v_exprv1in()|Stmtv1->letv1=v_stmtv1in()|Stmtsv1->letv1=v_listv_stmtv1in()|Typev1->letv1=v_type_v1in()|Toplevelv1->letv1=v_toplevelv1in()|Programv1->letv1=v_programv1in()andv_programv=v_listv_toplevelvandall_functionsx=v_anyxinv_any