This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Ensure 'q' works in debugger with RemotePort.
[perl5.git] / regcomp.h
index c1744c3..0b69f6e 100644 (file)
--- a/regcomp.h
+++ b/regcomp.h
@@ -84,9 +84,7 @@
  * but allows patterns to get big without disasters.
  *
  * [The "next" pointer is always aligned on an even
- * boundary, and reads the offset directly as a short.  Also, there is no
- * special test to reverse the sign of BACK pointers since the offset is
- * stored negative.]
+ * boundary, and reads the offset directly as a short.]
  */
 
 /* This is the stuff that used to live in regexp.h that was truly
 #define PREGf_USE_RE_EVAL      0x00000020 /* compiled with "use re 'eval'" */
 /* these used to be extflags, but are now intflags */
 #define PREGf_NOSCAN            0x00000040
-#define PREGf_CANY_SEEN         0x00000080
+                                /* spare */
 #define PREGf_GPOS_SEEN         0x00000100
 #define PREGf_GPOS_FLOAT        0x00000200
 
@@ -216,7 +214,7 @@ struct regnode_charclass {
     U8 flags;
     U8  type;
     U16 next_off;
-    U32 arg1;
+    U32 arg1;                           /* set by set_ANYOF_arg() */
     char bitmap[ANYOF_BITMAP_SIZE];    /* only compile-time */
 };
 
