Make TokenLexer capable of storing preprocessor directive tokens

llvm-svn: 126220
This commit is contained in:
Peter Collingbourne 2011-02-22 13:49:00 +00:00
parent e16dc2a6e7
commit 2c9f966600
4 changed files with 16 additions and 4 deletions

View File

@ -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();

View File

@ -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();

View File

@ -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();
}

View File

@ -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