<div dir="ltr">Hi Manuel,<div>thanks for your help.</div><div><br></div><div>Yes i meant "int main()". Based on what you said I think I should do something like: decl->getInit()->getNameInfo()->getName();</div><div><br></div><div>Thanks,</div><div>Alberto</div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-01-08 8:54 GMT+00:00 Manuel Klimek <span dir="ltr"><<a href="mailto:klimek@google.com" target="_blank">klimek@google.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">getInit should be/contain a declrefexpr </p>
<br><div class="gmail_quote"><span class="">On Wed, Jan 7, 2015, 21:41 Alberto Barbaro <<a href="mailto:barbaro.alberto@gmail.com" target="_blank">barbaro.alberto@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div>Hi all,<br></div>please consider this code:<br><br></div>int main {<br></div></div></div></blockquote><div><br></div></span><div>I assume you mean "main()"</div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div></div> int a = 7;<br></div> int b = a;<br><div><div>}<br><br></div><div>I have a Decl object called decl that represents int b = a; If i do decl->getInit() i can have an Expr pointer that represents a I think. From there how can i retrieve the variable name 'a'? Maybe using getNameAsString()? I tried but it didn't work.<br></div></div></div></blockquote><div><br></div></span><div>As -ast-dump shows, getInit is a ImplicitCastExpr which has a DeclRefExpr which points to 'a'.</div><div><br></div><div><div>$ clang_check -ast-dump /tmp/t.cc --</div><div>TranslationUnitDecl 0x21c05e0 <<invalid sloc>> <invalid sloc></div><div>|-TypedefDecl 0x21c0b20 <<invalid sloc>> <invalid sloc> implicit __int128_t '__int128'</div><div>|-TypedefDecl 0x21c0b80 <<invalid sloc>> <invalid sloc> implicit __uint128_t 'unsigned __int128'</div><div>|-TypedefDecl 0x21c0f40 <<invalid sloc>> <invalid sloc> implicit __builtin_va_list '__va_list_tag [1]'</div><div>`-FunctionDecl 0x21c0fe0 </tmp/t.cc:1:1, line:4:1> line:1:5 main 'int (void)'</div><div> `-CompoundStmt 0x21c1240 <col:12, line:4:1></div><div> |-DeclStmt 0x21c1168 <line:2:3, col:12></div><div> | `-VarDecl 0x21c10f0 <col:3, col:11> col:7 used a 'int' cinit</div><div> | `-IntegerLiteral 0x21c1148 <col:11> 'int' 7</div><div> `-DeclStmt 0x21c1228 <line:3:3, col:12></div><div> `-VarDecl 0x21c1190 <col:3, col:11> col:7 b 'int' cinit</div><div> `-ImplicitCastExpr 0x21c1210 <col:11> 'int' <LValueToRValue></div><div> `-DeclRefExpr 0x21c11e8 <col:11> 'int' lvalue Var 0x21c10f0 'a' 'int'</div></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><div><br></div><div>Thanks,<br>Alberto<br></div></div></div>
______________________________<u></u><u></u>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailm<u></u>an/listinfo/cfe-dev</a><br>
</blockquote></div>
</blockquote></div><br></div>