1 /////////////////////////////////////////////////////////////////////////////// 2 // compile.hpp 3 // 4 // Copyright 2008 Eric Niebler. Distributed under the Boost 5 // Software License, Version 1.0. (See accompanying file 6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 8 #ifndef BOOST_XPRESSIVE_DETAIL_STATIC_COMPILE_HPP_EAN_10_04_2005 9 #define BOOST_XPRESSIVE_DETAIL_STATIC_COMPILE_HPP_EAN_10_04_2005 10 11 // MS compatible compilers support #pragma once 12 #if defined(_MSC_VER) 13 # pragma once 14 #endif 15 16 #include <boost/mpl/bool.hpp> 17 #include <boost/iterator/iterator_traits.hpp> 18 #include <boost/proto/core.hpp> 19 #include <boost/xpressive/regex_traits.hpp> 20 #include <boost/xpressive/detail/core/regex_impl.hpp> 21 #include <boost/xpressive/detail/core/linker.hpp> 22 #include <boost/xpressive/detail/core/optimize.hpp> 23 #include <boost/xpressive/detail/core/adaptor.hpp> 24 #include <boost/xpressive/detail/core/matcher/end_matcher.hpp> 25 #include <boost/xpressive/detail/static/static.hpp> 26 #include <boost/xpressive/detail/static/visitor.hpp> 27 #include <boost/xpressive/detail/static/grammar.hpp> 28 29 namespace boost { namespace xpressive { namespace detail 30 { 31 32 /////////////////////////////////////////////////////////////////////////////// 33 // static_compile_impl2 34 template<typename Xpr, typename BidiIter, typename Traits> static_compile_impl2(Xpr const & xpr,shared_ptr<regex_impl<BidiIter>> const & impl,Traits const & tr)35 void static_compile_impl2(Xpr const &xpr, shared_ptr<regex_impl<BidiIter> > const &impl, Traits const &tr) 36 { 37 typedef typename iterator_value<BidiIter>::type char_type; 38 impl->tracking_clear(); 39 impl->traits_ = new traits_holder<Traits>(tr); 40 41 // "compile" the regex and wrap it in an xpression_adaptor. 42 typedef xpression_visitor<BidiIter, mpl::false_, Traits> visitor_type; 43 visitor_type visitor(tr, impl); 44 intrusive_ptr<matchable_ex<BidiIter> const> adxpr = make_adaptor<matchable_ex<BidiIter> >( 45 typename Grammar<char_type>::template impl<Xpr const &, end_xpression, visitor_type &>()( 46 xpr 47 , end_xpression() 48 , visitor 49 ) 50 ); 51 52 // Link and optimize the regex 53 common_compile(adxpr, *impl, visitor.traits()); 54 55 // References changed, update dependencies. 56 impl->tracking_update(); 57 } 58 59 /////////////////////////////////////////////////////////////////////////////// 60 // pattern for imbued regexes. 61 struct XpressiveLocaleModifier 62 : proto::binary_expr< 63 modifier_tag 64 , proto::terminal<locale_modifier<proto::_> > 65 , proto::_ 66 > 67 {}; 68 69 /////////////////////////////////////////////////////////////////////////////// 70 // static_compile_impl1 71 template<typename Xpr, typename BidiIter> 72 typename disable_if<proto::matches<Xpr, XpressiveLocaleModifier> >::type static_compile_impl1(Xpr const & xpr,shared_ptr<regex_impl<BidiIter>> const & impl)73 static_compile_impl1(Xpr const &xpr, shared_ptr<regex_impl<BidiIter> > const &impl) 74 { 75 // use default traits 76 typedef typename iterator_value<BidiIter>::type char_type; 77 typedef typename default_regex_traits<char_type>::type traits_type; 78 traits_type tr; 79 static_compile_impl2(xpr, impl, tr); 80 } 81 82 /////////////////////////////////////////////////////////////////////////////// 83 // static_compile_impl1 84 template<typename Xpr, typename BidiIter> 85 typename enable_if<proto::matches<Xpr, XpressiveLocaleModifier> >::type static_compile_impl1(Xpr const & xpr,shared_ptr<regex_impl<BidiIter>> const & impl)86 static_compile_impl1(Xpr const &xpr, shared_ptr<regex_impl<BidiIter> > const &impl) 87 { 88 // use specified traits 89 typedef typename proto::result_of::value<typename proto::result_of::left<Xpr>::type>::type::locale_type locale_type; 90 typedef typename regex_traits_type<locale_type, BidiIter>::type traits_type; 91 static_compile_impl2(proto::right(xpr), impl, traits_type(proto::value(proto::left(xpr)).getloc())); 92 } 93 94 /////////////////////////////////////////////////////////////////////////////// 95 // static_compile 96 template<typename Xpr, typename BidiIter> static_compile(Xpr const & xpr,shared_ptr<regex_impl<BidiIter>> const & impl)97 void static_compile(Xpr const &xpr, shared_ptr<regex_impl<BidiIter> > const &impl) 98 { 99 static_compile_impl1(xpr, impl); 100 } 101 102 }}} // namespace boost::xpressive::detail 103 104 #endif 105