Boost logo

Boost-Commit :

From: eric_at_[hidden]
Date: 2008-02-09 15:32:28


Author: eric_niebler
Date: 2008-02-09 15:32:27 EST (Sat, 09 Feb 2008)
New Revision: 43199
URL: http://svn.boost.org/trac/boost/changeset/43199

Log:
more doxygen comments, const-correctness tweak for fusion::at() on proto expression
Text files modified:
   trunk/boost/xpressive/proto/eval.hpp | 4
   trunk/boost/xpressive/proto/fusion.hpp | 16 ++
   trunk/boost/xpressive/proto/matches.hpp | 216 ++++++++++++++++++++++++++++++++++++---
   trunk/boost/xpressive/proto/proto.hpp | 1
   trunk/boost/xpressive/proto/transform/fold.hpp | 12 +-
   5 files changed, 220 insertions(+), 29 deletions(-)

Modified: trunk/boost/xpressive/proto/eval.hpp
==============================================================================
--- trunk/boost/xpressive/proto/eval.hpp (original)
+++ trunk/boost/xpressive/proto/eval.hpp 2008-02-09 15:32:27 EST (Sat, 09 Feb 2008)
@@ -58,8 +58,8 @@
 
             /// \brief Evaluate a given Proto expression with a given
             /// context.
- /// \param The Proto expression to evaluate
- /// \param The context in which the expression should be
+ /// \param expr The Proto expression to evaluate
+ /// \param context The context in which the expression should be
             /// evaluated.
             /// \return <tt>typename Context::template eval<Expr>()(expr, context)</tt>
             template<typename Expr, typename Context>

Modified: trunk/boost/xpressive/proto/fusion.hpp
==============================================================================
--- trunk/boost/xpressive/proto/fusion.hpp (original)
+++ trunk/boost/xpressive/proto/fusion.hpp 2008-02-09 15:32:27 EST (Sat, 09 Feb 2008)
@@ -554,6 +554,22 @@
                     typename proto::result_of::arg_c<
                         Sequence
                       , Index::value
