libstdc++
regex_nfa.tcc
Go to the documentation of this file.
00001 // class template regex -*- C++ -*-
00002 
00003 // Copyright (C) 2010, 2011 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 3, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 /**
00026  * @file bits/regex_nfa.tcc
00027  *  This is an internal header file, included by other library headers.
00028  *  Do not attempt to use it directly. @headername{regex}
00029  */
00030 #include <regex>
00031 
00032 namespace std _GLIBCXX_VISIBILITY(default)
00033 {
00034 namespace __regex
00035 {
00036 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00037 
00038 #ifdef _GLIBCXX_DEBUG
00039 inline std::ostream& _State::
00040 _M_print(std::ostream& ostr) const
00041 {
00042   switch (_M_opcode)
00043   {
00044     case _S_opcode_alternative:
00045       ostr << "alt next=" << _M_next << " alt=" << _M_alt;
00046       break;
00047     case _S_opcode_subexpr_begin:
00048       ostr << "subexpr begin next=" << _M_next << " index=" << _M_subexpr;
00049       break;
00050     case _S_opcode_subexpr_end:
00051       ostr << "subexpr end next=" << _M_next << " index=" << _M_subexpr;
00052       break;
00053     case _S_opcode_match:
00054       ostr << "match next=" << _M_next;
00055       break;
00056     case _S_opcode_accept:
00057       ostr << "accept next=" << _M_next;
00058       break;
00059     default:
00060       ostr << "unknown next=" << _M_next;
00061       break;
00062   }
00063   return ostr;
00064 }
00065 
00066 // Prints graphviz dot commands for state.
00067 inline std::ostream& _State::
00068 _M_dot(std::ostream& __ostr, _StateIdT __id) const
00069 {
00070   switch (_M_opcode)
00071   {
00072     case _S_opcode_alternative:
00073       __ostr << __id << " [label=\"" << __id << "\\nALT\"];\n" 
00074              << __id << " -> " << _M_next
00075              << " [label=\"epsilon\", tailport=\"s\"];\n"
00076              << __id << " -> " << _M_alt 
00077              << " [label=\"epsilon\", tailport=\"n\"];\n";
00078       break;
00079     case _S_opcode_subexpr_begin:
00080       __ostr << __id << " [label=\"" << __id << "\\nSBEGIN "
00081              << _M_subexpr << "\"];\n" 
00082              << __id << " -> " << _M_next << " [label=\"epsilon\"];\n";
00083       break;
00084     case _S_opcode_subexpr_end:
00085       __ostr << __id << " [label=\"" << __id << "\\nSEND "
00086              << _M_subexpr << "\"];\n" 
00087              << __id << " -> " << _M_next << " [label=\"epsilon\"];\n";
00088       break;
00089     case _S_opcode_match:
00090       __ostr << __id << " [label=\"" << __id << "\\nMATCH\"];\n" 
00091              << __id << " -> " << _M_next << " [label=\"<match>\"];\n";
00092       break;
00093     case _S_opcode_accept:
00094       __ostr << __id << " [label=\"" << __id << "\\nACC\"];\n" ;
00095       break;
00096     default:
00097       __ostr << __id << " [label=\"" << __id << "\\nUNK\"];\n" 
00098              << __id << " -> " << _M_next << " [label=\"?\"];\n";
00099       break;
00100   }
00101   return __ostr;
00102 }
00103 
00104 inline std::ostream& _Nfa::
00105 _M_dot(std::ostream& __ostr) const
00106 {
00107   __ostr << "digraph _Nfa {\n"
00108    << "  rankdir=LR;\n";
00109   for (unsigned int __i = 0; __i < this->size(); ++__i)
00110   { this->at(__i)._M_dot(__ostr, __i); }
00111   __ostr << "}\n";
00112   return __ostr;
00113 }
00114 #endif
00115 
00116 inline _StateSeq& _StateSeq::
00117 operator=(const _StateSeq& __rhs)
00118 {
00119   _M_start = __rhs._M_start;
00120   _M_end1  = __rhs._M_end1;
00121   _M_end2  = __rhs._M_end2;
00122   return *this;
00123 }
00124 
00125 inline void _StateSeq::
00126 _M_push_back(_StateIdT __id)
00127 {
00128   if (_M_end1 != _S_invalid_state_id)
00129     _M_nfa[_M_end1]._M_next = __id;
00130   _M_end1 = __id;
00131 }
00132 
00133 inline void _StateSeq::
00134 _M_append(_StateIdT __id)
00135 {
00136   if (_M_end2 != _S_invalid_state_id)
00137   {
00138     if (_M_end2 == _M_end1)
00139       _M_nfa[_M_end2]._M_alt = __id;
00140     else
00141       _M_nfa[_M_end2]._M_next = __id;
00142     _M_end2 = _S_invalid_state_id;
00143   }
00144   if (_M_end1 != _S_invalid_state_id)
00145     _M_nfa[_M_end1]._M_next = __id;
00146   _M_end1 = __id;
00147 }
00148 
00149 inline void _StateSeq::
00150 _M_append(_StateSeq& __rhs)
00151 {
00152   if (_M_end2 != _S_invalid_state_id)
00153   {
00154     if (_M_end2 == _M_end1)
00155       _M_nfa[_M_end2]._M_alt = __rhs._M_start;
00156     else
00157       _M_nfa[_M_end2]._M_next = __rhs._M_start;
00158     _M_end2 = _S_invalid_state_id;
00159   }
00160   if (__rhs._M_end2 != _S_invalid_state_id)
00161     _M_end2 = __rhs._M_end2;
00162   if (_M_end1 != _S_invalid_state_id)
00163     _M_nfa[_M_end1]._M_next = __rhs._M_start;
00164   _M_end1 = __rhs._M_end1;
00165 }
00166 
00167 // @todo implement this function.
00168 inline _StateIdT _StateSeq::
00169 _M_clone()
00170 { return 0; }
00171 
00172 _GLIBCXX_END_NAMESPACE_VERSION
00173 } // namespace __regex
00174 } // namespace