<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">I just wanted to say that it would be really amazing if HTML output knew how to show the macros properly (I guess it might be less critical for plists, as Artem says).<div class="">This is definitely one of my top complaints about HTML reports; I’ve tried working on it at the past, but other work took priority.</div><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Aug 17, 2018, at 4:55 PM, Artem Dergachev via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" class="">
<div text="#000000" bgcolor="#FFFFFF" class="">
I guess nobody did this before because plists were supposed to be
used by IDEs, and IDEs were supposed to have their own
jump-to-definition functionality (in this case, macro definition).<br class="">
<br class="">
I don't know that much about macros and source locations, but i
suspect it should indeed be possible to obtain the expanded text by
traversing spelling and expansion locations, though probably
sometimes scanning token-by-token is inevitable. To state the
obvious, there are a lot of useful methods in the SourceManager, but
it's often unobvious how to combine them correctly :/<br class="">
<br class="">
<div class="moz-cite-prefix">On 8/17/18 5:09 AM, Kristóf Umann via
cfe-dev wrote:<br class="">
</div>
<blockquote type="cite" cite="mid:CAGcXOD49+ZQs910PPbA6mqtKn3t_EA3=MURC6tLf6gNbj_LseQ@mail.gmail.com" class="">
<meta http-equiv="content-type" content="text/html; charset=UTF-8" class="">
<div dir="ltr" class="">
<div class="">Hi!<br class="">
<br class="">
I'm currently trying to implement a new node in the plist
output that would show the expansion of a macro, like this:<br class="">
<br class="">
<span style="font-family:monospace,monospace" class="">void
setToNull(int **vptr) {</span><br class="">
<span style="font-family:monospace,monospace" class=""> *vptr =
nullptr;</span><br class="">
<span style="font-family:monospace,monospace" class="">}</span><br class="">
<span style="font-family:monospace,monospace" class=""><br class="">
</span></div>
<span style="font-family:monospace,monospace" class="">void print(void*);</span><br class="">
<div class=""><br class="">
<span style="font-family:monospace,monospace" class=""></span><span style="font-family:monospace,monospace" class="">#define TO_NULL(x) \<br class="">
</span><span style="font-family:monospace,monospace" class="">
setToNull(x)<br class="">
</span><span style="font-family:monospace,monospace" class=""><br class="">
</span><span style="font-family:monospace,monospace" class="">#define
DOES_NOTHING(x) \</span><br class="">
<span style="font-family:monospace,monospace" class="">
{ \</span><br class="">
<span style="font-family:monospace,monospace" class=""> int
b; \</span><br class="">
<span style="font-family:monospace,monospace" class=""> b =
5; \</span><br class="">
<span style="font-family:monospace,monospace" class="">
} \</span><br class="">
<span style="font-family:monospace,monospace" class=""> print(x)</span><br class="">
<span style="font-family:monospace,monospace" class=""></span><br class="">
<span style="font-family:monospace,monospace" class="">#define
DEREF(x) \</span><br class="">
<span style="font-family:monospace,monospace" class="">
DOES_NOTHING(x); \</span><br class="">
<span style="font-family:monospace,monospace" class=""> *x</span><br class="">
<span style="font-family:monospace,monospace" class=""></span><br class="">
<span style="font-family:monospace,monospace" class="">void f() {</span><br class="">
<span style="font-family:monospace,monospace" class=""> int *a = new
int(5);</span><br class="">
<span style="font-family:monospace,monospace" class="">
TO_NULL(&a);</span><br class="">
<span style="font-family:monospace,monospace" class=""> DEREF(a) = 5;</span><br class="">
<span style="font-family:monospace,monospace" class="">}</span><br class="">
<br class="">
For this code, two <span style="font-family:monospace,monospace" class="">PathDiagnosticMacroPiece</span>s
should be generated, and a message like this should be
displayed:<span style="font-family:monospace,monospace" class=""></span><br class="">
<span style="font-family:monospace,monospace" class=""> Expanding
macro 'TO_NULL' to 'print(&a); setToNull(&a)'</span><br class="">
<span style="font-family:monospace,monospace" class=""> Expanding
macro 'DEREF' to '{ int sajt; sajt = 5; } print(a); *a'</span><br class="">
I've made some progress on this issue, but here are the
problems I faced.<br class="">
<br class="">
Currently, HTML file generation supports macro expansions
fairly well, however, the code that achieves this seems to be
held together by sheer luck:<br class="">
<a href="https://clang.llvm.org/doxygen/namespaceclang_1_1html.html#a3283736376c3e436ff65975acdb1d399" target="_blank" moz-do-not-send="true" class="">https://clang.llvm.org/doxygen/namespaceclang_1_1html.html#a3283736376c3e436ff65975acdb1d399</a><br class="">
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 class="">
<br class="">
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 class="">
<div class="">
<div style="margin-left:40px" class=""><br class="">
</div>
Do you know any way of obtaining the expansion of a macro
expression that doesn't involve such <span class=" gmail-m_5067136254874769323gmail-yZ8quc gmail-m_5067136254874769323gmail-ILfuVd
">abusement</span>
of the preprocessor? Something like this would be ideal:<br class="">
<span style="font-family:monospace,monospace" class=""></span><br class="">
<span style="font-family:monospace,monospace" class=""></span><span style="font-family:monospace,monospace" class="">SourceLocation Loc
= /* PathDiagnosticMacroPiece location */;</span><br class="">
<span style="font-family:monospace,monospace" class=""></span><span style="font-family:monospace,monospace" class="">Preproc.getMacroExpansionForExpression(Loc));</span><br class="">
<br class="">
Cheers,<br class="">
Kristóf</div>
</div>
</div>
<br class="">
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
cfe-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a>
</pre>
</blockquote>
<br class="">
</div>
_______________________________________________<br class="">cfe-dev mailing list<br class=""><a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev<br class=""></div></blockquote></div><br class=""></div></body></html>