+ >::reference
+ type;
+
+ static type call(Sequence &seq)
+ {
+ return proto::arg_c<Index::value>(seq);
+ }
+ };
+
+ template<typename Sequence, typename Index>
+ struct apply<Sequence const, Index>
+ {
+ typedef
+ typename proto::result_of::arg_c<
+ Sequence
+ , Index::value
>::const_reference
                 type;
 

Modified: trunk/boost/xpressive/proto/matches.hpp
==============================================================================
--- trunk/boost/xpressive/proto/matches.hpp (original)
+++ trunk/boost/xpressive/proto/matches.hpp 2008-02-09 15:32:27 EST (Sat, 09 Feb 2008)
@@ -363,7 +363,7 @@
             template<typename Expr, typename If, typename Then, typename Else>
             struct matches_<Expr, proto::if_<If, Then, Else> >
               : mpl::eval_if<
- typename when<_, If>::template result<void(Expr, mpl::void_, mpl::void_)>::type
+ typename when<_, If>::template result<void(Expr, int, int)>::type
                   , matches_<Expr, typename Then::proto_base_expr>
                   , matches_<Expr, typename Else::proto_base_expr>
>::type
@@ -371,7 +371,7 @@
 
             template<typename Expr, typename If>
             struct matches_<Expr, proto::if_<If> >
- : when<_, If>::template result<void(Expr, mpl::void_, mpl::void_)>::type
+ : when<_, If>::template result<void(Expr, int, int)>::type
             {};
 
             // handle proto::not_
@@ -417,14 +417,12 @@
             /// matches some \c Bx for \c x in <tt>[0,n)</tt>.
             /// \li An expression \c E matches <tt>and_\<B0,B1,...Bn\></tt> if \c E
             /// matches all \c Bx for \c x in <tt>[0,n)</tt>.
- /// \li An expression \c E matches <tt>if_\<T\></tt> if
- /// <tt>when\<_,T\>::result\<void(E,int,int)\>::type::value</tt>
- /// is \c true.
             /// \li An expression \c E matches <tt>if_\<T,U,V\></tt> if
- /// <tt>when\<_,T\>::result\<void(E,int,int)\>::type::value</tt>
- /// is \c true and \E matches \c U; or, if
- /// <tt>when\<_,T\>::result\<void(E,int,int)\>::type::value</tt>
- /// is \c false and \E matches \c V.
+ /// <tt>when\<_,T\>::::result\<void(E,int,int)\>::::type::value</tt>
+ /// is \c true and \c E matches \c U; or, if
+ /// <tt>when\<_,T\>::::result\<void(E,int,int)\>::::type::value</tt>
+ /// is \c false and \c E matches \c V. (Note: \c U defaults to \c _
+ /// and \c V defaults to \c not\<_\>.)
             /// \li An expression \c E matches <tt>not_\<T\></tt> if \c E does
             /// not match \c T.
             /// \li An expression \c E matches <tt>switch_\<C\></tt> if
@@ -440,7 +438,7 @@
             /// \li \c A is <tt>B const &</tt>
             /// \li \c B is <tt>exact\<A\></tt>
             /// \li \c B is <tt>convertible_to\<X\></tt> and
- /// <tt>is_convertible\<A,X\>::value</tt> is \c true.
+ /// <tt>is_convertible\<A,X\>::::value</tt> is \c true.
             /// \li \c A is <tt>X[M]</tt> or <tt>X(&)[M]</tt> and
             /// \c B is <tt>X[proto::N]</tt>.
             /// \li \c A is <tt>X(&)[M]</tt> and \c B is <tt>X(&)[proto::N]</tt>.
@@ -467,6 +465,47 @@
 
         namespace wildcardns_
         {
+ /// \brief A wildcard grammar element that matches any expression,
+ /// and a transform that returns the current expression unchanged.
+ ///
+ /// The wildcard type, \c _, is a grammar element such that
+ /// <tt>matches\<E,_\>::::value</tt> is \c true for any expression
+ /// type \c E.
+ ///
+ /// The wildcard can also be used as a stand-in for a template
+ /// argument when matching terminals. For instance, the following
+ /// is a grammar that will match any <tt>std::complex\<\></tt>
+ /// terminal:
+ ///
+ /// \code
+ /// BOOST_MPL_ASSERT((
+ /// matches<
+ /// terminal<std::complex<double> >::type
+ /// , terminal<std::complex< _ > >
+ /// >
+ /// ));
+ /// \endcode
+ ///
+ /// When used as a transform, \c _ returns the current expression
+ /// unchanged. For instance, in the following, \c _ is used with
+ /// the \c fold\<\> transform to fold the children of a node:
+ ///
+ /// \code
+ /// struct CountChildren
+ /// : or_<
+ /// // Terminals have no children
+ /// when<terminal<_>, mpl::int_<0>()>
+ /// // Use fold<> to count the children of non-terminals
+ /// , otherwise<
+ /// fold<
+ /// _ // <-- fold the current expression
+ /// , mpl::int_<0>()
+ /// , mpl::plus<_state, mpl::int_<1> >()
+ /// >
+ /// >
+ /// >
+ /// {};
+ /// \endcode
             struct _ : proto::callable
             {
                 typedef _ proto_base_expr;
@@ -481,7 +520,7 @@
                 };
 
                 /// \param expr An expression
- /// \return expr
+ /// \return \c expr
                 template<typename Expr, typename State, typename Visitor>
                 Expr const &operator ()(Expr const &expr, State const &, Visitor &) const
                 {
@@ -492,7 +531,13 @@
 
         namespace control
         {
- // not_
+ /// \brief Inverts the set of expressions matched by a grammar. When
+ /// used as a transform, \c not_\<\> returns the current expression
+ /// unchanged.
+ ///
+ /// If an expression type \c E does not match a grammar \c G, then
+ /// \c E \e does match <tt>not_\<G\></tt>. For example,
+ /// <tt>not_\<terminal\<_\> \></tt> will match any non-terminal.
             template<typename Grammar>
             struct not_ : proto::callable
             {
@@ -508,7 +553,8 @@
                 };
 
                 /// \param expr An expression
- /// \return expr
+ /// \pre <tt>matches\<Expr,not_\>::::value</tt> is \c true.
+ /// \return \c expr
                 template<typename Expr, typename State, typename Visitor>
                 Expr const &operator ()(Expr const &expr, State const &, Visitor &) const
                 {
@@ -516,7 +562,56 @@
                 }
             };
 
- // if_
+ /// \brief Used to select one grammar or another based on the result
+ /// of a compile-time Boolean. When used as a transform, \c if_\<\>
+ /// selects between two transforms based on a compile-time Boolean.
+ ///
+ /// When <tt>if_\<If,Then,Else\></tt> is used as a grammar, \c If
+ /// must be a Proto transform and \c Then and \c Else must be grammars.
+ /// An expression type \c E matches <tt>if_\<If,Then,Else\></tt> if
+ /// <tt>when\<_,If\>::::result\<void(E,int,int)\>::::type::value</tt>
+ /// is \c true and \c E matches \c U; or, if
+ /// <tt>when\<_,If\>::::result\<void(E,int,int)\>::::type::value</tt>
+ /// is \c false and \c E matches \c V.
+ ///
+ /// The template parameter \c Then defaults to \c _
+ /// and \c Else defaults to \c not\<_\>, so an expression type \c E
+ /// will match <tt>if_\<If\></tt> if and only if
+ /// <tt>when\<_,If\>::::result\<void(E,int,int)\>::::type::value</tt>
+ /// is \c true.
+ ///
+ /// \code
+ /// // A grammar that only matches integral terminals,
+ /// // using is_integral<> from Boost.Type_traits.
+ /// struct IsIntegral
+ /// : and_<
+ /// terminal<_>
+ /// , if_< is_integral<_arg>() >
+ /// >
+ /// {};
+ /// \endcode
+ ///
+ /// When <tt>if_\<If,Then,Else\></tt> is used as a transform, \c If,
+ /// \c Then and \c Else must be Proto transforms. When applying
+ /// the transform to an expression \c E, state \c S and visitor \c V,
+ /// if <tt>when\<_,If\>::::result\<void(E,S,V)\>::::type::value</tt>
+ /// is \c true then the \c Then transform is applied; otherwise
+ /// the \c Else transform is applied.
+ ///
+ /// \code
+ /// // Match a terminal. If the terminal is integral, return
+ /// // mpl::true_; otherwise, return mpl::false_.
+ /// struct IsIntegral2
+ /// : when<
+ /// terminal<_>
+ /// , if_<
+ /// is_integral<_arg>()
+ /// , mpl::true_()
+ /// , mpl::false_()
+ /// >
+ /// >
+ /// {};
+ /// \endcode
             template<typename If, typename Then, typename Else>
             struct if_ : proto::callable
             {
@@ -546,7 +641,7 @@
                 /// \param expr An expression
                 /// \param state The current state
                 /// \param visitor A visitor of arbitrary type
- /// \return <tt>result\<void(Expr, State, Visitor)\>::which()(expr, state, visitor)</tt>
+ /// \return <tt>result\<void(Expr, State, Visitor)\>::::which()(expr, state, visitor)</tt>
                 template<typename Expr, typename State, typename Visitor>
                 typename result<void(Expr, State, Visitor)>::type
                 operator ()(Expr const &expr, State const &state, Visitor &visitor) const
@@ -559,7 +654,18 @@
                 }
             };
 
- // or_
+ /// \brief For matching one of a set of alternate grammars. Alternates
+ /// tried in order to avoid ambiguity. When used as a transform, \c or_\<\>
+ /// applies the transform associated with the first grammar that matches
+ /// the expression.
+ ///
+ /// An expression type \c E matches <tt>or_\<B0,B1,...Bn\></tt> if \c E
+ /// matches any \c Bx for \c x in <tt>[0,n)</tt>.
+ ///
+ /// When applying <tt>or_\<B0,B1,...Bn\></tt> as a transform with an
+ /// expression \c e of type \c E, state \c s and visitor \c v, it is
+ /// equivalent to <tt>Bx()(e, s, v)</tt>, where \c x is the lowest
+ /// number such that <tt>matches\<E,Bx\>::::value</tt> is \c true.
             template<BOOST_PP_ENUM_PARAMS(BOOST_PROTO_MAX_LOGICAL_ARITY, typename G)>
             struct or_ : proto::callable
             {
@@ -578,7 +684,8 @@
                 /// \param expr An expression
                 /// \param state The current state
                 /// \param visitor A visitor of arbitrary type
- /// \return <tt>result\<void(Expr, State, Visitor)\>::which()(expr, state, visitor)</tt>
+ /// \pre <tt>matches\<Expr,or_\>::::value</tt> is \c true.
+ /// \return <tt>result\<void(Expr, State, Visitor)\>::::which()(expr, state, visitor)</tt>
                 template<typename Expr, typename State, typename Visitor>
                 typename result<void(Expr, State, Visitor)>::type
                 operator ()(Expr const &expr, State const &state, Visitor &visitor) const
@@ -588,7 +695,16 @@
                 }
             };
 
- // and_
+ /// \brief For matching all of a set of grammars. When used as a
+ /// transform, \c and_\<\> applies the transform associated with
+ /// the last grammar in the set.
+ ///
+ /// An expression type \c E matches <tt>and_\<B0,B1,...Bn\></tt> if \c E
+ /// matches all \c Bx for \c x in <tt>[0,n)</tt>.
+ ///
+ /// When applying <tt>and_\<B0,B1,...Bn\></tt> as a transform with an
+ /// expression \c e, state \c s and visitor \c v, it is
+ /// equivalent to <tt>Bn()(e, s, v)</tt>.
             template<BOOST_PP_ENUM_PARAMS(BOOST_PROTO_MAX_LOGICAL_ARITY, typename G)>
             struct and_ : proto::callable
             {
@@ -607,7 +723,8 @@
                 /// \param expr An expression
                 /// \param state The current state
                 /// \param visitor A visitor of arbitrary type
- /// \return <tt>result\<void(Expr, State, Visitor)\>::which()(expr, state, visitor)</tt>
+ /// \pre <tt>matches\<Expr,and_\>::::value</tt> is \c true.
+ /// \return <tt>result\<void(Expr, State, Visitor)\>::::which()(expr, state, visitor)</tt>
                 template<typename Expr, typename State, typename Visitor>
                 typename result<void(Expr, State, Visitor)>::type
                 operator ()(Expr const &expr, State const &state, Visitor &visitor) const
@@ -617,7 +734,22 @@
                 }
             };
 
