cmState: Extend Snapshot concept with a SnapshotType.

Store it together with the Parent position.
This commit is contained in:
Stephen Kelly 2015-05-23 09:54:07 +02:00
parent 91cd014d64
commit 1b323949fe
2 changed files with 27 additions and 8 deletions

View File

@ -18,6 +18,12 @@
#include <assert.h> #include <assert.h>
struct cmState::SnapshotDataType
{
cmState::PositionType DirectoryParent;
cmState::SnapshotType SnapshotType;
};
cmState::cmState(cmake* cm) cmState::cmState(cmake* cm)
: CMakeInstance(cm), : CMakeInstance(cm),
IsInTryCompile(false), IsInTryCompile(false),
@ -202,7 +208,7 @@ void cmState::Reset()
assert(this->Locations.size() > 0); assert(this->Locations.size() > 0);
assert(this->OutputLocations.size() > 0); assert(this->OutputLocations.size() > 0);
assert(this->ParentPositions.size() > 0); assert(this->SnapshotData.size() > 0);
assert(this->CurrentSourceDirectoryComponents.size() > 0); assert(this->CurrentSourceDirectoryComponents.size() > 0);
assert(this->CurrentBinaryDirectoryComponents.size() > 0); assert(this->CurrentBinaryDirectoryComponents.size() > 0);
assert(this->RelativePathTopSource.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->Locations.erase(this->Locations.begin() + 1, this->Locations.end());
this->OutputLocations.erase(this->OutputLocations.begin() + 1, this->OutputLocations.erase(this->OutputLocations.begin() + 1,
this->OutputLocations.end()); this->OutputLocations.end());
this->ParentPositions.erase(this->ParentPositions.begin() + 1, this->SnapshotData.erase(this->SnapshotData.begin() + 1,
this->ParentPositions.end()); this->SnapshotData.end());
this->CurrentSourceDirectoryComponents.erase( this->CurrentSourceDirectoryComponents.erase(
this->CurrentSourceDirectoryComponents.begin() + 1, this->CurrentSourceDirectoryComponents.begin() + 1,
this->CurrentSourceDirectoryComponents.end()); this->CurrentSourceDirectoryComponents.end());
@ -662,7 +668,10 @@ void cmState::Snapshot::ComputeRelativePathTopBinary()
cmState::Snapshot cmState::CreateBaseSnapshot() cmState::Snapshot cmState::CreateBaseSnapshot()
{ {
PositionType pos = 0; 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->Locations.resize(1);
this->OutputLocations.resize(1); this->OutputLocations.resize(1);
this->CurrentSourceDirectoryComponents.resize(1); this->CurrentSourceDirectoryComponents.resize(1);
@ -676,8 +685,11 @@ cmState::Snapshot
cmState::CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot) cmState::CreateBuildsystemDirectorySnapshot(Snapshot originSnapshot)
{ {
assert(originSnapshot.IsValid()); assert(originSnapshot.IsValid());
PositionType pos = this->ParentPositions.size(); PositionType pos = this->SnapshotData.size();
this->ParentPositions.push_back(originSnapshot.Position); 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->Locations.resize(this->Locations.size() + 1);
this->OutputLocations.resize(this->OutputLocations.size() + 1); this->OutputLocations.resize(this->OutputLocations.size() + 1);
this->CurrentSourceDirectoryComponents.resize( this->CurrentSourceDirectoryComponents.resize(
@ -782,7 +794,8 @@ cmState::Snapshot cmState::Snapshot::GetBuildsystemDirectoryParent() const
{ {
return snapshot; return snapshot;
} }
PositionType parentPos = this->State->ParentPositions[this->Position]; PositionType parentPos =
this->State->SnapshotData[this->Position].DirectoryParent;
snapshot = Snapshot(this->State, parentPos); snapshot = Snapshot(this->State, parentPos);
return snapshot; return snapshot;

View File

@ -21,12 +21,18 @@ class cmCommand;
class cmState class cmState
{ {
struct SnapshotDataType;
typedef std::vector<std::string>::size_type PositionType; typedef std::vector<std::string>::size_type PositionType;
friend class Snapshot; friend class Snapshot;
public: public:
cmState(cmake* cm); cmState(cmake* cm);
~cmState(); ~cmState();
enum SnapshotType
{
BuildsystemDirectoryType
};
class Snapshot { class Snapshot {
public: public:
Snapshot(cmState* state = 0, PositionType position = 0); Snapshot(cmState* state = 0, PositionType position = 0);
@ -160,7 +166,7 @@ private:
cmake* CMakeInstance; cmake* CMakeInstance;
std::vector<std::string> Locations; std::vector<std::string> Locations;
std::vector<std::string> OutputLocations; std::vector<std::string> OutputLocations;
std::vector<PositionType> ParentPositions; std::vector<SnapshotDataType> SnapshotData;
std::vector<std::vector<std::string> > CurrentSourceDirectoryComponents; std::vector<std::vector<std::string> > CurrentSourceDirectoryComponents;
std::vector<std::vector<std::string> > CurrentBinaryDirectoryComponents; std::vector<std::vector<std::string> > CurrentBinaryDirectoryComponents;