@@ -234,7 +232,7 @@ struct regnode_charclass_class {
  * extra SV*, used only during its construction and which is not used by
  * regexec.c.  Note that the 'next_off' field is unused, as the SSC stands
  * alone, so there is never a next node.  Also, there is no alignment issue,
- * becase these are declared or allocated as a complete unit so the compiler
+ * because these are declared or allocated as a complete unit so the compiler
  * takes care of alignment.  This is unlike the other regnodes which are
  * allocated in terms of multiples of a single-argument regnode.  SSC nodes can
  * have a pointer field because there is no alignment issue, and because it is
@@ -245,7 +243,7 @@ struct regnode_ssc {
     U16 next_off;
     U32 arg1;
     char bitmap[ANYOF_BITMAP_SIZE];    /* both compile-time ... */
-    U32 classflags;                    /* and run-time */
+    U32 classflags;                    /* ... and run-time */
 
     /* Auxiliary, only used during construction; NULL afterwards: list of code
      * points matched */
@@ -263,7 +261,7 @@ struct regnode_ssc {
 #define set_ANYOF_SYNTHETIC(n) STMT_START{ OP(n) = ANYOF;              \
                                            NEXT_OFF(n) = 1;            \
                                } STMT_END
-#define is_ANYOF_SYNTHETIC(n) (OP(n) == ANYOF && NEXT_OFF(n) == 1)
+#define is_ANYOF_SYNTHETIC(n) (PL_regkind[OP(n)] == ANYOF && NEXT_OFF(n) == 1)
 
 /* XXX fix this description.
    Impose a limit of REG_INFTY on various pattern matching operations
@@ -361,6 +359,13 @@ struct regnode_ssc {
     (ptr)->type = op;    (ptr)->next_off = 0;   (ptr)++; } STMT_END
 #define FILL_ADVANCE_NODE_ARG(ptr, op, arg) STMT_START { \
     ARG_SET(ptr, arg);  FILL_ADVANCE_NODE(ptr, op); (ptr) += 1; } 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;                                     \
+                } STMT_END
 
 #define REG_MAGIC 0234
 
@@ -373,59 +378,99 @@ struct regnode_ssc {
  * reach this high). */
 #define ANYOF_ONLY_HAS_BITMAP  ((U32) -1)
 
-/* Flags for node->flags of ANYOF.  These are in short supply, with none
- * currently available.  The ABOVE_BITMAP_ALL bit could be freed up
+/* Below are the flags for node->flags of ANYOF.  These are in short supply,
+ * with none currently available.  The ABOVE_BITMAP_ALL bit could be freed up
  * by resorting to creating a swash containing everything above 255.  This
- * introduces a performance penalty.  An option that wouldn't slow things down
- * would be to split one of the two LOC flags out into a separate
- * node, like what was done with ANYOF_NON_UTF8_NON_ASCII_ALL in commit
- * 34fdef848b1687b91892ba55e9e0c3430e0770f6 (but which was reverted because it
- * wasn't the best option available at the time), and using a LOC flag is
- * probably better than that commit anyway.  But it could be reinstated if we
- * need a bit.  The LOC flags are only for /l nodes; the reverted commit was
- * only for /d, so there are no combinatorial issues.  The LOC flag to use is
- * probably the POSIXL one.
+ * seems likely to introduce a performance penalty (but actual numbers haven't
+ * been done), so its probably better do some of the other possibilities below
+ * in preference to this.
+ *
+ * If just one bit is required, it seems to me (khw) that the best option would
+ * be to turn the ANYOF_LOC_REQ_UTF8 bit into a separate node type: a
+ * specialization of the ANYOFL type, freeing up the currently occupied bit.
+ * When turning a bit into a node type, one has to take into consideration that
+ * a SSC may use that bit -- not just a regular ANYOF[DL]?.  In the case of
+ * ANYOF_LOC_REQ_UTF8, the only likely problem is accurately settting the SSC
+ * node-type to the new one, which would likely involve S_ssc_or and S_ssc_and,
+ * and not how the SSC currently gets set to ANYOFL.  This bit is a natural
+ * candidate for being a separate node type because it is a specialization of
+ * the current ANYOFL, and because no other ANYOFL-only bits are set when it
+ * is; also most of its uses are actually outside the reginclass() function, so
+ * this could be done with no performance penalty.  The other potential bits
+ * seem to me to have a potential issue with a combinatorial explosion of node
+ * types, because of not having that mutual exclusivity, where you may end up
+ * having to have a node type for bitX being set, one for bitY, and one for
+ * both bitXY.
+ *
+ * If you don't want to do this, or two bits are required, one could instead
+ * rename the ANYOF_POSIXL bit to be ANYOFL_LARGE, to mean that the ANYOF node
+ * has an extra 32 bits beyond what a regular one does.  That's what it
+ * effectively means now, with the extra space all for the POSIX class bits.
+ * But those classes actually only occupy 30 bits, so the ANYOF_LOC_REQ_BIT (if
+ * an extra node type for it hasn't been created) and/or the ANYOF_LOC_FOLD
+ * bits could be moved there.  The downside of this is that ANYOFL nodes with
+ * whichever of the bits get moved would have to have the extra space always
+ * allocated.
+ *
+ * If three bits are required, one could additionally make a node type for
+ * ANYOFL_LARGE, removing that as a bit, and move both the above bits to that
+ * extra word.  There isn't an SSC problem as all SSCs are this large anyway,
+ * and the SSC could be set to this node type.   REGINCLASS would have to be
+ * modified so that if the node type were this, it would call reginclass().
+ * as the flag bit that does this now would be gone.
+ *
  * Several flags are not used in synthetic start class (SSC) nodes, so could be
  * shared should new flags be needed for SSCs, like SSC_MATCHES_EMPTY_STRING
  * now. */
 
-/* regexec.c is expecting this to be in the low bit */
+/* If this is set, the result of the match should be complemented.  regexec.c
+ * is expecting this to be in the low bit.  Never in an SSC */
 #define ANYOF_INVERT                           0x01
 
 /* For the SSC node only, which cannot be inverted, so is shared with that bit.
  * This is used only during regex compilation. */
 #define SSC_MATCHES_EMPTY_STRING                ANYOF_INVERT
 
-/* Are there things outside the bitmap that will match only if the target
- * string is encoded in UTF-8?  (This is not set if ANYOF_ABOVE_BITMAP_ALL is
- * set) */
-#define ANYOF_HAS_UTF8_NONBITMAP_MATCHES        0x02
+/* Set if this is a regnode_charclass_posixl vs a regnode_charclass.  This
+ * is used for runtime \d, \w, [:posix:], ..., which are used only in locale
+ * and the optimizer's synthetic start class.  Non-locale \d, etc are resolved
+ * at compile-time.  Only set under /l; can be in SSC */
+#define ANYOF_MATCHES_POSIXL                    0x02
 
 /* The fold is calculated and stored in the bitmap where possible at compile
  * time.  However under locale, the actual folding varies depending on
  * what the locale is at the time of execution, so it has to be deferred until
- * then */
+ * then.  Only set under /l; never in an SSC  */
 #define ANYOF_LOC_FOLD                          0x04
 
-/* Set if this is a regnode_charclass_posixl vs a regnode_charclass.  This
- * is used for runtime \d, \w, [:posix:], ..., which are used only in locale
- * and the optimizer's synthetic start class.  Non-locale \d, etc are resolved
- * at compile-time */
-#define ANYOF_MATCHES_POSIXL                    0x08
+/* If set, means to warn if runtime locale isn't a UTF-8 one.  Only under /l.
+ * If set, none of INVERT, LOC_FOLD, POSIXL, HAS_NONBITMAP_NON_UTF8_MATCHES can
+ * be set.  Can be in an SSC */
+#define ANYOF_LOC_REQ_UTF8                      0x08
 
-/* Should we raise a warning if matching against an above-Unicode code point?
- * */
-#define ANYOF_WARN_SUPER                        0x10
+/* If set, the node matches every code point NUM_ANYOF_CODE_POINTS and above.
+ * Can be in an SSC */
+#define ANYOF_MATCHES_ALL_ABOVE_BITMAP          0x10
 
-/* Can match something outside the bitmap that isn't in utf8 */
+/* If set, the node can match something outside the bitmap that isn't in utf8;
+ * never set under /d nor in an SSC */
 #define ANYOF_HAS_NONBITMAP_NON_UTF8_MATCHES    0x20
 
-/* Matches every code point NUM_ANYOF_CODE_POINTS and above*/
-#define ANYOF_MATCHES_ALL_ABOVE_BITMAP          0x40
-
-/* Match all Latin1 characters that aren't ASCII when the target string is not
- * in utf8. */
-#define ANYOF_MATCHES_ALL_NON_UTF8_NON_ASCII    0x80
+/* Are there things outside the bitmap that will match only if the target
+ * string is encoded in UTF-8?  (This is not set if ANYOF_ABOVE_BITMAP_ALL is
+ * set).  Can be in SSC */
+#define ANYOF_HAS_UTF8_NONBITMAP_MATCHES        0x40
+
+/* Shared bit:
+ *      Under /d it means the ANYOFD node matches all non-ASCII Latin1
+ *          characters when the target string is not in utf8.
+ *      When not under /d, it means the ANYOF node should raise a warning if
+ *          matching against an above-Unicode code point.
+ * (These uses are mutually exclusive because the warning requires a \p{}, and
+ * \p{} implies /u which deselects /d).  An SSC node only has this bit set if
+ * what is meant is the warning.  The long macro name is to make sure that you
+ * are cautioned about its shared nature */
+#define ANYOF_SHARED_d_MATCHES_ALL_NON_UTF8_NON_ASCII_non_d_WARN_SUPER 0x80
 
 #define ANYOF_FLAGS_ALL                (0xff)
 
@@ -433,8 +478,9 @@ struct regnode_ssc {
 
 /* These are the flags that apply to both regular ANYOF nodes and synthetic
  * start class nodes during construction of the SSC.  During finalization of
- * the SSC, other of the flags could be added to it */
-#define ANYOF_COMMON_FLAGS    (ANYOF_WARN_SUPER|ANYOF_HAS_UTF8_NONBITMAP_MATCHES)
+ * the SSC, other of the flags may get added to it */
+#define ANYOF_COMMON_FLAGS    ( ANYOF_HAS_UTF8_NONBITMAP_MATCHES    \
+                               |ANYOF_LOC_REQ_UTF8)
 
 /* Character classes for node->classflags of ANYOF */
 /* Should be synchronized with a table in regprop() */
@@ -461,8 +507,6 @@ struct regnode_ssc {
 #define ANYOF_NLOWER   ((ANYOF_LOWER) + 1)
 #define ANYOF_PRINT    ((_CC_PRINT) * 2)
 #define ANYOF_NPRINT   ((ANYOF_PRINT) + 1)
-#define ANYOF_PSXSPC   ((_CC_PSXSPC) * 2)    /* POSIX space: \s plus the vertical tab */
-#define ANYOF_NPSXSPC  ((ANYOF_PSXSPC) + 1)
 #define ANYOF_PUNCT    ((_CC_PUNCT) * 2)
 #define ANYOF_NPUNCT   ((ANYOF_PUNCT) + 1)
 #define ANYOF_SPACE    ((_CC_SPACE) * 2)     /* \s */
@@ -586,7 +630,6 @@ struct regnode_ssc {
 #define REG_LOOKBEHIND_SEEN                 0x00000002
 #define REG_GPOS_SEEN                       0x00000004
 /* spare */
-#define REG_CANY_SEEN                       0x00000010
 #define REG_RECURSE_SEEN                    0x00000020
 #define REG_TOP_LEVEL_BRANCHES_SEEN         0x00000040
 #define REG_VERBARG_SEEN                    0x00000080
@@ -980,12 +1023,13 @@ re.pm, especially to the documentation.
 
 #endif /* DEBUG RELATED DEFINES */
 
+typedef enum {
+       TRADITIONAL_BOUND = _CC_WORDCHAR,
+       GCB_BOUND,
+       SB_BOUND,
+       WB_BOUND
+} bound_type;
+
 /*
- * Local variables:
- * c-indentation-style: bsd
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- *
  * ex: set ts=8 sts=4 sw=4 et:
  */