32 #ifndef _GLIBCXX_REGEX_STATE_LIMIT
33 #define _GLIBCXX_REGEX_STATE_LIMIT 100000
36 namespace std _GLIBCXX_VISIBILITY(default)
38 _GLIBCXX_BEGIN_NAMESPACE_VERSION
48 typedef long _StateIdT;
49 static const _StateIdT _S_invalid_state_id = -1;
51 template<
typename _CharT>
52 using _Matcher = std::function<bool (_CharT)>;
59 _S_opcode_alternative,
62 _S_opcode_line_begin_assertion,
63 _S_opcode_line_end_assertion,
64 _S_opcode_word_boundary,
65 _S_opcode_subexpr_lookahead,
66 _S_opcode_subexpr_begin,
67 _S_opcode_subexpr_end,
83 size_t _M_backref_index;
94 __gnu_cxx::__aligned_membuf<_Matcher<char>> _M_matcher_storage;
98 explicit _State_base(
_Opcode __opcode)
99 : _M_opcode(__opcode), _M_next(_S_invalid_state_id)
106 return _M_opcode == _S_opcode_alternative
107 || _M_opcode == _S_opcode_repeat
108 || _M_opcode == _S_opcode_subexpr_lookahead;
111 #ifdef _GLIBCXX_DEBUG
121 template<
typename _Char_type>
122 struct _State : _State_base
124 typedef _Matcher<_Char_type> _MatcherT;
125 static_assert(
sizeof(_MatcherT) ==
sizeof(_Matcher<char>),
126 "std::function<bool(T)> has the same size as "
127 "std::function<bool(char)>");
128 static_assert(
alignof(_MatcherT) ==
alignof(_Matcher<char>),
129 "std::function<bool(T)> has the same alignment as "
130 "std::function<bool(char)>");
133 _State(
_Opcode __opcode) : _State_base(__opcode)
135 if (_M_opcode() == _S_opcode_match)
136 new (this->_M_matcher_storage._M_addr()) _MatcherT();
139 _State(
const _State& __rhs) : _State_base(__rhs)
141 if (__rhs._M_opcode() == _S_opcode_match)
142 new (this->_M_matcher_storage._M_addr())
143 _MatcherT(__rhs._M_get_matcher());
146 _State(_State&& __rhs) : _State_base(__rhs)
148 if (__rhs._M_opcode() == _S_opcode_match)
149 new (this->_M_matcher_storage._M_addr())
150 _MatcherT(
std::move(__rhs._M_get_matcher()));
154 operator=(
const _State&) =
delete;
158 if (_M_opcode() == _S_opcode_match)
159 _M_get_matcher().~_MatcherT();
166 {
return _State_base::_M_opcode; }
169 _M_matches(_Char_type __char)
const
170 {
return _M_get_matcher()(__char); }
174 {
return *
static_cast<_MatcherT*
>(this->_M_matcher_storage._M_addr()); }
177 _M_get_matcher()
const
179 return *
static_cast<const _MatcherT*
>(
180 this->_M_matcher_storage._M_addr());
186 typedef size_t _SizeT;
190 _NFA_base(_FlagT __f)
191 : _M_flags(__f), _M_start_state(0), _M_subexpr_count(0),
192 _M_has_backref(false)
195 _NFA_base(_NFA_base&&) =
default;
198 ~_NFA_base() =
default;
207 {
return _M_start_state; }
211 {
return _M_subexpr_count; }
213 _GLIBCXX_STD_C::vector<size_t> _M_paren_stack;
215 _StateIdT _M_start_state;
216 _SizeT _M_subexpr_count;
220 template<
typename _TraitsT>
222 : _NFA_base, _GLIBCXX_STD_C::vector<_State<typename _TraitsT::char_type>>
224 typedef typename _TraitsT::char_type _Char_type;
225 typedef _State<_Char_type> _StateT;
226 typedef _Matcher<_Char_type> _MatcherT;
228 _NFA(
const typename _TraitsT::locale_type& __loc, _FlagT __flags)
230 { _M_traits.imbue(__loc); }
233 _NFA(
const _NFA&) =
delete;
234 _NFA(_NFA&&) =
default;
239 auto __ret = _M_insert_state(_StateT(_S_opcode_accept));
244 _M_insert_alt(_StateIdT __next, _StateIdT __alt,
245 bool __neg __attribute__((__unused__)))
247 _StateT __tmp(_S_opcode_alternative);
250 __tmp._M_next = __next;
251 __tmp._M_alt = __alt;
252 return _M_insert_state(
std::move(__tmp));
256 _M_insert_repeat(_StateIdT __next, _StateIdT __alt,
bool __neg)
258 _StateT __tmp(_S_opcode_repeat);
261 __tmp._M_next = __next;
262 __tmp._M_alt = __alt;
263 __tmp._M_neg = __neg;
264 return _M_insert_state(
std::move(__tmp));
268 _M_insert_matcher(_MatcherT __m)
270 _StateT __tmp(_S_opcode_match);
272 return _M_insert_state(
std::move(__tmp));
276 _M_insert_subexpr_begin()
278 auto __id = this->_M_subexpr_count++;
279 this->_M_paren_stack.push_back(__id);
280 _StateT __tmp(_S_opcode_subexpr_begin);
281 __tmp._M_subexpr = __id;
282 return _M_insert_state(
std::move(__tmp));
286 _M_insert_subexpr_end()
288 _StateT __tmp(_S_opcode_subexpr_end);
289 __tmp._M_subexpr = this->_M_paren_stack.back();
290 this->_M_paren_stack.pop_back();
291 return _M_insert_state(
std::move(__tmp));
295 _M_insert_backref(
size_t __index);
298 _M_insert_line_begin()
299 {
return _M_insert_state(_StateT(_S_opcode_line_begin_assertion)); }
303 {
return _M_insert_state(_StateT(_S_opcode_line_end_assertion)); }
306 _M_insert_word_bound(
bool __neg)
308 _StateT __tmp(_S_opcode_word_boundary);
309 __tmp._M_neg = __neg;
310 return _M_insert_state(
std::move(__tmp));
314 _M_insert_lookahead(_StateIdT __alt,
bool __neg)
316 _StateT __tmp(_S_opcode_subexpr_lookahead);
317 __tmp._M_alt = __alt;
318 __tmp._M_neg = __neg;
319 return _M_insert_state(
std::move(__tmp));
324 {
return _M_insert_state(_StateT(_S_opcode_dummy)); }
327 _M_insert_state(_StateT __s)
330 if (this->
size() > _GLIBCXX_REGEX_STATE_LIMIT)
333 "Number of NFA states exceeds limit. Please use shorter regex "
334 "string, or use smaller brace expression, or make "
335 "_GLIBCXX_REGEX_STATE_LIMIT larger.");
336 return this->
size() - 1;
341 _M_eliminate_dummy();
343 #ifdef _GLIBCXX_DEBUG
354 template<
typename _TraitsT>
358 typedef _NFA<_TraitsT> _RegexT;
362 : _M_nfa(__nfa), _M_start(__s), _M_end(__s)
365 _StateSeq(_RegexT& __nfa, _StateIdT __s, _StateIdT __end)
366 : _M_nfa(__nfa), _M_start(__s), _M_end(__end)
371 _M_append(_StateIdT __id)
373 _M_nfa[_M_end]._M_next = __id;
381 _M_nfa[_M_end]._M_next = __s._M_start;
398 _GLIBCXX_END_NAMESPACE_VERSION
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
_Opcode
Operation codes that define the type of transitions within the base NFA that represents the regular e...
ISO C++ entities toplevel namespace is std.
constexpr error_type error_space(_S_error_space)
syntax_option_type
This is a bitmask type indicating how to interpret the regex.
Describes a sequence of one or more _State, its current start and end(s). This structure contains fra...
void push_back(const value_type &__x)
Add data to the end of the vector.
size_type size() const noexcept