<div dir="ltr">Well, it seems that I can get a list of redeclarations for each VarDecl, since they inherit Redeclarable<VarDecl>, but it also looks like only the second VarDecl contains the first VarDecl as a redeclaration, whereas the first VarDecl does not contain the second VarDecl as a redeclaration (only itself). It looks like Redeclarations are added on as they are redeclared, and are not added to previous Decls, although intuitively that would make more sense.<div><br></div><div>So it still looks like I'll have to recurse the AST twice, in order to get a pointer to the second VarDecl for the first VarDecl, but maybe someone can still help with an idea on how to avoid that?</div><div><br></div><div>Cheers!</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Sep 28, 2014 at 7:42 PM, Mihai Draghicioiu <span dir="ltr"><<a href="mailto:mihai.draghicioiu@gmail.com" target="_blank">mihai.draghicioiu@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">Hi guys. I'm trying to get a pointer to the last VarDecl from the first VarDecl, so I can access the initialization Expr. As you can see below, There are two VarDecls, and I'd like to get a pointer to the out-of-class one. Also, I can't figure out how the second VarDecl gets its parent pointer.<div><br></div><div>I just hope I don't have to recurse the AST again each time.<br><div><br></div><div><pre style="color:rgb(0,0,0);font-size:medium"><span style="color:rgb(128,0,0);font-weight:bold">class</span> Foo <span style="color:rgb(128,0,128)">{</span>
        <span style="color:rgb(128,0,0);font-weight:bold">static</span> <span style="color:rgb(128,0,0);font-weight:bold">int</span> poop<span style="color:rgb(128,0,128)">;</span>
<span style="color:rgb(128,0,128)">}</span><span style="color:rgb(128,0,128)">;</span>

<span style="color:rgb(128,0,0);font-weight:bold">int</span> Foo<span style="color:rgb(128,0,128)">::</span>poop <span style="color:rgb(128,128,48)">=</span> <span style="color:rgb(0,140,0)">3</span><span style="color:rgb(128,0,128)">;</span></pre></div><div><br></div><div><pre style="color:white;background:black"><span style="background-color:rgb(0,0,0)"><span style="color:lime">TranslationUnitDecl</span><span style="color:olive"> 0x4b6b060</span><span style="color:white"> <</span><span style="color:olive"><invalid sloc></span><span style="color:white">> </span><span style="color:olive"><invalid sloc></span><span style="color:white"> <br></span><span style="color:navy">|-</span><span style="color:lime">TypedefDecl</span><span style="color:olive"> 0x4b6b5a0</span><span style="color:white"> <</span><span style="color:olive"><invalid sloc></span><span style="color:white">> </span><span style="color:olive"><invalid sloc></span><span style="color:white"> implicit</span><span style="color:aqua"> __int128_t</span><span style="color:white"> </span><span style="color:green">'__int128'</span><span style="color:white"> <br></span><span style="color:navy">|-</span><span style="color:lime">TypedefDecl</span><span style="color:olive"> 0x4b6b600</span><span style="color:white"> <</span><span style="color:olive"><invalid sloc></span><span style="color:white">> </span><span style="color:olive"><invalid sloc></span><span style="color:white"> implicit</span><span style="color:aqua"> __uint128_t</span><span style="color:white"> </span><span style="color:green">'unsigned __int128'</span><span style="color:white"> <br></span><span style="color:navy">|-</span><span style="color:lime">TypedefDecl</span><span style="color:olive"> 0x4b6b9c0</span><span style="color:white"> <</span><span style="color:olive"><invalid sloc></span><span style="color:white">> </span><span style="color:olive"><invalid sloc></span><span style="color:white"> implicit</span><span style="color:aqua"> __builtin_va_list</span><span style="color:white"> </span><span style="color:green">'__va_list_tag [1]'</span><span style="color:white"> <br></span><span style="color:navy">|-</span><span style="color:lime">CXXRecordDecl</span><span style="color:olive"> 0x4b6ba10</span><span style="color:white"> <</span><span style="color:olive">/tmp/cxxXX38p7:1:1</span><span style="color:white">, </span><span style="color:olive">line:3:1</span><span style="color:white">> </span><span style="color:olive">line:1:7</span><span style="color:white"> class</span><span style="color:aqua"> Foo</span><span style="color:white"> definition<br></span><span style="color:navy">| |-</span><span style="color:lime">CXXRecordDecl</span><span style="color:olive"> 0x4b6bb20</span><span style="color:white"> <</span><span style="color:olive">col:1</span><span style="color:white">, </span><span style="color:olive">col:7</span><span style="color:white">> </span><span style="color:olive">col:7</span><span style="color:white"> implicit class</span><span style="color:aqua"> Foo</span><span style="color:white"> <br></span><span style="color:navy">| `-</span><span style="color:lime">VarDecl</span><span style="color:olive"> 0x4b6bbc0</span><span style="color:white"> <</span><span style="color:olive">line:2:2</span><span style="color:white">, </span><span style="color:olive">col:13</span><span style="color:white">> </span><span style="color:olive">col:13</span><span style="color:aqua"> poop</span><span style="color:white"> </span><span style="color:green">'int'</span><span style="color:white"> static<br></span><span style="color:navy">`-</span><span style="color:lime">VarDecl</span><span style="color:olive"> 0x4b6bc50</span><span style="color:white"> parent 0x4b6ba10 prev 0x4b6bbc0 <</span><span style="color:olive">line:5:1</span><span style="color:white">, </span><span style="color:olive">col:17</span><span style="color:white">> </span><span style="color:olive">col:10</span><span style="color:aqua"> poop</span><span style="color:white"> </span><span style="color:green">'int'</span><span style="color:white"> cinit<br></span><span style="color:navy">  `-</span><span style="color:fuchsia">IntegerLiteral</span><span style="color:olive"> 0x4b6bd00</span><span style="color:white"> <</span><span style="color:olive">col:17</span><span style="color:white">> </span><span style="color:green">'int'</span><span style="color:aqua"> 3</span><span style="color:white"> </span></span></pre></div></div></div>
</blockquote></div><br></div>