Boost C++ Libraries: Ticket #1752: Feeding new tokens to be processed from a "#pragma wave" directive https://svn.boost.org/trac10/ticket/1752 <p> While processing a custom "#pragma wave" directive using a struct derived from context_policies::default_preprocessing_hooks like in this example : </p> <pre class="wiki"> class EmptyPreprocessorHooks : public boost::wave::context_policies::default_preprocessing_hooks { public: template &lt;typename ContextT, typename ContainerT&gt; bool interpret_pragma(ContextT const &amp;ctx, ContainerT &amp;pending, typename ContextT::token_type const &amp;option, ContainerT const &amp;values, typename ContextT::token_type const &amp;pragma_token) { return true; } }; </pre><p> it is possible to feed tokens in the "pending" container, that are copied verbatim to the output. What I think it would be very interesting is that this tokens are not copied verbatim, but parsed and processed. For instance, you could add "#define" or "#include" directives and they would be processed normally. Right now they are just copied. </p> <p> Thanks. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/1752 Trac 1.4.3 Hartmut Kaiser Wed, 02 Apr 2008 12:27:03 GMT status changed https://svn.boost.org/trac10/ticket/1752#comment:1 https://svn.boost.org/trac10/ticket/1752#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> Replying to <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/1752" title="#1752: Feature Requests: Feeding new tokens to be processed from a &#34;#pragma wave&#34; directive (closed: fixed)">caminant@gmail.com</a>: </p> <blockquote class="citation"> <p> While processing a custom "#pragma wave" directive using a struct derived from context_policies::default_preprocessing_hooks like in this example : </p> </blockquote> <p> [snipped example] </p> <blockquote class="citation"> <p> it is possible to feed tokens in the "pending" container, that are copied verbatim to the output. What I think it would be very interesting is that this tokens are not copied verbatim, but parsed and processed. For instance, you could add "#define" or "#include" directives and they would be processed normally. Right now they are just copied. </p> </blockquote> <p> It's currently implemented the way it is to conform with the #define preprocessor directive for which it is undefined behaviour to generate a token sequence comprising in another preprocessor directive. </p> <p> Do you have a real use case for this functionality or is it just a 'nice to have' feature? </p> <p> Regards Hartmut </p> Ticket caminant@… Thu, 03 Apr 2008 08:35:32 GMT <link>https://svn.boost.org/trac10/ticket/1752#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1752#comment:2</guid> <description> <p> Thanks for answering so quickly. </p> <p> What we are trying to do, is to define "macros" that allow to compile a certain piece of code in a very customisable way. These "macros" define several options which are later selected by a user and imply adding some #defines or including other files that can add more options. The piece of code is going to be big, and we don't want to have it in a monolithic file full of #ifdefs. We use a tool that reads the possible options of a piece of code (from our "macros") and allows the user to change them and recompile again, getting new options, and so on. </p> <p> We cannot use preprocessor macros because of the limitation you mention. That's why we moved to wave and tried to use "#pragma wave". Right now we are doing our own parsing, combined with wave, but this implies some complicated code doing multiple passes. It would be really clean if we could use one single pass of wave. </p> <p> I understand the decission of working like a preprocessor macro for the new tokens, it makes a lot of sense. But i also thought that, not being defined in the standard, it wouldn't be difficult to allow to insert tokens that would be preprocessed. Something like putting them in the "unput" container instead of the "pending", using the names in the wave source code. </p> <p> j. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Hartmut Kaiser</dc:creator> <pubDate>Fri, 04 Apr 2008 01:36:20 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/1752#comment:3 https://svn.boost.org/trac10/ticket/1752#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Ok, I have been thinking for this for a while now and after looking at the code I realized that it isn't difficult to do the preprocessing inside the interpret_pragma hook. But while implementing this idea I stumbled over a couple of issues which had to be fixed before everything worked just fine. </p> <p> To demonstrate how this can be done with only a couple lines of code I created a new example called 'preprocess_pragma_output', which does exactly what its name says: it takes the option token sequence from a #pragma directive, concatenates everything into a single string, preprocesses this string using the current context, and returns the generated token sequence to be inserted in the output. </p> <p> Everything (the example and the fixes) are committed to the SVN(Head). Please give some feedback if this is really what you need. I'm going to close this ticket, please re-open it as needed. </p> <p> Note to self: the Wave docs have to be updated, still. </p> <p> Regards Hartmut </p> Ticket caminant@… Fri, 04 Apr 2008 12:19:03 GMT <link>https://svn.boost.org/trac10/ticket/1752#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/1752#comment:4</guid> <description> <p> Thank you very much. This will work well for our case. </p> </description> <category>Ticket</category> </item> </channel> </rss>