cedlemo cedlemo - 10 months ago 59
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?


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;