[cfe-dev] Not getting expected Decls (possible newbie mistake)
Douglas Gregor
dgregor at apple.com
Mon Feb 22 15:19:47 PST 2010
On Feb 22, 2010, at 2:41 PM, Pascal Dennerly wrote:
> ==Stuff.h==
> namespace Stuff
> {
> template< typename A, int B >
> class Thingy
> {
> public:
> Thingy() {}
>
> private:
> int data;
> };
> }
>
> ==Stuff.cpp==
> #include "Stuff.h"
> Stuff::Thingy< double, 2 > gThing;
> void funcy()
> {
> int i;
> i++;
> }
>
> I tried to write an AST consumer that would iterate over the Decls in the HandleTranslationUnit method but when I ran it over the above code only got __builtin_va_list (as a TypedefDecl) and 2 VarDecls as for "Stuff". I was expecting a RecordDecl for the Thingy class and decl for the class.
>
> I don't suppose someone would be able to tell me why I'm so far off base?
The top-level declarations are __builtin_va_list (injected by the compiler), Stuff, gThing, and funcy.
Thingy is not a top-level declaration; it's stored within the namespace 'Stuff'. You can iterate through the declarations within a namespace with decls_begin/decls_end; check out the DeclContext class for more information.
- Doug
More information about the cfe-dev
mailing list