mirror of
https://github.com/Kitware/CMake.git
synced 2025-06-19 19:36:41 +08:00

This reverts commit 5abfde6cb8a1ae0b2825797eab6c2e9842eb7c49. The behaviors associated with implicit pulldown on variable lookup seriously conflict with the optimizations made in these commits. Basically, since values were copied upon variable lookup, not just on PARENT_SCOPE, coupled with PARENT_SCOPE's behavior based on whether the variable is in the current scope or not causes serious problems with not storing a value for every variable at every scope. The commit changed behavior of the following example, among other cases: function(test_set) set(blah "value2") message("before PARENT_SCOPE blah=${blah}") set(blah ${blah} PARENT_SCOPE) message("after PARENT_SCOPE blah=${blah}") endfunction() set(blah value1) test_set() message("in parent scope, blah=${blah}") Reported-by: Alex Merry <alex.merry@kde.org> Reported-by: Ben Cooksley <bcooksley@kde.org>
91 lines
2.9 KiB
C++
91 lines
2.9 KiB
C++
/*============================================================================
|
|
CMake - Cross Platform Makefile Generator
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
see accompanying file Copyright.txt for details.
|
|
|
|
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.
|
|
============================================================================*/
|
|
#ifndef cmDefinitions_h
|
|
#define cmDefinitions_h
|
|
|
|
#include "cmStandardIncludes.h"
|
|
|
|
/** \class cmDefinitions
|
|
* \brief Store a scope of variable definitions for CMake language.
|
|
*
|
|
* This stores the state of variable definitions (set or unset) for
|
|
* one scope. Sets are always local. Gets search parent scopes
|
|
* transitively and save results locally.
|
|
*/
|
|
class cmDefinitions
|
|
{
|
|
public:
|
|
/** Construct with the given parent scope. */
|
|
cmDefinitions(cmDefinitions* parent = 0);
|
|
|
|
/** Reset object as if newly constructed. */
|
|
void Reset(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);
|
|
|
|
/** Set (or unset if null) a value associated with a key. */
|
|
const char* Set(const std::string& key, const char* value);
|
|
|
|
/** Get the set of all local keys. */
|
|
std::set<std::string> LocalKeys() const;
|
|
|
|
/** Compute the closure of all defined keys with values.
|
|
This flattens the scope. The result has no parent. */
|
|
cmDefinitions Closure() const;
|
|
|
|
/** Compute the set of all defined keys. */
|
|
std::set<std::string> ClosureKeys() const;
|
|
|
|
private:
|
|
// String with existence boolean.
|
|
struct Def: public std::string
|
|
{
|
|
private:
|
|
typedef std::string std_string;
|
|
public:
|
|
Def(): std_string(), Exists(false) {}
|
|
Def(const char* v): std_string(v?v:""), Exists(v?true:false) {}
|
|
Def(const std_string& v): std_string(v), Exists(true) {}
|
|
Def(Def const& d): std_string(d), Exists(d.Exists) {}
|
|
bool Exists;
|
|
};
|
|
static Def NoDef;
|
|
|
|
// Parent scope, if any.
|
|
cmDefinitions* Up;
|
|
|
|
// Local definitions, set or unset.
|
|
typedef std::map<std::string, Def> MapType;
|
|
MapType Map;
|
|
|
|
// Internal query and update methods.
|
|
Def const& GetInternal(const std::string& key);
|
|
Def const& SetInternal(const std::string& key, Def const& def);
|
|
|
|
// Implementation of Closure() method.
|
|
struct ClosureTag {};
|
|
cmDefinitions(ClosureTag const&, cmDefinitions const* root);
|
|
void ClosureImpl(std::set<std::string>& undefined,
|
|
cmDefinitions const* defs);
|
|
|
|
// Implementation of ClosureKeys() method.
|
|
void ClosureKeys(std::set<std::string>& defined,
|
|
std::set<std::string>& undefined) const;
|
|
};
|
|
|
|
#endif
|