[cfe-dev] Clang, macros and declarations

George Kastrinis george.kastrinis at logicblox.com
Wed Aug 14 13:42:52 PDT 2013


Great. The combination of SourceManager::getDecomposedIncludedLoc and
SourceManager::getImmediateMacroCallerLoc (in a loop) (along with the
spelling location and the presumed location) seems to work for all the
cases that I tried. I just accumulate the information in a string and get a
hash afterwards.

Thank you for your help.


On Wed, Aug 14, 2013 at 12:53 PM, Eli Friedman <eli.friedman at gmail.com>wrote:

> On Wed, Aug 14, 2013 at 8:36 AM, George Kastrinis <
> george.kastrinis at logicblox.com> wrote:
>
>> Thanks. Yeah, SourceManager::getImmediateMacroCallerLoc is what we though
>> might help to get all the expansion stack and I think it helped in some
>> cases. But now we have the following issue (again from the same math
>> header!). Say you have in file a.cpp
>>
>> #define __THROW throw ()
>>
>> #define __MATHCALL(function, args) \
>>   __MATHDECL (double,function, args)
>> #define __MATHDECL(type, function, args) \
>>   __MATHDECL_1(type, function, args); \
>>   __MATHDECL_1(type, __ ## function, args)
>> #define __MATHDECL_1(type, function, args) \
>>   extern type __MATH_PRECNAME(function) args __THROW
>>
>> #define __MATH_PRECNAME(name) name
>> #include "b.h"
>> #undef __MATH_PRECNAME
>>
>> #define __MATH_PRECNAME(name) name##f
>> #include "b.h"
>> #undef __MATH_PRECNAME
>>
>> and in b.h
>>
>> __MATHCALL (cpow, (double __x, double __y));
>>
>> This will create 4 functions (cpow, __cpow, cpowf, __cpowf).
>> Using SourceManager::getImmediateMacroCallerLoc we are able to
>> differentiate for example cpow and __cpow. But there is still an issue with
>> cpow and cpowf (and with __cpow and __cpowf). Those pairs have the same
>> locations even when getting the whole expansion macro.
>>
>> Is there anything we can do to handle this case?
>>
>>
>>
> I think you also need to track the include stack.
> SourceManager::getDecomposedIncludedLoc might be useful here.
>
> -Eli
>



-- 

George Kastrinis
http://gkastrinis.info/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130814/23a84357/attachment.html>


More information about the cfe-dev mailing list