Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:53:51

0001 ///////////////////////////////////////////////////////////////////////////////
0002 // compile.hpp
0003 //
0004 //  Copyright 2008 Eric Niebler. Distributed under the Boost
0005 //  Software License, Version 1.0. (See accompanying file
0006 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0007 
0008 #ifndef BOOST_XPRESSIVE_DETAIL_STATIC_COMPILE_HPP_EAN_10_04_2005
0009 #define BOOST_XPRESSIVE_DETAIL_STATIC_COMPILE_HPP_EAN_10_04_2005
0010 
0011 // MS compatible compilers support #pragma once
0012 #if defined(_MSC_VER)
0013 # pragma once
0014 #endif
0015 
0016 #include <boost/mpl/bool.hpp>
0017 #include <boost/iterator/iterator_traits.hpp>
0018 #include <boost/proto/core.hpp>
0019 #include <boost/xpressive/regex_traits.hpp>
0020 #include <boost/xpressive/detail/core/regex_impl.hpp>
0021 #include <boost/xpressive/detail/core/linker.hpp>
0022 #include <boost/xpressive/detail/core/optimize.hpp>
0023 #include <boost/xpressive/detail/core/adaptor.hpp>
0024 #include <boost/xpressive/detail/core/matcher/end_matcher.hpp>
0025 #include <boost/xpressive/detail/static/static.hpp>
0026 #include <boost/xpressive/detail/static/visitor.hpp>
0027 #include <boost/xpressive/detail/static/grammar.hpp>
0028 
0029 namespace boost { namespace xpressive { namespace detail
0030 {
0031 
0032     ///////////////////////////////////////////////////////////////////////////////
0033     // static_compile_impl2
0034     template<typename Xpr, typename BidiIter, typename Traits>
0035     void static_compile_impl2(Xpr const &xpr, shared_ptr<regex_impl<BidiIter> > const &impl, Traits const &tr)
0036     {
0037         typedef typename iterator_value<BidiIter>::type char_type;
0038         impl->tracking_clear();
0039         impl->traits_ = new traits_holder<Traits>(tr);
0040 
0041         // "compile" the regex and wrap it in an xpression_adaptor.
0042         typedef xpression_visitor<BidiIter, mpl::false_, Traits> visitor_type;
0043         visitor_type visitor(tr, impl);
0044         intrusive_ptr<matchable_ex<BidiIter> const> adxpr = make_adaptor<matchable_ex<BidiIter> >(
0045             typename Grammar<char_type>::template impl<Xpr const &, end_xpression, visitor_type &>()(
0046                 xpr
0047               , end_xpression()
0048               , visitor
0049             )
0050         );
0051 
0052         // Link and optimize the regex
0053         common_compile(adxpr, *impl, visitor.traits());
0054 
0055         // References changed, update dependencies.
0056         impl->tracking_update();
0057     }
0058 
0059     ///////////////////////////////////////////////////////////////////////////////
0060     // pattern for imbued regexes.
0061     struct XpressiveLocaleModifier
0062       : proto::binary_expr<
0063             modifier_tag
0064           , proto::terminal<locale_modifier<proto::_> >
0065           , proto::_
0066         >
0067     {};
0068 
0069     ///////////////////////////////////////////////////////////////////////////////
0070     // static_compile_impl1
0071     template<typename Xpr, typename BidiIter>
0072     typename disable_if<proto::matches<Xpr, XpressiveLocaleModifier> >::type
0073     static_compile_impl1(Xpr const &xpr, shared_ptr<regex_impl<BidiIter> > const &impl)
0074     {
0075         // use default traits
0076         typedef typename iterator_value<BidiIter>::type char_type;
0077         typedef typename default_regex_traits<char_type>::type traits_type;
0078         traits_type tr;
0079         static_compile_impl2(xpr, impl, tr);
0080     }
0081 
0082     ///////////////////////////////////////////////////////////////////////////////
0083     // static_compile_impl1
0084     template<typename Xpr, typename BidiIter>
0085     typename enable_if<proto::matches<Xpr, XpressiveLocaleModifier> >::type
0086     static_compile_impl1(Xpr const &xpr, shared_ptr<regex_impl<BidiIter> > const &impl)
0087     {
0088         // use specified traits
0089         typedef typename proto::result_of::value<typename proto::result_of::left<Xpr>::type>::type::locale_type locale_type;
0090         typedef typename regex_traits_type<locale_type, BidiIter>::type traits_type;
0091         static_compile_impl2(proto::right(xpr), impl, traits_type(proto::value(proto::left(xpr)).getloc()));
0092     }
0093 
0094     ///////////////////////////////////////////////////////////////////////////////
0095     // static_compile
0096     template<typename Xpr, typename BidiIter>
0097     void static_compile(Xpr const &xpr, shared_ptr<regex_impl<BidiIter> > const &impl)
0098     {
0099         static_compile_impl1(xpr, impl);
0100     }
0101 
0102 }}} // namespace boost::xpressive::detail
0103 
0104 #endif