[cfe-commits] r134621 - /cfe/trunk/lib/Lex/TokenLexer.cpp
Argyrios Kyrtzidis
akyrtzi at gmail.com
Thu Jul 7 11:04:47 PDT 2011
Author: akirtzidis
Date: Thu Jul 7 13:04:47 2011
New Revision: 134621
URL: http://llvm.org/viewvc/llvm-project?rev=134621&view=rev
Log:
Turn hashhash into tok::unkwown when it comes from expanding an argument, per Chris' suggestion.
Modified:
cfe/trunk/lib/Lex/TokenLexer.cpp
Modified: cfe/trunk/lib/Lex/TokenLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/TokenLexer.cpp?rev=134621&r1=134620&r2=134621&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/TokenLexer.cpp (original)
+++ cfe/trunk/lib/Lex/TokenLexer.cpp Thu Jul 7 13:04:47 2011
@@ -193,10 +193,7 @@
// Otherwise, this is a use of the argument. Find out if there is a paste
// (##) operator before or after the argument.
bool PasteBefore =
- !ResultToks.empty() && ResultToks.back().is(tok::hashhash) &&
- // If the '##' came from expanding an argument,treat it as a normal token.
- SM.isBeforeInSourceLocationOffset(ResultToks.back().getLocation(),
- MacroStartSLocOffset);
+ !ResultToks.empty() && ResultToks.back().is(tok::hashhash);
bool PasteAfter = i+1 != e && Tokens[i+1].is(tok::hashhash);
// If it is not the LHS/RHS of a ## operator, we must pre-expand the
@@ -219,6 +216,14 @@
unsigned NumToks = MacroArgs::getArgLength(ResultArgToks);
ResultToks.append(ResultArgToks, ResultArgToks+NumToks);
+ // If the '##' came from expanding an argument, turn it into 'unknown'
+ // to avoid pasting.
+ for (unsigned i = FirstResult, e = ResultToks.size(); i != e; ++i) {
+ Token &Tok = ResultToks[i];
+ if (Tok.is(tok::hashhash))
+ Tok.setKind(tok::unknown);
+ }
+
if(InstantiateLocStart.isValid()) {
SourceLocation curInst =
getMacroExpansionLocation(CurTok.getLocation());
@@ -267,6 +272,15 @@
ResultToks.append(ArgToks, ArgToks+NumToks);
+ // If the '##' came from expanding an argument, turn it into 'unknown'
+ // to avoid pasting.
+ for (unsigned i = ResultToks.size() - NumToks, e = ResultToks.size();
+ i != e; ++i) {
+ Token &Tok = ResultToks[i];
+ if (Tok.is(tok::hashhash))
+ Tok.setKind(tok::unknown);
+ }
+
if(InstantiateLocStart.isValid()) {
SourceLocation curInst =
getMacroExpansionLocation(CurTok.getLocation());
@@ -387,10 +401,7 @@
// If this token is followed by a token paste (##) operator, paste the tokens!
// Note that ## is a normal token when not expanding a macro.
- if (!isAtEnd() && Tokens[CurToken].is(tok::hashhash) && Macro &&
- // If the '##' came from expanding an argument,treat it as a normal token.
- SM.isBeforeInSourceLocationOffset(Tokens[CurToken].getLocation(),
- MacroStartSLocOffset)) {
+ if (!isAtEnd() && Tokens[CurToken].is(tok::hashhash) && Macro) {
// When handling the microsoft /##/ extension, the final token is
// returned by PasteTokens, not the pasted token.
if (PasteTokens(Tok))
More information about the cfe-commits
mailing list