3 * Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 * 2000, 2001, 2002, 2003, 2005 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 typedef OP OP_4tree; /* Will be redefined later. */
14 #define PERL_ENABLE_TRIE_OPTIMISATION 1
15 #define PERL_ENABLE_EXTENDED_TRIE_OPTIMISATION 1
16 #define PERL_ENABLE_POSITIVE_ASSERTION_STUDY 1
17 #define PERL_ENABLE_EXPERIMENTAL_REGEX_OPTIMISATIONS 0
18 /* Unless the next line is uncommented it is illegal to combine lazy
19 matching with possessive matching. Frankly it doesn't make much sense
20 to allow it as X*?+ matches nothing, X+?+ matches a single char only,
21 and X{min,max}?+ matches min times only.
23 /* #define REG_ALLOW_MINMOD_SUSPEND */
26 * The "internal use only" fields in regexp.h are present to pass info from
27 * compile to execute that permits the execute phase to run lots faster on
28 * simple cases. They are:
30 * regstart sv that must begin a match; NULL if none obvious
31 * reganch is the match anchored (at beginning-of-line only)?
32 * regmust string (pointer into program) that match must include, or NULL
33 * [regmust changed to SV* for bminstr()--law]
34 * regmlen length of regmust string
35 * [regmlen not used currently]
37 * Regstart and reganch permit very fast decisions on suitable starting points
38 * for a match, cutting down the work a lot. Regmust permits fast rejection
39 * of lines that cannot possibly match. The regmust tests are costly enough
40 * that pregcomp() supplies a regmust only if the r.e. contains something
41 * potentially expensive (at present, the only such thing detected is * or +
42 * at the start of the r.e., which can involve a lot of backup). Regmlen is
43 * supplied because the test in pregexec() needs it and pregcomp() is computing
45 * [regmust is now supplied always. The tests that use regmust have a
46 * heuristic that disables the test if it usually matches.]
48 * [In fact, we now use regmust in many cases to locate where the search
49 * starts in the string, so if regback is >= 0, the regmust search is never
50 * wasted effort. The regback variable says how many characters back from
51 * where regmust matched is the earliest possible start of the match.
52 * For instance, /[a-z].foo/ has a regmust of 'foo' and a regback of 2.]
56 * Structure for regexp "program". This is essentially a linear encoding
57 * of a nondeterministic finite-state machine (aka syntax charts or
58 * "railroad normal form" in parsing technology). Each node is an opcode
59 * plus a "next" pointer, possibly plus an operand. "Next" pointers of
60 * all nodes except BRANCH implement concatenation; a "next" pointer with
61 * a BRANCH on both ends of it is connecting two alternatives. (Here we
62 * have one of the subtle syntax dependencies: an individual BRANCH (as
63 * opposed to a collection of them) is never concatenated with anything
64 * because of operator precedence.) The operand of some types of node is
65 * a literal string; for others, it is a node leading into a sub-FSM. In
66 * particular, the operand of a BRANCH node is the first node of the branch.
67 * (NB this is *not* a tree structure: the tail of the branch connects
68 * to the thing following the set of BRANCHes.) The opcodes are defined
69 * in regnodes.h which is generated from regcomp.sym by regcomp.pl.
73 * A node is one char of opcode followed by two chars of "next" pointer.
74 * "Next" pointers are stored as two 8-bit pieces, high order first. The
75 * value is a positive offset from the opcode of the node containing it.
76 * An operand, if any, simply follows the node. (Note that much of the
77 * code generation knows about this implicit relationship.)
79 * Using two bytes for the "next" pointer is vast overkill for most things,
80 * but allows patterns to get big without disasters.
82 * [The "next" pointer is always aligned on an even
83 * boundary, and reads the offset directly as a short. Also, there is no
84 * special test to reverse the sign of BACK pointers since the offset is
88 struct regnode_string {
95 /* Argument bearing node - workhorse,
96 arg1 is often for the data field */
104 /* Similar to a regnode_1 but with an extra signed argument */
113 /* 'Two field' -- Two 16 bit unsigned args */
123 #define ANYOF_BITMAP_SIZE 32 /* 256 b/(8 b/B) */
124 #define ANYOF_CLASSBITMAP_SIZE 4 /* up to 32 (8*4) named classes */
126 /* also used by trie */
127 struct regnode_charclass {
132 char bitmap[ANYOF_BITMAP_SIZE]; /* only compile-time */
135 struct regnode_charclass_class { /* has [[:blah:]] classes */
136 U8 flags; /* should have ANYOF_CLASS here */
140 char bitmap[ANYOF_BITMAP_SIZE]; /* both compile-time */
141 char classflags[ANYOF_CLASSBITMAP_SIZE]; /* and run-time */
144 /* XXX fix this description.
145 Impose a limit of REG_INFTY on various pattern matching operations
146 to limit stack growth and to avoid "infinite" recursions.
148 /* The default size for REG_INFTY is I16_MAX, which is the same as
149 SHORT_MAX (see perl.h). Unfortunately I16 isn't necessarily 16 bits
150 (see handy.h). On the Cray C90, sizeof(short)==4 and hence I16_MAX is
151 ((1<<31)-1), while on the Cray T90, sizeof(short)==8 and I16_MAX is
152 ((1<<63)-1). To limit stack growth to reasonable sizes, supply a
154 --Andy Dougherty 11 June 1998
158 # define REG_INFTY ((1<<15)-1)
163 # define REG_INFTY I16_MAX
166 #define ARG_VALUE(arg) (arg)
167 #define ARG__SET(arg,val) ((arg) = (val))
173 #define ARG(p) ARG_VALUE(ARG_LOC(p))
174 #define ARG1(p) ARG_VALUE(ARG1_LOC(p))
175 #define ARG2(p) ARG_VALUE(ARG2_LOC(p))
176 #define ARG2L(p) ARG_VALUE(ARG2L_LOC(p))
178 #define ARG_SET(p, val) ARG__SET(ARG_LOC(p), (val))
179 #define ARG1_SET(p, val) ARG__SET(ARG1_LOC(p), (val))
180 #define ARG2_SET(p, val) ARG__SET(ARG2_LOC(p), (val))
181 #define ARG2L_SET(p, val) ARG__SET(ARG2L_LOC(p), (val))
186 #define NEXT_OFF(p) ((p)->next_off)
187 #define NODE_ALIGN(node)
188 #define NODE_ALIGN_FILL(node) ((node)->flags = 0xde) /* deadbeef */
190 #define SIZE_ALIGN NODE_ALIGN
197 #define OP(p) ((p)->type)
198 #define OPERAND(p) (((struct regnode_string *)p)->string)
199 #define MASK(p) ((char*)OPERAND(p))
200 #define STR_LEN(p) (((struct regnode_string *)p)->str_len)
201 #define STRING(p) (((struct regnode_string *)p)->string)
202 #define STR_SZ(l) ((l + sizeof(regnode) - 1) / sizeof(regnode))
203 #define NODE_SZ_STR(p) (STR_SZ(STR_LEN(p))+1)
210 #define NODE_ALIGN(node)
211 #define ARG_LOC(p) (((struct regnode_1 *)p)->arg1)
212 #define ARG1_LOC(p) (((struct regnode_2 *)p)->arg1)
213 #define ARG2_LOC(p) (((struct regnode_2 *)p)->arg2)
214 #define ARG2L_LOC(p) (((struct regnode_2L *)p)->arg2)
216 #define NODE_STEP_REGNODE 1 /* sizeof(regnode)/sizeof(regnode) */
217 #define EXTRA_STEP_2ARGS EXTRA_SIZE(struct regnode_2)
219 #define NODE_STEP_B 4
221 #define NEXTOPER(p) ((p) + NODE_STEP_REGNODE)
222 #define PREVOPER(p) ((p) - NODE_STEP_REGNODE)
224 #define FILL_ADVANCE_NODE(ptr, op) STMT_START { \
225 (ptr)->type = op; (ptr)->next_off = 0; (ptr)++; } STMT_END
226 #define FILL_ADVANCE_NODE_ARG(ptr, op, arg) STMT_START { \
227 ARG_SET(ptr, arg); FILL_ADVANCE_NODE(ptr, op); (ptr) += 1; } STMT_END
229 #define REG_MAGIC 0234
231 #define SIZE_ONLY (RExC_emit == &PL_regdummy)
233 /* Flags for node->flags of ANYOF */
235 #define ANYOF_CLASS 0x08 /* has [[:blah:]] classes */
236 #define ANYOF_INVERT 0x04
237 #define ANYOF_FOLD 0x02
238 #define ANYOF_LOCALE 0x01
240 /* Used for regstclass only */
241 #define ANYOF_EOS 0x10 /* Can match an empty string too */
243 /* There is a character or a range past 0xff */
244 #define ANYOF_UNICODE 0x20
245 #define ANYOF_UNICODE_ALL 0x40 /* Can match any char past 0xff */
247 /* size of node is large (includes class pointer) */
248 #define ANYOF_LARGE 0x80
250 /* Are there any runtime flags on in this node? */
251 #define ANYOF_RUNTIME(s) (ANYOF_FLAGS(s) & 0x0f)
253 #define ANYOF_FLAGS_ALL 0xff
255 /* Character classes for node->classflags of ANYOF */
256 /* Should be synchronized with a table in regprop() */
257 /* 2n should pair with 2n+1 */
259 #define ANYOF_ALNUM 0 /* \w, PL_utf8_alnum, utf8::IsWord, ALNUM */
260 #define ANYOF_NALNUM 1
261 #define ANYOF_SPACE 2 /* \s */
262 #define ANYOF_NSPACE 3
263 #define ANYOF_DIGIT 4
264 #define ANYOF_NDIGIT 5
265 #define ANYOF_ALNUMC 6 /* isalnum(3), utf8::IsAlnum, ALNUMC */
266 #define ANYOF_NALNUMC 7
267 #define ANYOF_ALPHA 8
268 #define ANYOF_NALPHA 9
269 #define ANYOF_ASCII 10
270 #define ANYOF_NASCII 11
271 #define ANYOF_CNTRL 12
272 #define ANYOF_NCNTRL 13
273 #define ANYOF_GRAPH 14
274 #define ANYOF_NGRAPH 15
275 #define ANYOF_LOWER 16
276 #define ANYOF_NLOWER 17
277 #define ANYOF_PRINT 18
278 #define ANYOF_NPRINT 19
279 #define ANYOF_PUNCT 20
280 #define ANYOF_NPUNCT 21
281 #define ANYOF_UPPER 22
282 #define ANYOF_NUPPER 23
283 #define ANYOF_XDIGIT 24
284 #define ANYOF_NXDIGIT 25
285 #define ANYOF_PSXSPC 26 /* POSIX space: \s plus the vertical tab */
286 #define ANYOF_NPSXSPC 27
287 #define ANYOF_BLANK 28 /* GNU extension: space and tab: non-vertical space */
288 #define ANYOF_NBLANK 29
292 /* Backward source code compatibility. */
294 #define ANYOF_ALNUML ANYOF_ALNUM
295 #define ANYOF_NALNUML ANYOF_NALNUM
296 #define ANYOF_SPACEL ANYOF_SPACE
297 #define ANYOF_NSPACEL ANYOF_NSPACE
299 /* Utility macros for the bitmap and classes of ANYOF */
301 #define ANYOF_SIZE (sizeof(struct regnode_charclass))
302 #define ANYOF_CLASS_SIZE (sizeof(struct regnode_charclass_class))
304 #define ANYOF_FLAGS(p) ((p)->flags)
306 #define ANYOF_BIT(c) (1 << ((c) & 7))
308 #define ANYOF_CLASS_BYTE(p, c) (((struct regnode_charclass_class*)(p))->classflags[((c) >> 3) & 3])
309 #define ANYOF_CLASS_SET(p, c) (ANYOF_CLASS_BYTE(p, c) |= ANYOF_BIT(c))
310 #define ANYOF_CLASS_CLEAR(p, c) (ANYOF_CLASS_BYTE(p, c) &= ~ANYOF_BIT(c))
311 #define ANYOF_CLASS_TEST(p, c) (ANYOF_CLASS_BYTE(p, c) & ANYOF_BIT(c))
313 #define ANYOF_CLASS_ZERO(ret) Zero(((struct regnode_charclass_class*)(ret))->classflags, ANYOF_CLASSBITMAP_SIZE, char)
314 #define ANYOF_BITMAP_ZERO(ret) Zero(((struct regnode_charclass*)(ret))->bitmap, ANYOF_BITMAP_SIZE, char)
316 #define ANYOF_BITMAP(p) (((struct regnode_charclass*)(p))->bitmap)
317 #define ANYOF_BITMAP_BYTE(p, c) (ANYOF_BITMAP(p)[(((U8)(c)) >> 3) & 31])
318 #define ANYOF_BITMAP_SET(p, c) (ANYOF_BITMAP_BYTE(p, c) |= ANYOF_BIT(c))
319 #define ANYOF_BITMAP_CLEAR(p,c) (ANYOF_BITMAP_BYTE(p, c) &= ~ANYOF_BIT(c))
320 #define ANYOF_BITMAP_TEST(p, c) (ANYOF_BITMAP_BYTE(p, c) & ANYOF_BIT(c))
322 #define ANYOF_BITMAP_SETALL(p) \
323 memset (ANYOF_BITMAP(p), 255, ANYOF_BITMAP_SIZE)
324 #define ANYOF_BITMAP_CLEARALL(p) \
325 Zero (ANYOF_BITMAP(p), ANYOF_BITMAP_SIZE)
326 /* Check that all 256 bits are all set. Used in S_cl_is_anything() */
327 #define ANYOF_BITMAP_TESTALLSET(p) \
328 memEQ (ANYOF_BITMAP(p), "\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377\377", ANYOF_BITMAP_SIZE)
330 #define ANYOF_SKIP ((ANYOF_SIZE - 1)/sizeof(regnode))
331 #define ANYOF_CLASS_SKIP ((ANYOF_CLASS_SIZE - 1)/sizeof(regnode))
332 #define ANYOF_CLASS_ADD_SKIP (ANYOF_CLASS_SKIP - ANYOF_SKIP)
336 * Utility definitions.
339 # define UCHARAT(p) ((int)*(const U8*)(p))
341 # define UCHARAT(p) ((int)*(p)&CHARMASK)
344 #define EXTRA_SIZE(guy) ((sizeof(guy)-1)/sizeof(struct regnode))
346 #define REG_SEEN_ZERO_LEN 0x00000001
347 #define REG_SEEN_LOOKBEHIND 0x00000002
348 #define REG_SEEN_GPOS 0x00000004
349 #define REG_SEEN_EVAL 0x00000008
350 #define REG_SEEN_CANY 0x00000010
351 #define REG_SEEN_SANY REG_SEEN_CANY /* src bckwrd cmpt */
352 #define REG_SEEN_RECURSE 0x00000020
353 #define REG_TOP_LEVEL_BRANCHES 0x00000040
354 #define REG_SEEN_VERBARG 0x00000080
358 #ifdef PLUGGABLE_RE_EXTENSION
359 #include "re_nodes.h"
361 #include "regnodes.h"
364 /* The following have no fixed length. U8 so we can do strchr() on it. */
366 EXTCONST U8 PL_varies[];
368 EXTCONST U8 PL_varies[] = {
369 BRANCH, BACK, STAR, PLUS, CURLY, CURLYX, REF, REFF, REFFL,
370 WHILEM, CURLYM, CURLYN, BRANCHJ, IFTHEN, SUSPEND, CLUMP, 0
374 /* The following always have a length of 1. U8 we can do strchr() on it. */
375 /* (Note that length 1 means "one character" under UTF8, not "one octet".) */
377 EXTCONST U8 PL_simple[];
379 EXTCONST U8 PL_simple[] = {
391 #ifndef PLUGGABLE_RE_EXTENSION
393 EXTCONST regexp_engine PL_core_reg_engine;
395 EXTCONST regexp_engine PL_core_reg_engine = {
398 Perl_re_intuit_start,
399 Perl_re_intuit_string,
401 #if defined(USE_ITHREADS)
406 #endif /* PLUGGABLE_RE_EXTENSION */
412 /* .what is a character array with one character for each member of .data
413 * The character describes the function of the corresponding .data item:
414 * f - start-class data for regstclass optimization
415 * n - Root of op tree for (?{EVAL}) item
416 * o - Start op for (?{EVAL}) item
417 * p - Pad for (?{EVAL}) item
418 * s - swash for unicode-style character class, and the multicharacter
419 * strings resulting from casefolding the single-character entries
420 * in the character class
422 * T - aho-trie struct
423 * S - sv for named capture lookup
424 * 20010712 mjd@plover.com
425 * (Remember to update re_dup() and pregfree() if you add any items.)
433 struct reg_substr_datum {
436 SV *substr; /* non-utf8 variant */
437 SV *utf8_substr; /* utf8 variant */
441 struct reg_substr_data {
442 struct reg_substr_datum data[3]; /* Actual array */
445 #define anchored_substr substrs->data[0].substr
446 #define anchored_utf8 substrs->data[0].utf8_substr
447 #define anchored_offset substrs->data[0].min_offset
448 #define anchored_end_shift substrs->data[0].end_shift
450 #define float_substr substrs->data[1].substr
451 #define float_utf8 substrs->data[1].utf8_substr
452 #define float_min_offset substrs->data[1].min_offset
453 #define float_max_offset substrs->data[1].max_offset
454 #define float_end_shift substrs->data[1].end_shift
456 #define check_substr substrs->data[2].substr
457 #define check_utf8 substrs->data[2].utf8_substr
458 #define check_offset_min substrs->data[2].min_offset
459 #define check_offset_max substrs->data[2].max_offset
460 #define check_end_shift substrs->data[2].end_shift
464 /* trie related stuff */
466 /* a transition record for the state machine. the
467 check field determines which state "owns" the
468 transition. the char the transition is for is
469 determined by offset from the owning states base
470 field. the next field determines which state
471 is to be transitioned to if any.
473 struct _reg_trie_trans {
478 /* a transition list element for the list based representation */
479 struct _reg_trie_trans_list_elem {
483 typedef struct _reg_trie_trans_list_elem reg_trie_trans_le;
485 /* a state for compressed nodes. base is an offset
486 into an array of reg_trie_trans array. If wordnum is
487 nonzero the state is accepting. if base is zero then
488 the state has no children (and will be accepting)
490 struct _reg_trie_state {
494 reg_trie_trans_le* list;
500 typedef struct _reg_trie_state reg_trie_state;
501 typedef struct _reg_trie_trans reg_trie_trans;
504 /* anything in here that needs to be freed later
505 should be dealt with in pregfree */
506 struct _reg_trie_data {
507 U16 uniquecharcount; /* unique chars in trie (width of trans table) */
508 U32 lasttrans; /* last valid transition element */
509 U16 *charmap; /* byte to charid lookup array */
510 HV *widecharmap; /* code points > 255 to charid */
511 reg_trie_state *states; /* state data */
512 reg_trie_trans *trans; /* array of transition elements */
513 char *bitmap; /* stclass bitmap */
514 U32 refcount; /* number of times this trie is referenced */
515 U32 startstate; /* initial state - used for common prefix optimisation */
516 STRLEN minlen; /* minimum length of words in trie - build/opt only? */
517 STRLEN maxlen; /* maximum length of words in trie - build/opt only? */
518 U32 *wordlen; /* array of lengths of words */
519 U16 *jump; /* optional 1 indexed array of offsets before tail
520 for the node following a given word. */
521 U16 *nextword; /* optional 1 indexed array to support linked list
522 of duplicate wordnums */
523 U32 statecount; /* Build only - number of states in the states array
524 (including the unused zero state) */
525 U32 wordcount; /* Build only */
527 STRLEN charcount; /* Build only */
528 AV *words; /* Array of words contained in trie, for dumping */
529 AV *revcharmap; /* Map of each charid back to its character representation */
532 typedef struct _reg_trie_data reg_trie_data;
534 struct _reg_ac_data {
536 reg_trie_state *states;
540 typedef struct _reg_ac_data reg_ac_data;
542 /* ANY_BIT doesnt use the structure, so we can borrow it here.
543 This is simpler than refactoring all of it as wed end up with
544 three different sets... */
546 #define TRIE_BITMAP(p) (((reg_trie_data *)(p))->bitmap)
547 #define TRIE_BITMAP_BYTE(p, c) (TRIE_BITMAP(p)[(((U8)(c)) >> 3) & 31])
548 #define TRIE_BITMAP_SET(p, c) (TRIE_BITMAP_BYTE(p, c) |= ANYOF_BIT((U8)c))
549 #define TRIE_BITMAP_CLEAR(p,c) (TRIE_BITMAP_BYTE(p, c) &= ~ANYOF_BIT((U8)c))
550 #define TRIE_BITMAP_TEST(p, c) (TRIE_BITMAP_BYTE(p, c) & ANYOF_BIT((U8)c))
552 #define IS_ANYOF_TRIE(op) ((op)==TRIEC || (op)==AHOCORASICKC)
553 #define IS_TRIE_AC(op) ((op)>=AHOCORASICK)
556 #define BITMAP_BYTE(p, c) (((U8*)p)[(((U8)(c)) >> 3) & 31])
557 #define BITMAP_TEST(p, c) (BITMAP_BYTE(p, c) & ANYOF_BIT((U8)c))
559 /* these defines assume uniquecharcount is the correct variable, and state may be evaluated twice */
560 #define TRIE_NODENUM(state) (((state)-1)/(trie->uniquecharcount)+1)
561 #define SAFE_TRIE_NODENUM(state) ((state) ? (((state)-1)/(trie->uniquecharcount)+1) : (state))
562 #define TRIE_NODEIDX(state) ((state) ? (((state)-1)*(trie->uniquecharcount)+1) : (state))
565 #define TRIE_CHARCOUNT(trie) ((trie)->charcount)
566 #define TRIE_REVCHARMAP(trie) ((trie)->revcharmap)
568 #define TRIE_CHARCOUNT(trie) (trie_charcount)
569 #define TRIE_REVCHARMAP(trie) (trie_revcharmap)
572 #define RE_TRIE_MAXBUF_INIT 65536
573 #define RE_TRIE_MAXBUF_NAME "\022E_TRIE_MAXBUF"
574 #define RE_DEBUG_FLAGS "\022E_DEBUG_FLAGS"
578 RE_DEBUG_FLAGS is used to control what debug output is emitted
579 its divided into three groups of options, some of which interact.
580 The three groups are: Compile, Execute, Extra. There is room for a
581 further group, as currently only the low three bytes are used.
602 If you modify any of these make sure you make corresponding changes to
603 re.pm, especially to the documentation.
609 #define RE_DEBUG_COMPILE_MASK 0x0000FF
610 #define RE_DEBUG_COMPILE_PARSE 0x000001
611 #define RE_DEBUG_COMPILE_OPTIMISE 0x000002
612 #define RE_DEBUG_COMPILE_TRIE 0x000004
613 #define RE_DEBUG_COMPILE_DUMP 0x000008
616 #define RE_DEBUG_EXECUTE_MASK 0x00FF00
617 #define RE_DEBUG_EXECUTE_INTUIT 0x000100
618 #define RE_DEBUG_EXECUTE_MATCH 0x000200
619 #define RE_DEBUG_EXECUTE_TRIE 0x000400
622 #define RE_DEBUG_EXTRA_MASK 0xFF0000
623 #define RE_DEBUG_EXTRA_TRIE 0x010000
624 #define RE_DEBUG_EXTRA_OFFSETS 0x020000
625 #define RE_DEBUG_EXTRA_OFFDEBUG 0x040000
626 #define RE_DEBUG_EXTRA_STATE 0x080000
627 #define RE_DEBUG_EXTRA_OPTIMISE 0x100000
629 #define RE_DEBUG_EXTRA_STACK 0x280000
631 #define RE_DEBUG_FLAG(x) (re_debug_flags & x)
633 #define DEBUG_COMPILE_r(x) DEBUG_r( \
634 if (re_debug_flags & RE_DEBUG_COMPILE_MASK) x )
635 #define DEBUG_PARSE_r(x) DEBUG_r( \
636 if (re_debug_flags & RE_DEBUG_COMPILE_PARSE) x )
637 #define DEBUG_OPTIMISE_r(x) DEBUG_r( \
638 if (re_debug_flags & RE_DEBUG_COMPILE_OPTIMISE) x )
639 #define DEBUG_PARSE_r(x) DEBUG_r( \
640 if (re_debug_flags & RE_DEBUG_COMPILE_PARSE) x )
641 #define DEBUG_DUMP_r(x) DEBUG_r( \
642 if (re_debug_flags & RE_DEBUG_COMPILE_DUMP) x )
643 #define DEBUG_TRIE_COMPILE_r(x) DEBUG_r( \
644 if (re_debug_flags & RE_DEBUG_COMPILE_TRIE) x )
647 #define DEBUG_EXECUTE_r(x) DEBUG_r( \
648 if (re_debug_flags & RE_DEBUG_EXECUTE_MASK) x )
649 #define DEBUG_INTUIT_r(x) DEBUG_r( \
650 if (re_debug_flags & RE_DEBUG_EXECUTE_INTUIT) x )
651 #define DEBUG_MATCH_r(x) DEBUG_r( \
652 if (re_debug_flags & RE_DEBUG_EXECUTE_MATCH) x )
653 #define DEBUG_TRIE_EXECUTE_r(x) DEBUG_r( \
654 if (re_debug_flags & RE_DEBUG_EXECUTE_TRIE) x )
657 #define DEBUG_EXTRA_r(x) DEBUG_r( \
658 if (re_debug_flags & RE_DEBUG_EXTRA_MASK) x )
659 #define DEBUG_OFFSETS_r(x) DEBUG_r( \
660 if (re_debug_flags & RE_DEBUG_EXTRA_OFFSETS) x )
661 #define DEBUG_STATE_r(x) DEBUG_r( \
662 if (re_debug_flags & RE_DEBUG_EXTRA_STATE) x )
663 #define DEBUG_STACK_r(x) DEBUG_r( \
664 if (re_debug_flags & RE_DEBUG_EXTRA_STACK) x )
665 #define DEBUG_OPTIMISE_MORE_r(x) DEBUG_r( \
666 if ((RE_DEBUG_EXTRA_OPTIMISE|RE_DEBUG_COMPILE_OPTIMISE) == \
667 (re_debug_flags & (RE_DEBUG_EXTRA_OPTIMISE|RE_DEBUG_COMPILE_OPTIMISE)) ) x )
668 #define MJD_OFFSET_DEBUG(x) DEBUG_r( \
669 if (re_debug_flags & RE_DEBUG_EXTRA_OFFDEBUG) \
670 Perl_warn_nocontext x )
671 #define DEBUG_TRIE_COMPILE_MORE_r(x) DEBUG_TRIE_COMPILE_r( \
672 if (re_debug_flags & RE_DEBUG_EXTRA_TRIE) x )
673 #define DEBUG_TRIE_EXECUTE_MORE_r(x) DEBUG_TRIE_EXECUTE_r( \
674 if (re_debug_flags & RE_DEBUG_EXTRA_TRIE) x )
676 #define DEBUG_TRIE_r(x) DEBUG_r( \
677 if (re_debug_flags & (RE_DEBUG_COMPILE_TRIE \
678 | RE_DEBUG_EXECUTE_TRIE )) x )
681 /* get_sv() can return NULL during global destruction. */
682 #define GET_RE_DEBUG_FLAGS DEBUG_r({ \
683 SV * re_debug_flags_sv = NULL; \
684 re_debug_flags_sv = get_sv(RE_DEBUG_FLAGS, 1); \
685 if (re_debug_flags_sv) { \
686 if (!SvIOK(re_debug_flags_sv)) \
687 sv_setuv(re_debug_flags_sv, RE_DEBUG_COMPILE_DUMP | RE_DEBUG_EXECUTE_MASK ); \
688 re_debug_flags=SvIV(re_debug_flags_sv); \
694 #define GET_RE_DEBUG_FLAGS_DECL IV re_debug_flags = 0; GET_RE_DEBUG_FLAGS;
696 #define RE_PV_COLOR_DECL(rpv,rlen,isuni,dsv,pv,l,m,c1,c2) \
697 const char * const rpv = \
698 pv_pretty((dsv), (pv), (l), (m), \
699 PL_colors[(c1)],PL_colors[(c2)], \
700 ((isuni) ? PERL_PV_ESCAPE_UNI : 0) ); \
701 const int rlen = SvCUR(dsv)
703 #define RE_SV_ESCAPE(rpv,isuni,dsv,sv,m) \
704 const char * const rpv = \
705 pv_pretty((dsv), (SvPV_nolen_const(sv)), (SvCUR(sv)), (m), \
706 PL_colors[(c1)],PL_colors[(c2)], \
707 ((isuni) ? PERL_PV_ESCAPE_UNI : 0) )
709 #define RE_PV_QUOTED_DECL(rpv,isuni,dsv,pv,l,m) \
710 const char * const rpv = \
711 pv_pretty((dsv), (pv), (l), (m), \
712 PL_colors[0], PL_colors[1], \
713 ( PERL_PV_PRETTY_QUOTE | PERL_PV_PRETTY_ELIPSES | \
714 ((isuni) ? PERL_PV_ESCAPE_UNI : 0)) \
717 #define RE_SV_DUMPLEN(ItEm) (SvCUR(ItEm) - (SvTAIL(ItEm)!=0))
718 #define RE_SV_TAIL(ItEm) (SvTAIL(ItEm) ? "$" : "")
720 #else /* if not DEBUGGING */
722 #define GET_RE_DEBUG_FLAGS_DECL
723 #define RE_PV_COLOR_DECL(rpv,rlen,isuni,dsv,pv,l,m,c1,c2)
724 #define RE_SV_ESCAPE(rpv,isuni,dsv,sv,m)
725 #define RE_PV_QUOTED_DECL(rpv,isuni,dsv,pv,l,m)
726 #define RE_SV_DUMPLEN(ItEm)
727 #define RE_SV_TAIL(ItEm)
729 #endif /* DEBUG RELATED DEFINES */