[Cmake-commits] CMake branch, next, updated. v3.3.1-2335-g27ebbf3

Stephen Kelly steveire at gmail.com
Sun Aug 23 11:09:22 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  27ebbf3f4ed8b79fbe7c2c01c5faf43a242a52a1 (commit)
       via  505e1bd266469a4ed2452a333f1e40b9a4ab69d1 (commit)
       via  3dd1d3512061c46b8b5a5a66353bc0e8782cc5fb (commit)
       via  31dcb50a5166c60c65fad2bfc8a757d5c2a4aac9 (commit)
       via  6954c8936f52dcf7710e4b72b2e090b79bf38d1c (commit)
       via  1fc645bd9cffb3170743de5c983f2407eeaaa086 (commit)
       via  0f070dd3e12408e0e33945c3c8f585268c4b0db9 (commit)
       via  25e04ddffeba6d4b1c9deab1ea42038c322cec83 (commit)
       via  4bbe261cd34818379d06b68d2e153a98cfccfcf5 (commit)
       via  29c1385675df37146465e820d303de3cdd703e8c (commit)
      from  c12be0dce8d045b3759296f5ce0607e80820f27d (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=27ebbf3f4ed8b79fbe7c2c01c5faf43a242a52a1
commit 27ebbf3f4ed8b79fbe7c2c01c5faf43a242a52a1
Merge: c12be0d 505e1bd
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Aug 23 11:09:20 2015 -0400
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Sun Aug 23 11:09:20 2015 -0400

    Merge topic 'cmState-definitions' into next
    
    505e1bd2 cmState: Reserve the number of cmLinkedTree nodes if known.
    3dd1d351 cmLinkedTree: Add API for size query and reserve.
    31dcb50a cmState: Host variable definitions.
    6954c893 cmState: Add a VariableScope snapshot type.
    1fc645bd cmState: Add a Base snapshot type.
    0f070dd3 cmMakefile: Decouple the container of cmDefinitions from scoping logic.
    25e04ddf cmDefinitions: Implement in terms of cmLinkedTree.
    4bbe261c cmMakefile: Extract InitializeVarScope method.
    29c13856 CMake Nightly Date Stamp


http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=505e1bd266469a4ed2452a333f1e40b9a4ab69d1
commit 505e1bd266469a4ed2452a333f1e40b9a4ab69d1
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Jun 21 13:05:15 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Aug 23 17:08:54 2015 +0200

    cmState: Reserve the number of cmLinkedTree nodes if known.

diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index cda26cd..a19a074 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -1141,6 +1141,42 @@ void cmGlobalGenerator::Configure()
   this->BinaryDirectories.insert(
       this->CMakeInstance->GetHomeOutputDirectory());
 
+  if (const char *numStr =
+      this->GetCMakeInstance()->GetState()
+          ->GetInitializedCacheValue("CMAKE_NUMBER_OF_DEFINITION_STATES"))
+    {
+    int num = atoi(numStr);
+    this->GetCMakeInstance()->GetState()->ReserveDefinitions(num);
+    }
+  if (const char *numStr =
+      this->GetCMakeInstance()->GetState()
+          ->GetInitializedCacheValue("CMAKE_NUMBER_OF_SNAPSHOT_STATES"))
+    {
+    int num = atoi(numStr);
+    this->GetCMakeInstance()->GetState()->ReserveSnapshots(num);
+    }
+  if (const char *numStr =
+      this->GetCMakeInstance()->GetState()
+          ->GetInitializedCacheValue("CMAKE_NUMBER_OF_LISTFILE_STATES"))
+    {
+    int num = atoi(numStr);
+    this->GetCMakeInstance()->GetState()->ReserveListFiles(num);
+    }
+  if (const char *numStr =
+      this->GetCMakeInstance()->GetState()
+          ->GetInitializedCacheValue("CMAKE_NUMBER_OF_LOCAL_GENERATORS"))
+    {
+    int num = atoi(numStr);
+    this->GetCMakeInstance()->GetState()->ReserveDirectories(num);
+    }
+  if (const char *numStr =
+      this->GetCMakeInstance()->GetState()
+          ->GetInitializedCacheValue("CMAKE_NUMBER_OF_POLICY_STATES"))
+    {
+    int num = atoi(numStr);
+    this->GetCMakeInstance()->GetState()->ReservePolicies(num);
+    }
+
   // now do it
   lg->GetMakefile()->Configure();
   lg->GetMakefile()->EnforceDirectoryLevelRules();
@@ -1153,6 +1189,35 @@ void cmGlobalGenerator::Configure()
     ("CMAKE_NUMBER_OF_MAKEFILES", num,
      "number of local generators", cmState::INTERNAL);
 
+  {
+  std::ostringstream str;
+  str << this->GetCMakeInstance()->GetState()->DefinitionsSize();
+  this->GetCMakeInstance()->AddCacheEntry
+    ("CMAKE_NUMBER_OF_DEFINITION_STATES", str.str().c_str(),
+     "number of definition states", cmState::INTERNAL);
+  }
+  {
+  std::ostringstream str;
+  str << this->GetCMakeInstance()->GetState()->SnapshotsSize();
+  this->GetCMakeInstance()->AddCacheEntry
+    ("CMAKE_NUMBER_OF_SNAPSHOT_STATES", str.str().c_str(),
+     "number of snapshot states", cmState::INTERNAL);
+  }
+  {
+  std::ostringstream str;
+  str << this->GetCMakeInstance()->GetState()->ListFilesSize();
+  this->GetCMakeInstance()->AddCacheEntry
+    ("CMAKE_NUMBER_OF_LISTFILE_STATES", str.str().c_str(),
+     "number of listfile states", cmState::INTERNAL);
+  }
+  {
+  std::ostringstream str;
+  str << this->GetCMakeInstance()->GetState()->PoliciesSize();
+  this->GetCMakeInstance()->AddCacheEntry
+    ("CMAKE_NUMBER_OF_POLICY_STATES", str.str().c_str(),
+     "number of policy states", cmState::INTERNAL);
+  }
+
   // check for link libraries and include directories containing "NOTFOUND"
   // and for infinite loops
   this->CheckLocalGenerators();
diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index ab309ad..99a7537 100644
--- a/Source/cmState.cxx
+++ b/Source/cmState.cxx
@@ -651,6 +651,56 @@ bool cmState::UseMSYSShell() const
   return this->MSYSShell;
 }
 
