<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Hi</p>
<p>I was also taking the HTMLRewrite code as base for expanding
macros. Maybe this is helping you as additional data point for
achieving what you want.
lists.llvm.org/pipermail/cfe-dev/2018-July/058489.html</p>
<p>Unfortunately I didn't receive much feedback and couldn't solve
the issue with macro argument expansion. That issue shouldn't
affect your use-case.<br>
</p>
<p>One thing I improved on was to use a new Preprocessor instead of
reusing the existing one. This was necessary because I needed
recursion. Even though the code was indeed fragile, there don't
seem to be any API misuses and in the end it was stable for me.<br>
</p>
<p>Rafael<br>
</p>
<br>
<div class="moz-cite-prefix">On 17.08.2018 14:09, Kristóf Umann via
cfe-dev wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAGcXOD49+ZQs910PPbA6mqtKn3t_EA3=MURC6tLf6gNbj_LseQ@mail.gmail.com">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<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" moz-do-not-send="true">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>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<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>
</body>
</html>