How to access an AnnotateAttr inside a CXXRecordDecl?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to access an AnnotateAttr inside a CXXRecordDecl?

shirley breuer via cfe-dev
Hi,

how can I access an AnnotateAttr inside a CXXRecordDecl?

Example:

CXXRecordDecl 0x327da78 ... struct struct_s definition
|-DefinitionData pass_in_registers aggregate standard_layout
trivially_copyable pod trivial literal
| |-DefaultConstructor exists trivial needs_implicit
| |-CopyConstructor simple trivial has_const_param needs_implicit
implicit_has_const_param
| |-MoveConstructor exists simple trivial needs_implicit
| |-CopyAssignment trivial has_const_param needs_implicit
implicit_has_const_param
| |-MoveAssignment exists simple trivial needs_implicit
| `-Destructor simple irrelevant trivial needs_implicit
|-AnnotateAttr 0x327db98 <line:3:35, col:62> "SOME ANNOTATION"
   ^^^^^^^^^^^^
|-CXXRecordDecl 0x32a0780 <line:6:1, col:19> col:19 implicit struct struct_s
|-FieldDecl 0x32a08e8 <line:8:3, col:25> col:25 i 'uint32_t':'unsigned int'
| |-AnnotateAttr 0x32a0938 <line:4:34, col:60> "SOME ANNOTATION"
| `-FullComment 0x32a0d70 <line:8:45, line:10:56>

...

Thanks

Marcel
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: How to access an AnnotateAttr inside a CXXRecordDecl?

shirley breuer via cfe-dev
On Thu, Nov 26, 2020 at 6:42 PM Marcel Schaible via cfe-dev
<[hidden email]> wrote:

>
> Hi,
>
> how can I access an AnnotateAttr inside a CXXRecordDecl?
>
> Example:
>
> CXXRecordDecl 0x327da78 ... struct struct_s definition
> |-DefinitionData pass_in_registers aggregate standard_layout
> trivially_copyable pod trivial literal
> | |-DefaultConstructor exists trivial needs_implicit
> | |-CopyConstructor simple trivial has_const_param needs_implicit
> implicit_has_const_param
> | |-MoveConstructor exists simple trivial needs_implicit
> | |-CopyAssignment trivial has_const_param needs_implicit
> implicit_has_const_param
> | |-MoveAssignment exists simple trivial needs_implicit
> | `-Destructor simple irrelevant trivial needs_implicit
> |-AnnotateAttr 0x327db98 <line:3:35, col:62> "SOME ANNOTATION"
>    ^^^^^^^^^^^^
> |-CXXRecordDecl 0x32a0780 <line:6:1, col:19> col:19 implicit struct struct_s
> |-FieldDecl 0x32a08e8 <line:8:3, col:25> col:25 i 'uint32_t':'unsigned int'
> | |-AnnotateAttr 0x32a0938 <line:4:34, col:60> "SOME ANNOTATION"
> | `-FullComment 0x32a0d70 <line:8:45, line:10:56>

Once you have a CXXRecordDecl * (or any Decl *), you can use
Obj->getAttr<AnnotateAttr>() to get a pointer to the AnnotateAttr to
inspect it, or if you only care about the presence of the attribute,
you can use Obj->hasAttr<AnnotateAttr>(). Finally, if you may have to
handle multiple annotation attributes, you can use
Obj->specific_attrs<AnnotateAttr>() or
Obj->specific_attr_begin<AnnotateAttr>()/Obj->specific_attr_end<AnnotateAttr>()
to loop over all of them. HTH!

~Aaron

>
> ...
>
> Thanks
>
> Marcel
> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev