[cfe-dev] Clang, macros and declarations

Jacob Carlborg doob at me.com
Wed Aug 14 00:50:35 PDT 2013


On 2013-08-13 20:17, George Kastrinis wrote:
> Hi all,
>
> We are working on a Clang plugin, and we wan to have a way to uniquely
> identify every declaration in a C++ program. We tried using the following.
> (presumed location start, presumed location end, spelling location
> start, spelling location end, declaration kind)
>
> But we still have a problem.
>
> For example, in /usr/include/x86_64-linux-gnu/bits/cmathcalls.h, line
> 101 a macro called _MATHCALL is used. If you look at
> /usr/include/complex.h, line 65 where the macro is defined, you will see
> that the macro uses other macros inside and create two functions (e.g.
> cpowf and __cpowf)
>
> I tried using spelling locations, presumed locations,
> SourceManager::getExpansionLoc on the spelling location. All give the
> same locations for cpowf and __cpowf.
>
> Is there any way to achieve what I try to do here?

I don't know if this is the right solution but the C API in Clang has 
functions to do cross references in the AST. I assume that API uses some 
unique way to identify the entities.

I'm thinking of clang_getCursorUSR:

http://clang.llvm.org/doxygen/group__CINDEX__CURSOR__XREF.html#ga51679cb755bbd94cc5e9476c685f2df3

Perhaps it's possible to reuse.

-- 
/Jacob Carlborg




More information about the cfe-dev mailing list