123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249(* Js_of_ocaml compiler
* http://www.ocsigen.org/js_of_ocaml/
*
* 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.
*)open!Stdlibletrecconstant_of_const:_->Code.constant=letopenLambdainletopenAsttypesinfunction|Const_base(Const_inti)->Int(Int32.of_int_warning_on_overflowi)|Const_base(Const_charc)->Int(Int32.of_int(Char.codec))|((Const_base(Const_string(s,_)))[@ifocaml_version<(4,11,0)])|((Const_base(Const_string(s,_,_)))[@ifocaml_version>=(4,11,0)])->Strings|Const_base(Const_floats)->Float(float_of_strings)|Const_base(Const_int32i)->Inti|Const_base(Const_int64i)->Int64i|Const_base(Const_nativeinti)->Int(Int32.of_nativeint_warning_on_overflowi)|Const_immstrings->Strings|Const_float_arraysl->letl=List.map~f:(funf->Code.Float(float_of_stringf))slinTuple(Obj.double_array_tag,Array.of_listl,Unknown)|((Const_pointer(i,_))[@ifBUCKLESCRIPT])->Int(Int32.of_int_warning_on_overflowi)|((Const_block(tag,_,l))[@ifBUCKLESCRIPT])->letl=Array.of_list(List.mapl~f:constant_of_const)inTuple(tag,l,Unknown)|((Const_pointeri)[@ifnotBUCKLESCRIPT][@ifocaml_version<(4,12,0)])->Int(Int32.of_int_warning_on_overflowi)|((Const_block(tag,l))[@ifnotBUCKLESCRIPT])->letl=Array.of_list(List.mapl~f:constant_of_const)inTuple(tag,l,Unknown)letrecfind_loc_in_summaryident'=function|Env.Env_empty->None|Env.Env_value(_summary,ident,description)whenPoly.(ident=ident')->Somedescription.Types.val_loc|Env.Env_value(summary,_,_)|Env.Env_type(summary,_,_)|Env.Env_extension(summary,_,_)|(Env.Env_module(summary,_,_,_)[@ifocaml_version>=(4,8,0)])|(Env.Env_module(summary,_,_)[@ifocaml_version<(4,8,0)])|Env.Env_modtype(summary,_,_)|Env.Env_class(summary,_,_)|Env.Env_cltype(summary,_,_)|(Env.Env_open(summary,_)[@ifocaml_version>=(4,8,0)])|(Env.Env_open(summary,_,_)[@ifocaml_version<(4,8,0)][@ifocaml_version>=(4,7,0)])|(Env.Env_open(summary,_)[@ifocaml_version<(4,7,0)])|Env.Env_functor_arg(summary,_)|(Env.Env_constraints(summary,_)[@ifocaml_version>=(4,4,0)])|(Env.Env_copy_types(summary,_)[@ifocaml_version>=(4,6,0)][@ifocaml_version<(4,10,0)])|(Env.Env_copy_types(summary)[@ifocaml_version>=(4,10,0)])|(Env.Env_persistent(summary,_)[@ifocaml_version>=(4,8,0)])|(Env.Env_value_unbound(summary,_,_)[@ifocaml_version>=(4,10,0)])|(Env.Env_module_unbound(summary,_,_)[@ifocaml_version>=(4,10,0)])->find_loc_in_summaryident'summary[@@ocamlformat"disable"](* Copied from ocaml/utils/tbl.ml *)moduleTbl=structopenPolytype('a,'b)t=|Empty|Nodeof('a,'b)t*'a*'b*('a,'b)t*intletempty=Emptyletheight=function|Empty->0|Node(_,_,_,_,h)->hletcreatelxdr=lethl=heightlandhr=heightrinNode(l,x,d,r,ifhl>=hrthenhl+1elsehr+1)letballxdr=lethl=heightlandhr=heightrinifhl>hr+1thenmatchlwith|Node(ll,lv,ld,lr,_)whenheightll>=heightlr->createlllvld(createlrxdr)|Node(ll,lv,ld,Node(lrl,lrv,lrd,lrr,_),_)->create(createlllvldlrl)lrvlrd(createlrrxdr)|_->assertfalseelseifhr>hl+1thenmatchrwith|Node(rl,rv,rd,rr,_)whenheightrr>=heightrl->create(createlxdrl)rvrdrr|Node(Node(rll,rlv,rld,rlr,_),rv,rd,rr,_)->create(createlxdrll)rlvrld(createrlrrvrdrr)|_->assertfalseelsecreatelxdrletrecaddxdata=function|Empty->Node(Empty,x,data,Empty,1)|Node(l,v,d,r,h)->letc=comparexvinifc=0thenNode(l,x,data,r,h)elseifc<0thenbal(addxdatal)vdrelseballvd(addxdatar)letreciterf=function|Empty->()|Node(l,v,d,r,_)->iterfl;fvd;iterfrletrecfindcomparex=function|Empty->raiseNot_found|Node(l,v,d,r,_)->letc=comparexvinifc=0thendelsefindcomparex(ifc<0thenlelser)letrecfoldfmaccu=matchmwith|Empty->accu|Node(l,v,d,r,_)->foldfr(fvd(foldflaccu))end[@@ifocaml_version<(4,8,0)]moduleSymtable=structtype'anumtable={num_cnt:int;num_tbl:('a,int)Tbl.t}moduleGlobalMap=structtypet=Ident.tnumtableletfilter_global_map(p:Ident.t->bool)gmap=letnewtbl=refTbl.emptyinTbl.iter(funidnum->ifpidthennewtbl:=Tbl.addidnum!newtbl)gmap.num_tbl;{num_cnt=gmap.num_cnt;num_tbl=!newtbl}letfindnnt=Tbl.find(funx1x2->String.compare(Ident.namex1)(Ident.namex2))nnt.num_tblletiternnt=Tbl.iternnt.num_tblletfoldftacc=Tbl.foldft.num_tblaccendletreloc_identname=letbuf=Bytes.create4inSymtable.patch_objectbuf[Reloc_setglobal(Ident.create_persistentname),0];letgeti=Char.code(Bytes.getbufi)inget0+(get1lsl8)+(get2lsl16)+(get3lsl24)end[@@ifocaml_version<(4,8,0)]moduleSymtable=struct(* Copied from ocaml/bytecomp/symtable.ml *)moduleNum_tbl(M:Map.S)=struct[@@@ocaml.warning"-32"]typet={cnt:int;(* The next number *)tbl:intM.t(* The table of already numbered objects *)}letempty={cnt=0;tbl=M.empty}letfindkeynt=M.findkeynt.tblletiterfnt=M.iterfnt.tblletfoldfnta=M.foldfnt.tblaletenterntkey=letn=!nt.cntinnt:={cnt=n+1;tbl=M.addkeyn!nt.tbl};nletincrnt=letn=!nt.cntinnt:={cnt=n+1;tbl=!nt.tbl};nendmoduleGlobalMap=structmoduleGlobalMap=Num_tbl(Ident.Map)includeGlobalMapletfilter_global_map(p:Ident.t->bool)(gmap:t)=letnewtbl=refIdent.Map.emptyinIdent.Map.iter(funidnum->ifpidthennewtbl:=Ident.Map.addidnum!newtbl)gmap.tbl;{cnt=gmap.cnt;tbl=!newtbl}endletreloc_identname=letbuf=Bytes.create4inSymtable.patch_object[|buf|][Reloc_setglobal(Ident.create_persistentname),0];letgeti=Char.code(Bytes.getbufi)inget0+(get1lsl8)+(get2lsl16)+(get3lsl24)end[@@ifocaml_version>=(4,8,0)]moduleIdent=struct(* Copied from ocaml/typing/ident.ml *)type'atbl'=|Empty|Nodeof'atbl'*'adata*'atbl'*intand'adata={ident:Ident.t;data:'a;previous:'adataoption}type'atbl='aIdent.tblletrectable_contents_recsztrem=matchtwith|Empty->rem|Node(l,v,r,_)->table_contents_recszl((sz-v.data,Ident.namev.ident,v.ident)::table_contents_recszrrem)lettable_contentssz(t:'atbl)=List.sort~cmp:(fun(i,_,_)(j,_,_)->compareij)(table_contents_recsz(Obj.magic(t:'atbl):'atbl')[])end