closure.ipp

来自「著名的Parser库Spirit在VC6上的Port」· IPP 代码 · 共 169 行

IPP
169
字号
/*=============================================================================
    Closures

    Spirit V1.3.1
    Copyright (c) 2001, Joel de Guzman

    This software is provided 'as-is', without any express or implied
    warranty. In no event will the copyright holder be held liable for
    any damages arising from the use of this software.

    Permission is granted to anyone to use this software for any purpose,
    including commercial applications, and to alter it and redistribute
    it freely, subject to the following restrictions:

    1.  The origin of this software must not be misrepresented; you must
        not claim that you wrote the original software. If you use this
        software in a product, an acknowledgment in the product documentation
        would be appreciated but is not required.

    2.  Altered source versions must be plainly marked as such, and must
        not be misrepresented as being the original software.

    3.  This notice may not be removed or altered from any source
        distribution.

    Acknowledgements:

        Special thanks to Dan Nuffer, John (EBo) David, Chris Uzdavinis,
        and Doug Gregor. These people are most instrumental in steering
        Spirit in the right direction.

        Special thanks also to people who have contributed to the code base
        and sample code, ported Spirit to various platforms and compilers,
        gave suggestions, reported and provided bug fixes. Alexander
        Hirner, Andy Elvey, Bogdan Kushnir, Brett Calcott, Bruce Florman,
        Changzhe Han, Colin McPhail, Hakki Dogusan, Jan Bares, Joseph
        Smith, Martijn W. van der Lee, Raghavendra Satish, Remi Delcos, Tom
        Spilman, Vladimir Prus, W. Scott Dillman, David A. Greene, Bob
        Bailey, Hartmut Kaiser.

        Finally special thanks also to people who gave feedback and
        valuable comments, particularly members of Spirit's Source Forge
        mailing list and boost.org.

    URL: http://spirit.sourceforge.net/

=============================================================================*/
#ifndef SPIRIT_CLOSURE_IPP
#define SPIRIT_CLOSURE_IPP

///////////////////////////////////////////////////////////////////////////////

#include "boost/spirit/MSVC/closure.hpp"
#if defined(SPIRIT_DEBUG)
#include "boost/tuple/tuple_io.hpp"
#endif 
#include <cassert>

///////////////////////////////////////////////////////////////////////////////
namespace spirit {

///////////////////////////////////////////////////////////////////////////////
//
//  closure_parser_action class implementation
//
///////////////////////////////////////////////////////////////////////////////
template <typename ParserT, typename ActionT>
inline closure_parser_action<ParserT, ActionT>::
        closure_parser_action(ParserT const& parser_, ActionT const& actor_) :
    base_action<ParserT, ActionT, closure_parser_action<ParserT, ActionT> >(parser_, actor_)
{
}



///////////////////////////////////////////////////////////////////////////////
//
//  closure_parser class implementation
//
//      The parse member function creates a local_saver class before calling
//      the subject's parse member function.
//
///////////////////////////////////////////////////////////////////////////////
template <typename TupleT, typename ParserT>
inline closure_parser<TupleT, ParserT>::closure_parser(
    TupleT*& ptr_,
    ParserT const& parser_)
:   unary<ParserT>(parser_),
    ptr(ptr_) 
{
#if defined(SPIRIT_DEBUG)
    debug.name (std::string("closure parser: ") + parser_.debug.name());
#endif 
}

//////////////////////////////////
#ifdef SPIRIT_DEBUG
template <typename TupleT>
void
print_closure_info(bool hit, int level, bool close, std::string const &name, TupleT *ptr)
{
    if (ptr && !name.empty())
    {
        for (int i = 0; i < level; ++i)
            SPIRIT_DEBUG_OUT << "  ";
        if (close)
        {
            if (hit)
                SPIRIT_DEBUG_OUT << "/";
            else
                SPIRIT_DEBUG_OUT << "#";
        }
        SPIRIT_DEBUG_OUT << name << ": "<< *ptr << "\n";
    }
}
#endif


///////////////////////////////////////////////////////////////////////////////
//
//  closure class implementation
//
//      Closures are implemented using the boost::tuples library. Each
//      closure variable is a tuple element. The closure class has two member
//      variables: 1) a pointer to the <actual> tuple that is created at run-
//      time in the stack area of a parser's parse member function, and 2) a
//      tuples holding the local class proxies that refers to the each
//      element in the <actual> tuple.
//
//      Schematically:
//
//          closure { ptr <--- locals }
//                      |         |
//                      |         |
//                      |         +----<-- referencees (semantic actions)
//                      |
//                      +----<-- closure_parsers (actual local vars)
//
///////////////////////////////////////////////////////////////////////////////
template <
    typename T0, typename T1, typename T2, typename T3, typename T4,
    typename T5, typename T6, typename T7, typename T8, typename T9
>
inline base_closure<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::base_closure()
:   ptr(0),
    locals(
        LT0::init(ptr), LT1::init(ptr),
        LT2::init(ptr), LT3::init(ptr),
        LT4::init(ptr), LT5::init(ptr),
        LT6::init(ptr), LT7::init(ptr),
        LT8::init(ptr), LT9::init(ptr)
    )
{
}

template <
    typename T0, typename T1, typename T2, typename T3, typename T4,
    typename T5, typename T6, typename T7, typename T8, typename T9
>
inline closure<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>::closure()
{
}

///////////////////////////////////////////////////////////////////////////////

}   //  namespace Spirit

#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?