summaryrefslogtreecommitdiffstats
path: root/clang/lib/Lex
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
commitdccf6e194848852a8cbfb8795174e6817ef034f1 (patch)
tree46dbbad375e236f55d5ea57ef8cbb6634f382ff0 /clang/lib/Lex
parentbf8cc60d1b4a4c4ba3013c6b6f77b98854817f6d (diff)
downloadbcm5719-llvm-dccf6e194848852a8cbfb8795174e6817ef034f1.tar.gz
bcm5719-llvm-dccf6e194848852a8cbfb8795174e6817ef034f1.zip
Turn hashhash into tok::unkwown when it comes from expanding an argument, per Chris' suggestion.
llvm-svn: 134621
Diffstat (limited to 'clang/lib/Lex')
-rw-r--r--clang/lib/Lex/TokenLexer.cpp27
1 files changed, 19 insertions, 8 deletions
diff --git a/clang/lib/Lex/TokenLexer.cpp b/clang/lib/Lex/TokenLexer.cpp
index 586f26fd2bc..e2b002549a3 100644
--- a/clang/lib/Lex/TokenLexer.cpp
+++ b/clang/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))
OpenPOWER on IntegriCloud