diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2011-02-22 13:49:00 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2011-02-22 13:49:00 +0000 |
commit | b2eb53d9fd973a1a02e05e67a3307b3efd12eff2 (patch) | |
tree | f739b1262129ef9487501a10293d43928e82bd73 | |
parent | cf603e1b1e2353d88171d04e9580b9688854b953 (diff) |
Make TokenLexer capable of storing preprocessor directive tokens
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126220 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Lex/TokenLexer.h | 4 | ||||
-rw-r--r-- | lib/Lex/PPDirectives.cpp | 8 | ||||
-rw-r--r-- | lib/Lex/Pragma.cpp | 3 | ||||
-rw-r--r-- | lib/Lex/TokenLexer.cpp | 5 |
4 files changed, 16 insertions, 4 deletions
diff --git a/include/clang/Lex/TokenLexer.h b/include/clang/Lex/TokenLexer.h index 3f13e9cc12..6ae00cd586 100644 --- a/include/clang/Lex/TokenLexer.h +++ b/include/clang/Lex/TokenLexer.h @@ -121,6 +121,10 @@ public: /// Lex - Lex and return a token from this macro stream. void Lex(Token &Tok); + /// isParsingPreprocessorDirective - Return true if we are in the middle of a + /// preprocessor directive. + bool isParsingPreprocessorDirective() const; + private: void destroy(); diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp index 0f0d25b887..f92fa038a3 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/lib/Lex/PPDirectives.cpp @@ -167,10 +167,12 @@ void Preprocessor::CheckEndOfDirective(const char *DirType, bool EnableMacros) { if (Tmp.isNot(tok::eom)) { // Add a fixit in GNU/C99/C++ mode. Don't offer a fixit for strict-C89, - // because it is more trouble than it is worth to insert /**/ and check that - // there is no /**/ in the range also. + // or if this is a macro-style preprocessing directive, because it is more + // trouble than it is worth to insert /**/ and check that there is no /**/ + // in the range also. FixItHint Hint; - if (Features.GNUMode || Features.C99 || Features.CPlusPlus) + if ((Features.GNUMode || Features.C99 || Features.CPlusPlus) && + !CurTokenLexer) Hint = FixItHint::CreateInsertion(Tmp.getLocation(),"//"); Diag(Tmp, diag::ext_pp_extra_tokens_at_eol) << DirType << Hint; DiscardUntilEndOfDirective(); diff --git a/lib/Lex/Pragma.cpp b/lib/Lex/Pragma.cpp index f0475bc0cb..31e777604e 100644 --- a/lib/Lex/Pragma.cpp +++ b/lib/Lex/Pragma.cpp @@ -110,7 +110,8 @@ void Preprocessor::HandlePragmaDirective(unsigned Introducer) { PragmaHandlers->HandlePragma(*this, PragmaIntroducerKind(Introducer), Tok); // If the pragma handler didn't read the rest of the line, consume it now. - if (CurPPLexer && CurPPLexer->ParsingPreprocessorDirective) + if ((CurTokenLexer && CurTokenLexer->isParsingPreprocessorDirective()) + || (CurPPLexer && CurPPLexer->ParsingPreprocessorDirective)) DiscardUntilEndOfDirective(); } diff --git a/lib/Lex/TokenLexer.cpp b/lib/Lex/TokenLexer.cpp index ea39b47904..caa44bf4a1 100644 --- a/lib/Lex/TokenLexer.cpp +++ b/lib/Lex/TokenLexer.cpp @@ -543,6 +543,11 @@ unsigned TokenLexer::isNextTokenLParen() const { return Tokens[CurToken].is(tok::l_paren); } +/// isParsingPreprocessorDirective - Return true if we are in the middle of a +/// preprocessor directive. +bool TokenLexer::isParsingPreprocessorDirective() const { + return Tokens[NumTokens-1].is(tok::eom) && !isAtEnd(); +} /// HandleMicrosoftCommentPaste - In microsoft compatibility mode, /##/ pastes /// together to form a comment that comments out everything in the current |