2009-09-28 19:43:28 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2009-07-22 22:22:45 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2009-07-22 22:22:45 +04:00
|
|
|
|
2009-09-28 19:43:28 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2009-07-22 22:22:45 +04:00
|
|
|
#include "cmDefinitions.h"
|
|
|
|
|
2015-04-26 16:54:02 +03:00
|
|
|
#include <list>
|
|
|
|
|
2009-07-22 22:22:45 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
cmDefinitions::Def cmDefinitions::NoDef;
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2014-03-12 09:48:06 +04:00
|
|
|
cmDefinitions::cmDefinitions(cmDefinitions* parent)
|
|
|
|
: Up(parent)
|
2009-07-22 22:22:45 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
cmDefinitions::Def const&
|
2014-10-24 20:58:12 +04:00
|
|
|
cmDefinitions::GetInternal(const std::string& key)
|
2009-07-22 22:22:45 +04:00
|
|
|
{
|
|
|
|
MapType::const_iterator i = this->Map.find(key);
|
|
|
|
if(i != this->Map.end())
|
|
|
|
{
|
|
|
|
return i->second;
|
|
|
|
}
|
2014-03-12 09:48:06 +04:00
|
|
|
if(cmDefinitions* up = this->Up)
|
2009-07-22 22:22:45 +04:00
|
|
|
{
|
2014-10-24 20:58:12 +04:00
|
|
|
// 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;
|
2009-07-22 22:22:45 +04:00
|
|
|
}
|
|
|
|
return this->NoDef;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2015-04-26 12:33:47 +03:00
|
|
|
const char* cmDefinitions::Get(const std::string& key)
|
2009-07-22 22:22:45 +04:00
|
|
|
{
|
2015-04-26 12:33:47 +03:00
|
|
|
Def const& def = this->GetInternal(key);
|
|
|
|
return def.Exists? def.c_str() : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
void cmDefinitions::Set(const std::string& key, const char* value)
|
|
|
|
{
|
|
|
|
Def def(value);
|
2015-04-25 17:36:48 +03:00
|
|
|
this->Map[key] = def;
|
2009-07-22 22:22:45 +04:00
|
|
|
}
|
|
|
|
|
2015-04-25 17:33:26 +03:00
|
|
|
void cmDefinitions::Erase(const std::string& key)
|
|
|
|
{
|
|
|
|
this->Map.erase(key);
|
|
|
|
}
|
|
|
|
|
2010-08-24 22:40:51 +04:00
|
|
|
//----------------------------------------------------------------------------
|
2015-04-26 17:34:13 +03:00
|
|
|
std::vector<std::string> cmDefinitions::LocalKeys() const
|
2010-08-24 22:40:51 +04:00
|
|
|
{
|
2015-04-26 17:34:13 +03:00
|
|
|
std::vector<std::string> keys;
|
|
|
|
keys.reserve(this->Map.size());
|
2010-08-24 22:40:51 +04:00
|
|
|
// Consider local definitions.
|
|
|
|
for(MapType::const_iterator mi = this->Map.begin();
|
|
|
|
mi != this->Map.end(); ++mi)
|
|
|
|
{
|
2010-09-17 00:07:34 +04:00
|
|
|
if (mi->second.Exists)
|
|
|
|
{
|
2015-04-26 17:34:13 +03:00
|
|
|
keys.push_back(mi->first);
|
2010-09-17 00:07:34 +04:00
|
|
|
}
|
2010-08-24 22:40:51 +04:00
|
|
|
}
|
|
|
|
return keys;
|
|
|
|
}
|
|
|
|
|
2009-07-22 22:22:45 +04:00
|
|
|
//----------------------------------------------------------------------------
|
2015-04-26 16:44:26 +03:00
|
|
|
cmDefinitions cmDefinitions::MakeClosure() const
|
2009-07-22 22:22:45 +04:00
|
|
|
{
|
2014-02-10 09:21:34 +04:00
|
|
|
std::set<std::string> undefined;
|
2015-04-26 16:44:26 +03:00
|
|
|
cmDefinitions closure;
|
|
|
|
closure.MakeClosure(undefined, this);
|
|
|
|
return closure;
|
2009-07-22 22:22:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2015-04-26 16:44:26 +03:00
|
|
|
void cmDefinitions::MakeClosure(std::set<std::string>& undefined,
|
2009-07-22 22:22:45 +04:00
|
|
|
cmDefinitions const* defs)
|
|
|
|
{
|
2015-04-26 16:54:02 +03:00
|
|
|
std::list<cmDefinitions const*> ups;
|
2015-04-26 16:49:43 +03:00
|
|
|
while(defs)
|
2009-07-22 22:22:45 +04:00
|
|
|
{
|
2015-04-26 16:54:02 +03:00
|
|
|
ups.push_back(defs);
|
|
|
|
defs = defs->Up;
|
|
|
|
}
|
|
|
|
for (std::list<cmDefinitions const*>::const_iterator it = ups.begin();
|
|
|
|
it != ups.end(); ++it)
|
|
|
|
{
|
2015-04-26 16:49:43 +03:00
|
|
|
// Consider local definitions.
|
2015-04-26 16:54:02 +03:00
|
|
|
for(MapType::const_iterator mi = (*it)->Map.begin();
|
|
|
|
mi != (*it)->Map.end(); ++mi)
|
2009-07-22 22:22:45 +04:00
|
|
|
{
|
2015-04-26 16:49:43 +03:00
|
|
|
// Use this key if it is not already set or unset.
|
|
|
|
if(this->Map.find(mi->first) == this->Map.end() &&
|
|
|
|
undefined.find(mi->first) == undefined.end())
|
2009-07-22 22:22:45 +04:00
|
|
|
{
|
2015-04-26 16:49:43 +03:00
|
|
|
if(mi->second.Exists)
|
|
|
|
{
|
|
|
|
this->Map.insert(*mi);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
undefined.insert(mi->first);
|
|
|
|
}
|
2009-07-22 22:22:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
2015-04-26 16:36:49 +03:00
|
|
|
std::vector<std::string> cmDefinitions::ClosureKeys() const
|
2009-07-22 22:22:45 +04:00
|
|
|
{
|
2015-04-26 16:36:49 +03:00
|
|
|
std::vector<std::string> defined;
|
|
|
|
std::set<std::string> bound;
|
2009-07-22 22:22:45 +04:00
|
|
|
|
2015-04-26 12:38:08 +03:00
|
|
|
cmDefinitions const* up = this;
|
|
|
|
|
|
|
|
while (up)
|
2009-07-22 22:22:45 +04:00
|
|
|
{
|
2015-04-26 12:38:08 +03:00
|
|
|
// Consider local definitions.
|
|
|
|
for(MapType::const_iterator mi = up->Map.begin();
|
|
|
|
mi != up->Map.end(); ++mi)
|
2009-07-22 22:22:45 +04:00
|
|
|
{
|
2015-04-26 12:38:08 +03:00
|
|
|
// Use this key if it is not already set or unset.
|
2015-04-26 16:36:49 +03:00
|
|
|
if(bound.insert(mi->first).second && mi->second.Exists)
|
2015-04-26 12:38:08 +03:00
|
|
|
{
|
2015-04-26 16:36:49 +03:00
|
|
|
defined.push_back(mi->first);
|
2015-04-26 12:38:08 +03:00
|
|
|
}
|
2009-07-22 22:22:45 +04:00
|
|
|
}
|
2015-04-26 12:38:08 +03:00
|
|
|
up = up->Up;
|
2009-07-22 22:22:45 +04:00
|
|
|
}
|
2015-04-26 16:38:09 +03:00
|
|
|
return defined;
|
2009-07-22 22:22:45 +04:00
|
|
|
}
|