Re: [proto] Adding stuff in proto operator

2010-12-29 Thread Joel Falcou

OK, small road bump.

I tried a simple grammar as geenrator thingy but using the idea that i 
didnt wanted to replicate all possible generator out there.

So i made a template grammar taking a Generator and doing thing around:

struct print_tag : proto::callable
{
  typedef void result_type;
  templateclass X void operator()(X const) const
  {
std::cout  typeid(typename proto::tag_ofX::type).name()  \n;
  }
};

templateclass Generator
struct  debug_generator
  : proto::when  proto::_
, proto::and_  print_tag(proto::_)
  , Generator(proto::_)

 {};

I then took the Calc2 example and changed the calculator_domain to be :

struct calculator_domain
  : 
proto::domaindebug_generatorproto::generatorcalculator_expression  

{};

Boost version is 1.45
The full modified code is : http://codepad.org/41nnNNwf
Alas, I got a lump of errors as specified here : http://codepad.org/4hnylfvQ

Am I missing something or is the and_ not working like I thougt it was 
as a transform.

___
proto mailing list
proto@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/proto


Re: [proto] Adding stuff in proto operator

2010-12-29 Thread Joel Falcou

Error found.

The problem was in the and_impl transform. It uses comma operator to 
chain calls to each and_ alternatives.
However, when this is used in a grammar used as a Generator, it enters a 
subtle infinite loop as each comma

want to build an expression with the newly generated expression.

I locally modified proto this way in boost/proto/matches.hpp :

templateBOOST_PP_ENUM_PARAMS(N, typename G), typename Expr, typename 
State, typename Data

struct _and_implproto::and_BOOST_PP_ENUM_PARAMS(N, G), Expr, State, Data
 : proto::transform_implExpr, State, Data
{
  #define M0(Z, N, 
DATA)\
  
typedef   
\
  typename proto::whenproto::_, BOOST_PP_CAT(G, 
N)\
  ::template implExpr, State, 
Data\
  BOOST_PP_CAT(Gimpl, 
N);   \

  /**/
  BOOST_PP_REPEAT(N, M0, ~)

  typedef typename BOOST_PP_CAT(Gimpl, BOOST_PP_DEC(N))::result_type 
result_type;


  result_type operator()(
  typename _and_impl::expr_param e
, typename _and_impl::state_param s
, typename _and_impl::data_param d
  ) const
  {
   // Fix: jfalcou - 12/29/2010
   // This allow and_ to be used in grammar used as generator
   // by not using comma which caused an infinite loop

  #define M1(Z,N,DATA) \
  BOOST_PP_CAT(Gimpl,N)()(e,s,d);\
  /**/

// expands to G0()(e,s,d); G1()(e,s,d); ... G{N-1}()(e,s,d);
BOOST_PP_REPEAT(BOOST_PP_DEC(N),M1,~)
return BOOST_PP_CAT(Gimpl,BOOST_PP_DEC(N))()(e,s,d);
  }

  #undef M1
  #undef M0
};

instead of using comma, I just generate N-1 application of GimplN and 
return the last Gimpl call.


Is this fix acceptable or am I doing something wrong all together ?
If yes, Eric, any objections that I merge this into trunk ?

___
proto mailing list
proto@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/proto


Re: [proto] Adding stuff in proto operator

2010-12-29 Thread Eric Niebler
On 12/29/2010 5:40 AM, Joel Falcou wrote:
 Error found.
 
 The problem was in the and_impl transform. It uses comma operator to
 chain calls to each and_ alternatives.
 However, when this is used in a grammar used as a Generator, it enters a
 subtle infinite loop as each comma
 want to build an expression with the newly generated expression.
snip

The problem is that in this expression, Proto's overloaded comma
operator is considered. It shouldn't be. I was being a little too cute
when I used the comma operator like this.

 Is this fix acceptable or am I doing something wrong all together ?
 If yes, Eric, any objections that I merge this into trunk ?

I made a few adjustments and committed it myself. Thanks, Joel!

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com
___
proto mailing list
proto@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/proto