<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, May 10, 2016 at 6:50 AM, Mikhail Ramalho 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I almost forgot:<div><br></div><div>I know that we can get the VarDecl from the DeclRef (by using getDecl() or getFoundDecl()). What I meant by "<span style="font-size:12.8px">if I can generate the AST with the varDecls</span>" was actually an AST with the explicit VarDecls of __i0, __i1, etc.</div></div></blockquote><div><br></div><div>The VarDecls are in the AST, you can access them by calling getArrayIndices() on the CXXCtorInitializer.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Thank you, </div><div><br></div><div class="gmail_extra"><div><div class="h5"><br><div class="gmail_quote">2016-05-10 14:45 GMT+01:00 Mikhail Ramalho <span dir="ltr"><<a href="mailto:mikhail.ramalho@gmail.com" target="_blank">mikhail.ramalho@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello all,<div><br></div><div>I'm using libTooling to generate the AST of a given program (that will later be translated to our own internal AST), and I just found this odd CXXConstructorDecl for the following program:</div><div><br></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><div>class X</div></div><div><div>{</div></div><div><div>  public:</div></div><div><div>    X() {};</div></div><div><div><br></div></div><div><div>    char str[20][20][230];</div></div><div><div>};</div></div><div><div><br></div></div><div><div>int main(void)</div></div><div><div>{</div></div><div><div>  X x;</div></div><div><div>  X x1 = x;</div></div><div><div>  return 0;</div></div><div><div>}</div></div></blockquote><div><div><br></div><div>The implicit constructor for X is:</div><div><br></div><div><div>CXXConstructorDecl 0x3959fd0 <line:3:7> col:7 implicit used X 'void (const class X &) throw()' inline</div><div>|   |-ParmVarDecl 0x395a110 <col:7> col:7 used 'const class X &'</div><div>|   |-CXXCtorInitializer Field 0x3908c48 'str' 'char [20][20][230]'</div><div>|   | `-ImplicitCastExpr 0x395a6e8 <col:7> 'char' <LValueToRValue></div><div>|   |   `-ArraySubscriptExpr 0x395a6c0 <col:7> 'const char' lvalue</div><div>|   |     |-ImplicitCastExpr 0x395a6a8 <col:7> 'const char *' <ArrayToPointerDecay></div><div>|   |     | `-ArraySubscriptExpr 0x395a560 <col:7> 'char const[230]' lvalue</div><div>|   |     |   |-ImplicitCastExpr 0x395a548 <col:7> 'char const (*)[230]' <ArrayToPointerDecay></div><div>|   |     |   | `-ArraySubscriptExpr 0x395a400 <col:7> 'char const[20][230]' lvalue</div><div>|   |     |   |   |-ImplicitCastExpr 0x395a3e8 <col:7> 'char const (*)[20][230]' <ArrayToPointerDecay></div><div>|   |     |   |   | `-MemberExpr 0x395a298 <col:7> 'char const[20][20][230]' lvalue .str 0x3908c48</div><div>|   |     |   |   |   `-DeclRefExpr 0x395a270 <col:7> 'const class X' lvalue ParmVar 0x395a110 '' 'const class X &'</div><div>|   |     |   |   `-ImplicitCastExpr 0x395a368 <col:7> 'unsigned int' <LValueToRValue></div><div>|   |     |   |     `-DeclRefExpr 0x395a340 <col:7> 'unsigned int' lvalue Var 0x395a2e0 '__i0' 'unsigned int'</div><div>|   |     |   `-ImplicitCastExpr 0x395a4c0 <col:7> 'unsigned int' <LValueToRValue></div><div>|   |     |     `-DeclRefExpr 0x395a498 <col:7> 'unsigned int' lvalue Var 0x395a438 '__i1' 'unsigned int'</div><div>|   |     `-ImplicitCastExpr 0x395a620 <col:7> 'unsigned int' <LValueToRValue></div><div>|   |       `-DeclRefExpr 0x395a5f8 <col:7> 'unsigned int' lvalue Var 0x395a598 '__i2' 'unsigned int'</div><div>|   `-CompoundStmt 0x395a748 <col:7></div></div><div><br></div><div>Which should look this (I think): </div><div><br></div><div>X(const X& ref) : str(ref.str[__i0][__i1][__i2]) {}</div><div><br></div><div>Or maybe: </div><div><br></div><div>X(const X& ref) { str(ref.str[__i0][__i1][__i2]); }<br></div><div><br></div><div>(None of the above is compiled)</div><div>(If we call emit-llvm, it's translated into a memcpy)</div><div><br></div><div>Anyway, there are a few things missing on this AST, in my opinion:</div><div><br></div><div>1. No VarDecl for __i0, __i1, __i2.</div><div>2. No loop to iterate and copy the array elements (a call to memcpy would be good as well, but I don't expect that clang will generate that).</div><div><br></div><div>Does anyone knows if I can generate the AST with the varDecls and the loop? I found a method on SemaDeclCXX that seems to build a loop, it's called buildSingleCopyAssignRecursively. It's called by buildSingleCopyAssign, that even tries to build a memcpy.</div><div><br></div><div>Am I out of luck and will have to go through all the implicit generated CXXConstructorDecls and build a loop myself or is there an alternative?</div><div><br></div><div>Thank you,</div><span><font color="#888888"><div><br></div>-- <br><div><div dir="ltr"><div><br></div><div>Mikhail Ramalho.</div></div></div>
</font></span></div></div>
</blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br><div><div dir="ltr"><div><br></div><div>Mikhail Ramalho.</div></div></div>
</font></span></div></div>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">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>