123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
* Copyright (C) 2017- 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. *)openImportmoduleWarnings=structtypet=|Unused_attributeofstring|Fragile_externalofstring|Redundant_mel_string|Deprecated_send_pipeletkind=function|Unused_attribute_->"unused"|Fragile_external_->"fragile"|Redundant_mel_string->"redundant"|Deprecated_send_pipe->"deprecated"letppfmtt=matchtwith|Unused_attributes->Format.fprintffmt"Unused attribute [%@%s]@\n\
This means such annotation is not annotated properly.@\n\
For example, some annotations are only meaningful in externals\n"s|Fragile_externals->Format.fprintffmt"%s : the external name is inferred from val name is unsafe from \
refactoring when changing value name"s|Redundant_mel_string->Format.fprintffmt"[@mel.string] is redundant here, you can safely remove it"|Deprecated_send_pipe->Format.fprintffmt"[@mel.send.pipe] is deprecated and will be removed in the next \
version of Melange"endletwarn_raw=letmoduleLocation=Ocaml_common.Locationinfun~loc~kindmessage->Location.prerr_alertloc{Ocaml_common.Warnings.kind;message;def=Location.none;use=loc}letwarn~loct=warn_raw~loc~kind:(Warnings.kindt)(Format.asprintf"%a"Warnings.ppt)letused_attributes:stringAsttypes.locPolyvariant.Hash_set.t=Polyvariant.Hash_set.create16(* only mark non-ghost used mel attribute *)letmark_used_mel_attribute({attr_name=x;_}:attribute)=ifnotx.loc.loc_ghostthenPolyvariant.Hash_set.addused_attributesxletwarn_unused_attribute({attr_name={txt;loc}assloc;_}:attribute):unit=if(* XXX(anmonteiro): the `not loc.loc_ghost` expression is holding together
e.g. the fact that we don't emit unused attribute warnings for
`mel.internal.ffi` *)Melange_ffi.External_ffi_attributes.is_mel_attributetxt&&(notloc.loc_ghost)&¬(Polyvariant.Hash_set.memused_attributessloc)thenwarn~loc(Unused_attributetxt)letwarn_discarded_unused_attributes?(has_mel_send=false)(attrs:attributes)=letattrs=ifhas_mel_sendthenList.filterattrs~f:(function|{attr_name={txt="mel.this";_};_}->false|_->true)elseattrsinifattrs<>[]thenList.iter~f:warn_unused_attributeattrsletemit_external_warnings:Ast_traverse.iter=object(_self)inheritAst_traverse.iterassupermethod!attributeattr=warn_unused_attributeattrmethod!label_declarationlbl=List.iter~f:(funattr->matchattrwith|{attr_name={txt="mel.as";_};_}->mark_used_mel_attributeattr|_->())lbl.pld_attributes;super#label_declarationlblendletemit_external_warnings_on_structurestru=emit_external_warnings#structurestruletemit_external_warnings_on_signaturesigi=emit_external_warnings#signaturesigi