123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733(* Yoann Padioleau
*
* Copyright (C) 2019 Yoann Padioleau
*
* 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.
*)openCommonmoduleA=Ast_jsmoduleC=Cst_js(*****************************************************************************)(* Prelude *)(*****************************************************************************)(* Cst_js to Ast_js *)(*****************************************************************************)(* Types *)(*****************************************************************************)(* used only to tag Id to avoid repetition in the code highlighter
* less: factorize code with graph_code_js?
*)typeenv={(* I handle block scope by not using
* a ref of mutable here! Just build a new list and passed it down.
*)locals:(string*Ast_js.resolved_name(* Local or Param *))list;(* 'var' have a function scope.
* alt: lift var up in a ast_js_build.ml transforming phase
*)vars:(string,bool)Hashtbl.t;}letempty_env()={locals=[];vars=Hashtbl.create0;}exceptionTodoConstructofstring*Parse_info.info(* The string is usually "advanced es6" or "Typescript" *)exceptionUnhandledConstructofstring*Parse_info.info(*****************************************************************************)(* Helpers *)(*****************************************************************************)letoptfenvx=matchxwith|None->None|Somex->Some(fenvx)letreccomma_list=function|[]->[]|Common.Leftx::rl->x::comma_listrl|Common.Right_::rl->comma_listrlletparen(_,x,_)=xletfst3(x,_,_)=xletnoop=A.Block[]letnot_resolved()=refA.NotResolvedexceptionFoundofParse_info.infoletfirst_tok_of_itemx=lethooks={Visitor_js.default_visitorwithVisitor_js.kinfo=(fun(_k,_)i->raise(Foundi));}inbeginletvout=Visitor_js.mk_visitorhooksintryvout(C.Itemx);failwith"first_to_of_item: could not find a token";withFoundtok->tokendlets_of_nn=Ast_js.str_of_namen(*
let is_local env n =
let s = s_of_n n in
List.mem_assoc s env.locals || Hashtbl.mem env.vars s
*)(* copy-paste of Graph_code_js.add_locals mostly *)letadd_localsenvvs=letlocals=vs|>Common.map_filter(funv->lets=s_of_nv.A.v_nameinmatchv.A.v_kindwith|A.Let|A.Const->Some(s,A.Local)|A.Var->Hashtbl.replaceenv.varsstrue;None)in{envwithlocals=locals@env.locals}letadd_paramsenvps=letparams=ps|>List.map(funp->lets=s_of_np.A.p_nameins,A.Param)in{envwithlocals=params@env.locals}(*****************************************************************************)(* Entry point *)(*****************************************************************************)letrecprogramxs=letenv=empty_env()inmodule_itemsenvxsandmodule_itemsenvxs=xs|>List.map(module_itemenv)|>List.flattenandmodule_itemenv=function|C.Itx->itemenvx|>List.map(funres->matchreswith|A.VarDeclvar->A.Vvar|_->lettok=first_tok_of_itemxinA.S(tok,res))|C.Import(_,x,_)->importenvx|C.Export(tok,x)->exportenvtokxandimportenv=function|C.ImportEffect((_file,tok))->raise(UnhandledConstruct("import effect",tok))|C.ImportFrom((default_opt,names_opt),(_,path))->(matchdefault_optwith|Somen->[A.Import((A.default_entity,sndn),nameenvn,path)]|None->[])@(matchnames_optwith|None->[]|Someni->(matchniwith|C.ImportNamespace(_,_,(_name,tok))->raise(UnhandledConstruct("import namespace",tok))|C.ImportNamesxs->xs|>paren|>comma_list|>List.map(fun(n1,n2opt)->letn1=nameenvn1inletn2=matchn2optwith|None->n1|Some(_,n2)->nameenvn2inA.Import(n1,n2,path))))andexportenvtok=function|C.ExportDefaultExpr(tok,e,_)->lete=exprenveinletn=A.default_entity,tokinletv={A.v_name=n;v_kind=A.Const;v_init=e;v_resolved=not_resolved()}in[A.Vv;A.Export(n)]|C.ExportDeclx->letxs=itemenvxinxs|>List.map(function(* less: v_kind? *)|A.VarDeclv->[A.Vv;A.Export(v.A.v_name)]|_->raise(UnhandledConstruct("exporting a stmt",tok)))|>List.flatten|C.ExportDefaultDecl(tok,x)->letxs=itemenvxinxs|>List.map(function|A.VarDeclv->(* todo: what was in v.A.v_name ?*)letn=A.default_entity,tokinletv={vwithA.v_name=n}in[A.Vv;A.Export(n)]|_->raise(UnhandledConstruct("exporting a stmt",tok)))|>List.flatten|C.ExportNames(xs,_)->xs|>paren|>comma_list|>List.map(fun(n1,n2opt)->letn1=nameenvn1inmatchn2optwith|None->[A.Export(n1)]|Some(_,n2)->letn2=nameenvn2inletid=A.Id(n1,not_resolved())inletv={A.v_name=n2;v_kind=A.Const;v_init=id;v_resolved=not_resolved()}in[A.Vv;A.Exportn2])|>List.flatten|C.ReExportNamespace(_,_,_)->raise(UnhandledConstruct("reexporting namespace",tok))|C.ReExportNames(_,_,_)->raise(UnhandledConstruct("reexporting names",tok))anditemenv=function|C.Stx->stmtenvx|C.FunDeclx->letfun_=func_declenvxin(matchx.C.f_kindwith|C.F_func(_,Somex)->[A.VarDecl{A.v_name=nameenvx;v_kind=A.Const;v_init=A.Fun(fun_,None);v_resolved=not_resolved()}]|_->raise(UnhandledConstruct("weird func decl",fst3x.C.f_params)))|C.ClassDeclx->letclass_=class_declenvxin(matchx.C.c_namewith|Somex->[A.VarDecl{A.v_name=nameenvx;v_kind=A.Const;v_init=A.Classclass_;v_resolved=not_resolved()}]|None->raise(UnhandledConstruct("weird anon class decl",x.C.c_tok)))|C.InterfaceDeclx->raise(UnhandledConstruct("Typescript",x.C.i_tok))|C.ItemTodotok->raise(TodoConstruct("ItemTodo",tok))(* ------------------------------------------------------------------------- *)(* Names *)(* ------------------------------------------------------------------------- *)andname_envx=xandlabel_envx=xandproperty_nameenv=function|C.PN_Idx->A.PN(nameenvx)|C.PN_Stringx->A.PN(nameenvx)|C.PN_Numx->A.PN(nameenvx)|C.PN_Computedx->A.PN_Computed(x|>paren|>exprenv)(* ------------------------------------------------------------------------- *)(* Statement *)(* ------------------------------------------------------------------------- *)andstmtenv=function|C.VarsDecl((vkind,_),bindings,_)->bindings|>comma_list|>List.map(funx->A.VarDecl(var_bindingenvvkindx))|C.Blockx->[stmt1_item_listenv(parenx)]|C.Nop_->[]|C.ExprStmt(e,_)->lete=exprenvein(matchewith|A.String("use strict",tok)->[A.ExprStmt(A.Apply(A.IdSpecial(A.UseStrict,tok),[]))]|_->[A.ExprStmte])|C.If(_,e,then_,elseopt)->lete=e|>paren|>exprenvinletthen_=stmt1envthen_inletelse_=matchelseoptwith|None->noop|Some(_,st)->stmt1envstin[A.If(e,then_,else_)]|C.Do(_,st,_,e,_)->letst=stmt1envstinlete=e|>paren|>exprenvin[A.Do(st,e)]|C.While(_,e,st)->lete=e|>paren|>exprenvinletst=stmt1envstin[A.While(e,st)]|C.For(_,_,lhs_vars_opt,_,e2opt,_,e3opt,_,st)->lete1=matchlhs_vars_optwith|Some(C.LHS1e)->Right(exprenve)|Some(C.ForVars(((vkind,_),vbindings)))->Left(vbindings|>comma_list|>List.map(funx->(var_bindingenvvkindx)))|None->Right(A.Nop)inlete2=expr_optenve2optinlete3=expr_optenve3optinletst=stmt1envstin[A.For(A.ForClassic(e1,e2,e3),st)]|C.ForIn(_,_,lhs_var,_,e2,_,st)->lete1=matchlhs_varwith|C.LHS2e->Right(exprenve)|C.ForVar((vkind,_),binding)->Left(var_bindingenvvkindbinding)inlete2=exprenve2inletst=stmt1envstin[A.For(A.ForIn(e1,e2),st)]|C.ForOf(_,_,lhs_var,_,e2,_,st)->lete1=matchlhs_varwith|C.LHS2e->Right(exprenve)|C.ForVar((vkind,_),binding)->Left(var_bindingenvvkindbinding)inlete2=exprenve2inletst=stmt1envstin[A.For(A.ForOf(e1,e2),st)]|C.Switch(_,e,xs)->lete=e|>paren|>exprenvinletxs=xs|>paren|>List.map(case_clauseenv)in[A.Switch(e,xs)]|C.Continue(_,lopt,_)->[A.Continue(optlabelenvlopt)]|C.Break(_,lopt,_)->[A.Break(optlabelenvlopt)]|C.Return(_,eopt,_)->[A.Return(expr_optenveopt)]|C.With(tok,_e,_st)->raise(TodoConstruct("with",tok))|C.Labeled(lbl,_,st)->letlbl=labelenvlblinletst=stmt1envstin[A.Label(lbl,st)]|C.Throw(_,e,_)->lete=exprenvein[A.Throwe]|C.Try(_,st,catchopt,finally_opt)->letst=stmt1envstinletcatchopt=opt(funenv(_,arg,st)->letarg=nameenv(parenarg)inletst=stmt1envstin(arg,st))envcatchoptinletfinally_opt=opt(funenv(_,st)->stmt1envst)envfinally_optin[A.Try(st,catchopt,finally_opt)]andstmt1envst=matchstmtenvstwith|[]->A.Block[]|[x]->x|xs->A.Blockxsandcase_clauseenv=function|C.Default(_,_,xs)->A.Default(stmt1_item_listenvxs)|C.Case(_,e,_,xs)->lete=exprenveinA.Case(e,stmt1_item_listenvxs)andstmt1_item_listenvitems=letstmt1xs=matchxswith|[]->A.Block[]|[x]->x|xs->A.Blockxsinletrecauxaccenv=function|[]->List.revacc|>List.flatten|>stmt1|x::xs->letys=itemenvxinletenv=letlocals=ys|>Common.map_filter(funx->matchxwith|A.VarDeclv->Somev|_->None)inadd_localsenvlocalsinaux(ys::acc)envxsinaux[]envitems(* ------------------------------------------------------------------------- *)(* Expression *)(* ------------------------------------------------------------------------- *)andexprenv=function|C.Lx->literalenvx|C.V(s,tok)->letresolved=try(List.assocsenv.locals)withNot_found->ifHashtbl.memenv.varssthenA.LocalelseA.NotResolvedin(matchresolvedwith|A.Local|A.Param->A.Id((s,tok),refresolved)|A.NotResolved|A.Global_->(matchswith|"eval"->A.IdSpecial(A.Eval,tok)|"undefined"->A.IdSpecial(A.Undefined,tok)|"require"->A.IdSpecial(A.Require,tok)|"exports"->A.IdSpecial(A.Exports,tok)|"module"->A.IdSpecial(A.Module,tok)|_->A.Id((s,tok),refresolved)))|C.Thistok->A.IdSpecial(A.This,tok)|C.Supertok->A.IdSpecial(A.Super,tok)|C.U((op,tok),e)->letspecial=unopenvopinlete=exprenveinA.Apply(A.IdSpecial(special,tok),[e])|C.B(e1,op,e2)->lete1=exprenve1inlete2=exprenve2inbinopenvope1e2|C.Period(e,_,n)->lete=exprenveinA.ObjAccess(e,A.PN(nameenvn))|C.Bracket(e,e2)->(* let e = expr env e in
A.ObjAccess (e, A.PN_Computed (expr env (paren e2)))
*)lete=exprenveinlete2=exprenv(parene2)inA.ArrAccess(e,e2)|C.Objectxs->A.Obj(xs|>paren|>comma_list|>List.map(propertyenv))|C.Array(tok,xs,_)->(* A.Obj (array_obj env 0 tok xs) *)A.Arr(array_arrenvtokxs)|C.Apply(e,es)->lete=exprenveinletes=List.map(exprenv)(es|>paren|>comma_list)inA.Apply(e,es)|C.Conditional(e1,_,e2,_,e3)->lete1=exprenve1inlete2=exprenve2inlete3=exprenve3inA.Conditional(e1,e2,e3)|C.Assign(e1,(op,tok),e2)->lete1=exprenve1inlete2=exprenve2in(matchopwith|C.A_eq->A.Assign(e1,e2)(* less: should use intermediate? can unsugar like this? *)|C.A_add->A.Assign(e1,A.Apply(A.IdSpecial(A.Plus,tok),[e1;e2]))|C.A_sub->A.Assign(e1,A.Apply(A.IdSpecial(A.Minus,tok),[e1;e2]))|C.A_mul->A.Assign(e1,A.Apply(A.IdSpecial(A.Mul,tok),[e1;e2]))|C.A_div->A.Assign(e1,A.Apply(A.IdSpecial(A.Div,tok),[e1;e2]))|C.A_mod->A.Assign(e1,A.Apply(A.IdSpecial(A.Mod,tok),[e1;e2]))|C.A_lsl->A.Assign(e1,A.Apply(A.IdSpecial(A.Lsl,tok),[e1;e2]))|C.A_lsr->A.Assign(e1,A.Apply(A.IdSpecial(A.Lsr,tok),[e1;e2]))|C.A_asr->A.Assign(e1,A.Apply(A.IdSpecial(A.Asr,tok),[e1;e2]))|C.A_and->A.Assign(e1,A.Apply(A.IdSpecial(A.And,tok),[e1;e2]))|C.A_or->A.Assign(e1,A.Apply(A.IdSpecial(A.Or,tok),[e1;e2]))|C.A_xor->A.Assign(e1,A.Apply(A.IdSpecial(A.Xor,tok),[e1;e2])))|C.Seq(e1,tok,e2)->lete1=exprenve1inlete2=exprenve2inA.Apply(A.IdSpecial(A.Seq,tok),[e1;e2])|C.Functionx->letfun_=func_declenvxin(matchx.C.f_kindwith|C.F_func(_,None)->A.Fun(fun_,None)|C.F_func(_,Somen)->A.Fun(fun_,Some(nameenvn))|_->raise(UnhandledConstruct("weird lambda",fst3x.C.f_params)))|C.Classx->letclass_=class_declenvxin(matchx.C.c_namewith|None->A.Classclass_|Some_->raise(UnhandledConstruct("weird named class expr",x.C.c_tok)))|C.Arrowx->A.Fun(arrow_funcenvx,None)|C.Yield(tok,star,eopt)->letspecial=ifstar=NonethenA.YieldelseA.YieldStarinlete=expr_optenveoptinA.Apply(A.IdSpecial(special,tok),[e])|C.Await(tok,e)->lete=exprenveinA.Apply(A.IdSpecial(A.Await,tok),[e])|C.NewTarget(tok,_,_)->A.Apply(A.IdSpecial(A.NewTarget,tok),[])|C.Encaps(name_opt,tok,xs,_)->letspecial=A.Encapsname_optinletxs=List.map(encapsenv)xsinA.Apply(A.IdSpecial(special,tok),xs)|C.XhpHtmlx->lettok=matchxwith|C.Xhp((_,tok),_,_,_,_)->tok|C.XhpSingleton((_,tok),_,_)->tokinraise(UnhandledConstruct("xhp",tok))|C.Parenx->exprenv(parenx)andexpr_optenv=function|None->A.Nop|Somee->exprenveandliteral_env=function|C.Boolx->A.Boolx|C.Numx->A.Numx|C.Stringx->A.Stringx|C.Regexpx->A.Regexpx|C.Nulltok->A.IdSpecial(A.Null,tok)andunop_env=function|C.U_new->A.New|C.U_delete->A.Delete|C.U_typeof->A.Typeof|C.U_void->A.Void|C.U_pre_increment->A.Incr(true)|C.U_pre_decrement->A.Decr(true)|C.U_post_increment->A.Incr(false)|C.U_post_decrement->A.Decr(false)|C.U_plus->A.Plus|C.U_minus->A.Minus|C.U_not->A.Not|C.U_bitnot->A.BitNot|C.U_spread->A.Spreadandbinop_env(op,tok)e1e2=letres=matchopwith|C.B_instanceof->LeftA.Instanceof|C.B_in->LeftA.In|C.B_add->LeftA.Plus|C.B_sub->LeftA.Minus|C.B_mul->LeftA.Mul|C.B_div->LeftA.Div|C.B_mod->LeftA.Mod|C.B_expo->LeftA.Expo|C.B_lt->LeftA.Lower|C.B_gt->LeftA.Greater|C.B_lsr->LeftA.Lsr|C.B_asr->LeftA.Asr|C.B_lsl->LeftA.Lsl|C.B_bitand->LeftA.BitAnd|C.B_bitor->LeftA.BitOr|C.B_bitxor->LeftA.BitXor|C.B_and->LeftA.And|C.B_or->LeftA.Or|C.B_equal->LeftA.Equal|C.B_physequal->LeftA.PhysEqual(* less: e1 and e2 can have side effect, need intermediate var *)|C.B_le->Right(A.Apply(A.IdSpecial(A.Or,tok),[A.Apply(A.IdSpecial(A.Lower,tok),[e1;e2]);A.Apply(A.IdSpecial(A.Equal,tok),[e1;e2]);]))|C.B_ge->Right(A.Apply(A.IdSpecial(A.Or,tok),[A.Apply(A.IdSpecial(A.Greater,tok),[e1;e2]);A.Apply(A.IdSpecial(A.Equal,tok),[e1;e2]);]))|C.B_notequal->Right(A.Apply(A.IdSpecial(A.Not,tok),[A.Apply(A.IdSpecial(A.Equal,tok),[e1;e2]);]))|C.B_physnotequal->Right(A.Apply(A.IdSpecial(A.Not,tok),[A.Apply(A.IdSpecial(A.PhysEqual,tok),[e1;e2]);]))inmatchreswith|Leftspecial->A.Apply(A.IdSpecial(special,tok),[e1;e2])|Rightx->xandencapsenv=function|C.EncapsStringx->A.Stringx|C.EncapsExpr(_,e,_)->exprenve(* ------------------------------------------------------------------------- *)(* Entities *)(* ------------------------------------------------------------------------- *)andvar_bindingenvvkind=function|C.VarClassicx->variable_declarationenvvkindx|C.VarPattern_->raiseTodoandvariable_declarationenvvkindx=letn=nameenvx.C.v_nameinletinit=matchx.C.v_initwith(* less Undefined? *)|None->A.Nop|Some(_,e)->exprenveinletvkind=var_kindenvvkindin{A.v_name=n;v_init=init;v_kind=vkind;v_resolved=not_resolved()}andvar_kind_env=function|C.Var->A.Var|C.Const->A.Const|C.Let->A.Letandfunc_declenvx=letprops=func_propsenvx.C.f_kindx.C.f_propertiesinletparams=x.C.f_params|>paren|>comma_list|>List.map(parameter_bindingenv)inletenv=add_paramsenvparamsinletbody=stmt1_item_listenv(x.C.f_body|>paren)in{A.f_props=props;f_params=params;f_body=body}andfunc_props_envkindprops=(matchkindwith|C.F_func_->[]|C.F_method_->[]|C.F_get_->[A.Get]|C.F_set_->[A.Set])@(props|>List.map(function|C.Generator_->A.Generator|C.Async_->A.Async))andparameter_bindingenv=function|C.ParamClassicp->parameterenvp|C.ParamPattern_->raiseTodoandparameterenvp=letname=nameenvp.C.p_nameinletd=optdefaultenvp.C.p_defaultinletdots=p.C.p_dots<>Nonein{A.p_name=name;p_default=d;p_dots=dots}anddefaultenv=function(* less: use Undefined? *)|C.DNone_->A.Nop|C.DSome(_,e)->exprenveandarrow_funcenvx=(* todo: they can have some too, but not in CST for now *)letprops=[]inletbindings=matchx.C.a_paramswith|C.ASingleParamx->[x]|C.AParamsxs->xs|>paren|>comma_listinletparams=bindings|>List.map(parameter_bindingenv)inletenv=add_paramsenvparamsinletbody=matchx.C.a_bodywith|C.AExpre->A.ExprStmt(exprenve)|C.ABodyxs->stmt1_item_listenv(xs|>paren)in{A.f_props=props;f_params=params;f_body=body}andpropertyenv=function|C.P_field(pname,_,e)->letpname=property_nameenvpnameinlete=exprenveinletprops=[]inA.Field(pname,props,e)|C.P_methodx->letfun_=func_declenvxin(matchx.C.f_kindwith|C.F_method(pn)->letpname=property_nameenvpninA.Field(pname,[],A.Fun(fun_,None))|_->raise(UnhandledConstruct("weird method decl",fst3x.C.f_params)))|C.P_shorthandn->letn=nameenvninA.Field(A.PNn,[],A.Id(n,not_resolved()))|C.P_spread(_,e)->lete=exprenveinA.FieldSpreadeand_array_objenvidxtokxs=matchxswith|[]->[]|x::xs->(matchxwith|Righttok->_array_objenv(idx+1)tokxs|Lefte->letn=A.PN(string_of_intidx,tok)inlete=exprenveinletelt=A.Field(n,[],e)inelt::_array_objenvidxtokxs)andarray_arrenvtokxs=matchxswith|[]->[]|[Right_]->[]|[Lefte]->[exprenve]|(Lefte)::(Righttok)::xs->lete=exprenveine::array_arrenvtokxs|(Right_)::xs->lete=A.Nopine::array_arrenvtokxs|(Left_)::(Left_)::_->raise(TodoConstruct("array_arr, 2 left? impossible?",tok))andclass_declenvx=letextends=opt(funenv(_,typ)->nominal_typeenvtyp)envx.C.c_extendsinletxs=x.C.c_body|>paren|>List.map(class_elementenv)|>List.flattenin{A.c_extends=extends;c_body=xs}andnominal_typeenv(e,_)=exprenveandclass_elementenv=function|C.C_field(n,_,_)->letn=nameenvnin[A.Field(A.PNn,[],A.Nop)]|C.C_method(static_opt,x)->letfun_=func_declenvxinletprops=matchstatic_optwith|None->[]|Some_->[A.Static]in(matchx.C.f_kindwith|C.F_methodpn->letpname=property_nameenvpnin[A.Field(pname,props,A.Fun(fun_,None))]|_->raise(UnhandledConstruct("weird method decl",fst3x.C.f_params)))|C.C_extrasemicolon_->[]|C.C_todo->raiseTodo(* ------------------------------------------------------------------------- *)(* Misc *)(* ------------------------------------------------------------------------- *)letanyx=letenv=empty_env()inmatchxwith|C.Exprx->A.Expr(exprenvx)|C.Stmtx->A.Stmt(stmt1envx)|C.Item_x->raiseTodo|C.Program_x->raiseTodo