<div dir="ltr">I probably coded this up wrong...<div>Can I just use the Plan Old Datatype as the one and only check???<br><div>







<p class=""><span class="">enum</span> <span class="">CXSizeOfTypeError</span> clang_getSizeAndAlignOfType(<span class="">CXType</span> CT, <span class="">long</span> <span class="">long</span> *size, <span class="">long</span> <span class="">long</span> *alignment)</p>


<p class="">{</p>
<p class="">  <span class="">if</span>(<span class="">clang_isPODType</span>(CT) == 0)</p>
<p class="">  {</p>
<p class=""><span class="">     </span>*size = *alignment = -1;</p>
<p class=""><span class="">     </span><span class="">return</span> <span class="">CXSizeOfTypeError_DependentType</span>;</p>
<p class="">  }</p>
<p class="">  <span class="">QualType</span> T = <span class="">GetQualType</span>(CT);</p>
<p class="">  <span class="">const</span> <span class="">Type</span> *TP = T.<span class="">getTypePtrOrNull</span>();</p>
<p class="">  <span class="">if</span>(!TP)</p>
<p class="">  {</p>
<p class="">    *size = *alignment = -1;</p>
<p class="">    <span class="">return</span> <span class="">CXSizeOfTypeError_VoidPointer</span>;</p>
<p class="">  }</p>
<p class="">  <span class="">if</span>(TP && TP-><span class="">isDependentType</span>()) {</p>
<p class="">    *size = *alignment = -1;</p>
<p class="">    <span class="">return</span> <span class="">CXSizeOfTypeError_DependentType</span>;</p>
<p class="">  }</p>
<p class=""><br></p>
<p class="">  <span class="">CXTranslationUnit</span> TU = <span class="">GetTU</span>(CT);</p>
<p class="">  <span class="">ASTUnit</span> *AU = clang::cxtu::<span class="">getASTUnit</span>(TU);</p>
<p class="">  <span class="">const</span> <span class="">ASTContext</span> &AC = AU-><span class="">getASTContext</span>();</p>
<p class=""><br></p>
<p class="">  *size = AC.<span class="">getTypeSize</span>(T);</p>
<p class="">  *alignment = AC.<span class="">getTypeAlign</span>(T);</p>
<p class="">  <span class="">return</span> <span class="">CXSizeOfTypeError_None</span>;</p>
<p class="">}</p></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Feb 23, 2013 at 7:17 PM, Argyrios Kyrtzidis <span dir="ltr"><<a href="mailto:akyrtzi@gmail.com" target="_blank">akyrtzi@gmail.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"><br>
On Feb 22, 2013, at 4:38 PM, Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com">gribozavr@gmail.com</a>> wrote:<br>
<br>
> On Sat, Feb 23, 2013 at 1:22 AM, Sam Price <<a href="mailto:thesamprice@gmail.com">thesamprice@gmail.com</a>> wrote:<br>
>> Added a command to grab the the size, and the proper hooks to access it<br>
>> within python bindings.<br>
><br>
> Hi Sam,<br>
><br>
> /**<br>
> + * \brief Retrieve the size of the given type.<br>
> + */<br>
> +CINDEX_LINKAGE long long clang_getTypeSize(CXType T);<br>
><br>
> Is the size in bytes or bits?<br>
><br>
> Please also expand this comment to cover what we do for corner cases.<br>
> I think that it is a good idea for this API to return exactly the same<br>
> value that sizeof returns.  (But I don't think this is the case with<br>
> current implementation -- consider function types, references,<br>
> incomplete types, uninstantiated templates).  I understand that this<br>
> is might be much more than you need to accomplish your task, but the<br>
> feature should be implemented completely, or not done at all.<br>
><br>
> Argyrios, what is your preference on the semantics of this function?<br>
> Should it try to return the same thing as sizeof?<br>
<br>
</div>Yes, that makes sense and is easy to understand what the function does.<br>
<br>
Also how about enhancing it to also return alignment with something like this:<br>
CXSizeOfTypeError clang_getSizeAndAlignOfType(CXType T, unsigned long long *size, unsigned long long *align)<br>
<br>
The return value would be an enum indicating if the function was successful and if not what kind of error occurred.<br>
<span class="HOEnZb"><font color="#888888"><br>
-Argyrios<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
><br>
> +    /*Print Size of type*/<br>
><br>
> It should be /* Print size of type. */ -- note spaces, capitalization,<br>
> full stop.<br>
><br>
> +    {<br>
> +      PrintTypeSize(T, "[typesize=%d]");<br>
> +    }<br>
><br>
> (1) There should be a space in the string, " [typesize...<br>
> (2) The format should be %lld<br>
> (3) Just inline the PrintTypeSize.  There's only one call site, thus<br>
> no need for this trivial function.<br>
><br>
> +long long clang_getTypeSize(CXType CT ) {<br>
><br>
> Extra space after CT.<br>
><br>
> +  CXTranslationUnit TU = GetTU(CT);<br>
> +  ASTUnit *AU = clang::cxtu::getASTUnit(TU);<br>
> +  const ASTContext &AC = AU->getASTContext();<br>
> +  QualType T = GetQualType(CT);<br>
> +  return AC.getTypeSize(T);<br>
> +}<br>
><br>
> I did not run this, but it would probably crash on an incomplete type.<br>
> Even if it doesn't, we should have a separate error code for that.<br>
><br>
> The actual tests are missing.  I think that current tests should have<br>
> been broken by this, too, since you have changed the output format of<br>
> c-index-test (this is the correct thing to do, but you need to update<br>
> existing tests for the new information you print).<br>
><br>
> Python bindings also need tests -- see bindings/python/tests/ directory.<br>
><br>
> Dmitri<br>
><br>
> --<br>
> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if<br>
> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com">gribozavr@gmail.com</a>>*/<br>
<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>Thank you,<br><br>Sam Price<br>(707) 742-3726
</div>