<div dir="ltr"><div class="" itemprop="text">
<p>Hello,<br></p><p>I'm currently busy with using libclang library.</p>
<p>My goal is to parse code that contains macro with parameters and to
get the type of the macro parameters in order to make syntax coloration.</p>
<p>If we consider the following piece of code</p>
<pre style="" class=""><code><span class="">#define</span><span class=""> MACRO</span><span class="">(</span><span class="">X</span><span class="">)</span><span class=""> X
</span><span class="">typedef</span><span class=""> </span><span class="">struct</span><span class="">
</span><span class="">{</span><span class="">
</span><span class="">int</span><span class=""> a</span><span class="">;</span><span class="">
</span><span class="">}</span><span class=""> aType</span><span class="">;</span><span class="">
aType data</span><span class="">;</span><span class="">
</span><span class="">int</span><span class=""> var </span><span class="">=</span><span class=""> MACRO</span><span class="">(</span><span class="">data</span><span class="">.</span><span class="">a</span><span class="">);</span></code></pre>
<p>My goal is to be able to color the field <code>a</code> of the structure <code>aType</code> on the line <code>int var = MACRO(data.a)</code>. I.e. I would like to get the line, column and type whenever I'm getting a cursor over the field <code>a</code> of <code>data</code> variable.</p>
<p>The problem is that whenever I'm getting the cursor on the position of character <code>a</code>, its type is <code>CXCursor_MacroExpansion</code>. I've already tried to get the referenced cursor (via <code>clang_getCursorReferenced</code>) but then I'm getting a cursor type <code>CXCursor_MacroDefinition</code>.</p>
<p>I've also already tried to visit the child via <code>clang_visitChildren</code> but this returning the cursor itself as well, so it is not useful.</p>
<p>If I could get a cursor with type <code>CXCursor_MemberRefExpr</code> out of my cursor with type <code>CXCusor_MacroExtension</code> I would have what I need.</p>
<p>Does anyone have an idea how to actually get the info of expanded code iso getting <code>CXCursor_MacroExpansion</code>, whenever cursor is over a macro expansion?</p>
<p>Thanks a lot for your time and help.</p>
<p>Kind regards,</p>
<p>Laurent</p>
</div></div>