libelling - tokens/AST and the preprocessor

So libclang makes tokenising and thus syntax highlighting easy; but ... what I'm struggling with is #ifdef blocks - specifically those which are compiled (out as I want to highlight them differently)

A quick test show that given the following code:

#ifdef EXCLUDE
int a = 0;

I always get the same tokens (#, ifdef, EXCLUDE, int, a, =, 0, ;, #, endif). But depending on the value of EXCLUDE the AST behind those tokens changes - when excluded they are all put in a single COMPOUND_STMT.

The question is, how do I tell these tokens have been excluded from the compile; and thus I can mark them as dimmed?

I've tried most things I can think of but still can't figure out how to take an AST cursor and get if it was actually included.




When create Preprocessor add own PPCallbacks impl with implemented SourceRangeSkipped to track dead blocks.

Hope it helps,

If you are using pure libclang.
Then your method is
CINDEX_LINKAGE CXSourceRangeList *clang_getSkippedRanges(CXTranslationUnit tu,
                                                          CXFile file);