diff options
author | Justin Bogner <mail@justinbogner.com> | 2014-02-04 19:18:37 +0000 |
---|---|---|
committer | Justin Bogner <mail@justinbogner.com> | 2014-02-04 19:18:37 +0000 |
commit | d554a8eb91116cf055f36e3ffe34cb262a110fd5 (patch) | |
tree | 6870d8d8055dcdde2ba408ce299c22365fc0180e /clang/lib/Lex/TokenLexer.cpp | |
parent | 79c93845f6229465f1b0c710cacc60c21f7b9bf6 (diff) | |
download | bcm5719-llvm-d554a8eb91116cf055f36e3ffe34cb262a110fd5.tar.gz bcm5719-llvm-d554a8eb91116cf055f36e3ffe34cb262a110fd5.zip |
Clean up whitespace checks
In TokenLexer::ExpandFunctionArguments(), CurTok.hasLeadingSpace() is
checked in multiple locations, each time subtly differently. Checking it
early, when the token is seen, and using NextTokGetsSpace exclusively
after that makes the code simpler.
No change in behaviour is intended.
Patch by Harald van Dijk!
llvm-svn: 200788
Diffstat (limited to 'clang/lib/Lex/TokenLexer.cpp')
-rw-r--r-- | clang/lib/Lex/TokenLexer.cpp | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/clang/lib/Lex/TokenLexer.cpp b/clang/lib/Lex/TokenLexer.cpp index 307e781cae8..9913f3087a1 100644 --- a/clang/lib/Lex/TokenLexer.cpp +++ b/clang/lib/Lex/TokenLexer.cpp @@ -183,6 +183,9 @@ void TokenLexer::ExpandFunctionArguments() { // preprocessor already verified that the following token is a macro name // when the #define was parsed. const Token &CurTok = Tokens[i]; + if (i != 0 && !Tokens[i-1].is(tok::hashhash) && CurTok.hasLeadingSpace()) + NextTokGetsSpace = true; + if (CurTok.is(tok::hash) || CurTok.is(tok::hashat)) { int ArgNo = Macro->getArgumentNum(Tokens[i+1].getIdentifierInfo()); assert(ArgNo != -1 && "Token following # is not an argument?"); @@ -207,7 +210,7 @@ void TokenLexer::ExpandFunctionArguments() { // The stringified/charified string leading space flag gets set to match // the #/#@ operator. - if (CurTok.hasLeadingSpace() || NextTokGetsSpace) + if (NextTokGetsSpace) Res.setFlag(Token::LeadingSpace); ResultToks.push_back(Res); @@ -301,14 +304,8 @@ void TokenLexer::ExpandFunctionArguments() { // before the first token should match the whitespace of the arg // identifier. ResultToks[FirstResult].setFlagValue(Token::LeadingSpace, - CurTok.hasLeadingSpace() || NextTokGetsSpace); NextTokGetsSpace = false; - } else { - // If this is an empty argument, if there was whitespace before the - // formal token, and this is not the first token in the macro - // definition, make sure the next token gets whitespace before it. - NextTokGetsSpace |= i != 0 && CurTok.hasLeadingSpace(); } continue; } @@ -356,8 +353,7 @@ void TokenLexer::ExpandFunctionArguments() { // assembler-with-cpp mode, invalid pastes are allowed through: in this // case, we do not want the extra whitespace to be added. For example, // we want ". ## foo" -> ".foo" not ". foo". - if ((CurTok.hasLeadingSpace() && !PasteBefore) || - (NextTokGetsSpace && !NonEmptyPasteBefore)) + if (NextTokGetsSpace) ResultToks[ResultToks.size()-NumToks].setFlag(Token::LeadingSpace); NextTokGetsSpace = false; @@ -368,8 +364,6 @@ void TokenLexer::ExpandFunctionArguments() { // 6.10.3.3p2,3) calls for a bunch of placemarker stuff to occur. We // implement this by eating ## operators when a LHS or RHS expands to // empty. - if (!PasteBefore) - NextTokGetsSpace |= i != 0 && CurTok.hasLeadingSpace(); if (PasteAfter) { // Discard the argument token and skip (don't copy to the expansion // buffer) the paste operator after it. |