[cfe-dev] Lexical scope for macro expansion

Chris Lattner clattner at apple.com
Thu Dec 10 15:47:59 PST 2009

On Dec 10, 2009, at 10:25 AM, Abramo Bagnara wrote:

> Il 10/12/2009 18:37, Chris Lattner ha scritto:
>> On Dec 10, 2009, at 8:56 AM, Abramo Bagnara wrote:
>>> Is there any way from MacroExpands callback to reach current lexical scope?
>>> What I'm trying to do is to detect if some identifiers in the macro body
>>> is a known typedef id.
>> Nope, there is no way to do this, because the lexer/preprocessor
>> lives at a lower level (and macros can be used and defined in
>> multiple contexts, and don't follow the grammar of the language).
>> However, given a typedef, you can tell if it came from a macro.
> Let see if I've understand correctly:
> 1) I collect macro bodies using MacroExpands callback
> 2) I collect the spelling locations for the NameLoc of each encountered
> TypedefLoc
> 3) I scan the previously collected tokens of the macros body: if one of
> them has the same location of one of that collected in step 2 I know for
> sure that the macro body contains a typedef name
> Right?

Sounds like it could work!  I don't know the real use case you're going for here though.


More information about the cfe-dev mailing list