[Cmake-commits] CMake branch, next, updated. v3.3.0-2042-g6b479d5

Stephen Kelly steveire at gmail.com
Thu Aug 6 18:39:36 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  6b479d5ee112efce1565fb8cbdebe389af3a9337 (commit)
       via  230c212756e641cbfc6327ce796ffa0f617a4c24 (commit)
       via  37554424986199c41fc8825d81490ba75f271edb (commit)
       via  94052592b9aa298ed367542841f44cca23b927be (commit)
       via  ddcae2f2e80e10ef8c1a1e32ef9bfd67272ea766 (commit)
       via  24c9ec4569f08e2320fd1c4f43e01bf9cfefae5a (commit)
       via  976bd2a8ea0b0d66de06d1c21a483bb29d3ea903 (commit)
       via  615dec8af09469e9243b473b7b8a1f970bb7d00f (commit)
       via  ba3f3e3b43ae3ce8e61a62b90f57c6cfdf6d2243 (commit)
      from  026814ad56e9da194baa1597a4de222227920ca5 (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=6b479d5ee112efce1565fb8cbdebe389af3a9337
commit 6b479d5ee112efce1565fb8cbdebe389af3a9337
Merge: 026814a 230c212
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Thu Aug 6 18:39:34 2015 -0400
Commit:     CMake Topic Stage <kwrobot at kitware.com>
CommitDate: Thu Aug 6 18:39:34 2015 -0400

    Merge topic 'cmState-definitions' into next
    
    230c2127 cmState: Reserve the number of cmLinkedTree nodes if known.
    37554424 cmLinkedTree: Add API for size query and reserve.
    94052592 cmState: Host variable definitions.
    ddcae2f2 cmState: Add a VariableScope snapshot type.
    24c9ec45 cmState: Add a Base snapshot type.
    976bd2a8 cmMakefile: Decouple the container of cmDefinitions from scoping logic.
    615dec8a cmDefinitions: Implement in terms of cmLinkedTree.
    ba3f3e3b cmMakefile: Extract InitializeVarScope method.

diff --cc Source/cmGlobalGenerator.cxx
index 1885e24,6d079cd..b76f277
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@@ -1148,11 -1183,40 +1184,40 @@@ void cmGlobalGenerator::Configure(
    // update the cache entry for the number of local generators, this is used
    // for progress
    char num[100];
 -  sprintf(num,"%d",static_cast<int>(this->LocalGenerators.size()));
 +  sprintf(num,"%d",static_cast<int>(this->Makefiles.size()));
    this->GetCMakeInstance()->AddCacheEntry
 -    ("CMAKE_NUMBER_OF_LOCAL_GENERATORS", num,
 +    ("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();

http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=230c212756e641cbfc6327ce796ffa0f617a4c24
commit 230c212756e641cbfc6327ce796ffa0f617a4c24
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Jun 21 13:05:15 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Fri Aug 7 00:37:42 2015 +0200

    cmState: Reserve the number of cmLinkedTree nodes if known.

diff --git a/Source/cmGlobalGenerator.cxx b/Source/cmGlobalGenerator.cxx
index 3c818ff..6d079cd 100644
--- a/Source/cmGlobalGenerator.cxx
+++ b/Source/cmGlobalGenerator.cxx
@@ -1140,6 +1140,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();
@@ -1152,6 +1188,35 @@ void cmGlobalGenerator::Configure()
     ("CMAKE_NUMBER_OF_LOCAL_GENERATORS", 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 17ff09c..fc4fa30 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=37554424986199c41fc8825d81490ba75f271edb
commit 37554424986199c41fc8825d81490ba75f271edb
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Jun 21 13:04:43 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Fri Aug 7 00:37:42 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=94052592b9aa298ed367542841f44cca23b927be
commit 94052592b9aa298ed367542841f44cca23b927be
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun Jun 21 21:26:43 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Fri Aug 7 00:37:42 2015 +0200

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

diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 40c90ea..15cfd0c 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,131 +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);
-    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
@@ -180,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
@@ -1606,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",
@@ -1673,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)
@@ -1701,8 +1570,6 @@ void cmMakefile::PopFunctionScope(bool reportError)
   this->PopLoopBlockBarrier();
 
   this->CheckForUnusedVariables();
-
-  this->Internal->PopDefinitions();
 }
 
 void cmMakefile::PushMacroScope(std::string const& fileName,
@@ -2005,7 +1872,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();
@@ -2068,7 +1935,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);
 }
 
 
@@ -2078,7 +1945,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 )
@@ -2095,7 +1964,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)
     {
@@ -2105,12 +1974,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,
@@ -2158,7 +2027,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 )
@@ -2624,7 +2493,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);
@@ -2645,7 +2514,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);
@@ -2681,7 +2550,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());
@@ -4460,8 +4329,6 @@ std::string cmMakefile::FormatListFileStack() const
 
 void cmMakefile::PushScope()
 {
-  this->Internal->PushDefinitions(Internals::VariableScope);
-
   std::string commandName;
   long line = 0;
   if (!this->ContextStack.empty())
@@ -4490,7 +4357,6 @@ void cmMakefile::PopScope()
 
   this->CheckForUnusedVariables();
 
-  this->Internal->PopDefinitions();
   this->StateSnapshot =
       this->GetState()->Pop(this->StateSnapshot);
   assert(this->StateSnapshot.IsValid());
@@ -4503,7 +4369,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..17ff09c 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,25 @@ cmState::CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot,
   pos->PolicyScope = originSnapshot.Position->Policies;
   assert(pos->Policies.IsValid());
   assert(pos->PolicyRoot.IsValid());
+
+  cmLinkedTree<cmDefinitions>::iterator origin = originSnapshot.Position->Vars;
+  cmLinkedTree<cmDefinitions>::iterator newVars = this->VarTree.Extend(origin);
+
+  PositionType originPos = originSnapshot.Position;
+  while(originPos.IsValid())
+    {
+    originPos->Vars = newVars;
+    if ((originPos->SnapshotType == BaseType)
+        || (originPos->SnapshotType == FunctionCallType)
+        || (originPos->SnapshotType == VariableScopeType)
+        || (originPos->SnapshotType == BuildsystemDirectoryType))
+      break;
+    ++originPos;
+    }
+
+  pos->Parent = newVars;
+  pos->Root = origin;
+  pos->Vars = this->VarTree.Extend(origin);
   return cmState::Snapshot(this, pos);
 }
 
