[cfe-dev] Rewriter: expand macro to definition

Alexander Graf via cfe-dev cfe-dev at lists.llvm.org
Thu Aug 17 04:25:29 PDT 2017


Hi all,

I am currently working on a source-to-source transformation using 
libtooling/clang. I would like to selectively expand some macros to 
their definition during rewrite. Possible recursion and other macros in 
the expansion shall be expanded as well. e.g.

#define FOO( name, line ) name##line
#define BAR( name, line ) FOO( name, line )
#define BAZ( name ) BAR( name, __LINE__ )

such that

BAZ( test )

at line 42 can be expanded to the string "test42". How can I do that? I 
found an old, similar question on the clang list, which never received a 
proper answer[1]. It cannot be that hard, can it?

Thank you!

Regards,
Alex

[1] 
http://clang-developers.42468.n3.nabble.com/Using-Clang-to-Expand-Macros-td4028424.html



More information about the cfe-dev mailing list