Commit ab1c993b by Tim Shen Committed by Tim Shen

regex.h (regex_token_iterator<>::regex_token_iterator): Fix initialization…

regex.h (regex_token_iterator<>::regex_token_iterator): Fix initialization orders in initialization list and add explicit braces for...

2013-10-17  Tim Shen  <timshen91@gmail.com>

	* include/bits/regex.h (regex_token_iterator<>::regex_token_iterator):
	Fix initialization orders in initialization list and add explicit braces
	for potentially ambiguous(actually not) `else` branch to eliminate
	warnings.
	* include/bits/regex_automaton.h (_NFA<>::_NFA): Likewise.
	* include/bits/regex_compiler.h (_CharMatcher<>::_CharMatcher,
	_BracketMatcher<>::_BracketMatcher): Likewise.
	* include/bits/regex_compiler.tcc (_Compiler<>::_Compiler,
	_Compiler<>::_M_atom): Likewise.
	* include/bits/regex_executor.h (_Executor<>::_Executor): Likewise.
	* include/bits/regex_executor.tcc (_DFSExecutor<>::_M_dfs,
	_Executor<>::_M_word_boundry): Likewise.
	* include/bits/regex_scanner.tcc (_Scanner<>::_Scanner,
	_Scanner<>::_M_eat_class): Likewise.
	* include/bits/regex.tcc (__regex_algo_impl<>,
	regex_iterator<>::operator++): Likewise, and remove unused typedef.