- // switch_
+ /// \brief For matching one of a set of alternate grammars, which
+ /// are looked up based on an expression's tag type. When used as a
+ /// transform, \c switch_\<\> applies the transform associated with
+ /// the grammar that matches the expression.
+ ///
+ /// \note \c switch_\<\> is functionally identical to \c or_\<\> but
+ /// is often more efficient. It does a fast, O(1) lookup based on an
+ /// expression's tag type to find a sub-grammar that may potentially
+ /// match the expression.
+ ///
+ /// An expression type \c E matches <tt>switch_\<C\></tt> if \c E
+ /// matches <tt>C::case_\<E::proto_tag\></tt>.
+ ///
+ /// When applying <tt>switch_\<C\></tt> as a transform with an
+ /// expression \c e of type \c E, state \c s and visitor \c v, it is
+ /// equivalent to <tt>C::case_\<E::proto_tag\>()(e, s, v)</tt>.
             template<typename Cases>
             struct switch_ : proto::callable
             {
@@ -636,7 +768,8 @@
                 /// \param expr An expression
                 /// \param state The current state
                 /// \param visitor A visitor of arbitrary type
- /// \return <tt>result\<void(Expr, State, Visitor)\>::which()(expr, state, visitor)</tt>
+ /// \pre <tt>matches\<Expr,switch_\>::::value</tt> is \c true.
+ /// \return <tt>result\<void(Expr, State, Visitor)\>::::which()(expr, state, visitor)</tt>
                 template<typename Expr, typename State, typename Visitor>
                 typename result<void(Expr, State, Visitor)>::type
                 operator ()(Expr const &expr, State const &state, Visitor &visitor) const
@@ -646,14 +779,55 @@
                 }
             };
 
