[cfe-dev] Extracting macro information using libclang, the C Interface to Clang

Mark inbox at akiwi.co.uk
Thu Nov 27 10:47:17 PST 2014


Hello all,
I'm new to libclang and using the Clang C-interface (version 3.6.0, 
222169) to parse some C header files.

My goal is to extract all the #define constants from the .h files.

For example, for the following #defines:

#define FEE 12
#define FIE 34
#define FOE (FEE+FIE)
#define FUM FIE

I would like to get both the names and the resulting raw values as follows:

FEE = 12
FIE = 34
FOE = 46
FUM = 34

I've got as far as handling /CXCursor_MacroDefinition, /and getting the 
macro name from the cursor spelling. But after that, it's not clear to 
me how I might obtain further information about the defined macro values 
themselves.

Is this possible using the libclang C interface?
If so, could someone please provide an example, or suggest an approach 
that that might work?

Thank you,

Mark.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20141127/61b98a90/attachment.html>


More information about the cfe-dev mailing list