<div dir="ltr"><div>> <i><span style="font-family:arial,sans-serif;font-size:13px">If I had to guess, I would assume somewhere on the ASTContext, if it's </span><span style="font-family:arial,sans-serif;font-size:13px">not on the clang Type itself - but I could be wrong.</span></i></div>
<div><i><span style="font-family:arial,sans-serif;font-size:13px"><br></span></i></div><div><span style="font-family:arial,sans-serif;font-size:13px">You're correct, it's called ASTContext::getTypeSize:<i> </i></span><a href="http://clang.llvm.org/doxygen/classclang_1_1ASTContext.html#a3e16bd856974e4ac9710e0c507a60cee">http://clang.llvm.org/doxygen/classclang_1_1ASTContext.html#a3e16bd856974e4ac9710e0c507a60cee</a></div>
<div><br></div><div>> <span style="font-family:arial,sans-serif;font-size:13px"><i>And is there any method that can provide me the information of alignment for some structure type?</i></span></div><div><span style="font-family:arial,sans-serif;font-size:13px"><br>
</span></div><div><span style="font-family:arial,sans-serif;font-size:13px">To get such information - like type size, and alignment, and so on - you usually will want to check the ASTContext type first. There is a method for getting alignment, but finding it among ASTContext's methods falls to you. :)</span><br>
</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/8/15 David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Thu, Aug 15, 2013 at 1:26 AM, Arthur Yoo <<a href="mailto:phjy007@gmail.com">phjy007@gmail.com</a>> wrote:<br>
> David:<br>
><br>
> Thank you very much for your help. Now I can get the the information of a<br>
> structure's fields. :-)<br>
><br>
> By the way, I want to know that does Clang provide us the methods to get the<br>
> length of some data type? For examples, the length of int is 4 bytes, the<br>
> length of char is one byte and so on.<br>
> And is there any method that can provide me the information of alignment for<br>
> some structure type?<br>
<br>
</div>I imagine you could discover what code to use for this by, say,<br>
writing the code:<br>
<br>
int main() {<br>
static_assert(sizeof(int) == 42, "foo");<br>
}<br>
<br>
compiling it, breaking on the compilation error, then working<br>
backwards through the stack/calls to see where the sizeof value was<br>
derived. I tend to take this sort of approach when I don't know where<br>
something is in the compiler.<br>
<br>
If I had to guess, I would assume somewhere on the ASTContext, if it's<br>
not on the clang Type itself - but I could be wrong.<br>
<div class="HOEnZb"><div class="h5"><br>
><br>
> Thank you.<br>
><br>
><br>
><br>
> 2013/8/15 David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>><br>
>><br>
>> On Wed, Aug 14, 2013 at 7:09 AM, Arthur Yoo <<a href="mailto:phjy007@gmail.com">phjy007@gmail.com</a>> wrote:<br>
>> > Hi all,<br>
>> ><br>
>> > I can use isStructureType() and isUnionType() to check whether an Expr<br>
>> > is<br>
>> > structure type or union type. Now I want to get the structure/union<br>
>> > type's<br>
>> > detailed information, such as the fields and their types of a structure.<br>
>> > How<br>
>> > can I get these information? Thanks a lot.<br>
>><br>
>> So you have a Type already (since isStructureType isn't a member of<br>
>> Expr, it's a member of Type), so looking at the Type documentation:<br>
>><br>
>> <a href="http://clang.llvm.org/doxygen/classclang_1_1Type.html" target="_blank">http://clang.llvm.org/doxygen/classclang_1_1Type.html</a><br>
>><br>
>> & then follow through to the source of isStructureType (<br>
>> <a href="http://clang.llvm.org/doxygen/Type_8cpp_source.html#l00366" target="_blank">http://clang.llvm.org/doxygen/Type_8cpp_source.html#l00366</a> ) you'll<br>
>> see it's simply:<br>
>><br>
>> if (const RecordType *RT = getAs<RecordType>())<br>
>> return RT->getDecl()->isStruct();<br>
>> return false;<br>
>><br>
>> So you can do something similar -<br>
>> cast<RecordDecl>(cast<RecordType>(T)->getDecl()) and then once you've<br>
>> got the RecordDecl you can use its API to access the list of members,<br>
>> etc. (you may need to make sure it's a definition of a record, not<br>
>> just a declaration, etc)<br>
>> ><br>
>> > --<br>
>> > Best regards,<br>
>> > Arthur Yoo<br>
>> ><br>
>> > _______________________________________________<br>
>> > cfe-dev mailing list<br>
>> > <a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
>> > <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
>> ><br>
><br>
><br>
> --<br>
> Best regards,<br>
> Arthur Yoo<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</div></div></blockquote></div><br></div>