123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119(* 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. *)openImportletpval_prim_default=["";""]letsingle_string_payload_error~loc=Ast_helper.Exp.constant(Pconst_string("Melange requires a single string in `external` payloads",loc,None))lethandleExternalInSig(self:Ast_traverse.map)(prim:value_description)(sigi:signature_item):signature_item=letloc=prim.pval_locinletpval_type=self#core_typeprim.pval_typeinletpval_attributes=self#attributesprim.pval_attributesinmatchprim.pval_primwith|[]->Location.raise_errorf~loc"empty primitive string"|_::_::_->[%sigi:[%%ocaml.error[%esingle_string_payload_error~loc]]]|[v]->let{Ast_external_process.pval_type;pval_prim;pval_attributes;dont_inline_cross_module;}=Ast_external_process.handle_attributes_as_stringlocpval_typepval_attributesprim.pval_name.txtvin{sigiwithpsig_desc=Psig_value{primwithpval_type;pval_prim=(ifdont_inline_cross_modulethen[]elsepval_prim);pval_attributes=Ast_attributes.unboxable_type_in_prim_decl::pval_attributes;};}lethandleExternalInStru(self:Ast_traverse.map)(prim:value_description)(str:structure_item):structure_item=letloc=prim.pval_locinletpval_type=self#core_typeprim.pval_typeinletpval_attributes=self#attributesprim.pval_attributesinmatchprim.pval_primwith|[]->Location.raise_errorf~loc"empty primitive string"|_::_::_->[%stri[%%ocaml.error[%esingle_string_payload_error~loc]]]|[v]->let{Ast_external_process.pval_type;pval_prim;pval_attributes;dont_inline_cross_module;}=Ast_external_process.handle_attributes_as_stringlocpval_typepval_attributesprim.pval_name.txtvinletexternal_result={strwithpstr_desc=Pstr_primitive{primwithpval_type;pval_prim;pval_attributes=Ast_attributes.unboxable_type_in_prim_decl::pval_attributes;};}inifnotdont_inline_cross_modulethenexternal_resultelseletopenAst_helperinStr.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;};])))