diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx index 61328be60..94d27c29c 100644 --- a/Source/cmDefinitions.cxx +++ b/Source/cmDefinitions.cxx @@ -11,6 +11,8 @@ ============================================================================*/ #include "cmDefinitions.h" +#include + //---------------------------------------------------------------------------- cmDefinitions::Def cmDefinitions::NoDef; @@ -21,28 +23,33 @@ cmDefinitions::cmDefinitions(cmDefinitions* parent) } //---------------------------------------------------------------------------- -cmDefinitions::Def const& -cmDefinitions::GetInternal(const std::string& key) +cmDefinitions::Def const& cmDefinitions::GetInternal( + const std::string& key, + std::list::reverse_iterator rbegin, + std::list::reverse_iterator rend) { + assert(&*rbegin == this); MapType::const_iterator i = this->Map.find(key); if(i != this->Map.end()) { return i->second; } - cmDefinitions* up = this->Up; - if(!up) + ++rbegin; + if(rbegin == rend) { return this->NoDef; } // Query the parent scope and store the result locally. - Def def = up->GetInternal(key); + Def def = rbegin->GetInternal(key, rbegin, rend); return this->Map.insert(MapType::value_type(key, def)).first->second; } //---------------------------------------------------------------------------- -const char* cmDefinitions::Get(const std::string& key) +const char* cmDefinitions::Get(const std::string& key, + std::list::reverse_iterator rbegin, + std::list::reverse_iterator rend) { - Def const& def = this->GetInternal(key); + Def const& def = this->GetInternal(key, rbegin, rend); return def.Exists? def.c_str() : 0; } diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h index 4c7f11f60..2bcfcb0b2 100644 --- a/Source/cmDefinitions.h +++ b/Source/cmDefinitions.h @@ -37,7 +37,9 @@ public: /** Get the value associated with a key; null if none. Store the result locally if it came from a parent. */ - const char* Get(const std::string& key); + const char* Get(const std::string& key, + std::list::reverse_iterator rbegin, + std::list::reverse_iterator rend); /** Set (or unset if null) a value associated with a key. */ void Set(const std::string& key, const char* value); @@ -81,7 +83,9 @@ private: MapType Map; // Internal query and update methods. - Def const& GetInternal(const std::string& key); + Def const& GetInternal(const std::string& key, + std::list::reverse_iterator rbegin, + std::list::reverse_iterator rend); void MakeClosure(std::set& undefined, std::list::const_reverse_iterator rbegin, diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 5686b1b0d..ae7e56454 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -70,7 +70,8 @@ public: const char* GetDefinition(std::string const& name) { - return this->VarStack.back().Get(name); + return this->VarStack.back().Get(name, this->VarStack.rbegin(), + this->VarStack.rend()); } void SetDefinition(std::string const& name, std::string const& value)