cmDepends: Define DependencyMap instead of DependencyVector

In `cmDepends` use
`typedef std::map<std::string, std::vector<std::string>> DependencyMap`
instead of defining a
`class DependencyVector : public std::vector<std::string>`
and using it in `std::map<std::string, DependencyVector>`.

Since `std::map<std::string, std::vector<std::string>>` is used in various
other places, we now reuse all of it's auto generated methods.  This doesn't
happen when we use `DependencyVector` in a `std::map`, because it is a
different class than `std::vector<std::string>`.
This commit is contained in:
Sebastian Holtermann
2019-03-27 15:50:17 +01:00
parent 5a15c9e7cb
commit 87341d8328
8 changed files with 28 additions and 36 deletions

View File

@@ -61,7 +61,7 @@ bool cmDepends::Finalize(std::ostream& /*unused*/, std::ostream& /*unused*/)
bool cmDepends::Check(const std::string& makeFile, bool cmDepends::Check(const std::string& makeFile,
const std::string& internalFile, const std::string& internalFile,
std::map<std::string, DependencyVector>& validDeps) DependencyMap& validDeps)
{ {
// Check whether dependencies must be regenerated. // Check whether dependencies must be regenerated.
bool okay = true; bool okay = true;
@@ -101,9 +101,9 @@ bool cmDepends::WriteDependencies(const std::set<std::string>& /*unused*/,
return false; return false;
} }
bool cmDepends::CheckDependencies( bool cmDepends::CheckDependencies(std::istream& internalDepends,
std::istream& internalDepends, const std::string& internalDependsFileName, const std::string& internalDependsFileName,
std::map<std::string, DependencyVector>& validDeps) DependencyMap& validDeps)
{ {
// Read internal depends file time // Read internal depends file time
cmFileTime internalDependsTime; cmFileTime internalDependsTime;
@@ -124,7 +124,7 @@ bool cmDepends::CheckDependencies(
std::string dependee; std::string dependee;
cmFileTime dependerTime; cmFileTime dependerTime;
cmFileTime dependeeTime; cmFileTime dependeeTime;
DependencyVector* currentDependencies = nullptr; std::vector<std::string>* currentDependencies = nullptr;
while (std::getline(internalDepends, line)) { while (std::getline(internalDepends, line)) {
// Check if this an empty or a comment line // Check if this an empty or a comment line

View File

@@ -23,6 +23,9 @@ class cmLocalGenerator;
*/ */
class cmDepends class cmDepends
{ {
public:
typedef std::map<std::string, std::vector<std::string>> DependencyMap;
public: public:
/** Instances need to know the build directory name and the relative /** Instances need to know the build directory name and the relative
path from the build directory to the target file. */ path from the build directory to the target file. */
@@ -55,17 +58,13 @@ public:
/** Write dependencies for the target file. */ /** Write dependencies for the target file. */
bool Write(std::ostream& makeDepends, std::ostream& internalDepends); bool Write(std::ostream& makeDepends, std::ostream& internalDepends);
class DependencyVector : public std::vector<std::string>
{
};
/** Check dependencies for the target file. Returns true if /** Check dependencies for the target file. Returns true if
dependencies are okay and false if they must be generated. If dependencies are okay and false if they must be generated. If
they must be generated Clear has already been called to wipe out they must be generated Clear has already been called to wipe out
the old dependencies. the old dependencies.
Dependencies which are still valid will be stored in validDeps. */ Dependencies which are still valid will be stored in validDeps. */
bool Check(const std::string& makeFile, const std::string& internalFile, bool Check(const std::string& makeFile, const std::string& internalFile,
std::map<std::string, DependencyVector>& validDeps); DependencyMap& validDeps);
/** Clear dependencies for the target file so they will be regenerated. */ /** Clear dependencies for the target file so they will be regenerated. */
void Clear(const std::string& file); void Clear(const std::string& file);
@@ -84,9 +83,9 @@ protected:
// Check dependencies for the target file in the given stream. // Check dependencies for the target file in the given stream.
// Return false if dependencies must be regenerated and true // Return false if dependencies must be regenerated and true
// otherwise. // otherwise.
virtual bool CheckDependencies( virtual bool CheckDependencies(std::istream& internalDepends,
std::istream& internalDepends, const std::string& internalDependsFileName, const std::string& internalDependsFileName,
std::map<std::string, DependencyVector>& validDeps); DependencyMap& validDeps);
// Finalize the dependency information for the target. // Finalize the dependency information for the target.
virtual bool Finalize(std::ostream& makeDepends, virtual bool Finalize(std::ostream& makeDepends,

View File

@@ -21,9 +21,8 @@
cmDependsC::cmDependsC() = default; cmDependsC::cmDependsC() = default;
cmDependsC::cmDependsC( cmDependsC::cmDependsC(cmLocalGenerator* lg, const std::string& targetDir,
cmLocalGenerator* lg, const std::string& targetDir, const std::string& lang, const std::string& lang, const DependencyMap* validDeps)
const std::map<std::string, DependencyVector>* validDeps)
: cmDepends(lg, targetDir) : cmDepends(lg, targetDir)
, ValidDeps(validDeps) , ValidDeps(validDeps)
{ {
@@ -102,8 +101,7 @@ bool cmDependsC::WriteDependencies(const std::set<std::string>& sources,
this->LocalGenerator->MaybeConvertToRelativePath(binDir, obj); this->LocalGenerator->MaybeConvertToRelativePath(binDir, obj);
if (this->ValidDeps != nullptr) { if (this->ValidDeps != nullptr) {
std::map<std::string, DependencyVector>::const_iterator tmpIt = auto const tmpIt = this->ValidDeps->find(obj_i);
this->ValidDeps->find(obj_i);
if (tmpIt != this->ValidDeps->end()) { if (tmpIt != this->ValidDeps->end()) {
dependencies.insert(tmpIt->second.begin(), tmpIt->second.end()); dependencies.insert(tmpIt->second.begin(), tmpIt->second.end());
haveDeps = true; haveDeps = true;

View File

@@ -27,8 +27,7 @@ public:
relative path from the build directory to the target file. */ relative path from the build directory to the target file. */
cmDependsC(); cmDependsC();
cmDependsC(cmLocalGenerator* lg, const std::string& targetDir, cmDependsC(cmLocalGenerator* lg, const std::string& targetDir,
const std::string& lang, const std::string& lang, const DependencyMap* validDeps);
const std::map<std::string, DependencyVector>* validDeps);
/** Virtual destructor to cleanup subclasses properly. */ /** Virtual destructor to cleanup subclasses properly. */
~cmDependsC() override; ~cmDependsC() override;
@@ -81,7 +80,7 @@ public:
}; };
protected: protected:
const std::map<std::string, DependencyVector>* ValidDeps = nullptr; const DependencyMap* ValidDeps = nullptr;
std::set<std::string> Encountered; std::set<std::string> Encountered;
std::queue<UnscannedEntry> Unscanned; std::queue<UnscannedEntry> Unscanned;

View File

@@ -24,8 +24,7 @@ bool cmDependsJava::WriteDependencies(const std::set<std::string>& sources,
bool cmDependsJava::CheckDependencies( bool cmDependsJava::CheckDependencies(
std::istream& /*internalDepends*/, std::istream& /*internalDepends*/,
const std::string& /*internalDependsFileName*/, const std::string& /*internalDependsFileName*/, DependencyMap& /*validDeps*/)
std::map<std::string, DependencyVector>& /*validDeps*/)
{ {
return true; return true;
} }

View File

@@ -8,7 +8,6 @@
#include "cmDepends.h" #include "cmDepends.h"
#include <iosfwd> #include <iosfwd>
#include <map>
#include <set> #include <set>
#include <string> #include <string>
@@ -33,9 +32,9 @@ protected:
bool WriteDependencies(const std::set<std::string>& sources, bool WriteDependencies(const std::set<std::string>& sources,
const std::string& file, std::ostream& makeDepends, const std::string& file, std::ostream& makeDepends,
std::ostream& internalDepends) override; std::ostream& internalDepends) override;
bool CheckDependencies( bool CheckDependencies(std::istream& internalDepends,
std::istream& internalDepends, const std::string& internalDependsFileName, const std::string& internalDependsFileName,
std::map<std::string, DependencyVector>& validDeps) override; DependencyMap& validDeps) override;
}; };
#endif #endif

View File

@@ -1312,7 +1312,7 @@ bool cmLocalUnixMakefileGenerator3::UpdateDependencies(
// The build.make file may have explicit dependencies for the object // The build.make file may have explicit dependencies for the object
// files but these will not affect the scanning process so they need // files but these will not affect the scanning process so they need
// not be considered. // not be considered.
std::map<std::string, cmDepends::DependencyVector> validDependencies; cmDepends::DependencyMap validDependencies;
bool needRescanDependencies = false; bool needRescanDependencies = false;
if (!needRescanDirInfo) { if (!needRescanDirInfo) {
cmDependsC checker; cmDependsC checker;
@@ -1352,8 +1352,7 @@ bool cmLocalUnixMakefileGenerator3::UpdateDependencies(
bool cmLocalUnixMakefileGenerator3::ScanDependencies( bool cmLocalUnixMakefileGenerator3::ScanDependencies(
std::string const& targetDir, std::string const& dependFile, std::string const& targetDir, std::string const& dependFile,
std::string const& internalDependFile, std::string const& internalDependFile, cmDepends::DependencyMap& validDeps)
std::map<std::string, cmDepends::DependencyVector>& validDeps)
{ {
// Read the directory information file. // Read the directory information file.
cmMakefile* mf = this->Makefile; cmMakefile* mf = this->Makefile;

View File

@@ -143,8 +143,7 @@ public:
// File pairs for implicit dependency scanning. The key of the map // File pairs for implicit dependency scanning. The key of the map
// is the depender and the value is the explicit dependee. // is the depender and the value is the explicit dependee.
struct ImplicitDependFileMap struct ImplicitDependFileMap : public cmDepends::DependencyMap
: public std::map<std::string, cmDepends::DependencyVector>
{ {
}; };
struct ImplicitDependLanguageMap struct ImplicitDependLanguageMap
@@ -230,10 +229,10 @@ protected:
const char* filename = nullptr); const char* filename = nullptr);
// Helper methods for dependency updates. // Helper methods for dependency updates.
bool ScanDependencies( bool ScanDependencies(std::string const& targetDir,
std::string const& targetDir, std::string const& dependFile, std::string const& dependFile,
std::string const& internalDependFile, std::string const& internalDependFile,
std::map<std::string, cmDepends::DependencyVector>& validDeps); cmDepends::DependencyMap& validDeps);
void CheckMultipleOutputs(bool verbose); void CheckMultipleOutputs(bool verbose);
private: private: