[cfe-dev] How to retrieve a custom annotation in an ASTVisitor?

Aaron Ballman via cfe-dev cfe-dev at lists.llvm.org
Wed Aug 2 09:16:44 PDT 2017


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