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 f418086..0b69f6e 100644 (file)
--- a/regcomp.h
+++ b/regcomp.h
 #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
 
@@ -261,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
@@ -378,67 +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.  Now that there is an ANYOFL (locale) node, another
- * option would be to make all of those include the POSIXL data structure,
- * which would get rid of needing a separate POSIXL flag.  But it would
- * increase the size of all such nodes, so it's probably not as atractive as
- * having an ANYOF_POSIXL node type.  But if we did do it, note that not all 32
- * bits of that extra space are used, one bit of that could be set aside for
- * the LOC_FOLD flag, yielding yet another bit.  This would require extra code
- * for masking, so again not the most attractive solution.
+ * 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)
 
@@ -446,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() */
@@ -597,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