<div dir="ltr">Little lost on how to add the unit tests for this feature.<div style>I opened up tools/c-index-test.c</div><div style>and looked for some similar examples</div><div style>
<p class="">clang_getArraySize</p><p class="">
</p><p class="">clang_getArrayElementType</p><p class="">However I didn't see these calls in the c-index-test.c file.<br></p><p class="" style>Am I looking at the right place? Can you provide me with an comparable unit test to mimic?</p>
<p></p></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Feb 22, 2013 at 2:32 AM, Dmitri Gribenko <span dir="ltr"><<a href="mailto:gribozavr@gmail.com" target="_blank">gribozavr@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">On Fri, Feb 22, 2013 at 6:52 AM, Sam Price <<a href="mailto:thesamprice@gmail.com">thesamprice@gmail.com</a>> wrote:<br>
> That is what I want.<br>
> I think I need to use an ASTContext to get get the size of a type though.<br>
><br>
> Waiting for code to compile. I ended up with something like this<br>
><br>
> int clang_getSizeOf(CXType CT ) {<br>
><br>
> CXTranslationUnit TU = GetTU( CT );<br>
><br>
> ASTUnit * AU = clang::cxtu::getASTUnit( TU );<br>
><br>
> const ASTContext & AC = AU->getASTContext();<br>
><br>
> QualType T = GetQualType( CT );<br>
><br>
> return AC.getTypeSize(T);<br>
><br>
> }<br>
<br>
</div>That looks correct as a first approximation. But:<br>
* change the return type to long long;<br>
* you also need to check for incomplete types and return an error;<br>
* LLVM and Clang style is to put star next to the identifier: "ASTUnit *AU";<br>
* style: no spaces in function calls: "GetQualType(CT);"<br>
* you might want to make this function work like sizeof() *or*<br>
document the differences (for example, if computing the size requires<br>
template instantiation, we should do it; or sizeof a reference type<br>
equals the size of the type; what about sizeof void, sizeof a function<br>
type etc...);<br>
* please add tests. You need to extend c-index-test for that.<br>
<span class="HOEnZb"><font color="#888888"><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>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br>Thank you,<br><br>Sam Price<br>(707) 742-3726
</div>