+ /// \brief For forcing exact matches of terminal types.
+ ///
+ /// By default, matching terminals ignores references and
+ /// cv-qualifiers. For instance, a terminal expression of
+ /// type <tt>terminal\<int const &\>::::type</tt> will match
+ /// the grammar <tt>terminal\<int\></tt>. If that is not
+ /// desired, you can force an exact match with
+ /// <tt>terminal\<exact\<int\> \></tt>. This will only
+ /// match integer terminals where the terminal is held by
+ /// value.
             template<typename T>
             struct exact
             {};
 
+ /// \brief For matching terminals that are convertible to
+ /// a type.
+ ///
+ /// Use \c convertible_to\<\> to match a terminal that is
+ /// convertible to some type. For example, the grammar
+ /// <tt>terminal\<convertible_to\<int\> \></tt> will match
+ /// any terminal whose argument is convertible to an integer.
+ ///
+ /// \note The trait \c is_convertible\<\> from Boost.Type_traits
+ /// is used to determinal convertibility.
             template<typename T>
             struct convertible_to
             {};
 
+ /// \brief For matching a Grammar to a variable number of
+ /// sub-expressions.
+ ///
+ /// An expression type <tt>expr\<AT, argsN\<A0,...An,U0,...Um\> \></tt>
+ /// matches a grammar <tt>expr\<BT, argsM\<B0,...Bn,vararg\<V\> \> \></tt>
+ /// if \c BT is \c _ or \c AT, and if \c Ax matches \c Bx
+ /// for each \c x in <tt>[0,n)</tt> and if \c Ux matches \c V
+ /// for each \c x in <tt>[0,m)</tt>.
+ ///
+ /// For example:
+ ///
+ /// \code
+ /// // Match any function call expression, irregardless
+ /// // of the number of function arguments:
+ /// struct Function
+ /// : function< vararg<_> >
+ /// {};
+ /// \endcode
+ ///
+ /// When used as a transform, <tt>vararg\<G\></tt> applies
+ /// <tt>G</tt>'s transform.
             template<typename Grammar>
             struct vararg
               : Grammar

