How to retrieve a user defined attribute from a DeclGroup?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to retrieve a user defined attribute from a DeclGroup?

Sumner, Brian via cfe-dev
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
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to retrieve a user defined attribute from a DeclGroup?

Sumner, Brian via cfe-dev
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 <[hidden email]>:

> 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
> [hidden email]
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to retrieve a user defined attribute from a DeclGroup?

Sumner, Brian via cfe-dev
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 <[hidden email]>:
>> 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
>> [hidden email]
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Loading...