cmDefinitions: Implement in terms of cmLinkedTree.
Store the definitions in a cmLinkedTree in the cmMakefile. This can be moved to cmState and then the tree will provide snapshotting possibilities. It will also make the Closure copy created at the start of each cmMakefile unnecesarry.
This commit is contained in:
parent
4bbe261cd3
commit
25e04ddffe
|
@ -56,9 +56,9 @@ void cmDefinitions::Raise(const std::string& key,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cmDefinitions::HasKey(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);
|
MapType::const_iterator i = it->Map.find(key);
|
||||||
if (i != it->Map.end())
|
if (i != it->Map.end())
|
||||||
|
@ -94,12 +94,12 @@ std::vector<std::string> cmDefinitions::UnusedKeys() const
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
cmDefinitions cmDefinitions::MakeClosure(StackConstIter begin,
|
cmDefinitions cmDefinitions::MakeClosure(StackIter begin,
|
||||||
StackConstIter end)
|
StackIter end)
|
||||||
{
|
{
|
||||||
cmDefinitions closure;
|
cmDefinitions closure;
|
||||||
std::set<std::string> undefined;
|
std::set<std::string> undefined;
|
||||||
for (StackConstIter it = begin; it != end; ++it)
|
for (StackIter it = begin; it != end; ++it)
|
||||||
{
|
{
|
||||||
// Consider local definitions.
|
// Consider local definitions.
|
||||||
for(MapType::const_iterator mi = it->Map.begin();
|
for(MapType::const_iterator mi = it->Map.begin();
|
||||||
|
@ -125,12 +125,12 @@ cmDefinitions cmDefinitions::MakeClosure(StackConstIter begin,
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
std::vector<std::string>
|
std::vector<std::string>
|
||||||
cmDefinitions::ClosureKeys(StackConstIter begin, StackConstIter end)
|
cmDefinitions::ClosureKeys(StackIter begin, StackIter end)
|
||||||
{
|
{
|
||||||
std::set<std::string> bound;
|
std::set<std::string> bound;
|
||||||
std::vector<std::string> defined;
|
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());
|
defined.reserve(defined.size() + it->Map.size());
|
||||||
for(MapType::const_iterator mi = it->Map.begin();
|
for(MapType::const_iterator mi = it->Map.begin();
|
||||||
|
|
|
@ -13,6 +13,9 @@
|
||||||
#define cmDefinitions_h
|
#define cmDefinitions_h
|
||||||
|
|
||||||
#include "cmStandardIncludes.h"
|
#include "cmStandardIncludes.h"
|
||||||
|
|
||||||
|
#include "cmLinkedTree.h"
|
||||||
|
|
||||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||||
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
|
#ifdef CMake_HAVE_CXX11_UNORDERED_MAP
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
@ -32,26 +35,26 @@
|
||||||
*/
|
*/
|
||||||
class cmDefinitions
|
class cmDefinitions
|
||||||
{
|
{
|
||||||
typedef std::list<cmDefinitions>::reverse_iterator StackIter;
|
typedef cmLinkedTree<cmDefinitions>::iterator StackIter;
|
||||||
typedef std::list<cmDefinitions>::const_reverse_iterator StackConstIter;
|
|
||||||
public:
|
public:
|
||||||
static const char* Get(const std::string& key,
|
static const char* Get(const std::string& key,
|
||||||
StackIter begin, StackIter end);
|
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,
|
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. */
|
/** Set (or unset if null) a value associated with a key. */
|
||||||
void Set(const std::string& key, const char* value);
|
void Set(const std::string& key, const char* value);
|
||||||
|
|
||||||
std::vector<std::string> UnusedKeys() const;
|
std::vector<std::string> UnusedKeys() const;
|
||||||
|
|
||||||
static std::vector<std::string> ClosureKeys(StackConstIter begin,
|
static std::vector<std::string> ClosureKeys(StackIter begin,
|
||||||
StackConstIter end);
|
StackIter end);
|
||||||
|
|
||||||
static cmDefinitions MakeClosure(StackConstIter begin, StackConstIter end);
|
static cmDefinitions MakeClosure(StackIter begin, StackIter end);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// String with existence boolean.
|
// String with existence boolean.
|
||||||
|
|
|
@ -47,70 +47,73 @@
|
||||||
class cmMakefile::Internals
|
class cmMakefile::Internals
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::list<cmDefinitions> VarStack;
|
cmLinkedTree<cmDefinitions> VarTree;
|
||||||
|
cmLinkedTree<cmDefinitions>::iterator VarTreeIter;
|
||||||
bool IsSourceFileTryCompile;
|
bool IsSourceFileTryCompile;
|
||||||
|
|
||||||
void PushDefinitions()
|
void PushDefinitions()
|
||||||
{
|
{
|
||||||
this->VarStack.push_back(cmDefinitions());
|
assert(this->VarTreeIter.IsValid());
|
||||||
|
this->VarTreeIter = this->VarTree.Extend(this->VarTreeIter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitializeVarScope()
|
void InitializeVarScope()
|
||||||
{
|
{
|
||||||
|
this->VarTreeIter = this->VarTree.Root();
|
||||||
this->PushDefinitions();
|
this->PushDefinitions();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitializeDefinitions(cmMakefile* parent)
|
void InitializeDefinitions(cmMakefile* parent)
|
||||||
{
|
{
|
||||||
this->VarStack.back() =
|
*this->VarTreeIter =
|
||||||
cmDefinitions::MakeClosure(parent->Internal->VarStack.rbegin(),
|
cmDefinitions::MakeClosure(parent->Internal->VarTreeIter,
|
||||||
parent->Internal->VarStack.rend());
|
parent->Internal->VarTree.Root());
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* GetDefinition(std::string const& name)
|
const char* GetDefinition(std::string const& name)
|
||||||
{
|
{
|
||||||
return cmDefinitions::Get(name, this->VarStack.rbegin(),
|
assert(this->VarTreeIter != this->VarTree.Root());
|
||||||
this->VarStack.rend());
|
return cmDefinitions::Get(name,
|
||||||
|
this->VarTreeIter, this->VarTree.Root());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsInitialized(std::string const& name)
|
bool IsInitialized(std::string const& name)
|
||||||
{
|
{
|
||||||
return cmDefinitions::HasKey(name, this->VarStack.rbegin(),
|
return cmDefinitions::HasKey(name,
|
||||||
this->VarStack.rend());
|
this->VarTreeIter, this->VarTree.Root());
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetDefinition(std::string const& name, std::string const& value)
|
void SetDefinition(std::string const& name, std::string const& value)
|
||||||
{
|
{
|
||||||
this->VarStack.back().Set(name, value.c_str());
|
this->VarTreeIter->Set(name, value.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveDefinition(std::string const& name)
|
void RemoveDefinition(std::string const& name)
|
||||||
{
|
{
|
||||||
this->VarStack.back().Set(name, 0);
|
this->VarTreeIter->Set(name, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> UnusedKeys() const
|
std::vector<std::string> UnusedKeys() const
|
||||||
{
|
{
|
||||||
return this->VarStack.back().UnusedKeys();
|
return this->VarTreeIter->UnusedKeys();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> ClosureKeys() const
|
std::vector<std::string> ClosureKeys() const
|
||||||
{
|
{
|
||||||
return cmDefinitions::ClosureKeys(this->VarStack.rbegin(),
|
return cmDefinitions::ClosureKeys(this->VarTreeIter, this->VarTree.Root());
|
||||||
this->VarStack.rend());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PopDefinitions()
|
void PopDefinitions()
|
||||||
{
|
{
|
||||||
this->VarStack.pop_back();
|
++this->VarTreeIter;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RaiseScope(std::string const& var, const char* varDef, cmMakefile* mf)
|
bool RaiseScope(std::string const& var, const char* varDef, cmMakefile* mf)
|
||||||
{
|
{
|
||||||
std::list<cmDefinitions>::reverse_iterator it = this->VarStack.rbegin();
|
cmLinkedTree<cmDefinitions>::iterator it = this->VarTreeIter;
|
||||||
assert(it != this->VarStack.rend());
|
assert(it != this->VarTree.Root());
|
||||||
++it;
|
++it;
|
||||||
if(it == this->VarStack.rend())
|
if(it == this->VarTree.Root())
|
||||||
{
|
{
|
||||||
cmLocalGenerator* plg = mf->LocalGenerator->GetParent();
|
cmLocalGenerator* plg = mf->LocalGenerator->GetParent();
|
||||||
if(!plg)
|
if(!plg)
|
||||||
|
@ -132,7 +135,7 @@ public:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// First localize the definition in the current scope.
|
// First localize the definition in the current scope.
|
||||||
cmDefinitions::Raise(var, this->VarStack.rbegin(), this->VarStack.rend());
|
cmDefinitions::Raise(var, this->VarTreeIter, this->VarTree.Root());
|
||||||
|
|
||||||
// Now update the definition in the parent scope.
|
// Now update the definition in the parent scope.
|
||||||
it->Set(var, varDef);
|
it->Set(var, varDef);
|
||||||
|
|
Loading…
Reference in New Issue