[cfe-dev] Macro expansion with Clang

Alexander Basov coopht at gmail.com
Tue Oct 15 21:28:53 PDT 2013


That is not proper way for me.
I cannot include the header and compile source and I don't know macro names
that i want to evaluate.
There is no any reason to use C++ API, but if you know how to do it with
libclang-c that's could be great.





2013/10/16 Richard Smith <richard at metafoo.co.uk>

> On Mon, Oct 14, 2013 at 9:48 PM, Alexander Basov <coopht at gmail.com> wrote:
>
>> Hello.
>> Could somebody help me with macro expansion?
>>
>> I have a header with the following macroses defined:
>>
>> #define foo(x) x + 2
>> #define A 1
>> #define B foo(A)
>>
>> And I need get the following map:
>> A = 1
>> B = 3
>>
>> How can I do it?
>>
>
> One way:
>
> #include "your_header.h"
>
> int main() {
>   printf("A = %d\nB = %d\n", A, B);
>   return 0;
> }
>
> What additional constraints do you have? Do you need to do this using the
> Clang C++ API for some reason? Do you know in advance the names of the
> macros that you want to evaluate?
>
> I'm ale to get list of MacroInfo * classes with PPCallbacks or get it with
>> Preprocessor::macro_begin() iterator, but I don't know how to get expaneded
>> value.
>>
>> Thank you in advance.
>>
>> --
>> Alexander
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
>>
>


-- 
Alexander
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131016/ae3d3b5a/attachment.html>


More information about the cfe-dev mailing list