aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/include/bits/regex_automaton.h
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2013-11-08 22:46:41 +0000
committerJoseph Myers <joseph@codesourcery.com>2013-11-08 22:46:41 +0000
commitfb3f3b1678683afa84b77049e373b942476f4a26 (patch)
tree81d81cfbf7328090ebee52ccef1d6ae41c6b6d62 /libstdc++-v3/include/bits/regex_automaton.h
parent168756e6efd81fafc03b809b2291c2cbbb685dff (diff)
parentec1c555d37fcda7b7bcd00051fc6c0bdb84ad1b2 (diff)
Merge from trunk.C11-atomic
git-svn-id: https://gcc.gnu.org/svn/gcc/branches/C11-atomic@204607 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/include/bits/regex_automaton.h')
-rw-r--r--libstdc++-v3/include/bits/regex_automaton.h185
1 files changed, 105 insertions, 80 deletions
diff --git a/libstdc++-v3/include/bits/regex_automaton.h b/libstdc++-v3/include/bits/regex_automaton.h
index e6305123703..1be51221ecd 100644
--- a/libstdc++-v3/include/bits/regex_automaton.h
+++ b/libstdc++-v3/include/bits/regex_automaton.h
@@ -65,81 +65,114 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_S_opcode_accept,
};
- template<typename _CharT, typename _TraitsT>
- class _State
+ struct _State_base
+ {
+ _Opcode _M_opcode; // type of outgoing transition
+ _StateIdT _M_next; // outgoing transition
+ union // Since they are mutually exclusive.
{
- public:
- typedef _Matcher<_CharT> _MatcherT;
-
- _Opcode _M_opcode; // type of outgoing transition
- _StateIdT _M_next; // outgoing transition
- union // Since they are mutually exclusive.
+ size_t _M_subexpr; // for _S_opcode_subexpr_*
+ size_t _M_backref_index; // for _S_opcode_backref
+ struct
{
- size_t _M_subexpr; // for _S_opcode_subexpr_*
- size_t _M_backref_index; // for _S_opcode_backref
- struct
- {
- // for _S_opcode_alternative.
- _StateIdT _M_quant_index;
- // for _S_opcode_alternative or _S_opcode_subexpr_lookahead
- _StateIdT _M_alt;
- // for _S_opcode_word_boundary or _S_opcode_subexpr_lookahead or
- // quantifiers(ungreedy if set true)
- bool _M_neg;
- };
+ // for _S_opcode_alternative.
+ _StateIdT _M_quant_index;
+ // for _S_opcode_alternative or _S_opcode_subexpr_lookahead
+ _StateIdT _M_alt;
+ // for _S_opcode_word_boundary or _S_opcode_subexpr_lookahead or
+ // quantifiers (ungreedy if set true)
+ bool _M_neg;
};
- _MatcherT _M_matches; // for _S_opcode_match
+ };
- explicit _State(_Opcode __opcode)
- : _M_opcode(__opcode), _M_next(_S_invalid_state_id)
- { }
+ explicit _State_base(_Opcode __opcode)
+ : _M_opcode(__opcode), _M_next(_S_invalid_state_id)
+ { }
+ protected:
+ ~_State_base() = default;
+
+ public:
#ifdef _GLIBCXX_DEBUG
- std::ostream&
- _M_print(std::ostream& ostr) const;
+ std::ostream&
+ _M_print(std::ostream& ostr) const;
- // Prints graphviz dot commands for state.
- std::ostream&
- _M_dot(std::ostream& __ostr, _StateIdT __id) const;
+ // Prints graphviz dot commands for state.
+ std::ostream&
+ _M_dot(std::ostream& __ostr, _StateIdT __id) const;
#endif
- };
+ };
- template<typename _CharT, typename _TraitsT>
- class _NFA
- : public std::vector<_State<_CharT, _TraitsT>>
+ template<typename _TraitsT>
+ struct _State : _State_base
{
- public:
- typedef _State<_CharT, _TraitsT> _StateT;
- typedef const _Matcher<_CharT>& _MatcherT;
- typedef size_t _SizeT;
- typedef regex_constants::syntax_option_type _FlagT;
-
- _NFA(_FlagT __f)
- : _M_flags(__f), _M_start_state(0), _M_subexpr_count(0),
- _M_quant_count(0), _M_has_backref(false)
- { }
+ typedef _Matcher<typename _TraitsT::char_type> _MatcherT;
- _FlagT
- _M_options() const
- { return _M_flags; }
+ _MatcherT _M_matches; // for _S_opcode_match
- _StateIdT
- _M_start() const
- { return _M_start_state; }
+ explicit _State(_Opcode __opcode) : _State_base(__opcode) { }
+ };
- const _StateSet&
- _M_final_states() const
- { return _M_accepting_states; }
+ struct _NFA_base
+ {
+ typedef size_t _SizeT;
+ typedef regex_constants::syntax_option_type _FlagT;
+
+ explicit
+ _NFA_base(_FlagT __f)
+ : _M_flags(__f), _M_start_state(0), _M_subexpr_count(0),
+ _M_quant_count(0), _M_has_backref(false)
+ { }
+
+ _NFA_base(_NFA_base&&) = default;
+
+ protected:
+ ~_NFA_base() = default;
+
+ public:
+ _FlagT
+ _M_options() const
+ { return _M_flags; }
+
+ _StateIdT
+ _M_start() const
+ { return _M_start_state; }
+
+ const _StateSet&
+ _M_final_states() const
+ { return _M_accepting_states; }
+
+ _SizeT
+ _M_sub_count() const
+ { return _M_subexpr_count; }
+
+ std::vector<size_t> _M_paren_stack;
+ _StateSet _M_accepting_states;
+ _FlagT _M_flags;
+ _StateIdT _M_start_state;
+ _SizeT _M_subexpr_count;
+ _SizeT _M_quant_count;
+ bool _M_has_backref;
+ };
+
+ template<typename _TraitsT>
+ struct _NFA
+ : _NFA_base, std::vector<_State<_TraitsT>>
+ {
+ typedef _State<_TraitsT> _StateT;
+ typedef _Matcher<typename _TraitsT::char_type> _MatcherT;
- _SizeT
- _M_sub_count() const
- { return _M_subexpr_count; }
+ using _NFA_base::_NFA_base;
+
+ // for performance reasons _NFA objects should only be moved not copied
+ _NFA(const _NFA&) = delete;
+ _NFA(_NFA&&) = default;
_StateIdT
_M_insert_accept()
{
auto __ret = _M_insert_state(_StateT(_S_opcode_accept));
- _M_accepting_states.insert(__ret);
+ this->_M_accepting_states.insert(__ret);
return __ret;
}
@@ -149,38 +182,38 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_StateT __tmp(_S_opcode_alternative);
// It labels every quantifier to make greedy comparison easier in BFS
// approach.
- __tmp._M_quant_index = _M_quant_count++;
+ __tmp._M_quant_index = this->_M_quant_count++;
__tmp._M_next = __next;
__tmp._M_alt = __alt;
__tmp._M_neg = __neg;
- return _M_insert_state(__tmp);
+ return _M_insert_state(std::move(__tmp));
}
_StateIdT
_M_insert_matcher(_MatcherT __m)
{
_StateT __tmp(_S_opcode_match);
- __tmp._M_matches = __m;
- return _M_insert_state(__tmp);
+ __tmp._M_matches = std::move(__m);
+ return _M_insert_state(std::move(__tmp));
}
_StateIdT
_M_insert_subexpr_begin()
{
- auto __id = _M_subexpr_count++;
- _M_paren_stack.push_back(__id);
+ auto __id = this->_M_subexpr_count++;
+ this->_M_paren_stack.push_back(__id);
_StateT __tmp(_S_opcode_subexpr_begin);
__tmp._M_subexpr = __id;
- return _M_insert_state(__tmp);
+ return _M_insert_state(std::move(__tmp));
}
_StateIdT
_M_insert_subexpr_end()
{
_StateT __tmp(_S_opcode_subexpr_end);
- __tmp._M_subexpr = _M_paren_stack.back();
- _M_paren_stack.pop_back();
- return _M_insert_state(__tmp);
+ __tmp._M_subexpr = this->_M_paren_stack.back();
+ this->_M_paren_stack.pop_back();
+ return _M_insert_state(std::move(__tmp));
}
_StateIdT
@@ -199,7 +232,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
_StateT __tmp(_S_opcode_word_boundary);
__tmp._M_neg = __neg;
- return _M_insert_state(__tmp);
+ return _M_insert_state(std::move(__tmp));
}
_StateIdT
@@ -208,7 +241,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_StateT __tmp(_S_opcode_subexpr_lookahead);
__tmp._M_alt = __alt;
__tmp._M_neg = __neg;
- return _M_insert_state(__tmp);
+ return _M_insert_state(std::move(__tmp));
}
_StateIdT
@@ -218,7 +251,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
_StateIdT
_M_insert_state(_StateT __s)
{
- this->push_back(__s);
+ this->push_back(std::move(__s));
return this->size()-1;
}
@@ -230,28 +263,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
std::ostream&
_M_dot(std::ostream& __ostr) const;
#endif
-
- std::vector<size_t> _M_paren_stack;
- _StateSet _M_accepting_states;
- _FlagT _M_flags;
- _StateIdT _M_start_state;
- _SizeT _M_subexpr_count;
- _SizeT _M_quant_count;
- bool _M_has_backref;
};
/// Describes a sequence of one or more %_State, its current start
/// and end(s). This structure contains fragments of an NFA during
/// construction.
- template<typename _CharT, typename _TraitsT>
+ template<typename _TraitsT>
class _StateSeq
{
public:
- typedef _NFA<_CharT, _TraitsT> _RegexT;
+ typedef _NFA<_TraitsT> _RegexT;
public:
_StateSeq(_RegexT& __nfa, _StateIdT __s)
- : _StateSeq(__nfa, __s, __s)
+ : _M_nfa(__nfa), _M_start(__s), _M_end(__s)
{ }
_StateSeq(_RegexT& __nfa, _StateIdT __s, _StateIdT __end)