initial import
[ICEs.git] / hppa-ICE-insn-constraints / regex.i.6
1 struct locale_data {
2 unsigned int nstrings;
3 union locale_data_value {
4 char *string;
5 unsigned int word;
6 } values[];
7 };
8 extern __thread struct locale_data *
9 *_nl_current_LC_CTYPE
10 __attribute__ ((tls_model("initial-exec")));
11 typedef unsigned long int reg_syntax_t;
12 extern reg_syntax_t re_syntax_options;
13 typedef enum {
14 REG_ENOSYS = -1, REG_NOERROR =
15 0, REG_NOMATCH, REG_BADPAT, REG_ECOLLATE, REG_ECTYPE, REG_EESCAPE,
16 REG_ESUBREG, REG_EBRACK, REG_EPAREN, REG_EBRACE, REG_BADBR,
17 REG_ERANGE, REG_ESPACE, REG_BADRPT, REG_EEND, REG_ESIZE, REG_ERPAREN
18 } reg_errcode_t;
19 typedef struct {
20 unsigned char *buffer;
21 reg_syntax_t syntax;
22 char *fastmap;
23 unsigned char *translate;
24 unsigned int re_nsub;
25 unsigned fastmap_accurate:1;
26 unsigned not_bol:1;
27 unsigned not_eol:1;
28 } regex_t;
29 extern __thread void *__libc_tsd_CTYPE_TOLOWER;
30 inline
31 int **
32 __ctype_tolower_loc(void)
33 {
34 union {
35 void **ptr;
36 int **tablep;
37 } u;
38 u.ptr = (&__libc_tsd_CTYPE_TOLOWER);
39 if (*u.tablep == 0)
40 *u.tablep =
41 ((int *)((*_nl_current_LC_CTYPE)->values[0].string) + 128);
42 return u.tablep;
43 }
44 inline int tolower(int __c)
45 {
46 return *__ctype_tolower_loc()[__c]
47 ;}
48 typedef struct {
49 } mbstate_t;
50 typedef unsigned long int *bitset_t;
51 typedef unsigned long int *re_bitset_ptr_t;
52 typedef struct {
53 int nelem;
54 int *elems;
55 } re_node_set;
56 typedef enum {
57 NON_TYPE = 0, CHARACTER = 1, END_OF_RE = 2, SIMPLE_BRACKET =
58 3, OP_BACK_REF = 4, OP_PERIOD = 5, COMPLEX_BRACKET =
59 6, OP_UTF8_PERIOD = 7, OP_OPEN_SUBEXP = 8 | 0, OP_CLOSE_SUBEXP =
60 8 | 1, OP_ALT = 8 | 2, OP_DUP_ASTERISK = 8 | 3, ANCHOR =
61 8 | 4, CONCAT = 16, SUBEXP = 17, OP_DUP_PLUS =
62 18, OP_DUP_QUESTION, OP_OPEN_BRACKET, OP_CLOSE_BRACKET,
63 OP_CHARSET_RANGE, OP_OPEN_DUP_NUM, OP_CLOSE_DUP_NUM,
64 OP_NON_MATCH_LIST, OP_OPEN_COLL_ELEM, OP_CLOSE_COLL_ELEM,
65 OP_OPEN_EQUIV_CLASS, OP_CLOSE_EQUIV_CLASS, OP_OPEN_CHAR_CLASS,
66 OP_CLOSE_CHAR_CLASS, OP_WORD, OP_NOTWORD, OP_SPACE, OP_NOTSPACE,
67 BACK_SLASH
68 } re_token_type_t;
69 typedef struct {
70 long int *mbchars;
71 int nmbchars;
72 } re_charset_t;
73 typedef struct {
74 union {
75 unsigned char c;
76 re_bitset_ptr_t sbcset;
77 re_charset_t *mbcset;
78 int idx;
79 } opr;
80 re_token_type_t type:8;
81 } re_token_t;
82 typedef struct re_dfa_t re_dfa_t;
83 typedef struct bin_tree_t bin_tree_t;
84 struct re_dfastate_t {
85 re_node_set nodes;
86 };
87 typedef struct re_dfastate_t re_dfastate_t;
88 struct re_dfa_t {
89 re_token_t *nodes;
90 unsigned int nodes_len;
91 int *nexts;
92 int *org_indices;
93 re_node_set *edests;
94 re_node_set *eclosures;
95 re_dfastate_t *init_state;
96 bin_tree_t *str_tree;
97 re_bitset_ptr_t sb_char;
98 int nbackref;
99 unsigned int has_mb_node:1;
100 unsigned int is_utf8:1;
101 unsigned int map_notascii:1;
102 int mb_cur_max;
103 int *subexp_map;
104 };
105 static reg_errcode_t re_compile_internal(regex_t * preg,
106 const
107 char *pattern,
108 unsigned int length,
109 reg_syntax_t syntax);
110 static void re_compile_fastmap_iter(regex_t * bufp,
111 const re_dfastate_t * init_state,
112 char *fastmap);
113 static reg_errcode_t analyze(regex_t * preg);
114 static reg_errcode_t optimize_subexps(void *extra, bin_tree_t * node);
115 const char *__re_compile_pattern(pattern, length, bufp)
116 const char *pattern;
117 {
118 reg_errcode_t ret;
119 ret = re_compile_internal(bufp, pattern, length, re_syntax_options);
120 }
121
122 int __re_compile_fastmap(regex_t *bufp)
123 {
124 re_dfa_t *dfa = (re_dfa_t *) bufp->buffer;
125 char *fastmap = bufp->fastmap;
126 re_compile_fastmap_iter(bufp, dfa->init_state, fastmap);
127 }
128 static inline void
129 re_set_fastmap(char *fastmap, int icase,
130 int ch)
131 {
132 if (icase) {
133 int __res;
134 if (sizeof(ch) > 1) {
135 if (ch) {
136 } else
137 __res = tolower(ch);
138 }
139 fastmap[__res] = 1;
140 }
141 }
142 static void re_compile_fastmap_iter(regex_t * bufp,
143 const re_dfastate_t * init_state,
144 char *fastmap)
145 {
146 re_dfa_t *dfa = (re_dfa_t *) bufp->buffer;
147 int node_cnt;
148 int icase = (dfa->mb_cur_max == 1 && (bufp->syntax & 0x40000));
149 for (node_cnt = 0; node_cnt < init_state->nodes.nelem; ++node_cnt) {
150 int node = init_state->nodes.elems[node_cnt];
151 re_token_type_t type = dfa->nodes[node].type;
152 if (type == CHARACTER) {
153 if ((bufp->syntax & 0x40000) && dfa->mb_cur_max > 1) {
154 unsigned char *buf
155 =
156 alloca(dfa->mb_cur_max);
157 }
158 int i;
159 int ch;
160 for (;
161 i < (256 / (sizeof(unsigned long int) * 8)); ) {
162 int j;
163 unsigned long int w =
164 dfa->nodes[node].opr.sbcset[i];
165 for (; j < (sizeof(unsigned long int) * 8);)
166 if (w & ((unsigned long int)1 << j))
167 re_set_fastmap(fastmap, icase,
168 ch);
169 }
170 } else if (type == COMPLEX_BRACKET) {
171 int i;
172 re_charset_t *cset = dfa->nodes[node].opr.mbcset;
173 for (i = 0; i < cset->nmbchars; ++i) {
174 char buf[256];
175 mbstate_t state;
176 if (__wcrtomb(buf, cset->mbchars[i], &state) !=
177 (unsigned int)-1)
178 re_set_fastmap(fastmap, icase,
179 *(unsigned char *)buf);
180 if ((bufp->syntax & 0x4000)
181 && dfa->mb_cur_max > 1) {
182 if (__wcrtomb
183 (buf, towlower(cset->mbchars[i]),
184 &state) != (unsigned int)-1)
185 re_set_fastmap(fastmap, 0,
186 *(unsigned char
187 *)buf);
188 }
189 }
190 }
191 }
192 }
193 static const bitset_t utf8_sb_map;
194 static reg_errcode_t re_compile_internal(regex_t * preg, const char *pattern,
195 unsigned int length,
196 reg_syntax_t syntax)
197 {
198 reg_errcode_t err;
199 re_dfa_t *dfa;
200 preg->fastmap_accurate = 0;
201 preg->not_bol = preg->not_eol = 0;
202 err = analyze(preg);
203 if (dfa->is_utf8 && !(syntax & 0x400000) && preg->translate == 0)
204 optimize_utf8(dfa);
205 if (dfa->mb_cur_max == 6 && __extension__( {
206 unsigned int __s1_len;
207 unsigned int __s2_len;
208 (
209 (__s1_len =
210 strlen(((*_nl_current_LC_CTYPE)->values[0].string)), __s2_len = strlen("UTF-8"), (!((unsigned int)(const void *)((((*_nl_current_LC_CTYPE)->values[0].string)) + 1) - (unsigned int)(const void *)(((*_nl_current_LC_CTYPE)->values[0].string)) == 1) || __s1_len >= 4) && (!((unsigned int)(const void *)(("UTF-8") + 1) - (unsigned int)(const void *)("UTF-8") == 1) || __s2_len >= 4)) ? strcmp(((*_nl_current_LC_CTYPE)->values[0].string), "UTF-8") : (
211 ((unsigned int)(const void *)((((*_nl_current_LC_CTYPE)->values[0].string)) + 1) - (unsigned int)(const void *)(((*_nl_current_LC_CTYPE)->values[0].string)) == 1) && (__s1_len = strlen(((*_nl_current_LC_CTYPE)->values[0].string)), __s1_len < 4) ? (
212 ((unsigned int)(const void *)(("UTF-8") + 1) - (unsigned int)(const void *)("UTF-8") == 1) ?
213 strcmp(((*_nl_current_LC_CTYPE)->values[0].string), "UTF-8") : (__extension__( {
214 __const
215 unsigned
216 char
217 *__s2
218 =
219 (__const
220 unsigned
221 char
222 *)
223 (__const
224 char
225 *)
226 ("UTF-8");
227 register
228 int
229 __result
230 =
231 (((__const unsigned char *)(__const char *)(((*_nl_current_LC_CTYPE)->values[0].string)))[0] - __s2[0]); __result;}
232 ))): (
233 ((unsigned int)(const void *)(("UTF-8") + 1) - (unsigned int)(const void *)("UTF-8") == 1) && (__s2_len = strlen("UTF-8"), __s2_len < 4) ? (
234 ((unsigned int)(const void *)((((*_nl_current_LC_CTYPE)->values[0].string)) + 1) - (unsigned int)(const void *)(((*_nl_current_LC_CTYPE)->values[0].string)) == 1) ?
235 strcmp(((*_nl_current_LC_CTYPE)->values[0].string), "UTF-8") : (__extension__( {
236 __const
237 unsigned
238 char
239 *__s1
240 =
241 (__const
242 unsigned
243 char
244 *)
245 (__const
246 char
247 *)
248 (((*_nl_current_LC_CTYPE)->values[0].string)); register int __result = __s1[0] - ((__const unsigned char *)(__const char *)("UTF-8"))[0]; __result;}
249 ))): strcmp(((*_nl_current_LC_CTYPE)->values[0].string), "UTF-8"))));}
250 ) == 0)
251 dfa->is_utf8 = 1;
252 dfa->map_notascii =
253 (((unsigned int)(*_nl_current_LC_CTYPE)->values[0].word) != 0);
254 if (dfa->mb_cur_max > 1) {
255 if (dfa->is_utf8)
256 dfa->sb_char = (re_bitset_ptr_t) utf8_sb_map;
257 else {
258 int i;
259 int j;
260 int ch;
261 dfa->sb_char =
262 (re_bitset_ptr_t) calloc(sizeof(bitset_t), 1);
263 for (i = 0, ch = 0;
264 i < (256 / (sizeof(unsigned long int) * 8)); ++i)
265 for (j = 0; j < (sizeof(unsigned long int) * 8);
266 ++j, ++ch) {
267 unsigned int wch = __btowc(ch);
268 if (wch != (0xffffffffu))
269 dfa->sb_char[i] |=
270 (unsigned long int)1 << j;
271 }
272 }
273 }
274 int node;
275 int i;
276 int mb_chars;
277 int has_period;
278 for (
279 ; node < dfa->nodes_len;)
280 switch (dfa->nodes[node].type) {
281 case CHARACTER:
282 if (dfa->nodes[node].opr.c >= 0x80)
283 mb_chars = 1;
284 case ANCHOR:
285 switch (dfa->nodes[node].opr.idx) {
286 }
287 case OP_PERIOD:
288 has_period = 1;
289 for (i = 0x80 / (sizeof(unsigned long int) * 8);
290 i < (256 / (sizeof(unsigned long int) * 8)); ++i)
291 if (dfa->nodes[node].opr.sbcset[i])
292 return;
293 }
294 dfa->has_mb_node = dfa->nbackref > 0 || has_period;
295 }
296 static reg_errcode_t analyze(regex_t * preg)
297 {
298 re_dfa_t *dfa = (re_dfa_t *) preg->buffer;
299 if (
300 (dfa->nexts == 0 || dfa->org_indices == 0 || dfa->edests == 0
301 || dfa->eclosures == 0))
302 return REG_ESPACE;
303 if (dfa->subexp_map != 0) {
304 int i;
305 for (
306 ; i < preg->re_nsub;
307 )
308 dfa->subexp_map[i] = i;
309 preorder(dfa->str_tree, optimize_subexps, dfa);
310 for (i = 0; i < preg->re_nsub; i++)
311 if (dfa->subexp_map[i] != i)
312 break;
313 }
314 }