python bindings

I got the python bindings to work,
However I want to get size, and offset information for various types.

This doesn’t seem to be exposed in the Index.h file

Would I just add new routines to that file?
Where are the index.h routines at?
Would I add a new routine
int getSizeOfCursor(Cursor)
Get the ASTContext from the cursor,

and then do GetTypeInfo from the ASTContext?

and then expose it on the cindex.py routine?

I got the python bindings to work,
However I want to get size, and offset information for various types.

This doesn't seem to be exposed in the Index.h file

Would I just add new routines to that file?
Where are the index.h routines at?
Would I add a new routine
int getSizeOfCursor(Cursor)
Get the ASTContext from the cursor,
and then do GetTypeInfo from the ASTContext?

and then expose it on the cindex.py routine?

Are you interested in something like:
"int clang_getSizeOfType(CXType T);"
?

Start by taking a look at how
"int clang_getNumArgTypes(CXType T);"
is implemented.

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

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?

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.

Unfortunately, it looks like there are no tests for these :frowning:

Patches welcome!

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

Please take a look at the PrintType() function. Just print one more
chunk of information there.

Dmitri

How do I send these patches back your way when I'm done.

I want to add member offset, and expose the comment extractor also.

Sam Price

How do I send these patches back your way when I'm done.

Just send a patch to cfe-commits list for review. Develop your patch
on the latest trunk.

I want to add member offset, and expose the comment extractor also.

There's a review thread about the former [1] (if I understood your
intent correctly). I don't know if Loïc wants to continue to work on
that patch, though.

[1] http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20130211/073932.html

Could you explain the "comment extractor" part? There are APIs in
libclang to extract documentation comments. Is there anything missing?

Dmitri