summaryrefslogtreecommitdiffstats
path: root/lib/Lex/TokenLexer.cpp
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-07-07 18:04:47 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-07-07 18:04:47 +0000
commit3582a6c0a35f202249b721e100229fde9de0d6a6 (patch)
tree29ec40284e0e1612844625d7dc2745c9952ce0ff /lib/Lex/TokenLexer.cpp
parent8e627066a0765a7c8df69b3ac6e4f25d8a0ce9d8 (diff)
Turn hashhash into tok::unkwown when it comes from expanding an argument, per Chris' suggestion.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134621 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/TokenLexer.cpp')
-rw-r--r--lib/Lex/TokenLexer.cpp27
1 files changed, 19 insertions, 8 deletions
diff --git a/lib/Lex/TokenLexer.cpp b/lib/Lex/TokenLexer.cpp
index 586f26fd2b..e2b002549a 100644
--- a/lib/Lex/TokenLexer.cpp
+++ b/lib/Lex/TokenLexer.cpp
@@ -193,10 +193,7 @@ void TokenLexer::ExpandFunctionArguments() {
// 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 @@ void TokenLexer::ExpandFunctionArguments() {
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 @@ void TokenLexer::ExpandFunctionArguments() {
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 @@ void TokenLexer::Lex(Token &Tok) {
// 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))