diff options
author | timshen <timshen@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-10-06 17:53:14 +0000 |
---|---|---|
committer | timshen <timshen@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-10-06 17:53:14 +0000 |
commit | 96f22277dec96894381ec19337dc1a20d5119dc8 (patch) | |
tree | 11e71078d7989a6eeed530a3f83baefff784fb8b | |
parent | 02d3a327c95fd3eeaac76b7c002c0f890a2609bb (diff) | |
download | gcc-96f22277dec96894381ec19337dc1a20d5119dc8.tar.gz |
2013-10-06 Tim Shen <timshen91@gmail.com>
* include/bits/regex.h: (regex_token_iterator<>::regex_token_iterator):
Fix compile error.
* include/bits/regex.tcc: (regex_replace<>): Remove default parameter.
2013-10-06 Tim Shen <timshen91@gmail.com>
* include/bits/regex.h (__regex_algo_impl<>, regex_match<>,
regex_search<>): New abstract function for regex_match and regex_search.
* include/bits/regex.tcc (__regex_algo_impl<>): Implement.
* include/bits/regex_executor.h
(_Executor<>::_M_lookahead,
_DFSExecutor<>::_M_clone,
_BFSExecutor<>::_M_clone): Let _M_clone to choose which executor to
use.
* include/bits/regex_executor.tcc (__get_executor<>): Update the
definition to support __policy.
* testsuite/28_regex/algorithms/regex_match/awk/cstring_01.cc: Use
*_debug.
* testsuite/28_regex/algorithms/regex_match/basic/empty_range.cc: Same.
* testsuite/28_regex/algorithms/regex_match/basic/string_01.cc: Same.
* testsuite/28_regex/algorithms/regex_match/basic/string_range_00_03.cc:
Same.
* testsuite/28_regex/algorithms/regex_match/basic/string_range_01_03.cc:
Same.
* testsuite/28_regex/algorithms/regex_match/basic/string_range_02_03.cc:
Same.
* testsuite/28_regex/algorithms/regex_match/ecma/char/53622.cc: Same.
* testsuite/28_regex/algorithms/regex_match/ecma/char/57173.cc: Same.
* testsuite/28_regex/algorithms/regex_match/ecma/char/58576.cc: Same.
* testsuite/28_regex/algorithms/regex_match/ecma/char/anymatcher.cc:
Same.
* testsuite/28_regex/algorithms/regex_match/ecma/char/backref.cc: Same.
* testsuite/28_regex/algorithms/regex_match/ecma/char/empty_range.cc:
Same.
* testsuite/28_regex/algorithms/regex_match/ecma/char/emptygroup.cc:
Same.
* testsuite/28_regex/algorithms/regex_match/ecma/char/hex.cc: Same.
* testsuite/28_regex/algorithms/regex_match/ecma/char/quoted_char.cc:
Same.
* testsuite/28_regex/algorithms/regex_match/ecma/wchar_t/anymatcher.cc:
Same.
* testsuite/28_regex/algorithms/regex_match/ecma/wchar_t/hex.cc: Same.
* testsuite/28_regex/algorithms/regex_match/extended/
string_bracket_01.cc: Same.
* testsuite/28_regex/algorithms/regex_match/extended/cstring_plus.cc:
Same.
* testsuite/28_regex/algorithms/regex_match/extended/
string_questionmark.cc: Same.
* testsuite/28_regex/algorithms/regex_match/extended/cstring_range.cc:
Same.
* testsuite/28_regex/algorithms/regex_match/extended/string_any.cc:
Same.
* testsuite/28_regex/algorithms/regex_match/extended/
string_dispatch_01.cc: Same.
* testsuite/28_regex/algorithms/regex_match/extended/
string_range_00_03.cc: Same.
* testsuite/28_regex/algorithms/regex_match/extended/
string_range_01_03.cc: Same.
* testsuite/28_regex/algorithms/regex_match/extended/
string_range_02_03.cc: Same.
* testsuite/28_regex/algorithms/regex_match/extended/wstring_locale.cc:
Same.
* testsuite/28_regex/algorithms/regex_search/basic/string_01.cc: Same.
* testsuite/28_regex/algorithms/regex_search/ecma/assertion.cc: Same.
* testsuite/28_regex/algorithms/regex_search/ecma/flags.cc: Same.
* testsuite/28_regex/algorithms/regex_search/ecma/greedy.cc: Same.
* testsuite/28_regex/algorithms/regex_search/ecma/string_01.cc: Same.
* testsuite/28_regex/match_results/format.cc: Same.
* testsuite/util/testsuite_regex.h
(regex_match_debug<>, regex_search_debug<>): Implement.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@203231 138bc75d-0d04-0410-961f-82ee72b054a4
42 files changed, 680 insertions, 317 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 4a00019bae0..377ac0e7e9f 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,76 @@ +2013-10-06 Tim Shen <timshen91@gmail.com> + + * include/bits/regex.h: (regex_token_iterator<>::regex_token_iterator): + Fix compile error. + * include/bits/regex.tcc: (regex_replace<>): Remove default parameter. + +2013-10-06 Tim Shen <timshen91@gmail.com> + + * include/bits/regex.h (__regex_algo_impl<>, regex_match<>, + regex_search<>): New abstract function for regex_match and regex_search. + * include/bits/regex.tcc (__regex_algo_impl<>): Implement. + * include/bits/regex_executor.h + (_Executor<>::_M_lookahead, + _DFSExecutor<>::_M_clone, + _BFSExecutor<>::_M_clone): Let _M_clone to choose which executor to + use. + * include/bits/regex_executor.tcc (__get_executor<>): Update the + definition to support __policy. + * testsuite/28_regex/algorithms/regex_match/awk/cstring_01.cc: Use + *_debug. + * testsuite/28_regex/algorithms/regex_match/basic/empty_range.cc: Same. + * testsuite/28_regex/algorithms/regex_match/basic/string_01.cc: Same. + * testsuite/28_regex/algorithms/regex_match/basic/string_range_00_03.cc: + Same. + * testsuite/28_regex/algorithms/regex_match/basic/string_range_01_03.cc: + Same. + * testsuite/28_regex/algorithms/regex_match/basic/string_range_02_03.cc: + Same. + * testsuite/28_regex/algorithms/regex_match/ecma/char/53622.cc: Same. + * testsuite/28_regex/algorithms/regex_match/ecma/char/57173.cc: Same. + * testsuite/28_regex/algorithms/regex_match/ecma/char/58576.cc: Same. + * testsuite/28_regex/algorithms/regex_match/ecma/char/anymatcher.cc: + Same. + * testsuite/28_regex/algorithms/regex_match/ecma/char/backref.cc: Same. + * testsuite/28_regex/algorithms/regex_match/ecma/char/empty_range.cc: + Same. + * testsuite/28_regex/algorithms/regex_match/ecma/char/emptygroup.cc: + Same. + * testsuite/28_regex/algorithms/regex_match/ecma/char/hex.cc: Same. + * testsuite/28_regex/algorithms/regex_match/ecma/char/quoted_char.cc: + Same. + * testsuite/28_regex/algorithms/regex_match/ecma/wchar_t/anymatcher.cc: + Same. + * testsuite/28_regex/algorithms/regex_match/ecma/wchar_t/hex.cc: Same. + * testsuite/28_regex/algorithms/regex_match/extended/ + string_bracket_01.cc: Same. + * testsuite/28_regex/algorithms/regex_match/extended/cstring_plus.cc: + Same. + * testsuite/28_regex/algorithms/regex_match/extended/ + string_questionmark.cc: Same. + * testsuite/28_regex/algorithms/regex_match/extended/cstring_range.cc: + Same. + * testsuite/28_regex/algorithms/regex_match/extended/string_any.cc: + Same. + * testsuite/28_regex/algorithms/regex_match/extended/ + string_dispatch_01.cc: Same. + * testsuite/28_regex/algorithms/regex_match/extended/ + string_range_00_03.cc: Same. + * testsuite/28_regex/algorithms/regex_match/extended/ + string_range_01_03.cc: Same. + * testsuite/28_regex/algorithms/regex_match/extended/ + string_range_02_03.cc: Same. + * testsuite/28_regex/algorithms/regex_match/extended/wstring_locale.cc: + Same. + * testsuite/28_regex/algorithms/regex_search/basic/string_01.cc: Same. + * testsuite/28_regex/algorithms/regex_search/ecma/assertion.cc: Same. + * testsuite/28_regex/algorithms/regex_search/ecma/flags.cc: Same. + * testsuite/28_regex/algorithms/regex_search/ecma/greedy.cc: Same. + * testsuite/28_regex/algorithms/regex_search/ecma/string_01.cc: Same. + * testsuite/28_regex/match_results/format.cc: Same. + * testsuite/util/testsuite_regex.h + (regex_match_debug<>, regex_search_debug<>): Implement. + 2013-10-06 Oleg Endo <olegendo@gcc.gnu.org> Paolo Carlini <paolo.carlini@oracle.com> diff --git a/libstdc++-v3/include/bits/regex.h b/libstdc++-v3/include/bits/regex.h index 4d7e7d7ff36..3420f10b18b 100644 --- a/libstdc++-v3/include/bits/regex.h +++ b/libstdc++-v3/include/bits/regex.h @@ -32,6 +32,24 @@ namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION +namespace __detail +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + template<typename _BiIter, typename _Alloc, + typename _CharT, typename _TraitsT, + _RegexExecutorPolicy __policy, + bool __match_mode> + bool + __regex_algo_impl(_BiIter __s, + _BiIter __e, + match_results<_BiIter, _Alloc>& __m, + const basic_regex<_CharT, _TraitsT>& __re, + regex_constants::match_flag_type __flags); + +_GLIBCXX_END_NAMESPACE_VERSION +} + /** * @addtogroup regex * @{ @@ -713,7 +731,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _AutomatonPtr; template<typename _BiIter, typename _Alloc, - typename _CharT, typename _TraitsT> + typename _CharT, typename _TraitsT, + __detail::_RegexExecutorPolicy __policy> friend std::unique_ptr< __detail::_Executor<_BiIter, _Alloc, _CharT, _TraitsT>> __detail::__get_executor(_BiIter, @@ -722,19 +741,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION const basic_regex<_CharT, _TraitsT>&, regex_constants::match_flag_type); - template<typename _Bp, typename _Ap, typename _Cp, typename _Rp> - friend bool - regex_match(_Bp, _Bp, - match_results<_Bp, _Ap>&, - const basic_regex<_Cp, _Rp>&, - regex_constants::match_flag_type); - - template<typename _Bp, typename _Ap, typename _Cp, typename _Rp> + template<typename _Bp, typename _Ap, typename _Cp, typename _Rp, + __detail::_RegexExecutorPolicy, bool> friend bool - regex_search(_Bp, _Bp, - match_results<_Bp, _Ap>&, - const basic_regex<_Cp, _Rp>&, - regex_constants::match_flag_type); + __detail::__regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&, + const basic_regex<_Cp, _Rp>&, + regex_constants::match_flag_type); template<typename, typename, typename, typename> friend class __detail::_Executor; @@ -1851,21 +1863,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename, typename, typename> friend class regex_iterator; - template<typename _Bp, typename _Ap, - typename _Ch_type, typename _Rx_traits> - friend bool - regex_match(_Bp, _Bp, match_results<_Bp, _Ap>&, - const basic_regex<_Ch_type, - _Rx_traits>&, - regex_constants::match_flag_type); - - template<typename _Bp, typename _Ap, - typename _Ch_type, typename _Rx_traits> + template<typename _Bp, typename _Ap, typename _Cp, typename _Rp, + __detail::_RegexExecutorPolicy, bool> friend bool - regex_search(_Bp, _Bp, match_results<_Bp, _Ap>&, - const basic_regex<_Ch_type, - _Rx_traits>&, - regex_constants::match_flag_type); + __detail::__regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&, + const basic_regex<_Cp, _Rp>&, + regex_constants::match_flag_type); _Bi_iter _M_begin; bool _M_in_iterator; @@ -1951,13 +1954,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ template<typename _Bi_iter, typename _Alloc, typename _Ch_type, typename _Rx_traits> - bool + inline bool regex_match(_Bi_iter __s, _Bi_iter __e, match_results<_Bi_iter, _Alloc>& __m, const basic_regex<_Ch_type, _Rx_traits>& __re, regex_constants::match_flag_type __flags - = regex_constants::match_default); + = regex_constants::match_default) + { + return __detail::__regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits, + __detail::_RegexExecutorPolicy::_S_auto, true> + (__s, __e, __m, __re, __flags); + } /** * @brief Indicates if there is a match between the regular expression @p e @@ -2091,12 +2099,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ template<typename _Bi_iter, typename _Alloc, typename _Ch_type, typename _Rx_traits> - bool - regex_search(_Bi_iter __first, _Bi_iter __last, + inline bool + regex_search(_Bi_iter __s, _Bi_iter __e, match_results<_Bi_iter, _Alloc>& __m, const basic_regex<_Ch_type, _Rx_traits>& __re, regex_constants::match_flag_type __flags - = regex_constants::match_default); + = regex_constants::match_default) + { + return __detail::__regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits, + __detail::_RegexExecutorPolicy::_S_auto, false> + (__s, __e, __m, __re, __flags); + } /** * Searches for a regular expression within a range. @@ -2586,8 +2599,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @param __rhs [IN] A %regex_token_iterator to copy. */ regex_token_iterator(const regex_token_iterator& __rhs) - : _M_position(__rhs.position), _M_subs(__rhs.subs), _M_n(__rhs.N), - _M_result(__rhs.result), _M_suffix(__rhs.suffix), + : _M_position(__rhs._M_position), _M_subs(__rhs._M_subs), + _M_n(__rhs._M_n), _M_result(__rhs._M_result), _M_suffix(__rhs._M_suffix), _M_has_m1(__rhs._M_has_m1) { if (__rhs._M_result == &__rhs._M_suffix) diff --git a/libstdc++-v3/include/bits/regex.tcc b/libstdc++-v3/include/bits/regex.tcc index 24316d26616..128a92c2f0d 100644 --- a/libstdc++-v3/include/bits/regex.tcc +++ b/libstdc++-v3/include/bits/regex.tcc @@ -32,6 +32,83 @@ namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION +namespace __detail +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + // Result of merging regex_match and regex_search. + // + // __policy now can be _S_auto(auto dispatch by checking back-references) + // and _S_force_dfs(just use _DFSExecutor). + // + // That __match_mode is true means regex_match, else regex_search. + template<typename _BiIter, typename _Alloc, + typename _CharT, typename _TraitsT, + _RegexExecutorPolicy __policy, + bool __match_mode> + bool + __regex_algo_impl(_BiIter __s, + _BiIter __e, + match_results<_BiIter, _Alloc>& __m, + const basic_regex<_CharT, _TraitsT>& __re, + regex_constants::match_flag_type __flags) + { + if (__re._M_automaton == nullptr) + return false; + + typename match_results<_BiIter, _Alloc>::_Base_type& __res = __m; + __res.resize(__re._M_automaton->_M_sub_count() + 2); + for (auto& __it : __res) + __it.matched = false; + + typedef std::unique_ptr<_Executor<_BiIter, _Alloc, _CharT, _TraitsT>> + _ExecutorPtr; + typedef _DFSExecutor<_BiIter, _Alloc, _CharT, _TraitsT> _DFSExecutorT; + typedef _BFSExecutor<_BiIter, _Alloc, _CharT, _TraitsT> _BFSExecutorT; + + _ExecutorPtr __executor = + __get_executor<_BiIter, _Alloc, _CharT, _TraitsT, + __policy>(__s, __e, __res, __re, __flags); + + bool __ret; + if (__match_mode) + __ret = __executor->_M_match(); + else + __ret = __executor->_M_search(); + if (__ret) + { + for (auto __it : __res) + if (!__it.matched) + __it.first = __it.second = __e; + auto& __pre = __res[__res.size()-2]; + auto& __suf = __res[__res.size()-1]; + if (__match_mode) + { + __pre.matched = false; + __pre.first = __s; + __pre.second = __s; + __suf.matched = false; + __suf.first = __e; + __suf.second = __e; + } + else + { + __pre.first = __s; + __pre.second = __res[0].first; + __pre.matched = (__pre.first != __pre.second); + __suf.first = __res[0].second; + __suf.second = __e; + __suf.matched = (__suf.first != __suf.second); + } + if (__re.flags() & regex_constants::nosubs) + __res.resize(3); + } + return __ret; + } + +_GLIBCXX_END_NAMESPACE_VERSION +} + template<typename _Ch_type> template<typename _Fwd_iter> typename regex_traits<_Ch_type>::string_type @@ -295,7 +372,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION value(_Ch_type __ch, int __radix) const { std::basic_istringstream<char_type> __is(string_type(1, __ch)); - int __v; + long __v; if (__radix == 8) __is >> std::oct; else if (__radix == 16) @@ -318,7 +395,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION const __ctype_type& __fctyp(use_facet<__ctype_type>(__traits.getloc())); - auto __output = [&](int __idx) + auto __output = [&](size_t __idx) { auto& __sub = _Base_type::operator[](__idx); if (__sub.matched) @@ -376,7 +453,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __output(_Base_type::size()-1); else if (__fctyp.is(__ctype_type::digit, *__next)) { - int __num = __traits.value(*__next, 10); + long __num = __traits.value(*__next, 10); if (++__next != __fmt_last && __fctyp.is(__ctype_type::digit, *__next)) { @@ -395,90 +472,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __out; } - template<typename _Bi_iter, typename _Alloc, - typename _Ch_type, typename _Rx_traits> - bool - regex_match(_Bi_iter __s, - _Bi_iter __e, - match_results<_Bi_iter, _Alloc>& __m, - const basic_regex<_Ch_type, _Rx_traits>& __re, - regex_constants::match_flag_type __flags - = regex_constants::match_default) - { - if (__re._M_automaton == nullptr) - return false; - - typename match_results<_Bi_iter, _Alloc>::_Base_type& __res = __m; - auto __size = __re._M_automaton->_M_sub_count(); - __size += 2; - __res.resize(__size); - for (decltype(__size) __i = 0; __i < __size; ++__i) - __res[__i].matched = false; - - if (__detail::__get_executor(__s, __e, __res, __re, __flags)->_M_match()) - { - for (auto __it : __res) - if (!__it.matched) - __it.first = __it.second = __e; - auto& __pre = __res[__res.size()-2]; - auto& __suf = __res[__res.size()-1]; - __pre.matched = false; - __pre.first = __s; - __pre.second = __s; - __suf.matched = false; - __suf.first = __e; - __suf.second = __e; - return true; - } - return false; - } - - template<typename _Bi_iter, typename _Alloc, - typename _Ch_type, typename _Rx_traits> - bool - regex_search(_Bi_iter __first, _Bi_iter __last, - match_results<_Bi_iter, _Alloc>& __m, - const basic_regex<_Ch_type, _Rx_traits>& __re, - regex_constants::match_flag_type __flags - = regex_constants::match_default) - { - if (__re._M_automaton == nullptr) - return false; - - typename match_results<_Bi_iter, _Alloc>::_Base_type& __res = __m; - auto __size = __re._M_automaton->_M_sub_count(); - __size += 2; - __res.resize(__size); - for (decltype(__size) __i = 0; __i < __size; ++__i) - __res[__i].matched = false; - - if (__detail::__get_executor(__first, __last, __res, __re, __flags) - ->_M_search()) - { - for (auto __it : __res) - if (!__it.matched) - __it.first = __it.second = __last; - auto& __pre = __res[__res.size()-2]; - auto& __suf = __res[__res.size()-1]; - __pre.first = __first; - __pre.second = __res[0].first; - __pre.matched = (__pre.first != __pre.second); - __suf.first = __res[0].second; - __suf.second = __last; - __suf.matched = (__suf.first != __suf.second); - return true; - } - return false; - } - template<typename _Out_iter, typename _Bi_iter, typename _Rx_traits, typename _Ch_type> _Out_iter regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last, const basic_regex<_Ch_type, _Rx_traits>& __e, const _Ch_type* __fmt, - regex_constants::match_flag_type __flags - = regex_constants::match_default) + regex_constants::match_flag_type __flags) { typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> _IterT; _IterT __i(__first, __last, __e, __flags); diff --git a/libstdc++-v3/include/bits/regex_automaton.h b/libstdc++-v3/include/bits/regex_automaton.h index 94a14ce96aa..60744b20662 100644 --- a/libstdc++-v3/include/bits/regex_automaton.h +++ b/libstdc++-v3/include/bits/regex_automaton.h @@ -40,7 +40,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * @{ */ - typedef int _StateIdT; + typedef long _StateIdT; typedef std::set<_StateIdT> _StateSet; static const _StateIdT _S_invalid_state_id = -1; @@ -49,7 +49,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// Operation codes that define the type of transitions within the base NFA /// that represents the regular expression. - enum _Opcode + enum _Opcode : int { _S_opcode_unknown, _S_opcode_alternative, @@ -69,15 +69,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION class _State { public: - typedef int _OpcodeT; typedef _Matcher<_CharT> _MatcherT; - _OpcodeT _M_opcode; // type of outgoing transition + _Opcode _M_opcode; // type of outgoing transition _StateIdT _M_next; // outgoing transition union // Since they are mutually exclusive. { - unsigned int _M_subexpr; // for _S_opcode_subexpr_* - unsigned int _M_backref_index; // for _S_opcode_backref + size_t _M_subexpr; // for _S_opcode_subexpr_* + size_t _M_backref_index; // for _S_opcode_backref struct { // for _S_opcode_alternative. @@ -91,7 +90,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; _MatcherT _M_matches; // for _S_opcode_match - explicit _State(_OpcodeT __opcode) + explicit _State(_Opcode __opcode) : _M_opcode(__opcode), _M_next(_S_invalid_state_id) { } @@ -110,7 +109,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION class _Automaton { public: - typedef unsigned int _SizeT; + typedef size_t _SizeT; public: virtual _SizeT @@ -130,7 +129,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION public: typedef _State<_CharT, _TraitsT> _StateT; typedef const _Matcher<_CharT>& _MatcherT; - typedef unsigned int _SizeT; + typedef size_t _SizeT; typedef regex_constants::syntax_option_type _FlagT; _NFA(_FlagT __f) @@ -203,7 +202,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } _StateIdT - _M_insert_backref(unsigned int __index); + _M_insert_backref(size_t __index); _StateIdT _M_insert_line_begin() @@ -250,7 +249,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _M_dot(std::ostream& __ostr) const; #endif - std::vector<unsigned int> _M_paren_stack; + std::vector<size_t> _M_paren_stack; _StateSet _M_accepting_states; _FlagT _M_flags; _StateIdT _M_start_state; diff --git a/libstdc++-v3/include/bits/regex_automaton.tcc b/libstdc++-v3/include/bits/regex_automaton.tcc index 3402ef33d39..c15e3e99545 100644 --- a/libstdc++-v3/include/bits/regex_automaton.tcc +++ b/libstdc++-v3/include/bits/regex_automaton.tcc @@ -137,7 +137,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { __ostr << "digraph _Nfa {\n" << " rankdir=LR;\n"; - for (unsigned int __i = 0; __i < this->size(); ++__i) + for (size_t __i = 0; __i < this->size(); ++__i) { this->at(__i)._M_dot(__ostr, __i); } __ostr << "}\n"; return __ostr; @@ -146,7 +146,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _CharT, typename _TraitsT> _StateIdT _NFA<_CharT, _TraitsT>:: - _M_insert_backref(unsigned int __index) + _M_insert_backref(size_t __index) { // To figure out whether a backref is valid, a stack is used to store // unfinished sub-expressions. For example, when parsing diff --git a/libstdc++-v3/include/bits/regex_compiler.tcc b/libstdc++-v3/include/bits/regex_compiler.tcc index 5225bc1ee6c..52386ce4e64 100644 --- a/libstdc++-v3/include/bits/regex_compiler.tcc +++ b/libstdc++-v3/include/bits/regex_compiler.tcc @@ -222,9 +222,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __throw_regex_error(regex_constants::error_badbrace); _StateSeqT __r(_M_pop()); _StateSeqT __e(_M_nfa, _M_nfa._M_insert_dummy()); - int __min_rep = _M_cur_int_value(10); + long __min_rep = _M_cur_int_value(10); bool __infi = false; - int __n; + long __n; // {3 if (_M_match_token(_ScannerT::_S_token_comma)) @@ -239,7 +239,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __neg = __neg && _M_match_token(_ScannerT::_S_token_opt); - for (int __i = 0; __i < __min_rep; ++__i) + for (long __i = 0; __i < __min_rep; ++__i) __e._M_append(__r._M_clone()); if (__infi) @@ -260,7 +260,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // "match less" one. Switch _M_alt and _M_next of all created // nodes. This is a hacking but IMO works well. std::stack<_StateIdT> __stack; - for (int __i = 0; __i < __n; ++__i) + for (long __i = 0; __i < __n; ++__i) { auto __tmp = __r._M_clone(); auto __alt = _M_nfa._M_insert_alt(__tmp._M_start, @@ -318,7 +318,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } else if (_M_match_token(_ScannerT::_S_token_subexpr_begin)) { - int __mark = _M_nfa._M_sub_count(); + auto __mark = _M_nfa._M_sub_count(); _StateSeqT __r(_M_nfa, _M_nfa._M_insert_subexpr_begin()); this->_M_disjunction(); if (!_M_match_token(_ScannerT::_S_token_subexpr_end)) @@ -425,7 +425,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Compiler<_FwdIter, _CharT, _TraitsT>:: _M_cur_int_value(int __radix) { - int __v = 0; + long __v = 0; for (typename _StringT::size_type __i = 0; __i < _M_value.length(); ++__i) __v =__v * __radix + _M_traits.value(_M_value[__i], __radix); diff --git a/libstdc++-v3/include/bits/regex_executor.h b/libstdc++-v3/include/bits/regex_executor.h index a0149d2a548..2770098152b 100644 --- a/libstdc++-v3/include/bits/regex_executor.h +++ b/libstdc++-v3/include/bits/regex_executor.h @@ -145,8 +145,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION bool _M_word_boundry(_State<_CharT, _TraitsT> __state) const; + virtual std::unique_ptr<_Executor> + _M_clone() const = 0; + + // Return whether now match the given sub-NFA. bool - _M_lookahead(_State<_CharT, _TraitsT> __state) const; + _M_lookahead(_State<_CharT, _TraitsT> __state) const + { + auto __sub = this->_M_clone(); + __sub->_M_set_start(__state._M_alt); + return __sub->_M_search_from_first(); + } void _M_set_results(_ResultsVec& __cur_results); @@ -226,6 +235,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION bool _M_dfs(_StateIdT __start); + std::unique_ptr<_BaseT> + _M_clone() const + { + return std::unique_ptr<_BaseT>(new _DFSExecutor(this->_M_current, + this->_M_end, + this->_M_results, + this->_M_re, + this->_M_flags)); + } + // To record current solution. _ResultsVec _M_cur_results; const _NFAT& _M_nfa; @@ -268,8 +287,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // greedy policy. // // The definition of `greedy`: - // For the sequence of quantifiers in NFA sorted by there start position, - // now maintain a vector in every matching state, with equal length to + // For the sequence of quantifiers in NFA sorted by their start positions, + // now maintain a vector in every matching state, with length equal to // quantifier seq, recording repeating times of every quantifier. Now to // compare two matching states, we just lexically compare these two // vectors. To win the compare(to survive), one matching state needs to @@ -281,26 +300,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // operator<() for lexicographical_compare will emit the answer. // // When two vectors equal, it means the `where`, `when` and quantifier - // counts are identical, and indicates the same solution; so just return - // false. + // counts are identical, and indicates the same solution; so + // _ResultsEntry::operator<() just return false. struct _ResultsEntry : private _ResultsVec { public: - _ResultsEntry(unsigned int __res_sz, unsigned int __sz) + _ResultsEntry(size_t __res_sz, size_t __sz) : _ResultsVec(__res_sz), _M_quant_keys(__sz) { } void - resize(unsigned int __n) + resize(size_t __n) { _ResultsVec::resize(__n); } - unsigned int + size_t size() { return _ResultsVec::size(); } sub_match<_BiIter>& - operator[](unsigned int __idx) + operator[](size_t __idx) { return _ResultsVec::operator[](__idx); } bool @@ -315,7 +334,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } void - _M_inc(unsigned int __idx, bool __neg) + _M_inc(size_t __idx, bool __neg) { _M_quant_keys[__idx] += __neg ? 1 : -1; } _ResultsVec& @@ -369,6 +388,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION bool _M_includes_some(); + std::unique_ptr<_BaseT> + _M_clone() const + { + return std::unique_ptr<_BaseT>(new _BFSExecutor(this->_M_current, + this->_M_end, + this->_M_results, + this->_M_re, + this->_M_flags)); + } + std::map<_StateIdT, _ResultsPtr> _M_covered; // To record global optimal solution. _ResultsPtr _M_cur_results; @@ -376,15 +405,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _StateIdT _M_start_state; }; - template<typename _BiIter, typename _Alloc, - typename _CharT, typename _TraitsT> - std::unique_ptr<_Executor<_BiIter, _Alloc, _CharT, _TraitsT>> - __get_executor(_BiIter __b, - _BiIter __e, - std::vector<sub_match<_BiIter>, _Alloc>& __m, - const basic_regex<_CharT, _TraitsT>& __re, - regex_constants::match_flag_type __flags); - //@} regex-detail _GLIBCXX_END_NAMESPACE_VERSION } // namespace __detail diff --git a/libstdc++-v3/include/bits/regex_executor.tcc b/libstdc++-v3/include/bits/regex_executor.tcc index 60ba9527c64..3b1fcbc9e38 100644 --- a/libstdc++-v3/include/bits/regex_executor.tcc +++ b/libstdc++-v3/include/bits/regex_executor.tcc @@ -365,39 +365,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION return __ans; } - // Return whether now match the given sub-NFA. - template<typename _BiIter, typename _Alloc, - typename _CharT, typename _TraitsT> - bool _Executor<_BiIter, _Alloc, _CharT, _TraitsT>:: - _M_lookahead(_State<_CharT, _TraitsT> __state) const - { - auto __sub = __get_executor(this->_M_current, - this->_M_end, - this->_M_results, - this->_M_re, - this->_M_flags); - __sub->_M_set_start(__state._M_alt); - return __sub->_M_search_from_first(); - } - template<typename _BiIter, typename _Alloc, typename _CharT, typename _TraitsT> void _Executor<_BiIter, _Alloc, _CharT, _TraitsT>:: _M_set_results(_ResultsVec& __cur_results) { - if (_M_re.flags() & regex_constants::nosubs) - { - // truncate - __cur_results.resize(3); - _M_results.resize(3); - } - for (unsigned int __i = 0; __i < __cur_results.size(); ++__i) + for (size_t __i = 0; __i < __cur_results.size(); ++__i) if (__cur_results[__i].matched) _M_results[__i] = __cur_results[__i]; } + enum class _RegexExecutorPolicy : int + { _S_auto, _S_force_dfs }; + template<typename _BiIter, typename _Alloc, - typename _CharT, typename _TraitsT> + typename _CharT, typename _TraitsT, + _RegexExecutorPolicy __policy> std::unique_ptr<_Executor<_BiIter, _Alloc, _CharT, _TraitsT>> __get_executor(_BiIter __b, _BiIter __e, @@ -411,7 +394,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typedef _BFSExecutor<_BiIter, _Alloc, _CharT, _TraitsT> _BFSExecutorT; auto __p = std::static_pointer_cast<_NFA<_CharT, _TraitsT>> (__re._M_automaton); - if (__p->_M_has_backref) + if (__policy == _RegexExecutorPolicy::_S_force_dfs + || (__policy == _RegexExecutorPolicy::_S_auto && __p->_M_has_backref)) return _ExecutorPtr(new _DFSExecutorT(__b, __e, __m, __re, __flags)); return _ExecutorPtr(new _BFSExecutorT(__b, __e, __m, __re, __flags)); } diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/awk/cstring_01.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/awk/cstring_01.cc index d4edf123e97..e2bde2216df 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/awk/cstring_01.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/awk/cstring_01.cc @@ -25,7 +25,9 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> +using namespace __gnu_test; using namespace std; void @@ -34,12 +36,12 @@ test01() bool test __attribute__((unused)) = true; regex("\\[", regex_constants::awk); - VERIFY(regex_match("\"", regex("[\\\"]", regex_constants::awk))); - VERIFY(regex_match("/", regex("/", regex_constants::awk))); - VERIFY(regex_match("\a", regex("\\a", regex_constants::awk))); - VERIFY(regex_match("\"", regex("\\\"", regex_constants::awk))); - VERIFY(regex_match("5", regex("\\65", regex_constants::awk))); - VERIFY(regex_match("53", regex("\\0653", regex_constants::awk))); + VERIFY(regex_match_debug("\"", regex("[\\\"]", regex_constants::awk))); + VERIFY(regex_match_debug("/", regex("/", regex_constants::awk))); + VERIFY(regex_match_debug("\a", regex("\\a", regex_constants::awk))); + VERIFY(regex_match_debug("\"", regex("\\\"", regex_constants::awk))); + VERIFY(regex_match_debug("5", regex("\\65", regex_constants::awk))); + VERIFY(regex_match_debug("53", regex("\\0653", regex_constants::awk))); } int diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/basic/empty_range.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/basic/empty_range.cc index eb22569f337..dd0dac4392f 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/basic/empty_range.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/basic/empty_range.cc @@ -25,7 +25,9 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> +using namespace __gnu_test; using namespace std; void @@ -45,8 +47,8 @@ test01() } FAIL("[]"); FAIL("[^]"); - VERIFY(regex_match("]", regex("[]]", regex_constants::basic))); - VERIFY(!regex_match("]", regex("[^]]", regex_constants::basic))); + VERIFY(regex_match_debug ("]", regex("[]]", regex_constants::basic))); + VERIFY(!regex_match_debug ("]", regex("[^]]", regex_constants::basic))); } int diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/basic/string_01.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/basic/string_01.cc index 668309d8cbf..34cfa557f01 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/basic/string_01.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/basic/string_01.cc @@ -25,6 +25,10 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> + +using namespace __gnu_test; +using namespace std; void test01() @@ -35,7 +39,7 @@ test01() std::string target("aaba"); std::smatch m; - VERIFY( std::regex_match(target, m, re) ); + VERIFY( regex_match_debug(target, m, re) ); VERIFY( m.size() == re.mark_count()+1 ); VERIFY( m.empty() == false ); diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/basic/string_range_00_03.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/basic/string_range_00_03.cc index 18783866f5e..36f032d7024 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/basic/string_range_00_03.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/basic/string_range_00_03.cc @@ -25,6 +25,10 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> + +using namespace __gnu_test; +using namespace std; void test01() @@ -35,7 +39,7 @@ test01() std::string target("aa"); std::smatch m; - VERIFY( std::regex_match(target, m, re) ); + VERIFY( regex_match_debug(target, m, re) ); VERIFY( m.size() == re.mark_count()+1 ); VERIFY( m.empty() == false ); diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/basic/string_range_01_03.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/basic/string_range_01_03.cc index 93826a78fb3..812e3efa4d3 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/basic/string_range_01_03.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/basic/string_range_01_03.cc @@ -25,6 +25,10 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> + +using namespace __gnu_test; +using namespace std; void test01() @@ -35,7 +39,7 @@ test01() std::string target("aa"); std::smatch m; - VERIFY( std::regex_match(target, m, re) ); + VERIFY( regex_match_debug(target, m, re) ); VERIFY( m.size() == re.mark_count()+1 ); VERIFY( m.empty() == false ); diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/basic/string_range_02_03.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/basic/string_range_02_03.cc index 91bc101392b..0924ed0014b 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/basic/string_range_02_03.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/basic/string_range_02_03.cc @@ -25,6 +25,10 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> + +using namespace __gnu_test; +using namespace std; void test01() @@ -35,7 +39,7 @@ test01() std::string target("aa"); std::smatch m; - VERIFY( std::regex_match(target, m, re) ); + VERIFY( regex_match_debug(target, m, re) ); VERIFY( m.size() == re.mark_count()+1 ); VERIFY( m.empty() == false ); diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/53622.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/53622.cc index 5f4b1d1b894..5a762ab6eb4 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/53622.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/53622.cc @@ -24,6 +24,10 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> + +using namespace __gnu_test; +using namespace std; // libstdc++/53622 void @@ -36,7 +40,7 @@ test01() std::string target("zxcv/onetwoabc"); std::smatch m; - VERIFY( std::regex_match(target, m, re) ); + VERIFY( regex_match_debug(target, m, re) ); VERIFY( m.size() == 2 ); VERIFY( m[0].matched == true ); VERIFY( std::string(m[0].first, m[0].second) == "zxcv/onetwoabc" ); @@ -49,7 +53,7 @@ test01() std::string target("zxcv/onetwoabc"); std::smatch m; - VERIFY( std::regex_match(target, m, re) ); + VERIFY( regex_match_debug(target, m, re) ); VERIFY( m.size() == 3 ); VERIFY( m[0].matched == true ); VERIFY( std::string(m[0].first, m[0].second) == "zxcv/onetwoabc" ); diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/57173.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/57173.cc index b9a72c93f01..dc177e54274 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/57173.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/57173.cc @@ -24,6 +24,10 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> + +using namespace __gnu_test; +using namespace std; #include <iostream> // libstdc++/57173 @@ -37,7 +41,7 @@ test01() std::string target("/asdf/qwerty"); std::smatch m; - VERIFY( std::regex_match(target, m, re) ); + VERIFY( regex_match_debug(target, m, re) ); VERIFY( m.size() == 2 ); VERIFY( std::string(m[1].first, m[1].second) == "/qwerty"); } @@ -46,7 +50,7 @@ test01() std::string target("/asdf/qwerty"); std::smatch m; - VERIFY( std::regex_match(target, m, re) ); + VERIFY( regex_match_debug(target, m, re) ); VERIFY( m.size() == 3 ); VERIFY( std::string(m[1].first, m[1].second) == "/qwerty"); } diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/58576.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/58576.cc index 1a1365ceea2..f745ef34e37 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/58576.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/58576.cc @@ -24,13 +24,15 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> + +using namespace __gnu_test; +using namespace std; // libstdc++/58576 void test01() { - using namespace std; - bool test __attribute__((unused)) = true; string domain_name = "valid.hostname.org"; @@ -74,9 +76,9 @@ test01() }; try { - VERIFY(regex_match( domain_name, m, fqdn_regex )); + VERIFY(regex_match_debug( domain_name, m, fqdn_regex )); VERIFY(m.size() == sizeof(sol) / sizeof(*sol)); - for (int i = 0; i < (int)m.size(); i++) { + for (size_t i = 0; i < m.size(); i++) { string s(m[i].first, m[i].second); VERIFY(s == sol[i]); } diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/anymatcher.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/anymatcher.cc index 6e6095b8f24..866ff7fead8 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/anymatcher.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/anymatcher.cc @@ -25,7 +25,9 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> +using namespace __gnu_test; using namespace std; void @@ -37,7 +39,7 @@ test01() {\ regex re(res);\ string st(s);\ - VERIFY(!regex_match(st, re));\ + VERIFY(!regex_match_debug(st, re));\ } TEST(".", "\0"); TEST(".", "\n"); diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/backref.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/backref.cc index 321ce35a038..05a57725d04 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/backref.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/backref.cc @@ -25,7 +25,9 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> +using namespace __gnu_test; using namespace std; void diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/empty_range.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/empty_range.cc index 3c48d3521a5..9f09c7463e8 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/empty_range.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/empty_range.cc @@ -25,7 +25,9 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> +using namespace __gnu_test; using namespace std; void @@ -33,10 +35,10 @@ test01() { bool test __attribute__((unused)) = true; - VERIFY(!regex_match("x", regex("[]"))); - VERIFY(regex_match("x", regex("[^]"))); - VERIFY(!regex_match("]", regex("[]]"))); - VERIFY(!regex_match("]", regex("[^]]"))); + VERIFY(!regex_match_debug("x", regex("[]"))); + VERIFY(regex_match_debug("x", regex("[^]"))); + VERIFY(!regex_match_debug("]", regex("[]]"))); + VERIFY(!regex_match_debug("]", regex("[^]]"))); } int diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/emptygroup.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/emptygroup.cc index 1dc8f63f789..77fd43c0acb 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/emptygroup.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/emptygroup.cc @@ -25,7 +25,9 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> +using namespace __gnu_test; using namespace std; void @@ -37,7 +39,7 @@ test01() regex re("()*\\1"); cmatch m; const char s[] = ""; - VERIFY( regex_match(s, m, re) ); + VERIFY( regex_match_debug(s, m, re) ); VERIFY( m.size() == 2 ); VERIFY( m[0].matched ); VERIFY( m[1].matched ); @@ -46,7 +48,7 @@ test01() regex re("()*"); cmatch m; const char s[] = ""; - VERIFY( regex_match(s, m, re) ); + VERIFY( regex_match_debug(s, m, re) ); } } diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/hex.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/hex.cc index a73b742a5e4..b1030615ec3 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/hex.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/hex.cc @@ -25,7 +25,9 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> +using namespace __gnu_test; using namespace std; void @@ -33,7 +35,7 @@ test01() { bool test __attribute__((unused)) = true; - VERIFY(regex_match(":", regex("\\x3a"))); + VERIFY(regex_match_debug(":", regex("\\x3a"))); try { regex("\\u400x"); diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/quoted_char.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/quoted_char.cc index b54f5619a24..118c4722677 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/quoted_char.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/char/quoted_char.cc @@ -25,7 +25,9 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> +using namespace __gnu_test; using namespace std; void @@ -33,15 +35,15 @@ test01() { bool test __attribute__((unused)) = true; - VERIFY(regex_match("01", regex("\\d*"))); - VERIFY(regex_match("asdfjkl", regex("\\D*"))); - VERIFY(!regex_match("asdfjkl0", regex("\\D*"))); - VERIFY(regex_match("\r\t\v\f ", regex("\\s*"))); - VERIFY(regex_match("asdfjkl", regex("\\S*"))); - VERIFY(!regex_match("asdfjkl\r", regex("\\S*"))); - VERIFY(regex_match("_az", regex("\\w*"))); - VERIFY(regex_match("!@#$%", regex("\\W*"))); - VERIFY(!regex_match("_01234", regex("\\W*"))); + VERIFY(regex_match_debug("01", regex("\\d*"))); + VERIFY(regex_match_debug("asdfjkl", regex("\\D*"))); + VERIFY(!regex_match_debug("asdfjkl0", regex("\\D*"))); + VERIFY(regex_match_debug("\r\t\v\f ", regex("\\s*"))); + VERIFY(regex_match_debug("asdfjkl", regex("\\S*"))); + VERIFY(!regex_match_debug("asdfjkl\r", regex("\\S*"))); + VERIFY(regex_match_debug("_az", regex("\\w*"))); + VERIFY(regex_match_debug("!@#$%", regex("\\W*"))); + VERIFY(!regex_match_debug("_01234", regex("\\W*"))); } int diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/wchar_t/anymatcher.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/wchar_t/anymatcher.cc index c574908d6a9..323a2ff4ed6 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/wchar_t/anymatcher.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/wchar_t/anymatcher.cc @@ -25,7 +25,9 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> +using namespace __gnu_test; using namespace std; void @@ -37,7 +39,7 @@ test01() {\ wregex re(res);\ wstring st(s);\ - VERIFY(!regex_match(st, re));\ + VERIFY(!regex_match_debug(st, re));\ } TESTL(L".", L"\u2028"); TESTL(L".", L"\u2029"); diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/wchar_t/hex.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/wchar_t/hex.cc index f9561be70e2..876a7df1e2e 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/wchar_t/hex.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/ecma/wchar_t/hex.cc @@ -25,7 +25,9 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> +using namespace __gnu_test; using namespace std; void @@ -33,7 +35,7 @@ test01() { bool test __attribute__((unused)) = true; - VERIFY(regex_match(L"\u1234", wregex(L"\\u1234"))); + VERIFY(regex_match_debug(L"\u1234", wregex(L"\\u1234"))); } int diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/cstring_bracket_01.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/cstring_bracket_01.cc index 5d8378556c6..c5f066bec81 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/cstring_bracket_01.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/cstring_bracket_01.cc @@ -25,6 +25,10 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> + +using namespace __gnu_test; +using namespace std; void test01() @@ -33,33 +37,33 @@ test01() { std::regex re("pre/[za-x]", std::regex::extended); - VERIFY( std::regex_match("pre/z", re) ); - VERIFY( std::regex_match("pre/a", re) ); - VERIFY( !std::regex_match("pre/y", re) ); + VERIFY( regex_match_debug("pre/z", re) ); + VERIFY( regex_match_debug("pre/a", re) ); + VERIFY( !regex_match_debug("pre/y", re) ); } { std::regex re("pre/[[:uPPer:]]", std::regex::extended); - VERIFY( std::regex_match("pre/Z", re) ); - VERIFY( !std::regex_match("pre/_", re) ); - VERIFY( !std::regex_match("pre/a", re) ); - VERIFY( !std::regex_match("pre/0", re) ); + VERIFY( regex_match_debug("pre/Z", re) ); + VERIFY( !regex_match_debug("pre/_", re) ); + VERIFY( !regex_match_debug("pre/a", re) ); + VERIFY( !regex_match_debug("pre/0", re) ); } { std::regex re("pre/[[:lOWer:]]", std::regex::extended | std::regex::icase); - VERIFY( std::regex_match("pre/Z", re) ); - VERIFY( std::regex_match("pre/a", re) ); + VERIFY( regex_match_debug("pre/Z", re) ); + VERIFY( regex_match_debug("pre/a", re) ); } { std::regex re("pre/[[:w:][.tilde.]]", std::regex::extended); - VERIFY( std::regex_match("pre/~", re) ); - VERIFY( std::regex_match("pre/_", re) ); - VERIFY( std::regex_match("pre/a", re) ); - VERIFY( std::regex_match("pre/0", re) ); + VERIFY( regex_match_debug("pre/~", re) ); + VERIFY( regex_match_debug("pre/_", re) ); + VERIFY( regex_match_debug("pre/a", re) ); + VERIFY( regex_match_debug("pre/0", re) ); } { std::regex re("pre/[[=a=]]", std::regex::extended); - VERIFY( std::regex_match("pre/a", re) ); - VERIFY( std::regex_match("pre/A", re) ); + VERIFY( regex_match_debug("pre/a", re) ); + VERIFY( regex_match_debug("pre/A", re) ); } } diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/cstring_plus.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/cstring_plus.cc index 375f34b8064..32bc24f9982 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/cstring_plus.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/cstring_plus.cc @@ -25,6 +25,10 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> + +using namespace __gnu_test; +using namespace std; void test01() @@ -35,7 +39,7 @@ test01() const char target[] = "aa"; std::cmatch m; - VERIFY( std::regex_match(target, m, re) ); + VERIFY( regex_match_debug(target, m, re) ); VERIFY( re.mark_count() == 1 ); VERIFY( m.size() == re.mark_count()+1 ); @@ -53,9 +57,9 @@ test01() VERIFY( m[1].second == target+sizeof(target)-1 ); VERIFY( m[1].matched == true ); - VERIFY(!std::regex_match("", std::regex("a+", std::regex::extended))); - VERIFY(std::regex_match("a", std::regex("a+", std::regex::extended))); - VERIFY(std::regex_match("aa", std::regex("a+", std::regex::extended))); + VERIFY(!regex_match_debug("", std::regex("a+", std::regex::extended))); + VERIFY(regex_match_debug("a", std::regex("a+", std::regex::extended))); + VERIFY(regex_match_debug("aa", std::regex("a+", std::regex::extended))); } diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/cstring_questionmark.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/cstring_questionmark.cc index 79b52a88c4f..90e9eafae60 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/cstring_questionmark.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/cstring_questionmark.cc @@ -25,6 +25,10 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> + +using namespace __gnu_test; +using namespace std; void test01() @@ -35,7 +39,7 @@ test01() char target[] = "a"; std::cmatch m; - VERIFY( std::regex_match(target, m, re) ); + VERIFY( regex_match_debug(target, m, re) ); VERIFY( re.mark_count() == 1 ); VERIFY( m.size() == re.mark_count()+1 ); @@ -53,9 +57,9 @@ test01() VERIFY( m[1].second == target+sizeof(target)-1 ); VERIFY( m[1].matched == true ); - VERIFY(std::regex_match("", std::regex("a?", std::regex::extended))); - VERIFY(std::regex_match("a", std::regex("a?", std::regex::extended))); - VERIFY(!std::regex_match("aa", std::regex("a?", std::regex::extended))); + VERIFY(regex_match_debug("", std::regex("a?", std::regex::extended))); + VERIFY(regex_match_debug("a", std::regex("a?", std::regex::extended))); + VERIFY(!regex_match_debug("aa", std::regex("a?", std::regex::extended))); } diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/cstring_range.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/cstring_range.cc index 62f825a0fb9..f9f7b6af1fd 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/cstring_range.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/cstring_range.cc @@ -25,7 +25,9 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> +using namespace __gnu_test; using namespace std; void @@ -35,29 +37,29 @@ test01() regex re; re.assign("(ab){3}", std::regex::extended); - VERIFY(!regex_match("abab", re)); - VERIFY(regex_match("ababab", re)); - VERIFY(!regex_match("abababab", re)); + VERIFY(!regex_match_debug("abab", re)); + VERIFY(regex_match_debug("ababab", re)); + VERIFY(!regex_match_debug("abababab", re)); re.assign("(ab){3,}", std::regex::extended); - VERIFY(!regex_match("abab", re)); - VERIFY(regex_match("ababab", re)); - VERIFY(regex_match("abababab", re)); - VERIFY(regex_match("ababababab", re)); + VERIFY(!regex_match_debug("abab", re)); + VERIFY(regex_match_debug("ababab", re)); + VERIFY(regex_match_debug("abababab", re)); + VERIFY(regex_match_debug("ababababab", re)); re.assign("(ab){0,3}", std::regex::extended); - VERIFY(regex_match("", re)); - VERIFY(regex_match("ab", re)); - VERIFY(regex_match("abab", re)); - VERIFY(regex_match("ababab", re)); - VERIFY(!regex_match("abababab", re)); + VERIFY(regex_match_debug("", re)); + VERIFY(regex_match_debug("ab", re)); + VERIFY(regex_match_debug("abab", re)); + VERIFY(regex_match_debug("ababab", re)); + VERIFY(!regex_match_debug("abababab", re)); re.assign("(a|b){0,2}", std::regex::extended); - VERIFY(regex_match("", re)); - VERIFY(regex_match("a", re)); - VERIFY(regex_match("b", re)); - VERIFY(regex_match("aa", re)); - VERIFY(regex_match("ab", re)); - VERIFY(regex_match("ba", re)); - VERIFY(regex_match("bb", re)); - VERIFY(!regex_match("aaa", re)); + VERIFY(regex_match_debug("", re)); + VERIFY(regex_match_debug("a", re)); + VERIFY(regex_match_debug("b", re)); + VERIFY(regex_match_debug("aa", re)); + VERIFY(regex_match_debug("ab", re)); + VERIFY(regex_match_debug("ba", re)); + VERIFY(regex_match_debug("bb", re)); + VERIFY(!regex_match_debug("aaa", re)); } int diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/string_any.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/string_any.cc index 57628f13215..cd870396781 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/string_any.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/string_any.cc @@ -25,6 +25,10 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> + +using namespace __gnu_test; +using namespace std; void test01() @@ -35,7 +39,7 @@ test01() std::string target("aaba"); std::smatch m; - VERIFY( std::regex_match(target, m, re) ); + VERIFY( regex_match_debug(target, m, re) ); VERIFY( m.size() == re.mark_count()+1 ); VERIFY( m.empty() == false ); diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/string_dispatch_01.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/string_dispatch_01.cc index 4634c7d1d35..50141f0037d 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/string_dispatch_01.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/string_dispatch_01.cc @@ -38,10 +38,12 @@ template<typename _Bi_iter, typename _Alloc, regex_constants::match_flag_type __flags = regex_constants::match_default) { + using namespace __detail; auto& __res = (vector<sub_match<_Bi_iter>, _Alloc>&)(__m); VERIFY( (dynamic_cast - <__detail::_DFSExecutor<_Bi_iter, _Alloc, _Ch_type, _Rx_traits>*> - (&*__detail::__get_executor(__s, __e, __res, __re, __flags)) + <_DFSExecutor<_Bi_iter, _Alloc, _Ch_type, _Rx_traits>*> + (&*__get_executor<_Bi_iter, _Alloc, _Ch_type, _Rx_traits, + _RegexExecutorPolicy::_S_auto>(__s, __e, __res, __re, __flags)) != nullptr) ); } diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/string_range_00_03.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/string_range_00_03.cc index e10dba81ffa..e483b0abb9d 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/string_range_00_03.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/string_range_00_03.cc @@ -25,6 +25,9 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> + +using namespace __gnu_test; void test01() @@ -35,7 +38,7 @@ test01() std::string target("aa"); std::smatch m; - VERIFY( std::regex_match(target, m, re) ); + VERIFY( regex_match_debug(target, m, re) ); VERIFY( m.size() == re.mark_count()+1 ); VERIFY( m.empty() == false ); diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/string_range_01_03.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/string_range_01_03.cc index e715290c242..3879fc418aa 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/string_range_01_03.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/string_range_01_03.cc @@ -25,6 +25,10 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> + +using namespace __gnu_test; +using namespace std; void test01() @@ -35,7 +39,7 @@ test01() std::string target("aa"); std::smatch m; - VERIFY( std::regex_match(target, m, re) ); + VERIFY( regex_match_debug(target, m, re) ); VERIFY( m.size() == re.mark_count()+1 ); VERIFY( m.empty() == false ); diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/string_range_02_03.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/string_range_02_03.cc index 62793b4a199..c2ebdf8b143 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/string_range_02_03.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/string_range_02_03.cc @@ -25,6 +25,10 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> + +using namespace __gnu_test; +using namespace std; void test01() @@ -35,7 +39,7 @@ test01() std::string target("aa"); std::smatch m; - VERIFY( std::regex_match(target, m, re) ); + VERIFY( regex_match_debug(target, m, re) ); VERIFY( m.size() == re.mark_count()+1 ); VERIFY( m.empty() == false ); diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/wstring_locale.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/wstring_locale.cc index 6ab48ca6baf..ba0ecd5b4c4 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/wstring_locale.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_match/extended/wstring_locale.cc @@ -26,6 +26,10 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> + +using namespace __gnu_test; +using namespace std; void test01() @@ -37,7 +41,7 @@ test01() re2.imbue(std::locale("de_DE.UTF-8")); re2.assign(L"[[:upper:]]*", std::regex::extended); std::wsmatch m2; - VERIFY(std::regex_match(str2, m2, re2)); + VERIFY(regex_match_debug(str2, m2, re2)); } int diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/basic/string_01.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/basic/string_01.cc index ee487f19836..fed8e7dd17f 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/basic/string_01.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/basic/string_01.cc @@ -25,6 +25,10 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> + +using namespace __gnu_test; +using namespace std; void test01() @@ -35,7 +39,7 @@ test01() std::string target("xxasdfyy"); std::smatch m; - VERIFY( std::regex_search(target, m, re) ); + VERIFY( regex_search_debug(target, m, re) ); VERIFY( m.size() == re.mark_count()+1 ); VERIFY( m.empty() == false ); diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/assertion.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/assertion.cc index 3064b3b26e4..f7bce8023d3 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/assertion.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/assertion.cc @@ -25,7 +25,9 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> +using namespace __gnu_test; using namespace std; void @@ -33,21 +35,21 @@ test01() { bool test __attribute__((unused)) = true; - VERIFY(!regex_search("2123456", regex("^1234"))); - VERIFY(regex_search("123456", regex("^1234"))); - VERIFY(regex_search("123456", regex("(5|^)1234"))); - VERIFY(regex_search("5123456", regex("(5|^)1234"))); - VERIFY(!regex_search("1234562", regex("3456$"))); - VERIFY(regex_search("123456", regex("3456$"))); - VERIFY(!regex_search("123456", regex("(?=1234)56"))); - VERIFY(regex_search("123456", regex("(?=1234)123456"))); - VERIFY(regex_search("123456", regex("(?!1234)56"))); - VERIFY(!regex_search("123456", regex("(?!1234)123456"))); + VERIFY(!regex_search_debug("2123456", regex("^1234"))); + VERIFY(regex_search_debug("123456", regex("^1234"))); + VERIFY(regex_search_debug("123456", regex("(5|^)1234"))); + VERIFY(regex_search_debug("5123456", regex("(5|^)1234"))); + VERIFY(!regex_search_debug("1234562", regex("3456$"))); + VERIFY(regex_search_debug("123456", regex("3456$"))); + VERIFY(!regex_search_debug("123456", regex("(?=1234)56"))); + VERIFY(regex_search_debug("123456", regex("(?=1234)123456"))); + VERIFY(regex_search_debug("123456", regex("(?!1234)56"))); + VERIFY(!regex_search_debug("123456", regex("(?!1234)123456"))); - VERIFY(regex_search("a-", regex("a\\b-"))); - VERIFY(!regex_search("ab", regex("a\\bb"))); - VERIFY(!regex_search("a-", regex("a\\B-"))); - VERIFY(regex_search("ab", regex("a\\Bb"))); + VERIFY(regex_search_debug("a-", regex("a\\b-"))); + VERIFY(!regex_search_debug("ab", regex("a\\bb"))); + VERIFY(!regex_search_debug("a-", regex("a\\B-"))); + VERIFY(regex_search_debug("ab", regex("a\\Bb"))); string s("This is a regular expression"); string sol[] = diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/flags.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/flags.cc index 4be406cb072..490ab1c9159 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/flags.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/flags.cc @@ -25,7 +25,9 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> +using namespace __gnu_test; using namespace std; void @@ -35,32 +37,34 @@ test01() cmatch m; regex re("((as)(df))", regex_constants::ECMAScript | regex_constants::nosubs); - VERIFY(regex_search("asdf", m, re)); + VERIFY(regex_search_debug("asdf", m, re)); VERIFY(m.size() == 1); VERIFY(m[0].matched && string(m[0].first, m[0].second) == "asdf"); - VERIFY( regex_search("a", regex("^a"))); - VERIFY(!regex_search("a", regex("^a"), regex_constants::match_not_bol)); - VERIFY( regex_search("a", regex("a$"))); - VERIFY(!regex_search("a", regex("a$"), regex_constants::match_not_eol)); - VERIFY( regex_search("a", regex("\\ba"))); - VERIFY(!regex_search("a", regex("\\ba"), regex_constants::match_not_bow)); - VERIFY( regex_search("a", regex("a\\b"))); - VERIFY(!regex_search("a", regex("a\\b"), regex_constants::match_not_eow)); - VERIFY( regex_search("", regex(""))); - VERIFY(!regex_search("", regex(""), regex_constants::match_not_null)); - VERIFY( regex_search("", regex("^$"))); - VERIFY(!regex_search("", regex("^$"), regex_constants::match_not_null)); - VERIFY( regex_search("aaa", m, regex("a*?"), - regex_constants::match_not_null)); + VERIFY( regex_search_debug("a", regex("^a"))); + VERIFY(!regex_search_debug("a", regex("^a"), regex_constants::match_not_bol)); + VERIFY( regex_search_debug("a", regex("a$"))); + VERIFY(!regex_search_debug("a", regex("a$"), regex_constants::match_not_eol)); + VERIFY( regex_search_debug("a", regex("\\ba"))); + VERIFY(!regex_search_debug("a", regex("\\ba"), + regex_constants::match_not_bow)); + VERIFY( regex_search_debug("a", regex("a\\b"))); + VERIFY(!regex_search_debug("a", regex("a\\b"), + regex_constants::match_not_eow)); + VERIFY( regex_search_debug("", regex(""))); + VERIFY(!regex_search_debug("", regex(""), regex_constants::match_not_null)); + VERIFY( regex_search_debug("", regex("^$"))); + VERIFY(!regex_search_debug("", regex("^$"), regex_constants::match_not_null)); + VERIFY( regex_search_debug("aaa", m, regex("a*?"), + regex_constants::match_not_null)); VERIFY(m[0].matched && string(m[0].first, m[0].second) == "a"); - VERIFY( regex_search("asdf", regex("sdf"))); - VERIFY(!regex_search("asdf", regex("sdf"), - regex_constants::match_continuous)); - VERIFY( regex_search(" a"+1, regex("\\ba"), - regex_constants::match_prev_avail)); - VERIFY( regex_search("ba"+1, regex("\\Ba"), - regex_constants::match_prev_avail)); + VERIFY( regex_search_debug("asdf", regex("sdf"))); + VERIFY(!regex_search_debug("asdf", regex("sdf"), + regex_constants::match_continuous)); + VERIFY( regex_search_debug(" a"+1, regex("\\ba"), + regex_constants::match_prev_avail)); + VERIFY( regex_search_debug("ba"+1, regex("\\Ba"), + regex_constants::match_prev_avail)); } int diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/greedy.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/greedy.cc index ad37ec8649a..107ced0edc8 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/greedy.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/greedy.cc @@ -25,7 +25,9 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> +using namespace __gnu_test; using namespace std; void @@ -35,30 +37,30 @@ test01() cmatch m; #define TEST(i, s) VERIFY(m[i].matched && string(m[i].first, m[i].second) == s) - VERIFY(regex_search("aaaa", m, regex("a*"))); + VERIFY(regex_search_debug("aaaa", m, regex("a*"))); TEST(0, "aaaa"); - VERIFY(regex_search("aaaa", m, regex("a*?"))); + VERIFY(regex_search_debug("aaaa", m, regex("a*?"))); TEST(0, ""); - VERIFY(regex_search("aaaa", m, regex("a+"))); + VERIFY(regex_search_debug("aaaa", m, regex("a+"))); TEST(0, "aaaa"); - VERIFY(regex_search("aaaa", m, regex("a+?"))); + VERIFY(regex_search_debug("aaaa", m, regex("a+?"))); TEST(0, "a"); - VERIFY(regex_search("a", m, regex("a?"))); + VERIFY(regex_search_debug("a", m, regex("a?"))); TEST(0, "a"); - VERIFY(regex_search("a", m, regex("a??"))); + VERIFY(regex_search_debug("a", m, regex("a??"))); TEST(0, ""); - VERIFY(regex_search("", m, regex("a??"))); + VERIFY(regex_search_debug("", m, regex("a??"))); TEST(0, ""); - VERIFY(regex_search("aaaa", m, regex("(a+)(a+)"))); + VERIFY(regex_search_debug("aaaa", m, regex("(a+)(a+)"))); TEST(1, "aaa"); TEST(2, "a"); - VERIFY(regex_search("aaaa", m, regex("(a+?)(a+)"))); + VERIFY(regex_search_debug("aaaa", m, regex("(a+?)(a+)"))); TEST(1, "a"); TEST(2, "aaa"); - VERIFY(regex_search("aaaa", m, regex("(a+?)(a+)"))); + VERIFY(regex_search_debug("aaaa", m, regex("(a+?)(a+)"))); TEST(1, "a"); TEST(2, "aaa"); - VERIFY(regex_search("aaaa", m, regex("(a+?)(a+?)"))); + VERIFY(regex_search_debug("aaaa", m, regex("(a+?)(a+?)"))); TEST(1, "a"); TEST(2, "a"); } diff --git a/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/string_01.cc b/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/string_01.cc index ec25875fdee..c07e7efa7d4 100644 --- a/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/string_01.cc +++ b/libstdc++-v3/testsuite/28_regex/algorithms/regex_search/ecma/string_01.cc @@ -25,13 +25,17 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> + +using namespace __gnu_test; +using namespace std; void test01() { bool test __attribute__((unused)) = true; - VERIFY(std::regex_search("", std::regex(""))); + VERIFY(regex_search_debug("", std::regex(""))); } int diff --git a/libstdc++-v3/testsuite/28_regex/match_results/format.cc b/libstdc++-v3/testsuite/28_regex/match_results/format.cc index be080162143..659ffdcb13b 100644 --- a/libstdc++-v3/testsuite/28_regex/match_results/format.cc +++ b/libstdc++-v3/testsuite/28_regex/match_results/format.cc @@ -25,8 +25,10 @@ #include <regex> #include <testsuite_hooks.h> +#include <testsuite_regex.h> using namespace std; +using namespace __gnu_test; void test01() @@ -34,8 +36,8 @@ test01() bool test __attribute__((unused)) = true; cmatch m; - VERIFY(regex_search("*** this is a string !!!", m, - regex("(\\w+) (\\w+) (\\w+) (\\w+)"))); + VERIFY(regex_search_debug("*** this is a string !!!", m, + regex("(\\w+) (\\w+) (\\w+) (\\w+)"))); VERIFY(m.format("$&|$`|$3|$4|$2|$1|$'$$$") == "this is a string|*** |a|string|is|this| !!!$$"); VERIFY(m.format("&|\\3|\\4|\\2|\\1|\\", diff --git a/libstdc++-v3/testsuite/util/testsuite_regex.h b/libstdc++-v3/testsuite/util/testsuite_regex.h index ebd72a67258..17be78d9c1b 100644 --- a/libstdc++-v3/testsuite/util/testsuite_regex.h +++ b/libstdc++-v3/testsuite/util/testsuite_regex.h @@ -31,9 +31,12 @@ namespace __gnu_test // Test on a compilation of simple expressions, throw regex_error on error. typedef std::regex regex_type; typedef regex_type::flag_type flag_type; + typedef std::regex_constants::match_flag_type match_flag_type; typedef std::regex_constants::error_type error_type; typedef std::size_t size_type; typedef std::string string_type; + using std::basic_regex; + using std::match_results; // Utilities struct regex_expected_fail { }; @@ -126,5 +129,177 @@ namespace __gnu_test } } + // regex_match_debug behaves like regex_match, but will run *two* executors + // (if there's no back-reference) and check if their results agree. If not, + // an exception throws. One can use them just in the way of using regex_match. + template<typename _Bi_iter, typename _Alloc, + typename _Ch_type, typename _Rx_traits> + bool + regex_match_debug(_Bi_iter __s, + _Bi_iter __e, + match_results<_Bi_iter, _Alloc>& __m, + const basic_regex<_Ch_type, _Rx_traits>& __re, + match_flag_type __flags + = std::regex_constants::match_default) + { + using namespace std::__detail; + auto __res1 = __regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits, + _RegexExecutorPolicy::_S_auto, true> + (__s, __e, __m, __re, __flags); + match_results<_Bi_iter, _Alloc> __mm; + auto __res2 = __regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits, + _RegexExecutorPolicy::_S_force_dfs, true> + (__s, __e, __mm, __re, __flags); + if (__res1 == __res2 && __m == __mm) + return __res1; + throw(std::exception()); + } + + // No match_results version + template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits> + inline bool + regex_match_debug(_Bi_iter __first, + _Bi_iter __last, + const basic_regex<_Ch_type, _Rx_traits>& __re, + match_flag_type __flags + = std::regex_constants::match_default) + { + match_results<_Bi_iter> __what; + return regex_match_debug(__first, __last, __what, __re, __flags); + } + + // C-string version + template<typename _Ch_type, typename _Alloc, typename _Rx_traits> + inline bool + regex_match_debug(const _Ch_type* __s, + match_results<const _Ch_type*, _Alloc>& __m, + const basic_regex<_Ch_type, _Rx_traits>& __re, + match_flag_type __f + = std::regex_constants::match_default) + { return regex_match_debug(__s, __s + _Rx_traits::length(__s), + __m, __re, __f); } + + // C-string version without match_results + template<typename _Ch_type, class _Rx_traits> + inline bool + regex_match_debug(const _Ch_type* __s, + const basic_regex<_Ch_type, _Rx_traits>& __re, + match_flag_type __f + = std::regex_constants::match_default) + { return regex_match_debug(__s, __s + _Rx_traits::length(__s), + __re, __f); } + + // std::basic_string version + template<typename _Ch_traits, typename _Ch_alloc, + typename _Alloc, typename _Ch_type, typename _Rx_traits> + inline bool + regex_match_debug(const std::basic_string<_Ch_type, _Ch_traits, + _Ch_alloc>& __s, + match_results<typename std::basic_string<_Ch_type, + _Ch_traits, _Ch_alloc>::const_iterator, + _Alloc>& __m, + const basic_regex<_Ch_type, _Rx_traits>& __re, + match_flag_type __flags + = std::regex_constants::match_default) + { return regex_match_debug(__s.begin(), __s.end(), + __m, __re, __flags); } + + // std::basic_string version without match_results + template<typename _Ch_traits, typename _Str_allocator, + typename _Ch_type, typename _Rx_traits> + inline bool + regex_match_debug(const std::basic_string<_Ch_type, _Ch_traits, + _Str_allocator>& __s, + const basic_regex<_Ch_type, _Rx_traits>& __re, + match_flag_type __flags + = std::regex_constants::match_default) + { return regex_match_debug(__s.begin(), __s.end(), __re, __flags); } + + // regex_match_debug behaves like regex_match, but will run *two* executors + // (if there's no back-reference) and check if their results agree. If not, + // an exception throws. One can use them just in the way of using regex_match. + template<typename _Bi_iter, typename _Alloc, + typename _Ch_type, typename _Rx_traits> + bool + regex_search_debug(_Bi_iter __s, + _Bi_iter __e, + match_results<_Bi_iter, _Alloc>& __m, + const basic_regex<_Ch_type, _Rx_traits>& __re, + match_flag_type __flags + = std::regex_constants::match_default) + { + using namespace std::__detail; + auto __res1 = __regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits, + _RegexExecutorPolicy::_S_auto, false> + (__s, __e, __m, __re, __flags); + match_results<_Bi_iter, _Alloc> __mm; + auto __res2 = __regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits, + _RegexExecutorPolicy::_S_force_dfs, false> + (__s, __e, __mm, __re, __flags); + if (__res1 == __res2 && __m == __mm) + return __res1; + throw(std::exception()); // Let test fail. Give it a name. + } + + // No match_results version + template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits> + inline bool + regex_search_debug(_Bi_iter __first, + _Bi_iter __last, + const basic_regex<_Ch_type, _Rx_traits>& __re, + match_flag_type __flags + = std::regex_constants::match_default) + { + match_results<_Bi_iter> __what; + return regex_search_debug(__first, __last, __what, __re, __flags); + } + + // C-string version + template<typename _Ch_type, class _Alloc, class _Rx_traits> + inline bool + regex_search_debug(const _Ch_type* __s, + match_results<const _Ch_type*, _Alloc>& __m, + const basic_regex<_Ch_type, _Rx_traits>& __e, + match_flag_type __f + = std::regex_constants::match_default) + { return regex_search_debug(__s, __s + _Rx_traits::length(__s), + __m, __e, __f); } + + // C-string version without match_results + template<typename _Ch_type, typename _Rx_traits> + inline bool + regex_search_debug(const _Ch_type* __s, + const basic_regex<_Ch_type, _Rx_traits>& __e, + match_flag_type __f + = std::regex_constants::match_default) + { return regex_search_debug(__s, __s + _Rx_traits::length(__s), + __e, __f); } + + // std::basic_string version + template<typename _Ch_traits, typename _Ch_alloc, + typename _Alloc, typename _Ch_type, + typename _Rx_traits> + inline bool + regex_search_debug(const std::basic_string<_Ch_type, _Ch_traits, + _Ch_alloc>& __s, + match_results<typename std::basic_string<_Ch_type, + _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>& + __m, + const basic_regex<_Ch_type, _Rx_traits>& __e, + match_flag_type __f + = std::regex_constants::match_default) + { return regex_search_debug(__s.begin(), __s.end(), __m, __e, __f); } + + // std::basic_string version without match_results + template<typename _Ch_traits, typename _String_allocator, + typename _Ch_type, typename _Rx_traits> + inline bool + regex_search_debug(const std::basic_string<_Ch_type, _Ch_traits, + _String_allocator>& __s, + const basic_regex<_Ch_type, _Rx_traits>& __e, + match_flag_type __f + = std::regex_constants::match_default) + { return regex_search_debug(__s.begin(), __s.end(), __e, __f); } + } // namespace __gnu_test #endif |