123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126(* 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. *)openAst_helper(**
[newTdcls tdcls newAttrs]
functional update attributes of last declaration *)letnewTdcls(tdcls:Parsetree.type_declarationlist)(newAttrs:Parsetree.attributes):Parsetree.type_declarationlist=matchtdclswith|[x]->[{xwithParsetree.ptype_attributes=newAttrs}]|_->Ext_list.map_lasttdcls(funlastx->iflastthen{xwithParsetree.ptype_attributes=newAttrs}elsex)letdisable_unused_type:Parsetree.attribute={attr_name=Location.mknoloc"ocaml.warning";attr_payload=PStr[Str.eval(Exp.constant(Pconst_string(* -unused-type-declaration -unused-field *)("-34-69",Location.none,None)));];attr_loc=Location.none;}lethandleTdclsInSigi(self:Ast_mapper.mapper)(sigi:Parsetree.signature_item)rf(tdcls:Parsetree.type_declarationlist):Ast_signature.item=matchAst_attributes.process_derive_type(Ext_list.lasttdcls).ptype_attributeswith|{bs_deriving =Someactions},newAttrs->letloc=sigi.psig_locinletoriginalTdclsNewAttrs=newTdclstdcls(disable_unused_type::newAttrs)in(* remove the processed attr*)letnewTdclsNewAttrs=List.map(self.type_declaration self)originalTdclsNewAttrsinletkind=Ast_derive_abstract.isAbstractactionsinifkind<>Not_abstractthenletcodes=Ast_derive_abstract.handleTdclsInSig~light:(kind=Light_abstract)rforiginalTdclsNewAttrsinAst_signature.fuseAll ~loc(Sig.include_~loc(Incl.mk~loc(Mty.typeof_~loc(Mod.constraint_ ~loc(Mod.structure ~loc[Ast_compatible.rec_type_str~locrfnewTdclsNewAttrs;])(Mty.signature~loc[]))))::(* include module type of struct [processed_code for checking like invariance ]end *)self.signatureselfcodes)elseAst_signature.fuseAll~loc(Ast_compatible.rec_type_sig ~locrfnewTdclsNewAttrs::self.signatureself(Ast_derive.gen_signaturetdclsactionsrf))|{bs_deriving=None},_->Ast_mapper.default_mapper.signature_itemselfsigilethandleTdclsInStru(self:Ast_mapper.mapper)(str :Parsetree.structure_item)rf(tdcls:Parsetree.type_declarationlist):Ast_structure.item=matchAst_attributes.process_derive_type(Ext_list.lasttdcls).ptype_attributeswith|{bs_deriving =Someactions},newAttrs->letloc=str.pstr_locinletoriginalTdclsNewAttrs=newTdclstdcls(disable_unused_type::newAttrs)inletnewStr:Parsetree.structure_item=Ast_compatible.rec_type_str ~locrf(List.map(self.type_declarationself)originalTdclsNewAttrs)inletkind=Ast_derive_abstract.isAbstractactionsinifkind<>Not_abstractthenletcodes=Ast_derive_abstract.handleTdclsInStr~light:(kind=Light_abstract)rforiginalTdclsNewAttrsin(* use [tdcls2] avoid nonterminating *)Ast_structure.fuseAll~loc(Ast_structure.constraint_ ~loc[newStr][]::(* [include struct end : sig end] for error checking *)self.structureselfcodes)elseAst_structure.fuseAll~loc(newStr:: self.structureself(Ext_list.filter_mapactions(funaction->Ast_derive.gen_structure_signatureloctdclsactionrf)))|{bs_deriving =None },_->Ast_mapper.default_mapper.structure_itemselfstr