lib clang help request: usage of clang_getIncludedFile()

Hi all,

I am trying to find out the files included from a file.

I use clang_tokenize() and clang_annotateTokens() in order to get a set of tokens and cursors.

When I iterate through them, for #import directives I get a cursor kind of preprocessor directive instead of file inclusion ( which is what I expected if I understood lib clang correctly ) .

When I call clang_getIncludedFile() on the correspondent cursor it returns a zero file, so that I cannot get its filename.

Am I doing something terribly wrong here or is there something wrong with the way clang_annotateTokens() works or anything else?

What is the correct way to find the files included from a file?

Thanks,
A

Hi all,

I am trying to find out the files included from a file.

I use clang_tokenize() and clang_annotateTokens() in order to get a set of tokens and cursors.

When I iterate through them, for #import directives I get a cursor kind of preprocessor directive instead of file inclusion ( which is what I expected if I understood lib clang correctly ) .

Yes, you should get it. Are you specifying CXTranslationUnit_DetailedPreprocessingRecord when you're parsing the translation unit? If not, libclang isn't keeping detailed information about inclusions.

When I call clang_getIncludedFile() on the correspondent cursor it returns a zero file, so that I cannot get its filename.

Am I doing something terribly wrong here or is there something wrong with the way clang_annotateTokens() works or anything else?

What is the correct way to find the files included from a file?

An alternative way is to perform a non-recursive visit of the contents of the translation unit using clang_visitChildren on the translation unit. Then, you'll get all of the inclusion directive cursors. You still need to specify CXTranslationUnit_DetailedPreprocessingRecord, of course.

  - Doug