How to retrieve a user defined attribute from a DeclGroup?

Hi,

I am struggling with a propably stupid simple problem:

In my plugin I have attributted the ast for a function decl with my own attribute:

Something like that:
     class AnnotateFunctionsConsumer : public ASTConsumer {

     public:
         bool HandleTopLevelDecl(DeclGroupRef DG) override {
             for (auto D : DG)
                 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
FD->addAttr(AnnotateAttr::CreateImplicit(FD->getASTContext(),
                         "MyOwnAttr"));
             return true;
         }
     };

In another part of my tool I want to retrieve this attribute inside of a AstConsumer and perform some transformations.

What is the proper way for doing this? Is FD->getAttr the intended function for this and if yes how to call in the above mentiond example?

Thanks

Marcel

If you have a FunctionDecl FD, you can just do something like this to
get the AnnotateAttr back:

if (clang::AnnotateAttr *Annot = D->getAttr<AnnotateAttr>())
  printf("Found an annotate attribute!");
else
  printf("This FunctionDecl has no AnnotateAttr");

- Raphael

Hi Raphael,

works.

Thanx for your help!

Marcel