This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
regexec.c: Rule out match sooner
[perl5.git] / regcomp.h
index 45d24c2..eb100bb 100644 (file)
--- a/regcomp.h
+++ b/regcomp.h
@@ -7,6 +7,10 @@
  *    License or the Artistic License, as specified in the README file.
  *
  */
+
+#ifndef PERL_REGCOMP_H_
+#define PERL_REGCOMP_H_
+
 #include "regcharclass.h"
 
 /* Convert branch sequences to more efficient trie ops? */
@@ -190,7 +194,7 @@ struct regnode_2 {
  * Cyrillic, Greek, Hebrew, Indian subcontinent, Latin, and Thai; but not Han,
  * Japanese, nor Korean.  (The regarglen structure in regnodes.h is a U8, and
  * the trie types TRIEC and AHOCORASICKC are larger than U8 for shift values
- * below above 12.)  Be sure to benchmark before changing, as larger sizes do
+ * above 12.)  Be sure to benchmark before changing, as larger sizes do
  * significantly slow down the test suite */
 #define NUM_ANYOF_CODE_POINTS   (1 << 8)
 
@@ -353,38 +357,34 @@ struct regnode_ssc {
 #define        NEXTOPER(p)     ((p) + NODE_STEP_REGNODE)
 #define        PREVOPER(p)     ((p) - NODE_STEP_REGNODE)
 
-#define FILL_NODE(ptr, op)                                           \
-    STMT_START {                                                     \
-                    OP(ptr) = op;                                    \
-                    NEXT_OFF(ptr) = 0;                               \
+#define FILL_NODE(offset, op)                                           \
+    STMT_START {                                                        \
+                    OP(REGNODE_p(offset)) = op;                         \
+                    NEXT_OFF(REGNODE_p(offset)) = 0;                    \
     } STMT_END
-#define FILL_ADVANCE_NODE(ptr, op)                                   \
-    STMT_START {                                                     \
-                    FILL_NODE(ptr, op);                              \
-                    (ptr)++;                                         \
+#define FILL_ADVANCE_NODE(offset, op)                                   \
+    STMT_START {                                                        \
+                    FILL_NODE(offset, op);                              \
+                    (offset)++;                                         \
     } STMT_END
-#define FILL_ADVANCE_NODE_ARG(ptr, op, arg)                         \
-    STMT_START {                                                    \
-                    ARG_SET(ptr, arg);                              \
-                    FILL_ADVANCE_NODE(ptr, op);                     \
-                    /* This is used generically for other operations\
-                     * that have a longer argument */               \
-                    (ptr) += regarglen[op];                         \
+#define FILL_ADVANCE_NODE_ARG(offset, op, arg)                          \
+    STMT_START {                                                        \
+                    ARG_SET(REGNODE_p(offset), arg);                    \
+                    FILL_ADVANCE_NODE(offset, op);                      \
+                    /* This is used generically for other operations    \
+                     * that have a longer argument */                   \
+                    (offset) += regarglen[op];                          \
     } STMT_END
-#define FILL_ADVANCE_NODE_2L_ARG(ptr, op, arg1, arg2)               \
-    STMT_START {                                                    \
-                    ARG_SET(ptr, arg1);                             \
-                    ARG2L_SET(ptr, arg2);                           \
-                    FILL_ADVANCE_NODE(ptr, op);                     \
-                    (ptr) += 2;                                     \
+#define FILL_ADVANCE_NODE_2L_ARG(offset, op, arg1, arg2)                \
+    STMT_START {                                                        \
+                    ARG_SET(REGNODE_p(offset), arg1);                   \
+                    ARG2L_SET(REGNODE_p(offset), arg2);                 \
+                    FILL_ADVANCE_NODE(offset, op);                      \
+                    (offset) += 2;                                      \
     } STMT_END
 
 #define REG_MAGIC 0234
 
-#define SIZE_ONLY cBOOL(RExC_emit == (regnode *) & RExC_emit_dummy)
-#define PASS1 SIZE_ONLY
-#define PASS2 (! SIZE_ONLY)
-
 /* An ANYOF node is basically a bitmap with the index being a code point.  If
  * the bit for that code point is 1, the code point matches;  if 0, it doesn't
  * match (complemented if inverted).  There is an additional mechanism to deal
@@ -509,9 +509,9 @@ struct regnode_ssc {
 #define ANYOFL_FOLD                             0x04
 
 /* Shared bit set only with ANYOFL and SSC nodes:
- *    If ANYOFL_FOLD is set, this means there are potential matches valid
- *       only if the locale is a UTF-8 one.
- *    If ANYOFL_FOLD is NOT set, this means to warn if the runtime locale
+ *    If ANYOFL_FOLD is set, this flag indicates there are potential matches
+ *      valid only if the locale is a UTF-8 one.
+ *    If ANYOFL_FOLD is NOT set, this flag means to warn if the runtime locale
  *       isn't a UTF-8 one (and the generated node assumes a UTF-8 locale).
  *       None of INVERT, POSIXL,
  *       ANYOF_SHARED_d_UPPER_LATIN1_UTF8_STRING_MATCHES_non_d_RUNTIME_USER_PROP
@@ -1007,59 +1007,57 @@ re.pm, especially to the documentation.
 #define RE_DEBUG_FLAG(x) (re_debug_flags & x)
 /* Compile */
 #define DEBUG_COMPILE_r(x) DEBUG_r( \
-    if (re_debug_flags & RE_DEBUG_COMPILE_MASK) x  )
+    if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_COMPILE_MASK)) x  )
 #define DEBUG_PARSE_r(x) DEBUG_r( \
-    if (re_debug_flags & RE_DEBUG_COMPILE_PARSE) x  )
+    if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_COMPILE_PARSE)) x  )
 #define DEBUG_OPTIMISE_r(x) DEBUG_r( \
