<div dir="ltr">Hi <div><br></div><div>I'm writing a clang tool and one of the things I have to do is to dump all of the attributes of functions. So for example, If I specify an attribute __attribute__((myAttribute("arg1"))), I'd like to output myAttribute("arg1")</div>
<div>There is the printPretty function of clang::Attr, but this also appends the __attribute__  (which I could chip away, but that's not a nice solution). So what I tried is to go via the source, but here I stumble over the usage of macros/preprocessor. What I tried is this: </div>
<div><br></div><div><pre style="font-family:Consolas;background-image:initial;background-repeat:initial"><font color="#0000ff">clang::SourceRange</font><span style="color:black"> <span style="color:rgb(136,0,0)">range</span> = <span style="color:rgb(33,111,133)">attr</span>-><span style="color:rgb(136,0,0)">getRange</span>();
<span style="color:rgb(33,111,133)">clang</span>::<span style="color:rgb(33,111,133)">SourceRange</span> expandedRange(<span style="color:navy">sm</span>.<span style="color:rgb(136,0,0)">getExpansionLoc</span>(<span style="color:rgb(136,0,0)">range</span>.<span style="color:rgb(136,0,0)">getBegin</span>()), <span style="color:navy">sm</span>.<span style="color:rgb(136,0,0)">getExpansionLoc</span>(<span style="color:rgb(136,0,0)">range</span>.<span style="color:rgb(136,0,0)">getEnd</span>()));
<span style="color:rgb(111,0,138)">assert</span>(expandedRange.<span style="color:rgb(136,0,0)">isValid</span>());
<span style="color:rgb(33,111,133)">std</span>::<span style="font-style:italic;color:rgb(33,111,133)">string</span> <span style="color:navy">text</span> = <span style="color:rgb(33,111,133)">clang</span>::<span style="color:rgb(33,111,133)">Lexer</span>::<span style="color:rgb(136,0,0)">getSourceText</span>(<span style="color:rgb(33,111,133)">clang</span>::<span style="color:rgb(33,111,133)">CharSourceRange</span>::<span style="color:rgb(136,0,0)">getTokenRange</span>(expandedRange), <span style="color:navy">sm</span>, <span style="color:rgb(33,111,133)">clang</span>::<span style="color:rgb(33,111,133)">LangOptions</span>(), 0);</span></pre>
<pre style="background-image:initial;background-repeat:initial"><font face="arial, helvetica, sans-serif">But if the attribute is specified by means of a preprocessor macro, I get the name of the macro and not the expanded text. </font></pre>
<pre style="background-image:initial;background-repeat:initial"><font face="arial, helvetica, sans-serif">What is the best way of getting the macro text? </font></pre><pre style="background-image:initial;background-repeat:initial">
<font face="arial, helvetica, sans-serif">Thank you</font></pre><pre style="font-family:Consolas;background-image:initial;background-repeat:initial"><br></pre><pre style="font-family:Consolas;background-image:initial;background-repeat:initial">
<br></pre><div><br></div>-- <br><div dir="ltr">Benjamin Schindler, PhD<br>Software Engineer, VirtaMed AG</div>
</div></div>