cedlemo cedlemo - 1 year ago 97
C Question

How to get the structure members from a TagDecl with clang

I have an AST consumer that get all the TagDecl which are structure with


How to get members of the structure (declaration, type) in an array like the FunctionDecl class:

clang::FunctionDecl::getParamDecl(unsigned i)

Or in any other ways?

Answer Source

The TagDecl must be cast to a RecordDecl that have the methods to get the members / fields information.

clang::RecordDecl::field_iterator jt;

for(jt = r->field_begin(); jt != r->field_end();++jt)
    std::cout << jt->getType().getAsString() << " " << jt->getNameAsString() << std::endl;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download