[cfe-dev] Getting the pointer to an out-of-class VarDecl
Yaron Keren
yaron.keren at gmail.com
Tue Sep 30 00:13:11 PDT 2014
A redeclaration chain contains all redeclarations, that's the idea, it is a
circular singly-linked list.
You should be able to traverse the chain
with getFirstDecl(), getMostRecentDecl() and friends from Redeclarable.h.
Yaron
2014-09-30 10:00 GMT+03:00 Mihai Draghicioiu <mihai.draghicioiu at gmail.com>:
> 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.
>
> 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?
>
> Cheers!
>
> On Sun, Sep 28, 2014 at 7:42 PM, Mihai Draghicioiu <
> mihai.draghicioiu at gmail.com> wrote:
>
>> 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.
>>
>> I just hope I don't have to recurse the AST again each time.
>>
>> class Foo {
>> static int poop;};
>> int Foo::poop = 3;
>>
>>
>> TranslationUnitDecl 0x4b6b060 <<invalid sloc>> <invalid sloc>
>> |-TypedefDecl 0x4b6b5a0 <<invalid sloc>> <invalid sloc> implicit __int128_t '__int128'
>> |-TypedefDecl 0x4b6b600 <<invalid sloc>> <invalid sloc> implicit __uint128_t 'unsigned __int128'
>> |-TypedefDecl 0x4b6b9c0 <<invalid sloc>> <invalid sloc> implicit __builtin_va_list '__va_list_tag [1]'
>> |-CXXRecordDecl 0x4b6ba10 </tmp/cxxXX38p7:1:1, line:3:1> line:1:7 class Foo definition
>> | |-CXXRecordDecl 0x4b6bb20 <col:1, col:7> col:7 implicit class Foo
>> | `-VarDecl 0x4b6bbc0 <line:2:2, col:13> col:13 poop 'int' static
>> `-VarDecl 0x4b6bc50 parent 0x4b6ba10 prev 0x4b6bbc0 <line:5:1, col:17> col:10 poop 'int' cinit
>> `-IntegerLiteral 0x4b6bd00 <col:17> 'int' 3
>>
>>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140930/f9d03704/attachment.html>
More information about the cfe-dev
mailing list