From 7503deb2c55a32f72c9ec34f17a800d4ab1e4c75 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 14 Apr 2016 10:31:44 -0400 Subject: cmIfCommand: Simplify execution context construction --- Source/cmIfCommand.cxx | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx index 9a07dde..fc54ca5 100644 --- a/Source/cmIfCommand.cxx +++ b/Source/cmIfCommand.cxx @@ -203,15 +203,9 @@ bool cmIfCommand cmake::MessageType status; - cmListFileContext execContext = this->Makefile->GetExecutionContext(); - - cmCommandContext commandContext; - commandContext.Line = execContext.Line; - commandContext.Name = execContext.Name; - cmConditionEvaluator conditionEvaluator( - *(this->Makefile), cmListFileContext::FromCommandContext( - commandContext, execContext.FilePath), + *(this->Makefile), + this->Makefile->GetExecutionContext(), this->Makefile->GetBacktrace()); bool isTrue = conditionEvaluator.IsTrue( -- cgit v0.12 From a559f0f6b020697a064517637ae04f0733ffc6ea Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 14 Apr 2016 10:46:41 -0400 Subject: cmWhileCommand: Simplify context construction --- Source/cmWhileCommand.cxx | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Source/cmWhileCommand.cxx b/Source/cmWhileCommand.cxx index aabbe27..7bb78bf 100644 --- a/Source/cmWhileCommand.cxx +++ b/Source/cmWhileCommand.cxx @@ -55,13 +55,9 @@ IsFunctionBlocked(const cmListFileFunction& lff, cmMakefile &mf, commandContext.Line = execContext.Line; commandContext.Name = execContext.Name; - cmListFileContext conditionContext = - cmListFileContext::FromCommandContext( - commandContext, - this->GetStartingContext().FilePath); - cmConditionEvaluator conditionEvaluator( - mf, conditionContext, + mf, + this->GetStartingContext(), mf.GetBacktrace(commandContext)); bool isTrue = conditionEvaluator.IsTrue( -- cgit v0.12 From b6ed71b17c888c5f79129871bf7bc865b43063e3 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 14 Apr 2016 11:02:40 -0400 Subject: cmMakefile: Move cmMakefileCall to .cxx file --- Source/cmMakefile.cxx | 33 ++++++++++++++++++++------------- Source/cmMakefile.h | 13 ------------- 2 files changed, 20 insertions(+), 26 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 7be6b88..162d3e7 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -222,6 +222,26 @@ void cmMakefile::PrintCommandTrace(const cmListFileFunction& lff) const cmSystemTools::Message(msg.str().c_str()); } +// Helper class to make sure the call stack is valid. +class cmMakefileCall +{ +public: + cmMakefileCall(cmMakefile* mf, const cmCommandContext& lfc, + cmExecutionStatus& status): Makefile(mf) + { + this->Makefile->ContextStack.push_back(&lfc); + this->Makefile->ExecutionStatusStack.push_back(&status); + } + + ~cmMakefileCall() + { + this->Makefile->ExecutionStatusStack.pop_back(); + this->Makefile->ContextStack.pop_back(); + } +private: + cmMakefile* Makefile; +}; + //---------------------------------------------------------------------------- bool cmMakefile::ExecuteCommand(const cmListFileFunction& lff, cmExecutionStatus &status) @@ -5148,16 +5168,3 @@ cmMakefile::MacroPushPop::~MacroPushPop() { this->Makefile->PopMacroScope(this->ReportError); } - -cmMakefileCall::cmMakefileCall(cmMakefile* mf, const cmCommandContext& lfc, - cmExecutionStatus& status): Makefile(mf) -{ - this->Makefile->ContextStack.push_back(&lfc); - this->Makefile->ExecutionStatusStack.push_back(&status); -} - -cmMakefileCall::~cmMakefileCall() -{ - this->Makefile->ExecutionStatusStack.pop_back(); - this->Makefile->ContextStack.pop_back(); -} diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 45f2efb..7217944 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -959,17 +959,4 @@ private: mutable bool SuppressWatches; }; -//---------------------------------------------------------------------------- -// Helper class to make sure the call stack is valid. -class cmMakefileCall -{ -public: - cmMakefileCall(cmMakefile* mf, - cmCommandContext const& lfc, - cmExecutionStatus& status); - ~cmMakefileCall(); -private: - cmMakefile* Makefile; -}; - #endif -- cgit v0.12 From c50285dee66394b68eb3df17d190072289a33a4e Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 14 Apr 2016 11:49:32 -0400 Subject: cmOutputConverter: Assert construction with a valid snapshot We unconditionally use information from the snapshot so it must be valid. --- Source/cmOutputConverter.cxx | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/cmOutputConverter.cxx b/Source/cmOutputConverter.cxx index 5acae2f..59fb2e9 100644 --- a/Source/cmOutputConverter.cxx +++ b/Source/cmOutputConverter.cxx @@ -22,6 +22,7 @@ cmOutputConverter::cmOutputConverter(cmState::Snapshot snapshot) : StateSnapshot(snapshot), LinkScriptShell(false) { + assert(this->StateSnapshot.IsValid()); } //---------------------------------------------------------------------------- -- cgit v0.12 From cc7aed77a8774c565c8bc6c4965f10e3560f8d64 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 14 Apr 2016 16:35:12 -0400 Subject: cmLocalGenerator: Use own IssueMessage method --- Source/cmLocalGenerator.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 0195b9e..746bcab 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -1608,7 +1608,7 @@ void cmLocalGenerator::OutputLinkLibraries(std::string& linkLibraries, "For compatibility with older versions of CMake, " "additional flags may be added to export symbols on all " "executables regardless of thier ENABLE_EXPORTS property."; - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, w.str()); + this->IssueMessage(cmake::AUTHOR_WARNING, w.str()); } case cmPolicies::OLD: // OLD behavior is to always add the flags @@ -1616,7 +1616,7 @@ void cmLocalGenerator::OutputLinkLibraries(std::string& linkLibraries, break; case cmPolicies::REQUIRED_IF_USED: case cmPolicies::REQUIRED_ALWAYS: - this->Makefile->IssueMessage( + this->IssueMessage( cmake::FATAL_ERROR, cmPolicies::GetRequiredPolicyError(cmPolicies::CMP0065) ); -- cgit v0.12 From da07c506b9044e89ad9d904450aa590bb260bd78 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 15 Apr 2016 10:08:37 -0400 Subject: cmLocalGenerator: Simplify IssueMessage implementation This method was added by commit v3.4.0-rc1~424^2~6 (cmLocalGenerator: Add IssueMessage method, 2015-06-13) in order to reduce callers' dependency on cmMakefile. Currently the implementation of cmLocalGenerator::IssueMessage is just a copy of the post-configure code path in cmMakefile::IssueMessage. De-duplicate the implementation by simply calling the cmMakefile copy for now. This will simplify upcoming refactoring of backtraces. The dependency on cmMakefile can be removed by future work once that is done. --- Source/cmLocalGenerator.cxx | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/Source/cmLocalGenerator.cxx b/Source/cmLocalGenerator.cxx index 746bcab..b93fc21 100644 --- a/Source/cmLocalGenerator.cxx +++ b/Source/cmLocalGenerator.cxx @@ -69,17 +69,7 @@ cmLocalGenerator::~cmLocalGenerator() void cmLocalGenerator::IssueMessage(cmake::MessageType t, std::string const& text) const { - cmListFileContext lfc; - lfc.FilePath = this->StateSnapshot.GetDirectory().GetCurrentSource(); - lfc.FilePath += "/CMakeLists.txt"; - - if(!this->GlobalGenerator->GetCMakeInstance()->GetIsInTryCompile()) - { - cmOutputConverter converter(this->StateSnapshot); - lfc.FilePath = converter.Convert(lfc.FilePath, cmLocalGenerator::HOME); - } - lfc.Line = 0; - this->GlobalGenerator->GetCMakeInstance()->IssueMessage(t, text, lfc); + this->Makefile->IssueMessage(t, text); } //---------------------------------------------------------------------------- -- cgit v0.12 From 2faa8b362050c716cc5626f9bb9d8a8612b97f95 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 15 Apr 2016 10:13:12 -0400 Subject: Add call stack to unused/uninitialized variable warnings In commit v2.8.4~32^2~14 (Use cmake::IssueMessage for warnings, 2010-12-07) these warnings became formatted. It is more informative to give the full call stack with such warnings. Also it is easier to implement warnings with a full call stack because we do not have to construct a custom backtrace with only the top. --- Source/cmCommandArgumentParserHelper.cxx | 9 +-------- Source/cmMakefile.cxx | 20 +++----------------- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/Source/cmCommandArgumentParserHelper.cxx b/Source/cmCommandArgumentParserHelper.cxx index 14e9e56..15ab746 100644 --- a/Source/cmCommandArgumentParserHelper.cxx +++ b/Source/cmCommandArgumentParserHelper.cxx @@ -140,15 +140,8 @@ char* cmCommandArgumentParserHelper::ExpandVariable(const char* var) this->Makefile->GetHomeOutputDirectory())) { std::ostringstream msg; - cmListFileContext lfc; - cmOutputConverter converter(this->Makefile->GetStateSnapshot()); - lfc.FilePath = converter.Convert(this->FileName, - cmOutputConverter::HOME); - - lfc.Line = this->FileLine; msg << "uninitialized variable \'" << var << "\'"; - this->Makefile->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, - msg.str(), lfc); + this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, msg.str()); } } return 0; diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 162d3e7..13bcdac 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1961,21 +1961,15 @@ void cmMakefile::LogUnused(const char* reason, if (this->WarnUnused) { std::string path; - cmListFileContext lfc; if (!this->ExecutionStatusStack.empty()) { - lfc = this->GetExecutionContext(); - path = lfc.FilePath; + path = this->GetExecutionContext().FilePath; } else { path = this->GetCurrentSourceDirectory(); path += "/CMakeLists.txt"; - lfc.FilePath = path; - lfc.Line = 0; } - cmOutputConverter converter(this->StateSnapshot); - lfc.FilePath = converter.Convert(lfc.FilePath, cmOutputConverter::HOME); if (this->CheckSystemVars || cmSystemTools::IsSubDirectory(path, @@ -1987,9 +1981,7 @@ void cmMakefile::LogUnused(const char* reason, { std::ostringstream msg; msg << "unused variable (" << reason << ") \'" << name << "\'"; - this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, - msg.str(), - lfc); + this->IssueMessage(cmake::AUTHOR_WARNING, msg.str()); } } } @@ -2919,14 +2911,8 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew( this->GetHomeOutputDirectory())) { std::ostringstream msg; - cmListFileContext lfc; - cmOutputConverter converter(this->StateSnapshot); - lfc.FilePath = - converter.Convert(filename, cmOutputConverter::HOME); - lfc.Line = line; msg << "uninitialized variable \'" << lookup << "\'"; - this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, - msg.str(), lfc); + this->IssueMessage(cmake::AUTHOR_WARNING, msg.str()); } } } -- cgit v0.12