This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regcomp.c: Add macro for warnings output
authorKarl Williamson <khw@cpan.org>
Sun, 14 Oct 2018 23:07:57 +0000 (17:07 -0600)
committerKarl Williamson <khw@cpan.org>
Sat, 20 Oct 2018 06:09:56 +0000 (00:09 -0600)
This macro does nothing for now.  It is being added in this separate
commit to lessen the number of differences in the future commit that
will need it, so that these don't distract from the main intent of that
commit.

The code is moving away from emitting all warnings in the code
generation pass, to emitting them as soon as encountered.  But to avoid
emitting them more than once should the pattern have to be reparsed,
they will not be emitted unless the parse has gotten further this time
than it got earlier.  This commit prepares for that.

regcomp.c

index eaf8d47..9975615 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -810,6 +810,8 @@ static const scan_data_t zero_scan_data = {
 #define TO_OUTPUT_WARNINGS(loc)                                         \
   (PASS2 && RExC_copy_start_in_constructed)
 
 #define TO_OUTPUT_WARNINGS(loc)                                         \
   (PASS2 && RExC_copy_start_in_constructed)
 
+#define UPDATE_WARNINGS_LOC(loc)  NOOP
+
 #define _WARN_HELPER(loc, warns, code)                                  \
     STMT_START {                                                        \
         if (! RExC_copy_start_in_constructed) {                         \
 #define _WARN_HELPER(loc, warns, code)                                  \
     STMT_START {                                                        \
         if (! RExC_copy_start_in_constructed) {                         \
@@ -819,6 +821,7 @@ static const scan_data_t zero_scan_data = {
         }                                                               \
         if (TO_OUTPUT_WARNINGS(loc)) {                                  \
             code;                                                       \
         }                                                               \
         if (TO_OUTPUT_WARNINGS(loc)) {                                  \
             code;                                                       \
+            UPDATE_WARNINGS_LOC(loc);                                   \
         }                                                               \
     } STMT_END
 
         }                                                               \
     } STMT_END
 
@@ -13794,6 +13797,7 @@ S_regatom(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
                                                   to exact spot of failure */
                                vFAIL(error_msg);
                            }
                                                   to exact spot of failure */
                                vFAIL(error_msg);
                            }
+                            UPDATE_WARNINGS_LOC(p - 1);
                             ender = result;
                            if (ender > 0xff) {
                                REQUIRE_UTF8(flagp);
                             ender = result;
                            if (ender > 0xff) {
                                REQUIRE_UTF8(flagp);
@@ -13821,6 +13825,7 @@ S_regatom(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
                                                   to exact spot of failure */
                                vFAIL(error_msg);
                            }
                                                   to exact spot of failure */
                                vFAIL(error_msg);
                            }
+                            UPDATE_WARNINGS_LOC(p - 1);
                             ender = result;
 
                             if (ender < 0x100) {
                             ender = result;
 
                             if (ender < 0x100) {
@@ -13838,6 +13843,7 @@ S_regatom(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
                    case 'c':
                        p++;
                        ender = grok_bslash_c(*p, TO_OUTPUT_WARNINGS(p));
                    case 'c':
                        p++;
                        ender = grok_bslash_c(*p, TO_OUTPUT_WARNINGS(p));
+                        UPDATE_WARNINGS_LOC(p);
                         p++;
                        break;
                     case '8': case '9': /* must be a backreference */
                         p++;
                        break;
                     case '8': case '9': /* must be a backreference */
@@ -16358,6 +16364,10 @@ S_output_or_return_posix_warnings(pTHX_ RExC_state_t *pRExC_state, AV* posix_war
             SvREFCNT_dec_NN(msg);
         }
     }
             SvREFCNT_dec_NN(msg);
         }
     }
+
+    if (! return_posix_warnings) {
+        UPDATE_WARNINGS_LOC(RExC_parse);
+    }
 }
 
 STATIC AV *
 }
 
 STATIC AV *
@@ -17122,6 +17132,7 @@ S_regclass(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth,
                    if (! valid) {
                        vFAIL(error_msg);
                    }
                    if (! valid) {
                        vFAIL(error_msg);
                    }
+                    UPDATE_WARNINGS_LOC(RExC_parse - 1);
                }
                 non_portable_endpoint++;
                break;
                }
                 non_portable_endpoint++;
                break;
@@ -17140,11 +17151,13 @@ S_regclass(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth,
                     if (! valid) {
                        vFAIL(error_msg);
                    }
                     if (! valid) {
                        vFAIL(error_msg);
                    }
+                    UPDATE_WARNINGS_LOC(RExC_parse - 1);
                }
                 non_portable_endpoint++;
                break;
            case 'c':
                value = grok_bslash_c(*RExC_parse, TO_OUTPUT_WARNINGS(RExC_parse));
                }
                 non_portable_endpoint++;
                break;
            case 'c':
                value = grok_bslash_c(*RExC_parse, TO_OUTPUT_WARNINGS(RExC_parse));
+                UPDATE_WARNINGS_LOC(RExC_parse);
                RExC_parse++;
                 non_portable_endpoint++;
                break;
                RExC_parse++;
                 non_portable_endpoint++;
                break;