From 25e04ddffeba6d4b1c9deab1ea42038c322cec83 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 30 May 2015 17:08:34 +0200 Subject: [PATCH] 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. --- Source/cmDefinitions.cxx | 14 +++++++------- Source/cmDefinitions.h | 17 ++++++++++------- Source/cmMakefile.cxx | 41 +++++++++++++++++++++------------------- 3 files changed, 39 insertions(+), 33 deletions(-) diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx index 2dab169ef..b06fb5c0b 100644 --- a/Source/cmDefinitions.cxx +++ b/Source/cmDefinitions.cxx @@ -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 cmDefinitions::UnusedKeys() const } //---------------------------------------------------------------------------- -cmDefinitions cmDefinitions::MakeClosure(StackConstIter begin, - StackConstIter end) +cmDefinitions cmDefinitions::MakeClosure(StackIter begin, + StackIter end) { cmDefinitions closure; std::set 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 -cmDefinitions::ClosureKeys(StackConstIter begin, StackConstIter end) +cmDefinitions::ClosureKeys(StackIter begin, StackIter end) { std::set bound; std::vector 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(); diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h index 5fdcaab72..411867c52 100644 --- a/Source/cmDefinitions.h +++ b/Source/cmDefinitions.h @@ -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 @@ -32,26 +35,26 @@ */ class cmDefinitions { - typedef std::list::reverse_iterator StackIter; - typedef std::list::const_reverse_iterator StackConstIter; + typedef cmLinkedTree::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 UnusedKeys() const; - static std::vector ClosureKeys(StackConstIter begin, - StackConstIter end); + static std::vector ClosureKeys(StackIter begin, + StackIter end); - static cmDefinitions MakeClosure(StackConstIter begin, StackConstIter end); + static cmDefinitions MakeClosure(StackIter begin, StackIter end); private: // String with existence boolean. diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 5b2499ba3..afb016640 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -47,70 +47,73 @@ class cmMakefile::Internals { public: - std::list VarStack; + cmLinkedTree VarTree; + cmLinkedTree::iterator VarTreeIter; bool IsSourceFileTryCompile; void PushDefinitions() { - this->VarStack.push_back(cmDefinitions()); + assert(this->VarTreeIter.IsValid()); + this->VarTreeIter = this->VarTree.Extend(this->VarTreeIter); } void InitializeVarScope() { + this->VarTreeIter = this->VarTree.Root(); this->PushDefinitions(); } void InitializeDefinitions(cmMakefile* parent) { - this->VarStack.back() = - cmDefinitions::MakeClosure(parent->Internal->VarStack.rbegin(), - parent->Internal->VarStack.rend()); + *this->VarTreeIter = + cmDefinitions::MakeClosure(parent->Internal->VarTreeIter, + parent->Internal->VarTree.Root()); } const char* GetDefinition(std::string const& name) { - return cmDefinitions::Get(name, this->VarStack.rbegin(), - this->VarStack.rend()); + assert(this->VarTreeIter != this->VarTree.Root()); + return cmDefinitions::Get(name, + this->VarTreeIter, this->VarTree.Root()); } bool IsInitialized(std::string const& name) { - return cmDefinitions::HasKey(name, this->VarStack.rbegin(), - this->VarStack.rend()); + return cmDefinitions::HasKey(name, + this->VarTreeIter, this->VarTree.Root()); } 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) { - this->VarStack.back().Set(name, 0); + this->VarTreeIter->Set(name, 0); } std::vector UnusedKeys() const { - return this->VarStack.back().UnusedKeys(); + return this->VarTreeIter->UnusedKeys(); } std::vector ClosureKeys() const { - return cmDefinitions::ClosureKeys(this->VarStack.rbegin(), - this->VarStack.rend()); + return cmDefinitions::ClosureKeys(this->VarTreeIter, this->VarTree.Root()); } void PopDefinitions() { - this->VarStack.pop_back(); + ++this->VarTreeIter; } bool RaiseScope(std::string const& var, const char* varDef, cmMakefile* mf) { - std::list::reverse_iterator it = this->VarStack.rbegin(); - assert(it != this->VarStack.rend()); + cmLinkedTree::iterator it = this->VarTreeIter; + assert(it != this->VarTree.Root()); ++it; - if(it == this->VarStack.rend()) + if(it == this->VarTree.Root()) { cmLocalGenerator* plg = mf->LocalGenerator->GetParent(); if(!plg) @@ -132,7 +135,7 @@ public: return true; } // 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. it->Set(var, varDef);