This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
gutsupport for C++ exceptions
[perl5.git] / regexp.h
1 /*    regexp.h
2  */
3
4 /*
5  * Definitions etc. for regexp(3) routines.
6  *
7  * Caveat:  this is V8 regexp(3) [actually, a reimplementation thereof],
8  * not the System V one.
9  */
10
11
12 struct regnode {
13     U8  flags;
14     U8  type;
15     U16 next_off;
16 };
17
18 typedef struct regnode regnode;
19
20 struct reg_data {
21     U32 count;
22     U8 *what;
23     void* data[1];
24 };
25
26 struct reg_substr_datum {
27     I32 min_offset;
28     I32 max_offset;
29     SV *substr;
30 };
31
32 struct reg_substr_data {
33     struct reg_substr_datum data[3];    /* Actual array */
34 };
35
36 typedef struct regexp {
37         I32 refcnt;
38         char **startp;
39         char **endp;
40         regnode *regstclass;
41         I32 minlen;             /* mininum possible length of $& */
42         I32 prelen;             /* length of precomp */
43         U32 nparens;            /* number of parentheses */
44         U32 lastparen;          /* last paren matched */
45         char *precomp;          /* pre-compilation regular expression */
46         char *subbase;          /* saved string so \digit works forever */
47         char *subbeg;           /* same, but not responsible for allocation */
48         char *subend;           /* end of subbase */
49         U32 reganch;            /* Internal use only +
50                                    Tainted information used by regexec? */
51 #if 0
52         SV *anchored_substr;    /* Substring at fixed position wrt start. */
53         I32 anchored_offset;    /* Position of it. */
54         SV *float_substr;       /* Substring at variable position wrt start. */
55         I32 float_min_offset;   /* Minimal position of it. */
56         I32 float_max_offset;   /* Maximal position of it. */
57         SV *check_substr;       /* Substring to check before matching. */
58         I32 check_offset_min;   /* Offset of the above. */
59         I32 check_offset_max;   /* Offset of the above. */
60 #else
61         struct reg_substr_data *substrs;
62 #endif
63         struct reg_data *data;  /* Additional data. */
64         regnode program[1];     /* Unwarranted chumminess with compiler. */
65 } regexp;
66
67 #define anchored_substr substrs->data[0].substr
68 #define anchored_offset substrs->data[0].min_offset
69 #define float_substr substrs->data[1].substr
70 #define float_min_offset substrs->data[1].min_offset
71 #define float_max_offset substrs->data[1].max_offset
72 #define check_substr substrs->data[2].substr
73 #define check_offset_min substrs->data[2].min_offset
74 #define check_offset_max substrs->data[2].max_offset
75
76 #define ROPT_ANCH               (ROPT_ANCH_BOL|ROPT_ANCH_MBOL|ROPT_ANCH_GPOS)
77 #define ROPT_ANCH_SINGLE        (ROPT_ANCH_BOL|ROPT_ANCH_GPOS)
78 #define ROPT_ANCH_BOL           0x00001
79 #define ROPT_ANCH_MBOL          0x00002
80 #define ROPT_ANCH_GPOS          0x00004
81 #define ROPT_SKIP               0x00008
82 #define ROPT_IMPLICIT           0x00010 /* Converted .* to ^.* */
83 #define ROPT_NOSCAN             0x00020 /* Check-string always at start. */
84 #define ROPT_GPOS_SEEN          0x00040
85 #define ROPT_CHECK_ALL          0x00080
86 #define ROPT_LOOKBEHIND_SEEN    0x00100
87 #define ROPT_EVAL_SEEN          0x00200
88 #define ROPT_TAINTED_SEEN       0x00400
89 #define ROPT_ANCH_SBOL          0x00800
90
91 /* 0xf800 of reganch is used by PMf_COMPILETIME */
92
93 #define ROPT_UTF8               0x10000
94 #define ROPT_NAUGHTY            0x20000 /* how exponential is this pattern? */
95
96 #define RX_MATCH_TAINTED(prog)  ((prog)->reganch & ROPT_TAINTED_SEEN)
97 #define RX_MATCH_TAINTED_on(prog) ((prog)->reganch |= ROPT_TAINTED_SEEN)
98 #define RX_MATCH_TAINTED_off(prog) ((prog)->reganch &= ~ROPT_TAINTED_SEEN)
99 #define RX_MATCH_TAINTED_set(prog, t) ((t) \
100                                        ? RX_MATCH_TAINTED_on(prog) \
101                                        : RX_MATCH_TAINTED_off(prog))
102
103 #define REXEC_COPY_STR  1               /* Need to copy the string. */
104 #define REXEC_CHECKED   2               /* check_substr already checked. */
105 #define REXEC_SCREAM    4               /* use scream table. */
106 #define REXEC_IGNOREPOS 8               /* \G matches at start. */
107
108 #define ReREFCNT_inc(re) ((re && re->refcnt++), re)
109 #define ReREFCNT_dec(re) pregfree(re)