diff options
author | John Thompson <John.Thompson.JTSoftware@gmail.com> | 2015-02-19 16:47:27 +0000 |
---|---|---|
committer | John Thompson <John.Thompson.JTSoftware@gmail.com> | 2015-02-19 16:47:27 +0000 |
commit | 8eb8d9367291c65b7f508bbc1555e7606f01b554 (patch) | |
tree | 3539d8a785f824c5a6dd57b203cac84bead6dbcc /clang-tools-extra/modularize/ModularizeUtilities.cpp | |
parent | be5680f98553854eb637d5113374cd20772ab342 (diff) | |
download | bcm5719-llvm-8eb8d9367291c65b7f508bbc1555e7606f01b554.tar.gz bcm5719-llvm-8eb8d9367291c65b7f508bbc1555e7606f01b554.zip |
Added module map coverage support, extracted from module-map-checker.
llvm-svn: 229869
Diffstat (limited to 'clang-tools-extra/modularize/ModularizeUtilities.cpp')
-rw-r--r-- | clang-tools-extra/modularize/ModularizeUtilities.cpp | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/clang-tools-extra/modularize/ModularizeUtilities.cpp b/clang-tools-extra/modularize/ModularizeUtilities.cpp index afc03d49bd5..302e2526a17 100644 --- a/clang-tools-extra/modularize/ModularizeUtilities.cpp +++ b/clang-tools-extra/modularize/ModularizeUtilities.cpp @@ -13,16 +13,17 @@ // //===----------------------------------------------------------------------===// -#include "ModularizeUtilities.h" #include "clang/Basic/SourceManager.h" #include "clang/Driver/Options.h" #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendActions.h" +#include "CoverageChecker.h" #include "llvm/ADT/SmallString.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
+#include "ModularizeUtilities.h" using namespace clang; using namespace llvm; @@ -42,6 +43,7 @@ ModularizeUtilities::ModularizeUtilities(std::vector<std::string> &InputPaths, llvm::StringRef Prefix) : InputFilePaths(InputPaths), HeaderPrefix(Prefix), + HasModuleMap(false), // Init clang stuff needed for loading the module map and preprocessing. LangOpts(new LangOptions()), DiagIDs(new DiagnosticIDs()), DiagnosticOpts(new DiagnosticOptions()), @@ -88,7 +90,34 @@ std::error_code ModularizeUtilities::loadAllHeaderListsAndDependencies() { } return std::error_code(); } - + +// Do coverage checks. +// For each loaded module map, do header coverage check. +// Starting from the directory of the module.map file, +// Find all header files, optionally looking only at files +// covered by the include path options, and compare against +// the headers referenced by the module.map file. +// Display warnings for unaccounted-for header files. +// Returns 0 if there were no errors or warnings, 1 if there +// were warnings, 2 if any other problem, such as a bad +// module map path argument was specified. +std::error_code ModularizeUtilities::doCoverageCheck( + std::vector<std::string> &IncludePaths, + llvm::ArrayRef<std::string> CommandLine) { + int ModuleMapCount = ModuleMaps.size(); + int ModuleMapIndex; + std::error_code EC; + for (ModuleMapIndex = 0; ModuleMapIndex < ModuleMapCount; ++ModuleMapIndex) { + std::unique_ptr<clang::ModuleMap> &ModMap = ModuleMaps[ModuleMapIndex]; + CoverageChecker *Checker = CoverageChecker::createCoverageChecker( + InputFilePaths[ModuleMapIndex], IncludePaths, CommandLine, ModMap.get()); + std::error_code LocalEC = Checker->doChecks(); + if (LocalEC.value() > 0) + EC = LocalEC; + } + return EC; +} + // Load single header list and dependencies. std::error_code ModularizeUtilities::loadSingleHeaderListsAndDependencies( llvm::StringRef InputPath) { @@ -209,6 +238,9 @@ std::error_code ModularizeUtilities::loadModuleMap( // Save module map. ModuleMaps.push_back(std::move(ModMap)); + // Indicate we are using module maps. + HasModuleMap = true; + return std::error_code(); } @@ -338,3 +370,16 @@ bool ModularizeUtilities::isHeader(StringRef FileName) { return true; return false; } + +// Get directory path component from file path. +// \returns the component of the given path, which will be +// relative if the given path is relative, absolute if the +// given path is absolute, or "." if the path has no leading +// path component. +std::string ModularizeUtilities::getDirectoryFromPath(StringRef Path) { + SmallString<256> Directory(Path); + sys::path::remove_filename(Directory); + if (Directory.size() == 0) + return "."; + return Directory.str(); +} |