[cfe-dev] How to retrieve a user defined attribute from a DeclGroup?

Marcel Schaible via cfe-dev cfe-dev at lists.llvm.org
Tue Jul 18 08:51:58 PDT 2017


Hi Raphael,

works.

Thanx for your help!

Marcel

Am 18.07.2017 um 17:31 schrieb Raphael Isemann:
> 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
>
>
> 2017-07-18 17:05 GMT+02:00 Marcel Schaible via cfe-dev <cfe-dev at lists.llvm.org>:
>> 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
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list