Merge topic 'clean-up-cmMakefile'

4c192fb5 cmMakefile: Remove cacheOnly option from GetDefinitions.
046aafff cmGetCMakePropertyCommand: Don't explicitly specify default param.
021c4b6f cmMakefile: Simplify handling of CACHE_VARIABLES property.
1981c971 cmMakefile: Simplify InitializeFromParent method.
353e422b cmMakefile: Remove unused GetPolicies method.
00bfa047 cmMakefile: Out-of-line the cmMakefileCall.
db74ce58 cmMakefile: Inline PushScope into PushFunctionScope.
ca140c2e cmMakefile: Create a unified raii for macro scopes.
d5dc4169 cmMakefile: Create a unified raii for function scopes.
This commit is contained in:
Brad King 2015-06-08 13:54:09 -04:00 committed by CMake Topic Stage
commit ccc6fe9445
6 changed files with 141 additions and 63 deletions

View File

@ -73,7 +73,6 @@ public:
cmPolicies::PolicyMap Policies;
};
bool cmFunctionHelperCommand::InvokeInitialPass
(const std::vector<cmListFileArgument>& 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<void>(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;
}

View File

@ -32,8 +32,7 @@ bool cmGetCMakePropertyCommand
if ( args[1] == "VARIABLES" )
{
int cacheonly = 0;
std::vector<std::string> vars = this->Makefile->GetDefinitions(cacheonly);
std::vector<std::string> vars = this->Makefile->GetDefinitions();
if (!vars.empty())
{
output = cmJoin(vars, ";");

View File

@ -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;
}

View File

@ -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<std::string> cmMakefile
::GetDefinitions(int cacheonly /* = 0 */) const
std::vector<std::string> cmMakefile::GetDefinitions() const
{
std::vector<std::string> res;
if ( !cacheonly )
{
res = this->Internal->ClosureKeys();
}
std::vector<std::string> cacheKeys =
this->GetState()->GetCacheEntryKeys();
std::vector<std::string> res = this->Internal->ClosureKeys();
std::vector<std::string> 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();
}

View File

@ -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<cmListFileContext> CMP0054ReportedIds;
/**
@ -517,7 +511,7 @@ public:
* cacheonly is specified and is greater than 0, then only cache
* variables will be listed.
*/
std::vector<std::string> GetDefinitions(int cacheonly=0) const;
std::vector<std::string> 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<cmTestGenerator*>& 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;
};

View File

@ -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; }