[cfe-dev] How can I get the detailed information of Structure/Union

David Blaikie dblaikie at gmail.com
Wed Aug 14 10:14:36 PDT 2013


On Wed, Aug 14, 2013 at 7:09 AM, Arthur Yoo <phjy007 at gmail.com> wrote:
> Hi all,
>
> I can use isStructureType() and isUnionType() to check whether an Expr is
> structure type or union type. Now I want to get the structure/union type's
> detailed information, such as the fields and their types of a structure. How
> can I get these information? Thanks a lot.

So you have a Type already (since isStructureType isn't a member of
Expr, it's a member of Type), so looking at the Type documentation:

http://clang.llvm.org/doxygen/classclang_1_1Type.html

& then follow through to the source of isStructureType (
http://clang.llvm.org/doxygen/Type_8cpp_source.html#l00366 ) you'll
see it's simply:

if (const RecordType *RT = getAs<RecordType>())
  return RT->getDecl()->isStruct();
return false;

So you can do something similar -
cast<RecordDecl>(cast<RecordType>(T)->getDecl()) and then once you've
got the RecordDecl you can use its API to access the list of members,
etc. (you may need to make sure it's a definition of a record, not
just a declaration, etc)


>
> --
> Best regards,
> Arthur Yoo
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>



More information about the cfe-dev mailing list