diff options
Diffstat (limited to 'lib/Lex')
-rw-r--r-- | lib/Lex/PPDirectives.cpp | 8 | ||||
-rw-r--r-- | lib/Lex/PPLexerChange.cpp | 20 | ||||
-rw-r--r-- | lib/Lex/Preprocessor.cpp | 8 |
3 files changed, 17 insertions, 19 deletions
diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp index eb8664585f..417724b777 100644 --- a/lib/Lex/PPDirectives.cpp +++ b/lib/Lex/PPDirectives.cpp @@ -1098,9 +1098,8 @@ void Preprocessor::HandleIncludeDirective(Token &IncludeTok, // Ask HeaderInfo if we should enter this #include file. If not, #including // this file will have no effect. if (!HeaderInfo.ShouldEnterIncludeFile(File, isImport)) { - if (Callbacks) { + if (Callbacks) Callbacks->FileSkipped(*File, FilenameTok, FileCharacter); - } return; } @@ -1113,10 +1112,7 @@ void Preprocessor::HandleIncludeDirective(Token &IncludeTok, } // Finally, if all is good, enter the new file! - std::string ErrorStr; - if (EnterSourceFile(FID, CurDir, ErrorStr)) - Diag(FilenameTok, diag::err_pp_error_opening_file) - << std::string(SourceMgr.getFileEntryForID(FID)->getName()) << ErrorStr; + EnterSourceFile(FID, CurDir, FilenameTok.getLocation()); } /// HandleIncludeNextDirective - Implements #include_next. diff --git a/lib/Lex/PPLexerChange.cpp b/lib/Lex/PPLexerChange.cpp index 335d3db627..4a40405992 100644 --- a/lib/Lex/PPLexerChange.cpp +++ b/lib/Lex/PPLexerChange.cpp @@ -64,8 +64,8 @@ PreprocessorLexer *Preprocessor::getCurrentFileLexer() const { /// EnterSourceFile - Add a source file to the top of the include stack and /// start lexing tokens from it instead of the current buffer. -bool Preprocessor::EnterSourceFile(FileID FID, const DirectoryLookup *CurDir, - std::string &ErrorStr) { +void Preprocessor::EnterSourceFile(FileID FID, const DirectoryLookup *CurDir, + SourceLocation Loc) { assert(CurTokenLexer == 0 && "Cannot #include a file inside a macro!"); ++NumEnteredSourceFiles; @@ -75,19 +75,23 @@ bool Preprocessor::EnterSourceFile(FileID FID, const DirectoryLookup *CurDir, if (PTH) { if (PTHLexer *PL = PTH->CreateLexer(FID)) { EnterSourceFileWithPTH(PL, CurDir); - return false; + return; } } // Get the MemoryBuffer for this FID, if it fails, we fail. bool Invalid = false; - const llvm::MemoryBuffer *InputFile = getSourceManager().getBuffer(FID, - &Invalid); - if (Invalid) - return true; + const llvm::MemoryBuffer *InputFile = + getSourceManager().getBuffer(FID, Loc, &Invalid); + if (Invalid) { + SourceLocation FileStart = SourceMgr.getLocForStartOfFile(FID); + Diag(Loc, diag::err_pp_error_opening_file) + << std::string(SourceMgr.getBufferName(FileStart)) << ""; + return; + } EnterSourceFileWithLexer(new Lexer(FID, InputFile, *this), CurDir); - return false; + return; } /// EnterSourceFileWithLexer - Add a source file to the top of the include stack diff --git a/lib/Lex/Preprocessor.cpp b/lib/Lex/Preprocessor.cpp index 4598383c1c..ce6d9ab5c0 100644 --- a/lib/Lex/Preprocessor.cpp +++ b/lib/Lex/Preprocessor.cpp @@ -490,7 +490,7 @@ SourceLocation Preprocessor::getLocForEndOfToken(SourceLocation Loc, /// EnterMainSourceFile - Enter the specified FileID as the main source file, /// which implicitly adds the builtin defines etc. -bool Preprocessor::EnterMainSourceFile() { +void Preprocessor::EnterMainSourceFile() { // We do not allow the preprocessor to reenter the main file. Doing so will // cause FileID's to accumulate information from both runs (e.g. #line // information) and predefined macros aren't guaranteed to be set properly. @@ -498,9 +498,7 @@ bool Preprocessor::EnterMainSourceFile() { FileID MainFileID = SourceMgr.getMainFileID(); // Enter the main file source buffer. - std::string ErrorStr; - if (EnterSourceFile(MainFileID, 0, ErrorStr)) - return true; + EnterSourceFile(MainFileID, 0, SourceLocation()); // Tell the header info that the main file was entered. If the file is later // #imported, it won't be re-entered. @@ -515,7 +513,7 @@ bool Preprocessor::EnterMainSourceFile() { assert(!FID.isInvalid() && "Could not create FileID for predefines?"); // Start parsing the predefines. - return EnterSourceFile(FID, 0, ErrorStr); + EnterSourceFile(FID, 0, SourceLocation()); } void Preprocessor::EndSourceFile() { |