Commit | Line | Data |
---|---|---|
a0d0e21e LW |
1 | /* regexp.h |
2 | */ | |
3 | ||
378cc40b LW |
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 | ||
378cc40b | 11 | |
c277df42 IZ |
12 | struct regnode { |
13 | U8 flags; | |
14 | U8 type; | |
15 | U16 next_off; | |
16 | }; | |
17 | ||
18 | typedef struct regnode regnode; | |
19 | ||
c31fac66 GS |
20 | struct reg_data { |
21 | U32 count; | |
22 | U8 *what; | |
23 | void* data[1]; | |
24 | }; | |
25 | ||
2779dcf1 IZ |
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 | ||
378cc40b | 36 | typedef struct regexp { |
c277df42 | 37 | I32 refcnt; |
fe14fcc3 LW |
38 | char **startp; |
39 | char **endp; | |
c277df42 | 40 | regnode *regstclass; |
79072805 LW |
41 | I32 minlen; /* mininum possible length of $& */ |
42 | I32 prelen; /* length of precomp */ | |
a0d0e21e LW |
43 | U32 nparens; /* number of parentheses */ |
44 | U32 lastparen; /* last paren matched */ | |
378cc40b LW |
45 | char *precomp; /* pre-compilation regular expression */ |
46 | char *subbase; /* saved string so \digit works forever */ | |
9ef589d8 | 47 | char *subbeg; /* same, but not responsible for allocation */ |
00bf170e | 48 | char *subend; /* end of subbase */ |
a0d0e21e | 49 | U16 naughty; /* how exponential is this pattern? */ |
c277df42 IZ |
50 | U16 reganch; /* Internal use only + |
51 | Tainted information used by regexec? */ | |
2779dcf1 | 52 | #if 0 |
c277df42 IZ |
53 | SV *anchored_substr; /* Substring at fixed position wrt start. */ |
54 | I32 anchored_offset; /* Position of it. */ | |
55 | SV *float_substr; /* Substring at variable position wrt start. */ | |
56 | I32 float_min_offset; /* Minimal position of it. */ | |
57 | I32 float_max_offset; /* Maximal position of it. */ | |
58 | SV *check_substr; /* Substring to check before matching. */ | |
59 | I32 check_offset_min; /* Offset of the above. */ | |
60 | I32 check_offset_max; /* Offset of the above. */ | |
2779dcf1 IZ |
61 | #else |
62 | struct reg_substr_data *substrs; | |
63 | #endif | |
c277df42 IZ |
64 | struct reg_data *data; /* Additional data. */ |
65 | regnode program[1]; /* Unwarranted chumminess with compiler. */ | |
378cc40b LW |
66 | } regexp; |
67 | ||
2779dcf1 IZ |
68 | #define anchored_substr substrs->data[0].substr |
69 | #define anchored_offset substrs->data[0].min_offset | |
70 | #define float_substr substrs->data[1].substr | |
71 | #define float_min_offset substrs->data[1].min_offset | |
72 | #define float_max_offset substrs->data[1].max_offset | |
73 | #define check_substr substrs->data[2].substr | |
74 | #define check_offset_min substrs->data[2].min_offset | |
75 | #define check_offset_max substrs->data[2].max_offset | |
76 | ||
c277df42 IZ |
77 | #define ROPT_ANCH (ROPT_ANCH_BOL|ROPT_ANCH_MBOL|ROPT_ANCH_GPOS) |
78 | #define ROPT_ANCH_SINGLE (ROPT_ANCH_BOL|ROPT_ANCH_GPOS) | |
79 | #define ROPT_ANCH_BOL 1 | |
80 | #define ROPT_ANCH_MBOL 2 | |
81 | #define ROPT_ANCH_GPOS 4 | |
82 | #define ROPT_SKIP 8 | |
83 | #define ROPT_IMPLICIT 0x10 /* Converted .* to ^.* */ | |
84 | #define ROPT_NOSCAN 0x20 /* Check-string always at start. */ | |
85 | #define ROPT_GPOS_SEEN 0x40 | |
86 | #define ROPT_CHECK_ALL 0x80 | |
87 | #define ROPT_LOOKBEHIND_SEEN 0x100 | |
ce862d02 | 88 | #define ROPT_EVAL_SEEN 0x200 |
8782bef2 GB |
89 | #define ROPT_TAINTED_SEEN 0x400 |
90 | /* 0xf800 of reganch is used by PMf_COMPILETIME */ | |
c277df42 IZ |
91 | |
92 | #define RX_MATCH_TAINTED(prog) ((prog)->reganch & ROPT_TAINTED_SEEN) | |
72311751 GS |
93 | #define RX_MATCH_TAINTED_on(prog) ((prog)->reganch |= ROPT_TAINTED_SEEN) |
94 | #define RX_MATCH_TAINTED_off(prog) ((prog)->reganch &= ~ROPT_TAINTED_SEEN) | |
95 | #define RX_MATCH_TAINTED_set(prog, t) ((t) \ | |
96 | ? RX_MATCH_TAINTED_on(prog) \ | |
97 | : RX_MATCH_TAINTED_off(prog)) | |
c277df42 IZ |
98 | |
99 | #define REXEC_COPY_STR 1 /* Need to copy the string. */ | |
100 | #define REXEC_CHECKED 2 /* check_substr already checked. */ | |
101 | ||
102 | #define ReREFCNT_inc(re) ((re && re->refcnt++), re) | |
103 | #define ReREFCNT_dec(re) pregfree(re) |