+size_t cmState::DefinitionsSize() const
+{
+  return this->VarTree.Size();
+}
+
+void cmState::ReserveDefinitions(size_t amount)
+{
+  this->VarTree.Reserve(amount);
+}
+
+size_t cmState::SnapshotsSize() const
+{
+  return this->SnapshotData.Size();
+}
+
+void cmState::ReserveSnapshots(size_t amount)
+{
+  this->SnapshotData.Reserve(amount);
+}
+
+size_t cmState::ListFilesSize() const
+{
+  return this->ExecutionListFiles.Size();
+}
+
+void cmState::ReserveListFiles(size_t amount)
+{
+  this->ExecutionListFiles.Reserve(amount);
+}
+
+size_t cmState::DirectoriesSize() const
+{
+  return this->BuildsystemDirectory.Size();
+}
+
+void cmState::ReserveDirectories(size_t amount)
+{
+  this->BuildsystemDirectory.Reserve(amount);
+}
+
+size_t cmState::PoliciesSize() const
+{
+  return this->PolicyStack.Size();
+}
+
+void cmState::ReservePolicies(size_t amount)
+{
+  this->PolicyStack.Reserve(amount);
+}
+
 const char* cmState::GetBinaryDirectory() const
 {
   return this->BinaryDirectory.c_str();
diff --git a/Source/cmState.h b/Source/cmState.h
index 5499665..8380587 100644
--- a/Source/cmState.h
+++ b/Source/cmState.h
@@ -270,6 +270,21 @@ public:
   void SetMSYSShell(bool mSYSShell);
   bool UseMSYSShell() const;
 
+  size_t DefinitionsSize() const;
+  void ReserveDefinitions(size_t amount);
+
+  size_t SnapshotsSize() const;
+  void ReserveSnapshots(size_t amount);
+
+  size_t ListFilesSize() const;
+  void ReserveListFiles(size_t amount);
+
+  size_t DirectoriesSize() const;
+  void ReserveDirectories(size_t amount);
+
+  size_t PoliciesSize() const;
+  void ReservePolicies(size_t amount);
+
 private:
   std::map<cmProperty::ScopeType, cmPropertyDefinitionMap> PropertyDefinitions;
   std::vector<std::string> EnabledLanguages;

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=3dd1d3512061c46b8b5a5a66353bc0e8782cc5fb
commit 3dd1d3512061c46b8b5a5a66353bc0e8782cc5fb
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Jun 21 13:04:43 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Aug 23 17:08:54 2015 +0200

    cmLinkedTree: Add API for size query and reserve.

diff --git a/Source/cmLinkedTree.h b/Source/cmLinkedTree.h
index 3bcb940..385dff2 100644
--- a/Source/cmLinkedTree.h
+++ b/Source/cmLinkedTree.h
@@ -161,6 +161,17 @@ public:
     this->Data.clear();
   }
 
