From d5dc4169ac1c4dd5abd385b1e8499119df88c657 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 31 May 2015 18:19:58 +0200 Subject: cmMakefile: Create a unified raii for function scopes. --- Source/cmFunctionCommand.cxx | 14 +++----------- Source/cmMakefile.cxx | 33 +++++++++++++++++++++++++++++++++ Source/cmMakefile.h | 16 +++++++++++++++- 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/Source/cmFunctionCommand.cxx b/Source/cmFunctionCommand.cxx index 001adb1..dc6d2d2 100644 --- a/Source/cmFunctionCommand.cxx +++ b/Source/cmFunctionCommand.cxx @@ -73,7 +73,6 @@ public: cmPolicies::PolicyMap Policies; }; - bool cmFunctionHelperCommand::InvokeInitialPass (const std::vector& args, cmExecutionStatus & inStatus) @@ -93,14 +92,8 @@ bool cmFunctionHelperCommand::InvokeInitialPass return false; } - // we push a scope on the makefile - cmMakefile::ScopePushPop varScope(this->Makefile); - cmMakefile::LexicalPushPop lexScope(this->Makefile); - static_cast(varScope); - - // Push a weak policy scope which restores the policies recorded at - // function creation. - cmMakefile::PolicyPushPop polScope(this->Makefile, true, this->Policies); + cmMakefile::FunctionPushPop functionScope(this->Makefile, + this->Policies); // set the value of argc std::ostringstream strStream; @@ -145,8 +138,7 @@ bool cmFunctionHelperCommand::InvokeInitialPass { // The error message should have already included the call stack // so we do not need to report an error here. - lexScope.Quiet(); - polScope.Quiet(); + functionScope.Quiet(); inStatus.SetNestedError(true); return false; } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index b5d976a..7012701 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1562,6 +1562,26 @@ void cmMakefile::InitializeFromParent() this->ImportedTargets = parent->ImportedTargets; } +void cmMakefile::PushFunctionScope(const cmPolicies::PolicyMap& pm) +{ + this->PushScope(); + + this->PushFunctionBlockerBarrier(); + + this->PushPolicy(true, pm); + this->PushPolicyBarrier(); +} + +void cmMakefile::PopFunctionScope(bool reportError) +{ + this->PopPolicyBarrier(reportError); + this->PopPolicy(); + + this->PopFunctionBlockerBarrier(reportError); + + this->PopScope(); +} + //---------------------------------------------------------------------------- class cmMakefileCurrent { @@ -5418,3 +5438,16 @@ AddRequiredTargetCFeature(cmTarget *target, const std::string& feature) const } return true; } + + +cmMakefile::FunctionPushPop::FunctionPushPop(cmMakefile* mf, + cmPolicies::PolicyMap const& pm) + : Makefile(mf), ReportError(true) +{ + this->Makefile->PushFunctionScope(pm); +} + +cmMakefile::FunctionPushPop::~FunctionPushPop() +{ + this->Makefile->PopFunctionScope(this->ReportError); +} diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 431ed08..ed9bc70 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -746,7 +746,21 @@ public: const std::vector& GetTestGenerators() const { return this->TestGenerators; } - // push and pop variable scopes + class FunctionPushPop + { + public: + FunctionPushPop(cmMakefile* mf, + cmPolicies::PolicyMap const& pm); + ~FunctionPushPop(); + + void Quiet() { this->ReportError = false; } + private: + cmMakefile* Makefile; + bool ReportError; + }; + + void PushFunctionScope(cmPolicies::PolicyMap const& pm); + void PopFunctionScope(bool reportError); void PushScope(); void PopScope(); void RaiseScope(const std::string& var, const char *value); -- cgit v0.12 From ca140c2e898ca74a7daa305449b136b1294a41f0 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 31 May 2015 18:32:01 +0200 Subject: cmMakefile: Create a unified raii for macro scopes. --- Source/cmMacroCommand.cxx | 11 +++-------- Source/cmMakefile.cxx | 29 +++++++++++++++++++++++++++++ Source/cmMakefile.h | 15 +++++++++++++++ 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx index 7ac4432..028ab62 100644 --- a/Source/cmMacroCommand.cxx +++ b/Source/cmMacroCommand.cxx @@ -96,12 +96,8 @@ bool cmMacroHelperCommand::InvokeInitialPass return false; } - // Enforce matching logical blocks inside the macro. - cmMakefile::LexicalPushPop lexScope(this->Makefile); - - // Push a weak policy scope which restores the policies recorded at - // macro creation. - cmMakefile::PolicyPushPop polScope(this->Makefile, true, this->Policies); + cmMakefile::MacroPushPop macroScope(this->Makefile, + this->Policies); // set the value of argc std::ostringstream argcDefStream; @@ -191,8 +187,7 @@ bool cmMacroHelperCommand::InvokeInitialPass { // The error message should have already included the call stack // so we do not need to report an error here. - lexScope.Quiet(); - polScope.Quiet(); + macroScope.Quiet(); inStatus.SetNestedError(true); return false; } diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 7012701..d3a8121 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1582,6 +1582,22 @@ void cmMakefile::PopFunctionScope(bool reportError) this->PopScope(); } +void cmMakefile::PushMacroScope(const cmPolicies::PolicyMap& pm) +{ + this->PushFunctionBlockerBarrier(); + + this->PushPolicy(true, pm); + this->PushPolicyBarrier(); +} + +void cmMakefile::PopMacroScope(bool reportError) +{ + this->PopPolicyBarrier(reportError); + this->PopPolicy(); + + this->PopFunctionBlockerBarrier(reportError); +} + //---------------------------------------------------------------------------- class cmMakefileCurrent { @@ -5451,3 +5467,16 @@ cmMakefile::FunctionPushPop::~FunctionPushPop() { this->Makefile->PopFunctionScope(this->ReportError); } + + +cmMakefile::MacroPushPop::MacroPushPop(cmMakefile* mf, + const cmPolicies::PolicyMap& pm) + : Makefile(mf), ReportError(true) +{ + this->Makefile->PushMacroScope(pm); +} + +cmMakefile::MacroPushPop::~MacroPushPop() +{ + this->Makefile->PopMacroScope(this->ReportError); +} diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index ed9bc70..0914a99 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -759,8 +759,23 @@ public: bool ReportError; }; + class MacroPushPop + { + public: + MacroPushPop(cmMakefile* mf, + cmPolicies::PolicyMap const& pm); + ~MacroPushPop(); + + void Quiet() { this->ReportError = false; } + private: + cmMakefile* Makefile; + bool ReportError; + }; + void PushFunctionScope(cmPolicies::PolicyMap const& pm); void PopFunctionScope(bool reportError); + void PushMacroScope(cmPolicies::PolicyMap const& pm); + void PopMacroScope(bool reportError); void PushScope(); void PopScope(); void RaiseScope(const std::string& var, const char *value); -- cgit v0.12 From db74ce5820e0d0a99649c6b472de74277e3fa6bf Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 31 May 2015 23:45:52 +0200 Subject: cmMakefile: Inline PushScope into PushFunctionScope. Make it possible to group the various methods here a different way. --- Source/cmMakefile.cxx | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index d3a8121..2072418 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1564,7 +1564,13 @@ void cmMakefile::InitializeFromParent() void cmMakefile::PushFunctionScope(const cmPolicies::PolicyMap& pm) { - this->PushScope(); + this->Internal->PushDefinitions(); + + this->PushLoopBlockBarrier(); + +#if defined(CMAKE_BUILD_WITH_CMAKE) + this->GetGlobalGenerator()->GetFileLockPool().PushFunctionScope(); +#endif this->PushFunctionBlockerBarrier(); @@ -1579,7 +1585,15 @@ void cmMakefile::PopFunctionScope(bool reportError) this->PopFunctionBlockerBarrier(reportError); - this->PopScope(); +#if defined(CMAKE_BUILD_WITH_CMAKE) + this->GetGlobalGenerator()->GetFileLockPool().PopFunctionScope(); +#endif + + this->PopLoopBlockBarrier(); + + this->CheckForUnusedVariables(); + + this->Internal->PopDefinitions(); } void cmMakefile::PushMacroScope(const cmPolicies::PolicyMap& pm) -- cgit v0.12 From 00bfa047481ed9f75444cb4954d7d72f616aef0f Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 31 May 2015 19:03:46 +0200 Subject: cmMakefile: Out-of-line the cmMakefileCall. --- Source/cmMakefile.cxx | 12 ++++++++++++ Source/cmMakefile.h | 11 ++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 2072418..d4bf6c1 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -5494,3 +5494,15 @@ cmMakefile::MacroPushPop::~MacroPushPop() { this->Makefile->PopMacroScope(this->ReportError); } + +cmMakefileCall::cmMakefileCall(cmMakefile* mf, const cmListFileContext& lfc, + cmExecutionStatus& status): Makefile(mf) +{ + cmMakefile::CallStackEntry entry = {&lfc, &status}; + this->Makefile->CallStack.push_back(entry); +} + +cmMakefileCall::~cmMakefileCall() +{ + this->Makefile->CallStack.pop_back(); +} diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 0914a99..0b328e9 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -1084,15 +1084,8 @@ class cmMakefileCall public: cmMakefileCall(cmMakefile* mf, cmListFileContext const& lfc, - cmExecutionStatus& status): Makefile(mf) - { - cmMakefile::CallStackEntry entry = {&lfc, &status}; - this->Makefile->CallStack.push_back(entry); - } - ~cmMakefileCall() - { - this->Makefile->CallStack.pop_back(); - } + cmExecutionStatus& status); + ~cmMakefileCall(); private: cmMakefile* Makefile; }; -- cgit v0.12 From 353e422b2ad3d51dfc6c6db968ebcece10cbcc8d Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 3 May 2015 00:47:53 +0200 Subject: cmMakefile: Remove unused GetPolicies method. --- Source/cmMakefile.h | 6 ------ Source/cmake.h | 3 --- 2 files changed, 9 deletions(-) diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 0b328e9..85451ad 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -14,7 +14,6 @@ #include "cmExecutionStatus.h" #include "cmListFileCache.h" -#include "cmPolicies.h" #include "cmPropertyMap.h" #include "cmSystemTools.h" #include "cmTarget.h" @@ -373,11 +372,6 @@ public: }; friend class PolicyPushPop; - /** - * Get the Policies Instance - */ - cmPolicies *GetPolicies() const; - mutable std::set CMP0054ReportedIds; /** diff --git a/Source/cmake.h b/Source/cmake.h index 0fe7bfc..f0f9411 100644 --- a/Source/cmake.h +++ b/Source/cmake.h @@ -222,9 +222,6 @@ class cmake ///! this is called by generators to update the progress void UpdateProgress(const char *msg, float prog); - ///! get the cmake policies instance - cmPolicies *GetPolicies() {return this->Policies;} - ///! Get the variable watch object cmVariableWatch* GetVariableWatch() { return this->VariableWatch; } -- cgit v0.12 From 1981c9718b7099670b03535a241c735477d6bc6c Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 6 Jun 2015 09:17:45 +0200 Subject: cmMakefile: Simplify InitializeFromParent method. Provide a parent instead of requiring it to be computed through the cmLocalGenerator. --- Source/cmMakefile.cxx | 6 ++---- Source/cmMakefile.h | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index d4bf6c1..3ac77e9 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -1485,10 +1485,8 @@ void cmMakefile::AddLinkDirectory(const std::string& dir) } } -void cmMakefile::InitializeFromParent() +void cmMakefile::InitializeFromParent(cmMakefile* parent) { - cmMakefile *parent = this->LocalGenerator->GetParent()->GetMakefile(); - // Initialize definitions with the closure of the parent scope. this->Internal->InitializeDefinitions(parent); @@ -1672,7 +1670,7 @@ void cmMakefile::Configure() void cmMakefile::ConfigureSubDirectory(cmMakefile *mf) { - mf->InitializeFromParent(); + mf->InitializeFromParent(this); std::string currentStart = mf->GetCurrentSourceDirectory(); if (this->GetCMakeInstance()->GetDebugOutput()) { diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 85451ad..def0c23 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -728,7 +728,7 @@ public: cmPropertyMap &GetProperties() { return this->Properties; } ///! Initialize a makefile from its parent - void InitializeFromParent(); + void InitializeFromParent(cmMakefile* parent); void AddInstallGenerator(cmInstallGenerator* g) { if(g) this->InstallGenerators.push_back(g); } -- cgit v0.12 From 021c4b6f2bced25c9adbb472b94148987e1b6398 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 7 Jun 2015 15:11:04 +0200 Subject: cmMakefile: Simplify handling of CACHE_VARIABLES property. --- Source/cmMakefile.cxx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 3ac77e9..b083f70 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -4163,14 +4163,14 @@ const char *cmMakefile::GetProperty(const std::string& prop, output = cmJoin(this->ListFileStack, ";"); return output.c_str(); } - else if (prop == "VARIABLES" || prop == "CACHE_VARIABLES") + else if ( prop == "CACHE_VARIABLES" ) { - int cacheonly = 0; - if ( prop == "CACHE_VARIABLES" ) - { - cacheonly = 1; - } - output = cmJoin(this->GetDefinitions(cacheonly), ";"); + output = cmJoin(this->GetState()->GetCacheEntryKeys(), ";"); + return output.c_str(); + } + else if (prop == "VARIABLES") + { + output = cmJoin(this->GetDefinitions(), ";"); return output.c_str(); } else if (prop == "MACROS") -- cgit v0.12 From 046aafff12e6fa9834c7c114a59389df404ddf18 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 7 Jun 2015 15:11:42 +0200 Subject: cmGetCMakePropertyCommand: Don't explicitly specify default param. --- Source/cmGetCMakePropertyCommand.cxx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/cmGetCMakePropertyCommand.cxx b/Source/cmGetCMakePropertyCommand.cxx index 76803c1..61cf85b 100644 --- a/Source/cmGetCMakePropertyCommand.cxx +++ b/Source/cmGetCMakePropertyCommand.cxx @@ -32,8 +32,7 @@ bool cmGetCMakePropertyCommand if ( args[1] == "VARIABLES" ) { - int cacheonly = 0; - std::vector vars = this->Makefile->GetDefinitions(cacheonly); + std::vector vars = this->Makefile->GetDefinitions(); if (!vars.empty()) { output = cmJoin(vars, ";"); -- cgit v0.12 From 4c192fb53152a61015eb29c0a3826adeec16f8f8 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sun, 7 Jun 2015 15:12:51 +0200 Subject: cmMakefile: Remove cacheOnly option from GetDefinitions. It is now unused. --- Source/cmMakefile.cxx | 13 +++---------- Source/cmMakefile.h | 2 +- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index b083f70..2a3c51b 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -2497,18 +2497,11 @@ const char* cmMakefile::GetSafeDefinition(const std::string& def) const return ret; } -std::vector cmMakefile -::GetDefinitions(int cacheonly /* = 0 */) const +std::vector cmMakefile::GetDefinitions() const { - std::vector res; - if ( !cacheonly ) - { - res = this->Internal->ClosureKeys(); - } - std::vector cacheKeys = - this->GetState()->GetCacheEntryKeys(); + std::vector res = this->Internal->ClosureKeys(); + std::vector cacheKeys = this->GetState()->GetCacheEntryKeys(); res.insert(res.end(), cacheKeys.begin(), cacheKeys.end()); - std::sort(res.begin(), res.end()); return res; } diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index def0c23..ca7d4b0 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -511,7 +511,7 @@ public: * cacheonly is specified and is greater than 0, then only cache * variables will be listed. */ - std::vector GetDefinitions(int cacheonly=0) const; + std::vector GetDefinitions() const; /** * Test a boolean variable to see if it is true or false. -- cgit v0.12