Integrate mainline as of _55
[p5sagit/p5-mst-13.2.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 typedef struct regexp {
21         I32 refcnt;
22         char **startp;
23         char **endp;
24         regnode *regstclass;
25         I32 minlen;             /* mininum possible length of $& */
26         I32 prelen;             /* length of precomp */
27         U32 nparens;            /* number of parentheses */
28         U32 lastparen;          /* last paren matched */
29         char *precomp;          /* pre-compilation regular expression */
30         char *subbase;          /* saved string so \digit works forever */
31         char *subbeg;           /* same, but not responsible for allocation */
32         char *subend;           /* end of subbase */
33         U16 naughty;            /* how exponential is this pattern? */
34         U16 reganch;            /* Internal use only +
35                                    Tainted information used by regexec? */
36         SV *anchored_substr;    /* Substring at fixed position wrt start. */
37         I32 anchored_offset;    /* Position of it. */
38         SV *float_substr;       /* Substring at variable position wrt start. */
39         I32 float_min_offset;   /* Minimal position of it. */
40         I32 float_max_offset;   /* Maximal position of it. */
41         SV *check_substr;       /* Substring to check before matching. */
42         I32 check_offset_min;   /* Offset of the above. */
43         I32 check_offset_max;   /* Offset of the above. */
44         struct reg_data *data;  /* Additional data. */
45         regnode program[1];     /* Unwarranted chumminess with compiler. */
46 } regexp;
47
48 #define ROPT_ANCH               (ROPT_ANCH_BOL|ROPT_ANCH_MBOL|ROPT_ANCH_GPOS)
49 #define ROPT_ANCH_SINGLE        (ROPT_ANCH_BOL|ROPT_ANCH_GPOS)
50 #define ROPT_ANCH_BOL           1
51 #define ROPT_ANCH_MBOL          2
52 #define ROPT_ANCH_GPOS          4
53 #define ROPT_SKIP               8
54 #define ROPT_IMPLICIT           0x10    /* Converted .* to ^.* */
55 #define ROPT_NOSCAN             0x20    /* Check-string always at start. */
56 #define ROPT_GPOS_SEEN          0x40
57 #define ROPT_CHECK_ALL          0x80
58 #define ROPT_LOOKBEHIND_SEEN    0x100
59
60 #define ROPT_TAINTED_SEEN       0x8000
61
62 #define RX_MATCH_TAINTED(prog)  ((prog)->reganch & ROPT_TAINTED_SEEN)
63 #define RX_MATCH_TAINTED_SET(prog, t) ((t) \
64                                        ? ((prog)->reganch |= ROPT_TAINTED_SEEN) \
65                                        : ((prog)->reganch &= ~ROPT_TAINTED_SEEN))
66
67 #define REXEC_COPY_STR  1               /* Need to copy the string. */
68 #define REXEC_CHECKED   2               /* check_substr already checked. */
69
70 #define ReREFCNT_inc(re) ((re && re->refcnt++), re)
71 #define ReREFCNT_dec(re) pregfree(re)