+  size_t Size() const
+  {
+    return this->UpPositions.size();
+  }
+
+  void Reserve(size_t amount)
+  {
+    this->UpPositions.reserve(amount);
+    this->Data.reserve(amount);
+  }
+
 private:
   T& GetReference(PositionType pos)
   {

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=31dcb50a5166c60c65fad2bfc8a757d5c2a4aac9
commit 31dcb50a5166c60c65fad2bfc8a757d5c2a4aac9
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Jun 21 21:26:43 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Aug 23 17:08:54 2015 +0200

    cmState: Host variable definitions.
    
    Version them through the snapshot system.

diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 1d02cfa..513a643 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -31,7 +31,6 @@
 #endif
 #include "cmInstallGenerator.h"
 #include "cmTestGenerator.h"
-#include "cmDefinitions.h"
 #include "cmAlgorithms.h"
 #include "cmake.h"
 #include <stdlib.h> // required for atoi
@@ -47,132 +46,7 @@
 class cmMakefile::Internals
 {
 public:
-
-  enum ScopeType
-  {
-    BaseScope,
-    MacroScope,
-    FunctionScope,
-    VariableScope
-  };
-
-  struct VarScope
-  {
-    ScopeType Type;
-    cmLinkedTree<cmDefinitions>::iterator Vars;
-    cmLinkedTree<cmDefinitions>::iterator ParentScope;
-  };
-
-  cmLinkedTree<cmDefinitions> VarTree;
-  cmLinkedTree<VarScope> VarScopes;
-  cmLinkedTree<VarScope>::iterator VarScopeIter;
   bool IsSourceFileTryCompile;
-
-  void PushDefinitions(ScopeType scope)
-  {
-    assert(this->VarScopeIter.IsValid());
-    assert(this->VarScopeIter->Vars.IsValid());
-    cmLinkedTree<cmDefinitions>::iterator origin =
-        this->VarScopeIter->Vars;
-    cmLinkedTree<cmDefinitions>::iterator parentScope =
-//         this->VarTree.Extend(origin);
-        origin;
-    this->VarScopeIter->Vars = parentScope;
-    this->VarScopeIter = this->VarScopes.Extend(this->VarScopeIter);
-    this->VarScopeIter->ParentScope = parentScope;
-    this->VarScopeIter->Vars = this->VarTree.Extend(origin);
-    this->VarScopeIter->Type = scope;
-  }
-
-  void InitializeVarScope()
-  {
-    assert(!this->VarScopeIter.IsValid());
-    this->VarScopeIter = this->VarScopes.Extend(this->VarScopes.Root());
-    this->VarScopeIter->Vars = this->VarTree.Extend(this->VarTree.Root());
-    this->VarScopeIter->ParentScope = this->VarTree.Root();
-    this->VarScopeIter->Type = BaseScope;
-  }
-
-  void InitializeDefinitions(cmMakefile* parent)
-  {
-    assert(this->VarScopeIter.IsValid());
-    assert(this->VarScopeIter->Vars.IsValid());
-    *this->VarScopeIter->Vars =
-        cmDefinitions::MakeClosure(parent->Internal->VarScopeIter->Vars,
-                                   parent->Internal->VarTree.Root());
-  }
-
-  const char* GetDefinition(std::string const& name)
-  {
-    assert(this->VarScopeIter.IsValid());
-    assert(this->VarScopeIter->Vars.IsValid());
-    return cmDefinitions::Get(name,
-                              this->VarScopeIter->Vars, this->VarTree.Root());
-  }
-
-  bool IsInitialized(std::string const& name)
-  {
-    return cmDefinitions::HasKey(name,
-                              this->VarScopeIter->Vars, this->VarTree.Root());
-  }
-
-  void SetDefinition(std::string const& name, std::string const& value)
-  {
-    this->VarScopeIter->Vars->Set(name, value.c_str());
-  }
-
-  void RemoveDefinition(std::string const& name)
-  {
-    this->VarScopeIter->Vars->Set(name, 0);
-  }
-
-  std::vector<std::string> UnusedKeys() const
-  {
-    return this->VarScopeIter->Vars->UnusedKeys();
-  }
-
-  std::vector<std::string> ClosureKeys() const
-  {
-    return cmDefinitions::ClosureKeys(this->VarScopeIter->Vars,
-                                      this->VarTree.Root());
-  }
-
-  void PopDefinitions()
-  {
-    ++this->VarScopeIter;
-  }
-
-  bool RaiseScope(std::string const& var, const char* varDef, cmMakefile* mf)
-  {
-    assert(this->VarScopeIter->Vars != this->VarTree.Root());
-    if(this->VarScopeIter->ParentScope == this->VarTree.Root())
-      {
-      cmLocalGenerator* plg = mf->LocalGenerator->GetParent();
-      if(!plg)
-        {
-        return false;
-        }
-      // Update the definition in the parent directory top scope.  This
-      // directory's scope was initialized by the closure of the parent
-      // scope, so we do not need to localize the definition first.
-      cmMakefile* parent = plg->GetMakefile();
-      if (varDef)
-        {
-        parent->AddDefinition(var, varDef);
-        }
-      else
-        {
-        parent->RemoveDefinition(var);
-        }
-      return true;
-      }
-    // First localize the definition in the current scope.
-    cmDefinitions::Raise(var, this->VarScopeIter->Vars, this->VarTree.Root());
-
-    // Now update the definition in the parent scope.
-    this->VarScopeIter->ParentScope->Set(var, varDef);
-    return true;
-  }
 };
 
 // default is not to be building executables
@@ -181,7 +55,6 @@ cmMakefile::cmMakefile(cmLocalGenerator* localGenerator)
     LocalGenerator(localGenerator),
     StateSnapshot(localGenerator->GetStateSnapshot())
 {
-  this->Internal->InitializeVarScope();
   this->Internal->IsSourceFileTryCompile = false;
 
   // Initialize these first since AddDefaultDefinitions calls AddDefinition
@@ -1607,9 +1480,6 @@ void cmMakefile::AddLinkLibrary(const std::string& lib)
 
 void cmMakefile::InitializeFromParent(cmMakefile* parent)
 {
-  // Initialize definitions with the closure of the parent scope.
-  this->Internal->InitializeDefinitions(parent);
-
   this->StateSnapshot.InitializeFromParent();
 
   this->AddDefinition("CMAKE_CURRENT_SOURCE_DIR",
@@ -1674,8 +1544,6 @@ void cmMakefile::PushFunctionScope(std::string const& fileName,
         fileName);
   assert(this->StateSnapshot.IsValid());
 
-  this->Internal->PushDefinitions(Internals::FunctionScope);
-
   this->PushLoopBlockBarrier();
 
 #if defined(CMAKE_BUILD_WITH_CMAKE)
@@ -1702,8 +1570,6 @@ void cmMakefile::PopFunctionScope(bool reportError)
   this->PopLoopBlockBarrier();
 
   this->CheckForUnusedVariables();
-
-  this->Internal->PopDefinitions();
 }
 
 void cmMakefile::PushMacroScope(std::string const& fileName,
@@ -2007,7 +1873,7 @@ void cmMakefile::AddDefinition(const std::string& name, const char* value)
     {
     this->LogUnused("changing definition", name);
     }
-  this->Internal->SetDefinition(name, value);
+  this->StateSnapshot.SetDefinition(name, value);
 
 #ifdef CMAKE_BUILD_WITH_CMAKE
   cmVariableWatch* vv = this->GetVariableWatch();
@@ -2070,7 +1936,7 @@ void cmMakefile::AddCacheDefinition(const std::string& name, const char* value,
   this->GetState()->AddCacheEntry(name, haveVal ? val.c_str() : 0,
                                           doc, type);
   // if there was a definition then remove it
-  this->Internal->RemoveDefinition(name);
+  this->StateSnapshot.RemoveDefinition(name);
 }
 
 
@@ -2080,7 +1946,9 @@ void cmMakefile::AddDefinition(const std::string& name, bool value)
     {
     this->LogUnused("changing definition", name);
     }
-  this->Internal->SetDefinition(name, value ? "ON" : "OFF");
+
+  this->StateSnapshot.SetDefinition(name, value ? "ON" : "OFF");
+
 #ifdef CMAKE_BUILD_WITH_CMAKE
   cmVariableWatch* vv = this->GetVariableWatch();
   if ( vv )
@@ -2097,7 +1965,7 @@ void cmMakefile::CheckForUnusedVariables() const
     {
     return;
     }
-  const std::vector<std::string>& unused = this->Internal->UnusedKeys();
+  const std::vector<std::string>& unused = this->StateSnapshot.UnusedKeys();
   std::vector<std::string>::const_iterator it = unused.begin();
   for (; it != unused.end(); ++it)
     {
@@ -2107,12 +1975,12 @@ void cmMakefile::CheckForUnusedVariables() const
 
 void cmMakefile::MarkVariableAsUsed(const std::string& var)
 {
-  this->Internal->GetDefinition(var);
+  this->StateSnapshot.GetDefinition(var);
 }
 
 bool cmMakefile::VariableInitialized(const std::string& var) const
 {
-  return this->Internal->IsInitialized(var);
+  return this->StateSnapshot.IsInitialized(var);
 }
 
 void cmMakefile::LogUnused(const char* reason,
@@ -2160,7 +2028,7 @@ void cmMakefile::RemoveDefinition(const std::string& name)
     {
     this->LogUnused("unsetting", name);
     }
-  this->Internal->RemoveDefinition(name);
+  this->StateSnapshot.RemoveDefinition(name);
 #ifdef CMAKE_BUILD_WITH_CMAKE
   cmVariableWatch* vv = this->GetVariableWatch();
   if ( vv )
@@ -2626,7 +2494,7 @@ const char* cmMakefile::GetRequiredDefinition(const std::string& name) const
 
 bool cmMakefile::IsDefinitionSet(const std::string& name) const
 {
-  const char* def = this->Internal->GetDefinition(name);
+  const char* def = this->StateSnapshot.GetDefinition(name);
   if(!def)
     {
     def = this->GetState()->GetInitializedCacheValue(name);
@@ -2647,7 +2515,7 @@ bool cmMakefile::IsDefinitionSet(const std::string& name) const
 
 const char* cmMakefile::GetDefinition(const std::string& name) const
 {
-  const char* def = this->Internal->GetDefinition(name);
+  const char* def = this->StateSnapshot.GetDefinition(name);
   if(!def)
     {
     def = this->GetState()->GetInitializedCacheValue(name);
@@ -2683,7 +2551,7 @@ const char* cmMakefile::GetSafeDefinition(const std::string& def) const
 
 std::vector<std::string> cmMakefile::GetDefinitions() const
 {
-  std::vector<std::string> res = this->Internal->ClosureKeys();
+  std::vector<std::string> res = this->StateSnapshot.ClosureKeys();
   std::vector<std::string> cacheKeys = this->GetState()->GetCacheEntryKeys();
   res.insert(res.end(), cacheKeys.begin(), cacheKeys.end());
   std::sort(res.begin(), res.end());
@@ -4462,8 +4330,6 @@ std::string cmMakefile::FormatListFileStack() const
 
 void cmMakefile::PushScope()
 {
-  this->Internal->PushDefinitions(Internals::VariableScope);
-
   std::string commandName;
   long line = 0;
   if (!this->ContextStack.empty())
@@ -4492,7 +4358,6 @@ void cmMakefile::PopScope()
 
   this->CheckForUnusedVariables();
 
-  this->Internal->PopDefinitions();
   this->StateSnapshot =
       this->GetState()->Pop(this->StateSnapshot);
   assert(this->StateSnapshot.IsValid());
@@ -4505,7 +4370,7 @@ void cmMakefile::RaiseScope(const std::string& var, const char *varDef)
     return;
     }
 
-  if (!this->Internal->RaiseScope(var, varDef, this))
+  if (!this->StateSnapshot.RaiseScope(var, varDef))
     {
     std::ostringstream m;
     m << "Cannot set \"" << var << "\": current scope has no parent.";
diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index 9e09353..ab309ad 100644
--- a/Source/cmState.cxx
+++ b/Source/cmState.cxx
@@ -15,6 +15,7 @@
 #include "cmCacheManager.h"
 #include "cmCommand.h"
 #include "cmAlgorithms.h"
+#include "cmDefinitions.h"
 
 #include <assert.h>
 
@@ -29,6 +30,9 @@ struct cmState::SnapshotDataType
   cmLinkedTree<std::string>::iterator ExecutionListFile;
   cmLinkedTree<cmState::BuildsystemDirectoryStateType>::iterator
                                                           BuildSystemDirectory;
+  cmLinkedTree<cmDefinitions>::iterator Vars;
+  cmLinkedTree<cmDefinitions>::iterator Root;
+  cmLinkedTree<cmDefinitions>::iterator Parent;
   std::string EntryPointCommand;
   long EntryPointLine;
   std::vector<std::string>::size_type IncludeDirectoryPosition;
@@ -275,6 +279,10 @@ cmState::Snapshot cmState::Reset()
   pos->PolicyScope = this->PolicyStack.Root();
   assert(pos->Policies.IsValid());
   assert(pos->PolicyRoot.IsValid());
+  this->VarTree.Clear();
+  pos->Vars = this->VarTree.Extend(this->VarTree.Root());
+  pos->Parent = this->VarTree.Root();
+  pos->Root = this->VarTree.Root();
 
   this->DefineProperty
     ("RULE_LAUNCH_COMPILE", cmProperty::DIRECTORY,
@@ -752,6 +760,10 @@ cmState::Snapshot cmState::CreateBaseSnapshot()
   pos->PolicyScope = this->PolicyStack.Root();
   assert(pos->Policies.IsValid());
   assert(pos->PolicyRoot.IsValid());
+  pos->Vars = this->VarTree.Extend(this->VarTree.Root());
+  assert(pos->Vars.IsValid());
+  pos->Parent = this->VarTree.Root();
+  pos->Root = this->VarTree.Root();
   return cmState::Snapshot(this, pos);
 }
 
@@ -779,6 +791,12 @@ cmState::CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot,
   pos->PolicyScope = originSnapshot.Position->Policies;
   assert(pos->Policies.IsValid());
   assert(pos->PolicyRoot.IsValid());
+
+  cmLinkedTree<cmDefinitions>::iterator origin =
+      originSnapshot.Position->Vars;
+  pos->Parent = origin;
+  pos->Root = origin;
+  pos->Vars = this->VarTree.Extend(origin);
   return cmState::Snapshot(this, pos);
 }
 
@@ -798,6 +816,11 @@ cmState::CreateFunctionCallSnapshot(cmState::Snapshot originSnapshot,
         originSnapshot.Position->ExecutionListFile, fileName);
   pos->BuildSystemDirectory->DirectoryEnd = pos;
   pos->PolicyScope = originSnapshot.Position->Policies;
+  assert(originSnapshot.Position->Vars.IsValid());
+  cmLinkedTree<cmDefinitions>::iterator origin =
+      originSnapshot.Position->Vars;
+  pos->Parent = origin;
+  pos->Vars = this->VarTree.Extend(origin);
   return cmState::Snapshot(this, pos);
 }
 
@@ -815,6 +838,7 @@ cmState::CreateMacroCallSnapshot(cmState::Snapshot originSnapshot,
   pos->SnapshotType = MacroCallType;
   pos->ExecutionListFile = this->ExecutionListFiles.Extend(
         originSnapshot.Position->ExecutionListFile, fileName);
+  assert(originSnapshot.Position->Vars.IsValid());
   pos->BuildSystemDirectory->DirectoryEnd = pos;
   pos->PolicyScope = originSnapshot.Position->Policies;
   return cmState::Snapshot(this, pos);
@@ -833,6 +857,7 @@ cmState::CreateCallStackSnapshot(cmState::Snapshot originSnapshot,
   pos->SnapshotType = CallStackType;
   pos->ExecutionListFile = this->ExecutionListFiles.Extend(
         originSnapshot.Position->ExecutionListFile, fileName);
+  assert(originSnapshot.Position->Vars.IsValid());
   pos->BuildSystemDirectory->DirectoryEnd = pos;
   pos->PolicyScope = originSnapshot.Position->Policies;
   return cmState::Snapshot(this, pos);
@@ -849,7 +874,13 @@ cmState::CreateVariableScopeSnapshot(cmState::Snapshot originSnapshot,
   pos->EntryPointLine = entryPointLine;
   pos->EntryPointCommand = entryPointCommand;
   pos->SnapshotType = VariableScopeType;
+  assert(originSnapshot.Position->Vars.IsValid());
 
+  cmLinkedTree<cmDefinitions>::iterator origin =
+      originSnapshot.Position->Vars;
+  pos->Parent = origin;
+  pos->Vars = this->VarTree.Extend(origin);
+  assert(pos->Vars.IsValid());
   return cmState::Snapshot(this, pos);
 }
 
@@ -1141,6 +1172,72 @@ bool cmState::Snapshot::HasDefinedPolicyCMP0011()
   return !this->Position->Policies->IsEmpty();
 }
 
+const char* cmState::Snapshot::GetDefinition(std::string const& name) const
+{
+  assert(this->Position->Vars.IsValid());
+  return cmDefinitions::Get(name, this->Position->Vars,
+                    this->Position->Root);
+}
+
+bool cmState::Snapshot::IsInitialized(std::string const& name) const
+{
+  return cmDefinitions::HasKey(name, this->Position->Vars,
+                               this->Position->Root);
+}
+
+void cmState::Snapshot::SetDefinition(std::string const& name,
+                                      std::string const& value)
+{
+  this->Position->Vars->Set(name, value.c_str());
+}
+
+void cmState::Snapshot::RemoveDefinition(std::string const& name)
+{
+  this->Position->Vars->Set(name, 0);
+}
+
+std::vector<std::string> cmState::Snapshot::UnusedKeys() const
+{
+  return this->Position->Vars->UnusedKeys();
+}
+
+std::vector<std::string> cmState::Snapshot::ClosureKeys() const
+{
+  return cmDefinitions::ClosureKeys(this->Position->Vars,
+                                    this->Position->Root);
+}
+
+bool cmState::Snapshot::RaiseScope(std::string const& var, const char* varDef)
+{
+  if(this->Position->ScopeParent == this->Position->DirectoryParent)
+    {
+    Snapshot parentDir = this->GetBuildsystemDirectoryParent();
+    if(!parentDir.IsValid())
+      {
+      return false;
+      }
+    // Update the definition in the parent directory top scope.  This
+    // directory's scope was initialized by the closure of the parent
+    // scope, so we do not need to localize the definition first.
+    if (varDef)
+      {
+      parentDir.SetDefinition(var, varDef);
+      }
+    else
+      {
+      parentDir.RemoveDefinition(var);
+      }
+    return true;
+    }
+  // First localize the definition in the current scope.
+  cmDefinitions::Raise(var, this->Position->Vars,
+                       this->Position->Root);
+
+  // Now update the definition in the parent scope.
+  this->Position->Parent->Set(var, varDef);
+  return true;
+}
+
 static const std::string cmPropertySentinal = std::string();
 
 template<typename T, typename U, typename V>
@@ -1177,6 +1274,11 @@ void InitializeContentFromParent(T& parentContent,
 void cmState::Snapshot::InitializeFromParent()
 {
   PositionType parent = this->Position->DirectoryParent;
+  assert(this->Position->Vars.IsValid());
+  assert(parent->Vars.IsValid());
+
+  *this->Position->Vars =
+      cmDefinitions::MakeClosure(parent->Vars, parent->Root);
 
   InitializeContentFromParent(parent->BuildSystemDirectory->IncludeDirectories,
               this->Position->BuildSystemDirectory->IncludeDirectories,
diff --git a/Source/cmState.h b/Source/cmState.h
index 4d87653..5499665 100644
--- a/Source/cmState.h
+++ b/Source/cmState.h
@@ -21,6 +21,8 @@
 
 class cmake;
 class cmCommand;
+class cmDefinitions;
+class cmListFileBacktrace;
 
 class cmState
 {
@@ -52,6 +54,14 @@ public:
     Snapshot(cmState* state = 0);
     Snapshot(cmState* state, PositionType position);
 
+    const char* GetDefinition(std::string const& name) const;
+    bool IsInitialized(std::string const& name) const;
+    void SetDefinition(std::string const& name, std::string const& value);
+    void RemoveDefinition(std::string const& name);
+    std::vector<std::string> UnusedKeys() const;
+    std::vector<std::string> ClosureKeys() const;
+    bool RaiseScope(std::string const& var, const char* varDef);
+
     void SetListFile(std::string const& listfile);
 
     std::string GetExecutionListFile() const;
@@ -273,6 +283,7 @@ private:
 
   cmLinkedTree<PolicyStackEntry> PolicyStack;
   cmLinkedTree<SnapshotDataType> SnapshotData;
+  cmLinkedTree<cmDefinitions> VarTree;
 
   std::vector<std::string> SourceDirectoryComponents;
   std::vector<std::string> BinaryDirectoryComponents;

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=6954c8936f52dcf7710e4b72b2e090b79bf38d1c
commit 6954c8936f52dcf7710e4b72b2e090b79bf38d1c
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sat Aug 1 19:41:26 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Aug 23 17:08:54 2015 +0200

    cmState: Add a VariableScope snapshot type.
    
    Match the scopes currently used in cmMakefile for definitions.

diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index aef016e..1d02cfa 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -4464,6 +4464,17 @@ void cmMakefile::PushScope()
 {
   this->Internal->PushDefinitions(Internals::VariableScope);
 
+  std::string commandName;
+  long line = 0;
+  if (!this->ContextStack.empty())
+    {
+    commandName = this->ContextStack.back()->Name;
+    line = this->ContextStack.back()->Line;
+    }
+  this->StateSnapshot = this->GetState()->CreateVariableScopeSnapshot(
+        this->StateSnapshot,
+        commandName,
+        line);
   this->PushLoopBlockBarrier();
 
 #if defined(CMAKE_BUILD_WITH_CMAKE)
@@ -4482,6 +4493,9 @@ void cmMakefile::PopScope()
   this->CheckForUnusedVariables();
 
   this->Internal->PopDefinitions();
+  this->StateSnapshot =
+      this->GetState()->Pop(this->StateSnapshot);
+  assert(this->StateSnapshot.IsValid());
 }
 
 void cmMakefile::RaiseScope(const std::string& var, const char *varDef)
diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index c777514..9e09353 100644
--- a/Source/cmState.cxx
+++ b/Source/cmState.cxx
@@ -20,6 +20,7 @@
 
 struct cmState::SnapshotDataType
 {
+  cmState::PositionType ScopeParent;
   cmState::PositionType DirectoryParent;
   cmLinkedTree<cmState::PolicyStackEntry>::iterator Policies;
   cmLinkedTree<cmState::PolicyStackEntry>::iterator PolicyRoot;
@@ -736,6 +737,7 @@ cmState::Snapshot cmState::CreateBaseSnapshot()
 {
   PositionType pos = this->SnapshotData.Extend(this->SnapshotData.Root());
   pos->DirectoryParent = this->SnapshotData.Root();
+  pos->ScopeParent = this->SnapshotData.Root();
   pos->SnapshotType = BaseType;
   pos->BuildSystemDirectory =
       this->BuildsystemDirectory.Extend(this->BuildsystemDirectory.Root());
@@ -763,6 +765,7 @@ cmState::CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot,
   pos->EntryPointLine = entryPointLine;
   pos->EntryPointCommand = entryPointCommand;
   pos->DirectoryParent = originSnapshot.Position;
+  pos->ScopeParent = originSnapshot.Position;
   pos->SnapshotType = BuildsystemDirectoryType;
   pos->BuildSystemDirectory =
       this->BuildsystemDirectory.Extend(
@@ -787,6 +790,7 @@ cmState::CreateFunctionCallSnapshot(cmState::Snapshot originSnapshot,
 {
   PositionType pos = this->SnapshotData.Extend(originSnapshot.Position,
                                                *originSnapshot.Position);
+  pos->ScopeParent = originSnapshot.Position;
   pos->EntryPointLine = entryPointLine;
   pos->EntryPointCommand = entryPointCommand;
   pos->SnapshotType = FunctionCallType;
@@ -835,6 +839,21 @@ cmState::CreateCallStackSnapshot(cmState::Snapshot originSnapshot,
 }
 
 cmState::Snapshot
+cmState::CreateVariableScopeSnapshot(cmState::Snapshot originSnapshot,
+                                     std::string const& entryPointCommand,
+                                     long entryPointLine)
+{
+  PositionType pos = this->SnapshotData.Extend(originSnapshot.Position,
+                                               *originSnapshot.Position);
+  pos->ScopeParent = originSnapshot.Position;
+  pos->EntryPointLine = entryPointLine;
+  pos->EntryPointCommand = entryPointCommand;
+  pos->SnapshotType = VariableScopeType;
+
+  return cmState::Snapshot(this, pos);
+}
+
+cmState::Snapshot
 cmState::CreateInlineListFileSnapshot(cmState::Snapshot originSnapshot,
                                       const std::string& entryPointCommand,
                                       long entryPointLine,
diff --git a/Source/cmState.h b/Source/cmState.h
index bc89cc8..4d87653 100644
--- a/Source/cmState.h
+++ b/Source/cmState.h
@@ -41,7 +41,8 @@ public:
     MacroCallType,
     CallStackType,
     InlineListFileType,
-    PolicyScopeType
+    PolicyScopeType,
+    VariableScopeType
   };
 
   class Directory;
@@ -155,6 +156,9 @@ public:
                                    std::string const& entryPointCommand,
                                    long entryPointLine,
                                    std::string const& fileName);
+  Snapshot CreateVariableScopeSnapshot(Snapshot originSnapshot,
+                                       std::string const& entryPointCommand,
+                                       long entryPointLine);
   Snapshot CreateInlineListFileSnapshot(Snapshot originSnapshot,
                                         const std::string& entryPointCommand,
                                         long entryPointLine,

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=1fc645bd9cffb3170743de5c983f2407eeaaa086
commit 1fc645bd9cffb3170743de5c983f2407eeaaa086
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sat Aug 1 19:44:47 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Aug 23 17:08:54 2015 +0200

    cmState: Add a Base snapshot type.
    
    For completeness mostly.

diff --git a/Source/cmState.cxx b/Source/cmState.cxx
index f425861..c777514 100644
--- a/Source/cmState.cxx
+++ b/Source/cmState.cxx
@@ -736,7 +736,7 @@ cmState::Snapshot cmState::CreateBaseSnapshot()
 {
   PositionType pos = this->SnapshotData.Extend(this->SnapshotData.Root());
   pos->DirectoryParent = this->SnapshotData.Root();
-  pos->SnapshotType = BuildsystemDirectoryType;
+  pos->SnapshotType = BaseType;
   pos->BuildSystemDirectory =
       this->BuildsystemDirectory.Extend(this->BuildsystemDirectory.Root());
   pos->ExecutionListFile =
@@ -1019,7 +1019,8 @@ cmState::Snapshot cmState::Snapshot::GetCallStackParent() const
     {
     ++parentPos;
     }
-  if (parentPos->SnapshotType == cmState::BuildsystemDirectoryType)
+  if (parentPos->SnapshotType == cmState::BuildsystemDirectoryType
+      || parentPos->SnapshotType == cmState::BaseType)
     {
     return snapshot;
     }
diff --git a/Source/cmState.h b/Source/cmState.h
index 07aa2a5..bc89cc8 100644
--- a/Source/cmState.h
+++ b/Source/cmState.h
@@ -35,6 +35,7 @@ public:
 
   enum SnapshotType
   {
+    BaseType,
     BuildsystemDirectoryType,
     FunctionCallType,
     MacroCallType,

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=0f070dd3e12408e0e33945c3c8f585268c4b0db9
commit 0f070dd3e12408e0e33945c3c8f585268c4b0db9
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun May 31 11:26:05 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Aug 23 17:08:53 2015 +0200

    cmMakefile: Decouple the container of cmDefinitions from scoping logic.
    
    Maintain a Parent tree node for writing to in RaiseScope.

diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index afb0166..aef016e 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -47,73 +47,105 @@
 class cmMakefile::Internals
 {
 public:
+
+  enum ScopeType
+  {
+    BaseScope,
+    MacroScope,
+    FunctionScope,
+    VariableScope
+  };
+
+  struct VarScope
+  {
+    ScopeType Type;
+    cmLinkedTree<cmDefinitions>::iterator Vars;
+    cmLinkedTree<cmDefinitions>::iterator ParentScope;
+  };
+
   cmLinkedTree<cmDefinitions> VarTree;
-  cmLinkedTree<cmDefinitions>::iterator VarTreeIter;
+  cmLinkedTree<VarScope> VarScopes;
+  cmLinkedTree<VarScope>::iterator VarScopeIter;
   bool IsSourceFileTryCompile;
 
-  void PushDefinitions()
+  void PushDefinitions(ScopeType scope)
   {
-    assert(this->VarTreeIter.IsValid());
-    this->VarTreeIter = this->VarTree.Extend(this->VarTreeIter);
+    assert(this->VarScopeIter.IsValid());
+    assert(this->VarScopeIter->Vars.IsValid());
+    cmLinkedTree<cmDefinitions>::iterator origin =
+        this->VarScopeIter->Vars;
+    cmLinkedTree<cmDefinitions>::iterator parentScope =
+//         this->VarTree.Extend(origin);
+        origin;
+    this->VarScopeIter->Vars = parentScope;
+    this->VarScopeIter = this->VarScopes.Extend(this->VarScopeIter);
+    this->VarScopeIter->ParentScope = parentScope;
+    this->VarScopeIter->Vars = this->VarTree.Extend(origin);
+    this->VarScopeIter->Type = scope;
   }
 
   void InitializeVarScope()
   {
-    this->VarTreeIter = this->VarTree.Root();
-    this->PushDefinitions();
+    assert(!this->VarScopeIter.IsValid());
+    this->VarScopeIter = this->VarScopes.Extend(this->VarScopes.Root());
+    this->VarScopeIter->Vars = this->VarTree.Extend(this->VarTree.Root());
+    this->VarScopeIter->ParentScope = this->VarTree.Root();
+    this->VarScopeIter->Type = BaseScope;
   }
 
   void InitializeDefinitions(cmMakefile* parent)
   {
-    *this->VarTreeIter =
-        cmDefinitions::MakeClosure(parent->Internal->VarTreeIter,
+    assert(this->VarScopeIter.IsValid());
+    assert(this->VarScopeIter->Vars.IsValid());
+    *this->VarScopeIter->Vars =
+        cmDefinitions::MakeClosure(parent->Internal->VarScopeIter->Vars,
                                    parent->Internal->VarTree.Root());
   }
 
   const char* GetDefinition(std::string const& name)
   {
-    assert(this->VarTreeIter != this->VarTree.Root());
+    assert(this->VarScopeIter.IsValid());
+    assert(this->VarScopeIter->Vars.IsValid());
     return cmDefinitions::Get(name,
-                              this->VarTreeIter, this->VarTree.Root());
+                              this->VarScopeIter->Vars, this->VarTree.Root());
   }
 
   bool IsInitialized(std::string const& name)
   {
     return cmDefinitions::HasKey(name,
-                                 this->VarTreeIter, this->VarTree.Root());
+                              this->VarScopeIter->Vars, this->VarTree.Root());
   }
 
   void SetDefinition(std::string const& name, std::string const& value)
   {
-    this->VarTreeIter->Set(name, value.c_str());
+    this->VarScopeIter->Vars->Set(name, value.c_str());
   }
 
   void RemoveDefinition(std::string const& name)
   {
-    this->VarTreeIter->Set(name, 0);
+    this->VarScopeIter->Vars->Set(name, 0);
   }
 
   std::vector<std::string> UnusedKeys() const
   {
-    return this->VarTreeIter->UnusedKeys();
+    return this->VarScopeIter->Vars->UnusedKeys();
   }
 
   std::vector<std::string> ClosureKeys() const
   {
-    return cmDefinitions::ClosureKeys(this->VarTreeIter, this->VarTree.Root());
+    return cmDefinitions::ClosureKeys(this->VarScopeIter->Vars,
+                                      this->VarTree.Root());
   }
 
   void PopDefinitions()
   {
-    ++this->VarTreeIter;
+    ++this->VarScopeIter;
   }
 
   bool RaiseScope(std::string const& var, const char* varDef, cmMakefile* mf)
   {
-    cmLinkedTree<cmDefinitions>::iterator it = this->VarTreeIter;
-    assert(it != this->VarTree.Root());
-    ++it;
-    if(it == this->VarTree.Root())
+    assert(this->VarScopeIter->Vars != this->VarTree.Root());
+    if(this->VarScopeIter->ParentScope == this->VarTree.Root())
       {
       cmLocalGenerator* plg = mf->LocalGenerator->GetParent();
       if(!plg)
@@ -135,10 +167,10 @@ public:
       return true;
       }
     // First localize the definition in the current scope.
-    cmDefinitions::Raise(var, this->VarTreeIter, this->VarTree.Root());
+    cmDefinitions::Raise(var, this->VarScopeIter->Vars, this->VarTree.Root());
 
     // Now update the definition in the parent scope.
-    it->Set(var, varDef);
+    this->VarScopeIter->ParentScope->Set(var, varDef);
     return true;
   }
 };
@@ -1642,7 +1674,7 @@ void cmMakefile::PushFunctionScope(std::string const& fileName,
         fileName);
   assert(this->StateSnapshot.IsValid());
 
-  this->Internal->PushDefinitions();
+  this->Internal->PushDefinitions(Internals::FunctionScope);
 
   this->PushLoopBlockBarrier();
 
@@ -4430,7 +4462,7 @@ std::string cmMakefile::FormatListFileStack() const
 
 void cmMakefile::PushScope()
 {
-  this->Internal->PushDefinitions();
+  this->Internal->PushDefinitions(Internals::VariableScope);
 
   this->PushLoopBlockBarrier();
 

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=25e04ddffeba6d4b1c9deab1ea42038c322cec83
commit 25e04ddffeba6d4b1c9deab1ea42038c322cec83
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sat May 30 17:08:34 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Aug 23 17:08:53 2015 +0200

    cmDefinitions: Implement in terms of cmLinkedTree.
    
    Store the definitions in a cmLinkedTree in the cmMakefile.  This can
    be moved to cmState and then the tree will provide snapshotting
    possibilities.  It will also make the Closure copy created at
    the start of each cmMakefile unnecesarry.

diff --git a/Source/cmDefinitions.cxx b/Source/cmDefinitions.cxx
index 2dab169..b06fb5c 100644
--- a/Source/cmDefinitions.cxx
+++ b/Source/cmDefinitions.cxx
@@ -56,9 +56,9 @@ void cmDefinitions::Raise(const std::string& key,
 }
 
 bool cmDefinitions::HasKey(const std::string& key,
-                           StackConstIter begin, StackConstIter end)
+                           StackIter begin, StackIter end)
 {
-  for (StackConstIter it = begin; it != end; ++it)
+  for (StackIter it = begin; it != end; ++it)
     {
     MapType::const_iterator i = it->Map.find(key);
     if (i != it->Map.end())
@@ -94,12 +94,12 @@ std::vector<std::string> cmDefinitions::UnusedKeys() const
 }
 
 //----------------------------------------------------------------------------
-cmDefinitions cmDefinitions::MakeClosure(StackConstIter begin,
-                                         StackConstIter end)
+cmDefinitions cmDefinitions::MakeClosure(StackIter begin,
+                                         StackIter end)
 {
   cmDefinitions closure;
   std::set<std::string> undefined;
-  for (StackConstIter it = begin; it != end; ++it)
+  for (StackIter it = begin; it != end; ++it)
     {
     // Consider local definitions.
     for(MapType::const_iterator mi = it->Map.begin();
@@ -125,12 +125,12 @@ cmDefinitions cmDefinitions::MakeClosure(StackConstIter begin,
 
 //----------------------------------------------------------------------------
 std::vector<std::string>
-cmDefinitions::ClosureKeys(StackConstIter begin, StackConstIter end)
+cmDefinitions::ClosureKeys(StackIter begin, StackIter end)
 {
   std::set<std::string> bound;
   std::vector<std::string> defined;
 
-  for (StackConstIter it = begin; it != end; ++it)
+  for (StackIter it = begin; it != end; ++it)
     {
     defined.reserve(defined.size() + it->Map.size());
     for(MapType::const_iterator mi = it->Map.begin();
diff --git a/Source/cmDefinitions.h b/Source/cmDefinitions.h
index 5fdcaab..411867c 100644
--- a/Source/cmDefinitions.h
+++ b/Source/cmDefinitions.h
@@ -13,6 +13,9 @@
 #define cmDefinitions_h
 
 #include "cmStandardIncludes.h"
+
+#include "cmLinkedTree.h"
+
 #if defined(CMAKE_BUILD_WITH_CMAKE)
 #ifdef CMake_HAVE_CXX11_UNORDERED_MAP
 #include <unordered_map>
@@ -32,26 +35,26 @@
  */
 class cmDefinitions
 {
-  typedef std::list<cmDefinitions>::reverse_iterator StackIter;
-  typedef std::list<cmDefinitions>::const_reverse_iterator StackConstIter;
+  typedef cmLinkedTree<cmDefinitions>::iterator StackIter;
 public:
   static const char* Get(const std::string& key,
                          StackIter begin, StackIter end);
 
-  static void Raise(const std::string& key, StackIter begin, StackIter end);
+  static void Raise(const std::string& key,
+                    StackIter begin, StackIter end);
 
   static bool HasKey(const std::string& key,
-                     StackConstIter begin, StackConstIter end);
+                     StackIter begin, StackIter end);
 
   /** Set (or unset if null) a value associated with a key.  */
   void Set(const std::string& key, const char* value);
 
   std::vector<std::string> UnusedKeys() const;
 
-  static std::vector<std::string> ClosureKeys(StackConstIter begin,
-                                              StackConstIter end);
+  static std::vector<std::string> ClosureKeys(StackIter begin,
+                                              StackIter end);
 
-  static cmDefinitions MakeClosure(StackConstIter begin, StackConstIter end);
+  static cmDefinitions MakeClosure(StackIter begin, StackIter end);
 
 private:
   // String with existence boolean.
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 5b2499b..afb0166 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -47,70 +47,73 @@
 class cmMakefile::Internals
 {
 public:
-  std::list<cmDefinitions> VarStack;
+  cmLinkedTree<cmDefinitions> VarTree;
+  cmLinkedTree<cmDefinitions>::iterator VarTreeIter;
   bool IsSourceFileTryCompile;
 
   void PushDefinitions()
   {
-    this->VarStack.push_back(cmDefinitions());
+    assert(this->VarTreeIter.IsValid());
+    this->VarTreeIter = this->VarTree.Extend(this->VarTreeIter);
   }
 
   void InitializeVarScope()
   {
+    this->VarTreeIter = this->VarTree.Root();
     this->PushDefinitions();
   }
 
   void InitializeDefinitions(cmMakefile* parent)
   {
-    this->VarStack.back() =
-        cmDefinitions::MakeClosure(parent->Internal->VarStack.rbegin(),
-                                   parent->Internal->VarStack.rend());
+    *this->VarTreeIter =
+        cmDefinitions::MakeClosure(parent->Internal->VarTreeIter,
+                                   parent->Internal->VarTree.Root());
   }
 
   const char* GetDefinition(std::string const& name)
   {
-    return cmDefinitions::Get(name, this->VarStack.rbegin(),
-                                    this->VarStack.rend());
+    assert(this->VarTreeIter != this->VarTree.Root());
+    return cmDefinitions::Get(name,
+                              this->VarTreeIter, this->VarTree.Root());
   }
 
   bool IsInitialized(std::string const& name)
   {
-    return cmDefinitions::HasKey(name, this->VarStack.rbegin(),
-                                 this->VarStack.rend());
+    return cmDefinitions::HasKey(name,
+                                 this->VarTreeIter, this->VarTree.Root());
   }
 
   void SetDefinition(std::string const& name, std::string const& value)
   {
-    this->VarStack.back().Set(name, value.c_str());
+    this->VarTreeIter->Set(name, value.c_str());
   }
 
   void RemoveDefinition(std::string const& name)
   {
-    this->VarStack.back().Set(name, 0);
+    this->VarTreeIter->Set(name, 0);
   }
 
   std::vector<std::string> UnusedKeys() const
   {
-    return this->VarStack.back().UnusedKeys();
+    return this->VarTreeIter->UnusedKeys();
   }
 
   std::vector<std::string> ClosureKeys() const
   {
-    return cmDefinitions::ClosureKeys(this->VarStack.rbegin(),
-                                      this->VarStack.rend());
+    return cmDefinitions::ClosureKeys(this->VarTreeIter, this->VarTree.Root());
   }
 
   void PopDefinitions()
   {
-    this->VarStack.pop_back();
+    ++this->VarTreeIter;
   }
 
   bool RaiseScope(std::string const& var, const char* varDef, cmMakefile* mf)
   {
-    std::list<cmDefinitions>::reverse_iterator it = this->VarStack.rbegin();
-    assert(it != this->VarStack.rend());
+    cmLinkedTree<cmDefinitions>::iterator it = this->VarTreeIter;
+    assert(it != this->VarTree.Root());
     ++it;
-    if(it == this->VarStack.rend())
+    if(it == this->VarTree.Root())
       {
       cmLocalGenerator* plg = mf->LocalGenerator->GetParent();
       if(!plg)
@@ -132,7 +135,7 @@ public:
       return true;
       }
     // First localize the definition in the current scope.
-    cmDefinitions::Raise(var, this->VarStack.rbegin(), this->VarStack.rend());
+    cmDefinitions::Raise(var, this->VarTreeIter, this->VarTree.Root());
 
     // Now update the definition in the parent scope.
     it->Set(var, varDef);

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=4bbe261cd34818379d06b68d2e153a98cfccfcf5
commit 4bbe261cd34818379d06b68d2e153a98cfccfcf5
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Mon Jun 8 20:04:24 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Sun Aug 23 17:08:53 2015 +0200

    cmMakefile: Extract InitializeVarScope method.

diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 85bc493..5b2499b 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -55,6 +55,11 @@ public:
     this->VarStack.push_back(cmDefinitions());
   }
 
+  void InitializeVarScope()
+  {
+    this->PushDefinitions();
+  }
+
   void InitializeDefinitions(cmMakefile* parent)
   {
     this->VarStack.back() =
@@ -141,7 +146,7 @@ cmMakefile::cmMakefile(cmLocalGenerator* localGenerator)
     LocalGenerator(localGenerator),
     StateSnapshot(localGenerator->GetStateSnapshot())
 {
-  this->Internal->PushDefinitions();
+  this->Internal->InitializeVarScope();
   this->Internal->IsSourceFileTryCompile = false;
 
   // Initialize these first since AddDefaultDefinitions calls AddDefinition

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

Summary of changes:
 Source/CMakeVersion.cmake    |    2 +-
 Source/cmDefinitions.cxx     |   14 ++--
 Source/cmDefinitions.h       |   17 ++--
 Source/cmGlobalGenerator.cxx |   65 ++++++++++++++++
 Source/cmLinkedTree.h        |   11 +++
 Source/cmMakefile.cxx        |  135 +++++++-------------------------
 Source/cmState.cxx           |  176 +++++++++++++++++++++++++++++++++++++++++-
 Source/cmState.h             |   33 +++++++-
 8 files changed, 327 insertions(+), 126 deletions(-)


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list