3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, 2003, 2005, 2006, 2007, by Larry Wall and others
6 * You may distribute under the terms of either the GNU General Public
7 * License or the Artistic License, as specified in the README file.
11 #ifndef PERL_REGCOMP_H_
12 #define PERL_REGCOMP_H_
14 #include "regcharclass.h"
16 /* Convert branch sequences to more efficient trie ops? */
17 #define PERL_ENABLE_TRIE_OPTIMISATION 1
19 /* Be really aggressive about optimising patterns with trie sequences? */
20 #define PERL_ENABLE_EXTENDED_TRIE_OPTIMISATION 1
22 /* Should the optimiser take positive assertions into account? */
23 #define PERL_ENABLE_POSITIVE_ASSERTION_STUDY 0
25 /* Not for production use: */
26 #define PERL_ENABLE_EXPERIMENTAL_REGEX_OPTIMISATIONS 0
28 /* Activate offsets code - set to if 1 to enable */
30 #define RE_TRACK_PATTERN_OFFSETS
34 * The "internal use only" fields in regexp.h are present to pass info from
35 * compile to execute that permits the execute phase to run lots faster on
36 * simple cases. They are:
38 * regstart sv that must begin a match; NULL if none obvious
39 * reganch is the match anchored (at beginning-of-line only)?
40 * regmust string (pointer into program) that match must include, or NULL
41 * [regmust changed to SV* for bminstr()--law]
42 * regmlen length of regmust string
43 * [regmlen not used currently]
45 * Regstart and reganch permit very fast decisions on suitable starting points
46 * for a match, cutting down the work a lot. Regmust permits fast rejection
47 * of lines that cannot possibly match. The regmust tests are costly enough
48 * that pregcomp() supplies a regmust only if the r.e. contains something
49 * potentially expensive (at present, the only such thing detected is * or +
50 * at the start of the r.e., which can involve a lot of backup). Regmlen is
51 * supplied because the test in pregexec() needs it and pregcomp() is computing
53 * [regmust is now supplied always. The tests that use regmust have a
54 * heuristic that disables the test if it usually matches.]
56 * [In fact, we now use regmust in many cases to locate where the search
57 * starts in the string, so if regback is >= 0, the regmust search is never
58 * wasted effort. The regback variable says how many characters back from
59 * where regmust matched is the earliest possible start of the match.
60 * For instance, /[a-z].foo/ has a regmust of 'foo' and a regback of 2.]
64 * Structure for regexp "program". This is essentially a linear encoding
65 * of a nondeterministic finite-state machine (aka syntax charts or
66 * "railroad normal form" in parsing technology). Each node is an opcode
67 * plus a "next" pointer, possibly plus an operand. "Next" pointers of
68 * all nodes except BRANCH implement concatenation; a "next" pointer with
69 * a BRANCH on both ends of it is connecting two alternatives. (Here we
70 * have one of the subtle syntax dependencies: an individual BRANCH (as
71 * opposed to a collection of them) is never concatenated with anything
72 * because of operator precedence.) The operand of some types of node is
73 * a literal string; for others, it is a node leading into a sub-FSM. In
74 * particular, the operand of a BRANCH node is the first node of the branch.
75 * (NB this is *not* a tree structure: the tail of the branch connects
76 * to the thing following the set of BRANCHes.) The opcodes are defined
77 * in regnodes.h which is generated from regcomp.sym by regcomp.pl.
81 * A node is one char of opcode followed by two chars of "next" pointer.
82 * "Next" pointers are stored as two 8-bit pieces, high order first. The
83 * value is a positive offset from the opcode of the node containing it.
84 * An operand, if any, simply follows the node. (Note that much of the
85 * code generation knows about this implicit relationship.)
87 * Using two bytes for the "next" pointer is vast overkill for most things,
88 * but allows patterns to get big without disasters.
90 * [The "next" pointer is always aligned on an even
91 * boundary, and reads the offset directly as a short.]
94 /* This is the stuff that used to live in regexp.h that was truly
95 private to the engine itself. It now lives here. */
97 typedef struct regexp_internal {
98 int name_list_idx; /* Optional data index of an array of paren names */
100 U32 *offsets; /* offset annotations 20001228 MJD
101 data about mapping the program to the
103 offsets[0] is proglen when this is used
108 regnode *regstclass; /* Optional startclass as identified or constructed
110 struct reg_data *data; /* Additional miscellaneous data used by the program.
111 Used to make it easier to clone and free arbitrary
112 data that the regops need. Often the ARG field of
113 a regop is an index into this structure */
114 struct reg_code_blocks *code_blocks;/* positions of literal (?{}) */
115 regnode program[1]; /* Unwarranted chumminess with compiler. */
118 #define RXi_SET(x,y) (x)->pprivate = (void*)(y)
119 #define RXi_GET(x) ((regexp_internal *)((x)->pprivate))
120 #define RXi_GET_DECL(r,ri) regexp_internal *ri = RXi_GET(r)
122 * Flags stored in regexp->intflags
123 * These are used only internally to the regexp engine
125 * See regexp.h for flags used externally to the regexp engine
127 #define RXp_INTFLAGS(rx) ((rx)->intflags)
128 #define RX_INTFLAGS(prog) RXp_INTFLAGS(ReANY(prog))
130 #define PREGf_SKIP 0x00000001
131 #define PREGf_IMPLICIT 0x00000002 /* Converted .* to ^.* */
132 #define PREGf_NAUGHTY 0x00000004 /* how exponential is this pattern? */
133 #define PREGf_VERBARG_SEEN 0x00000008
134 #define PREGf_CUTGROUP_SEEN 0x00000010
135 #define PREGf_USE_RE_EVAL 0x00000020 /* compiled with "use re 'eval'" */
136 /* these used to be extflags, but are now intflags */
137 #define PREGf_NOSCAN 0x00000040
139 #define PREGf_GPOS_SEEN 0x00000100
140 #define PREGf_GPOS_FLOAT 0x00000200
142 #define PREGf_ANCH_MBOL 0x00000400
143 #define PREGf_ANCH_SBOL 0x00000800
144 #define PREGf_ANCH_GPOS 0x00001000
145 #define PREGf_RECURSE_SEEN 0x00002000
148 ( PREGf_ANCH_SBOL | PREGf_ANCH_GPOS | PREGf_ANCH_MBOL )
150 /* this is where the old regcomp.h started */
152 struct regnode_string {
159 struct regnode_lstring { /* Constructed this way to keep the string aligned. */
163 U32 str_len; /* Only 18 bits allowed before would overflow 'next_off' */
167 /* Argument bearing node - workhorse,
168 arg1 is often for the data field */
176 /* Similar to a regnode_1 but with an extra signed argument */
185 /* 'Two field' -- Two 16 bit unsigned args */
194 /* This give the number of code points that can be in the bitmap of an ANYOF
195 * node. The shift number must currently be one of: 8..12. It can't be less
196 * than 8 (256) because some code relies on it being at least that. Above 12
197 * (4096), and you start running into warnings that some data structure widths
198 * have been exceeded, though the test suite as of this writing still passes
199 * for up through 16, which is as high as anyone would ever want to go,
200 * encompassing all of the Unicode BMP, and thus including all the economically
201 * important world scripts. At 12 most of them are: including Arabic,
202 * Cyrillic, Greek, Hebrew, Indian subcontinent, Latin, and Thai; but not Han,
203 * Japanese, nor Korean. (The regarglen structure in regnodes.h is a U8, and
204 * the trie types TRIEC and AHOCORASICKC are larger than U8 for shift values
205 * above 12.) Be sure to benchmark before changing, as larger sizes do
206 * significantly slow down the test suite */
207 #define NUM_ANYOF_CODE_POINTS (1 << 8)
209 #define ANYOF_BITMAP_SIZE (NUM_ANYOF_CODE_POINTS / 8) /* 8 bits/Byte */
211 /* Note that these form structs which are supersets of the next smaller one, by
212 * appending fields. Alignment problems can occur if one of those optional
213 * fields requires stricter alignment than the base struct. And formal
214 * parameters that can really be two or more of the structs should be
215 * declared as the smallest one it could be. See commit message for
216 * 7dcac5f6a5195002b55c935ee1d67f67e1df280b. Regnode allocation is done
217 * without regard to alignment, and changing it to would also require changing
218 * the code that inserts and deletes regnodes. The basic single-argument
219 * regnode has a U32, which is what reganode() allocates as a unit. Therefore
220 * no field can require stricter alignment than U32. */
222 /* also used by trie */
223 struct regnode_charclass {
227 U32 arg1; /* set by set_ANYOF_arg() */
228 char bitmap[ANYOF_BITMAP_SIZE]; /* only compile-time */
231 /* has runtime (locale) \d, \w, ..., [:posix:] classes */
232 struct regnode_charclass_posixl {
233 U8 flags; /* ANYOF_MATCHES_POSIXL bit must go here */
237 char bitmap[ANYOF_BITMAP_SIZE]; /* both compile-time ... */
238 U32 classflags; /* and run-time */
241 /* A synthetic start class (SSC); is a regnode_charclass_posixl_fold, plus an
242 * extra SV*, used only during its construction and which is not used by
243 * regexec.c. Note that the 'next_off' field is unused, as the SSC stands
244 * alone, so there is never a next node. Also, there is no alignment issue,
245 * because these are declared or allocated as a complete unit so the compiler
246 * takes care of alignment. This is unlike the other regnodes which are
247 * allocated in terms of multiples of a single-argument regnode. SSC nodes can
248 * have a pointer field because there is no alignment issue, and because it is
249 * set to NULL after construction, before any cloning of the pattern */
251 U8 flags; /* ANYOF_MATCHES_POSIXL bit must go here */
255 char bitmap[ANYOF_BITMAP_SIZE]; /* both compile-time ... */
256 U32 classflags; /* ... and run-time */
258 /* Auxiliary, only used during construction; NULL afterwards: list of code
263 /* We take advantage of 'next_off' not otherwise being used in the SSC by
264 * actually using it: by setting it to 1. This allows us to test and
265 * distinguish between an SSC and other ANYOF node types, as 'next_off' cannot
266 * otherwise be 1, because it is the offset to the next regnode expressed in
267 * units of regnodes. Since an ANYOF node contains extra fields, it adds up
268 * to 12 regnode units on 32-bit systems, (hence the minimum this can be (if
269 * not 0) is 11 there. Even if things get tightly packed on a 64-bit system,
270 * it still would be more than 1. */
271 #define set_ANYOF_SYNTHETIC(n) STMT_START{ OP(n) = ANYOF; \
274 #define is_ANYOF_SYNTHETIC(n) (PL_regkind[OP(n)] == ANYOF && NEXT_OFF(n) == 1)
276 /* XXX fix this description.
277 Impose a limit of REG_INFTY on various pattern matching operations
278 to limit stack growth and to avoid "infinite" recursions.
280 /* The default size for REG_INFTY is U16_MAX, which is the same as
281 USHORT_MAX (see perl.h). Unfortunately U16 isn't necessarily 16 bits
282 (see handy.h). On the Cray C90, sizeof(short)==4 and hence U16_MAX is
283 ((1<<32)-1), while on the Cray T90, sizeof(short)==8 and U16_MAX is
284 ((1<<64)-1). To limit stack growth to reasonable sizes, supply a
286 --Andy Dougherty 11 June 1998
290 # define REG_INFTY ((1<<16)-1)
295 # define REG_INFTY U16_MAX
298 #define ARG_VALUE(arg) (arg)
299 #define ARG__SET(arg,val) ((arg) = (val))
305 #define ARG(p) ARG_VALUE(ARG_LOC(p))
306 #define ARG1(p) ARG_VALUE(ARG1_LOC(p))
307 #define ARG2(p) ARG_VALUE(ARG2_LOC(p))
308 #define ARG2L(p) ARG_VALUE(ARG2L_LOC(p))
310 #define ARG_SET(p, val) ARG__SET(ARG_LOC(p), (val))
311 #define ARG1_SET(p, val) ARG__SET(ARG1_LOC(p), (val))
312 #define ARG2_SET(p, val) ARG__SET(ARG2_LOC(p), (val))
313 #define ARG2L_SET(p, val) ARG__SET(ARG2L_LOC(p), (val))
318 #define NEXT_OFF(p) ((p)->next_off)
319 #define NODE_ALIGN(node)
320 /* the following define was set to 0xde in 075abff3
321 * as part of some linting logic. I have set it to 0
322 * as otherwise in every place where we /might/ set flags
323 * we have to set it 0 explicitly, which duplicates
324 * assignments and IMO adds an unacceptable level of
325 * surprise to working in the regex engine. If this
326 * is changed from 0 then at the very least make sure
327 * that SBOL for /^/ sets the flags to 0 explicitly.
329 #define NODE_ALIGN_FILL(node) ((node)->flags = 0)
331 #define SIZE_ALIGN NODE_ALIGN
337 #define OP(p) ((p)->type)
338 #define FLAGS(p) ((p)->flags) /* Caution: Doesn't apply to all \
339 regnode types. For some, it's the \
340 character set of the regnode */
341 #define STR_LENs(p) (__ASSERT_(OP(p) != LEXACT && OP(p) != LEXACT_REQ8) \
342 ((struct regnode_string *)p)->str_len)
343 #define STRINGs(p) (__ASSERT_(OP(p) != LEXACT && OP(p) != LEXACT_REQ8) \
344 ((struct regnode_string *)p)->string)
345 #define OPERANDs(p) STRINGs(p)
347 /* Long strings. Currently limited to length 18 bits, which handles a 262000
348 * byte string. The limiting factor is the 16 bit 'next_off' field, which
349 * points to the next regnode, so the furthest away it can be is 2**16. On
350 * most architectures, regnodes are 2**2 bytes long, so that yields 2**18
351 * bytes. Should a longer string be desired, we could increase it to 26 bits
352 * fairly easily, by changing this node to have longj type which causes the ARG
353 * field to be used for the link to the next regnode (although code would have
354 * to be changed to account for this), and then use a combination of the flags
355 * and next_off fields for the length. To get 34 bit length, also change the
356 * node to be an ARG2L, using the second 32 bit field for the length, and not
357 * using the flags nor next_off fields at all. One could have an llstring node
358 * and even an lllstring type. */
359 #define STR_LENl(p) (__ASSERT_(OP(p) == LEXACT || OP(p) == LEXACT_REQ8) \
360 (((struct regnode_lstring *)p)->str_len))
361 #define STRINGl(p) (__ASSERT_(OP(p) == LEXACT || OP(p) == LEXACT_REQ8) \
362 (((struct regnode_lstring *)p)->string))
363 #define OPERANDl(p) STRINGl(p)
365 #define STR_LEN(p) ((OP(p) == LEXACT || OP(p) == LEXACT_REQ8) \
366 ? STR_LENl(p) : STR_LENs(p))
367 #define STRING(p) ((OP(p) == LEXACT || OP(p) == LEXACT_REQ8) \
368 ? STRINGl(p) : STRINGs(p))
369 #define OPERAND(p) STRING(p)
371 /* The number of (smallest) regnode equivalents that a string of length l bytes
373 #define STR_SZ(l) (((l) + sizeof(regnode) - 1) / sizeof(regnode))
375 /* The number of (smallest) regnode equivalents that the EXACTISH node 'p'
377 #define NODE_SZ_STR(p) (STR_SZ(STR_LEN(p)) + 1 + regarglen[(p)->type])
379 #define setSTR_LEN(p,v) \
381 if (OP(p) == LEXACT || OP(p) == LEXACT_REQ8) \
382 ((struct regnode_lstring *)(p))->str_len = (v); \
384 ((struct regnode_string *)(p))->str_len = (v); \
387 #define ANYOFR_BASE_BITS 20
388 #define ANYOFRbase(p) (ARG(p) & ((1 << ANYOFR_BASE_BITS) - 1))
389 #define ANYOFRdelta(p) (ARG(p) >> ANYOFR_BASE_BITS)
396 #define NODE_ALIGN(node)
397 #define ARG_LOC(p) (((struct regnode_1 *)p)->arg1)
398 #define ARG1_LOC(p) (((struct regnode_2 *)p)->arg1)
399 #define ARG2_LOC(p) (((struct regnode_2 *)p)->arg2)
400 #define ARG2L_LOC(p) (((struct regnode_2L *)p)->arg2)
402 #define NODE_STEP_REGNODE 1 /* sizeof(regnode)/sizeof(regnode) */
403 #define EXTRA_STEP_2ARGS EXTRA_SIZE(struct regnode_2)
405 #define NODE_STEP_B 4
407 #define NEXTOPER(p) ((p) + NODE_STEP_REGNODE)
408 #define PREVOPER(p) ((p) - NODE_STEP_REGNODE)
410 #define FILL_NODE(offset, op) \
412 OP(REGNODE_p(offset)) = op; \
413 NEXT_OFF(REGNODE_p(offset)) = 0; \
415 #define FILL_ADVANCE_NODE(offset, op) \
417 FILL_NODE(offset, op); \
420 #define FILL_ADVANCE_NODE_ARG(offset, op, arg) \
422 ARG_SET(REGNODE_p(offset), arg); \
423 FILL_ADVANCE_NODE(offset, op); \
424 /* This is used generically for other operations \
425 * that have a longer argument */ \
426 (offset) += regarglen[op]; \
428 #define FILL_ADVANCE_NODE_2L_ARG(offset, op, arg1, arg2) \
430 ARG_SET(REGNODE_p(offset), arg1); \
431 ARG2L_SET(REGNODE_p(offset), arg2); \
432 FILL_ADVANCE_NODE(offset, op); \
436 #define REG_MAGIC 0234
438 /* An ANYOF node is basically a bitmap with the index being a code point. If
439 * the bit for that code point is 1, the code point matches; if 0, it doesn't
440 * match (complemented if inverted). There is an additional mechanism to deal
441 * with cases where the bitmap is insufficient in and of itself. This #define
442 * indicates if the bitmap does fully represent what this ANYOF node can match.
443 * The ARG is set to this special value (since 0, 1, ... are legal, but will
444 * never reach this high). */
445 #define ANYOF_ONLY_HAS_BITMAP ((U32) -1)
447 /* When the bitmap isn't completely sufficient for handling the ANYOF node,
448 * flags (in node->flags of the ANYOF node) get set to indicate this. These
449 * are perennially in short supply. Beyond several cases where warnings need
450 * to be raised under certain circumstances, currently, there are six cases
451 * where the bitmap alone isn't sufficient. We could use six flags to
452 * represent the 6 cases, but to save flags bits, we play some games. The
455 * 1) The bitmap has a compiled-in very finite size. So something else needs
456 * to be used to specify if a code point that is too large for the bitmap
457 * actually matches. The mechanism currently is an inversion
458 * list. ANYOF_ONLY_HAS_BITMAP, described above, being TRUE indicates
459 * there are no matches of too-large code points. But if it is FALSE,
460 * then almost certainly there are matches too large for the bitmap. (The
461 * other cases, described below, either imply this one or are extremely
462 * rare in practice.) So we can just assume that a too-large code point
463 * will need something beyond the bitmap if ANYOF_ONLY_HAS_BITMAP is
464 * FALSE, instead of having a separate flag for this.
465 * 2) A subset of item 1) is if all possible code points outside the bitmap
466 * match. This is a common occurrence when the class is complemented,
467 * like /[^ij]/. Therefore a bit is reserved to indicate this,
468 * rather than having an inversion list created,
469 * ANYOF_MATCHES_ALL_ABOVE_BITMAP.
470 * 3) Under /d rules, it can happen that code points that are in the upper
471 * latin1 range (\x80-\xFF or their equivalents on EBCDIC platforms) match
472 * only if the runtime target string being matched against is UTF-8. For
473 * example /[\w[:punct:]]/d. This happens only for posix classes (with a
474 * couple of exceptions, like \d where it doesn't happen), and all such
475 * ones also have above-bitmap matches. Thus, 3) implies 1) as well.
476 * Note that /d rules are no longer encouraged; 'use 5.14' or higher
477 * deselects them. But a flag is required so that they can be properly
478 * handled. But it can be a shared flag: see 5) below.
479 * 4) Also under /d rules, something like /[\Wfoo]/ will match everything in
480 * the \x80-\xFF range, unless the string being matched against is UTF-8.
481 * An inversion list could be created for this case, but this is
482 * relatively common, and it turns out that it's all or nothing: if any
483 * one of these code points matches, they all do. Hence a single bit
484 * suffices. We use a shared flag that doesn't take up space by itself:
485 * ANYOF_SHARED_d_MATCHES_ALL_NON_UTF8_NON_ASCII_non_d_WARN_SUPER. This
486 * also implies 1), with one exception: [:^cntrl:].
487 * 5) A user-defined \p{} property may not have been defined by the time the
488 * regex is compiled. In this case, we don't know until runtime what it
489 * will match, so we have to assume it could match anything, including
490 * code points that ordinarily would be in the bitmap. A flag bit is
491 * necessary to indicate this , though it can be shared with the item 3)
492 * flag, as that only occurs under /d, and this only occurs under non-d.
493 * This case is quite uncommon in the field, and the /(?[ ...])/ construct
494 * is a better way to accomplish what this feature does. This case also
496 * ANYOF_SHARED_d_UPPER_LATIN1_UTF8_STRING_MATCHES_non_d_RUNTIME_USER_PROP
497 * is the shared flag.
498 * 6) /[foo]/il may have folds that are only valid if the runtime locale is a
499 * UTF-8 one. These are quite rare, so it would be good to avoid the
500 * expense of looking for them. But /l matching is slow anyway, and we've
501 * traditionally not worried too much about its performance. And this
502 * condition requires the ANYOFL_FOLD flag to be set, so testing for
503 * that flag would be sufficient to rule out most cases of this. So it is
504 * unclear if this should have a flag or not. But, this flag can be
505 * shared with another, so it doesn't occupy extra space.
507 * At the moment, there is one spare bit, but this could be increased by
510 * If just one more bit is needed, as of this writing it seems to khw that the
511 * best choice would be to make ANYOF_MATCHES_ALL_ABOVE_BITMAP not a flag, but
514 * #define ANYOF_MATCHES_ALL_ABOVE_BITMAP ((U32) -2)
516 * and access it through the ARG like ANYOF_ONLY_HAS_BITMAP is. This flag is
517 * used by all ANYOF node types, and it could be used to avoid calling the
518 * handler function, as the macro REGINCLASS in regexec.c does now for other
521 * Another possibility is based on the fact that ANYOF_MATCHES_POSIXL is
522 * redundant with the node type ANYOFPOSIXL. That flag could be removed, but
523 * at the expense of extra code in regexec.c. The flag has been retained
524 * because it allows us to see if we need to call reginsert, or just use the
525 * bitmap in one test.
527 * If this is done, an extension would be to make all ANYOFL nodes contain the
528 * extra 32 bits that ANYOFPOSIXL ones do. The posix flags only occupy 30
529 * bits, so the ANYOFL_SHARED_UTF8_LOCALE_fold_HAS_MATCHES_nonfold_REQD flags
530 * and ANYOFL_FOLD could be moved to that extra space, but it would mean extra
531 * instructions, as there are currently places in the code that assume those
534 * All told, 5 bits could be available for other uses if all of the above were
537 * Some flags are not used in synthetic start class (SSC) nodes, so could be
538 * shared should new flags be needed for SSCs, like SSC_MATCHES_EMPTY_STRING
541 /* If this is set, the result of the match should be complemented. regexec.c
542 * is expecting this to be in the low bit. Never in an SSC */
543 #define ANYOF_INVERT 0x01
545 /* For the SSC node only, which cannot be inverted, so is shared with that bit.
546 * This is used only during regex compilation. */
547 #define SSC_MATCHES_EMPTY_STRING ANYOF_INVERT
549 /* Set if this is a regnode_charclass_posixl vs a regnode_charclass. This
550 * is used for runtime \d, \w, [:posix:], ..., which are used only in locale
551 * and the optimizer's synthetic start class. Non-locale \d, etc are resolved
552 * at compile-time. Only set under /l; can be in SSC */
553 #define ANYOF_MATCHES_POSIXL 0x02
555 /* The fold is calculated and stored in the bitmap where possible at compile
556 * time. However under locale, the actual folding varies depending on
557 * what the locale is at the time of execution, so it has to be deferred until
558 * then. Only set under /l; never in an SSC */
559 #define ANYOFL_FOLD 0x04
561 /* Shared bit set only with ANYOFL and SSC nodes:
562 * If ANYOFL_FOLD is set, this flag indicates there are potential matches
563 * valid only if the locale is a UTF-8 one.
564 * If ANYOFL_FOLD is NOT set, this flag means to warn if the runtime locale
565 * isn't a UTF-8 one (and the generated node assumes a UTF-8 locale).
566 * None of INVERT, POSIXL,
567 * ANYOF_SHARED_d_UPPER_LATIN1_UTF8_STRING_MATCHES_non_d_RUNTIME_USER_PROP
569 #define ANYOFL_SHARED_UTF8_LOCALE_fold_HAS_MATCHES_nonfold_REQD 0x08
571 /* Convenience macros for teasing apart the meanings when reading the above bit
573 #define ANYOFL_SOME_FOLDS_ONLY_IN_UTF8_LOCALE(flags) \
574 ((flags & ( ANYOFL_FOLD /* Both bits are set */ \
575 |ANYOFL_SHARED_UTF8_LOCALE_fold_HAS_MATCHES_nonfold_REQD)) \
577 |ANYOFL_SHARED_UTF8_LOCALE_fold_HAS_MATCHES_nonfold_REQD))
579 #define ANYOFL_UTF8_LOCALE_REQD(flags) \
580 ((flags & ( ANYOFL_FOLD /* Only REQD bit is set */ \
581 |ANYOFL_SHARED_UTF8_LOCALE_fold_HAS_MATCHES_nonfold_REQD)) \
582 == ANYOFL_SHARED_UTF8_LOCALE_fold_HAS_MATCHES_nonfold_REQD)
584 /* Spare: Be sure to change ANYOF_FLAGS_ALL if this gets used 0x10 */
586 /* If set, the node matches every code point NUM_ANYOF_CODE_POINTS and above.
587 * Can be in an SSC */
588 #define ANYOF_MATCHES_ALL_ABOVE_BITMAP 0x20
591 * Under /d it means the ANYOFD node matches more things if the target
592 * string is encoded in UTF-8; any such things will be non-ASCII,
593 * characters that are < 256, and can be accessed via the inversion
595 * When not under /d, it means the ANYOF node contains a user-defined
596 * property that wasn't yet defined at the time the regex was compiled,
597 * and so must be looked up at runtime, by creating an inversion list.
598 * (These uses are mutually exclusive because a user-defined property is
599 * specified by \p{}, and \p{} implies /u which deselects /d). The long macro
600 * name is to make sure that you are cautioned about its shared nature. Only
601 * the non-/d meaning can be in an SSC */
602 #define ANYOF_SHARED_d_UPPER_LATIN1_UTF8_STRING_MATCHES_non_d_RUNTIME_USER_PROP 0x40
605 * Under /d it means the ANYOFD node matches all non-ASCII Latin1
606 * characters when the target string is not in utf8.
607 * When not under /d, it means the ANYOF node should raise a warning if
608 * matching against an above-Unicode code point.
609 * (These uses are mutually exclusive because the warning requires a \p{}, and
610 * \p{} implies /u which deselects /d). An SSC node only has this bit set if
611 * what is meant is the warning. The long macro name is to make sure that you
612 * are cautioned about its shared nature */
613 #define ANYOF_SHARED_d_MATCHES_ALL_NON_UTF8_NON_ASCII_non_d_WARN_SUPER 0x80
615 #define ANYOF_FLAGS_ALL (0xff & ~0x10)
617 #define ANYOF_LOCALE_FLAGS (ANYOFL_FOLD | ANYOF_MATCHES_POSIXL)
619 /* These are the flags that apply to both regular ANYOF nodes and synthetic
620 * start class nodes during construction of the SSC. During finalization of
621 * the SSC, other of the flags may get added to it */
622 #define ANYOF_COMMON_FLAGS 0
624 /* Character classes for node->classflags of ANYOF */
625 /* Should be synchronized with a table in regprop() */
626 /* 2n should be the normal one, paired with its complement at 2n+1 */
628 #define ANYOF_ALPHA ((_CC_ALPHA) * 2)
629 #define ANYOF_NALPHA ((ANYOF_ALPHA) + 1)
630 #define ANYOF_ALPHANUMERIC ((_CC_ALPHANUMERIC) * 2) /* [[:alnum:]] isalnum(3), utf8::IsAlnum */
631 #define ANYOF_NALPHANUMERIC ((ANYOF_ALPHANUMERIC) + 1)
632 #define ANYOF_ASCII ((_CC_ASCII) * 2)
633 #define ANYOF_NASCII ((ANYOF_ASCII) + 1)
634 #define ANYOF_BLANK ((_CC_BLANK) * 2) /* GNU extension: space and tab: non-vertical space */
635 #define ANYOF_NBLANK ((ANYOF_BLANK) + 1)
636 #define ANYOF_CASED ((_CC_CASED) * 2) /* Pseudo class for [:lower:] or
637 [:upper:] under /i */
638 #define ANYOF_NCASED ((ANYOF_CASED) + 1)
639 #define ANYOF_CNTRL ((_CC_CNTRL) * 2)
640 #define ANYOF_NCNTRL ((ANYOF_CNTRL) + 1)
641 #define ANYOF_DIGIT ((_CC_DIGIT) * 2) /* \d */
642 #define ANYOF_NDIGIT ((ANYOF_DIGIT) + 1)
643 #define ANYOF_GRAPH ((_CC_GRAPH) * 2)
644 #define ANYOF_NGRAPH ((ANYOF_GRAPH) + 1)
645 #define ANYOF_LOWER ((_CC_LOWER) * 2)
646 #define ANYOF_NLOWER ((ANYOF_LOWER) + 1)
647 #define ANYOF_PRINT ((_CC_PRINT) * 2)
648 #define ANYOF_NPRINT ((ANYOF_PRINT) + 1)
649 #define ANYOF_PUNCT ((_CC_PUNCT) * 2)
650 #define ANYOF_NPUNCT ((ANYOF_PUNCT) + 1)
651 #define ANYOF_SPACE ((_CC_SPACE) * 2) /* \s */
652 #define ANYOF_NSPACE ((ANYOF_SPACE) + 1)
653 #define ANYOF_UPPER ((_CC_UPPER) * 2)
654 #define ANYOF_NUPPER ((ANYOF_UPPER) + 1)
655 #define ANYOF_WORDCHAR ((_CC_WORDCHAR) * 2) /* \w, PL_utf8_alnum, utf8::IsWord, ALNUM */
656 #define ANYOF_NWORDCHAR ((ANYOF_WORDCHAR) + 1)
657 #define ANYOF_XDIGIT ((_CC_XDIGIT) * 2)
658 #define ANYOF_NXDIGIT ((ANYOF_XDIGIT) + 1)
660 /* pseudo classes below this, not stored in the class bitmap, but used as flags
661 during compilation of char classes */
663 #define ANYOF_VERTWS ((_CC_VERTSPACE) * 2)
664 #define ANYOF_NVERTWS ((ANYOF_VERTWS)+1)
666 /* It is best if this is the last one, as all above it are stored as bits in a
667 * bitmap, and it isn't part of that bitmap */
668 #if _CC_VERTSPACE != _HIGHEST_REGCOMP_DOT_H_SYNC
669 # error Problem with handy.h _HIGHEST_REGCOMP_DOT_H_SYNC #define
672 #define ANYOF_POSIXL_MAX (ANYOF_VERTWS) /* So upper loop limit is written:
674 * Hence doesn't include VERTWS, as that
675 * is a pseudo class */
676 #define ANYOF_MAX ANYOF_POSIXL_MAX
678 #if (ANYOF_POSIXL_MAX > 32) /* Must fit in 32-bit word */
679 # error Problem with handy.h _CC_foo #defines
682 #define ANYOF_HORIZWS ((ANYOF_POSIXL_MAX)+2) /* = (ANYOF_NVERTWS + 1) */
683 #define ANYOF_NHORIZWS ((ANYOF_POSIXL_MAX)+3)
685 #define ANYOF_UNIPROP ((ANYOF_POSIXL_MAX)+4) /* Used to indicate a Unicode
686 property: \p{} or \P{} */
688 /* Backward source code compatibility. */
690 #define ANYOF_ALNUML ANYOF_ALNUM
691 #define ANYOF_NALNUML ANYOF_NALNUM
692 #define ANYOF_SPACEL ANYOF_SPACE
693 #define ANYOF_NSPACEL ANYOF_NSPACE
694 #define ANYOF_ALNUM ANYOF_WORDCHAR
695 #define ANYOF_NALNUM ANYOF_NWORDCHAR
697 /* Utility macros for the bitmap and classes of ANYOF */
699 #define ANYOF_FLAGS(p) ((p)->flags)
701 #define ANYOF_BIT(c) (1U << ((c) & 7))
703 #define POSIXL_SET(field, c) ((field) |= (1U << (c)))
704 #define ANYOF_POSIXL_SET(p, c) POSIXL_SET(((regnode_charclass_posixl*) (p))->classflags, (c))
706 #define POSIXL_CLEAR(field, c) ((field) &= ~ (1U <<(c)))
707 #define ANYOF_POSIXL_CLEAR(p, c) POSIXL_CLEAR(((regnode_charclass_posixl*) (p))->classflags, (c))
709 #define POSIXL_TEST(field, c) ((field) & (1U << (c)))
710 #define ANYOF_POSIXL_TEST(p, c) POSIXL_TEST(((regnode_charclass_posixl*) (p))->classflags, (c))
712 #define POSIXL_ZERO(field) STMT_START { (field) = 0; } STMT_END
713 #define ANYOF_POSIXL_ZERO(ret) POSIXL_ZERO(((regnode_charclass_posixl*) (ret))->classflags)
715 #define ANYOF_POSIXL_SET_TO_BITMAP(p, bits) \
717 ((regnode_charclass_posixl*) (p))->classflags = (bits); \
720 /* Shifts a bit to get, eg. 0x4000_0000, then subtracts 1 to get 0x3FFF_FFFF */
721 #define ANYOF_POSIXL_SETALL(ret) STMT_START { ((regnode_charclass_posixl*) (ret))->classflags = ((1U << ((ANYOF_POSIXL_MAX) - 1))) - 1; } STMT_END
722 #define ANYOF_CLASS_SETALL(ret) ANYOF_POSIXL_SETALL(ret)
724 #define ANYOF_POSIXL_TEST_ANY_SET(p) \
725 ((ANYOF_FLAGS(p) & ANYOF_MATCHES_POSIXL) \
726 && (((regnode_charclass_posixl*)(p))->classflags))
727 #define ANYOF_CLASS_TEST_ANY_SET(p) ANYOF_POSIXL_TEST_ANY_SET(p)
729 /* Since an SSC always has this field, we don't have to test for that; nor do
730 * we want to because the bit isn't set for SSC during its construction */
731 #define ANYOF_POSIXL_SSC_TEST_ANY_SET(p) \
732 cBOOL(((regnode_ssc*)(p))->classflags)
733 #define ANYOF_POSIXL_SSC_TEST_ALL_SET(p) /* Are all bits set? */ \
734 (((regnode_ssc*) (p))->classflags \
735 == ((1U << ((ANYOF_POSIXL_MAX) - 1))) - 1)
737 #define ANYOF_POSIXL_TEST_ALL_SET(p) \
738 ((ANYOF_FLAGS(p) & ANYOF_MATCHES_POSIXL) \
739 && ((regnode_charclass_posixl*) (p))->classflags \
740 == ((1U << ((ANYOF_POSIXL_MAX) - 1))) - 1)
742 #define ANYOF_POSIXL_OR(source, dest) STMT_START { (dest)->classflags |= (source)->classflags ; } STMT_END
743 #define ANYOF_CLASS_OR(source, dest) ANYOF_POSIXL_OR((source), (dest))
745 #define ANYOF_POSIXL_AND(source, dest) STMT_START { (dest)->classflags &= (source)->classflags ; } STMT_END
747 #define ANYOF_BITMAP_ZERO(ret) Zero(((regnode_charclass*)(ret))->bitmap, ANYOF_BITMAP_SIZE, char)
748 #define ANYOF_BITMAP(p) ((regnode_charclass*)(p))->bitmap
749 #define ANYOF_BITMAP_BYTE(p, c) BITMAP_BYTE(ANYOF_BITMAP(p), c)
750 #define ANYOF_BITMAP_SET(p, c) (ANYOF_BITMAP_BYTE(p, c) |= ANYOF_BIT(c))
751 #define ANYOF_BITMAP_CLEAR(p,c) (ANYOF_BITMAP_BYTE(p, c) &= ~ANYOF_BIT(c))
752 #define ANYOF_BITMAP_TEST(p, c) cBOOL(ANYOF_BITMAP_BYTE(p, c) & ANYOF_BIT(c))
754 #define ANYOF_BITMAP_SETALL(p) \
755 memset (ANYOF_BITMAP(p), 255, ANYOF_BITMAP_SIZE)
756 #define ANYOF_BITMAP_CLEARALL(p) \
757 Zero (ANYOF_BITMAP(p), ANYOF_BITMAP_SIZE)
760 * Utility definitions.
763 # define UCHARAT(p) ((int)*(const U8*)(p))
765 # define UCHARAT(p) ((int)*(p)&CHARMASK)
768 /* Number of regnode equivalents that 'guy' occupies beyond the size of the
769 * smallest regnode. */
770 #define EXTRA_SIZE(guy) ((sizeof(guy)-1)/sizeof(struct regnode))
772 #define REG_ZERO_LEN_SEEN 0x00000001
773 #define REG_LOOKBEHIND_SEEN 0x00000002
774 #define REG_GPOS_SEEN 0x00000004
776 #define REG_RECURSE_SEEN 0x00000020
777 #define REG_TOP_LEVEL_BRANCHES_SEEN 0x00000040
778 #define REG_VERBARG_SEEN 0x00000080
779 #define REG_CUTGROUP_SEEN 0x00000100
780 #define REG_RUN_ON_COMMENT_SEEN 0x00000200
781 #define REG_UNFOLDED_MULTI_SEEN 0x00000400
783 #define REG_UNBOUNDED_QUANTIFIER_SEEN 0x00001000
788 #ifdef PLUGGABLE_RE_EXTENSION
789 #include "re_nodes.h"
791 #include "regnodes.h"
794 #ifndef PLUGGABLE_RE_EXTENSION
796 EXTCONST regexp_engine PL_core_reg_engine;
798 EXTCONST regexp_engine PL_core_reg_engine = {
801 Perl_re_intuit_start,
802 Perl_re_intuit_string,
803 Perl_regfree_internal,
804 Perl_reg_numbered_buff_fetch,
805 Perl_reg_numbered_buff_store,
806 Perl_reg_numbered_buff_length,
808 Perl_reg_named_buff_iter,
810 #if defined(USE_ITHREADS)
811 Perl_regdupe_internal,
816 #endif /* PLUGGABLE_RE_EXTENSION */
822 /* .what is a character array with one character for each member of .data
823 * The character describes the function of the corresponding .data item:
824 * a - AV for paren_name_list under DEBUGGING
825 * f - start-class data for regstclass optimization
826 * l - start op for literal (?{EVAL}) item
827 * L - start op for literal (?{EVAL}) item, with separate CV (qr//)
828 * r - pointer to an embedded code-containing qr, e.g. /ab$qr/
829 * s - inversion list for Unicode-style character class, and the
830 * multicharacter strings resulting from casefolding the single-character
831 * entries in the character class
833 * u - trie struct's widecharmap (a HV, so can't share, must dup)
834 * also used for revcharmap and words under DEBUGGING
835 * T - aho-trie struct
836 * S - sv for named capture lookup
837 * 20010712 mjd@plover.com
838 * (Remember to update re_dup() and pregfree() if you add any items.)
846 /* Code in S_to_utf8_substr() and S_to_byte_substr() in regexec.c accesses
847 anchored* and float* via array indexes 0 and 1. */
848 #define anchored_substr substrs->data[0].substr
849 #define anchored_utf8 substrs->data[0].utf8_substr
850 #define anchored_offset substrs->data[0].min_offset
851 #define anchored_end_shift substrs->data[0].end_shift
853 #define float_substr substrs->data[1].substr
854 #define float_utf8 substrs->data[1].utf8_substr
855 #define float_min_offset substrs->data[1].min_offset
856 #define float_max_offset substrs->data[1].max_offset
857 #define float_end_shift substrs->data[1].end_shift
859 #define check_substr substrs->data[2].substr
860 #define check_utf8 substrs->data[2].utf8_substr
861 #define check_offset_min substrs->data[2].min_offset
862 #define check_offset_max substrs->data[2].max_offset
863 #define check_end_shift substrs->data[2].end_shift
865 #define RX_ANCHORED_SUBSTR(rx) (ReANY(rx)->anchored_substr)
866 #define RX_ANCHORED_UTF8(rx) (ReANY(rx)->anchored_utf8)
867 #define RX_FLOAT_SUBSTR(rx) (ReANY(rx)->float_substr)
868 #define RX_FLOAT_UTF8(rx) (ReANY(rx)->float_utf8)
870 /* trie related stuff */
872 /* a transition record for the state machine. the
873 check field determines which state "owns" the
874 transition. the char the transition is for is
875 determined by offset from the owning states base
876 field. the next field determines which state
877 is to be transitioned to if any.
879 struct _reg_trie_trans {
884 /* a transition list element for the list based representation */
885 struct _reg_trie_trans_list_elem {
889 typedef struct _reg_trie_trans_list_elem reg_trie_trans_le;
891 /* a state for compressed nodes. base is an offset
892 into an array of reg_trie_trans array. If wordnum is
893 nonzero the state is accepting. if base is zero then
894 the state has no children (and will be accepting)
896 struct _reg_trie_state {
900 reg_trie_trans_le* list;
904 /* info per word; indexed by wordnum */
906 U16 prev; /* previous word in acceptance chain; eg in
907 * zzz|abc|ab/ after matching the chars abc, the
908 * accepted word is #2, and the previous accepted
910 U32 len; /* how many chars long is this word? */
911 U32 accept; /* accept state for this word */
915 typedef struct _reg_trie_state reg_trie_state;
916 typedef struct _reg_trie_trans reg_trie_trans;
919 /* anything in here that needs to be freed later
920 should be dealt with in pregfree.
921 refcount is first in both this and _reg_ac_data to allow a space
922 optimisation in Perl_regdupe. */
923 struct _reg_trie_data {
924 U32 refcount; /* number of times this trie is referenced */
925 U32 lasttrans; /* last valid transition element */
926 U16 *charmap; /* byte to charid lookup array */
927 reg_trie_state *states; /* state data */
928 reg_trie_trans *trans; /* array of transition elements */
929 char *bitmap; /* stclass bitmap */
930 U16 *jump; /* optional 1 indexed array of offsets before tail
931 for the node following a given word. */
932 reg_trie_wordinfo *wordinfo; /* array of info per word */
933 U16 uniquecharcount; /* unique chars in trie (width of trans table) */
934 U32 startstate; /* initial state - used for common prefix optimisation */
935 STRLEN minlen; /* minimum length of words in trie - build/opt only? */
936 STRLEN maxlen; /* maximum length of words in trie - build/opt only? */
937 U32 prefixlen; /* #chars in common prefix */
938 U32 statecount; /* Build only - number of states in the states array
939 (including the unused zero state) */
940 U32 wordcount; /* Build only */
942 STRLEN charcount; /* Build only */
945 /* There is one (3 under DEBUGGING) pointers that logically belong in this
946 structure, but are held outside as they need duplication on thread cloning,
947 whereas the rest of the structure can be read only:
948 HV *widecharmap; code points > 255 to charid
950 AV *words; Array of words contained in trie, for dumping
951 AV *revcharmap; Map of each charid back to its character representation
955 #define TRIE_WORDS_OFFSET 2
957 typedef struct _reg_trie_data reg_trie_data;
959 /* refcount is first in both this and _reg_trie_data to allow a space
960 optimisation in Perl_regdupe. */
961 struct _reg_ac_data {
965 reg_trie_state *states;
967 typedef struct _reg_ac_data reg_ac_data;
969 /* ANY_BIT doesn't use the structure, so we can borrow it here.
970 This is simpler than refactoring all of it as wed end up with
971 three different sets... */
973 #define TRIE_BITMAP(p) (((reg_trie_data *)(p))->bitmap)
974 #define TRIE_BITMAP_BYTE(p, c) BITMAP_BYTE(TRIE_BITMAP(p), c)
975 #define TRIE_BITMAP_SET(p, c) (TRIE_BITMAP_BYTE(p, c) |= ANYOF_BIT((U8)c))
976 #define TRIE_BITMAP_CLEAR(p,c) (TRIE_BITMAP_BYTE(p, c) &= ~ANYOF_BIT((U8)c))
977 #define TRIE_BITMAP_TEST(p, c) (TRIE_BITMAP_BYTE(p, c) & ANYOF_BIT((U8)c))
979 #define IS_ANYOF_TRIE(op) ((op)==TRIEC || (op)==AHOCORASICKC)
980 #define IS_TRIE_AC(op) ((op)>=AHOCORASICK)
983 #define BITMAP_BYTE(p, c) (( (U8*) p) [ ( ( (UV) (c)) >> 3) ] )
984 #define BITMAP_TEST(p, c) (BITMAP_BYTE(p, c) & ANYOF_BIT((U8)c))
986 /* these defines assume uniquecharcount is the correct variable, and state may be evaluated twice */
987 #define TRIE_NODENUM(state) (((state)-1)/(trie->uniquecharcount)+1)
988 #define SAFE_TRIE_NODENUM(state) ((state) ? (((state)-1)/(trie->uniquecharcount)+1) : (state))
989 #define TRIE_NODEIDX(state) ((state) ? (((state)-1)*(trie->uniquecharcount)+1) : (state))
992 #define TRIE_CHARCOUNT(trie) ((trie)->charcount)
994 #define TRIE_CHARCOUNT(trie) (trie_charcount)
997 #define RE_TRIE_MAXBUF_INIT 65536
998 #define RE_TRIE_MAXBUF_NAME "\022E_TRIE_MAXBUF"
999 #define RE_DEBUG_FLAGS "\022E_DEBUG_FLAGS"
1001 #define RE_COMPILE_RECURSION_INIT 1000
1002 #define RE_COMPILE_RECURSION_LIMIT "\022E_COMPILE_RECURSION_LIMIT"
1006 RE_DEBUG_FLAGS is used to control what debug output is emitted
1007 its divided into three groups of options, some of which interact.
1008 The three groups are: Compile, Execute, Extra. There is room for a
1009 further group, as currently only the low three bytes are used.
1030 If you modify any of these make sure you make corresponding changes to
1031 re.pm, especially to the documentation.
1037 #define RE_DEBUG_COMPILE_MASK 0x0000FF
1038 #define RE_DEBUG_COMPILE_PARSE 0x000001
1039 #define RE_DEBUG_COMPILE_OPTIMISE 0x000002
1040 #define RE_DEBUG_COMPILE_TRIE 0x000004
1041 #define RE_DEBUG_COMPILE_DUMP 0x000008
1042 #define RE_DEBUG_COMPILE_FLAGS 0x000010
1043 #define RE_DEBUG_COMPILE_TEST 0x000020
1046 #define RE_DEBUG_EXECUTE_MASK 0x00FF00
1047 #define RE_DEBUG_EXECUTE_INTUIT 0x000100
1048 #define RE_DEBUG_EXECUTE_MATCH 0x000200
1049 #define RE_DEBUG_EXECUTE_TRIE 0x000400
1052 #define RE_DEBUG_EXTRA_MASK 0x1FF0000
1053 #define RE_DEBUG_EXTRA_TRIE 0x0010000
1054 #define RE_DEBUG_EXTRA_OFFSETS 0x0020000
1055 #define RE_DEBUG_EXTRA_OFFDEBUG 0x0040000
1056 #define RE_DEBUG_EXTRA_STATE 0x0080000
1057 #define RE_DEBUG_EXTRA_OPTIMISE 0x0100000
1058 #define RE_DEBUG_EXTRA_BUFFERS 0x0400000
1059 #define RE_DEBUG_EXTRA_GPOS 0x0800000
1060 #define RE_DEBUG_EXTRA_DUMP_PRE_OPTIMIZE 0x1000000
1062 #define RE_DEBUG_EXTRA_STACK 0x0280000
1064 #define RE_DEBUG_FLAG(x) (re_debug_flags & x)
1066 #define DEBUG_COMPILE_r(x) DEBUG_r( \
1067 if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_COMPILE_MASK)) x )
1068 #define DEBUG_PARSE_r(x) DEBUG_r( \
1069 if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_COMPILE_PARSE)) x )
1070 #define DEBUG_OPTIMISE_r(x) DEBUG_r( \
1071 if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_COMPILE_OPTIMISE)) x )
1072 #define DEBUG_DUMP_r(x) DEBUG_r( \
1073 if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_COMPILE_DUMP)) x )
1074 #define DEBUG_TRIE_COMPILE_r(x) DEBUG_r( \
1075 if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_COMPILE_TRIE)) x )
1076 #define DEBUG_FLAGS_r(x) DEBUG_r( \
1077 if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_COMPILE_FLAGS)) x )
1078 #define DEBUG_TEST_r(x) DEBUG_r( \
1079 if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_COMPILE_TEST)) x )
1081 #define DEBUG_EXECUTE_r(x) DEBUG_r( \
1082 if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_EXECUTE_MASK)) x )
1083 #define DEBUG_INTUIT_r(x) DEBUG_r( \
1084 if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_EXECUTE_INTUIT)) x )
1085 #define DEBUG_MATCH_r(x) DEBUG_r( \
1086 if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_EXECUTE_MATCH)) x )
1087 #define DEBUG_TRIE_EXECUTE_r(x) DEBUG_r( \
1088 if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_EXECUTE_TRIE)) x )
1091 #define DEBUG_EXTRA_r(x) DEBUG_r( \
1092 if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_EXTRA_MASK)) x )
1093 #define DEBUG_OFFSETS_r(x) DEBUG_r( \
1094 if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_EXTRA_OFFSETS)) x )
1095 #define DEBUG_STATE_r(x) DEBUG_r( \
1096 if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_EXTRA_STATE)) x )
1097 #define DEBUG_STACK_r(x) DEBUG_r( \
1098 if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_EXTRA_STACK)) x )
1099 #define DEBUG_BUFFERS_r(x) DEBUG_r( \
1100 if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_EXTRA_BUFFERS)) x )
1102 #define DEBUG_OPTIMISE_MORE_r(x) DEBUG_r( \
1103 if (DEBUG_v_TEST || ((RE_DEBUG_EXTRA_OPTIMISE|RE_DEBUG_COMPILE_OPTIMISE) == \
1104 (re_debug_flags & (RE_DEBUG_EXTRA_OPTIMISE|RE_DEBUG_COMPILE_OPTIMISE)))) x )
1105 #define MJD_OFFSET_DEBUG(x) DEBUG_r( \
1106 if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_EXTRA_OFFDEBUG)) \
1107 Perl_warn_nocontext x )
1108 #define DEBUG_TRIE_COMPILE_MORE_r(x) DEBUG_TRIE_COMPILE_r( \
1109 if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_EXTRA_TRIE)) x )
1110 #define DEBUG_TRIE_EXECUTE_MORE_r(x) DEBUG_TRIE_EXECUTE_r( \
1111 if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_EXTRA_TRIE)) x )
1113 #define DEBUG_TRIE_r(x) DEBUG_r( \
1114 if (DEBUG_v_TEST || (re_debug_flags & (RE_DEBUG_COMPILE_TRIE \
1115 | RE_DEBUG_EXECUTE_TRIE ))) x )
1116 #define DEBUG_GPOS_r(x) DEBUG_r( \
1117 if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_EXTRA_GPOS)) x )
1119 #define DEBUG_DUMP_PRE_OPTIMIZE_r(x) DEBUG_r( \
1120 if (DEBUG_v_TEST || (re_debug_flags & RE_DEBUG_EXTRA_DUMP_PRE_OPTIMIZE)) x )
1122 /* initialization */
1123 /* get_sv() can return NULL during global destruction. */
1124 #define GET_RE_DEBUG_FLAGS DEBUG_r({ \
1125 SV * re_debug_flags_sv = NULL; \
1126 re_debug_flags_sv = PL_curcop ? get_sv(RE_DEBUG_FLAGS, GV_ADD) : NULL; \
1127 if (re_debug_flags_sv) { \
1128 if (!SvIOK(re_debug_flags_sv)) \
1129 sv_setuv(re_debug_flags_sv, RE_DEBUG_COMPILE_DUMP | RE_DEBUG_EXECUTE_MASK ); \
1130 re_debug_flags=SvIV(re_debug_flags_sv); \
1136 #define GET_RE_DEBUG_FLAGS_DECL volatile IV re_debug_flags = 0; \
1137 PERL_UNUSED_VAR(re_debug_flags); GET_RE_DEBUG_FLAGS;
1139 #define RE_PV_COLOR_DECL(rpv,rlen,isuni,dsv,pv,l,m,c1,c2) \
1140 const char * const rpv = \
1141 pv_pretty((dsv), (pv), (l), (m), \
1142 PL_colors[(c1)],PL_colors[(c2)], \
1143 PERL_PV_ESCAPE_RE|PERL_PV_ESCAPE_NONASCII |((isuni) ? PERL_PV_ESCAPE_UNI : 0) ); \
1144 const int rlen = SvCUR(dsv)
1146 /* This is currently unsed in the core */
1147 #define RE_SV_ESCAPE(rpv,isuni,dsv,sv,m) \
1148 const char * const rpv = \
1149 pv_pretty((dsv), (SvPV_nolen_const(sv)), (SvCUR(sv)), (m), \
1150 PL_colors[(c1)],PL_colors[(c2)], \
1151 PERL_PV_ESCAPE_RE|PERL_PV_ESCAPE_NONASCII |((isuni) ? PERL_PV_ESCAPE_UNI : 0) )
1153 #define RE_PV_QUOTED_DECL(rpv,isuni,dsv,pv,l,m) \
1154 const char * const rpv = \
1155 pv_pretty((dsv), (pv), (l), (m), \
1156 PL_colors[0], PL_colors[1], \
1157 ( PERL_PV_PRETTY_QUOTE | PERL_PV_ESCAPE_RE | PERL_PV_ESCAPE_NONASCII | PERL_PV_PRETTY_ELLIPSES | \
1158 ((isuni) ? PERL_PV_ESCAPE_UNI : 0)) \
1161 #define RE_SV_DUMPLEN(ItEm) (SvCUR(ItEm) - (SvTAIL(ItEm)!=0))
1162 #define RE_SV_TAIL(ItEm) (SvTAIL(ItEm) ? "$" : "")
1164 #else /* if not DEBUGGING */
1166 #define GET_RE_DEBUG_FLAGS_DECL
1167 #define RE_PV_COLOR_DECL(rpv,rlen,isuni,dsv,pv,l,m,c1,c2)
1168 #define RE_SV_ESCAPE(rpv,isuni,dsv,sv,m)
1169 #define RE_PV_QUOTED_DECL(rpv,isuni,dsv,pv,l,m)
1170 #define RE_SV_DUMPLEN(ItEm)
1171 #define RE_SV_TAIL(ItEm)
1173 #endif /* DEBUG RELATED DEFINES */
1175 #define FIRST_NON_ASCII_DECIMAL_DIGIT 0x660 /* ARABIC_INDIC_DIGIT_ZERO */
1178 TRADITIONAL_BOUND = _CC_WORDCHAR,
1185 /* This unpacks the FLAGS field of ANYOF[HR]x nodes. The value it contains
1186 * gives the strict lower bound for the UTF-8 start byte of any code point
1187 * matchable by the node, and a loose upper bound as well.
1189 * The low bound is stored in the upper 6 bits, plus 0xC0.
1190 * The loose upper bound is determined from the lowest 2 bits and the low bound
1191 * (called x) as follows:
1193 * 11 The upper limit of the range can be as much as (EF - x) / 8
1194 * 10 The upper limit of the range can be as much as (EF - x) / 4
1195 * 01 The upper limit of the range can be as much as (EF - x) / 2
1196 * 00 The upper limit of the range can be as much as EF
1198 * For motivation of this design, see commit message in
1199 * 3146c00a633e9cbed741e10146662fbcedfdb8d3 */
1201 # define MAX_ANYOF_HRx_BYTE 0xF4
1203 # define MAX_ANYOF_HRx_BYTE 0xEF
1205 #define LOWEST_ANYOF_HRx_BYTE(b) (((b) >> 2) + 0xC0)
1206 #define HIGHEST_ANYOF_HRx_BYTE(b) \
1207 (LOWEST_ANYOF_HRx_BYTE(b) \
1208 + ((MAX_ANYOF_HRx_BYTE - LOWEST_ANYOF_HRx_BYTE(b)) >> ((b) & 3)))
1210 #endif /* PERL_REGCOMP_H_ */
1213 * ex: set ts=8 sts=4 sw=4 et: