2010-12-20 Tobias Burnus <burnus@net-b.de>
[official-gcc.git] / libstdc++-v3 / include / bits / regex_nfa.tcc
blob392b2c3f083fba9db3e8b86a25d961e7f1598ff6
1 // class template regex -*- C++ -*-
3 // Copyright (C) 2010 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23 // <http://www.gnu.org/licenses/>.
25 /**
26  * @file bits/regex_nfa.tcc
27  *  This is an internal header file, included by other library headers.
28  *  Do not attempt to use it directly. @headername{regex}
29  */
30 #include <regex>
32 _GLIBCXX_BEGIN_NAMESPACE(std)
34 namespace __regex
36 #ifdef _GLIBCXX_DEBUG
37 inline std::ostream& _State::
38 _M_print(std::ostream& ostr) const
40   switch (_M_opcode)
41   {
42     case _S_opcode_alternative:
43       ostr << "alt next=" << _M_next << " alt=" << _M_alt;
44       break;
45     case _S_opcode_subexpr_begin:
46       ostr << "subexpr begin next=" << _M_next << " index=" << _M_subexpr;
47       break;
48     case _S_opcode_subexpr_end:
49       ostr << "subexpr end next=" << _M_next << " index=" << _M_subexpr;
50       break;
51     case _S_opcode_match:
52       ostr << "match next=" << _M_next;
53       break;
54     case _S_opcode_accept:
55       ostr << "accept next=" << _M_next;
56       break;
57     default:
58       ostr << "unknown next=" << _M_next;
59       break;
60   }
61   return ostr;
64 // Prints graphviz dot commands for state.
65 inline std::ostream& _State::
66 _M_dot(std::ostream& __ostr, _StateIdT __id) const
68   switch (_M_opcode)
69   {
70     case _S_opcode_alternative:
71       __ostr << __id << " [label=\"" << __id << "\\nALT\"];\n" 
72              << __id << " -> " << _M_next
73              << " [label=\"epsilon\", tailport=\"s\"];\n"
74              << __id << " -> " << _M_alt 
75              << " [label=\"epsilon\", tailport=\"n\"];\n";
76       break;
77     case _S_opcode_subexpr_begin:
78       __ostr << __id << " [label=\"" << __id << "\\nSBEGIN "
79              << _M_subexpr << "\"];\n" 
80              << __id << " -> " << _M_next << " [label=\"epsilon\"];\n";
81       break;
82     case _S_opcode_subexpr_end:
83       __ostr << __id << " [label=\"" << __id << "\\nSEND "
84              << _M_subexpr << "\"];\n" 
85              << __id << " -> " << _M_next << " [label=\"epsilon\"];\n";
86       break;
87     case _S_opcode_match:
88       __ostr << __id << " [label=\"" << __id << "\\nMATCH\"];\n" 
89              << __id << " -> " << _M_next << " [label=\"<match>\"];\n";
90       break;
91     case _S_opcode_accept:
92       __ostr << __id << " [label=\"" << __id << "\\nACC\"];\n" ;
93       break;
94     default:
95       __ostr << __id << " [label=\"" << __id << "\\nUNK\"];\n" 
96              << __id << " -> " << _M_next << " [label=\"?\"];\n";
97       break;
98   }
99   return __ostr;
102 inline std::ostream& _Nfa::
103 _M_dot(std::ostream& __ostr) const
105   __ostr << "digraph _Nfa {\n"
106    << "  rankdir=LR;\n";
107   for (unsigned int __i = 0; __i < this->size(); ++__i)
108   { this->at(__i)._M_dot(__ostr, __i); }
109   __ostr << "}\n";
110   return __ostr;
112 #endif
114 inline _StateSeq& _StateSeq::
115 operator=(const _StateSeq& __rhs)
117   _M_start = __rhs._M_start;
118   _M_end1  = __rhs._M_end1;
119   _M_end2  = __rhs._M_end2;
120   return *this;
123 inline void _StateSeq::
124 _M_push_back(_StateIdT __id)
126   if (_M_end1 != _S_invalid_state_id)
127     _M_nfa[_M_end1]._M_next = __id;
128   _M_end1 = __id;
131 inline void _StateSeq::
132 _M_append(_StateIdT __id)
134   if (_M_end2 != _S_invalid_state_id)
135   {
136     if (_M_end2 == _M_end1)
137       _M_nfa[_M_end2]._M_alt = __id;
138     else
139       _M_nfa[_M_end2]._M_next = __id;
140     _M_end2 = _S_invalid_state_id;
141   }
142   if (_M_end1 != _S_invalid_state_id)
143     _M_nfa[_M_end1]._M_next = __id;
144   _M_end1 = __id;
147 inline void _StateSeq::
148 _M_append(_StateSeq& __rhs)
150   if (_M_end2 != _S_invalid_state_id)
151   {
152     if (_M_end2 == _M_end1)
153       _M_nfa[_M_end2]._M_alt = __rhs._M_start;
154     else
155       _M_nfa[_M_end2]._M_next = __rhs._M_start;
156     _M_end2 = _S_invalid_state_id;
157   }
158   if (__rhs._M_end2 != _S_invalid_state_id)
159     _M_end2 = __rhs._M_end2;
160   if (_M_end1 != _S_invalid_state_id)
161     _M_nfa[_M_end1]._M_next = __rhs._M_start;
162   _M_end1 = __rhs._M_end1;
165 // @todo implement this function.
166 inline _StateIdT _StateSeq::
167 _M_clone()
168 { return 0; }
170 } // namespace __regex
172 _GLIBCXX_END_NAMESPACE