[cfe-dev] libelling - tokens/AST and the preprocessor

R J Cooper cooper at mountainstorm.co.uk
Mon Mar 2 14:12:03 PST 2015


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;
#endif

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.

Thanks

Rich



More information about the cfe-dev mailing list