[cfe-dev] libclang 3.5 C interface - cannot get to macro definitions/expansions with cursors

Juaristi Álamos, Ander via cfe-dev cfe-dev at lists.llvm.org
Tue Dec 1 00:29:10 PST 2015


On Mon, 2015-11-30 at 15:05 -0700, Matt Stevens wrote:
> > On Nov 30, 2015, at 5:52 AM, Juaristi Álamos, Ander via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> > 
> > Hi all,
> > 
> > I'm writing a libclang-based C application to get information about
> > functions, variables and macros, and should treat them all equally.
> > 
> > What I need is to be able to parse the macro definitions and expansions
> > (before they are expanded), as if they were functions.
> > 
> > To test libclang, I've written a sample application that walks over the
> > AST like this:
> > 
> >    error = clang_parseTranslationUnit2(index, 0, argv, argc, 0, 0,
> >             CXTranslationUnit_None,
> >             &tu);
> >    if (tu) {
> >        cursor = clang_getTranslationUnitCursor(tu);
> >        clang_visitChildren(cursor, cx_visit, NULL);
> >        ...
> 
> Hi AJ,
> 
> To visit cursors for macro definitions and expansions pass the CXTranslationUnit_DetailedPreprocessingRecord option to clang_parseTranslationUnit2().
> 
> Matt

Simple enough!

Thanks.
- AJ



More information about the cfe-dev mailing list