Merge topic 'cmState-definitions'
bff27391
cmState: Host variable definitions.6954c893
cmState: Add a VariableScope snapshot type.1fc645bd
cmState: Add a Base snapshot type.0f070dd3
cmMakefile: Decouple the container of cmDefinitions from scoping logic.25e04ddf
cmDefinitions: Implement in terms of cmLinkedTree.4bbe261c
cmMakefile: Extract InitializeVarScope method.
This commit is contained in:
commit
2370a99400
|
@ -56,9 +56,9 @@ void cmDefinitions::Raise(const std::string& key,
|
|||
}
|
||||
|
||||
bool cmDefinitions::HasKey(const std::string& key,
|
||||
StackConstIter begin, StackConstIter end)
|
||||
StackIter begin, StackIter end)
|
||||
{
|
||||
for (StackConstIter it = begin; it != end; ++it)
|
||||
for (StackIter it = begin; it != end; ++it)
|
||||
{
|
||||
MapType::const_iterator i = it->Map.find(key);
|
||||
if (i != it->Map.end())
|
||||
|
@ -94,12 +94,12 @@ std::vector<std::string> cmDefinitions::UnusedKeys() const
|
|||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
cmDefinitions cmDefinitions::MakeClosure(StackConstIter begin,
|
||||
StackConstIter end)
|
||||
cmDefinitions cmDefinitions::MakeClosure(StackIter begin,
|
||||
StackIter end)
|
||||
{
|
||||
cmDefinitions closure;
|
||||
std::set<std::string> undefined;
|
||||
for (StackConstIter it = begin; it != end; ++it)
|
||||
for (StackIter it = begin; it != end; ++it)
|
||||
{
|
||||
// Consider local definitions.
|
||||
for(MapType::const_iterator mi = it->Map.begin();
|
||||
|
@ -125,12 +125,12 @@ cmDefinitions cmDefinitions::MakeClosure(StackConstIter begin,
|
|||
|
||||
//----------------------------------------------------------------------------
|
||||
std::vector<std::string>
|
||||
cmDefinitions::ClosureKeys(StackConstIter begin, StackConstIter end)
|
||||
cmDefinitions::ClosureKeys(StackIter begin, StackIter end)
|
||||
{
|
||||
std::set<std::string> bound;
|
||||
std::vector<std::string> defined;
|
||||
|
||||
for (StackConstIter it = begin; it != end; ++it)
|
||||
for (StackIter it = begin; it != end; ++it)
|
||||
{
|
||||
defined.reserve(defined.size() + it->Map.size());
|
||||
for(MapType::const_iterator mi = it->Map.begin();
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
#define cmDefinitions_h
|
||||
|
||||
#include "cmStandardIncludes.h"
|
||||
|
||||
#include "cmLinkedTree.h"
|
||||
|
||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
|
||||
#include <unordered_map>
|
||||
|
@ -32,26 +35,26 @@
|
|||
*/
|
||||
class cmDefinitions
|
||||
{
|
||||
typedef std::list<cmDefinitions>::reverse_iterator StackIter;
|
||||
typedef std::list<cmDefinitions>::const_reverse_iterator StackConstIter;
|
||||
typedef cmLinkedTree<cmDefinitions>::iterator StackIter;
|
||||
public:
|
||||
static const char* Get(const std::string& key,
|
||||
StackIter begin, StackIter end);
|
||||
|
||||
static void Raise(const std::string& key, StackIter begin, StackIter end);
|
||||
static void Raise(const std::string& key,
|
||||
StackIter begin, StackIter end);
|
||||
|
||||
static bool HasKey(const std::string& key,
|
||||
StackConstIter begin, StackConstIter end);
|
||||
StackIter begin, StackIter end);
|
||||
|
||||
/** Set (or unset if null) a value associated with a key. */
|
||||
void Set(const std::string& key, const char* value);
|
||||
|
||||
std::vector<std::string> UnusedKeys() const;
|
||||
|
||||
static std::vector<std::string> ClosureKeys(StackConstIter begin,
|
||||
StackConstIter end);
|
||||
static std::vector<std::string> ClosureKeys(StackIter begin,
|
||||
StackIter end);
|
||||
|
||||
static cmDefinitions MakeClosure(StackConstIter begin, StackConstIter end);
|
||||
static cmDefinitions MakeClosure(StackIter begin, StackIter end);
|
||||
|
||||
private:
|
||||
// String with existence boolean.
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#endif
|
||||
#include "cmInstallGenerator.h"
|
||||
#include "cmTestGenerator.h"
|
||||
#include "cmDefinitions.h"
|
||||
#include "cmAlgorithms.h"
|
||||
#include "cmake.h"
|
||||
#include <stdlib.h> // required for atoi
|
||||
|
@ -47,92 +46,7 @@
|
|||
class cmMakefile::Internals
|
||||
{
|
||||
public:
|
||||
std::list<cmDefinitions> VarStack;
|
||||
bool IsSourceFileTryCompile;
|
||||
|
||||
void PushDefinitions()
|
||||
{
|
||||
this->VarStack.push_back(cmDefinitions());
|
||||
}
|
||||
|
||||
void InitializeDefinitions(cmMakefile* parent)
|
||||
{
|
||||
this->VarStack.back() =
|
||||
cmDefinitions::MakeClosure(parent->Internal->VarStack.rbegin(),
|
||||
parent->Internal->VarStack.rend());
|
||||
}
|
||||
|
||||
const char* GetDefinition(std::string const& name)
|
||||
{
|
||||
return cmDefinitions::Get(name, this->VarStack.rbegin(),
|
||||
this->VarStack.rend());
|
||||
}
|
||||
|
||||
bool IsInitialized(std::string const& name)
|
||||
{
|
||||
return cmDefinitions::HasKey(name, this->VarStack.rbegin(),
|
||||
this->VarStack.rend());
|
||||
}
|
||||
|
||||
void SetDefinition(std::string const& name, std::string const& value)
|
||||
{
|
||||
this->VarStack.back().Set(name, value.c_str());
|
||||
}
|
||||
|
||||
void RemoveDefinition(std::string const& name)
|
||||
{
|
||||
this->VarStack.back().Set(name, 0);
|
||||
}
|
||||
|
||||
std::vector<std::string> UnusedKeys() const
|
||||
{
|
||||
return this->VarStack.back().UnusedKeys();
|
||||
}
|
||||
|
||||
std::vector<std::string> ClosureKeys() const
|
||||
{
|
||||
return cmDefinitions::ClosureKeys(this->VarStack.rbegin(),
|
||||
this->VarStack.rend());
|
||||
}
|
||||
|
||||
void PopDefinitions()
|
||||
{
|
||||
this->VarStack.pop_back();
|
||||
}
|
||||
|
||||
bool RaiseScope(std::string const& var, const char* varDef, cmMakefile* mf)
|
||||
{
|
||||
std::list<cmDefinitions>::reverse_iterator it = this->VarStack.rbegin();
|
||||
assert(it != this->VarStack.rend());
|
||||
++it;
|
||||
if(it == this->VarStack.rend())
|
||||
{
|
||||
cmLocalGenerator* plg = mf->LocalGenerator->GetParent();
|
||||
if(!plg)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// Update the definition in the parent directory top scope. This
|
||||
// directory's scope was initialized by the closure of the parent
|
||||
// scope, so we do not need to localize the definition first.
|
||||
cmMakefile* parent = plg->GetMakefile();
|
||||
if (varDef)
|
||||
{
|
||||
parent->AddDefinition(var, varDef);
|
||||
}
|
||||
else
|
||||
{
|
||||
parent->RemoveDefinition(var);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// First localize the definition in the current scope.
|
||||
cmDefinitions::Raise(var, this->VarStack.rbegin(), this->VarStack.rend());
|
||||
|
||||
// Now update the definition in the parent scope.
|
||||
it->Set(var, varDef);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// default is not to be building executables
|
||||
|
@ -141,7 +55,6 @@ cmMakefile::cmMakefile(cmLocalGenerator* localGenerator)
|
|||
LocalGenerator(localGenerator),
|
||||
StateSnapshot(localGenerator->GetStateSnapshot())
|
||||
{
|
||||
this->Internal->PushDefinitions();
|
||||
this->Internal->IsSourceFileTryCompile = false;
|
||||
|
||||
// Initialize these first since AddDefaultDefinitions calls AddDefinition
|
||||
|
@ -1567,9 +1480,6 @@ void cmMakefile::AddLinkLibrary(const std::string& lib)
|
|||
|
||||
void cmMakefile::InitializeFromParent(cmMakefile* parent)
|
||||
{
|
||||
// Initialize definitions with the closure of the parent scope.
|
||||
this->Internal->InitializeDefinitions(parent);
|
||||
|
||||
this->StateSnapshot.InitializeFromParent();
|
||||
|
||||
this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR",
|
||||
|
@ -1634,8 +1544,6 @@ void cmMakefile::PushFunctionScope(std::string const& fileName,
|
|||
fileName);
|
||||
assert(this->StateSnapshot.IsValid());
|
||||
|
||||
this->Internal->PushDefinitions();
|
||||
|
||||
this->PushLoopBlockBarrier();
|
||||
|
||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||
|
@ -1662,8 +1570,6 @@ void cmMakefile::PopFunctionScope(bool reportError)
|
|||
this->PopLoopBlockBarrier();
|
||||
|
||||
this->CheckForUnusedVariables();
|
||||
|
||||
this->Internal->PopDefinitions();
|
||||
}
|
||||
|
||||
void cmMakefile::PushMacroScope(std::string const& fileName,
|
||||
|
@ -1967,7 +1873,7 @@ void cmMakefile::AddDefinition(const std::string& name, const char* value)
|
|||
{
|
||||
this->LogUnused("changing definition", name);
|
||||
}
|
||||
this->Internal->SetDefinition(name, value);
|
||||
this->StateSnapshot.SetDefinition(name, value);
|
||||
|
||||
#ifdef CMAKE_BUILD_WITH_CMAKE
|
||||
cmVariableWatch* vv = this->GetVariableWatch();
|
||||
|
@ -2030,7 +1936,7 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value,
|
|||
this->GetState()->AddCacheEntry(name, haveVal ? val.c_str() : 0,
|
||||
doc, type);
|
||||
// if there was a definition then remove it
|
||||
this->Internal->RemoveDefinition(name);
|
||||
this->StateSnapshot.RemoveDefinition(name);
|
||||
}
|
||||
|
||||
|
||||
|
@ -2040,7 +1946,9 @@ void cmMakefile::AddDefinition(const std::string& name, bool value)
|
|||
{
|
||||
this->LogUnused("changing definition", name);
|
||||
}
|
||||
this->Internal->SetDefinition(name, value ? "ON" : "OFF");
|
||||
|
||||
this->StateSnapshot.SetDefinition(name, value ? "ON" : "OFF");
|
||||
|
||||
#ifdef CMAKE_BUILD_WITH_CMAKE
|
||||
cmVariableWatch* vv = this->GetVariableWatch();
|
||||
if ( vv )
|
||||
|
@ -2057,7 +1965,7 @@ void cmMakefile::CheckForUnusedVariables() const
|
|||
{
|
||||
return;
|
||||
}
|
||||
const std::vector<std::string>& unused = this->Internal->UnusedKeys();
|
||||
const std::vector<std::string>& unused = this->StateSnapshot.UnusedKeys();
|
||||
std::vector<std::string>::const_iterator it = unused.begin();
|
||||
for (; it != unused.end(); ++it)
|
||||
{
|
||||
|
@ -2067,12 +1975,12 @@ void cmMakefile::CheckForUnusedVariables() const
|
|||
|
||||
void cmMakefile::MarkVariableAsUsed(const std::string& var)
|
||||
{
|
||||
this->Internal->GetDefinition(var);
|
||||
this->StateSnapshot.GetDefinition(var);
|
||||
}
|
||||
|
||||
bool cmMakefile::VariableInitialized(const std::string& var) const
|
||||
{
|
||||
return this->Internal->IsInitialized(var);
|
||||
return this->StateSnapshot.IsInitialized(var);
|
||||
}
|
||||
|
||||
void cmMakefile::LogUnused(const char* reason,
|
||||
|
@ -2120,7 +2028,7 @@ void cmMakefile::RemoveDefinition(const std::string& name)
|
|||
{
|
||||
this->LogUnused("unsetting", name);
|
||||
}
|
||||
this->Internal->RemoveDefinition(name);
|
||||
this->StateSnapshot.RemoveDefinition(name);
|
||||
#ifdef CMAKE_BUILD_WITH_CMAKE
|
||||
cmVariableWatch* vv = this->GetVariableWatch();
|
||||
if ( vv )
|
||||
|
@ -2598,7 +2506,7 @@ const char* cmMakefile::GetRequiredDefinition(const std::string& name) const
|
|||
|
||||
bool cmMakefile::IsDefinitionSet(const std::string& name) const
|
||||
{
|
||||
const char* def = this->Internal->GetDefinition(name);
|
||||
const char* def = this->StateSnapshot.GetDefinition(name);
|
||||
if(!def)
|
||||
{
|
||||
def = this->GetState()->GetInitializedCacheValue(name);
|
||||
|
@ -2619,7 +2527,7 @@ bool cmMakefile::IsDefinitionSet(const std::string& name) const
|
|||
|
||||
const char* cmMakefile::GetDefinition(const std::string& name) const
|
||||
{
|
||||
const char* def = this->Internal->GetDefinition(name);
|
||||
const char* def = this->StateSnapshot.GetDefinition(name);
|
||||
if(!def)
|
||||
{
|
||||
def = this->GetState()->GetInitializedCacheValue(name);
|
||||
|
@ -2655,7 +2563,7 @@ const char* cmMakefile::GetSafeDefinition(const std::string& def) const
|
|||
|
||||
std::vector<std::string> cmMakefile::GetDefinitions() const
|
||||
{
|
||||
std::vector<std::string> res = this->Internal->ClosureKeys();
|
||||
std::vector<std::string> res = this->StateSnapshot.ClosureKeys();
|
||||
std::vector<std::string> cacheKeys = this->GetState()->GetCacheEntryKeys();
|
||||
res.insert(res.end(), cacheKeys.begin(), cacheKeys.end());
|
||||
std::sort(res.begin(), res.end());
|
||||
|
@ -4434,8 +4342,17 @@ std::string cmMakefile::FormatListFileStack() const
|
|||
|
||||
void cmMakefile::PushScope()
|
||||
{
|
||||
this->Internal->PushDefinitions();
|
||||
|
||||
std::string commandName;
|
||||
long line = 0;
|
||||
if (!this->ContextStack.empty())
|
||||
{
|
||||
commandName = this->ContextStack.back()->Name;
|
||||
line = this->ContextStack.back()->Line;
|
||||
}
|
||||
this->StateSnapshot = this->GetState()->CreateVariableScopeSnapshot(
|
||||
this->StateSnapshot,
|
||||
commandName,
|
||||
line);
|
||||
this->PushLoopBlockBarrier();
|
||||
|
||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||
|
@ -4453,7 +4370,9 @@ void cmMakefile::PopScope()
|
|||
|
||||
this->CheckForUnusedVariables();
|
||||
|
||||
this->Internal->PopDefinitions();
|
||||
this->StateSnapshot =
|
||||
this->GetState()->Pop(this->StateSnapshot);
|
||||
assert(this->StateSnapshot.IsValid());
|
||||
}
|
||||
|
||||
void cmMakefile::RaiseScope(const std::string& var, const char *varDef)
|
||||
|
@ -4463,7 +4382,7 @@ void cmMakefile::RaiseScope(const std::string& var, const char *varDef)
|
|||
return;
|
||||
}
|
||||
|
||||
if (!this->Internal->RaiseScope(var, varDef, this))
|
||||
if (!this->StateSnapshot.RaiseScope(var, varDef))
|
||||
{
|
||||
std::ostringstream m;
|
||||
m << "Cannot set \"" << var << "\": current scope has no parent.";
|
||||
|
|
|
@ -15,11 +15,13 @@
|
|||
#include "cmCacheManager.h"
|
||||
#include "cmCommand.h"
|
||||
#include "cmAlgorithms.h"
|
||||
#include "cmDefinitions.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
struct cmState::SnapshotDataType
|
||||
{
|
||||
cmState::PositionType ScopeParent;
|
||||
cmState::PositionType DirectoryParent;
|
||||
cmLinkedTree<cmState::PolicyStackEntry>::iterator Policies;
|
||||
cmLinkedTree<cmState::PolicyStackEntry>::iterator PolicyRoot;
|
||||
|
@ -28,6 +30,9 @@ struct cmState::SnapshotDataType
|
|||
cmLinkedTree<std::string>::iterator ExecutionListFile;
|
||||
cmLinkedTree<cmState::BuildsystemDirectoryStateType>::iterator
|
||||
BuildSystemDirectory;
|
||||
cmLinkedTree<cmDefinitions>::iterator Vars;
|
||||
cmLinkedTree<cmDefinitions>::iterator Root;
|
||||
cmLinkedTree<cmDefinitions>::iterator Parent;
|
||||
std::string EntryPointCommand;
|
||||
long EntryPointLine;
|
||||
std::vector<std::string>::size_type IncludeDirectoryPosition;
|
||||
|
@ -274,6 +279,10 @@ cmState::Snapshot cmState::Reset()
|
|||
pos->PolicyScope = this->PolicyStack.Root();
|
||||
assert(pos->Policies.IsValid());
|
||||
assert(pos->PolicyRoot.IsValid());
|
||||
this->VarTree.Clear();
|
||||
pos->Vars = this->VarTree.Extend(this->VarTree.Root());
|
||||
pos->Parent = this->VarTree.Root();
|
||||
pos->Root = this->VarTree.Root();
|
||||
|
||||
this->DefineProperty
|
||||
("RULE_LAUNCH_COMPILE", cmProperty::DIRECTORY,
|
||||
|
@ -736,7 +745,8 @@ cmState::Snapshot cmState::CreateBaseSnapshot()
|
|||
{
|
||||
PositionType pos = this->SnapshotData.Extend(this->SnapshotData.Root());
|
||||
pos->DirectoryParent = this->SnapshotData.Root();
|
||||
pos->SnapshotType = BuildsystemDirectoryType;
|
||||
pos->ScopeParent = this->SnapshotData.Root();
|
||||
pos->SnapshotType = BaseType;
|
||||
pos->BuildSystemDirectory =
|
||||
this->BuildsystemDirectory.Extend(this->BuildsystemDirectory.Root());
|
||||
pos->ExecutionListFile =
|
||||
|
@ -750,6 +760,10 @@ cmState::Snapshot cmState::CreateBaseSnapshot()
|
|||
pos->PolicyScope = this->PolicyStack.Root();
|
||||
assert(pos->Policies.IsValid());
|
||||
assert(pos->PolicyRoot.IsValid());
|
||||
pos->Vars = this->VarTree.Extend(this->VarTree.Root());
|
||||
assert(pos->Vars.IsValid());
|
||||
pos->Parent = this->VarTree.Root();
|
||||
pos->Root = this->VarTree.Root();
|
||||
return cmState::Snapshot(this, pos);
|
||||
}
|
||||
|
||||
|
@ -763,6 +777,7 @@ cmState::CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot,
|
|||
pos->EntryPointLine = entryPointLine;
|
||||
pos->EntryPointCommand = entryPointCommand;
|
||||
pos->DirectoryParent = originSnapshot.Position;
|
||||
pos->ScopeParent = originSnapshot.Position;
|
||||
pos->SnapshotType = BuildsystemDirectoryType;
|
||||
pos->BuildSystemDirectory =
|
||||
this->BuildsystemDirectory.Extend(
|
||||
|
@ -776,6 +791,12 @@ cmState::CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot,
|
|||
pos->PolicyScope = originSnapshot.Position->Policies;
|
||||
assert(pos->Policies.IsValid());
|
||||
assert(pos->PolicyRoot.IsValid());
|
||||
|
||||
cmLinkedTree<cmDefinitions>::iterator origin =
|
||||
originSnapshot.Position->Vars;
|
||||
pos->Parent = origin;
|
||||
pos->Root = origin;
|
||||
pos->Vars = this->VarTree.Extend(origin);
|
||||
return cmState::Snapshot(this, pos);
|
||||
}
|
||||
|
||||
|
@ -787,6 +808,7 @@ cmState::CreateFunctionCallSnapshot(cmState::Snapshot originSnapshot,
|
|||
{
|
||||
PositionType pos = this->SnapshotData.Extend(originSnapshot.Position,
|
||||
*originSnapshot.Position);
|
||||
pos->ScopeParent = originSnapshot.Position;
|
||||
pos->EntryPointLine = entryPointLine;
|
||||
pos->EntryPointCommand = entryPointCommand;
|
||||
pos->SnapshotType = FunctionCallType;
|
||||
|
@ -794,6 +816,11 @@ cmState::CreateFunctionCallSnapshot(cmState::Snapshot originSnapshot,
|
|||
originSnapshot.Position->ExecutionListFile, fileName);
|
||||
pos->BuildSystemDirectory->DirectoryEnd = pos;
|
||||
pos->PolicyScope = originSnapshot.Position->Policies;
|
||||
assert(originSnapshot.Position->Vars.IsValid());
|
||||
cmLinkedTree<cmDefinitions>::iterator origin =
|
||||
originSnapshot.Position->Vars;
|
||||
pos->Parent = origin;
|
||||
pos->Vars = this->VarTree.Extend(origin);
|
||||
return cmState::Snapshot(this, pos);
|
||||
}
|
||||
|
||||
|
@ -811,6 +838,7 @@ cmState::CreateMacroCallSnapshot(cmState::Snapshot originSnapshot,
|
|||
pos->SnapshotType = MacroCallType;
|
||||
pos->ExecutionListFile = this->ExecutionListFiles.Extend(
|
||||
originSnapshot.Position->ExecutionListFile, fileName);
|
||||
assert(originSnapshot.Position->Vars.IsValid());
|
||||
pos->BuildSystemDirectory->DirectoryEnd = pos;
|
||||
pos->PolicyScope = originSnapshot.Position->Policies;
|
||||
return cmState::Snapshot(this, pos);
|
||||
|
@ -829,11 +857,33 @@ cmState::CreateCallStackSnapshot(cmState::Snapshot originSnapshot,
|
|||
pos->SnapshotType = CallStackType;
|
||||
pos->ExecutionListFile = this->ExecutionListFiles.Extend(
|
||||
originSnapshot.Position->ExecutionListFile, fileName);
|
||||
assert(originSnapshot.Position->Vars.IsValid());
|
||||
pos->BuildSystemDirectory->DirectoryEnd = pos;
|
||||
pos->PolicyScope = originSnapshot.Position->Policies;
|
||||
return cmState::Snapshot(this, pos);
|
||||
}
|
||||
|
||||
cmState::Snapshot
|
||||
cmState::CreateVariableScopeSnapshot(cmState::Snapshot originSnapshot,
|
||||
std::string const& entryPointCommand,
|
||||
long entryPointLine)
|
||||
{
|
||||
PositionType pos = this->SnapshotData.Extend(originSnapshot.Position,
|
||||
*originSnapshot.Position);
|
||||
pos->ScopeParent = originSnapshot.Position;
|
||||
pos->EntryPointLine = entryPointLine;
|
||||
pos->EntryPointCommand = entryPointCommand;
|
||||
pos->SnapshotType = VariableScopeType;
|
||||
assert(originSnapshot.Position->Vars.IsValid());
|
||||
|
||||
cmLinkedTree<cmDefinitions>::iterator origin =
|
||||
originSnapshot.Position->Vars;
|
||||
pos->Parent = origin;
|
||||
pos->Vars = this->VarTree.Extend(origin);
|
||||
assert(pos->Vars.IsValid());
|
||||
return cmState::Snapshot(this, pos);
|
||||
}
|
||||
|
||||
cmState::Snapshot
|
||||
cmState::CreateInlineListFileSnapshot(cmState::Snapshot originSnapshot,
|
||||
const std::string& entryPointCommand,
|
||||
|
@ -1019,7 +1069,8 @@ cmState::Snapshot cmState::Snapshot::GetCallStackParent() const
|
|||
{
|
||||
++parentPos;
|
||||
}
|
||||
if (parentPos->SnapshotType == cmState::BuildsystemDirectoryType)
|
||||
if (parentPos->SnapshotType == cmState::BuildsystemDirectoryType
|
||||
|| parentPos->SnapshotType == cmState::BaseType)
|
||||
{
|
||||
return snapshot;
|
||||
}
|
||||
|
@ -1121,6 +1172,72 @@ bool cmState::Snapshot::HasDefinedPolicyCMP0011()
|
|||
return !this->Position->Policies->IsEmpty();
|
||||
}
|
||||
|
||||
const char* cmState::Snapshot::GetDefinition(std::string const& name) const
|
||||
{
|
||||
assert(this->Position->Vars.IsValid());
|
||||
return cmDefinitions::Get(name, this->Position->Vars,
|
||||
this->Position->Root);
|
||||
}
|
||||
|
||||
bool cmState::Snapshot::IsInitialized(std::string const& name) const
|
||||
{
|
||||
return cmDefinitions::HasKey(name, this->Position->Vars,
|
||||
this->Position->Root);
|
||||
}
|
||||
|
||||
void cmState::Snapshot::SetDefinition(std::string const& name,
|
||||
std::string const& value)
|
||||
{
|
||||
this->Position->Vars->Set(name, value.c_str());
|
||||
}
|
||||
|
||||
void cmState::Snapshot::RemoveDefinition(std::string const& name)
|
||||
{
|
||||
this->Position->Vars->Set(name, 0);
|
||||
}
|
||||
|
||||
std::vector<std::string> cmState::Snapshot::UnusedKeys() const
|
||||
{
|
||||
return this->Position->Vars->UnusedKeys();
|
||||
}
|
||||
|
||||
std::vector<std::string> cmState::Snapshot::ClosureKeys() const
|
||||
{
|
||||
return cmDefinitions::ClosureKeys(this->Position->Vars,
|
||||
this->Position->Root);
|
||||
}
|
||||
|
||||
bool cmState::Snapshot::RaiseScope(std::string const& var, const char* varDef)
|
||||
{
|
||||
if(this->Position->ScopeParent == this->Position->DirectoryParent)
|
||||
{
|
||||
Snapshot parentDir = this->GetBuildsystemDirectoryParent();
|
||||
if(!parentDir.IsValid())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// Update the definition in the parent directory top scope. This
|
||||
// directory's scope was initialized by the closure of the parent
|
||||
// scope, so we do not need to localize the definition first.
|
||||
if (varDef)
|
||||
{
|
||||
parentDir.SetDefinition(var, varDef);
|
||||
}
|
||||
else
|
||||
{
|
||||
parentDir.RemoveDefinition(var);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// First localize the definition in the current scope.
|
||||
cmDefinitions::Raise(var, this->Position->Vars,
|
||||
this->Position->Root);
|
||||
|
||||
// Now update the definition in the parent scope.
|
||||
this->Position->Parent->Set(var, varDef);
|
||||
return true;
|
||||
}
|
||||
|
||||
static const std::string cmPropertySentinal = std::string();
|
||||
|
||||
template<typename T, typename U, typename V>
|
||||
|
@ -1157,6 +1274,11 @@ void InitializeContentFromParent(T& parentContent,
|
|||
void cmState::Snapshot::InitializeFromParent()
|
||||
{
|
||||
PositionType parent = this->Position->DirectoryParent;
|
||||
assert(this->Position->Vars.IsValid());
|
||||
assert(parent->Vars.IsValid());
|
||||
|
||||
*this->Position->Vars =
|
||||
cmDefinitions::MakeClosure(parent->Vars, parent->Root);
|
||||
|
||||
InitializeContentFromParent(parent->BuildSystemDirectory->IncludeDirectories,
|
||||
this->Position->BuildSystemDirectory->IncludeDirectories,
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
class cmake;
|
||||
class cmCommand;
|
||||
class cmDefinitions;
|
||||
class cmListFileBacktrace;
|
||||
|
||||
class cmState
|
||||
{
|
||||
|
@ -35,12 +37,14 @@ public:
|
|||
|
||||
enum SnapshotType
|
||||
{
|
||||
BaseType,
|
||||
BuildsystemDirectoryType,
|
||||
FunctionCallType,
|
||||
MacroCallType,
|
||||
CallStackType,
|
||||
InlineListFileType,
|
||||
PolicyScopeType
|
||||
PolicyScopeType,
|
||||
VariableScopeType
|
||||
};
|
||||
|
||||
class Directory;
|
||||
|
@ -50,6 +54,14 @@ public:
|
|||
Snapshot(cmState* state = 0);
|
||||
Snapshot(cmState* state, PositionType position);
|
||||
|
||||
const char* GetDefinition(std::string const& name) const;
|
||||
bool IsInitialized(std::string const& name) const;
|
||||
void SetDefinition(std::string const& name, std::string const& value);
|
||||
void RemoveDefinition(std::string const& name);
|
||||
std::vector<std::string> UnusedKeys() const;
|
||||
std::vector<std::string> ClosureKeys() const;
|
||||
bool RaiseScope(std::string const& var, const char* varDef);
|
||||
|
||||
void SetListFile(std::string const& listfile);
|
||||
|
||||
std::string GetExecutionListFile() const;
|
||||
|
@ -161,6 +173,9 @@ public:
|
|||
std::string const& entryPointCommand,
|
||||
long entryPointLine,
|
||||
std::string const& fileName);
|
||||
Snapshot CreateVariableScopeSnapshot(Snapshot originSnapshot,
|
||||
std::string const& entryPointCommand,
|
||||
long entryPointLine);
|
||||
Snapshot CreateInlineListFileSnapshot(Snapshot originSnapshot,
|
||||
const std::string& entryPointCommand,
|
||||
long entryPointLine,
|
||||
|
@ -275,6 +290,7 @@ private:
|
|||
|
||||
cmLinkedTree<PolicyStackEntry> PolicyStack;
|
||||
cmLinkedTree<SnapshotDataType> SnapshotData;
|
||||
cmLinkedTree<cmDefinitions> VarTree;
|
||||
|
||||
std::vector<std::string> SourceDirectoryComponents;
|
||||
std::vector<std::string> BinaryDirectoryComponents;
|
||||
|
|
Loading…
Reference in New Issue