How to determine if Decl is a RecordDecl?

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

How to determine if Decl is a RecordDecl?

Manas via cfe-dev
Hi,

I am currently devoloping a tool, which collects Decl with a
user-defined attribute.

At the moement I am storing these Decls in a vector.

Afterwards I want to iterate over the vector of Decls and want to
determine if a element is e.g. of type RecordDecl or CxxRecordDecl

What is the preferred way for achieving this?

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 determine if Decl is a RecordDecl?

Manas via cfe-dev
On Wed, Nov 11, 2020 at 10:21 AM Marcel Schaible via cfe-dev
<[hidden email]> wrote:

>
> Hi,
>
> I am currently devoloping a tool, which collects Decl with a
> user-defined attribute.
>
> At the moement I am storing these Decls in a vector.
>
> Afterwards I want to iterate over the vector of Decls and want to
> determine if a element is e.g. of type RecordDecl or CxxRecordDecl
>
> What is the preferred way for achieving this?

You can use isa<CXXRecordDecl>(TheDecl) to test what kind of
declaration it is, or dyn_cast<RecordDecl>(TheDecl) or
cast<RecordDecl>(TheDecl) to convert the declaration to the more
derived type. See
https://llvm.org/docs/ProgrammersManual.html#the-isa-cast-and-dyn-cast-templates
for more details.

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
Reply | Threaded
Open this post in threaded view
|

Re: How to determine if Decl is a RecordDecl?

Manas via cfe-dev
In reply to this post by Manas via cfe-dev
You can either do a isa<RecordDecl>(MyDecl), or dyn_cast<RecordDecl>(MyDecl)

-----Original Message-----
From: cfe-dev <[hidden email]> On Behalf Of Marcel Schaible via cfe-dev
Sent: Wednesday, November 11, 2020 7:21 AM
To: [hidden email]
Subject: [cfe-dev] How to determine if Decl is a RecordDecl?

Hi,

I am currently devoloping a tool, which collects Decl with a user-defined attribute.

At the moement I am storing these Decls in a vector.

Afterwards I want to iterate over the vector of Decls and want to determine if a element is e.g. of type RecordDecl or CxxRecordDecl

What is the preferred way for achieving this?

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