[cfe-dev] diff: builtin macros

Chris Lattner clattner at apple.com
Thu Sep 2 11:20:52 PDT 2010


On Sep 2, 2010, at 10:11 AM, Vladimir Kirillov wrote:

> On 09:53 Thu 02 Sep, Chris Lattner wrote:
>> Hi Vladimir,
>> 
>> What problem are you trying to solve with this? 
>> Is it sufficient to see if the macro is in the predefines buffer?
> 
> Hi Chris!
> 
> Do you mean the Preprocessor::Predefines string by the predefines
> buffer? (and suggest doing string::find() on it?)
> 
> I didn't consider taking it into account actually, but marked
> the rest of internal macros to be really 'builtin' (aren't they built in
> by the compiler by definition?).
> 
> My goal is to filter out such builtins in PPCallbacks for my data
> gathering tool.
> 
> If you don't agree with this -- i think it would be proper to refactor
> such mentions of builtins, like DefineBuiltinMacro in
> lib/Frontend/InitPreprocessor.cpp, because such macros are not really
> 'builtin' within MacroInfo context.

I'm more concerned with keeping the preprocessor as simple as possible and consistent.  "builtin" macros aren't actually macros: they're magic things that get expanded by the preprocessor like __FILE__ __COUNTER__ etc.  If you'd like to tell whether a macro is "part of the implicit gunk that clang sets up" then I think you can just check to see if the SourceLocation is part of the predefines buffer.

It looks like PrintPreprocessedOutput.cpp does this by doing this:

if (Loc.isFileID() &&
         !strcmp(SourceMgr.getPresumedLoc(Loc).getFilename(),
                 "<built-in>"))
  // it is in the predefines buffer.

Which isn't particularly elegant, but is effective :-)

-Chris



More information about the cfe-dev mailing list