[Cmake-commits] CMake branch, next, updated. v3.2.2-2381-g74b8c6e

Stephen Kelly steveire at gmail.com
Thu Apr 30 19:19:44 EDT 2015


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "CMake".

The branch, next has been updated
       via  74b8c6e3c9c62d9df550fb20ef33ae3251f351cd (commit)
       via  3da9cbd79be9978e7e3f27b438abf747ac3f24d2 (commit)
      from  a15f5f34b55c1d22fe1104f2d76730db8b9d15f3 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=74b8c6e3c9c62d9df550fb20ef33ae3251f351cd
commit 74b8c6e3c9c62d9df550fb20ef33ae3251f351cd
Merge: a15f5f3 3da9cbd
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Thu Apr 30 19:19:41 2015 -0400
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Thu Apr 30 19:19:41 2015 -0400

    Merge topic 'refactor-cmDefinitions' into next
    
    3da9cbd7 Revert topic.


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3da9cbd79be9978e7e3f27b438abf747ac3f24d2
commit 3da9cbd79be9978e7e3f27b438abf747ac3f24d2
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Fri May 1 01:18:30 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Fri May 1 01:18:45 2015 +0200

    Revert topic.

diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index 13ebf7b..61328be 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -12,15 +12,38 @@
 #include "cmDefinitions.h"
 
 //----------------------------------------------------------------------------
-std::pair<const char*, bool> cmDefinitions::Get(const std::string& key)
+cmDefinitions::Def cmDefinitions::NoDef;
+
+//----------------------------------------------------------------------------
+cmDefinitions::cmDefinitions(cmDefinitions* parent)
+  : Up(parent)
+{
+}
+
+//----------------------------------------------------------------------------
+cmDefinitions::Def const&
+cmDefinitions::GetInternal(const std::string& key)
 {
   MapType::const_iterator i = this->Map.find(key);
-  std::pair<const char*, bool> result((const char*)0, false);
   if(i != this->Map.end())
     {
-    result = std::make_pair(i->second.Exists ? i->second.c_str() : 0, true);
+    return i->second;
     }
-  return result;
+  cmDefinitions* up = this->Up;
+  if(!up)
+    {
+    return this->NoDef;
+    }
+  // 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;
+}
+
+//----------------------------------------------------------------------------
+const char* cmDefinitions::Get(const std::string& key)
+{
+  Def const& def = this->GetInternal(key);
+  return def.Exists? def.c_str() : 0;
 }
 
 //----------------------------------------------------------------------------
diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h
index a698090..4c7f11f 100644
--- a/Source/cmDefinitions.h
+++ b/Source/cmDefinitions.h
@@ -23,12 +23,21 @@
  * \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.
+ * one scope.  Sets are always local.  Gets search parent scopes
+ * transitively and save results locally.
  */
 class cmDefinitions
 {
 public:
-  std::pair<const char*, bool> Get(const std::string& key);
+  /** Construct with the given parent scope.  */
+  cmDefinitions(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.  */
   void Set(const std::string& key, const char* value);
@@ -58,6 +67,10 @@ private:
     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.
 #if defined(CMAKE_BUILD_WITH_CMAKE)
@@ -67,6 +80,9 @@ private:
 #endif
   MapType Map;
 
+  // Internal query and update methods.
+  Def const& GetInternal(const std::string& key);
+
   void MakeClosure(std::set<std::string>& undefined,
                    std::list<cmDefinitions>::const_reverse_iterator rbegin,
                    std::list<cmDefinitions>::const_reverse_iterator rend);
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 445d774..5686b1b 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -53,7 +53,12 @@ public:
 
   void PushDefinitions()
   {
-    this->VarStack.push_back(cmDefinitions());
+    cmDefinitions* parent = 0;
+    if (!this->VarStack.empty())
+      {
+      parent = &this->VarStack.back();
+      }
+    this->VarStack.push_back(cmDefinitions(parent));
   }
 
   void InitializeDefinitions(cmMakefile* parent)
@@ -65,23 +70,7 @@ public:
 
   const char* GetDefinition(std::string const& name)
   {
-    std::pair<const char*, bool> result((const char*)0, false);
-    std::list<cmDefinitions>::reverse_iterator it = VarStack.rbegin();
-    for ( ; it != this->VarStack.rend(); ++it)
-      {
-      result = it->Get(name);
-      if(result.second)
-        {
-        break;
-        }
-      }
-    std::list<cmDefinitions>::reverse_iterator last = it;
-    // Store the result in intermediate scopes.
-    for (it = this->VarStack.rbegin(); it != last; ++it)
-      {
-      it->Set(name, result.first);
-      }
-    return result.first;
+    return this->VarStack.back().Get(name);
   }
 
   void SetDefinition(std::string const& name, std::string const& value)

-----------------------------------------------------------------------

Summary of changes:
 Source/cmDefinitions.cxx |   31 +++++++++++++++++++++++++++----
 Source/cmDefinitions.h   |   20 ++++++++++++++++++--
 Source/cmMakefile.cxx    |   25 +++++++------------------
 3 files changed, 52 insertions(+), 24 deletions(-)


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list