Clang-AST traversal - How to get class member variables
I want to go through the AST of a simple class having one member variable and one method. I realized that the class is represented as CXXRecordDecl.
What is the api inside CXXREcordDecl to get the list of member variables that are represented as FieldDecl?
+3
Raks
source
to share
1 answer
Fields can be retrieved using RecordDecl::fields
(there are also methods that get the start and end iterators of that range) for example. for aCXXRecordDecl
CXXRecordDecl* cl = ...;
for (const auto& field : cl->fields) {
const auto& name = field->getName();
const auto field_cl = field->getType()->getAsCXXRecordDecl();
}
Likewise, you can access methods with methods()
.
+2
Benjamin bannier
source
to share