[cfe-dev] How to retrieve a custom annotation in an ASTVisitor?
Marcel Schaible via cfe-dev
cfe-dev at lists.llvm.org
Wed Aug 2 09:43:01 PDT 2017
Thanks Aaron, works for one annotation.
If I have multiple annotations per function declaration how can I
iterate over them or can I use something like funcdecl->getAttr("SomeAttr")?
Cheers
Marcel
Am 02.08.2017 um 18:16 schrieb Aaron Ballman:
> On Wed, Aug 2, 2017 at 12:04 PM, Marcel Schaible via cfe-dev
> <cfe-dev at lists.llvm.org> wrote:
>> Hi everyone,
>>
>> I attach in my ASTConsumer for certain functions an annotation like this:
>>
>> bool HandleTopLevelDecl(DeclGroupRef DR) override {
>>
>> ...
>>
>> functionDecl->addAttr(AnnotateAttr::CreateImplicit(FD->getASTContext(),
>> "SomeAttribute"));
>>
>> ...
>>
>> }
>>
>> But how can I later retrieve this annotation in my visitor?
> You can use functionDecl->hasAttr<AnnotateAttr>() to test for the
> presence of the attribute, or const auto *A =
> functionDecl->getAttr<AnnotateAttr>() to get the attribute AST node
> from the declaration.
>
> HTH!
>
> ~Aaron
>
>> Any hint is welcome ;-)
>>
>> 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