[cfe-dev] Not getting expected Decls (possible newbie mistake)

Pascal Dennerly dnnrly at gmail.com
Mon Feb 22 16:41:21 PST 2010


That was my first thought but when I did if(dyn_cast< NamespaceDecl
>(pDecl)) { ...code... }, I found that I wasn't hitting my breakpoint inside
the if-block. Also pDecl->getDeclKindName() returns "Var" for all instances
of Stuff (I would have expected 1 for the declaration of gThing but not the
namespace too).

I also tried iterating through all of the items in the DeclGroupRef in
HandleTopLevelDecl(...) and trying to recurse down through all Decls that
successfully dyn_cast< DeclContext >.

(And the __builtin_va_list disappears when I copied used the
SourceLocation::isInvalid() check from
RewriteObjC::HandleTopLevelSingleDec(...) suggested as an example
previously.)

Pascal

On 22 February 2010 23:19, Douglas Gregor <dgregor at apple.com> wrote:

>
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100223/a64fb047/attachment.html>


More information about the cfe-dev mailing list