From 1b323949fe6770fa36846a5a85d049121c7ce2c4 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 23 May 2015 09:54:07 +0200 Subject: cmState: Extend Snapshot concept with a SnapshotType. Store it together with the Parent position. --- Source/cmState.cxx | 27 ++++++++++++++++++++------- Source/cmState.h | 8 +++++++- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/Source/cmState.cxx b/Source/cmState.cxx index c6fb299..4691a00 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -18,6 +18,12 @@ #include +struct cmState::SnapshotDataType +{ + cmState::PositionType DirectoryParent; + cmState::SnapshotType SnapshotType; +}; + cmState::cmState(cmake* cm) : CMakeInstance(cm), IsInTryCompile(false), @@ -202,7 +208,7 @@ void cmState::Reset() assert(this->Locations.size() > 0); assert(this->OutputLocations.size() > 0); - assert(this->ParentPositions.size() > 0); + assert(this->SnapshotData.size() > 0); assert(this->CurrentSourceDirectoryComponents.size() > 0); assert(this->CurrentBinaryDirectoryComponents.size() > 0); assert(this->RelativePathTopSource.size() > 0); @@ -211,8 +217,8 @@ void cmState::Reset() this->Locations.erase(this->Locations.begin() + 1, this->Locations.end()); this->OutputLocations.erase(this->OutputLocations.begin() + 1, this->OutputLocations.end()); - this->ParentPositions.erase(this->ParentPositions.begin() + 1, - this->ParentPositions.end()); + this->SnapshotData.erase(this->SnapshotData.begin() + 1, + this->SnapshotData.end()); this->CurrentSourceDirectoryComponents.erase( this->CurrentSourceDirectoryComponents.begin() + 1, this->CurrentSourceDirectoryComponents.end()); @@ -662,7 +668,10 @@ void cmState::Snapshot::ComputeRelativePathTopBinary() cmState::Snapshot cmState::CreateBaseSnapshot() { PositionType pos = 0; - this->ParentPositions.push_back(pos); + this->SnapshotData.resize(1); + SnapshotDataType& snp = this->SnapshotData.back(); + snp.DirectoryParent = 0; + snp.SnapshotType = BuildsystemDirectoryType; this->Locations.resize(1); this->OutputLocations.resize(1); this->CurrentSourceDirectoryComponents.resize(1); @@ -676,8 +685,11 @@ cmState::Snapshot cmState::CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot) { assert(originSnapshot.IsValid()); - PositionType pos = this->ParentPositions.size(); - this->ParentPositions.push_back(originSnapshot.Position); + PositionType pos = this->SnapshotData.size(); + this->SnapshotData.resize(this->SnapshotData.size() + 1); + SnapshotDataType& snp = this->SnapshotData.back(); + snp.DirectoryParent = originSnapshot.Position; + snp.SnapshotType = BuildsystemDirectoryType; this->Locations.resize(this->Locations.size() + 1); this->OutputLocations.resize(this->OutputLocations.size() + 1); this->CurrentSourceDirectoryComponents.resize( @@ -782,7 +794,8 @@ cmState::Snapshot cmState::Snapshot::GetBuildsystemDirectoryParent() const { return snapshot; } - PositionType parentPos = this->State->ParentPositions[this->Position]; + PositionType parentPos = + this->State->SnapshotData[this->Position].DirectoryParent; snapshot = Snapshot(this->State, parentPos); return snapshot; diff --git a/Source/cmState.h b/Source/cmState.h index 60b024f..024c9a9 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -21,12 +21,18 @@ class cmCommand; class cmState { + struct SnapshotDataType; typedef std::vector::size_type PositionType; friend class Snapshot; public: cmState(cmake* cm); ~cmState(); + enum SnapshotType + { + BuildsystemDirectoryType + }; + class Snapshot { public: Snapshot(cmState* state = 0, PositionType position = 0); @@ -160,7 +166,7 @@ private: cmake* CMakeInstance; std::vector Locations; std::vector OutputLocations; - std::vector ParentPositions; + std::vector SnapshotData; std::vector > CurrentSourceDirectoryComponents; std::vector > CurrentBinaryDirectoryComponents; -- cgit v0.12 From 7b9c75860d25479a153831740d289e8aca540f4d Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 23 May 2015 10:37:07 +0200 Subject: cmState: Group BuildsystemDirectory state together in a struct. It needs to be snapshotted independently of other state. --- Source/cmState.cxx | 139 +++++++++++++++++++++++++++++------------------------ Source/cmState.h | 16 ++---- 2 files changed, 81 insertions(+), 74 deletions(-) diff --git a/Source/cmState.cxx b/Source/cmState.cxx index 4691a00..161cee4 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -22,6 +22,24 @@ struct cmState::SnapshotDataType { cmState::PositionType DirectoryParent; cmState::SnapshotType SnapshotType; + std::vector::size_type + BuildSystemDirectoryPosition; +}; + +struct cmState::BuildsystemDirectoryStateType +{ + std::string Location; + std::string OutputLocation; + + std::vector CurrentSourceDirectoryComponents; + std::vector CurrentBinaryDirectoryComponents; + // The top-most directories for relative path conversion. Both the + // source and destination location of a relative path conversion + // must be underneath one of these directories (both under source or + // both under binary) in order for the relative path to be evaluated + // safely by the build tools. + std::string RelativePathTopSource; + std::string RelativePathTopBinary; }; cmState::cmState(cmake* cm) @@ -206,29 +224,13 @@ void cmState::Reset() this->GlobalProperties.clear(); this->PropertyDefinitions.clear(); - assert(this->Locations.size() > 0); - assert(this->OutputLocations.size() > 0); + assert(this->BuildsystemDirectory.size() > 0); assert(this->SnapshotData.size() > 0); - assert(this->CurrentSourceDirectoryComponents.size() > 0); - assert(this->CurrentBinaryDirectoryComponents.size() > 0); - assert(this->RelativePathTopSource.size() > 0); - assert(this->RelativePathTopBinary.size() > 0); - - this->Locations.erase(this->Locations.begin() + 1, this->Locations.end()); - this->OutputLocations.erase(this->OutputLocations.begin() + 1, - this->OutputLocations.end()); + + this->BuildsystemDirectory.erase(this->BuildsystemDirectory.begin() + 1, + this->BuildsystemDirectory.end()); this->SnapshotData.erase(this->SnapshotData.begin() + 1, this->SnapshotData.end()); - this->CurrentSourceDirectoryComponents.erase( - this->CurrentSourceDirectoryComponents.begin() + 1, - this->CurrentSourceDirectoryComponents.end()); - this->CurrentBinaryDirectoryComponents.erase( - this->CurrentBinaryDirectoryComponents.begin() + 1, - this->CurrentBinaryDirectoryComponents.end()); - this->RelativePathTopSource.erase(this->RelativePathTopSource.begin() + 1, - this->RelativePathTopSource.end()); - this->RelativePathTopBinary.erase(this->RelativePathTopBinary.begin() + 1, - this->RelativePathTopBinary.end()); this->DefineProperty ("RULE_LAUNCH_COMPILE", cmProperty::DIRECTORY, @@ -618,7 +620,9 @@ void cmState::Snapshot::ComputeRelativePathTopSource() result = currentSource; } } - this->State->RelativePathTopSource[this->Position] = result; + PositionType pos = + this->State->SnapshotData[this->Position].BuildSystemDirectoryPosition; + this->State->BuildsystemDirectory[pos].RelativePathTopSource = result; } void cmState::Snapshot::ComputeRelativePathTopBinary() @@ -652,16 +656,18 @@ void cmState::Snapshot::ComputeRelativePathTopBinary() } } + PositionType pos = + this->State->SnapshotData[this->Position].BuildSystemDirectoryPosition; // The current working directory on Windows cannot be a network // path. Therefore relative paths cannot work when the binary tree // is a network path. if(result.size() < 2 || result.substr(0, 2) != "//") { - this->State->RelativePathTopBinary[this->Position] = result; + this->State->BuildsystemDirectory[pos].RelativePathTopBinary = result; } else { - this->State->RelativePathTopBinary[this->Position] = ""; + this->State->BuildsystemDirectory[pos].RelativePathTopBinary = ""; } } @@ -672,12 +678,8 @@ cmState::Snapshot cmState::CreateBaseSnapshot() SnapshotDataType& snp = this->SnapshotData.back(); snp.DirectoryParent = 0; snp.SnapshotType = BuildsystemDirectoryType; - this->Locations.resize(1); - this->OutputLocations.resize(1); - this->CurrentSourceDirectoryComponents.resize(1); - this->CurrentBinaryDirectoryComponents.resize(1); - this->RelativePathTopSource.resize(1); - this->RelativePathTopBinary.resize(1); + snp.BuildSystemDirectoryPosition = 0; + this->BuildsystemDirectory.resize(1); return cmState::Snapshot(this, pos); } @@ -690,14 +692,8 @@ cmState::CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot) SnapshotDataType& snp = this->SnapshotData.back(); snp.DirectoryParent = originSnapshot.Position; snp.SnapshotType = BuildsystemDirectoryType; - this->Locations.resize(this->Locations.size() + 1); - this->OutputLocations.resize(this->OutputLocations.size() + 1); - this->CurrentSourceDirectoryComponents.resize( - this->CurrentSourceDirectoryComponents.size() + 1); - this->CurrentBinaryDirectoryComponents.resize( - this->CurrentBinaryDirectoryComponents.size() + 1); - this->RelativePathTopSource.resize(this->RelativePathTopSource.size() + 1); - this->RelativePathTopBinary.resize(this->RelativePathTopBinary.size() + 1); + snp.BuildSystemDirectoryPosition = this->BuildsystemDirectory.size(); + this->BuildsystemDirectory.resize(this->BuildsystemDirectory.size() + 1); return cmState::Snapshot(this, pos); } @@ -710,76 +706,95 @@ cmState::Snapshot::Snapshot(cmState* state, PositionType position) const char* cmState::Snapshot::GetCurrentSourceDirectory() const { - return this->State->Locations[this->Position].c_str(); + PositionType pos = + this->State->SnapshotData[this->Position].BuildSystemDirectoryPosition; + return this->State->BuildsystemDirectory[pos].Location.c_str(); } void cmState::Snapshot::SetCurrentSourceDirectory(std::string const& dir) { assert(this->State); - assert(this->State->Locations.size() > this->Position); - this->State->Locations[this->Position] = dir; - cmSystemTools::ConvertToUnixSlashes( - this->State->Locations[this->Position]); - this->State->Locations[this->Position] = - cmSystemTools::CollapseFullPath(this->State->Locations[this->Position]); + assert(this->State->SnapshotData.size() > this->Position); + PositionType pos = + this->State->SnapshotData[this->Position].BuildSystemDirectoryPosition; + std::string& loc = this->State->BuildsystemDirectory[pos].Location; + loc = dir; + cmSystemTools::ConvertToUnixSlashes(loc); + loc = cmSystemTools::CollapseFullPath(loc); cmSystemTools::SplitPath( - this->State->Locations[this->Position], - this->State->CurrentSourceDirectoryComponents[this->Position]); + loc, + this->State->BuildsystemDirectory[pos].CurrentSourceDirectoryComponents); this->ComputeRelativePathTopSource(); } const char* cmState::Snapshot::GetCurrentBinaryDirectory() const { - return this->State->OutputLocations[this->Position].c_str(); + PositionType pos = + this->State->SnapshotData[this->Position].BuildSystemDirectoryPosition; + return this->State->BuildsystemDirectory[pos].OutputLocation.c_str(); } void cmState::Snapshot::SetCurrentBinaryDirectory(std::string const& dir) { - assert(this->State->OutputLocations.size() > this->Position); - this->State->OutputLocations[this->Position] = dir; - cmSystemTools::ConvertToUnixSlashes( - this->State->OutputLocations[this->Position]); - this->State->OutputLocations[this->Position] = - cmSystemTools::CollapseFullPath( - this->State->OutputLocations[this->Position]); + assert(this->State->SnapshotData.size() > this->Position); + PositionType pos = + this->State->SnapshotData[this->Position].BuildSystemDirectoryPosition; + std::string& loc = this->State->BuildsystemDirectory[pos].OutputLocation; + loc = dir; + cmSystemTools::ConvertToUnixSlashes(loc); + loc = cmSystemTools::CollapseFullPath(loc); cmSystemTools::SplitPath( - this->State->OutputLocations[this->Position], - this->State->CurrentBinaryDirectoryComponents[this->Position]); + loc, + this->State->BuildsystemDirectory[pos].CurrentBinaryDirectoryComponents); this->ComputeRelativePathTopBinary(); } std::vector const& cmState::Snapshot::GetCurrentSourceDirectoryComponents() { - return this->State->CurrentSourceDirectoryComponents[this->Position]; + PositionType pos = + this->State->SnapshotData[this->Position].BuildSystemDirectoryPosition; + return this->State + ->BuildsystemDirectory[pos].CurrentSourceDirectoryComponents; } std::vector const& cmState::Snapshot::GetCurrentBinaryDirectoryComponents() { - return this->State->CurrentBinaryDirectoryComponents[this->Position]; + PositionType pos = + this->State->SnapshotData[this->Position].BuildSystemDirectoryPosition; + return this->State + ->BuildsystemDirectory[pos].CurrentBinaryDirectoryComponents; } const char* cmState::Snapshot::GetRelativePathTopSource() const { - return this->State->RelativePathTopSource[this->Position].c_str(); + PositionType pos = + this->State->SnapshotData[this->Position].BuildSystemDirectoryPosition; + return this->State->BuildsystemDirectory[pos].RelativePathTopSource.c_str(); } const char* cmState::Snapshot::GetRelativePathTopBinary() const { - return this->State->RelativePathTopBinary[this->Position].c_str(); + PositionType pos = + this->State->SnapshotData[this->Position].BuildSystemDirectoryPosition; + return this->State->BuildsystemDirectory[pos].RelativePathTopBinary.c_str(); } void cmState::Snapshot::SetRelativePathTopSource(const char* dir) { - this->State->RelativePathTopSource[this->Position] = dir; + PositionType pos = + this->State->SnapshotData[this->Position].BuildSystemDirectoryPosition; + this->State->BuildsystemDirectory[pos].RelativePathTopSource = dir; } void cmState::Snapshot::SetRelativePathTopBinary(const char* dir) { - this->State->RelativePathTopBinary[this->Position] = dir; + PositionType pos = + this->State->SnapshotData[this->Position].BuildSystemDirectoryPosition; + this->State->BuildsystemDirectory[pos].RelativePathTopBinary = dir; } bool cmState::Snapshot::IsValid() const diff --git a/Source/cmState.h b/Source/cmState.h index 024c9a9..4589a72 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -164,19 +164,11 @@ private: std::map Commands; cmPropertyMap GlobalProperties; cmake* CMakeInstance; - std::vector Locations; - std::vector OutputLocations; - std::vector SnapshotData; - std::vector > CurrentSourceDirectoryComponents; - std::vector > CurrentBinaryDirectoryComponents; - // The top-most directories for relative path conversion. Both the - // source and destination location of a relative path conversion - // must be underneath one of these directories (both under source or - // both under binary) in order for the relative path to be evaluated - // safely by the build tools. - std::vector RelativePathTopSource; - std::vector RelativePathTopBinary; + struct BuildsystemDirectoryStateType; + std::vector BuildsystemDirectory; + + std::vector SnapshotData; std::vector SourceDirectoryComponents; std::vector BinaryDirectoryComponents; -- cgit v0.12 From 4e5c70abe27997f17318cc6aca38eeddec486798 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Sat, 23 May 2015 00:04:09 +0200 Subject: cmState: Extract a cmLinkedTree container adaptor. This will be used to contain most of the content of the cmState in several different trees. Refer to the BuildsystemDirectory state from the SnapshotData state. Currently these trees have the same structure, but that will change when we have more snapshot types. --- Source/CMakeLists.txt | 1 + Source/cmLinkedTree.h | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++ Source/cmState.cxx | 112 +++++++++++++--------------------- Source/cmState.h | 9 +-- 4 files changed, 211 insertions(+), 75 deletions(-) create mode 100644 Source/cmLinkedTree.h diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index a7adb51..e8d5107 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -281,6 +281,7 @@ set(SRCS cmInstallTargetGenerator.cxx cmInstallDirectoryGenerator.h cmInstallDirectoryGenerator.cxx + cmLinkedTree.h cmListFileCache.cxx cmListFileCache.h cmListFileLexer.c diff --git a/Source/cmLinkedTree.h b/Source/cmLinkedTree.h new file mode 100644 index 0000000..d2339c4 --- /dev/null +++ b/Source/cmLinkedTree.h @@ -0,0 +1,164 @@ +/*============================================================================ + CMake - Cross Platform Makefile Generator + Copyright 2015 Stephen Kelly + + Distributed under the OSI-approved BSD License (the "License"); + see accompanying file Copyright.txt for details. + + This software is distributed WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the License for more information. +============================================================================*/ +#ifndef cmLinkedTree_h +#define cmLinkedTree_h + +#include "cmStandardIncludes.h" + +#include + +/** + @brief A adaptor for traversing a tree structure in a vector + + This class is not intended to be wholly generic like a standard library + container adaptor. Mostly it exists to facilitate code sharing for the + needs of the cmState. For example, the Truncate() method is a specific + requirement of the cmState. + + An empty cmLinkedTree provides a Root() method, and an Extend() method, + each of which return iterators. A Tree can be built up by extending + from the root, and then extending from any other iterator. + + An iterator resulting from this tree construction can be + forward-only-iterated toward the root. Extending the tree never + invalidates existing iterators. + */ +template +class cmLinkedTree +{ + typedef typename std::vector::size_type PositionType; + typedef T* PointerType; + typedef T& ReferenceType; +public: + class iterator : public std::iterator + { + friend class cmLinkedTree; + cmLinkedTree* Tree; + + // The Position is always 'one past the end'. + PositionType Position; + + iterator(cmLinkedTree* tree, PositionType pos) + : Tree(tree), Position(pos) + { + + } + + public: + iterator() + : Tree(0), Position(0) + { + + } + + void operator++() + { + assert(this->Tree); + assert(this->Tree->UpPositions.size() == this->Tree->Data.size()); + assert(this->Position <= this->Tree->Data.size()); + assert(this->Position > 0); + this->Position = this->Tree->UpPositions[this->Position - 1]; + } + + PointerType operator->() const + { + assert(this->Tree); + assert(this->Tree->UpPositions.size() == this->Tree->Data.size()); + assert(this->Position <= this->Tree->Data.size()); + assert(this->Position > 0); + return this->Tree->GetPointer(this->Position - 1); + } + + PointerType operator->() + { + assert(this->Tree); + assert(this->Tree->UpPositions.size() == this->Tree->Data.size()); + assert(this->Position <= this->Tree->Data.size()); + assert(this->Position > 0); + return this->Tree->GetPointer(this->Position - 1); + } + + bool operator==(iterator other) const + { + assert(this->Tree); + assert(this->Tree->UpPositions.size() == this->Tree->Data.size()); + assert(this->Tree == other.Tree); + return this->Position == other.Position; + } + + bool operator!=(iterator other) const + { + assert(this->Tree); + assert(this->Tree->UpPositions.size() == this->Tree->Data.size()); + return !(*this == other); + } + + bool IsValid() const + { + if (!this->Tree) + { + return false; + } + return this->Position <= this->Tree->Data.size(); + } + }; + + iterator Root() const + { + return iterator(const_cast(this), 0); + } + + iterator Extend(iterator it) + { + return Extend_impl(it, T()); + } + + iterator Extend(iterator it, T t) + { + return Extend_impl(it, t); + } + + iterator Truncate() + { + assert(this->UpPositions.size() > 0); + this->UpPositions.erase(this->UpPositions.begin() + 1, + this->UpPositions.end()); + assert(this->Data.size() > 0); + this->Data.erase(this->Data.begin() + 1, this->Data.end()); + return iterator(this, 1); + } + +private: + T& GetReference(PositionType pos) + { + return this->Data[pos]; + } + + T* GetPointer(PositionType pos) + { + return &this->Data[pos]; + } + + iterator Extend_impl(iterator it, T t) + { + assert(this->UpPositions.size() == this->Data.size()); + assert(it.Position <= this->UpPositions.size()); + this->UpPositions.push_back(it.Position); + this->Data.push_back(t); + return iterator(this, this->UpPositions.size()); + } + + std::vector Data; + std::vector UpPositions; +}; + +#endif diff --git a/Source/cmState.cxx b/Source/cmState.cxx index 161cee4..a2ebb24 100644 --- a/Source/cmState.cxx +++ b/Source/cmState.cxx @@ -22,8 +22,8 @@ struct cmState::SnapshotDataType { cmState::PositionType DirectoryParent; cmState::SnapshotType SnapshotType; - std::vector::size_type - BuildSystemDirectoryPosition; + cmLinkedTree::iterator + BuildSystemDirectory; }; struct cmState::BuildsystemDirectoryStateType @@ -224,13 +224,8 @@ void cmState::Reset() this->GlobalProperties.clear(); this->PropertyDefinitions.clear(); - assert(this->BuildsystemDirectory.size() > 0); - assert(this->SnapshotData.size() > 0); - - this->BuildsystemDirectory.erase(this->BuildsystemDirectory.begin() + 1, - this->BuildsystemDirectory.end()); - this->SnapshotData.erase(this->SnapshotData.begin() + 1, - this->SnapshotData.end()); + this->BuildsystemDirectory.Truncate(); + this->SnapshotData.Truncate(); this->DefineProperty ("RULE_LAUNCH_COMPILE", cmProperty::DIRECTORY, @@ -620,9 +615,7 @@ void cmState::Snapshot::ComputeRelativePathTopSource() result = currentSource; } } - PositionType pos = - this->State->SnapshotData[this->Position].BuildSystemDirectoryPosition; - this->State->BuildsystemDirectory[pos].RelativePathTopSource = result; + this->Position->BuildSystemDirectory->RelativePathTopSource = result; } void cmState::Snapshot::ComputeRelativePathTopBinary() @@ -656,30 +649,26 @@ void cmState::Snapshot::ComputeRelativePathTopBinary() } } - PositionType pos = - this->State->SnapshotData[this->Position].BuildSystemDirectoryPosition; // The current working directory on Windows cannot be a network // path. Therefore relative paths cannot work when the binary tree // is a network path. if(result.size() < 2 || result.substr(0, 2) != "//") { - this->State->BuildsystemDirectory[pos].RelativePathTopBinary = result; + this->Position->BuildSystemDirectory->RelativePathTopBinary = result; } else { - this->State->BuildsystemDirectory[pos].RelativePathTopBinary = ""; + this->Position->BuildSystemDirectory->RelativePathTopBinary = ""; } } cmState::Snapshot cmState::CreateBaseSnapshot() { - PositionType pos = 0; - this->SnapshotData.resize(1); - SnapshotDataType& snp = this->SnapshotData.back(); - snp.DirectoryParent = 0; - snp.SnapshotType = BuildsystemDirectoryType; - snp.BuildSystemDirectoryPosition = 0; - this->BuildsystemDirectory.resize(1); + PositionType pos = this->SnapshotData.Extend(this->SnapshotData.Root()); + pos->DirectoryParent = this->SnapshotData.Root(); + pos->SnapshotType = BuildsystemDirectoryType; + pos->BuildSystemDirectory = + this->BuildsystemDirectory.Extend(this->BuildsystemDirectory.Root()); return cmState::Snapshot(this, pos); } @@ -687,13 +676,12 @@ cmState::Snapshot cmState::CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot) { assert(originSnapshot.IsValid()); - PositionType pos = this->SnapshotData.size(); - this->SnapshotData.resize(this->SnapshotData.size() + 1); - SnapshotDataType& snp = this->SnapshotData.back(); - snp.DirectoryParent = originSnapshot.Position; - snp.SnapshotType = BuildsystemDirectoryType; - snp.BuildSystemDirectoryPosition = this->BuildsystemDirectory.size(); - this->BuildsystemDirectory.resize(this->BuildsystemDirectory.size() + 1); + PositionType pos = this->SnapshotData.Extend(originSnapshot.Position); + pos->DirectoryParent = originSnapshot.Position; + pos->SnapshotType = BuildsystemDirectoryType; + pos->BuildSystemDirectory = + this->BuildsystemDirectory.Extend( + originSnapshot.Position->BuildSystemDirectory); return cmState::Snapshot(this, pos); } @@ -706,112 +694,94 @@ cmState::Snapshot::Snapshot(cmState* state, PositionType position) const char* cmState::Snapshot::GetCurrentSourceDirectory() const { - PositionType pos = - this->State->SnapshotData[this->Position].BuildSystemDirectoryPosition; - return this->State->BuildsystemDirectory[pos].Location.c_str(); + return this->Position->BuildSystemDirectory->Location.c_str(); } void cmState::Snapshot::SetCurrentSourceDirectory(std::string const& dir) { assert(this->State); - assert(this->State->SnapshotData.size() > this->Position); - PositionType pos = - this->State->SnapshotData[this->Position].BuildSystemDirectoryPosition; - std::string& loc = this->State->BuildsystemDirectory[pos].Location; + std::string& loc = this->Position->BuildSystemDirectory->Location; loc = dir; cmSystemTools::ConvertToUnixSlashes(loc); loc = cmSystemTools::CollapseFullPath(loc); cmSystemTools::SplitPath( loc, - this->State->BuildsystemDirectory[pos].CurrentSourceDirectoryComponents); + this->Position->BuildSystemDirectory->CurrentSourceDirectoryComponents); this->ComputeRelativePathTopSource(); } const char* cmState::Snapshot::GetCurrentBinaryDirectory() const { - PositionType pos = - this->State->SnapshotData[this->Position].BuildSystemDirectoryPosition; - return this->State->BuildsystemDirectory[pos].OutputLocation.c_str(); + return this->Position->BuildSystemDirectory->OutputLocation.c_str(); } void cmState::Snapshot::SetCurrentBinaryDirectory(std::string const& dir) { - assert(this->State->SnapshotData.size() > this->Position); - PositionType pos = - this->State->SnapshotData[this->Position].BuildSystemDirectoryPosition; - std::string& loc = this->State->BuildsystemDirectory[pos].OutputLocation; + std::string& loc = this->Position->BuildSystemDirectory->OutputLocation; loc = dir; cmSystemTools::ConvertToUnixSlashes(loc); loc = cmSystemTools::CollapseFullPath(loc); cmSystemTools::SplitPath( loc, - this->State->BuildsystemDirectory[pos].CurrentBinaryDirectoryComponents); + this->Position->BuildSystemDirectory->CurrentBinaryDirectoryComponents); this->ComputeRelativePathTopBinary(); } std::vector const& cmState::Snapshot::GetCurrentSourceDirectoryComponents() { - PositionType pos = - this->State->SnapshotData[this->Position].BuildSystemDirectoryPosition; - return this->State - ->BuildsystemDirectory[pos].CurrentSourceDirectoryComponents; + return this->Position->BuildSystemDirectory + ->CurrentSourceDirectoryComponents; } std::vector const& cmState::Snapshot::GetCurrentBinaryDirectoryComponents() { - PositionType pos = - this->State->SnapshotData[this->Position].BuildSystemDirectoryPosition; - return this->State - ->BuildsystemDirectory[pos].CurrentBinaryDirectoryComponents; + return this->Position->BuildSystemDirectory + ->CurrentBinaryDirectoryComponents; } const char* cmState::Snapshot::GetRelativePathTopSource() const { - PositionType pos = - this->State->SnapshotData[this->Position].BuildSystemDirectoryPosition; - return this->State->BuildsystemDirectory[pos].RelativePathTopSource.c_str(); + return this->Position->BuildSystemDirectory->RelativePathTopSource.c_str(); } const char* cmState::Snapshot::GetRelativePathTopBinary() const { - PositionType pos = - this->State->SnapshotData[this->Position].BuildSystemDirectoryPosition; - return this->State->BuildsystemDirectory[pos].RelativePathTopBinary.c_str(); + return this->Position->BuildSystemDirectory->RelativePathTopBinary.c_str(); } void cmState::Snapshot::SetRelativePathTopSource(const char* dir) { - PositionType pos = - this->State->SnapshotData[this->Position].BuildSystemDirectoryPosition; - this->State->BuildsystemDirectory[pos].RelativePathTopSource = dir; + this->Position->BuildSystemDirectory->RelativePathTopSource = dir; } void cmState::Snapshot::SetRelativePathTopBinary(const char* dir) { - PositionType pos = - this->State->SnapshotData[this->Position].BuildSystemDirectoryPosition; - this->State->BuildsystemDirectory[pos].RelativePathTopBinary = dir; + this->Position->BuildSystemDirectory->RelativePathTopBinary = dir; } bool cmState::Snapshot::IsValid() const { - return this->State ? true : false; + return this->State && this->Position.IsValid() + ? this->Position != this->State->SnapshotData.Root() + : false; } cmState::Snapshot cmState::Snapshot::GetBuildsystemDirectoryParent() const { Snapshot snapshot; - if (!this->State || this->Position == 0) + if (!this->State || this->Position == this->State->SnapshotData.Root()) { return snapshot; } - PositionType parentPos = - this->State->SnapshotData[this->Position].DirectoryParent; - snapshot = Snapshot(this->State, parentPos); + PositionType parentPos = this->Position->DirectoryParent; + if (parentPos != this->State->SnapshotData.Root()) + { + snapshot = Snapshot(this->State, parentPos); + } return snapshot; } diff --git a/Source/cmState.h b/Source/cmState.h index 4589a72..1411e2f 100644 --- a/Source/cmState.h +++ b/Source/cmState.h @@ -15,6 +15,7 @@ #include "cmStandardIncludes.h" #include "cmPropertyDefinitionMap.h" #include "cmPropertyMap.h" +#include "cmLinkedTree.h" class cmake; class cmCommand; @@ -22,7 +23,7 @@ class cmCommand; class cmState { struct SnapshotDataType; - typedef std::vector::size_type PositionType; + typedef cmLinkedTree::iterator PositionType; friend class Snapshot; public: cmState(cmake* cm); @@ -35,7 +36,7 @@ public: class Snapshot { public: - Snapshot(cmState* state = 0, PositionType position = 0); + Snapshot(cmState* state = 0, PositionType position = PositionType()); const char* GetCurrentSourceDirectory() const; void SetCurrentSourceDirectory(std::string const& dir); @@ -166,9 +167,9 @@ private: cmake* CMakeInstance; struct BuildsystemDirectoryStateType; - std::vector BuildsystemDirectory; + cmLinkedTree BuildsystemDirectory; - std::vector SnapshotData; + cmLinkedTree SnapshotData; std::vector SourceDirectoryComponents; std::vector BinaryDirectoryComponents; -- cgit v0.12