[857] | 1 | /*=============================================================================
|
---|
| 2 | Copyright (c) 2001-2003 Joel de Guzman
|
---|
| 3 | http://spirit.sourceforge.net/
|
---|
| 4 |
|
---|
| 5 | Use, modification and distribution is subject to the Boost Software
|
---|
| 6 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
---|
| 7 | http://www.boost.org/LICENSE_1_0.txt)
|
---|
| 8 | =============================================================================*/
|
---|
| 9 | #ifndef BOOST_SPIRIT_SYMBOLS_IPP
|
---|
| 10 | #define BOOST_SPIRIT_SYMBOLS_IPP
|
---|
| 11 |
|
---|
| 12 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 13 | #include <boost/spirit/symbols/impl/tst.ipp>
|
---|
| 14 | #include <boost/detail/workaround.hpp>
|
---|
| 15 |
|
---|
| 16 | // MSVC: void warning about the use of 'this' pointer in constructors
|
---|
| 17 | #if defined(BOOST_MSVC)
|
---|
| 18 | #pragma warning(disable : 4355)
|
---|
| 19 | #endif
|
---|
| 20 |
|
---|
| 21 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 22 | namespace boost { namespace spirit {
|
---|
| 23 |
|
---|
| 24 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 25 | //
|
---|
| 26 | // symbols class implementation
|
---|
| 27 | //
|
---|
| 28 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 29 | template <typename T, typename CharT, typename SetT>
|
---|
| 30 | inline symbols<T, CharT, SetT>::symbols()
|
---|
| 31 | : SetT()
|
---|
| 32 | , add(*this)
|
---|
| 33 | {
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | //////////////////////////////////
|
---|
| 37 | template <typename T, typename CharT, typename SetT>
|
---|
| 38 | symbols<T, CharT, SetT>::symbols(symbols const& other)
|
---|
| 39 | : SetT(other)
|
---|
| 40 | // Tru64 CXX seems to be confused by the explicit call of the default
|
---|
| 41 | // constructor and generates wrong code which invalidates the just contructed
|
---|
| 42 | // first base class in the line above.
|
---|
| 43 | #if !BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(60590041))
|
---|
| 44 | , parser<symbols<T, CharT, SetT> >()
|
---|
| 45 | #endif
|
---|
| 46 | , add(*this)
|
---|
| 47 | {
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | //////////////////////////////////
|
---|
| 51 | template <typename T, typename CharT, typename SetT>
|
---|
| 52 | inline symbols<T, CharT, SetT>::~symbols()
|
---|
| 53 | {}
|
---|
| 54 |
|
---|
| 55 | //////////////////////////////////
|
---|
| 56 | template <typename T, typename CharT, typename SetT>
|
---|
| 57 | inline symbols<T, CharT, SetT>&
|
---|
| 58 | symbols<T, CharT, SetT>::operator=(symbols const& other)
|
---|
| 59 | {
|
---|
| 60 | SetT::operator=(other);
|
---|
| 61 | return *this;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | //////////////////////////////////
|
---|
| 65 | template <typename T, typename CharT, typename SetT>
|
---|
| 66 | inline symbol_inserter<T, SetT> const&
|
---|
| 67 | symbols<T, CharT, SetT>::operator=(CharT const* str)
|
---|
| 68 | {
|
---|
| 69 | return add, str;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 73 | //
|
---|
| 74 | // Symbol table utilities
|
---|
| 75 | //
|
---|
| 76 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 77 | template <typename T, typename CharT, typename SetT>
|
---|
| 78 | inline T*
|
---|
| 79 | find(symbols<T, CharT, SetT> const& table, CharT const* sym)
|
---|
| 80 | {
|
---|
| 81 | CharT const* last = sym;
|
---|
| 82 | while (*last)
|
---|
| 83 | last++;
|
---|
| 84 | scanner<CharT const *> scan(sym, last);
|
---|
| 85 | T* result = table.find(scan);
|
---|
| 86 | return scan.at_end()? result: 0;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | //////////////////////////////////
|
---|
| 90 | template <typename T, typename CharT, typename SetT>
|
---|
| 91 | inline T*
|
---|
| 92 | add(symbols<T, CharT, SetT>& table, CharT const* sym, T const& data)
|
---|
| 93 | {
|
---|
| 94 | CharT const* first = sym;
|
---|
| 95 | CharT const* last = sym;
|
---|
| 96 | while (*last)
|
---|
| 97 | last++;
|
---|
| 98 | scanner<CharT const *> scan(first, last);
|
---|
| 99 | if (table.find(scan) && scan.at_end())
|
---|
| 100 | return 0; // symbol already contained in symbol table
|
---|
| 101 | table.add(sym, last, data);
|
---|
| 102 | first = sym;
|
---|
| 103 | return table.find(scan); // refind the inserted symbol
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | ///////////////////////////////////////////////////////////////////////////////
|
---|
| 107 | }} // namespace boost::spirit
|
---|
| 108 |
|
---|
| 109 | #if defined(BOOST_MSVC)
|
---|
| 110 | #pragma warning(default : 4355)
|
---|
| 111 | #endif
|
---|
| 112 |
|
---|
| 113 | #endif
|
---|