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

Fāng-ruì Sòng via cfe-dev cfe-dev at lists.llvm.org
Wed Feb 28 23:45:07 PST 2018


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
>



-- 
宋方睿



More information about the cfe-dev mailing list