Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r60639 - trunk/boost/proto
From: eric_at_[hidden]
Date: 2010-03-16 00:55:14


Author: eric_niebler
Date: 2010-03-16 00:55:13 EDT (Tue, 16 Mar 2010)
New Revision: 60639
URL: http://svn.boost.org/trac/boost/changeset/60639

Log:
simplify and generalize display_expr
Text files modified:
   trunk/boost/proto/debug.hpp | 159 ++++++++++++++++++---------------------
   1 files changed, 73 insertions(+), 86 deletions(-)

Modified: trunk/boost/proto/debug.hpp
==============================================================================
--- trunk/boost/proto/debug.hpp (original)
+++ trunk/boost/proto/debug.hpp 2010-03-16 00:55:13 EDT (Tue, 16 Mar 2010)
@@ -11,6 +11,7 @@
 
 #include <boost/preprocessor/iteration/local.hpp>
 #include <boost/preprocessor/repetition/repeat.hpp>
+#include <boost/preprocessor/stringize.hpp>
 #include <iomanip>
 #include <iostream>
 #include <typeinfo>
@@ -25,94 +26,80 @@
 {
     namespace tag
     {
- namespace hidden_detail_
- {
- typedef char (&not_ostream)[sizeof(std::ostream)+1];
- not_ostream operator<<(std::ostream &, detail::dont_care);
-
- template<typename Tag, std::size_t S>
- struct printable_tag_
- {
- typedef char const *type;
- static type call() { return typeid(Tag).name(); }
- };
-
- template<typename Tag>
- struct printable_tag_<Tag, sizeof(std::ostream)>
- {
- typedef Tag type;
- static type call() { return Tag(); }
- };
-
- template<typename Tag>
- struct printable_tag
- : printable_tag_<Tag, sizeof(std::cout << Tag())>
- {};
- }
-
- /// INTERNAL ONLY
- template<typename Tag>
- inline typename hidden_detail_::printable_tag<Tag>::type proto_tag_name(Tag)
- {
- return hidden_detail_::printable_tag<Tag>::call();
- }
-
- #define BOOST_PROTO_DEFINE_TAG_NAME(Tag) \
+ #define BOOST_PROTO_DEFINE_TAG_INSERTION(Tag) \
         /** \brief INTERNAL ONLY */ \
- inline char const *proto_tag_name(tag::Tag) \
+ inline std::ostream &operator <<(std::ostream &sout, Tag const &) \
         { \
- return #Tag; \
+ return sout << BOOST_PP_STRINGIZE(Tag); \
         } \
         /**/
 
- BOOST_PROTO_DEFINE_TAG_NAME(terminal)
- BOOST_PROTO_DEFINE_TAG_NAME(unary_plus)
- BOOST_PROTO_DEFINE_TAG_NAME(negate)
- BOOST_PROTO_DEFINE_TAG_NAME(dereference)
- BOOST_PROTO_DEFINE_TAG_NAME(complement)
- BOOST_PROTO_DEFINE_TAG_NAME(address_of)
- BOOST_PROTO_DEFINE_TAG_NAME(logical_not)
- BOOST_PROTO_DEFINE_TAG_NAME(pre_inc)
- BOOST_PROTO_DEFINE_TAG_NAME(pre_dec)
- BOOST_PROTO_DEFINE_TAG_NAME(post_inc)
- BOOST_PROTO_DEFINE_TAG_NAME(post_dec)
- BOOST_PROTO_DEFINE_TAG_NAME(shift_left)
- BOOST_PROTO_DEFINE_TAG_NAME(shift_right)
- BOOST_PROTO_DEFINE_TAG_NAME(multiplies)
- BOOST_PROTO_DEFINE_TAG_NAME(divides)
- BOOST_PROTO_DEFINE_TAG_NAME(modulus)
- BOOST_PROTO_DEFINE_TAG_NAME(plus)
- BOOST_PROTO_DEFINE_TAG_NAME(minus)
- BOOST_PROTO_DEFINE_TAG_NAME(less)
- BOOST_PROTO_DEFINE_TAG_NAME(greater)
- BOOST_PROTO_DEFINE_TAG_NAME(less_equal)
- BOOST_PROTO_DEFINE_TAG_NAME(greater_equal)
- BOOST_PROTO_DEFINE_TAG_NAME(equal_to)
- BOOST_PROTO_DEFINE_TAG_NAME(not_equal_to)
- BOOST_PROTO_DEFINE_TAG_NAME(logical_or)
- BOOST_PROTO_DEFINE_TAG_NAME(logical_and)
- BOOST_PROTO_DEFINE_TAG_NAME(bitwise_and)
- BOOST_PROTO_DEFINE_TAG_NAME(bitwise_or)
- BOOST_PROTO_DEFINE_TAG_NAME(bitwise_xor)
- BOOST_PROTO_DEFINE_TAG_NAME(comma)
- BOOST_PROTO_DEFINE_TAG_NAME(mem_ptr)
- BOOST_PROTO_DEFINE_TAG_NAME(assign)
- BOOST_PROTO_DEFINE_TAG_NAME(shift_left_assign)
- BOOST_PROTO_DEFINE_TAG_NAME(shift_right_assign)
- BOOST_PROTO_DEFINE_TAG_NAME(multiplies_assign)
- BOOST_PROTO_DEFINE_TAG_NAME(divides_assign)
- BOOST_PROTO_DEFINE_TAG_NAME(modulus_assign)
- BOOST_PROTO_DEFINE_TAG_NAME(plus_assign)
- BOOST_PROTO_DEFINE_TAG_NAME(minus_assign)
- BOOST_PROTO_DEFINE_TAG_NAME(bitwise_and_assign)
- BOOST_PROTO_DEFINE_TAG_NAME(bitwise_or_assign)
- BOOST_PROTO_DEFINE_TAG_NAME(bitwise_xor_assign)
- BOOST_PROTO_DEFINE_TAG_NAME(subscript)
- BOOST_PROTO_DEFINE_TAG_NAME(member)
- BOOST_PROTO_DEFINE_TAG_NAME(if_else_)
- BOOST_PROTO_DEFINE_TAG_NAME(function)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(terminal)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(unary_plus)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(negate)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(dereference)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(complement)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(address_of)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(logical_not)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(pre_inc)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(pre_dec)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(post_inc)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(post_dec)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(shift_left)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(shift_right)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(multiplies)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(divides)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(modulus)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(plus)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(minus)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(less)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(greater)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(less_equal)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(greater_equal)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(equal_to)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(not_equal_to)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(logical_or)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(logical_and)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(bitwise_and)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(bitwise_or)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(bitwise_xor)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(comma)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(mem_ptr)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(assign)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(shift_left_assign)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(shift_right_assign)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(multiplies_assign)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(divides_assign)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(modulus_assign)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(plus_assign)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(minus_assign)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(bitwise_and_assign)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(bitwise_or_assign)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(bitwise_xor_assign)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(subscript)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(member)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(if_else_)
+ BOOST_PROTO_DEFINE_TAG_INSERTION(function)
 
- #undef BOOST_PROTO_DEFINE_TAG_NAME
+ #undef BOOST_PROTO_DEFINE_TAG_INSERTION
+ }
+
+ namespace hidden_detail_
+ {
+ struct ostream_wrapper
+ {
+ ostream_wrapper(std::ostream &sout)
+ : sout_(sout)
+ {}
+
+ std::ostream &sout_;
+ };
+
+ template<typename Tag>
+ std::ostream &operator <<(ostream_wrapper sout_wrap, Tag const &)
+ {
+ return sout_wrap.sout_ << typeid(Tag).name();
+ }
     }
 
     namespace functional
@@ -142,9 +129,9 @@
             template<typename Tag, typename Args>
             void operator()(proto::expr<Tag, Args, 0> const &expr) const
             {
- using namespace tag;
+ using namespace hidden_detail_;
                 this->sout_ << std::setw(this->depth_) << (this->first_? "" : ", ")
- << proto_tag_name(Tag()) << "(" << proto::value(expr) << ")\n";
+ << Tag() << "(" << proto::value(expr) << ")\n";
                 this->first_ = false;
             }
 
@@ -157,9 +144,9 @@
             template<typename Tag, typename Args> \
             void operator()(proto::expr<Tag, Args, N> const &expr) const \
             { \
- using namespace tag; \
+ using namespace hidden_detail_; \
                 this->sout_ << std::setw(this->depth_) << (this->first_? "" : ", ") \
- << proto_tag_name(Tag()) << "(\n"; \
+ << Tag() << "(\n"; \
                 display_expr display(this->sout_, this->depth_ + 4); \
                 BOOST_PP_REPEAT(N, BOOST_PROTO_CHILD, _) \
                 this->sout_ << std::setw(this->depth_) << "" << ")\n"; \


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk