cmMakefile: Remove stack adaptor for the VarStack.

The purpose of the stack is to allow access only to the top of it.  Access
to items which are not at the top is needed, so cmDefinitions objects
get a Parent pointer.

The existence of the Parent pointer is a workaround for the inappropriate
use of stack in the first place.  Remove it now.
This commit is contained in:
Stephen Kelly 2015-04-25 17:21:51 +02:00
parent f983d8913b
commit aaaa65b6a5
1 changed files with 12 additions and 12 deletions

View File

@ -46,7 +46,7 @@
class cmMakefile::Internals class cmMakefile::Internals
{ {
public: public:
std::stack<cmDefinitions, std::list<cmDefinitions> > VarStack; std::list<cmDefinitions> VarStack;
std::stack<std::set<std::string> > VarInitStack; std::stack<std::set<std::string> > VarInitStack;
std::stack<std::set<std::string> > VarUsageStack; std::stack<std::set<std::string> > VarUsageStack;
bool IsSourceFileTryCompile; bool IsSourceFileTryCompile;
@ -56,24 +56,24 @@ public:
cmDefinitions* parent = 0; cmDefinitions* parent = 0;
if (!this->VarStack.empty()) if (!this->VarStack.empty())
{ {
parent = &this->VarStack.top(); parent = &this->VarStack.back();
} }
this->VarStack.push(cmDefinitions(parent)); this->VarStack.push_back(cmDefinitions(parent));
} }
void InitializeDefinitions(cmMakefile* parent) void InitializeDefinitions(cmMakefile* parent)
{ {
this->VarStack.top() = parent->Internal->VarStack.top().MakeClosure(); this->VarStack.back() = parent->Internal->VarStack.back().MakeClosure();
} }
const char* GetDefinition(std::string const& name) const char* GetDefinition(std::string const& name)
{ {
return this->VarStack.top().Get(name); return this->VarStack.back().Get(name);
} }
void SetDefinition(std::string const& name, std::string const& value) void SetDefinition(std::string const& name, std::string const& value)
{ {
this->VarStack.top().Set(name, value.c_str()); this->VarStack.back().Set(name, value.c_str());
} }
void RemoveDefinition(std::string const& name) void RemoveDefinition(std::string const& name)
@ -81,32 +81,32 @@ public:
if (this->VarStack.size() > 1) if (this->VarStack.size() > 1)
{ {
// In lower scopes we store keys, defined or not. // In lower scopes we store keys, defined or not.
this->VarStack.top().Set(name, 0); this->VarStack.back().Set(name, 0);
} }
else else
{ {
this->VarStack.top().Erase(name); this->VarStack.back().Erase(name);
} }
} }
std::vector<std::string> LocalKeys() const std::vector<std::string> LocalKeys() const
{ {
return this->VarStack.top().LocalKeys(); return this->VarStack.back().LocalKeys();
} }
std::vector<std::string> ClosureKeys() const std::vector<std::string> ClosureKeys() const
{ {
return this->VarStack.top().ClosureKeys(); return this->VarStack.back().ClosureKeys();
} }
void PopDefinitions() void PopDefinitions()
{ {
this->VarStack.pop(); this->VarStack.pop_back();
} }
bool RaiseScope(std::string const& var, const char* varDef, cmMakefile* mf) bool RaiseScope(std::string const& var, const char* varDef, cmMakefile* mf)
{ {
cmDefinitions& cur = this->VarStack.top(); cmDefinitions& cur = this->VarStack.back();
if(cmDefinitions* up = cur.GetParent()) if(cmDefinitions* up = cur.GetParent())
{ {
// First localize the definition in the current scope. // First localize the definition in the current scope.