<div dir="ltr">Thank you for letting me know this API. However, I have another problem: when I have the forward declaration of vprintf (produced by the preprocessor), the clang AST will assign the type int to va_list. Is it a correct way to use prettyprint to dump code from AST?<div><br></div><div><br><div>=======================================</div><div>
<p class=""><span class="">bash-3.2$ cat t1.c </span></p>
<p class=""><span class="">int vprintf(const char * restrict, va_list) __attribute__((__format__ (__printf__, 1, 0)));</span></p>
<p class=""><span class="">bash-3.2$ clang -Xclang -ast-dump -w -fsyntax-only t1.c</span></p>
<p class=""><span class=""><b>TranslationUnitDecl</b></span><span class=""> 0x10382dcc0</span><span class=""> <</span><span class=""><invalid sloc></span><span class="">> </span><span class=""><invalid sloc></span></p>
<p class=""><span class="">|-</span><span class=""><b>TypedefDecl</b></span><span class=""> 0x10382e1c0</span><span class=""> <</span><span class=""><invalid sloc></span><span class="">> </span><span class=""><invalid sloc></span><span class=""> implicit</span><span class=""><b> __int128_t</b></span><span class=""> </span><span class="">'__int128'</span></p>
<p class=""><span class="">|-</span><span class=""><b>TypedefDecl</b></span><span class=""> 0x10382e220</span><span class=""> <</span><span class=""><invalid sloc></span><span class="">> </span><span class=""><invalid sloc></span><span class=""> implicit</span><span class=""><b> __uint128_t</b></span><span class=""> </span><span class="">'unsigned __int128'</span></p>
<p class=""><span class="">|-</span><span class=""><b>TypedefDecl</b></span><span class=""> 0x10382e5b0</span><span class=""> <</span><span class=""><invalid sloc></span><span class="">> </span><span class=""><invalid sloc></span><span class=""> implicit</span><span class=""><b> __builtin_va_list</b></span><span class=""> </span><span class="">'__va_list_tag [1]'</span></p>
<p class=""><span class="">|-</span><span class=""><b>FunctionDecl</b></span><span class=""> 0x10382e910</span><span class=""> <</span><span class="">t1.c:1:5</span><span class="">> </span><span class="">col:5</span><span class=""> implicit</span><span class=""><b> vprintf</b></span><span class=""> </span><span class="">'int (const char *, __va_list_tag *)'</span><span class=""> extern</span></p>
<p class=""><span class="">| |-</span><span class=""><b>ParmVarDecl</b></span><span class=""> 0x103871400</span><span class=""> <</span><span class=""><invalid sloc></span><span class="">> </span><span class=""><invalid sloc></span><span class=""> </span><span class="">'const char *'</span></p>
<p class=""><span class="">| |-</span><span class=""><b>ParmVarDecl</b></span><span class=""> 0x103871460</span><span class=""> <</span><span class=""><invalid sloc></span><span class="">> </span><span class=""><invalid sloc></span><span class=""> </span><span class="">'__va_list_tag *'</span></p>
<p class=""><span class="">| `-<b>FormatAttr</b></span><span class=""> 0x1038714d0</span><span class=""> <</span><span class="">col:5</span><span class="">> Implicit printf 1 0</span></p>
<p class=""><span class="">`-</span><span class=""><b>FunctionDecl</b></span><span class=""> 0x103871520</span><span class=""> prev 0x10382e910 <</span><span class="">col:1</span><span class="">, </span><span class="">col:90</span><span class="">> </span><span class="">col:5</span><span class=""><b> vprintf</b></span><span class=""> </span><span class="">'int (const char *restrict, int)'</span></p>
<p class=""><span class=""> |-</span><span class=""><b>ParmVarDecl</b></span><span class=""> 0x10382e640</span><span class=""> <</span><span class="">col:13</span><span class="">, </span><span class="">col:24</span><span class="">> </span><span class="">col:34</span><span class=""> </span><span class="">'const char *restrict'</span></p>
<p class=""><span class=""> |-</span><span class=""><b>ParmVarDecl</b></span><span class=""> 0x10382e6b0</span><span class=""> <</span><span class="">col:36</span><span class="">> </span><span class="">col:36</span><span class=""><b> va_list</b></span><span class=""> </span><span class="">'int'</span></p>
<p class=""><span class=""> `-<b>FormatAttr</b></span><span class=""> 0x1038715e0</span><span class=""> <</span><span class="">col:60</span><span class="">, </span><span class="">col:88</span><span class="">> printf 1 0</span></p></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 22, 2016 at 4:01 PM, David Majnemer <span dir="ltr"><<a href="mailto:david.majnemer@gmail.com" target="_blank">david.majnemer@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Mon, Feb 22, 2016 at 3:46 PM, Chengnian Sun via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">I want to randomly remove the variable declaration "a" or "b" from the source file. There are two ways to do this. <div> 1) I can pretty print the VarDecl of "a" and "b". However, these three builtin typedefs mentioned above make the modified source file not compilable, as the _builtin_va_list is not defined. </div></div></blockquote><div><br></div></span><div>Why not skip things marked as implicit (clang::Decl::isImplicit) ?</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class=""><div dir="ltr"><div> 2) I can use rewriter to change the source file. However, as both "a" and "b" are declared in one statement, removing either of them makes the deletion complex. </div><div><br></div><div>I think another way to do this is to separate the statement "int a, b;" into "int a; int b". Any existing functionality in clang to do this?</div><div><br></div><div>Thank you. Any advice is appreciated. </div><div><br></div><div> </div></div><div class="gmail_extra"><div><div><br><div class="gmail_quote">On Mon, Feb 22, 2016 at 3:30 PM, Meador Inge <span dir="ltr"><<a href="mailto:meadori@gmail.com" target="_blank">meadori@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><span><div class="gmail_quote">On Mon, Feb 22, 2016 at 11:15 AM, Chengnian Sun via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:</div></span><div class="gmail_quote"><span><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>Hi, </div><div><br></div><div>I found out that for the following code (only containing two variable declarations), clang will generate three internal typedef declarations. Is there any way to disable the generation of the three typedef?</div></div></blockquote><div><br></div></span><div>Not that I know of. What problem are you trying to solve by disabling them?</div><span><font color="#888888"><div><br></div><div>-- Meador</div></font></span></div>
</div></div>
</blockquote></div><br><br clear="all"><div><br></div></div></div><span>-- <br><div>Best Regards.<br><br>Chengnian SUN.</div>
</span></div>
<br></span>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Best Regards.<br><br>Chengnian SUN.</div>
</div>