[cfe-dev] python bindings

Sam Price thesamprice at gmail.com
Fri Feb 22 12:00:56 PST 2013


Little lost on how to add the unit tests for this feature.
I opened up tools/c-index-test.c
and looked for some similar examples

clang_getArraySize

clang_getArrayElementType

However I didn't see these calls in the c-index-test.c file.

Am I looking at the right place?  Can you provide me with
an comparable unit test to mimic?



On Fri, Feb 22, 2013 at 2:32 AM, Dmitri Gribenko <gribozavr at gmail.com>wrote:

> On Fri, Feb 22, 2013 at 6:52 AM, Sam Price <thesamprice at gmail.com> wrote:
> > That is what I want.
> > I think I need to use an ASTContext to get get the size of a type though.
> >
> > Waiting for code to compile. I ended up with something like this
> >
> > int clang_getSizeOf(CXType CT ) {
> >
> >   CXTranslationUnit TU = GetTU( CT );
> >
> >   ASTUnit * AU = clang::cxtu::getASTUnit( TU );
> >
> >   const ASTContext & AC = AU->getASTContext();
> >
> >   QualType T = GetQualType( CT );
> >
> >   return AC.getTypeSize(T);
> >
> > }
>
> That looks correct as a first approximation.  But:
> * change the return type to long long;
> * you also need to check for incomplete types and return an error;
> * LLVM and Clang style is to put star next to the identifier: "ASTUnit
> *AU";
> * style: no spaces in function calls: "GetQualType(CT);"
> * you might want to make this function work like sizeof() *or*
> document the differences (for example, if computing the size requires
> template instantiation, we should do it; or sizeof a reference type
> equals the size of the type; what about sizeof void, sizeof a function
> type etc...);
> * please add tests.  You need to extend c-index-test for that.
>
> Dmitri
>
> --
> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
>



-- 
Thank you,

Sam Price
(707) 742-3726
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130222/3308bf69/attachment.html>


More information about the cfe-dev mailing list