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-30 01:19:55 +03:00
|
|
|
#include <assert.h>
|
|
|
|
|
2009-07-22 22:22:45 +04:00
|
|
|
cmDefinitions::Def cmDefinitions::NoDef;
|
|
|
|
|
2015-04-30 01:19:55 +03:00
|
|
|
cmDefinitions::Def const& cmDefinitions::GetInternal(
|
2015-05-17 14:21:02 +03:00
|
|
|
const std::string& key, StackIter begin, StackIter end, bool raise)
|
2009-07-22 22:22:45 +04:00
|
|
|
{
|
2015-05-16 06:33:25 +03:00
|
|
|
assert(begin != end);
|
2015-05-17 17:19:55 +03:00
|
|
|
MapType::iterator i = begin->Map.find(key);
|
2015-05-16 06:33:25 +03:00
|
|
|
if (i != begin->Map.end())
|
2009-07-22 22:22:45 +04:00
|
|
|
{
|
2015-05-17 17:19:55 +03:00
|
|
|
i->second.Used = true;
|
2009-07-22 22:22:45 +04:00
|
|
|
return i->second;
|
|
|
|
}
|
2015-05-16 06:33:25 +03:00
|
|
|
StackIter it = begin;
|
|
|
|
++it;
|
|
|
|
if (it == end)
|
2009-07-22 22:22:45 +04:00
|
|
|
{
|
2015-05-01 20:35:47 +03:00
|
|
|
return cmDefinitions::NoDef;
|
2009-07-22 22:22:45 +04:00
|
|
|
}
|
2015-05-17 14:21:02 +03:00
|
|
|
Def const& def = cmDefinitions::GetInternal(key, it, end, raise);
|
|
|
|
if (!raise)
|
|
|
|
{
|
|
|
|
return def;
|
|
|
|
}
|
2015-05-16 06:33:25 +03:00
|
|
|
return begin->Map.insert(MapType::value_type(key, def)).first->second;
|
2009-07-22 22:22:45 +04:00
|
|
|
}
|
|
|
|
|
2015-04-30 01:19:55 +03:00
|
|
|
const char* cmDefinitions::Get(const std::string& key,
|
2015-05-16 06:33:25 +03:00
|
|
|
StackIter begin, StackIter end)
|
2009-07-22 22:22:45 +04:00
|
|
|
{
|
2015-05-17 14:21:02 +03:00
|
|
|
Def const& def = cmDefinitions::GetInternal(key, begin, end, false);
|
2015-04-26 12:33:47 +03:00
|
|
|
return def.Exists? def.c_str() : 0;
|
|
|
|
}
|
|
|
|
|
2015-05-17 14:21:02 +03:00
|
|
|
void cmDefinitions::Raise(const std::string& key,
|
|
|
|
StackIter begin, StackIter end)
|
|
|
|
{
|
|
|
|
cmDefinitions::GetInternal(key, begin, end, true);
|
|
|
|
}
|
|
|
|
|
2015-05-17 14:37:41 +03:00
|
|
|
bool cmDefinitions::HasKey(const std::string& key,
|
2015-05-30 18:08:34 +03:00
|
|
|
StackIter begin, StackIter end)
|
2015-05-17 14:37:41 +03:00
|
|
|
{
|
2015-05-30 18:08:34 +03:00
|
|
|
for (StackIter it = begin; it != end; ++it)
|
2015-05-17 14:37:41 +03:00
|
|
|
{
|
|
|
|
MapType::const_iterator i = it->Map.find(key);
|
|
|
|
if (i != it->Map.end())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-26 12:33:47 +03:00
|
|
|
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-05-17 17:19:55 +03:00
|
|
|
std::vector<std::string> cmDefinitions::UnusedKeys() 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)
|
|
|
|
{
|
2015-05-17 17:19:55 +03:00
|
|
|
if (!mi->second.Used)
|
2010-09-17 00:07:34 +04:00
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2015-05-30 18:08:34 +03:00
|
|
|
cmDefinitions cmDefinitions::MakeClosure(StackIter begin,
|
|
|
|
StackIter end)
|
2009-07-22 22:22:45 +04:00
|
|
|
{
|
2015-04-26 16:44:26 +03:00
|
|
|
cmDefinitions closure;
|
2015-05-16 06:33:19 +03:00
|
|
|
std::set<std::string> undefined;
|
2015-05-30 18:08:34 +03:00
|
|
|
for (StackIter it = begin; it != end; ++it)
|
2015-04-26 16:54:02 +03:00
|
|
|
{
|
2015-04-26 16:49:43 +03:00
|
|
|
// Consider local definitions.
|
2015-04-30 00:48:43 +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.
|
2015-05-16 06:33:19 +03:00
|
|
|
if(closure.Map.find(mi->first) == closure.Map.end() &&
|
2015-04-26 16:49:43 +03:00
|
|
|
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)
|
|
|
|
{
|
2015-05-16 06:33:19 +03:00
|
|
|
closure.Map.insert(*mi);
|
2015-04-26 16:49:43 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
undefined.insert(mi->first);
|
|
|
|
}
|
2009-07-22 22:22:45 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-16 06:33:19 +03:00
|
|
|
return closure;
|
2009-07-22 22:22:45 +04:00
|
|
|
}
|
|
|
|
|
2015-04-26 16:38:36 +03:00
|
|
|
std::vector<std::string>
|
2015-05-30 18:08:34 +03:00
|
|
|
cmDefinitions::ClosureKeys(StackIter begin, StackIter end)
|
2009-07-22 22:22:45 +04:00
|
|
|
{
|
2015-05-16 06:33:30 +03:00
|
|
|
std::set<std::string> bound;
|
2015-04-26 16:36:49 +03:00
|
|
|
std::vector<std::string> defined;
|
2015-05-16 06:33:30 +03:00
|
|
|
|
2015-05-30 18:08:34 +03:00
|
|
|
for (StackIter it = begin; it != end; ++it)
|
2009-07-22 22:22:45 +04:00
|
|
|
{
|
2015-05-16 06:33:30 +03:00
|
|
|
defined.reserve(defined.size() + it->Map.size());
|
|
|
|
for(MapType::const_iterator mi = it->Map.begin();
|
|
|
|
mi != it->Map.end(); ++mi)
|
2009-07-22 22:22:45 +04:00
|
|
|
{
|
2015-05-16 06:33:30 +03:00
|
|
|
// Use this key if it is not already set or unset.
|
|
|
|
if(bound.insert(mi->first).second && mi->second.Exists)
|
|
|
|
{
|
|
|
|
defined.push_back(mi->first);
|
|
|
|
}
|
2009-07-22 22:22:45 +04:00
|
|
|
}
|
|
|
|
}
|
2015-05-16 06:33:30 +03:00
|
|
|
|
2015-04-26 16:38:09 +03:00
|
|
|
return defined;
|
2009-07-22 22:22:45 +04:00
|
|
|
}
|