mirror of
https://gitlab.kitware.com/cmake/cmake.git
synced 2026-10-07 04:02:23 +03:00
Merge topic 'listfile-string'
b4c6db0f52 cmListFile: Use `std::string` in place of `const char*`
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !11793
This commit is contained in:
commit
9e485212b0
5 files changed
+32
-45
No files matched your search
+21
-32
@@ -48,12 +48,12 @@ class cmListFileParser
|
||||
{
|
||||
public:
|
||||
cmListFileParser(cmListFile* lf, cmListFileBacktrace lfbt,
|
||||
cmMessenger* messenger);
|
||||
cmMessenger* messenger, std::string const& filename);
|
||||
cmListFileParser(cmListFileParser const&) = delete;
|
||||
cmListFileParser& operator=(cmListFileParser const&) = delete;
|
||||
|
||||
bool ParseFile(char const* filename);
|
||||
bool ParseString(cm::string_view str, char const* virtual_filename);
|
||||
bool ParseFile();
|
||||
bool ParseString(cm::string_view str);
|
||||
|
||||
private:
|
||||
bool Parse();
|
||||
@@ -75,7 +75,7 @@ private:
|
||||
cmListFile* ListFile;
|
||||
cmListFileBacktrace Backtrace;
|
||||
cmMessenger* Messenger;
|
||||
char const* FileName = nullptr;
|
||||
std::string const& FileName;
|
||||
std::unique_ptr<cmListFileLexer, void (*)(cmListFileLexer*)> Lexer;
|
||||
std::string FunctionName;
|
||||
long FunctionLine;
|
||||
@@ -84,10 +84,12 @@ private:
|
||||
};
|
||||
|
||||
cmListFileParser::cmListFileParser(cmListFile* lf, cmListFileBacktrace lfbt,
|
||||
cmMessenger* messenger)
|
||||
cmMessenger* messenger,
|
||||
std::string const& filename)
|
||||
: ListFile(lf)
|
||||
, Backtrace(std::move(lfbt))
|
||||
, Messenger(messenger)
|
||||
, FileName(filename)
|
||||
, Lexer(cmListFileLexer_New(), cmListFileLexer_Delete)
|
||||
{
|
||||
}
|
||||
@@ -109,19 +111,20 @@ void cmListFileParser::IssueError(std::string const& text) const
|
||||
cmSystemTools::SetFatalErrorOccurred();
|
||||
}
|
||||
|
||||
bool cmListFileParser::ParseFile(char const* filename)
|
||||
bool cmListFileParser::ParseFile()
|
||||
{
|
||||
this->FileName = filename;
|
||||
std::string const* filename = &this->FileName;
|
||||
|
||||
#ifdef _WIN32
|
||||
std::string expandedFileName = cmsys::Encoding::ToNarrow(
|
||||
cmSystemTools::ConvertToWindowsExtendedPath(filename));
|
||||
filename = expandedFileName.c_str();
|
||||
cmSystemTools::ConvertToWindowsExtendedPath(*filename));
|
||||
filename = &expandedFileName;
|
||||
#endif
|
||||
|
||||
// Open the file.
|
||||
cmListFileLexer_BOM bom;
|
||||
if (!cmListFileLexer_SetFileName(this->Lexer.get(), filename, &bom)) {
|
||||
if (!cmListFileLexer_SetFileName(this->Lexer.get(), filename->c_str(),
|
||||
&bom)) {
|
||||
this->IssueFileOpenError("cmListFileCache: error can not open file.");
|
||||
return false;
|
||||
}
|
||||
@@ -137,11 +140,8 @@ bool cmListFileParser::ParseFile(char const* filename)
|
||||
return this->Parse();
|
||||
}
|
||||
|
||||
bool cmListFileParser::ParseString(cm::string_view str,
|
||||
char const* virtual_filename)
|
||||
bool cmListFileParser::ParseString(cm::string_view str)
|
||||
{
|
||||
this->FileName = virtual_filename;
|
||||
|
||||
if (!cmListFileLexer_SetString(this->Lexer.get(), str.data(),
|
||||
str.length())) {
|
||||
this->IssueFileOpenError("cmListFileCache: cannot allocate buffer.");
|
||||
@@ -422,7 +422,7 @@ cm::optional<cmListFileContext> cmListFileParser::CheckNesting() const
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
bool cmListFile::ParseFile(char const* filename, cmMessenger* messenger,
|
||||
bool cmListFile::ParseFile(std::string const& filename, cmMessenger* messenger,
|
||||
cmListFileBacktrace const& lfbt)
|
||||
{
|
||||
if (!cmSystemTools::FileExists(filename) ||
|
||||
@@ -430,28 +430,17 @@ bool cmListFile::ParseFile(char const* filename, cmMessenger* messenger,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool parseError = false;
|
||||
|
||||
{
|
||||
cmListFileParser parser(this, lfbt, messenger);
|
||||
parseError = !parser.ParseFile(filename);
|
||||
}
|
||||
|
||||
return !parseError;
|
||||
cmListFileParser parser(this, lfbt, messenger, filename);
|
||||
return parser.ParseFile();
|
||||
}
|
||||
|
||||
bool cmListFile::ParseString(cm::string_view str, char const* virtual_filename,
|
||||
bool cmListFile::ParseString(cm::string_view str,
|
||||
std::string const& virtual_filename,
|
||||
cmMessenger* messenger,
|
||||
cmListFileBacktrace const& lfbt)
|
||||
{
|
||||
bool parseError = false;
|
||||
|
||||
{
|
||||
cmListFileParser parser(this, lfbt, messenger);
|
||||
parseError = !parser.ParseString(str, virtual_filename);
|
||||
}
|
||||
|
||||
return !parseError;
|
||||
cmListFileParser parser(this, lfbt, messenger, virtual_filename);
|
||||
return parser.ParseString(str);
|
||||
}
|
||||
|
||||
#include "cmStack.tcc"
|
||||
|
||||
@@ -239,10 +239,10 @@ std::vector<BT<std::string>> cmExpandListWithBacktrace(
|
||||
|
||||
struct cmListFile
|
||||
{
|
||||
bool ParseFile(char const* path, cmMessenger* messenger,
|
||||
bool ParseFile(std::string const& path, cmMessenger* messenger,
|
||||
cmListFileBacktrace const& lfbt);
|
||||
|
||||
bool ParseString(cm::string_view str, char const* virtual_filename,
|
||||
bool ParseString(cm::string_view str, std::string const& virtual_filename,
|
||||
cmMessenger* messenger, cmListFileBacktrace const& lfbt);
|
||||
|
||||
std::vector<cmListFileFunction> Functions;
|
||||
|
||||
@@ -682,7 +682,7 @@ bool cmMakefile::ReadDependentFile(std::string const& filename,
|
||||
#endif
|
||||
|
||||
cmListFile listFile;
|
||||
if (!listFile.ParseFile(filenametoread.c_str(), this->GetMessenger(),
|
||||
if (!listFile.ParseFile(filenametoread, this->GetMessenger(),
|
||||
this->Backtrace)) {
|
||||
#ifdef CMake_ENABLE_DEBUGGER
|
||||
if (this->GetCMakeInstance()->GetDebugAdapter()) {
|
||||
@@ -805,7 +805,7 @@ bool cmMakefile::ReadListFile(std::string const& filename)
|
||||
#endif
|
||||
|
||||
cmListFile listFile;
|
||||
if (!listFile.ParseFile(filenametoread.c_str(), this->GetMessenger(),
|
||||
if (!listFile.ParseFile(filenametoread, this->GetMessenger(),
|
||||
this->Backtrace)) {
|
||||
#ifdef CMake_ENABLE_DEBUGGER
|
||||
if (this->GetCMakeInstance()->GetDebugAdapter()) {
|
||||
@@ -840,8 +840,8 @@ bool cmMakefile::ReadListFileAsString(std::string const& content,
|
||||
ListFileScope scope(this, filenametoread);
|
||||
|
||||
cmListFile listFile;
|
||||
if (!listFile.ParseString(content, virtualFileName.c_str(),
|
||||
this->GetMessenger(), this->Backtrace)) {
|
||||
if (!listFile.ParseString(content, virtualFileName, this->GetMessenger(),
|
||||
this->Backtrace)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1594,7 +1594,7 @@ void cmMakefile::Configure()
|
||||
#endif
|
||||
|
||||
cmListFile listFile;
|
||||
if (!listFile.ParseFile(currentStart.c_str(), this->GetMessenger(),
|
||||
if (!listFile.ParseFile(currentStart, this->GetMessenger(),
|
||||
this->Backtrace)) {
|
||||
#ifdef CMake_ENABLE_DEBUGGER
|
||||
if (this->GetCMakeInstance()->GetDebugAdapter()) {
|
||||
|
||||
@@ -72,8 +72,8 @@ public:
|
||||
Client->bind(server2client, client2server);
|
||||
Debugger->bind(client2server, server2client);
|
||||
}
|
||||
std::vector<cmListFileFunction> CreateListFileFunctions(char const* str,
|
||||
char const* filename)
|
||||
std::vector<cmListFileFunction> CreateListFileFunctions(
|
||||
char const* str, std::string const& filename)
|
||||
{
|
||||
cmMessenger messenger;
|
||||
cmListFileBacktrace backtrace;
|
||||
|
||||
@@ -75,8 +75,7 @@ static bool testHandleBreakpointRequestAfterFileIsLoaded()
|
||||
helper.bind();
|
||||
std::string sourcePath = "C:/CMakeLists.txt";
|
||||
std::vector<cmListFileFunction> functions = helper.CreateListFileFunctions(
|
||||
"# Comment1\nset(var1 foo)\n# Comment2\nset(var2\nbar)\n",
|
||||
sourcePath.c_str());
|
||||
"# Comment1\nset(var1 foo)\n# Comment2\nset(var2\nbar)\n", sourcePath);
|
||||
|
||||
breakpointManager.SourceFileLoaded(sourcePath, functions);
|
||||
dap::SetBreakpointsRequest setBreakpointRequest;
|
||||
@@ -149,8 +148,7 @@ static bool testSourceFileLoadedAfterHandleBreakpointRequest()
|
||||
sourceBreakpoints[4].line = 5;
|
||||
setBreakpointRequest.breakpoints = sourceBreakpoints;
|
||||
std::vector<cmListFileFunction> functions = helper.CreateListFileFunctions(
|
||||
"# Comment1\nset(var1 foo)\n# Comment2\nset(var2\nbar)\n",
|
||||
sourcePath.c_str());
|
||||
"# Comment1\nset(var1 foo)\n# Comment2\nset(var2\nbar)\n", sourcePath);
|
||||
auto got = helper.Client->send(setBreakpointRequest).get();
|
||||
|
||||
// Act
|
||||
|
||||
Reference in new issue
Block a user