Merge topic 'refactor-cmDefinitions-Get'
6c7dad41 cmDefinitions: Make Get method static. a7ce0c7b cmDefinitions: Make GetInternal method static. 7a5039fa cmDefinitions: Use static member without this->. 191573f7 cmDefinitions: Remove Parent pointer. 8b1745a1 cmDefinitions: Accept varStack iterators in Get API.
This commit is contained in:
commit
1ef88dcd46
@ -11,38 +11,39 @@
|
||||
============================================================================*/
|
||||
#include "cmDefinitions.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
cmDefinitions::Def cmDefinitions::NoDef;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
cmDefinitions::cmDefinitions(cmDefinitions* parent)
|
||||
: Up(parent)
|
||||
cmDefinitions::Def const& cmDefinitions::GetInternal(
|
||||
const std::string& key,
|
||||
std::list<cmDefinitions>::reverse_iterator rbegin,
|
||||
std::list<cmDefinitions>::reverse_iterator rend)
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
cmDefinitions::Def const&
|
||||
cmDefinitions::GetInternal(const std::string& key)
|
||||
{
|
||||
MapType::const_iterator i = this->Map.find(key);
|
||||
if(i != this->Map.end())
|
||||
assert(rbegin != rend);
|
||||
MapType::const_iterator i = rbegin->Map.find(key);
|
||||
if (i != rbegin->Map.end())
|
||||
{
|
||||
return i->second;
|
||||
}
|
||||
cmDefinitions* up = this->Up;
|
||||
if(!up)
|
||||
std::list<cmDefinitions>::reverse_iterator rit = rbegin;
|
||||
++rit;
|
||||
if (rit == rend)
|
||||
{
|
||||
return this->NoDef;
|
||||
return cmDefinitions::NoDef;
|
||||
}
|
||||
// Query the parent scope and store the result locally.
|
||||
Def def = up->GetInternal(key);
|
||||
return this->Map.insert(MapType::value_type(key, def)).first->second;
|
||||
Def const& def = cmDefinitions::GetInternal(key, rit, rend);
|
||||
return rbegin->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 = cmDefinitions::GetInternal(key, rbegin, rend);
|
||||
return def.Exists? def.c_str() : 0;
|
||||
}
|
||||
|
||||
|
@ -29,15 +29,11 @@
|
||||
class cmDefinitions
|
||||
{
|
||||
public:
|
||||
/** Construct with the given parent scope. */
|
||||
cmDefinitions(cmDefinitions* parent = 0);
|
||||
|
||||
/** Returns the parent scope, if any. */
|
||||
cmDefinitions* GetParent() const { return this->Up; }
|
||||
|
||||
/** 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);
|
||||
static 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);
|
||||
@ -69,9 +65,6 @@ private:
|
||||
};
|
||||
static Def NoDef;
|
||||
|
||||
// Parent scope, if any.
|
||||
cmDefinitions* Up;
|
||||
|
||||
// Local definitions, set or unset.
|
||||
#if defined(CMAKE_BUILD_WITH_CMAKE)
|
||||
typedef cmsys::hash_map<std::string, Def> MapType;
|
||||
@ -80,9 +73,9 @@ private:
|
||||
#endif
|
||||
MapType Map;
|
||||
|
||||
// Internal query and update methods.
|
||||
Def const& GetInternal(const std::string& key);
|
||||
|
||||
static 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,
|
||||
std::list<cmDefinitions>::const_reverse_iterator rend);
|
||||
|
@ -53,12 +53,7 @@ public:
|
||||
|
||||
void PushDefinitions()
|
||||
{
|
||||
cmDefinitions* parent = 0;
|
||||
if (!this->VarStack.empty())
|
||||
{
|
||||
parent = &this->VarStack.back();
|
||||
}
|
||||
this->VarStack.push_back(cmDefinitions(parent));
|
||||
this->VarStack.push_back(cmDefinitions());
|
||||
}
|
||||
|
||||
void InitializeDefinitions(cmMakefile* parent)
|
||||
@ -70,7 +65,8 @@ public:
|
||||
|
||||
const char* GetDefinition(std::string const& name)
|
||||
{
|
||||
return this->VarStack.back().Get(name);
|
||||
return cmDefinitions::Get(name, this->VarStack.rbegin(),
|
||||
this->VarStack.rend());
|
||||
}
|
||||
|
||||
void SetDefinition(std::string const& name, std::string const& value)
|
||||
|
Loading…
x
Reference in New Issue
Block a user