cmDefinitions: Accept varStack iterators in Get API.

This commit is contained in:
Stephen Kelly 2015-04-30 00:19:55 +02:00
parent e8ae46e5e2
commit 8b1745a1c5
3 changed files with 22 additions and 10 deletions

View File

@ -11,6 +11,8 @@
============================================================================*/
#include "cmDefinitions.h"
#include <assert.h>
//----------------------------------------------------------------------------
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<cmDefinitions>::reverse_iterator rbegin,
std::list<cmDefinitions>::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<cmDefinitions>::reverse_iterator rbegin,
std::list<cmDefinitions>::reverse_iterator rend)
{
Def const& def = this->GetInternal(key);
Def const& def = this->GetInternal(key, rbegin, rend);
return def.Exists? def.c_str() : 0;
}

View File

@ -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<cmDefinitions>::reverse_iterator rbegin,
std::list<cmDefinitions>::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<cmDefinitions>::reverse_iterator rbegin,
std::list<cmDefinitions>::reverse_iterator rend);
void MakeClosure(std::set<std::string>& undefined,
std::list<cmDefinitions>::const_reverse_iterator rbegin,

View File

@ -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)