-    if (re_debug_flags & RE_DEBUG_COMPILE_OPTIMISE) x  )
-#define DEBUG_PARSE_r(x) DEBUG_r( \
-    if (re_debug_flags & RE_DEBUG_COMPILE_PARSE) x  )
+    if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_COMPILE_OPTIMISE)) x  )
 #define DEBUG_DUMP_r(x) DEBUG_r( \
-    if (re_debug_flags & RE_DEBUG_COMPILE_DUMP) x  )
+    if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_COMPILE_DUMP)) x  )
 #define DEBUG_TRIE_COMPILE_r(x) DEBUG_r( \
-    if (re_debug_flags & RE_DEBUG_COMPILE_TRIE) x )
+    if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_COMPILE_TRIE)) x )
 #define DEBUG_FLAGS_r(x) DEBUG_r( \
-    if (re_debug_flags & RE_DEBUG_COMPILE_FLAGS) x )
+    if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_COMPILE_FLAGS)) x )
 #define DEBUG_TEST_r(x) DEBUG_r( \
-    if (re_debug_flags & RE_DEBUG_COMPILE_TEST) x )
+    if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_COMPILE_TEST)) x )
 /* Execute */
 #define DEBUG_EXECUTE_r(x) DEBUG_r( \
-    if (re_debug_flags & RE_DEBUG_EXECUTE_MASK) x  )
+    if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_EXECUTE_MASK)) x  )
 #define DEBUG_INTUIT_r(x) DEBUG_r( \
-    if (re_debug_flags & RE_DEBUG_EXECUTE_INTUIT) x  )
+    if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_EXECUTE_INTUIT)) x  )
 #define DEBUG_MATCH_r(x) DEBUG_r( \
-    if (re_debug_flags & RE_DEBUG_EXECUTE_MATCH) x  )
+    if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_EXECUTE_MATCH)) x  )
 #define DEBUG_TRIE_EXECUTE_r(x) DEBUG_r( \
-    if (re_debug_flags & RE_DEBUG_EXECUTE_TRIE) x )
+    if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_EXECUTE_TRIE)) x )
 
 /* Extra */
 #define DEBUG_EXTRA_r(x) DEBUG_r( \
-    if (re_debug_flags & RE_DEBUG_EXTRA_MASK) x  )
+    if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_EXTRA_MASK)) x  )
 #define DEBUG_OFFSETS_r(x) DEBUG_r( \
-    if (re_debug_flags & RE_DEBUG_EXTRA_OFFSETS) x  )
+    if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_EXTRA_OFFSETS)) x  )
 #define DEBUG_STATE_r(x) DEBUG_r( \
-    if (re_debug_flags & RE_DEBUG_EXTRA_STATE) x )
+    if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_EXTRA_STATE)) x )
 #define DEBUG_STACK_r(x) DEBUG_r( \
-    if (re_debug_flags & RE_DEBUG_EXTRA_STACK) x )
+    if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_EXTRA_STACK)) x )
 #define DEBUG_BUFFERS_r(x) DEBUG_r( \
-    if (re_debug_flags & RE_DEBUG_EXTRA_BUFFERS) x )
+    if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_EXTRA_BUFFERS)) x )
 
 #define DEBUG_OPTIMISE_MORE_r(x) DEBUG_r( \
-    if ((RE_DEBUG_EXTRA_OPTIMISE|RE_DEBUG_COMPILE_OPTIMISE) == \
-         (re_debug_flags & (RE_DEBUG_EXTRA_OPTIMISE|RE_DEBUG_COMPILE_OPTIMISE)) ) x )
+    if (DEBUG_v_TEST || ((RE_DEBUG_EXTRA_OPTIMISE|RE_DEBUG_COMPILE_OPTIMISE) == \
+         (re_debug_flags & (RE_DEBUG_EXTRA_OPTIMISE|RE_DEBUG_COMPILE_OPTIMISE)))) x )
 #define MJD_OFFSET_DEBUG(x) DEBUG_r( \
-    if (re_debug_flags & RE_DEBUG_EXTRA_OFFDEBUG) \
+    if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_EXTRA_OFFDEBUG)) \
         Perl_warn_nocontext x )
 #define DEBUG_TRIE_COMPILE_MORE_r(x) DEBUG_TRIE_COMPILE_r( \
-    if (re_debug_flags & RE_DEBUG_EXTRA_TRIE) x )
+    if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_EXTRA_TRIE)) x )
 #define DEBUG_TRIE_EXECUTE_MORE_r(x) DEBUG_TRIE_EXECUTE_r( \
-    if (re_debug_flags & RE_DEBUG_EXTRA_TRIE) x )
+    if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_EXTRA_TRIE)) x )
 
 #define DEBUG_TRIE_r(x) DEBUG_r( \
-    if (re_debug_flags & (RE_DEBUG_COMPILE_TRIE \
-        | RE_DEBUG_EXECUTE_TRIE )) x )
+    if (DEBUG_v_TEST || (re_debug_flags & (RE_DEBUG_COMPILE_TRIE \
+        | RE_DEBUG_EXECUTE_TRIE ))) x )
 #define DEBUG_GPOS_r(x) DEBUG_r( \
-    if (re_debug_flags & RE_DEBUG_EXTRA_GPOS) x )
+    if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_EXTRA_GPOS)) x )
 
 /* initialization */
 /* get_sv() can return NULL during global destruction. */
@@ -1124,6 +1122,8 @@ typedef enum {
        WB_BOUND
 } bound_type;
 
+#endif /* PERL_REGCOMP_H_ */
+
 /*
  * ex: set ts=8 sts=4 sw=4 et:
  */