Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file ppx_eliom_server.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246(* Ocsigen
* http://www.ocsigen.org
* Copyright (C) 2010-2011
* Raphaël Proust, Grégoire Henry, Gabriel Radanne
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, with linking exception;
* either version 2.1 of the License, or (at your option) any later version.
*
* 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
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*)(* This prepocessor generates the module to be loaded by Ocsigen server *)openPpxlibopenAst_helperopenPpx_eliom_utilsmodulePass=structletpush_nongen_str_item,flush_nongen_str_item=lettyping_strs=ref[]inletadd~fragment~unsafelocid=lettyp=iffragmentthen[%type:_Eliom_client_value.t]else[%type:_]intyping_strs:=(ifunsafe||Mli.exists()then[%strilet[%pPat.varid]=funy->(y:[%ttyp]:>[%ttyp])]else[%strilet[%pPat.varid]=letx=Stdlib.refNoneinfuny->iffalsethenx:=Somey;(y:[%ttyp]:>[%ttyp])])::!typing_strsinletflushloc=letres=!typing_strsintyping_strs:=[];Str.open_~loc(Opn.mk~loc(Mod.structure~locres))inadd,flushletone_char_locationloc={locwithLocation.loc_end={loc.Location.loc_startwithpos_cnum=loc.Location.loc_start.Lexing.pos_cnum+1}}letpush_escaped_binding,flush_escaped_bindings=letargs=ref[]inletpushlocorig_exprid~unsafe=ifList.for_all(function_,id',_,_->id.txt<>id'.txt)!argsthenargs:=(loc,id,orig_expr,unsafe)::!argsinletflush()=letres=List.rev!argsinargs:=[];letaux(loc,id,arg,unsafe)=push_nongen_str_item~fragment:false~unsafelocid;[%exprEliom_syntax.escaped_value[%eletloc=one_char_locationlocin[%expr[%eeidid][%earg]]]]inList.mapauxresinpush,flushmoduleSSet=Set.Make(String)letpush_injection,flush_injections=letbuffer:(_*_*_*_*_)listref=ref[]inletgen_ids=refSSet.emptyinletpushloc?identid~unsafeorig_expr=ifnot(SSet.memid!gen_ids)then(gen_ids:=SSet.addid!gen_ids;buffer:=(loc,id,orig_expr,ident,unsafe)::!buffer)inletflush_all()=letres=List.rev!bufferingen_ids:=SSet.empty;buffer:=[];resinletglobal_known=refSSet.emptyinletflush()=letall=flush_all()inletnovel=letis_fresh(_,gen_id,_,_,_)=not(SSet.memgen_id!global_known)inList.filteris_freshallinList.iter(function|_,gen_id,_,_,_->global_known:=SSet.addgen_id!global_known)novel;allinpush,flush(* For every injection of $orig_expr$ as $gen_id$:
let $gen_id$ = $orig_expr$ and ...
(Necessary for injections in shared section) *)letbind_injected_identsinjections=assert(injections<>[]);letbindings=List.map(fun(_,txt,expr,_,_)->letloc=expr.pexp_locinVb.mk~loc(Pat.var~loc{txt;loc})expr)injectionsinStr.valueNonrecursivebindingsletclose_server_sectionloc=[%strilet()=Eliom_syntax.close_server_section[%eeid@@id_file_hashloc]]letmay_close_server_section~no_fragmentloc=ifno_fragmentthen[]else[close_server_sectionloc]letclose_client_sectionlocinjections=assert(injections<>[]);letinjection_list=List.fold_right(fun(loc0,txt,expr,ident,unsafe)sofar->letloc=expr.pexp_locinletloc_expr=positionlocinletfrag_eid=eid{txt;loc}inletident=matchidentwith|None->[%exprNone]|Somei->[%exprSome[%estri]]inlet_,num=Mli.get_injected_ident_infotxtinletf_id={txt=txt^"_f";loc}inpush_nongen_str_item~fragment:false~unsafelocf_id;[%expr([%eintnum],Eliom_lib.to_poly[%eletloc=one_char_locationloc0in[%expr[%eeidf_id][%efrag_eid]]],[%eloc_expr],[%eident])::[%esofar]])injections[%expr[]]in[%strilet()=Eliom_syntax.close_client_section[%eeid@@id_file_hashloc][%einjection_list]](** Syntax extension *)letclient_stritem=letall_injections=flush_injections()inletloc=item.pstr_locinletstr=matchall_injectionswith|[]->[]|l->[bind_injected_identsl;close_client_sectionlocall_injections]inflush_nongen_str_itemloc::strletserver_strno_fragmentitem=letloc=item.pstr_locinflush_nongen_str_itemloc::item::may_close_server_section~no_fragmentlocletshared_strno_fragmentitem=letall_injections=flush_injections()inletloc=item.pstr_locinletcl=item::may_close_server_section~no_fragment:(no_fragment||all_injections<>[])locinletstr=matchall_injectionswith|[]->cl|l->(bind_injected_identsl::cl)@[close_client_sectionlocall_injections]inflush_nongen_str_itemloc::strletfragment~loc?typ~context:_~num~id~unsafe_=lettyp=matchtypwithSometyp->typ|None->[%type:_]inlete=format_args@@flush_escaped_bindings()inpush_nongen_str_item~fragment:true~unsafelocid;[%expr[%eeidid][%eletloc=one_char_locationlocin[%expr(Eliom_syntax.client_value~pos:[%epositionloc][%estrnum][%ee]:[%ttyp]Eliom_client_value.t)]]]letescape_inject~loc?ident~(context:Context.escape_inject)~id~unsafeexpr=matchcontextwith|`Escaped_value_->push_escaped_bindinglocexprid~unsafe;[%exprassertfalse]|`Injection_->push_injectionloc?identid.txt~unsafeexpr;eididletset_global~locb=letb=Exp.construct~loc{loc;txt=Longident.Lident(ifbthen"true"else"false")}Nonein[%strilet()=Eliom_syntax.set_global[%eb]]letpreludeloc=[set_global~loctrue]letpostludeloc=[set_global~locfalse]letshared_sigitem=[item]letserver_sigitem=[item]letclient_sig_=[]endincludeMake(Pass)let()=Ppxlib.Driver.register_transformation~impl:mapper#structure~intf:mapper#signature"ppx_eliom_server"