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

Arthur Yoo phjy007 at gmail.com
Thu Aug 15 01:26:47 PDT 2013


David:

Thank you very much for your help. Now I can get the the information of a
structure's fields.   :-)

By the way, I want to know that does Clang provide us the methods to get
the length of some data type? For examples, the length of int is 4 bytes,
the length of char is one byte and so on.
And is there any method that can provide me the information of alignment
for some structure type?

Thank you.



2013/8/15 David Blaikie <dblaikie at gmail.com>

> 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
> >


-- 
Best regards,
Arthur Yoo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130815/b6951cd4/attachment.html>


More information about the cfe-dev mailing list