From 1462576bcba68310395a7185e4b77da38e1e6b33 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 28 Jan 2016 22:10:28 +0100 Subject: [PATCH] Parser: Port away from cmMakefile It is an unneeded dependency. --- Source/cmListFileCache.cxx | 31 ++++++++++++++++--------------- Source/cmListFileCache.h | 5 +++-- Source/cmMakefile.cxx | 15 ++++++++++++--- Source/cmMakefile.h | 1 + 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx index 9204d1480..39d9e9704 100644 --- a/Source/cmListFileCache.cxx +++ b/Source/cmListFileCache.cxx @@ -12,7 +12,7 @@ #include "cmListFileCache.h" #include "cmListFileLexer.h" -#include "cmMakefile.h" +#include "cmMessenger.h" #include "cmOutputConverter.h" #include "cmSystemTools.h" #include "cmVersion.h" @@ -21,7 +21,8 @@ struct cmListFileParser { - cmListFileParser(cmListFile* lf, cmMakefile* mf, const char* filename); + cmListFileParser(cmListFile* lf, cmListFileBacktrace lfbt, + cmMessenger* messenger, const char* filename); ~cmListFileParser(); void IssueFileOpenError(std::string const& text) const; void IssueError(std::string const& text) const; @@ -30,8 +31,8 @@ struct cmListFileParser bool AddArgument(cmListFileLexer_Token* token, cmListFileArgument::Delimiter delim); cmListFile* ListFile; - cmMakefile* Makefile; cmListFileBacktrace Backtrace; + cmMessenger* Messenger; const char* FileName; cmListFileLexer* Lexer; cmListFileFunction Function; @@ -43,11 +44,12 @@ struct cmListFileParser } Separation; }; -cmListFileParser::cmListFileParser(cmListFile* lf, cmMakefile* mf, +cmListFileParser::cmListFileParser(cmListFile* lf, cmListFileBacktrace lfbt, + cmMessenger* messenger, const char* filename) : ListFile(lf) - , Makefile(mf) - , Backtrace(mf->GetBacktrace()) + , Backtrace(lfbt) + , Messenger(messenger) , FileName(filename) , Lexer(cmListFileLexer_New()) { @@ -60,7 +62,7 @@ cmListFileParser::~cmListFileParser() void cmListFileParser::IssueFileOpenError(const std::string& text) const { - this->Makefile->IssueMessage(cmake::FATAL_ERROR, text); + this->Messenger->IssueMessage(cmake::FATAL_ERROR, text, this->Backtrace); } void cmListFileParser::IssueError(const std::string& text) const @@ -70,8 +72,7 @@ void cmListFileParser::IssueError(const std::string& text) const lfc.Line = cmListFileLexer_GetCurrentLine(this->Lexer); cmListFileBacktrace lfbt = this->Backtrace; lfbt = lfbt.Push(lfc); - this->Makefile->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, text, - lfbt); + this->Messenger->IssueMessage(cmake::FATAL_ERROR, text, lfbt); cmSystemTools::SetFatalErrorOccured(); } @@ -129,7 +130,8 @@ bool cmListFileParser::ParseFile() return true; } -bool cmListFile::ParseFile(const char* filename, cmMakefile* mf) +bool cmListFile::ParseFile(const char* filename, cmMessenger* messenger, + cmListFileBacktrace const& lfbt) { if (!cmSystemTools::FileExists(filename) || cmSystemTools::FileIsDirectory(filename)) { @@ -139,7 +141,7 @@ bool cmListFile::ParseFile(const char* filename, cmMakefile* mf) bool parseError = false; { - cmListFileParser parser(this, mf, filename); + cmListFileParser parser(this, lfbt, messenger, filename); parseError = !parser.ParseFile(); } @@ -242,8 +244,7 @@ bool cmListFileParser::ParseFunction(const char* name, long line) lfbt = lfbt.Push(lfc); error << "Parse error. Function missing ending \")\". " << "End of file reached."; - this->Makefile->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, - error.str(), lfbt); + this->Messenger->IssueMessage(cmake::FATAL_ERROR, error.str(), lfbt); return false; } @@ -269,10 +270,10 @@ bool cmListFileParser::AddArgument(cmListFileLexer_Token* token, << "Argument not separated from preceding token by whitespace."; /* clang-format on */ if (isError) { - this->Makefile->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR, m.str(), lfbt); + this->Messenger->IssueMessage(cmake::FATAL_ERROR, m.str(), lfbt); return false; } - this->Makefile->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, m.str(), lfbt); + this->Messenger->IssueMessage(cmake::AUTHOR_WARNING, m.str(), lfbt); return true; } diff --git a/Source/cmListFileCache.h b/Source/cmListFileCache.h index f3e6f7008..cd4453680 100644 --- a/Source/cmListFileCache.h +++ b/Source/cmListFileCache.h @@ -23,7 +23,7 @@ * cmake list files. */ -class cmMakefile; +class cmMessenger; struct cmCommandContext { @@ -158,7 +158,8 @@ private: struct cmListFile { - bool ParseFile(const char* path, cmMakefile* mf); + bool ParseFile(const char* path, cmMessenger* messenger, + cmListFileBacktrace const& lfbt); std::vector Functions; }; diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 6c83b0622..6e4779746 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -25,6 +25,7 @@ #include "cmGlobalGenerator.h" #include "cmInstallGenerator.h" #include "cmListFileCache.h" +#include "cmMessenger.h" #include "cmSourceFile.h" #include "cmSourceFileLocation.h" #include "cmState.h" @@ -457,7 +458,8 @@ bool cmMakefile::ReadDependentFile(const char* filename, bool noPolicyScope) IncludeScope incScope(this, filenametoread, noPolicyScope); cmListFile listFile; - if (!listFile.ParseFile(filenametoread.c_str(), this)) { + if (!listFile.ParseFile(filenametoread.c_str(), this->GetMessenger(), + this->Backtrace)) { return false; } @@ -506,7 +508,8 @@ bool cmMakefile::ReadListFile(const char* filename) ListFileScope scope(this, filenametoread); cmListFile listFile; - if (!listFile.ParseFile(filenametoread.c_str(), this)) { + if (!listFile.ParseFile(filenametoread.c_str(), this->GetMessenger(), + this->Backtrace)) { return false; } @@ -1452,7 +1455,8 @@ void cmMakefile::Configure() this->AddDefinition("CMAKE_PARENT_LIST_FILE", currentStart.c_str()); cmListFile listFile; - if (!listFile.ParseFile(currentStart.c_str(), this)) { + if (!listFile.ParseFile(currentStart.c_str(), this->GetMessenger(), + this->Backtrace)) { return; } if (this->IsRootMakefile()) { @@ -3274,6 +3278,11 @@ cmake* cmMakefile::GetCMakeInstance() const return this->GlobalGenerator->GetCMakeInstance(); } +cmMessenger* cmMakefile::GetMessenger() const +{ + return this->GetCMakeInstance()->GetMessenger(); +} + cmGlobalGenerator* cmMakefile::GetGlobalGenerator() const { return this->GlobalGenerator; diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index d082964a1..b3587c5a7 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -607,6 +607,7 @@ public: * Get the instance */ cmake* GetCMakeInstance() const; + cmMessenger* GetMessenger() const; cmGlobalGenerator* GetGlobalGenerator() const; /**