<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Mar 2, 2017 at 1:10 AM, Stephan Bergmann via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">My problem is as follows:  I have a FunctionDecl d for which I know that d->isConstexpr(), so somewhere in d->getSourceRange() the token "constexpr" should appear.  Now, I want to know whether that "constexpr" is from the expansion of a specific object-like macro<br>
<br>
  #define M constexpr<br>
<br>
(whose use could be nested in some other macros, so it's important here to look into macro invocations in general).<br>
<br>
I'm trying to traverse d->getSourceRange() with Lexer::MeasureTokenLength/Sour<wbr>ceManager::getCharacterData to get at a token's content, then SourceLocation::getLocWithOffs<wbr>et to get at the next token.  Which works more-or-less well.  However:<br>
<br>
* When d->getSourceRange() happens to start off within a macro expansion, I could fall off its end before reaching the declaration's end.  This one is easy, I can use SourceManager::isAtEndOfImmedi<wbr>ateMacroExpansion to climb back out of the macro expansion and continue traversal one level further out.<br>
<br>
* But when the traversal reaches a macro invocation, I get the token of that invocation (multiple tokens in case of a function-like macro with its parentheses and arguments), without a clue that it is a macro and without a way to step into its expansion.  Am I missing anything, or is there just no way to do that?<br></blockquote><div><br></div><div>You might try to make a lexer to Lex(token) for you until you've reached the end of the range, rather than navigating by source locations.  Though actually I think we should make the AST record the location of the `constexpr` keyword, so that applications don't have to jump through these hoops.</div><div><br></div><div>-- James</div></div></div></div>