[cfe-dev] Declarations for a single file, not complete translation unit?

Douglas Gregor dgregor at apple.com
Wed Dec 29 12:51:13 PST 2010


On Dec 27, 2010, at 12:21 PM, Jacob Carlborg wrote:

> I'm working on a source to source translator which translates 
> Objective-C/C code into D code. I've subclassed ASTConsumer to create 
> something similar to the Objective-C rewriter.
> 
> The problem I have is that I'm receiving declarations for a complete 
> translation unit via HandleTopLevelDecl function. I'm wondering if it's 
> possible somehow to receive (or filter) the declarations for a single 
> file instead of a complete translation unit. I would like to have a one 
> to one mapping between the original files and the translated files.

You can filter the declarations yourself based on the location of the declaration. Use Decl::getLocation() to figure out where the declaration is, and then use SourceManager's various routines to map that down to the file where the declaration was located. If it's not in a file you care about, ignore it.

	- Doug



More information about the cfe-dev mailing list