From 9b4aefad41218866e392021b6d7239b2eeb50390 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 17 May 2015 23:12:16 +0200 Subject: cmMakefile: Replace deques with vectors. --- Source/cmMakefile.cxx | 2 +- Source/cmMakefile.h | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 7b8d3af..272ac4c 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -4371,7 +4371,7 @@ std::string cmMakefile::GetListFileStack() const size_t depth = this->ListFileStack.size(); if (depth > 0) { - std::deque::const_iterator it = this->ListFileStack.end(); + std::vector::const_iterator it = this->ListFileStack.end(); do { if (depth != this->ListFileStack.size()) diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index e0eef6f..453884a 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -35,7 +35,6 @@ #endif #include -#include class cmFunctionBlocker; class cmCommand; @@ -963,7 +962,7 @@ private: bool CheckSystemVars; // stack of list files being read - std::deque ListFileStack; + std::vector ListFileStack; // stack of commands being invoked. struct CallStackEntry @@ -971,7 +970,7 @@ private: cmListFileContext const* Context; cmExecutionStatus* Status; }; - typedef std::deque CallStackType; + typedef std::vector CallStackType; CallStackType CallStack; friend class cmMakefileCall; -- cgit v0.12 From 1ec1bf9f071ce930094171ab45f2dbc02c57927b Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 18 May 2015 00:00:53 +0200 Subject: if(): Test the effect of cmMakefileCall use in elseif() handling. --- Tests/RunCMake/if/RunCMakeTest.cmake | 1 + Tests/RunCMake/if/elseif-message-result.txt | 1 + Tests/RunCMake/if/elseif-message-stderr.txt | 8 ++++++++ Tests/RunCMake/if/elseif-message.cmake | 4 ++++ 4 files changed, 14 insertions(+) create mode 100644 Tests/RunCMake/if/elseif-message-result.txt create mode 100644 Tests/RunCMake/if/elseif-message-stderr.txt create mode 100644 Tests/RunCMake/if/elseif-message.cmake diff --git a/Tests/RunCMake/if/RunCMakeTest.cmake b/Tests/RunCMake/if/RunCMakeTest.cmake index 6b6b74b..b5546a7 100644 --- a/Tests/RunCMake/if/RunCMakeTest.cmake +++ b/Tests/RunCMake/if/RunCMakeTest.cmake @@ -2,3 +2,4 @@ include(RunCMake) run_cmake(IsDirectory) run_cmake(IsDirectoryLong) +run_cmake(elseif-message) diff --git a/Tests/RunCMake/if/elseif-message-result.txt b/Tests/RunCMake/if/elseif-message-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/if/elseif-message-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/if/elseif-message-stderr.txt b/Tests/RunCMake/if/elseif-message-stderr.txt new file mode 100644 index 0000000..c73977c --- /dev/null +++ b/Tests/RunCMake/if/elseif-message-stderr.txt @@ -0,0 +1,8 @@ +CMake Error at elseif-message.cmake:[0-9]+ \(elseif\): + given arguments: + + "Unknown" "arguments" + + Unknown arguments specified +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/if/elseif-message.cmake b/Tests/RunCMake/if/elseif-message.cmake new file mode 100644 index 0000000..5930966 --- /dev/null +++ b/Tests/RunCMake/if/elseif-message.cmake @@ -0,0 +1,4 @@ + +if (0) +elseif(Unknown arguments) +endif() -- cgit v0.12 From e17b5e426294dc5cc86ba31dfd4d4acc553c0c72 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 18 May 2015 21:35:29 +0200 Subject: cmMakefile: Add access to the top-level execution context. This is cheaper than getting the whole backtrace, and the cmListFileBacktrace will not always be composed of cmListFileContext objects. --- Source/cmConditionEvaluator.cxx | 4 ++-- Source/cmMakefile.cxx | 14 ++++++++++---- Source/cmMakefile.h | 1 + 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Source/cmConditionEvaluator.cxx b/Source/cmConditionEvaluator.cxx index 73aface..e5a89b6 100644 --- a/Source/cmConditionEvaluator.cxx +++ b/Source/cmConditionEvaluator.cxx @@ -113,7 +113,7 @@ const char* cmConditionEvaluator::GetDefinitionIfUnquoted( if(def && argument.WasQuoted() && this->Policy54Status == cmPolicies::WARN) { bool hasBeenReported = this->Makefile.HasCMP0054AlreadyBeenReported( - this->Makefile.GetBacktrace()[0]); + this->Makefile.GetExecutionContext()); if(!hasBeenReported) { @@ -162,7 +162,7 @@ bool cmConditionEvaluator::IsKeyword(std::string const& keyword, this->Policy54Status == cmPolicies::WARN) { bool hasBeenReported = this->Makefile.HasCMP0054AlreadyBeenReported( - this->Makefile.GetBacktrace()[0]); + this->Makefile.GetExecutionContext()); if(!hasBeenReported) { diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 272ac4c..4de3bcd 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -378,6 +378,12 @@ cmListFileBacktrace cmMakefile::GetBacktrace() const } //---------------------------------------------------------------------------- +cmListFileContext cmMakefile::GetExecutionContext() const +{ + return *this->CallStack.back().Context; +} + +//---------------------------------------------------------------------------- void cmMakefile::PrintCommandTrace(const cmListFileFunction& lff) const { std::ostringstream msg; @@ -1937,9 +1943,9 @@ void cmMakefile::CheckForUnused(const char* reason, cmListFileBacktrace bt(this->GetLocalGenerator()); if (!this->CallStack.empty()) { - const cmListFileContext* file = this->CallStack.back().Context; - bt.push_back(*file); - path = file->FilePath.c_str(); + cmListFileContext file = this->GetExecutionContext(); + bt.push_back(file); + path = file.FilePath; } else { @@ -3410,7 +3416,7 @@ void cmMakefile::AddFunctionBlocker(cmFunctionBlocker* fb) if(!this->CallStack.empty()) { // Record the context in which the blocker is created. - fb->SetStartingContext(*(this->CallStack.back().Context)); + fb->SetStartingContext(this->GetExecutionContext()); } this->FunctionBlockers.push_back(fb); diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 453884a..5ef2ec9 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -610,6 +610,7 @@ public: * Get the current context backtrace. */ cmListFileBacktrace GetBacktrace() const; + cmListFileContext GetExecutionContext() const; /** * Get the vector of files created by this makefile -- cgit v0.12 From f9785e0cb6c823849bb344e487d9e70d9fdaddb4 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 18 May 2015 21:39:15 +0200 Subject: cmMakefile: Simplify CMP0054 handling. --- Source/cmConditionEvaluator.cxx | 10 ++-------- Source/cmMakefile.cxx | 5 ++--- Source/cmMakefile.h | 3 +-- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/Source/cmConditionEvaluator.cxx b/Source/cmConditionEvaluator.cxx index e5a89b6..61847d4 100644 --- a/Source/cmConditionEvaluator.cxx +++ b/Source/cmConditionEvaluator.cxx @@ -112,10 +112,7 @@ const char* cmConditionEvaluator::GetDefinitionIfUnquoted( if(def && argument.WasQuoted() && this->Policy54Status == cmPolicies::WARN) { - bool hasBeenReported = this->Makefile.HasCMP0054AlreadyBeenReported( - this->Makefile.GetExecutionContext()); - - if(!hasBeenReported) + if(!this->Makefile.HasCMP0054AlreadyBeenReported()) { std::ostringstream e; e << (cmPolicies::GetPolicyWarning(cmPolicies::CMP0054)) << "\n"; @@ -161,10 +158,7 @@ bool cmConditionEvaluator::IsKeyword(std::string const& keyword, if(isKeyword && argument.WasQuoted() && this->Policy54Status == cmPolicies::WARN) { - bool hasBeenReported = this->Makefile.HasCMP0054AlreadyBeenReported( - this->Makefile.GetExecutionContext()); - - if(!hasBeenReported) + if(!this->Makefile.HasCMP0054AlreadyBeenReported()) { std::ostringstream e; e << cmPolicies::GetPolicyWarning(cmPolicies::CMP0054) << "\n"; diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 4de3bcd..33b7a0b 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -4941,10 +4941,9 @@ bool cmMakefile::SetPolicyVersion(const char *version) } //---------------------------------------------------------------------------- -bool cmMakefile::HasCMP0054AlreadyBeenReported( - cmListFileContext context) const +bool cmMakefile::HasCMP0054AlreadyBeenReported() const { - cmCMP0054Id id(context); + cmCMP0054Id id(this->GetExecutionContext()); bool alreadyReported = this->CMP0054ReportedIds.find(id) != this->CMP0054ReportedIds.end(); diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 5ef2ec9..3203b1b 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -411,8 +411,7 @@ public: * Determine if the given context, name pair has already been reported * in context of CMP0054. */ - bool HasCMP0054AlreadyBeenReported( - cmListFileContext context) const; + bool HasCMP0054AlreadyBeenReported() const; bool IgnoreErrorsCMP0061() const; -- cgit v0.12 From 7eb0dfa0622afe078c2e131ee1cbad293960b634 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 18 May 2015 21:41:42 +0200 Subject: cmMakefile: Use std::set::insert API to simplify CMP0054 handling. --- Source/cmMakefile.cxx | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 33b7a0b..5240dc8 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -4945,15 +4945,7 @@ bool cmMakefile::HasCMP0054AlreadyBeenReported() const { cmCMP0054Id id(this->GetExecutionContext()); - bool alreadyReported = - this->CMP0054ReportedIds.find(id) != this->CMP0054ReportedIds.end(); - - if(!alreadyReported) - { - this->CMP0054ReportedIds.insert(id); - } - - return alreadyReported; + return !this->CMP0054ReportedIds.insert(id).second; } //---------------------------------------------------------------------------- -- cgit v0.12 From e96b5d14f9f3500b2221e9afedfacabb0a56bb4c Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 18 May 2015 21:44:14 +0200 Subject: cmListFileContext: Implement LessThanComparable. Move wrapping existing code from cmMakefile, and simplify the implementation there. --- Source/cmListFileCache.cxx | 8 ++++++++ Source/cmListFileCache.h | 1 + Source/cmMakefile.cxx | 4 +--- Source/cmMakefile.h | 21 +-------------------- 4 files changed, 11 insertions(+), 23 deletions(-) diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx index ddcea9b..d8d339a 100644 --- a/Source/cmListFileCache.cxx +++ b/Source/cmListFileCache.cxx @@ -431,3 +431,11 @@ std::ostream& operator<<(std::ostream& os, cmListFileContext const& lfc) } return os; } + +bool operator<(const cmListFileContext& lhs, const cmListFileContext& rhs) +{ + if(lhs.FilePath != rhs.FilePath) + return lhs.FilePath < rhs.FilePath; + + return lhs.Line < rhs.Line; +} diff --git a/Source/cmListFileCache.h b/Source/cmListFileCache.h index 544ff1b..da89016 100644 --- a/Source/cmListFileCache.h +++ b/Source/cmListFileCache.h @@ -62,6 +62,7 @@ struct cmListFileContext }; std::ostream& operator<<(std::ostream&, cmListFileContext const&); +bool operator<(const cmListFileContext& lhs, const cmListFileContext& rhs); struct cmListFileFunction: public cmListFileContext { diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 5240dc8..8631d73 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -4943,9 +4943,7 @@ bool cmMakefile::SetPolicyVersion(const char *version) //---------------------------------------------------------------------------- bool cmMakefile::HasCMP0054AlreadyBeenReported() const { - cmCMP0054Id id(this->GetExecutionContext()); - - return !this->CMP0054ReportedIds.insert(id).second; + return !this->CMP0054ReportedIds.insert(this->GetExecutionContext()).second; } //---------------------------------------------------------------------------- diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 3203b1b..bfd6155 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -386,26 +386,7 @@ public: */ cmPolicies *GetPolicies() const; - struct cmCMP0054Id - { - cmCMP0054Id(cmListFileContext const& context): - Context(context) - { - - } - - bool operator< (cmCMP0054Id const& id) const - { - if(this->Context.FilePath != id.Context.FilePath) - return this->Context.FilePath < id.Context.FilePath; - - return this->Context.Line < id.Context.Line; - } - - cmListFileContext Context; - }; - - mutable std::set CMP0054ReportedIds; + mutable std::set CMP0054ReportedIds; /** * Determine if the given context, name pair has already been reported -- cgit v0.12 From 18f810a8659ea257c28d81b17aa3664f3d6f43e6 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 18 May 2015 21:46:50 +0200 Subject: cmListFileContext: Sort by line before file. This should be much faster. In the context where it is used the line comparison should be sufficient, removing the need to compare files at all. --- Source/cmListFileCache.cxx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx index d8d339a..650e2e5 100644 --- a/Source/cmListFileCache.cxx +++ b/Source/cmListFileCache.cxx @@ -434,8 +434,9 @@ std::ostream& operator<<(std::ostream& os, cmListFileContext const& lfc) bool operator<(const cmListFileContext& lhs, const cmListFileContext& rhs) { - if(lhs.FilePath != rhs.FilePath) - return lhs.FilePath < rhs.FilePath; - - return lhs.Line < rhs.Line; + if(lhs.Line != rhs.Line) + { + return lhs.Line < rhs.Line; + } + return lhs.FilePath < rhs.FilePath; } -- cgit v0.12 From 59ba1215b936b04fa5c5e8041eae14a754911cb4 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 18 May 2015 21:57:31 +0200 Subject: cmTarget: Remove needless iteration. This is not a loop. --- Source/cmTarget.cxx | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 8a8c163..d450a81 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -1279,7 +1279,6 @@ void cmTarget::GetTllSignatureTraces(std::ostringstream &s, { s << line.str(); } - ++i; } } } -- cgit v0.12 From 52a8d19c9b67e5c902155f52fc7d145e091a5e7d Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 18 May 2015 21:59:18 +0200 Subject: cmTarget: Store only cmListFileContext for CMP0023 handling. Only the top level execution context is shown, as appropriate, so store only that. --- Source/cmTarget.cxx | 27 ++++++++++++--------------- Source/cmTarget.h | 2 +- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index d450a81..ee5f02d 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -1239,8 +1239,8 @@ bool cmTarget::PushTLLCommandTrace(TLLSignature signature) ret = false; } } - cmListFileBacktrace lfbt = this->Makefile->GetBacktrace(); - this->TLLCommands.push_back(std::make_pair(signature, lfbt)); + cmListFileContext lfc = this->Makefile->GetExecutionContext(); + this->TLLCommands.push_back(std::make_pair(signature, lfc)); return ret; } @@ -1248,8 +1248,8 @@ bool cmTarget::PushTLLCommandTrace(TLLSignature signature) void cmTarget::GetTllSignatureTraces(std::ostringstream &s, TLLSignature sig) const { - std::vector sigs; - typedef std::vector > Container; + std::vector sigs; + typedef std::vector > Container; for(Container::const_iterator it = this->TLLCommands.begin(); it != this->TLLCommands.end(); ++it) { @@ -1258,6 +1258,7 @@ void cmTarget::GetTllSignatureTraces(std::ostringstream &s, sigs.push_back(it->second); } } + cmLocalGenerator* lg = this->GetMakefile()->GetLocalGenerator(); if (!sigs.empty()) { const char *sigString @@ -1265,20 +1266,16 @@ void cmTarget::GetTllSignatureTraces(std::ostringstream &s, : "plain"); s << "The uses of the " << sigString << " signature are here:\n"; UNORDERED_SET emitted; - for(std::vector::iterator it = sigs.begin(); + for(std::vector::iterator it = sigs.begin(); it != sigs.end(); ++it) { - it->MakeRelative(); - cmListFileBacktrace::const_iterator i = it->begin(); - if(i != it->end()) + cmListFileContext lfc = *it; + lfc.FilePath = lg->Convert(lfc.FilePath, cmLocalGenerator::HOME); + std::ostringstream line; + line << " * " << (lfc.Line? "": " in ") << lfc << std::endl; + if (emitted.insert(line.str()).second) { - cmListFileContext const& lfc = *i; - std::ostringstream line; - line << " * " << (lfc.Line? "": " in ") << lfc << std::endl; - if (emitted.insert(line.str()).second) - { - s << line.str(); - } + s << line.str(); } } } diff --git a/Source/cmTarget.h b/Source/cmTarget.h index a032414..c5e9fc4 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -641,7 +641,7 @@ private: // directories. std::set SystemIncludeDirectories; - std::vector > TLLCommands; + std::vector > TLLCommands; #if defined(_WIN32) && !defined(__CYGWIN__) /** -- cgit v0.12 From 9645cba3bfc4bd583259130fd7e63da0c8bbecca Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 18 May 2015 21:51:42 +0200 Subject: cmListFileContext: Implement EqualityComparable. --- Source/cmListFileCache.cxx | 10 ++++++++++ Source/cmListFileCache.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx index 650e2e5..3e3d708 100644 --- a/Source/cmListFileCache.cxx +++ b/Source/cmListFileCache.cxx @@ -440,3 +440,13 @@ bool operator<(const cmListFileContext& lhs, const cmListFileContext& rhs) } return lhs.FilePath < rhs.FilePath; } + +bool operator==(const cmListFileContext& lhs, const cmListFileContext& rhs) +{ + return lhs.Line == rhs.Line && lhs.FilePath == rhs.FilePath; +} + +bool operator!=(const cmListFileContext& lhs, const cmListFileContext& rhs) +{ + return !(lhs == rhs); +} diff --git a/Source/cmListFileCache.h b/Source/cmListFileCache.h index da89016..d7e29d9 100644 --- a/Source/cmListFileCache.h +++ b/Source/cmListFileCache.h @@ -63,6 +63,8 @@ struct cmListFileContext std::ostream& operator<<(std::ostream&, cmListFileContext const&); bool operator<(const cmListFileContext& lhs, const cmListFileContext& rhs); +bool operator==(cmListFileContext const& lhs, cmListFileContext const& rhs); +bool operator!=(cmListFileContext const& lhs, cmListFileContext const& rhs); struct cmListFileFunction: public cmListFileContext { -- cgit v0.12 From 65a42849639a3268f613795683d7c91a6ed8b661 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 18 May 2015 22:05:36 +0200 Subject: cmTarget: Store context in stack only if different. The PushTLLCommandTrace method is called once per link item for a single target_link_libraries command. Avoid storing copies of identical execution contexts and rely on the uniqueness while printing output. --- Source/cmTarget.cxx | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index ee5f02d..aa556c8 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -1240,7 +1240,10 @@ bool cmTarget::PushTLLCommandTrace(TLLSignature signature) } } cmListFileContext lfc = this->Makefile->GetExecutionContext(); - this->TLLCommands.push_back(std::make_pair(signature, lfc)); + if (this->TLLCommands.empty() || this->TLLCommands.back().second != lfc) + { + this->TLLCommands.push_back(std::make_pair(signature, lfc)); + } return ret; } @@ -1265,18 +1268,12 @@ void cmTarget::GetTllSignatureTraces(std::ostringstream &s, = (sig == cmTarget::KeywordTLLSignature ? "keyword" : "plain"); s << "The uses of the " << sigString << " signature are here:\n"; - UNORDERED_SET emitted; for(std::vector::iterator it = sigs.begin(); it != sigs.end(); ++it) { cmListFileContext lfc = *it; lfc.FilePath = lg->Convert(lfc.FilePath, cmLocalGenerator::HOME); - std::ostringstream line; - line << " * " << (lfc.Line? "": " in ") << lfc << std::endl; - if (emitted.insert(line.str()).second) - { - s << line.str(); - } + s << " * " << (lfc.Line ? "" : " in ") << lfc << std::endl; } } } -- cgit v0.12 From f4300cd4dd46560c95203bad4a386c5db0bda2cd Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 18 May 2015 22:07:52 +0200 Subject: cmTarget: Simplify output computation. We always have line information for contexts resulting from command execution. --- Source/cmTarget.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index aa556c8..e705aaa 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -1273,7 +1273,7 @@ void cmTarget::GetTllSignatureTraces(std::ostringstream &s, { cmListFileContext lfc = *it; lfc.FilePath = lg->Convert(lfc.FilePath, cmLocalGenerator::HOME); - s << " * " << (lfc.Line ? "" : " in ") << lfc << std::endl; + s << " * " << lfc << std::endl; } } } -- cgit v0.12 From a271f7f17707c50744c2dbeb20ae82b10c886f4f Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 18 May 2015 22:10:59 +0200 Subject: cmTarget: Simplify CMP0023 message loop. This method is only called if there is a mismatch and something to print. Remove intermediate container. --- Source/cmTarget.cxx | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index e705aaa..8feb7a5 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -1251,27 +1251,17 @@ bool cmTarget::PushTLLCommandTrace(TLLSignature signature) void cmTarget::GetTllSignatureTraces(std::ostringstream &s, TLLSignature sig) const { - std::vector sigs; + const char *sigString = (sig == cmTarget::KeywordTLLSignature ? "keyword" + : "plain"); + s << "The uses of the " << sigString << " signature are here:\n"; typedef std::vector > Container; + cmLocalGenerator* lg = this->GetMakefile()->GetLocalGenerator(); for(Container::const_iterator it = this->TLLCommands.begin(); it != this->TLLCommands.end(); ++it) { if (it->first == sig) { - sigs.push_back(it->second); - } - } - cmLocalGenerator* lg = this->GetMakefile()->GetLocalGenerator(); - if (!sigs.empty()) - { - const char *sigString - = (sig == cmTarget::KeywordTLLSignature ? "keyword" - : "plain"); - s << "The uses of the " << sigString << " signature are here:\n"; - for(std::vector::iterator it = sigs.begin(); - it != sigs.end(); ++it) - { - cmListFileContext lfc = *it; + cmListFileContext lfc = it->second; lfc.FilePath = lg->Convert(lfc.FilePath, cmLocalGenerator::HOME); s << " * " << lfc << std::endl; } -- cgit v0.12 From 61d52e6e77bef903225bd3bad3e381bac73ee557 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Mon, 18 May 2015 21:33:38 +0200 Subject: cmListFileBacktrace: Hide the context-stack implementation detail. The backtrace will soon not be implemented in terms of a stack of cmListFileContext objects. Keep the cmListFileContext in the API for convenience for now. --- Source/cmCommandArgumentParserHelper.cxx | 2 +- Source/cmListFileCache.cxx | 30 ++++++++++++++++++++++++++++++ Source/cmListFileCache.h | 7 ++++++- Source/cmMakefile.cxx | 10 +++++----- Source/cmake.cxx | 19 ++----------------- 5 files changed, 44 insertions(+), 24 deletions(-) diff --git a/Source/cmCommandArgumentParserHelper.cxx b/Source/cmCommandArgumentParserHelper.cxx index 0d1c86d..c816c23 100644 --- a/Source/cmCommandArgumentParserHelper.cxx +++ b/Source/cmCommandArgumentParserHelper.cxx @@ -143,7 +143,7 @@ char* cmCommandArgumentParserHelper::ExpandVariable(const char* var) cmListFileContext lfc; lfc.FilePath = this->FileName; lfc.Line = this->FileLine; - bt.push_back(lfc); + bt.Append(lfc); msg << "uninitialized variable \'" << var << "\'"; this->Makefile->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, msg.str(), bt); diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx index 3e3d708..2756cd2 100644 --- a/Source/cmListFileCache.cxx +++ b/Source/cmListFileCache.cxx @@ -400,6 +400,11 @@ bool cmListFileParser::AddArgument(cmListFileLexer_Token* token, } } +void cmListFileBacktrace::Append(cmListFileContext const& context) +{ + this->push_back(context); +} + //---------------------------------------------------------------------------- void cmListFileBacktrace::MakeRelative() { @@ -416,6 +421,31 @@ void cmListFileBacktrace::MakeRelative() this->Relative = true; } +void cmListFileBacktrace::PrintTitle(std::ostream& out) +{ + if (this->empty()) + { + return; + } + out << (this->front().Line ? " at " : " in ") << this->front(); +} + +void cmListFileBacktrace::PrintCallStack(std::ostream& out) +{ + if (size() <= 1) + { + return; + } + + const_iterator i = this->begin() + 1; + out << "Call Stack (most recent call first):\n"; + while(i != this->end()) + { + cmListFileContext const& lfc = *i; + out << " " << lfc << "\n"; + ++i; + } +} //---------------------------------------------------------------------------- std::ostream& operator<<(std::ostream& os, cmListFileContext const& lfc) diff --git a/Source/cmListFileCache.h b/Source/cmListFileCache.h index d7e29d9..4a1d181 100644 --- a/Source/cmListFileCache.h +++ b/Source/cmListFileCache.h @@ -71,7 +71,7 @@ struct cmListFileFunction: public cmListFileContext std::vector Arguments; }; -class cmListFileBacktrace: public std::vector +class cmListFileBacktrace: private std::vector { public: cmListFileBacktrace(cmLocalGenerator* localGen) @@ -80,7 +80,12 @@ class cmListFileBacktrace: public std::vector { } + void Append(cmListFileContext const& context); + void MakeRelative(); + + void PrintTitle(std::ostream& out); + void PrintCallStack(std::ostream& out); private: cmLocalGenerator* LocalGenerator; bool Relative; diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 8631d73..0d5a431 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -358,7 +358,7 @@ void cmMakefile::IssueMessage(cmake::MessageType t, lfc.FilePath = this->ListFileStack.back(); } lfc.Line = 0; - backtrace.push_back(lfc); + backtrace.Append(lfc); } // Issue the message. @@ -372,7 +372,7 @@ cmListFileBacktrace cmMakefile::GetBacktrace() const for(CallStackType::const_reverse_iterator i = this->CallStack.rbegin(); i != this->CallStack.rend(); ++i) { - backtrace.push_back(*i->Context); + backtrace.Append(*i->Context); } return backtrace; } @@ -1944,7 +1944,7 @@ void cmMakefile::CheckForUnused(const char* reason, if (!this->CallStack.empty()) { cmListFileContext file = this->GetExecutionContext(); - bt.push_back(file); + bt.Append(file); path = file.FilePath; } else @@ -1954,7 +1954,7 @@ void cmMakefile::CheckForUnused(const char* reason, cmListFileContext lfc; lfc.FilePath = path; lfc.Line = 0; - bt.push_back(lfc); + bt.Append(lfc); } if (this->CheckSystemVars || cmSystemTools::IsSubDirectory(path, @@ -2884,7 +2884,7 @@ cmake::MessageType cmMakefile::ExpandVariablesInStringNew( cmListFileContext lfc; lfc.FilePath = filename; lfc.Line = line; - bt.push_back(lfc); + bt.Append(lfc); msg << "uninitialized variable \'" << lookup << "\'"; this->GetCMakeInstance()->IssueMessage(cmake::AUTHOR_WARNING, msg.str(), bt); diff --git a/Source/cmake.cxx b/Source/cmake.cxx index 5c5c428..e447105 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -2485,13 +2485,7 @@ void cmake::IssueMessage(cmake::MessageType t, std::string const& text, } // Add the immediate context. - cmListFileBacktrace::const_iterator i = backtrace.begin(); - if(i != backtrace.end()) - { - cmListFileContext const& lfc = *i; - msg << (lfc.Line? " at ": " in ") << lfc; - ++i; - } + backtrace.PrintTitle(msg); // Add the message text. { @@ -2502,16 +2496,7 @@ void cmake::IssueMessage(cmake::MessageType t, std::string const& text, } // Add the rest of the context. - if(i != backtrace.end()) - { - msg << "Call Stack (most recent call first):\n"; - while(i != backtrace.end()) - { - cmListFileContext const& lfc = *i; - msg << " " << lfc << "\n"; - ++i; - } - } + backtrace.PrintCallStack(msg); // Add a note about warning suppression. if(t == cmake::AUTHOR_WARNING) -- cgit v0.12