Modified: trunk/boost/xpressive/proto/proto.hpp
==============================================================================
--- trunk/boost/xpressive/proto/proto.hpp (original)
+++ trunk/boost/xpressive/proto/proto.hpp 2008-02-09 15:32:27 EST (Sat, 09 Feb 2008)
@@ -18,6 +18,7 @@
 #include <boost/xpressive/proto/expr.hpp>
 #include <boost/xpressive/proto/traits.hpp>
 #include <boost/xpressive/proto/domain.hpp>
+#include <boost/xpressive/proto/fusion.hpp>
 #include <boost/xpressive/proto/matches.hpp>
 #include <boost/xpressive/proto/extends.hpp>
 #include <boost/xpressive/proto/literal.hpp>

Modified: trunk/boost/xpressive/proto/transform/fold.hpp
==============================================================================
--- trunk/boost/xpressive/proto/transform/fold.hpp (original)
+++ trunk/boost/xpressive/proto/transform/fold.hpp 2008-02-09 15:32:27 EST (Sat, 09 Feb 2008)
@@ -200,9 +200,9 @@
               : fold<_reverse(Sequence), State, Fun>
             {};
 
- /// This specialization is only for improved compile-time performance
- /// in the commom case when the Sequence transform is \c proto::_.
- ///
+ // This specialization is only for improved compile-time performance
+ // in the commom case when the Sequence transform is \c proto::_.
+ //
             /// INTERNAL ONLY
             ///
             template<typename State0, typename Fun>
@@ -245,9 +245,9 @@
                 }
             };
 
- /// This specialization is only for improved compile-time performance
- /// in the commom case when the Sequence transform is \c proto::_.
- ///
+ // This specialization is only for improved compile-time performance
+ // in the commom case when the Sequence transform is \c proto::_.
+ //
             /// INTERNAL ONLY
             ///
             template<typename State0, typename Fun>


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