[cfe-dev] [libClang] Parsing expanded function-like macros

Joe Turner via cfe-dev cfe-dev at lists.llvm.org
Wed Feb 28 17:35:34 PST 2018


I'm using libClang to parse the AST for Objective-C/C++ code, and have run
into an issue with macro-like functions. Given something like this:

#define FOO(a, b) a + b

int main() {
  int a = 0;
  int b = 1;
  int c = FOO(a, b);
  return c;
}

I would like to be able to see references to a and b in the AST when I
parse the "int c = FOO(a, b);" line. However, all I see in the AST is the
"int c = " part (a Decl and a VarDecl).

I've done a bunch of searching, and people mention
using CXTranslationUnit_DetailedPreprocessingRecord, which doesn't work for
me. This adds children to the translation unit that reference the macro
itself, but it doesn't give me access to the arguments passed into the
function-like macro.

Short of using the C++ API, is there any way to get this information from
libClang?

Thanks!
Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180228/893faec1/attachment.html>


More information about the cfe-dev mailing list