@@ -9069,6 +9069,105 @@ Perl_newSTATEOP(pTHX_ I32 flags, char *label, OP *o)
90699069 return op_prepend_elem(OP_LINESEQ, (OP*)cop, o);
90709070}
90719071
9072+ /*
9073+ =for apidoc cop_has_warning
9074+
9075+ Returns true if the set of warnings bits contained by (or implied by) the
9076+ COP contains the given warning, as specified by one of the C<WARN_...>
9077+ constants from F<warnings.h>.
9078+
9079+ =cut
9080+ */
9081+
9082+ bool
9083+ Perl_cop_has_warning(pTHX_ const COP *cop, int warn_bit)
9084+ {
9085+ PERL_ARGS_ASSERT_COP_HAS_WARNING;
9086+
9087+ const char *warning_bits = cop->cop_warnings;
9088+ if(warning_bits == pWARN_STD)
9089+ return (PL_dowarn & G_WARN_ON) ? true : PerlWarnIsSet_(WARN_DEFAULTstring, 2*warn_bit);
9090+ else if(warning_bits == pWARN_ALL)
9091+ return true;
9092+ else if(warning_bits == pWARN_NONE)
9093+ return false;
9094+ else
9095+ return isWARN_on(cop->cop_warnings, (STRLEN)warn_bit);
9096+ }
9097+
9098+ #define cop_inplace_expand_warning_bitmask(cop) S_cop_inplace_expand_warning_bitmask(aTHX_ cop)
9099+ STATIC void
9100+ S_cop_inplace_expand_warning_bitmask(pTHX_ COP *cop)
9101+ {
9102+ const char *warning_bits = cop->cop_warnings;
9103+
9104+ if(warning_bits == pWARN_STD)
9105+ warning_bits = (PL_dowarn & G_WARN_ON) ? WARN_ALLstring : WARN_DEFAULTstring;
9106+ else if(warning_bits == pWARN_ALL)
9107+ warning_bits = WARN_ALLstring;
9108+ else if(warning_bits == pWARN_NONE)
9109+ warning_bits = WARN_NONEstring;
9110+
9111+ /* Must allocate the new one before we throw the old buffer away */
9112+ char *new_warnings = Perl_new_warnings_bitfield(aTHX_ NULL, warning_bits, WARNsize);
9113+ free_and_set_cop_warnings(cop, new_warnings);
9114+ }
9115+
9116+ /*
9117+ =for apidoc cop_enable_warning
9118+
9119+ Ensures that the set of warning bits contained by the COP includes the given
9120+ warning, as specified by one of the C<WARN_...> constants from F<warnings.h>.
9121+
9122+ If the COP already includes the warning, no modification is made. Otherwise,
9123+ the stored warning bitmask is cloned, and the given warning bit is enabled
9124+ within it. The COP is modified in-place, and therefore this function is
9125+ intended only for use during compiletime when the optree is being constructed.
9126+
9127+ =cut
9128+ */
9129+
9130+ void
9131+ Perl_cop_enable_warning(pTHX_ COP *cop, int warn_bit)
9132+ {
9133+ PERL_ARGS_ASSERT_COP_ENABLE_WARNING;
9134+
9135+ if(cop_has_warning(cop, warn_bit))
9136+ return;
9137+
9138+ cop_inplace_expand_warning_bitmask(cop);
9139+
9140+ cop->cop_warnings[Perl_Warn_Off_(2 * warn_bit)] |= Perl_Warn_Bit_(2 * warn_bit);
9141+ }
9142+
9143+ /*
9144+ =for apidoc cop_disable_warning
9145+
9146+ Ensures that the set of warning bits contained by the COP does not include the
9147+ given warning, as specified by one of the C<WARN_...> constants from
9148+ F<warnings.h>.
9149+
9150+ If the COP does not include the warning, no modification is made. Otherwise,
9151+ the stored warning bitmask is cloned, and the given warning bit is disabled
9152+ within it. The COP is modified in-place, and therefore this function is
9153+ intended only for use during compiletime when the optree is being constructed.
9154+
9155+ =cut
9156+ */
9157+
9158+ void
9159+ Perl_cop_disable_warning(pTHX_ COP *cop, int warn_bit)
9160+ {
9161+ PERL_ARGS_ASSERT_COP_DISABLE_WARNING;
9162+
9163+ if(!cop_has_warning(cop, warn_bit))
9164+ return;
9165+
9166+ cop_inplace_expand_warning_bitmask(cop);
9167+
9168+ cop->cop_warnings[Perl_Warn_Off_(2 * warn_bit)] &= ~Perl_Warn_Bit_(2 * warn_bit);
9169+ }
9170+
90729171/*
90739172=for apidoc newLOGOP
90749173
0 commit comments