OSDN Git Service

2a1a4d076798806ba0f45b72406e129ae5a67018
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / bits / regex_nfa.tcc
1 // class template regex -*- C++ -*-
2
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.
10
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.
15
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.
19
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/>.
24
25 /**
26  * @file bits/regex_nfa.tcc
27  */
28 #include <regex>
29
30 namespace std
31 {
32 namespace __regex
33 {
34 #ifdef _GLIBCXX_DEBUG
35 inline std::ostream& _State::
36 _M_print(std::ostream& ostr) const
37 {
38   switch (_M_opcode)
39   {
40     case _S_opcode_alternative:
41       ostr << "alt next=" << _M_next << " alt=" << _M_alt;
42       break;
43     case _S_opcode_subexpr_begin:
44       ostr << "subexpr begin next=" << _M_next << " index=" << _M_subexpr;
45       break;
46     case _S_opcode_subexpr_end:
47       ostr << "subexpr end next=" << _M_next << " index=" << _M_subexpr;
48       break;
49     case _S_opcode_match:
50       ostr << "match next=" << _M_next;
51       break;
52     case _S_opcode_accept:
53       ostr << "accept next=" << _M_next;
54       break;
55     default:
56       ostr << "unknown next=" << _M_next;
57       break;
58   }
59   return ostr;
60 }
61
62 // Prints graphviz dot commands for state.
63 inline std::ostream& _State::
64 _M_dot(std::ostream& __ostr, _StateIdT __id) const
65 {
66   switch (_M_opcode)
67   {
68     case _S_opcode_alternative:
69       __ostr << __id << " [label=\"" << __id << "\\nALT\"];\n" 
70              << __id << " -> " << _M_next
71              << " [label=\"epsilon\", tailport=\"s\"];\n"
72              << __id << " -> " << _M_alt 
73              << " [label=\"epsilon\", tailport=\"n\"];\n";
74       break;
75     case _S_opcode_subexpr_begin:
76       __ostr << __id << " [label=\"" << __id << "\\nSBEGIN "
77              << _M_subexpr << "\"];\n" 
78              << __id << " -> " << _M_next << " [label=\"epsilon\"];\n";
79       break;
80     case _S_opcode_subexpr_end:
81       __ostr << __id << " [label=\"" << __id << "\\nSEND "
82              << _M_subexpr << "\"];\n" 
83              << __id << " -> " << _M_next << " [label=\"epsilon\"];\n";
84       break;
85     case _S_opcode_match:
86       __ostr << __id << " [label=\"" << __id << "\\nMATCH\"];\n" 
87              << __id << " -> " << _M_next << " [label=\"<match>\"];\n";
88       break;
89     case _S_opcode_accept:
90       __ostr << __id << " [label=\"" << __id << "\\nACC\"];\n" ;
91       break;
92     default:
93       __ostr << __id << " [label=\"" << __id << "\\nUNK\"];\n" 
94              << __id << " -> " << _M_next << " [label=\"?\"];\n";
95       break;
96   }
97   return __ostr;
98 }
99
100 inline std::ostream& _Nfa::
101 _M_dot(std::ostream& __ostr) const
102 {
103   __ostr << "digraph _Nfa {\n"
104    << "  rankdir=LR;\n";
105   for (unsigned int __i = 0; __i < this->size(); ++__i)
106   { this->at(__i)._M_dot(__ostr, __i); }
107   __ostr << "}\n";
108   return __ostr;
109 }
110 #endif
111
112 inline _StateSeq& _StateSeq::
113 operator=(const _StateSeq& __rhs)
114 {
115   _M_start = __rhs._M_start;
116   _M_end1  = __rhs._M_end1;
117   _M_end2  = __rhs._M_end2;
118   return *this;
119 }
120
121 inline void _StateSeq::
122 _M_push_back(_StateIdT __id)
123 {
124   if (_M_end1 != _S_invalid_state_id)
125     _M_nfa[_M_end1]._M_next = __id;
126   _M_end1 = __id;
127 }
128
129 inline void _StateSeq::
130 _M_append(_StateIdT __id)
131 {
132   if (_M_end2 != _S_invalid_state_id)
133   {
134     if (_M_end2 == _M_end1)
135       _M_nfa[_M_end2]._M_alt = __id;
136     else
137       _M_nfa[_M_end2]._M_next = __id;
138     _M_end2 = _S_invalid_state_id;
139   }
140   if (_M_end1 != _S_invalid_state_id)
141     _M_nfa[_M_end1]._M_next = __id;
142   _M_end1 = __id;
143 }
144
145 inline void _StateSeq::
146 _M_append(_StateSeq& __rhs)
147 {
148   if (_M_end2 != _S_invalid_state_id)
149   {
150     if (_M_end2 == _M_end1)
151       _M_nfa[_M_end2]._M_alt = __rhs._M_start;
152     else
153       _M_nfa[_M_end2]._M_next = __rhs._M_start;
154     _M_end2 = _S_invalid_state_id;
155   }
156   if (__rhs._M_end2 != _S_invalid_state_id)
157     _M_end2 = __rhs._M_end2;
158   if (_M_end1 != _S_invalid_state_id)
159     _M_nfa[_M_end1]._M_next = __rhs._M_start;
160   _M_end1 = __rhs._M_end1;
161 }
162
163 // @todo implement this function.
164 inline _StateIdT _StateSeq::
165 _M_clone()
166 { return 0; }
167
168 } // namespace __regex
169 } // namespace std
170