Update of /cvsroot/boost/boost/boost/xpressive/proto/compiler
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv21787/proto/compiler

Modified Files:
        pass_through.hpp 
Log Message:
don't recompile sub-expressions that don't need to be recompiled

Index: pass_through.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/xpressive/proto/compiler/pass_through.hpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- pass_through.hpp    7 Nov 2006 05:03:51 -0000       1.8
+++ pass_through.hpp    10 Nov 2006 02:31:22 -0000      1.9
@@ -11,14 +11,56 @@
     #ifndef BOOST_PROTO_COMPILER_PASS_THROUGH_HPP_EAN_04_23_2006
     #define BOOST_PROTO_COMPILER_PASS_THROUGH_HPP_EAN_04_23_2006
 
+    #include <boost/mpl/if.hpp>
     #include <boost/preprocessor/cat.hpp>
     #include <boost/preprocessor/enum.hpp>
     #include <boost/preprocessor/iterate.hpp>
     #include <boost/xpressive/proto/proto.hpp>
-    #include <boost/xpressive/proto/traits.hpp>
 
     namespace boost { namespace proto
     {
+        namespace meta
+        {
+            template<typename Expr, typename State, typename Visitor, typename 
DomainTag>
+            struct is_same_expr
+              : is_same<
+                    typename meta::compile<typename Expr::expr_type, State, 
Visitor, DomainTag>::type
+                  , typename Expr::expr_type
+                >
+            {};
+
+            template<typename Expr, typename State, typename Visitor, typename 
DomainTag
+                , bool IsSameExpr = is_same_expr<Expr, State, Visitor, 
DomainTag>::value
+            >
+            struct compile_if
+            {
+                typedef typename meta::compile<typename Expr::expr_type, 
State, Visitor, DomainTag>::type type;
+
+                static type call(Expr const &expr, State const &state, Visitor 
&visitor)
+                {
+                    return proto::compile(expr.cast(), state, visitor, 
DomainTag());
+                }
+            };
+
+            template<typename Expr, typename State, typename Visitor, typename 
DomainTag>
+            struct compile_if<Expr, State, Visitor, DomainTag, true>
+            {
+                typedef Expr type;
+
+                static Expr const &call(Expr const &expr, State const &, 
Visitor &)
+                {
+                    return expr;
+                }
+            };
+        }
+
+        template<typename Expr, typename State, typename Visitor, typename 
DomainTag>
+        typename meta::compile_if<Expr, State, Visitor, DomainTag>::type
+        compile_if(Expr const &expr, State const &state, Visitor &visitor, 
DomainTag)
+        {
+            return meta::compile_if<Expr, State, Visitor, 
DomainTag>::call(expr, state, visitor);
+        }
+
         template<typename DomainTag>
         struct pass_through_compiler
         {
@@ -26,10 +68,10 @@
             struct apply_impl;
 
         #define BOOST_PROTO_DEFINE_META_COMPILE(z, n, data)\
-            typename meta::compile<typename meta::arg_c<Expr, n>::type, State, 
Visitor, DomainTag>::type
+            typename meta::compile_if<typename 
BOOST_PP_CAT(BOOST_PP_CAT(Expr::arg, n), _type), State, Visitor, 
DomainTag>::type
 
         #define BOOST_PROTO_DEFINE_COMPILE(z, n, data)\
-            proto::compile(proto::arg_c<n>(expr), state, visitor, DomainTag())
+            proto::compile_if(BOOST_PP_CAT(expr.arg, n), state, visitor, 
DomainTag())
 
         #define BOOST_PP_ITERATION_PARAMS_1 (3, (1, BOOST_PROTO_MAX_ARITY, 
<boost/xpressive/proto/compiler/pass_through.hpp>))
 
@@ -79,15 +121,29 @@
                   , BOOST_PP_CAT(mpl::vector, N)<
                         BOOST_PP_ENUM(N, BOOST_PROTO_DEFINE_META_COMPILE, ~)
                     >
-                > type;
+                > expr_type;
+
+                typedef is_same<typename Expr::expr_type, expr_type> 
is_same_expr;
+                typedef typename mpl::if_<is_same_expr, Expr, expr_type>::type 
type;
 
                 static type call(Expr const &expr, State const &state, Visitor 
&visitor)
                 {
+                    return apply_impl::call_(expr, state, visitor, 
is_same_expr());
+                }
+
+            private:
+                static type call_(Expr const &expr, State const &state, 
Visitor &visitor, mpl::false_)
+                {
                     type that = {
                         BOOST_PP_ENUM(N, BOOST_PROTO_DEFINE_COMPILE, ~)
                     };
                     return that;
                 }
+
+                static type const &call_(Expr const &expr, State const &, 
Visitor &, mpl::true_)
+                {
+                    return expr;
+                }
             };
 
     #undef N


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs

Reply via email to