[cfe-dev] pre-processor object macros and literals

Douglas Gregor dgregor at apple.com
Mon Feb 7 07:39:13 PST 2011

On Feb 5, 2011, at 12:47 PM, Stephen Siegel wrote:

> If a pre-procesor object-like macro is used to define a literal value, such as in the example below (#define STEVE 345), is there any way to retrieve the name ("STEVE") from the AST?  In the example, I have printed the AST, and the right-hand side of the assignment statement is represented as:
>              <IntegerLiteral file="f2" line="2" col="15" type="_1F" value="345"/>
> The line and column numbers do refer to the line with the #define,  but the name "STEVE" does not seem to be stored anywhere.

This information can be extracted from Clang's in-memory AST, but it is not part of the XML output. In the in-memory AST, the source location of the integer literal will point into a macro instantiation, which you can map back to the tokens in the source code.

  - Doug
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110207/87d4660a/attachment.html>

More information about the cfe-dev mailing list