[cfe-users] libclang get AST tree of macro extension

Laurent Carlier via cfe-users cfe-users at lists.llvm.org
Wed Dec 2 12:40:07 PST 2015


Hello,

I'm currently busy with using libclang library.

My goal is to parse code that contains macro with parameters and to get the
type of the macro parameters in order to make syntax coloration.

If we consider the following piece of code

#define MACRO(X) X
typedef struct{
  int a;} aType;

aType data;
int var = MACRO(data.a);

My goal is to be able to color the field a of the structure aType on the
line int var = MACRO(data.a). I.e. I would like to get the line, column and
type whenever I'm getting a cursor over the field a of data variable.

The problem is that whenever I'm getting the cursor on the position of
character a, its type is CXCursor_MacroExpansion. I've already tried to get
the referenced cursor (via clang_getCursorReferenced) but then I'm getting
a cursor type CXCursor_MacroDefinition.

I've also already tried to visit the child via clang_visitChildren but this
returning the cursor itself as well, so it is not useful.

If I could get a cursor with type CXCursor_MemberRefExpr out of my cursor
with type CXCusor_MacroExtension I would have what I need.

Does anyone have an idea how to actually get the info of expanded code iso
getting CXCursor_MacroExpansion, whenever cursor is over a macro expansion?

Thanks a lot for your time and help.

Kind regards,

Laurent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20151202/3a5999ca/attachment.html>


More information about the cfe-users mailing list