Boost C++ Libraries: Ticket #11327: boost::wave produces non-existent tokens https://svn.boost.org/trac10/ticket/11327 <p> Consider the following program: </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#include</span> <span class="cpf">&lt;iostream&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;string&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/wave.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/wave/cpplexer/cpp_lex_iterator.hpp&gt;</span><span class="cp"></span> <span class="k">using</span> <span class="k">namespace</span> <span class="n">boost</span><span class="o">::</span><span class="n">wave</span><span class="o">::</span><span class="n">cpplexer</span><span class="p">;</span> <span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span><span class="o">*</span> <span class="n">argv</span><span class="p">[])</span> <span class="p">{</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span> <span class="n">str</span> <span class="o">=</span> <span class="s">&quot;int a</span><span class="se">\n\n</span><span class="s">;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">;</span> <span class="k">typedef</span> <span class="n">lex_iterator</span><span class="o">&lt;</span><span class="n">lex_token</span><span class="o">&lt;&gt;</span> <span class="o">&gt;</span> <span class="n">LexIterator</span><span class="p">;</span> <span class="k">typedef</span> <span class="n">boost</span><span class="o">::</span><span class="n">wave</span><span class="o">::</span><span class="n">context</span><span class="o">&lt;</span><span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">::</span><span class="n">const_iterator</span><span class="p">,</span> <span class="n">LexIterator</span><span class="o">&gt;</span> <span class="n">WaveContext</span><span class="p">;</span> <span class="n">WaveContext</span> <span class="n">ctx</span><span class="p">(</span><span class="n">str</span><span class="p">.</span><span class="n">cbegin</span><span class="p">(),</span> <span class="n">str</span><span class="p">.</span><span class="n">cend</span><span class="p">());</span> <span class="k">for</span> <span class="p">(</span><span class="k">auto</span> <span class="nl">tok</span> <span class="p">:</span> <span class="n">ctx</span><span class="p">)</span> <span class="p">{</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">boost</span><span class="o">::</span><span class="n">wave</span><span class="o">::</span><span class="n">get_token_name</span><span class="p">(</span><span class="n">boost</span><span class="o">::</span><span class="n">wave</span><span class="o">::</span><span class="n">token_id</span><span class="p">(</span><span class="n">tok</span><span class="p">))</span> <span class="o">&lt;&lt;</span> <span class="sc">&#39;(&#39;</span> <span class="o">&lt;&lt;</span> <span class="n">tok</span><span class="p">.</span><span class="n">get_value</span><span class="p">()</span> <span class="o">&lt;&lt;</span> <span class="sc">&#39;)&#39;</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="p">}</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> <span class="p">}</span> </pre></div></div><p> It produces the following output: </p> <pre class="wiki">INT(int) SPACE( ) IDENTIFIER(a) NEWLINE( ) PP_LINE(#line) SPACE( ) INTLIT(3) SPACE( ) STRINGLIT("&lt;Unknown&gt;") NEWLINE( ) SEMICOLON(;) NEWLINE( ) EOF() </pre><p> There are no <code>PP_LINE(#line)</code>, <code>INTLIT(3)</code> and <code>STRINGLIT("&lt;Unknown&gt;")</code> in the input. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11327 Trac 1.4.3 Hartmut Kaiser Thu, 21 May 2015 01:48:18 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/11327#comment:1 https://svn.boost.org/trac10/ticket/11327#comment:1 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> This is on purpose as it reflects the token stream which would be generated by a preprocessor. If you don't want to see the #line directives generated, add: </p> <pre class="wiki"> WaveContext.set_language( boost::wave::enable_emit_line_directives( ctx.get_language(), false)); </pre><p> before iterating over the input (see here for more information: <a href="http://www.boost.org/doc/libs/1_58_0/libs/wave/doc/class_reference_context.html">http://www.boost.org/doc/libs/1_58_0/libs/wave/doc/class_reference_context.html</a>). </p> Ticket Vyacheslav Andrejev Thu, 21 May 2015 19:58:20 GMT <link>https://svn.boost.org/trac10/ticket/11327#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11327#comment:2</guid> <description> <p> Thanks! </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Vyacheslav Andrejev</dc:creator> <pubDate>Thu, 21 May 2015 22:54:17 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11327#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11327#comment:3</guid> <description> <p> Actually enable_emit_line_directives has undesired effect: the lexer not only stops producing not existing <code>#line</code>, but also removes existing. For example </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#include</span> <span class="cpf">&lt;iostream&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;string&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/wave.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/wave/cpplexer/cpp_lex_iterator.hpp&gt;</span><span class="cp"></span> <span class="k">using</span> <span class="k">namespace</span> <span class="n">boost</span><span class="o">::</span><span class="n">wave</span><span class="p">;</span> <span class="k">using</span> <span class="k">namespace</span> <span class="n">boost</span><span class="o">::</span><span class="n">wave</span><span class="o">::</span><span class="n">cpplexer</span><span class="p">;</span> <span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span><span class="o">*</span> <span class="n">argv</span><span class="p">[])</span> <span class="p">{</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span> <span class="n">str</span> <span class="o">=</span> <span class="s">&quot;int a;</span><span class="se">\n</span><span class="s">#line 10 </span><span class="se">\&quot;</span><span class="s">file.cpp</span><span class="se">\&quot;\n</span><span class="s">int b;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">;</span> <span class="k">typedef</span> <span class="n">lex_iterator</span><span class="o">&lt;</span><span class="n">lex_token</span><span class="o">&lt;&gt;</span> <span class="o">&gt;</span> <span class="n">LexIterator</span><span class="p">;</span> <span class="k">typedef</span> <span class="n">boost</span><span class="o">::</span><span class="n">wave</span><span class="o">::</span><span class="n">context</span><span class="o">&lt;</span><span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">::</span><span class="n">const_iterator</span><span class="p">,</span> <span class="n">LexIterator</span><span class="o">&gt;</span> <span class="n">WaveContext</span><span class="p">;</span> <span class="n">WaveContext</span> <span class="n">ctx</span><span class="p">(</span><span class="n">str</span><span class="p">.</span><span class="n">cbegin</span><span class="p">(),</span> <span class="n">str</span><span class="p">.</span><span class="n">cend</span><span class="p">());</span> <span class="n">ctx</span><span class="p">.</span><span class="n">set_language</span><span class="p">(</span> <span class="n">boost</span><span class="o">::</span><span class="n">wave</span><span class="o">::</span><span class="n">enable_emit_line_directives</span><span class="p">(</span> <span class="n">ctx</span><span class="p">.</span><span class="n">get_language</span><span class="p">(),</span> <span class="nb">false</span><span class="p">));</span> <span class="k">for</span> <span class="p">(</span><span class="k">auto</span> <span class="nl">tok</span> <span class="p">:</span> <span class="n">ctx</span><span class="p">)</span> <span class="p">{</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">get_token_name</span><span class="p">(</span><span class="n">token_id</span><span class="p">(</span><span class="n">tok</span><span class="p">))</span> <span class="o">&lt;&lt;</span> <span class="sc">&#39;(&#39;</span> <span class="o">&lt;&lt;</span> <span class="n">tok</span><span class="p">.</span><span class="n">get_value</span><span class="p">()</span> <span class="o">&lt;&lt;</span> <span class="sc">&#39;)&#39;</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="p">}</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> <span class="p">}</span> </pre></div></div><p> The output: </p> <pre class="wiki">INT(int) SPACE( ) IDENTIFIER(a) SEMICOLON(;) NEWLINE( ) INT(int) SPACE( ) IDENTIFIER(b) SEMICOLON(;) NEWLINE( ) EOF() </pre><p> Is there a way to leave just existing <code>#line</code>? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Hartmut Kaiser</dc:creator> <pubDate>Fri, 22 May 2015 10:00:52 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11327#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11327#comment:4</guid> <description> <p> Wave always consumes any #line directives in the input to correctly assign line numbers to the generated tokens (like it consumes all other preprocessor directives). It outputs those #line directives based on its own heuristics. There is currently no way to retain those from the input. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Vyacheslav Andrejev</dc:creator> <pubDate>Wed, 27 May 2015 21:10:40 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11327#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11327#comment:5</guid> <description> <p> It produces incorrect line numbers if a file already has #line directives. </p> </description> <category>Ticket</category> </item> </channel> </rss>