Parser: Issue file open error messages through dedicated API

This commit is contained in:
Stephen Kelly 2016-06-09 09:58:15 +02:00
parent 8d80c8961f
commit 0a9094cd10
5 changed files with 13 additions and 26 deletions

View File

@ -23,6 +23,7 @@ struct cmListFileParser
{ {
cmListFileParser(cmListFile* lf, cmMakefile* mf, const char* filename); cmListFileParser(cmListFile* lf, cmMakefile* mf, const char* filename);
~cmListFileParser(); ~cmListFileParser();
void IssueFileOpenError(std::string const& text) const;
bool ParseFile(); bool ParseFile();
bool ParseFunction(const char* name, long line); bool ParseFunction(const char* name, long line);
bool AddArgument(cmListFileLexer_Token* token, bool AddArgument(cmListFileLexer_Token* token,
@ -54,23 +55,25 @@ cmListFileParser::~cmListFileParser()
cmListFileLexer_Delete(this->Lexer); cmListFileLexer_Delete(this->Lexer);
} }
void cmListFileParser::IssueFileOpenError(const std::string& text) const
{
this->Makefile->IssueMessage(cmake::FATAL_ERROR, text);
}
bool cmListFileParser::ParseFile() bool cmListFileParser::ParseFile()
{ {
// Open the file. // Open the file.
cmListFileLexer_BOM bom; cmListFileLexer_BOM bom;
if (!cmListFileLexer_SetFileName(this->Lexer, this->FileName, &bom)) { if (!cmListFileLexer_SetFileName(this->Lexer, this->FileName, &bom)) {
cmSystemTools::Error("cmListFileCache: error can not open file ", this->IssueFileOpenError("cmListFileCache: error can not open file.");
this->FileName);
return false; return false;
} }
// Verify the Byte-Order-Mark, if any. // Verify the Byte-Order-Mark, if any.
if (bom != cmListFileLexer_BOM_None && bom != cmListFileLexer_BOM_UTF8) { if (bom != cmListFileLexer_BOM_None && bom != cmListFileLexer_BOM_UTF8) {
cmListFileLexer_SetFileName(this->Lexer, 0, 0); cmListFileLexer_SetFileName(this->Lexer, 0, 0);
std::ostringstream m; this->IssueFileOpenError(
m << "File\n " << this->FileName << "\n" "File starts with a Byte-Order-Mark that is not UTF-8.");
<< "starts with a Byte-Order-Mark that is not UTF-8.";
this->Makefile->IssueMessage(cmake::FATAL_ERROR, m.str());
return false; return false;
} }

View File

@ -1,8 +1,4 @@
CMake Error in BOM-UTF-16-BE.cmake: CMake Error in BOM-UTF-16-BE.cmake:
File File starts with a Byte-Order-Mark that is not UTF-8.
.*/Tests/RunCMake/Syntax/BOM-UTF-16-BE.cmake
starts with a Byte-Order-Mark that is not UTF-8.
Call Stack \(most recent call first\): Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\) CMakeLists.txt:3 \(include\)

View File

@ -1,8 +1,4 @@
CMake Error in BOM-UTF-16-LE.cmake: CMake Error in BOM-UTF-16-LE.cmake:
File File starts with a Byte-Order-Mark that is not UTF-8.
.*/Tests/RunCMake/Syntax/BOM-UTF-16-LE.cmake
starts with a Byte-Order-Mark that is not UTF-8.
Call Stack \(most recent call first\): Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\) CMakeLists.txt:3 \(include\)

View File

@ -1,8 +1,4 @@
CMake Error in BOM-UTF-32-BE.cmake: CMake Error in BOM-UTF-32-BE.cmake:
File File starts with a Byte-Order-Mark that is not UTF-8.
.*/Tests/RunCMake/Syntax/BOM-UTF-32-BE.cmake
starts with a Byte-Order-Mark that is not UTF-8.
Call Stack \(most recent call first\): Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\) CMakeLists.txt:3 \(include\)

View File

@ -1,8 +1,4 @@
CMake Error in BOM-UTF-32-LE.cmake: CMake Error in BOM-UTF-32-LE.cmake:
File File starts with a Byte-Order-Mark that is not UTF-8.
.*/Tests/RunCMake/Syntax/BOM-UTF-32-LE.cmake
starts with a Byte-Order-Mark that is not UTF-8.
Call Stack \(most recent call first\): Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\) CMakeLists.txt:3 \(include\)