<div dir="ltr"><div>Hi!<br><br>I'm currently trying to implement a new node in the plist output that would show the expansion of a macro, like this:<br><br><span style="font-family:monospace,monospace">void setToNull(int **vptr) {</span><br><span style="font-family:monospace,monospace">  *vptr = nullptr;</span><br><span style="font-family:monospace,monospace">}</span><br><span style="font-family:monospace,monospace"><br></span></div><span style="font-family:monospace,monospace">void print(void*);</span><br><div><br><span style="font-family:monospace,monospace"></span><span style="font-family:monospace,monospace">#define TO_NULL(x) \<br></span><span style="font-family:monospace,monospace">  setToNull(x)<br></span><span style="font-family:monospace,monospace"><br></span><span style="font-family:monospace,monospace">#define DOES_NOTHING(x) \</span><br><span style="font-family:monospace,monospace">  {                     \</span><br><span style="font-family:monospace,monospace">    int b;              \</span><br><span style="font-family:monospace,monospace">    b = 5;              \</span><br><span style="font-family:monospace,monospace">  }                     \</span><br><span style="font-family:monospace,monospace">  print(x)</span><br><span style="font-family:monospace,monospace"></span><br><span style="font-family:monospace,monospace">#define DEREF(x)   \</span><br><span style="font-family:monospace,monospace">  DOES_NOTHING(x); \</span><br><span style="font-family:monospace,monospace">  *x</span><br><span style="font-family:monospace,monospace"></span><br><span style="font-family:monospace,monospace">void f() {</span><br><span style="font-family:monospace,monospace">  int *a = new int(5);</span><br><span style="font-family:monospace,monospace">  TO_NULL(&a);</span><br><span style="font-family:monospace,monospace">  DEREF(a) = 5;</span><br><span style="font-family:monospace,monospace">}</span><br><br>For this code, two <span style="font-family:monospace,monospace">PathDiagnosticMacroPiece</span>s should be generated, and a message like this should be displayed:<span style="font-family:monospace,monospace"></span><br><span style="font-family:monospace,monospace">  Expanding macro 'TO_NULL' to 'print(&a); setToNull(&a)'</span><br><span style="font-family:monospace,monospace">  Expanding macro 'DEREF' to '{ int sajt; sajt = 5; } print(a); *a'</span><br>I've made some progress on this issue, but here are the problems I faced.<br><br>Currently,
 HTML file generation supports macro expansions fairly well, however, 
the code that achieves this seems to be held together by sheer luck:<br><a href="https://clang.llvm.org/doxygen/namespaceclang_1_1html.html#a3283736376c3e436ff65975acdb1d399" target="_blank">https://clang.llvm.org/doxygen/namespaceclang_1_1html.html#a3283736376c3e436ff65975acdb1d399</a><br>As
 I understand it, the entire file is re-lexed and preprocessed, during 
which macro expansions are added to the HTML file. I attempted to reuse 
the code here without having to re-lex everything, but so far my efforts
 lead to little success. I also found that any modification of this code
 quickly leads to instabilities -- although this part of Clang is 
somewhat of a mystery to me just yet, so I'd concede to this being my 
fault.<br><br>I
 also fear that since HTML output is not as used as other 
outputs, and could lack vigorous testing, it could be crash-prone.<br><div><div style="margin-left:40px"><br></div>Do you know any way of obtaining the expansion of a macro expression that doesn't involve such <span class="gmail-m_5067136254874769323gmail-ILfuVd gmail-m_5067136254874769323gmail-yZ8quc">abusement</span> of the preprocessor? Something like this would be ideal:<br><span style="font-family:monospace,monospace"></span><br><span style="font-family:monospace,monospace"></span><span style="font-family:monospace,monospace">SourceLocation Loc = /* PathDiagnosticMacroPiece location */;</span><br><span style="font-family:monospace,monospace"></span><span style="font-family:monospace,monospace">Preproc.getMacroExpansionForExpression(Loc));</span><br><br>Cheers,<br>Kristóf</div></div></div>