When I’m looking through cursors using ‘clang_visitChildren’, how do I check whether that cursor comes from an included file.
I have tried:
clang_getSpellingLocation(clang_getRangeStart(clang_getCursorExtent(cursor), &cxf, NULL, NULL, NULL);
But clang_getCString(clang_getFileName(cxf)) will always return the name of the main file.
I have also tried:
and the same applies here.
I would like to be able to distinguish between cursors that are present in the original file, and those from included files.
This is how I do it:
auto loc = clang_getCursorLocation(cursor);
clang_getSpellingLocation(loc, &file, &line, &column, &offset);
if (file != mainFile)
// cursor is from included file
You can get "mainFile" using something like this:
auto mainFileName = "foo.c"; // you will probably get this from the command line or somewhere else
auto mainFile = clang_getFile(translationUnit, mainFileName);
You can have a look at my project, DStep:
You might want to start looking here:
It's written in D with a few wrappers around the Clang C API.