diff --git a/clang-tools-extra/clangd/ScanningProjectModules.cpp b/clang-tools-extra/clangd/ScanningProjectModules.cpp index 6a21ad2920764..e1b6cbe1ae818 100644 --- a/clang-tools-extra/clangd/ScanningProjectModules.cpp +++ b/clang-tools-extra/clangd/ScanningProjectModules.cpp @@ -104,7 +104,7 @@ ModuleDependencyScanner::scan(PathRef FilePath, if (Mangler) Mangler(Cmd, FilePath); - using namespace clang::tooling::dependencies; + using namespace clang::tooling; llvm::SmallString<128> FilePathDir(FilePath); llvm::sys::path::remove_filename(FilePathDir); diff --git a/clang/include/clang/DependencyScanning/DependencyScanningUtils.h b/clang/include/clang/DependencyScanning/DependencyScanningUtils.h index 80b73cefc942f..124f1eaa6cbba 100644 --- a/clang/include/clang/DependencyScanning/DependencyScanningUtils.h +++ b/clang/include/clang/DependencyScanning/DependencyScanningUtils.h @@ -21,7 +21,7 @@ namespace clang { namespace dependencies { /// Graph of modular dependencies. -using ModuleDepsGraph = std::vector; +using ModuleDepsGraph = std::vector; /// The full dependencies and module graph for a specific input. struct TranslationUnitDeps { @@ -31,7 +31,7 @@ struct TranslationUnitDeps { /// The identifier of the C++20 module this translation unit exports. /// /// If the translation unit is not a module then \c ID.ModuleName is empty. - clang::dependencies::ModuleID ID; + ModuleID ID; /// A collection of absolute paths to files that this translation unit /// directly depends on, not including transitive dependencies. @@ -39,14 +39,14 @@ struct TranslationUnitDeps { /// A collection of prebuilt modules this translation unit directly depends /// on, not including transitive dependencies. - std::vector PrebuiltModuleDeps; + std::vector PrebuiltModuleDeps; /// A list of modules this translation unit directly depends on, not including /// transitive dependencies. /// /// This may include modules with a different context hash when it can be /// determined that the differences are benign for this compilation. - std::vector ClangModuleDeps; + std::vector ClangModuleDeps; /// A list of module names that are visible to this translation unit. This /// includes both direct and transitive module dependencies. @@ -61,19 +61,18 @@ struct TranslationUnitDeps { /// FIXME: If we add support for multi-arch builds in clang-scan-deps, we /// should make the dependencies between commands explicit to enable parallel /// builds of each architecture. - std::vector Commands; + std::vector Commands; /// Deprecated driver command-line. This will be removed in a future version. std::vector DriverCommandLine; }; -class FullDependencyConsumer : public clang::dependencies::DependencyConsumer { +class FullDependencyConsumer : public DependencyConsumer { public: - FullDependencyConsumer( - const llvm::DenseSet &AlreadySeen) + FullDependencyConsumer(const llvm::DenseSet &AlreadySeen) : AlreadySeen(AlreadySeen) {} - void handleBuildCommand(clang::dependencies::Command Cmd) override { + void handleBuildCommand(Command Cmd) override { Commands.push_back(std::move(Cmd)); } @@ -83,16 +82,15 @@ class FullDependencyConsumer : public clang::dependencies::DependencyConsumer { Dependencies.push_back(std::string(File)); } - void handlePrebuiltModuleDependency( - clang::dependencies::PrebuiltModuleDep PMD) override { + void handlePrebuiltModuleDependency(PrebuiltModuleDep PMD) override { PrebuiltModuleDeps.emplace_back(std::move(PMD)); } - void handleModuleDependency(clang::dependencies::ModuleDeps MD) override { + void handleModuleDependency(ModuleDeps MD) override { ClangModuleDeps[MD.ID] = std::move(MD); } - void handleDirectModuleDependency(clang::dependencies::ModuleID ID) override { + void handleDirectModuleDependency(ModuleID ID) override { DirectModuleDeps.push_back(ID); } @@ -105,8 +103,8 @@ class FullDependencyConsumer : public clang::dependencies::DependencyConsumer { } void handleProvidedAndRequiredStdCXXModules( - std::optional Provided, - std::vector Requires) override { + std::optional Provided, + std::vector Requires) override { ModuleName = Provided ? Provided->ModuleName : ""; llvm::transform(Requires, std::back_inserter(NamedModuleDeps), [](const auto &Module) { return Module.ModuleName; }); @@ -116,34 +114,29 @@ class FullDependencyConsumer : public clang::dependencies::DependencyConsumer { private: std::vector Dependencies; - std::vector PrebuiltModuleDeps; - llvm::MapVector - ClangModuleDeps; + std::vector PrebuiltModuleDeps; + llvm::MapVector ClangModuleDeps; std::string ModuleName; std::vector NamedModuleDeps; - std::vector DirectModuleDeps; + std::vector DirectModuleDeps; std::vector VisibleModules; - std::vector Commands; + std::vector Commands; std::string ContextHash; - const llvm::DenseSet &AlreadySeen; + const llvm::DenseSet &AlreadySeen; }; /// A callback to lookup module outputs for "-fmodule-file=", "-o" etc. using LookupModuleOutputCallback = - llvm::function_ref; + llvm::function_ref; /// A simple dependency action controller that uses a callback. If no callback /// is provided, it is assumed that looking up module outputs is unreachable. -class CallbackActionController - : public clang::dependencies::DependencyActionController { +class CallbackActionController : public DependencyActionController { public: virtual ~CallbackActionController(); - static std::string - lookupUnreachableModuleOutput(const clang::dependencies::ModuleDeps &MD, - clang::dependencies::ModuleOutputKind Kind) { + static std::string lookupUnreachableModuleOutput(const ModuleDeps &MD, + ModuleOutputKind Kind) { llvm::report_fatal_error("unexpected call to lookupModuleOutput"); }; @@ -154,9 +147,8 @@ class CallbackActionController } } - std::string - lookupModuleOutput(const clang::dependencies::ModuleDeps &MD, - clang::dependencies::ModuleOutputKind Kind) override { + std::string lookupModuleOutput(const ModuleDeps &MD, + ModuleOutputKind Kind) override { return LookupModuleOutput(MD, Kind); } diff --git a/clang/include/clang/Tooling/DependencyScanningTool.h b/clang/include/clang/Tooling/DependencyScanningTool.h index 0ac142a3fc673..9d9c734df6c0d 100644 --- a/clang/include/clang/Tooling/DependencyScanningTool.h +++ b/clang/include/clang/Tooling/DependencyScanningTool.h @@ -13,23 +13,19 @@ #include "clang/DependencyScanning/DependencyScanningUtils.h" #include "clang/DependencyScanning/DependencyScanningWorker.h" #include "clang/DependencyScanning/ModuleDepCollector.h" -#include "clang/Tooling/JSONCompilationDatabase.h" +#include "clang/Tooling/CompilationDatabase.h" #include "llvm/ADT/DenseSet.h" -#include "llvm/ADT/MapVector.h" -#include "llvm/ADT/STLExtras.h" -#include #include #include #include namespace clang { namespace tooling { -namespace dependencies { struct P1689Rule { std::string PrimaryOutput; - std::optional Provides; - std::vector Requires; + std::optional Provides; + std::vector Requires; }; /// The high-level implementation of the dependency discovery tool that runs on @@ -40,10 +36,9 @@ class DependencyScanningTool { /// /// @param Service The parent service. Must outlive the tool. /// @param FS The filesystem for the tool to use. Defaults to the physical FS. - DependencyScanningTool( - clang::dependencies::DependencyScanningService &Service, - llvm::IntrusiveRefCntPtr FS = - llvm::vfs::createPhysicalFileSystem()); + DependencyScanningTool(dependencies::DependencyScanningService &Service, + llvm::IntrusiveRefCntPtr FS = + llvm::vfs::createPhysicalFileSystem()); /// Print out the dependency information into a string using the dependency /// file format that is specified in the options (-MD is the default) and @@ -66,12 +61,11 @@ class DependencyScanningTool { /// \returns A \c StringError with the diagnostic output if clang errors /// occurred, P1689 dependency format rules otherwise. llvm::Expected - getP1689ModuleDependencyFile(const clang::tooling::CompileCommand &Command, - StringRef CWD, std::string &MakeformatOutput, + getP1689ModuleDependencyFile(const CompileCommand &Command, StringRef CWD, + std::string &MakeformatOutput, std::string &MakeformatOutputPath); llvm::Expected - getP1689ModuleDependencyFile(const clang::tooling::CompileCommand &Command, - StringRef CWD) { + getP1689ModuleDependencyFile(const CompileCommand &Command, StringRef CWD) { std::string MakeformatOutput; std::string MakeformatOutputPath; @@ -96,11 +90,11 @@ class DependencyScanningTool { /// /// \returns a \c StringError with the diagnostic output if clang errors /// occurred, \c TranslationUnitDeps otherwise. - llvm::Expected + llvm::Expected getTranslationUnitDependencies( const std::vector &CommandLine, StringRef CWD, - const llvm::DenseSet &AlreadySeen, - clang::dependencies::LookupModuleOutputCallback LookupModuleOutput, + const llvm::DenseSet &AlreadySeen, + dependencies::LookupModuleOutputCallback LookupModuleOutput, std::optional TUBuffer = std::nullopt); /// Given a compilation context specified via the Clang driver command-line, @@ -109,12 +103,10 @@ class DependencyScanningTool { /// TODO: this method should be removed as soon as Swift and our C-APIs adopt /// CompilerInstanceWithContext. We are keeping it here so that it is easier /// to coordinate with Swift and C-API changes. - llvm::Expected - getModuleDependencies( + llvm::Expected getModuleDependencies( StringRef ModuleName, const std::vector &CommandLine, - StringRef CWD, - const llvm::DenseSet &AlreadySeen, - clang::dependencies::LookupModuleOutputCallback LookupModuleOutput); + StringRef CWD, const llvm::DenseSet &AlreadySeen, + dependencies::LookupModuleOutputCallback LookupModuleOutput); /// The following three methods provide a new interface to perform /// by name dependency scan. The new interface's intention is to improve @@ -144,11 +136,11 @@ class DependencyScanningTool { /// arguments for dependencies. /// @return An instance of \c TranslationUnitDeps if the scan is successful. /// Otherwise it returns an error. - llvm::Expected + llvm::Expected computeDependenciesByNameWithContext( StringRef ModuleName, - const llvm::DenseSet &AlreadySeen, - clang::dependencies::LookupModuleOutputCallback LookupModuleOutput); + const llvm::DenseSet &AlreadySeen, + dependencies::LookupModuleOutputCallback LookupModuleOutput); /// @brief This method finializes the compiler instance. It finalizes the /// diagnostics and deletes the compiler instance. Call this method @@ -159,12 +151,11 @@ class DependencyScanningTool { llvm::vfs::FileSystem &getWorkerVFS() const { return Worker.getVFS(); } private: - clang::dependencies::DependencyScanningWorker Worker; - std::unique_ptr + dependencies::DependencyScanningWorker Worker; + std::unique_ptr DiagPrinterWithOS; }; -} // end namespace dependencies } // end namespace tooling } // end namespace clang diff --git a/clang/lib/Tooling/DependencyScanningTool.cpp b/clang/lib/Tooling/DependencyScanningTool.cpp index e037420f4fcf2..1c3a35d1db3a3 100644 --- a/clang/lib/Tooling/DependencyScanningTool.cpp +++ b/clang/lib/Tooling/DependencyScanningTool.cpp @@ -12,8 +12,7 @@ using namespace clang; using namespace tooling; -using namespace clang::dependencies; -using namespace clang::tooling::dependencies; +using namespace dependencies; DependencyScanningTool::DependencyScanningTool( DependencyScanningService &Service, diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp b/clang/tools/clang-scan-deps/ClangScanDeps.cpp index 6a2acb0d4f20e..07157ae2dc06a 100644 --- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp +++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp @@ -41,8 +41,7 @@ using namespace clang; using namespace tooling; -using namespace clang::dependencies; -using namespace clang::tooling::dependencies; +using namespace dependencies; namespace { diff --git a/clang/unittests/Tooling/DependencyScannerTest.cpp b/clang/unittests/Tooling/DependencyScannerTest.cpp index 9fcd0545b17fa..da47252b37097 100644 --- a/clang/unittests/Tooling/DependencyScannerTest.cpp +++ b/clang/unittests/Tooling/DependencyScannerTest.cpp @@ -29,8 +29,7 @@ using namespace clang; using namespace tooling; -using namespace clang::dependencies; -using namespace tooling::dependencies; +using namespace dependencies; namespace {