From-SVN: r203798
parent 358e1993
2013-10-17 Tim Shen <timshen91@gmail.com>
* include/bits/regex.h (regex_token_iterator<>::regex_token_iterator):
Fix initialization orders in initialization list and add explicit braces
for potentially ambiguous(actually not) `else` branch to eliminate
warnings.
* include/bits/regex_automaton.h (_NFA<>::_NFA): Likewise.
* include/bits/regex_compiler.h (_CharMatcher<>::_CharMatcher,
_BracketMatcher<>::_BracketMatcher): Likewise.
* include/bits/regex_compiler.tcc (_Compiler<>::_Compiler,
_Compiler<>::_M_atom): Likewise.
* include/bits/regex_executor.h (_Executor<>::_Executor): Likewise.
* include/bits/regex_executor.tcc (_DFSExecutor<>::_M_dfs,
_Executor<>::_M_word_boundry): Likewise.
* include/bits/regex_scanner.tcc (_Scanner<>::_Scanner,
_Scanner<>::_M_eat_class): Likewise.
* include/bits/regex.tcc (__regex_algo_impl<>,
regex_iterator<>::operator++): Likewise, and remove unused typedef.
2013-10-16 Tim Shen <timshen91@gmail.com> 2013-10-16 Tim Shen <timshen91@gmail.com>
* include/bits/regex.h (regex_token_iterator<>::regex_token_iterator): * include/bits/regex.h (regex_token_iterator<>::regex_token_iterator):
......
...@@ -2514,7 +2514,7 @@ _GLIBCXX_END_NAMESPACE_VERSION ...@@ -2514,7 +2514,7 @@ _GLIBCXX_END_NAMESPACE_VERSION
* iterator of the same type. * iterator of the same type.
*/ */
regex_token_iterator() regex_token_iterator()
: _M_position(), _M_result(nullptr), _M_suffix(), _M_n(0), _M_subs(), : _M_position(), _M_subs(), _M_suffix(), _M_n(0), _M_result(nullptr),
_M_has_m1(false) _M_has_m1(false)
{ } { }
...@@ -2601,7 +2601,7 @@ _GLIBCXX_END_NAMESPACE_VERSION ...@@ -2601,7 +2601,7 @@ _GLIBCXX_END_NAMESPACE_VERSION
*/ */
regex_token_iterator(const regex_token_iterator& __rhs) regex_token_iterator(const regex_token_iterator& __rhs)
: _M_position(__rhs._M_position), _M_subs(__rhs._M_subs), : _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_suffix(__rhs._M_suffix), _M_n(__rhs._M_n), _M_result(__rhs._M_result),
_M_has_m1(__rhs._M_has_m1) _M_has_m1(__rhs._M_has_m1)
{ {
if (__rhs._M_result == &__rhs._M_suffix) if (__rhs._M_result == &__rhs._M_suffix)
...@@ -2679,10 +2679,10 @@ _GLIBCXX_END_NAMESPACE_VERSION ...@@ -2679,10 +2679,10 @@ _GLIBCXX_END_NAMESPACE_VERSION
{ return _M_result == nullptr; } { return _M_result == nullptr; }
_Position _M_position; _Position _M_position;
const value_type* _M_result; std::vector<int> _M_subs;
value_type _M_suffix; value_type _M_suffix;
std::size_t _M_n; std::size_t _M_n;
std::vector<int> _M_subs; const value_type* _M_result;
// Show whether _M_subs contains -1 // Show whether _M_subs contains -1
bool _M_has_m1; bool _M_has_m1;
......
...@@ -61,13 +61,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -61,13 +61,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
for (auto& __it : __res) for (auto& __it : __res)
__it.matched = false; __it.matched = false;
typedef std::unique_ptr<_Executor<_BiIter, _Alloc, _CharT, _TraitsT>> auto __executor = __get_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); __policy>(__s, __e, __res, __re, __flags);
bool __ret; bool __ret;
...@@ -540,6 +534,7 @@ _GLIBCXX_END_NAMESPACE_VERSION ...@@ -540,6 +534,7 @@ _GLIBCXX_END_NAMESPACE_VERSION
auto __start = _M_match[0].second; auto __start = _M_match[0].second;
auto __prefix_first = _M_match[0].second; auto __prefix_first = _M_match[0].second;
if (_M_match[0].first == _M_match[0].second) if (_M_match[0].first == _M_match[0].second)
{
if (__start == _M_end) if (__start == _M_end)
{ {
_M_match = value_type(); _M_match = value_type();
...@@ -547,7 +542,8 @@ _GLIBCXX_END_NAMESPACE_VERSION ...@@ -547,7 +542,8 @@ _GLIBCXX_END_NAMESPACE_VERSION
} }
else else
{ {
if (regex_search(__start, _M_end, _M_match, *_M_pregex, _M_flags if (regex_search(__start, _M_end, _M_match, *_M_pregex,
_M_flags
| regex_constants::match_not_null | regex_constants::match_not_null
| regex_constants::match_continuous)) | regex_constants::match_continuous))
{ {
...@@ -560,6 +556,7 @@ _GLIBCXX_END_NAMESPACE_VERSION ...@@ -560,6 +556,7 @@ _GLIBCXX_END_NAMESPACE_VERSION
else else
++__start; ++__start;
} }
}
_M_flags |= regex_constants::match_prev_avail; _M_flags |= regex_constants::match_prev_avail;
if (regex_search(__start, _M_end, _M_match, *_M_pregex, _M_flags)) if (regex_search(__start, _M_end, _M_match, *_M_pregex, _M_flags))
{ {
......
...@@ -138,7 +138,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -138,7 +138,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_NFA(_FlagT __f) _NFA(_FlagT __f)
: _M_flags(__f), _M_start_state(0), _M_subexpr_count(0), : _M_flags(__f), _M_start_state(0), _M_subexpr_count(0),
_M_has_backref(false), _M_quant_count(0) _M_quant_count(0), _M_has_backref(false)
{ } { }
_FlagT _FlagT
......
...@@ -156,7 +156,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -156,7 +156,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
explicit explicit
_CharMatcher(_CharT __ch, const _TraitsT& __traits, _FlagT __flags) _CharMatcher(_CharT __ch, const _TraitsT& __traits, _FlagT __flags)
: _M_ch(_M_translate(__ch)), _M_traits(__traits), _M_flags(__flags) : _M_traits(__traits), _M_flags(__flags), _M_ch(_M_translate(__ch))
{ } { }
bool bool
...@@ -189,8 +189,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -189,8 +189,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_BracketMatcher(bool __is_non_matching, _BracketMatcher(bool __is_non_matching,
const _TraitsT& __traits, const _TraitsT& __traits,
_FlagT __flags) _FlagT __flags)
: _M_is_non_matching(__is_non_matching), _M_traits(__traits), : _M_traits(__traits), _M_class_set(0), _M_flags(__flags),
_M_flags(__flags), _M_class_set(0) _M_is_non_matching(__is_non_matching)
{ } { }
bool bool
......
...@@ -73,8 +73,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -73,8 +73,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
? __flags ? __flags
: __flags | regex_constants::ECMAScript), : __flags | regex_constants::ECMAScript),
_M_traits(__traits), _M_traits(__traits),
_M_scanner(__b, __e, _M_flags, _M_traits.getloc()),
_M_ctype(std::use_facet<std::ctype<_CharT>>(_M_traits.getloc())), _M_ctype(std::use_facet<std::ctype<_CharT>>(_M_traits.getloc())),
_M_scanner(__b, __e, _M_flags, _M_traits.getloc()),
_M_nfa(_M_flags) _M_nfa(_M_flags)
{ {
_StateSeqT __r(_M_nfa, _M_nfa._M_start()); _StateSeqT __r(_M_nfa, _M_nfa._M_start());
...@@ -318,7 +318,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -318,7 +318,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
} }
else if (_M_match_token(_ScannerT::_S_token_subexpr_begin)) else if (_M_match_token(_ScannerT::_S_token_subexpr_begin))
{ {
auto __mark = _M_nfa._M_sub_count();
_StateSeqT __r(_M_nfa, _M_nfa._M_insert_subexpr_begin()); _StateSeqT __r(_M_nfa, _M_nfa._M_insert_subexpr_begin());
this->_M_disjunction(); this->_M_disjunction();
if (!_M_match_token(_ScannerT::_S_token_subexpr_end)) if (!_M_match_token(_ScannerT::_S_token_subexpr_end))
......
...@@ -74,8 +74,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -74,8 +74,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_FlagT __flags) _FlagT __flags)
: _M_begin(__begin), : _M_begin(__begin),
_M_end(__end), _M_end(__end),
_M_results(__results),
_M_re(__re), _M_re(__re),
_M_results(__results),
_M_flags((__flags & regex_constants::match_prev_avail) _M_flags((__flags & regex_constants::match_prev_avail)
? (__flags ? (__flags
& ~regex_constants::match_not_bol & ~regex_constants::match_not_bol
......
...@@ -145,6 +145,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -145,6 +145,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
if (this->_M_re._M_traits.transform(__submatch.first, if (this->_M_re._M_traits.transform(__submatch.first,
__submatch.second) __submatch.second)
== this->_M_re._M_traits.transform(__current, __last)) == this->_M_re._M_traits.transform(__current, __last))
{
if (__last != __current) if (__last != __current)
{ {
auto __backup = __current; auto __backup = __current;
...@@ -155,6 +156,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -155,6 +156,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
else else
__ret = _M_dfs(__state._M_next); __ret = _M_dfs(__state._M_next);
} }
}
break; break;
case _S_opcode_accept: case _S_opcode_accept:
if (this->_M_match_mode) if (this->_M_match_mode)
...@@ -353,6 +355,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -353,6 +355,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
auto __pre = _M_current; auto __pre = _M_current;
--__pre; --__pre;
if (!(_M_at_begin() && _M_at_end())) if (!(_M_at_begin() && _M_at_end()))
{
if (_M_at_begin()) if (_M_at_begin())
__ans = _M_is_word(*_M_current) __ans = _M_is_word(*_M_current)
&& !(_M_flags & regex_constants::match_not_bow); && !(_M_flags & regex_constants::match_not_bow);
...@@ -362,6 +365,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -362,6 +365,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
else else
__ans = _M_is_word(*_M_current) __ans = _M_is_word(*_M_current)
!= _M_is_word(*__pre); != _M_is_word(*__pre);
}
return __ans; return __ans;
} }
......
...@@ -56,8 +56,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -56,8 +56,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_Scanner<_FwdIter>:: _Scanner<_FwdIter>::
_Scanner(_FwdIter __begin, _FwdIter __end, _Scanner(_FwdIter __begin, _FwdIter __end,
_FlagT __flags, std::locale __loc) _FlagT __flags, std::locale __loc)
: _M_current(__begin) , _M_end(__end) , _M_flags(__flags), : _M_state(_S_state_normal), _M_current(__begin), _M_end(__end),
_M_ctype(std::use_facet<_CtypeT>(__loc)), _M_state(_S_state_normal), _M_flags(__flags),
_M_ctype(std::use_facet<_CtypeT>(__loc)),
_M_at_bracket_start(false), _M_at_bracket_start(false),
_M_token_map _M_token_map
{ {
...@@ -94,9 +95,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -94,9 +95,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{'t', '\t'}, {'t', '\t'},
{'v', '\v'}, {'v', '\v'},
}, },
_M_escape_map(_M_is_ecma()
? _M_ecma_escape_map
: _M_awk_escape_map),
_M_ecma_spec_char _M_ecma_spec_char
{ {
'^', '^',
...@@ -138,14 +136,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -138,14 +136,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
'^', '^',
'$', '$',
}, },
_M_eat_escape(_M_is_ecma() _M_escape_map(_M_is_ecma()
? &_Scanner::_M_eat_escape_ecma ? _M_ecma_escape_map
: &_Scanner::_M_eat_escape_posix), : _M_awk_escape_map),
_M_spec_char(_M_is_ecma() _M_spec_char(_M_is_ecma()
? _M_ecma_spec_char ? _M_ecma_spec_char
: _M_is_basic() : _M_is_basic()
? _M_basic_spec_char ? _M_basic_spec_char
: _M_extended_spec_char) : _M_extended_spec_char),
_M_eat_escape(_M_is_ecma()
? &_Scanner::_M_eat_escape_ecma
: &_Scanner::_M_eat_escape_posix)
{ _M_advance(); } { _M_advance(); }
template<typename _FwdIter> template<typename _FwdIter>
...@@ -243,9 +244,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -243,9 +244,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_M_state = _S_state_in_brace; _M_state = _S_state_in_brace;
_M_token = _S_token_interval_begin; _M_token = _S_token_interval_begin;
} }
else if (_M_spec_char.count(__c) else if ((_M_spec_char.count(__c)
&& __c != ']' && __c != ']'
&& __c != '}' && __c != '}')
|| (_M_is_grep() && __c == '\n')) || (_M_is_grep() && __c == '\n'))
_M_token = _M_token_map.at(__c); _M_token = _M_token_map.at(__c);
else else
...@@ -515,11 +516,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -515,11 +516,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
|| *_M_current++ != __ch || *_M_current++ != __ch
|| _M_current == _M_end // skip __ch || _M_current == _M_end // skip __ch
|| *_M_current++ != ']') // skip ']' || *_M_current++ != ']') // skip ']'
{
if (__ch == ':') if (__ch == ':')
__throw_regex_error(regex_constants::error_ctype); __throw_regex_error(regex_constants::error_ctype);
else else
__throw_regex_error(regex_constants::error_collate); __throw_regex_error(regex_constants::error_collate);
} }
}
#ifdef _GLIBCXX_DEBUG #ifdef _GLIBCXX_DEBUG
template<typename _FwdIter> template<typename _FwdIter>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment