123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124(* Copyright (C) 2018 Hongbo Zhang, Authors of ReScript
*
* 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, either version 3 of the License, or
* (at your option) any later version.
*
* In addition to the permissions granted to you by the LGPL, you may combine
* or link a "work that uses the Library" with a publicly distributed version
* of this file to produce a combined library or application, then distribute
* that combined work under the terms of your choosing, with no requirement
* to comply with the obligations normally placed on you by section 4 of the
* LGPL version 3 (or the corresponding section of a later version of the LGPL
* should you choose to use a 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. *)(* We disable warning 61 in Melange externals since they're substantially
different from OCaml externals. This warning doesn't make sense for a JS
runtime *)letunboxable_type_in_prim_decl:Parsetree.attribute=letopenAst_helperin{attr_name=Location.mknoloc"ocaml.warning";attr_payload=PStr[Str.eval(Exp.constant(Pconst_string("-unboxable-type-in-prim-decl",Location.none,None)));];attr_loc=Location.none;}lethandleExternalInSig(self:Ast_mapper.mapper)(prim:Parsetree.value_description)(sigi:Parsetree.signature_item):Parsetree.signature_item=let loc=prim.pval_locinletpval_type=self.typselfprim.pval_typeinletpval_attributes=self.attributesselfprim.pval_attributes inmatchprim.pval_primwith|[]->Location.raise_errorf ~loc"empty primitive string"|a::b:: _->Location.raise_errorf~loc"only a single string is allowed in bs external %S %S"ab|[v]->(matchAst_external_process.handle_attributes_as_stringlocpval_typepval_attributesprim.pval_name.txtvwith|{pval_type;pval_prim;pval_attributes;no_inline_cross_module }->{sigiwithpsig_desc=Psig_value{primwithpval_type;pval_prim=(ifno_inline_cross_module then[]elsepval_prim);pval_attributes=unboxable_type_in_prim_decl::pval_attributes;};})lethandleExternalInStru(self:Ast_mapper.mapper)(prim:Parsetree.value_description)(str:Parsetree.structure_item):Parsetree.structure_item=letloc=prim.pval_locinletpval_type=self.typselfprim.pval_typeinletpval_attributes=self.attributesselfprim.pval_attributes inmatchprim.pval_primwith|[]->Location.raise_errorf ~loc"empty primitive string"|a::b:: _->Location.raise_errorf~loc"only a single string is allowed in bs external %S : %S"ab|[v]->(matchAst_external_process.handle_attributes_as_stringlocpval_typepval_attributesprim.pval_name.txtvwith|{pval_type;pval_prim;pval_attributes;no_inline_cross_module }->letexternal_result={strwithpstr_desc=Pstr_primitive{primwithpval_type;pval_prim;pval_attributes=unboxable_type_in_prim_decl::pval_attributes;};}inifnotno_inline_cross_modulethenexternal_resultelseletopenAst_helper inStr.include_~loc(Incl.mk~loc(Mod.constraint_~loc(Mod.structure~loc [external_result])(Mty.signature~loc[{psig_desc=Psig_value{primwithpval_type;pval_prim =[];pval_attributes;};psig_loc=loc;};]))))