This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
B/Makefile.PL: Allow constants to be long/unsigned
[perl5.git] / op_reg_common.h
CommitLineData
1850c8f9
KW
1/* op_reg_common.h
2 *
3 * Definitions common to by op.h and regexp.h
4 *
2eee27d7 5 * Copyright (C) 2010, 2011 by Larry Wall and others
1850c8f9
KW
6 *
7 * You may distribute under the terms of either the GNU General Public
8 * License or the Artistic License, as specified in the README file.
9 *
10 */
11
12/* These defines are used in both op.h and regexp.h The definitions use the
5b126c84
KW
13 * shift form so that ext/B/defsubs_h.PL will pick them up.
14 *
15 * Data structures used in the two headers have common fields, and in fact one
16 * is copied onto the other. This makes it easy to keep them in sync */
17
18/* This tells where the first of these bits is. Setting it to 0 saved cycles
19 * and memory. I (khw) think the code will work if changed back, but haven't
20 * tested it */
da494bb7 21/* Make sure to update ext/re/re.pm when changing this! */
93136d17
KW
22#ifndef RXf_PMf_STD_PMMOD_SHIFT /* Only expand #include of this file once */
23
5b126c84
KW
24#define RXf_PMf_STD_PMMOD_SHIFT 0
25
26/* The bits need to be ordered so that the msix are contiguous starting at bit
27 * RXf_PMf_STD_PMMOD_SHIFT, followed by the p. See STD_PAT_MODS and
28 * INT_PAT_MODS in regexp.h for the reason contiguity is needed */
1e215989 29/* Make sure to update lib/re.pm when changing these! */
dbc200c5 30/* Make sure you keep the pure PMf_ versions below in sync */
5b126c84
KW
31#define RXf_PMf_MULTILINE (1 << (RXf_PMf_STD_PMMOD_SHIFT+0)) /* /m */
32#define RXf_PMf_SINGLELINE (1 << (RXf_PMf_STD_PMMOD_SHIFT+1)) /* /s */
33#define RXf_PMf_FOLD (1 << (RXf_PMf_STD_PMMOD_SHIFT+2)) /* /i */
34#define RXf_PMf_EXTENDED (1 << (RXf_PMf_STD_PMMOD_SHIFT+3)) /* /x */
334afb3e
KW
35#define RXf_PMf_EXTENDED_MORE (1 << (RXf_PMf_STD_PMMOD_SHIFT+4)) /* /xx */
36#define RXf_PMf_KEEPCOPY (1 << (RXf_PMf_STD_PMMOD_SHIFT+5)) /* /p */
a62b1201
KW
37
38/* The character set for the regex is stored in a field of more than one bit
39 * using an enum, for reasons of compactness and to ensure that the options are
40 * mutually exclusive */
693fefec 41/* Make sure to update ext/re/re.pm and regcomp.sym (as these are used as
ca143fe8 42 * offsets for various node types, like POSIXD vs POSIXL, etc) when changing
693fefec 43 * this! */
a62b1201
KW
44typedef enum {
45 REGEX_DEPENDS_CHARSET = 0,
46 REGEX_LOCALE_CHARSET,
cfaf538b 47 REGEX_UNICODE_CHARSET,
df7a8460
KW
48 REGEX_ASCII_RESTRICTED_CHARSET,
49 REGEX_ASCII_MORE_RESTRICTED_CHARSET
a62b1201
KW
50} regex_charset;
51
334afb3e 52#define _RXf_PMf_CHARSET_SHIFT ((RXf_PMf_STD_PMMOD_SHIFT)+6)
df7a8460 53#define RXf_PMf_CHARSET (7 << (_RXf_PMf_CHARSET_SHIFT)) /* 3 bits */
a62b1201 54
759ba3f2
KW
55/* Manually decorate these functions here with gcc-style attributes just to
56 * avoid making the regex_charset typedef global, which it would need to be for
57 * proto.h to understand it */
a62b1201
KW
58PERL_STATIC_INLINE void
59set_regex_charset(U32 * const flags, const regex_charset cs)
60 __attribute__nonnull__(1);
61
62PERL_STATIC_INLINE void
63set_regex_charset(U32 * const flags, const regex_charset cs)
64{
65 /* Sets the character set portion of 'flags' to 'cs', which is a member of
66 * the above enum */
67
68 *flags &= ~RXf_PMf_CHARSET;
69 *flags |= (cs << _RXf_PMf_CHARSET_SHIFT);
70}
71
72PERL_STATIC_INLINE regex_charset
73get_regex_charset(const U32 flags)
74 __attribute__warn_unused_result__;
75
76PERL_STATIC_INLINE regex_charset
77get_regex_charset(const U32 flags)
78{
79 /* Returns the enum corresponding to the character set in 'flags' */
80
bfba585a 81 return (regex_charset) ((flags & RXf_PMf_CHARSET) >> _RXf_PMf_CHARSET_SHIFT);
a62b1201 82}
1850c8f9 83
334afb3e 84#define _RXf_PMf_SHIFT_COMPILETIME (RXf_PMf_STD_PMMOD_SHIFT+9)
dbc200c5
YO
85
86/*
87 Set in Perl_pmruntime if op_flags & OPf_SPECIAL, i.e. split. Will
88 be used by regex engines to check whether they should set
89 RXf_SKIPWHITE
90*/
334afb3e 91#define RXf_PMf_SPLIT (1<<(RXf_PMf_STD_PMMOD_SHIFT+9))
dbc200c5 92
3214c85f
KW
93/* Next available bit after the above. Name begins with '_' so won't be
94 * exported by B */
334afb3e 95#define _RXf_PMf_SHIFT_NEXT (RXf_PMf_STD_PMMOD_SHIFT+10)
bb1c6009 96
5b126c84
KW
97/* Mask of the above bits. These need to be transferred from op_pmflags to
98 * re->extflags during compilation */
334afb3e 99#define RXf_PMf_COMPILETIME (RXf_PMf_MULTILINE|RXf_PMf_SINGLELINE|RXf_PMf_FOLD|RXf_PMf_EXTENDED|RXf_PMf_EXTENDED_MORE|RXf_PMf_KEEPCOPY|RXf_PMf_CHARSET)
9a7d4f5f 100#define RXf_PMf_FLAGCOPYMASK (RXf_PMf_COMPILETIME|RXf_PMf_SPLIT)
bb1c6009 101
13f27704
KW
102 /* Exclude win32 because it can't cope with I32_MAX definition */
103#ifndef WIN32
104# if RXf_PMf_COMPILETIME > I32_MAX
105# error RXf_PMf_COMPILETIME wont fit in arg2 field of eval node
106# endif
db703679
DM
107#endif
108
bb1c6009 109/* These copies need to be numerical or defsubs_h.PL won't know about them. */
a297f627
KW
110#define PMf_MULTILINE 1<<0
111#define PMf_SINGLELINE 1<<1
112#define PMf_FOLD 1<<2
113#define PMf_EXTENDED 1<<3
334afb3e
KW
114#define PMf_EXTENDED_MORE 1<<4
115#define PMf_KEEPCOPY 1<<5
116#define PMf_CHARSET 7<<6
117#define PMf_SPLIT 1<<9
bb1c6009 118
334afb3e 119#if PMf_MULTILINE != RXf_PMf_MULTILINE || PMf_SINGLELINE != RXf_PMf_SINGLELINE || PMf_FOLD != RXf_PMf_FOLD || PMf_EXTENDED != RXf_PMf_EXTENDED || PMf_EXTENDED_MORE != RXf_PMf_EXTENDED_MORE || PMf_KEEPCOPY != RXf_PMf_KEEPCOPY || PMf_SPLIT != RXf_PMf_SPLIT || PMf_CHARSET != RXf_PMf_CHARSET
bb1c6009
KW
120# error RXf_PMf defines are wrong
121#endif
5b126c84 122
5b126c84
KW
123/* Error check that haven't left something out of this. This isn't done
124 * directly in the #define because doing so confuses regcomp.pl.
125 * (2**n - 1) is n 1 bits, so the below gets the contiguous bits between the
126 * beginning and ending shifts */
dbc200c5 127#if RXf_PMf_COMPILETIME != (((1 << (_RXf_PMf_SHIFT_COMPILETIME))-1) \
5b126c84
KW
128 & (~((1 << RXf_PMf_STD_PMMOD_SHIFT)-1)))
129# error RXf_PMf_COMPILETIME is invalid
130#endif
93136d17
KW
131
132#endif /* Include only once */