[cfe-commits] Patch libclang to add functions for introspecting CXCursor_MacroDefinition cursors

Joe Groff arcata at gmail.com
Sun Apr 1 15:13:39 PDT 2012

Hi everyone. Attached is a patch that augments the libclang API with
some additional functions to introspect macro definitions referenced
by CXCursor_MacroDefinition cursors:

* clang_isMacroFunctionLike, to return whether a macro is function-like;
* clang_getMacroVarargsKind, to return whether a macro is GNU-style,
C99-style, or not variadic;
* clang_isMacroBuiltin, to return whether a macro is builtin;
* clang_numMacroArgs and clang_getMacroArgNames, to return the count
and names of a function-like macro's arguments;
* and clang_getMacroReplacementTokens, to return an array of CXTokens
making up the macro's body.

To implement this, I modified the MacroDefinition type to hold a
reference to its originating MacroInfo, and modified Preprocessor not
to deallocate MacroInfo records when a detailed preprocessing record
is being taken. This way, MacroDefinitions remain associated with the
proper MacroInfo even if a macro is subsequently #undef-ed or
re-#define-ed. If there's a better way to handle undefined MacroInfos,
or if you have any other suggestions, let me know. Thanks.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: libclang-macro-info.diff
Type: application/octet-stream
Size: 15794 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120401/50160d4d/attachment.obj>

More information about the cfe-commits mailing list