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

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

You can either do a isa<RecordDecl>(MyDecl), or dyn_cast<RecordDecl>(MyDecl)