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

Joe Turner via cfe-dev cfe-dev at lists.llvm.org
Thu Mar 1 11:20:30 PST 2018


Thanks to the pointer, but as far as I can tell, that is not actually ever
called when running the Clang C API (nor is handleDeclOccurence from what I
can tell).

When doing clang -Xclang -ast-dump, I get basically what I want (the macro
is fully expanded), so there must be some way of coercing libclang to give
me that same information.

Cheers,
Joe

On Wed, Feb 28, 2018 at 11:45 PM, Fāng-ruì Sòng <maskray at google.com> wrote:

> Is this relevant?
> clang::index::IndexDataConsumer::HandleMacroOccurence is not
> implemented (overriden) in clang/tools/libclang/CXIndexDataConsumer.h
>
> I guess CXTranslationUnit_DetailedPreprocessingRecord only makes macro
> expansions children of the translation unit AST, there is still no way
> to get their position in the macro replacement-list. I would also like
> to see the feature implemented in libclang.
>
> On Wed, Feb 28, 2018 at 5:35 PM, Joe Turner via cfe-dev
> <cfe-dev at lists.llvm.org> wrote:
> > 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
> >
> > _______________________________________________
> > cfe-dev mailing list
> > cfe-dev at lists.llvm.org
> > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
> >
>
>
>
> --
> 宋方睿
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180301/262f7359/attachment.html>


More information about the cfe-dev mailing list