Changeset View
Changeset View
Standalone View
Standalone View
clang/lib/Lex/Lexer.cpp
Show First 20 Lines • Show All 2,805 Lines • ▼ Show 20 Lines | bool Lexer::LexEndOfFile(Token &Result, const char *CurPtr) { | ||||
// If we are in a #if directive, emit an error. | // If we are in a #if directive, emit an error. | ||||
while (!ConditionalStack.empty()) { | while (!ConditionalStack.empty()) { | ||||
if (PP->getCodeCompletionFileLoc() != FileLoc) | if (PP->getCodeCompletionFileLoc() != FileLoc) | ||||
PP->Diag(ConditionalStack.back().IfLoc, | PP->Diag(ConditionalStack.back().IfLoc, | ||||
diag::err_pp_unterminated_conditional); | diag::err_pp_unterminated_conditional); | ||||
ConditionalStack.pop_back(); | ConditionalStack.pop_back(); | ||||
} | } | ||||
SourceLocation EndLoc = getSourceLocation(BufferEnd); | |||||
// C99 5.1.1.2p2: If the file is non-empty and didn't end in a newline, issue | // C99 5.1.1.2p2: If the file is non-empty and didn't end in a newline, issue | ||||
// a pedwarn. | // a pedwarn. | ||||
if (CurPtr != BufferStart && (CurPtr[-1] != '\n' && CurPtr[-1] != '\r')) { | if (CurPtr != BufferStart && (CurPtr[-1] != '\n' && CurPtr[-1] != '\r')) { | ||||
DiagnosticsEngine &Diags = PP->getDiagnostics(); | DiagnosticsEngine &Diags = PP->getDiagnostics(); | ||||
SourceLocation EndLoc = getSourceLocation(BufferEnd); | |||||
unsigned DiagID; | unsigned DiagID; | ||||
if (LangOpts.CPlusPlus11) { | if (LangOpts.CPlusPlus11) { | ||||
// C++11 [lex.phases] 2.2 p2 | // C++11 [lex.phases] 2.2 p2 | ||||
// Prefer the C++98 pedantic compatibility warning over the generic, | // Prefer the C++98 pedantic compatibility warning over the generic, | ||||
// non-extension, user-requested "missing newline at EOF" warning. | // non-extension, user-requested "missing newline at EOF" warning. | ||||
if (!Diags.isIgnored(diag::warn_cxx98_compat_no_newline_eof, EndLoc)) { | if (!Diags.isIgnored(diag::warn_cxx98_compat_no_newline_eof, EndLoc)) { | ||||
DiagID = diag::warn_cxx98_compat_no_newline_eof; | DiagID = diag::warn_cxx98_compat_no_newline_eof; | ||||
} else { | } else { | ||||
DiagID = diag::warn_no_newline_eof; | DiagID = diag::warn_no_newline_eof; | ||||
} | } | ||||
} else { | } else { | ||||
DiagID = diag::ext_no_newline_eof; | DiagID = diag::ext_no_newline_eof; | ||||
} | } | ||||
Diag(BufferEnd, DiagID) | Diag(BufferEnd, DiagID) | ||||
<< FixItHint::CreateInsertion(EndLoc, "\n"); | << FixItHint::CreateInsertion(EndLoc, "\n"); | ||||
} | } | ||||
BufferPtr = CurPtr; | BufferPtr = CurPtr; | ||||
// Finally, let the preprocessor handle this. | // Finally, let the preprocessor handle this. | ||||
return PP->HandleEndOfFile(Result, isPragmaLexer()); | return PP->HandleEndOfFile(Result, EndLoc, isPragmaLexer()); | ||||
} | } | ||||
/// isNextPPTokenLParen - Return 1 if the next unexpanded token lexed from | /// isNextPPTokenLParen - Return 1 if the next unexpanded token lexed from | ||||
/// the specified lexer will return a tok::l_paren token, 0 if it is something | /// the specified lexer will return a tok::l_paren token, 0 if it is something | ||||
/// else and 2 if there are no more tokens in the buffer controlled by the | /// else and 2 if there are no more tokens in the buffer controlled by the | ||||
/// lexer. | /// lexer. | ||||
unsigned Lexer::isNextPPTokenLParen() { | unsigned Lexer::isNextPPTokenLParen() { | ||||
assert(!LexingRawMode && "How can we expand a macro from a skipping buffer?"); | assert(!LexingRawMode && "How can we expand a macro from a skipping buffer?"); | ||||
▲ Show 20 Lines • Show All 1,170 Lines • Show Last 20 Lines |