@@ -798,6 +829,25 @@ 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;
+  cmLinkedTree<cmDefinitions>::iterator newVars = this->VarTree.Extend(origin);
+
+  PositionType originPos = originSnapshot.Position;
+  while(originPos.IsValid())
+    {
+    originPos->Vars = newVars;
+    if ((originPos->SnapshotType == BaseType)
+        || (originPos->SnapshotType == FunctionCallType)
+        || (originPos->SnapshotType == VariableScopeType)
+        || (originPos->SnapshotType == BuildsystemDirectoryType))
+      break;
+    ++originPos;
+    }
+
+  pos->Parent = newVars;
+  pos->Vars = this->VarTree.Extend(origin);
   return cmState::Snapshot(this, pos);
 }
 
@@ -815,6 +865,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 +884,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 +901,27 @@ 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;
+  cmLinkedTree<cmDefinitions>::iterator newVars = this->VarTree.Extend(origin);
 
+  PositionType originPos = originSnapshot.Position;
+  while(originPos.IsValid())
+    {
+    originPos->Vars = newVars;
+    if ((originPos->SnapshotType == BaseType)
+        || (originPos->SnapshotType == FunctionCallType)
+        || (originPos->SnapshotType == VariableScopeType)
+        || (originPos->SnapshotType == BuildsystemDirectoryType))
+      break;
+    ++originPos;
+    }
+
+  pos->Parent = newVars;
+  pos->Vars = this->VarTree.Extend(origin);
+  assert(pos->Vars.IsValid());
   return cmState::Snapshot(this, pos);
 }
 
@@ -1141,6 +1213,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 +1315,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=ddcae2f2e80e10ef8c1a1e32ef9bfd67272ea766
commit ddcae2f2e80e10ef8c1a1e32ef9bfd67272ea766
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sat Aug 1 19:41:26 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Fri Aug 7 00:37:41 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 889c1cb..40c90ea 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -4462,6 +4462,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)
@@ -4480,6 +4491,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=24c9ec4569f08e2320fd1c4f43e01bf9cfefae5a
commit 24c9ec4569f08e2320fd1c4f43e01bf9cfefae5a
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sat Aug 1 19:44:47 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Fri Aug 7 00:37:41 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=976bd2a8ea0b0d66de06d1c21a483bb29d3ea903
commit 976bd2a8ea0b0d66de06d1c21a483bb29d3ea903
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sun May 31 11:26:05 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Fri Aug 7 00:37:41 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 8ed1d4c..889c1cb 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -47,73 +47,104 @@
 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);
+    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 +166,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 +1673,7 @@ void cmMakefile::PushFunctionScope(std::string const& fileName,
         fileName);
   assert(this->StateSnapshot.IsValid());
 
-  this->Internal->PushDefinitions();
+  this->Internal->PushDefinitions(Internals::FunctionScope);
 
   this->PushLoopBlockBarrier();
 
@@ -4429,7 +4460,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=615dec8af09469e9243b473b7b8a1f970bb7d00f
commit 615dec8af09469e9243b473b7b8a1f970bb7d00f
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Sat May 30 17:08:34 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Fri Aug 7 00:37:41 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 e6fc464..8ed1d4c 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=ba3f3e3b43ae3ce8e61a62b90f57c6cfdf6d2243
commit ba3f3e3b43ae3ce8e61a62b90f57c6cfdf6d2243
Author:     Stephen Kelly <steveire at gmail.com>
AuthorDate: Mon Jun 8 20:04:24 2015 +0200
Commit:     Stephen Kelly <steveire at gmail.com>
CommitDate: Fri Aug 7 00:37:40 2015 +0200

    cmMakefile: Extract InitializeVarScope method.

diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index 60a11e1..e6fc464 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/cmDefinitions.cxx     |   14 +--
 Source/cmDefinitions.h       |   17 ++--
 Source/cmGlobalGenerator.cxx |   65 +++++++++++++
 Source/cmLinkedTree.h        |   11 +++
 Source/cmMakefile.cxx        |  135 ++++++--------------------
 Source/cmState.cxx           |  217 +++++++++++++++++++++++++++++++++++++++++-
 Source/cmState.h             |   33 ++++++-
 7 files changed, 367 insertions(+), 125 deletions(-)


hooks/post-receive
-- 
CMake


More information about the Cmake-commits mailing list