2016-09-27 19:01:08 +00:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2009-07-22 18:22:45 +00:00
|
|
|
#include "cmDefinitions.h"
|
|
|
|
|
2015-04-29 22:19:55 +00:00
|
|
|
#include <assert.h>
|
2016-11-05 20:40:14 +00:00
|
|
|
#include <cmConfigure.h>
|
2016-09-01 18:59:28 +00:00
|
|
|
#include <set>
|
|
|
|
#include <utility>
|
2015-04-29 22:19:55 +00:00
|
|
|
|
2009-07-22 18:22:45 +00:00
|
|
|
cmDefinitions::Def cmDefinitions::NoDef;
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
cmDefinitions::Def const& cmDefinitions::GetInternal(const std::string& key,
|
|
|
|
StackIter begin,
|
|
|
|
StackIter end, bool raise)
|
2009-07-22 18:22:45 +00:00
|
|
|
{
|
2015-05-16 03:33:25 +00:00
|
|
|
assert(begin != end);
|
2015-05-17 14:19:55 +00:00
|
|
|
MapType::iterator i = begin->Map.find(key);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (i != begin->Map.end()) {
|
2015-05-17 14:19:55 +00:00
|
|
|
i->second.Used = true;
|
2009-07-22 18:22:45 +00:00
|
|
|
return i->second;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-05-16 03:33:25 +00:00
|
|
|
StackIter it = begin;
|
|
|
|
++it;
|
2016-05-16 14:34:04 +00:00
|
|
|
if (it == end) {
|
2015-05-01 17:35:47 +00:00
|
|
|
return cmDefinitions::NoDef;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-05-17 11:21:02 +00:00
|
|
|
Def const& def = cmDefinitions::GetInternal(key, it, end, raise);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (!raise) {
|
2015-05-17 11:21:02 +00:00
|
|
|
return def;
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-05-16 03:33:25 +00:00
|
|
|
return begin->Map.insert(MapType::value_type(key, def)).first->second;
|
2009-07-22 18:22:45 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
const char* cmDefinitions::Get(const std::string& key, StackIter begin,
|
|
|
|
StackIter end)
|
2009-07-22 18:22:45 +00:00
|
|
|
{
|
2015-05-17 11:21:02 +00:00
|
|
|
Def const& def = cmDefinitions::GetInternal(key, begin, end, false);
|
2016-06-27 20:44:16 +00:00
|
|
|
return def.Exists ? def.c_str() : CM_NULLPTR;
|
2015-04-26 09:33:47 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
void cmDefinitions::Raise(const std::string& key, StackIter begin,
|
|
|
|
StackIter end)
|
2015-05-17 11:21:02 +00:00
|
|
|
{
|
|
|
|
cmDefinitions::GetInternal(key, begin, end, true);
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
bool cmDefinitions::HasKey(const std::string& key, StackIter begin,
|
|
|
|
StackIter end)
|
2015-05-17 11:37:41 +00:00
|
|
|
{
|
2016-05-16 14:34:04 +00:00
|
|
|
for (StackIter it = begin; it != end; ++it) {
|
2015-05-17 11:37:41 +00:00
|
|
|
MapType::const_iterator i = it->Map.find(key);
|
2016-05-16 14:34:04 +00:00
|
|
|
if (i != it->Map.end()) {
|
2015-05-17 11:37:41 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-05-17 11:37:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-26 09:33:47 +00:00
|
|
|
void cmDefinitions::Set(const std::string& key, const char* value)
|
|
|
|
{
|
|
|
|
Def def(value);
|
2015-04-25 14:36:48 +00:00
|
|
|
this->Map[key] = def;
|
2009-07-22 18:22:45 +00:00
|
|
|
}
|
|
|
|
|
2015-05-17 14:19:55 +00:00
|
|
|
std::vector<std::string> cmDefinitions::UnusedKeys() const
|
2010-08-24 18:40:51 +00:00
|
|
|
{
|
2015-04-26 14:34:13 +00:00
|
|
|
std::vector<std::string> keys;
|
|
|
|
keys.reserve(this->Map.size());
|
2010-08-24 18:40:51 +00:00
|
|
|
// Consider local definitions.
|
2016-05-16 14:34:04 +00:00
|
|
|
for (MapType::const_iterator mi = this->Map.begin(); mi != this->Map.end();
|
|
|
|
++mi) {
|
|
|
|
if (!mi->second.Used) {
|
2015-04-26 14:34:13 +00:00
|
|
|
keys.push_back(mi->first);
|
2010-08-24 18:40:51 +00:00
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2010-08-24 18:40:51 +00:00
|
|
|
return keys;
|
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
cmDefinitions cmDefinitions::MakeClosure(StackIter begin, StackIter end)
|
2009-07-22 18:22:45 +00:00
|
|
|
{
|
2015-04-26 13:44:26 +00:00
|
|
|
cmDefinitions closure;
|
2015-05-16 03:33:19 +00:00
|
|
|
std::set<std::string> undefined;
|
2016-05-16 14:34:04 +00:00
|
|
|
for (StackIter it = begin; it != end; ++it) {
|
2015-04-26 13:49:43 +00:00
|
|
|
// Consider local definitions.
|
2016-05-16 14:34:04 +00:00
|
|
|
for (MapType::const_iterator mi = it->Map.begin(); mi != it->Map.end();
|
|
|
|
++mi) {
|
2015-04-26 13:49:43 +00:00
|
|
|
// Use this key if it is not already set or unset.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (closure.Map.find(mi->first) == closure.Map.end() &&
|
|
|
|
undefined.find(mi->first) == undefined.end()) {
|
|
|
|
if (mi->second.Exists) {
|
2015-05-16 03:33:19 +00:00
|
|
|
closure.Map.insert(*mi);
|
2016-05-16 14:34:04 +00:00
|
|
|
} else {
|
2015-04-26 13:49:43 +00:00
|
|
|
undefined.insert(mi->first);
|
2009-07-22 18:22:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-05-16 03:33:19 +00:00
|
|
|
return closure;
|
2009-07-22 18:22:45 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
std::vector<std::string> cmDefinitions::ClosureKeys(StackIter begin,
|
|
|
|
StackIter end)
|
2009-07-22 18:22:45 +00:00
|
|
|
{
|
2015-05-16 03:33:30 +00:00
|
|
|
std::set<std::string> bound;
|
2015-04-26 13:36:49 +00:00
|
|
|
std::vector<std::string> defined;
|
2015-05-16 03:33:30 +00:00
|
|
|
|
2016-05-16 14:34:04 +00:00
|
|
|
for (StackIter it = begin; it != end; ++it) {
|
2015-05-16 03:33:30 +00:00
|
|
|
defined.reserve(defined.size() + it->Map.size());
|
2016-05-16 14:34:04 +00:00
|
|
|
for (MapType::const_iterator mi = it->Map.begin(); mi != it->Map.end();
|
|
|
|
++mi) {
|
2015-05-16 03:33:30 +00:00
|
|
|
// Use this key if it is not already set or unset.
|
2016-05-16 14:34:04 +00:00
|
|
|
if (bound.insert(mi->first).second && mi->second.Exists) {
|
2015-05-16 03:33:30 +00:00
|
|
|
defined.push_back(mi->first);
|
2009-07-22 18:22:45 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-16 14:34:04 +00:00
|
|
|
}
|
2015-05-16 03:33:30 +00:00
|
|
|
|
2015-04-26 13:38:09 +00:00
|
|
|
return defined;
|
2009-07-22 18:22:45 +00:00
|
|
|
}
|