[cfe-dev] A Clang plugin which iterates over macro declarations

Joshua Cranmer 🐧 Pidgeot18 at gmail.com
Fri Jul 4 12:10:02 PDT 2014


On 7/4/2014 7:14 AM, Reed Mangino wrote:
> Hi,
> I know how to write a function pass in LLVM to iterate over function 
> decls. I'd like to do something similiar using Clang for C/C++/ObjC 
> macros (#define foo).
> I haven't been able to find anything in the docs which describes how 
> to hook into Clang's preprocessing phase. Did I just miss it? Are 
> there any samples which demonstrate this?
<https://github.com/mozilla/dxr/blob/master/dxr/plugins/clang/dxr-index.cpp#L956> 
and onwards (until about 1087 or so) is the code in DXR that handles 
preprocessor callbacks. There's a bit of nastiness to account for trying 
to support multiple versions of Clang via preprocessor declarations, and 
I use a thunk class to take into account the fact that I'm trying to use 
the same class as both an ASTConsumer and a PPCallbacks, which causes 
issue with double deletes if I don't use a thunk (it's also useful for 
glossing over API differences). The thunk is defined here: 
<https://github.com/mozilla/dxr/blob/master/dxr/plugins/clang/dxr-index.cpp#L87> 
and used here: 
<https://github.com/mozilla/dxr/blob/master/dxr/plugins/clang/dxr-index.cpp#L161>.

-- 
Joshua Cranmer
Thunderbird and DXR developer
Source code archæologist

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


More information about the cfe-dev mailing list