diff --git a/Source/cmFunctionCommand.cxx b/Source/cmFunctionCommand.cxx index 001adb18c..dc6d2d270 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/cmGetCMakePropertyCommand.cxx b/Source/cmGetCMakePropertyCommand.cxx index 76803c103..61cf85b8e 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, ";"); diff --git a/Source/cmMacroCommand.cxx b/Source/cmMacroCommand.cxx index 7ac44320c..028ab6223 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 622c6a981..e81b0a2ce 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); @@ -1562,6 +1560,56 @@ void cmMakefile::InitializeFromParent() this->ImportedTargets = parent->ImportedTargets; } +void cmMakefile::PushFunctionScope(const cmPolicies::PolicyMap& pm) +{ + this->Internal->PushDefinitions(); + + this->PushLoopBlockBarrier(); + +#if defined(CMAKE_BUILD_WITH_CMAKE) + this->GetGlobalGenerator()->GetFileLockPool().PushFunctionScope(); +#endif + + this->PushFunctionBlockerBarrier(); + + this->PushPolicy(true, pm); + this->PushPolicyBarrier(); +} + +void cmMakefile::PopFunctionScope(bool reportError) +{ + this->PopPolicyBarrier(reportError); + this->PopPolicy(); + + this->PopFunctionBlockerBarrier(reportError); + +#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) +{ + this->PushFunctionBlockerBarrier(); + + this->PushPolicy(true, pm); + this->PushPolicyBarrier(); +} + +void cmMakefile::PopMacroScope(bool reportError) +{ + this->PopPolicyBarrier(reportError); + this->PopPolicy(); + + this->PopFunctionBlockerBarrier(reportError); +} + //---------------------------------------------------------------------------- class cmMakefileCurrent { @@ -1622,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()) { @@ -2449,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; } @@ -4115,14 +4156,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") @@ -5396,3 +5437,41 @@ 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); +} + + +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); +} + +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 c6e8bff78..46df37ba2 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; /** @@ -517,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. @@ -731,7 +725,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); } @@ -743,7 +737,36 @@ 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; + }; + + 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); @@ -1054,15 +1077,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; }; diff --git a/Source/cmake.h b/Source/cmake.h index 0fe7bfcc9..f0f94115c 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; }