https://github.com/davidstone updated https://github.com/llvm/llvm-project/pull/93388
>From 0933b8e0f3161c0037516f677f1de2e72811d921 Mon Sep 17 00:00:00 2001 From: David Stone <davidfromonl...@gmail.com> Date: Sat, 25 May 2024 14:13:30 -0600 Subject: [PATCH 1/4] [clang][Modules] Move `ASTSourceDescriptor` into its own file --- .../include/clang/Basic/ASTSourceDescriptor.h | 52 +++++++++++++++++++ clang/include/clang/Basic/Module.h | 26 ---------- clang/lib/AST/ExternalASTSource.cpp | 2 +- clang/lib/Basic/ASTSourceDescriptor.cpp | 33 ++++++++++++ clang/lib/Basic/CMakeLists.txt | 1 + clang/lib/Basic/Module.cpp | 15 ------ clang/lib/CodeGen/CGDebugInfo.h | 3 +- clang/lib/Serialization/ASTReader.cpp | 1 + .../Plugins/ExpressionParser/Clang/ASTUtils.h | 8 ++- .../Clang/ClangExternalASTSourceCallbacks.cpp | 1 + .../Clang/ClangExternalASTSourceCallbacks.h | 8 ++- 11 files changed, 105 insertions(+), 45 deletions(-) create mode 100644 clang/include/clang/Basic/ASTSourceDescriptor.h create mode 100644 clang/lib/Basic/ASTSourceDescriptor.cpp diff --git a/clang/include/clang/Basic/ASTSourceDescriptor.h b/clang/include/clang/Basic/ASTSourceDescriptor.h new file mode 100644 index 0000000000000..175e0551db765 --- /dev/null +++ b/clang/include/clang/Basic/ASTSourceDescriptor.h @@ -0,0 +1,52 @@ +//===- ASTSourceDescriptor.h -----------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +/// \file +/// Defines the clang::ASTSourceDescriptor class, which abstracts clang modules +/// and precompiled header files +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_BASIC_ASTSOURCEDESCRIPTOR_H +#define LLVM_CLANG_BASIC_ASTSOURCEDESCRIPTOR_H + +#include "clang/Basic/Module.h" +#include "llvm/ADT/StringRef.h" +#include <string> +#include <utility> + +namespace clang { + +/// Abstracts clang modules and precompiled header files and holds +/// everything needed to generate debug info for an imported module +/// or PCH. +class ASTSourceDescriptor { + StringRef PCHModuleName; + StringRef Path; + StringRef ASTFile; + ASTFileSignature Signature; + Module *ClangModule = nullptr; + +public: + ASTSourceDescriptor() = default; + ASTSourceDescriptor(StringRef Name, StringRef Path, StringRef ASTFile, + ASTFileSignature Signature) + : PCHModuleName(std::move(Name)), Path(std::move(Path)), + ASTFile(std::move(ASTFile)), Signature(Signature) {} + ASTSourceDescriptor(Module &M); + + std::string getModuleName() const; + StringRef getPath() const { return Path; } + StringRef getASTFile() const { return ASTFile; } + ASTFileSignature getSignature() const { return Signature; } + Module *getModuleOrNull() const { return ClangModule; } +}; + +} // namespace clang + +#endif // LLVM_CLANG_BASIC_ASTSOURCEDESCRIPTOR_H diff --git a/clang/include/clang/Basic/Module.h b/clang/include/clang/Basic/Module.h index 2d62d05cd9190..e86f4303d732b 100644 --- a/clang/include/clang/Basic/Module.h +++ b/clang/include/clang/Basic/Module.h @@ -868,32 +868,6 @@ class VisibleModuleSet { unsigned Generation = 0; }; -/// Abstracts clang modules and precompiled header files and holds -/// everything needed to generate debug info for an imported module -/// or PCH. -class ASTSourceDescriptor { - StringRef PCHModuleName; - StringRef Path; - StringRef ASTFile; - ASTFileSignature Signature; - Module *ClangModule = nullptr; - -public: - ASTSourceDescriptor() = default; - ASTSourceDescriptor(StringRef Name, StringRef Path, StringRef ASTFile, - ASTFileSignature Signature) - : PCHModuleName(std::move(Name)), Path(std::move(Path)), - ASTFile(std::move(ASTFile)), Signature(Signature) {} - ASTSourceDescriptor(Module &M); - - std::string getModuleName() const; - StringRef getPath() const { return Path; } - StringRef getASTFile() const { return ASTFile; } - ASTFileSignature getSignature() const { return Signature; } - Module *getModuleOrNull() const { return ClangModule; } -}; - - } // namespace clang #endif // LLVM_CLANG_BASIC_MODULE_H diff --git a/clang/lib/AST/ExternalASTSource.cpp b/clang/lib/AST/ExternalASTSource.cpp index e96a474968511..a5b6f80bde694 100644 --- a/clang/lib/AST/ExternalASTSource.cpp +++ b/clang/lib/AST/ExternalASTSource.cpp @@ -15,10 +15,10 @@ #include "clang/AST/ExternalASTSource.h" #include "clang/AST/ASTContext.h" #include "clang/AST/DeclarationName.h" +#include "clang/Basic/ASTSourceDescriptor.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LLVM.h" -#include "clang/Basic/Module.h" #include "clang/Basic/SourceManager.h" #include "llvm/Support/ErrorHandling.h" #include <cstdint> diff --git a/clang/lib/Basic/ASTSourceDescriptor.cpp b/clang/lib/Basic/ASTSourceDescriptor.cpp new file mode 100644 index 0000000000000..8072c08a51d3a --- /dev/null +++ b/clang/lib/Basic/ASTSourceDescriptor.cpp @@ -0,0 +1,33 @@ +//===- ASTSourceDescriptor.cpp -------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +/// Defines the clang::ASTSourceDescriptor class, which abstracts clang modules +/// and precompiled header files +// +//===----------------------------------------------------------------------===// + +#include "clang/Basic/ASTSourceDescriptor.h" + +namespace clang { + +ASTSourceDescriptor::ASTSourceDescriptor(Module &M) + : Signature(M.Signature), ClangModule(&M) { + if (M.Directory) + Path = M.Directory->getName(); + if (auto File = M.getASTFile()) + ASTFile = File->getName(); +} + +std::string ASTSourceDescriptor::getModuleName() const { + if (ClangModule) + return ClangModule->Name; + else + return std::string(PCHModuleName); +} + +} // namespace clang diff --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt index 824d4a0e2eee5..f30680552e0f5 100644 --- a/clang/lib/Basic/CMakeLists.txt +++ b/clang/lib/Basic/CMakeLists.txt @@ -55,6 +55,7 @@ if(CLANG_VENDOR) endif() add_clang_library(clangBasic + ASTSourceDescriptor.cpp Attributes.cpp Builtins.cpp CLWarnings.cpp diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp index 045ef580f9c33..90b7b0d24bb6a 100644 --- a/clang/lib/Basic/Module.cpp +++ b/clang/lib/Basic/Module.cpp @@ -724,18 +724,3 @@ void VisibleModuleSet::setVisible(Module *M, SourceLocation Loc, }; VisitModule({M, nullptr}); } - -ASTSourceDescriptor::ASTSourceDescriptor(Module &M) - : Signature(M.Signature), ClangModule(&M) { - if (M.Directory) - Path = M.Directory->getName(); - if (auto File = M.getASTFile()) - ASTFile = File->getName(); -} - -std::string ASTSourceDescriptor::getModuleName() const { - if (ClangModule) - return ClangModule->Name; - else - return std::string(PCHModuleName); -} diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index d6db4d711366a..8fe738be21568 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -20,8 +20,8 @@ #include "clang/AST/PrettyPrinter.h" #include "clang/AST/Type.h" #include "clang/AST/TypeOrdering.h" +#include "clang/Basic/ASTSourceDescriptor.h" #include "clang/Basic/CodeGenOptions.h" -#include "clang/Basic/Module.h" #include "clang/Basic/SourceLocation.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseSet.h" @@ -38,6 +38,7 @@ class MDNode; namespace clang { class ClassTemplateSpecializationDecl; class GlobalDecl; +class Module; class ModuleMap; class ObjCInterfaceDecl; class UsingDecl; diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index d7fc6697eaf74..389ac4ed76240 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -40,6 +40,7 @@ #include "clang/AST/TypeLoc.h" #include "clang/AST/TypeLocVisitor.h" #include "clang/AST/UnresolvedSet.h" +#include "clang/Basic/ASTSourceDescriptor.h" #include "clang/Basic/CommentOptions.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/DiagnosticError.h" diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.h b/lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.h index 17f1506036c69..da2b1a15f7461 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.h @@ -9,13 +9,19 @@ #ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_ASTUTILS_H #define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_ASTUTILS_H -#include "clang/Basic/Module.h" +#include "clang/Basic/ASTSourceDescriptor.h" #include "clang/Sema/Lookup.h" #include "clang/Sema/MultiplexExternalSemaSource.h" #include "clang/Sema/Sema.h" #include "clang/Sema/SemaConsumer.h" #include <optional> +namespace clang { + +class Module; + +} // namespace clang + namespace lldb_private { /// Wraps an ExternalASTSource into an ExternalSemaSource. Doesn't take diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.cpp index 89d9ac042e57a..e746e6afe39be 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.cpp @@ -11,6 +11,7 @@ #include "clang/AST/Decl.h" #include "clang/AST/DeclObjC.h" +#include "clang/Basic/Module.h" #include <optional> using namespace lldb_private; diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h index 219ed641615eb..6bd18186a567d 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h @@ -10,9 +10,15 @@ #define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGEXTERNALASTSOURCECALLBACKS_H #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/ASTSourceDescriptor.h" #include <optional> +namespace clang { + +class Module; + +} // namespace clang + namespace lldb_private { class ClangExternalASTSourceCallbacks : public clang::ExternalASTSource { >From 9be7409d8d246a24432faf7d5c238d6c0e1763d9 Mon Sep 17 00:00:00 2001 From: David Stone <davidfromonl...@gmail.com> Date: Sat, 25 May 2024 15:17:41 -0600 Subject: [PATCH 2/4] Add `clang/include/clang/Basic/Module` and `clang/lib/Basic/Module` directories. Move `Module.h` / `Module.cpp` and `ASTSourceDescriptor.h` / `ASTSourceDescriptor.cpp` into them. --- .github/new-prs-labeler.yml | 2 +- .../clangd/unittests/ReplayPeambleTests.cpp | 2 +- clang/docs/Modules.rst | 2 +- .../include/clang/APINotes/APINotesManager.h | 2 +- .../include/clang/Basic/ASTSourceDescriptor.h | 2 +- .../clang/Basic/Module/ASTSourceDescriptor.h | 52 ++ .../include/clang/Basic/{ => Module}/Module.h | 0 .../clang/ExtractAPI/ExtractAPIVisitor.h | 2 +- .../Serialization/SymbolGraphSerializer.h | 2 +- clang/include/clang/Lex/ModuleLoader.h | 2 +- clang/include/clang/Lex/ModuleMap.h | 2 +- clang/include/clang/Lex/Preprocessor.h | 2 +- clang/include/clang/Sema/Sema.h | 2 +- clang/include/clang/Serialization/ASTWriter.h | 2 +- .../include/clang/Serialization/ModuleFile.h | 2 +- .../clang/Serialization/ModuleManager.h | 2 +- .../Serialization/PCHContainerOperations.h | 2 +- clang/lib/AST/ASTContext.cpp | 2 +- clang/lib/AST/ASTDumper.cpp | 2 +- clang/lib/AST/Decl.cpp | 2 +- clang/lib/AST/DeclBase.cpp | 2 +- clang/lib/AST/DeclPrinter.cpp | 2 +- clang/lib/AST/ExternalASTSource.cpp | 2 +- clang/lib/AST/ItaniumMangle.cpp | 2 +- clang/lib/AST/ODRDiagsEmitter.cpp | 2 +- clang/lib/AST/TextNodeDumper.cpp | 2 +- clang/lib/Basic/CMakeLists.txt | 14 +- clang/lib/Basic/Module.cpp | 2 +- .../{ => Module}/ASTSourceDescriptor.cpp | 2 +- clang/lib/Basic/Module/Module.cpp | 726 ++++++++++++++++++ clang/lib/CodeGen/CGDebugInfo.h | 2 +- clang/lib/CodeGen/CodeGenModule.cpp | 2 +- clang/lib/CodeGen/CodeGenModule.h | 2 +- clang/lib/ExtractAPI/API.cpp | 2 +- .../TypedefUnderlyingTypeResolver.cpp | 2 +- clang/lib/Frontend/ASTUnit.cpp | 2 +- clang/lib/Frontend/FrontendActions.cpp | 2 +- clang/lib/Lex/HeaderSearch.cpp | 2 +- clang/lib/Lex/ModuleMap.cpp | 2 +- clang/lib/Lex/PPDirectives.cpp | 2 +- clang/lib/Lex/Pragma.cpp | 2 +- clang/lib/Lex/Preprocessor.cpp | 2 +- clang/lib/Serialization/ASTReader.cpp | 4 +- clang/lib/Serialization/ASTReaderDecl.cpp | 2 +- clang/lib/Serialization/ASTWriter.cpp | 2 +- .../header_exportable_declarations.cpp | 2 +- .../Plugins/ExpressionParser/Clang/ASTUtils.h | 2 +- .../Clang/ClangExternalASTSourceCallbacks.cpp | 2 +- .../Clang/ClangExternalASTSourceCallbacks.h | 2 +- 49 files changed, 831 insertions(+), 53 deletions(-) create mode 100644 clang/include/clang/Basic/Module/ASTSourceDescriptor.h rename clang/include/clang/Basic/{ => Module}/Module.h (100%) rename clang/lib/Basic/{ => Module}/ASTSourceDescriptor.cpp (94%) create mode 100644 clang/lib/Basic/Module/Module.cpp diff --git a/.github/new-prs-labeler.yml b/.github/new-prs-labeler.yml index a57ba28faf160..41325b2ff2e24 100644 --- a/.github/new-prs-labeler.yml +++ b/.github/new-prs-labeler.yml @@ -345,7 +345,7 @@ clang:modules: - clang/include/clang/AST/PropertiesBase.td - clang/include/clang/AST/ODRHash.h - clang/include/clang/AST/TypeProperties.td - - clang/include/clang/Basic/Module.h + - clang/include/clang/Basic/Module/** - clang/include/clang/Frontend/PrecompiledPreamble.h - clang/include/clang/Lex/ModuleLoader.h - clang/include/clang/Lex/ModuleMap.h diff --git a/clang-tools-extra/clangd/unittests/ReplayPeambleTests.cpp b/clang-tools-extra/clangd/unittests/ReplayPeambleTests.cpp index 147d9abe69137..c650f9b8440c2 100644 --- a/clang-tools-extra/clangd/unittests/ReplayPeambleTests.cpp +++ b/clang-tools-extra/clangd/unittests/ReplayPeambleTests.cpp @@ -25,7 +25,7 @@ #include "clang/AST/DeclTemplate.h" #include "clang/Basic/FileEntry.h" #include "clang/Basic/LLVM.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/TokenKinds.h" diff --git a/clang/docs/Modules.rst b/clang/docs/Modules.rst index 06294e3c58a4f..79c87250ad0d5 100644 --- a/clang/docs/Modules.rst +++ b/clang/docs/Modules.rst @@ -1126,7 +1126,7 @@ The Clang source code provides additional information about modules: ``clang/test/Modules/`` Tests specifically related to modules functionality. -``clang/include/clang/Basic/Module.h`` +``clang/include/clang/Basic/Module/Module.h`` The ``Module`` class in this header describes a module, and is used throughout the compiler to implement modules. ``clang/include/clang/Lex/ModuleMap.h`` diff --git a/clang/include/clang/APINotes/APINotesManager.h b/clang/include/clang/APINotes/APINotesManager.h index 18375c9e51a17..d9a133941f6b4 100644 --- a/clang/include/clang/APINotes/APINotesManager.h +++ b/clang/include/clang/APINotes/APINotesManager.h @@ -9,7 +9,7 @@ #ifndef LLVM_CLANG_APINOTES_APINOTESMANAGER_H #define LLVM_CLANG_APINOTES_APINOTESMANAGER_H -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/SourceLocation.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" diff --git a/clang/include/clang/Basic/ASTSourceDescriptor.h b/clang/include/clang/Basic/ASTSourceDescriptor.h index 175e0551db765..32fc9d4856cbe 100644 --- a/clang/include/clang/Basic/ASTSourceDescriptor.h +++ b/clang/include/clang/Basic/ASTSourceDescriptor.h @@ -15,7 +15,7 @@ #ifndef LLVM_CLANG_BASIC_ASTSOURCEDESCRIPTOR_H #define LLVM_CLANG_BASIC_ASTSOURCEDESCRIPTOR_H -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "llvm/ADT/StringRef.h" #include <string> #include <utility> diff --git a/clang/include/clang/Basic/Module/ASTSourceDescriptor.h b/clang/include/clang/Basic/Module/ASTSourceDescriptor.h new file mode 100644 index 0000000000000..32fc9d4856cbe --- /dev/null +++ b/clang/include/clang/Basic/Module/ASTSourceDescriptor.h @@ -0,0 +1,52 @@ +//===- ASTSourceDescriptor.h -----------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +/// \file +/// Defines the clang::ASTSourceDescriptor class, which abstracts clang modules +/// and precompiled header files +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_BASIC_ASTSOURCEDESCRIPTOR_H +#define LLVM_CLANG_BASIC_ASTSOURCEDESCRIPTOR_H + +#include "clang/Basic/Module/Module.h" +#include "llvm/ADT/StringRef.h" +#include <string> +#include <utility> + +namespace clang { + +/// Abstracts clang modules and precompiled header files and holds +/// everything needed to generate debug info for an imported module +/// or PCH. +class ASTSourceDescriptor { + StringRef PCHModuleName; + StringRef Path; + StringRef ASTFile; + ASTFileSignature Signature; + Module *ClangModule = nullptr; + +public: + ASTSourceDescriptor() = default; + ASTSourceDescriptor(StringRef Name, StringRef Path, StringRef ASTFile, + ASTFileSignature Signature) + : PCHModuleName(std::move(Name)), Path(std::move(Path)), + ASTFile(std::move(ASTFile)), Signature(Signature) {} + ASTSourceDescriptor(Module &M); + + std::string getModuleName() const; + StringRef getPath() const { return Path; } + StringRef getASTFile() const { return ASTFile; } + ASTFileSignature getSignature() const { return Signature; } + Module *getModuleOrNull() const { return ClangModule; } +}; + +} // namespace clang + +#endif // LLVM_CLANG_BASIC_ASTSOURCEDESCRIPTOR_H diff --git a/clang/include/clang/Basic/Module.h b/clang/include/clang/Basic/Module/Module.h similarity index 100% rename from clang/include/clang/Basic/Module.h rename to clang/include/clang/Basic/Module/Module.h diff --git a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h index 8ccebe457ed53..e1fe750328bec 100644 --- a/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h +++ b/clang/include/clang/ExtractAPI/ExtractAPIVisitor.h @@ -21,7 +21,7 @@ #include "clang/AST/DeclTemplate.h" #include "clang/AST/ParentMapContext.h" #include "clang/AST/RecursiveASTVisitor.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/Specifiers.h" #include "clang/ExtractAPI/API.h" diff --git a/clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h b/clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h index 27e9167ca1ad0..6560556a7d422 100644 --- a/clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h +++ b/clang/include/clang/ExtractAPI/Serialization/SymbolGraphSerializer.h @@ -17,7 +17,7 @@ #ifndef LLVM_CLANG_EXTRACTAPI_SERIALIZATION_SYMBOLGRAPHSERIALIZER_H #define LLVM_CLANG_EXTRACTAPI_SERIALIZATION_SYMBOLGRAPHSERIALIZER_H -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/ExtractAPI/API.h" #include "clang/ExtractAPI/APIIgnoresList.h" #include "clang/ExtractAPI/Serialization/APISetVisitor.h" diff --git a/clang/include/clang/Lex/ModuleLoader.h b/clang/include/clang/Lex/ModuleLoader.h index f880a9091a2ed..43318571ef822 100644 --- a/clang/include/clang/Lex/ModuleLoader.h +++ b/clang/include/clang/Lex/ModuleLoader.h @@ -15,7 +15,7 @@ #define LLVM_CLANG_LEX_MODULELOADER_H #include "clang/Basic/LLVM.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/SourceLocation.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/PointerIntPair.h" diff --git a/clang/include/clang/Lex/ModuleMap.h b/clang/include/clang/Lex/ModuleMap.h index 2e28ff6823cb2..1a1f246b76155 100644 --- a/clang/include/clang/Lex/ModuleMap.h +++ b/clang/include/clang/Lex/ModuleMap.h @@ -16,7 +16,7 @@ #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LangOptions.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/SourceLocation.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index c0850a8fa9f7f..986ea0ba8c3c4 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -19,7 +19,7 @@ #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/LangOptions.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/TokenKinds.h" diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 5247379181808..dd01197c8fafa 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -40,7 +40,7 @@ #include "clang/Basic/DarwinSDKInfo.h" #include "clang/Basic/ExpressionTraits.h" #include "clang/Basic/IdentifierTable.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/OpenCLOptions.h" #include "clang/Basic/PragmaKinds.h" #include "clang/Basic/Specifiers.h" diff --git a/clang/include/clang/Serialization/ASTWriter.h b/clang/include/clang/Serialization/ASTWriter.h index 88192e439a3f0..08b4340d8a47b 100644 --- a/clang/include/clang/Serialization/ASTWriter.h +++ b/clang/include/clang/Serialization/ASTWriter.h @@ -18,7 +18,7 @@ #include "clang/AST/Decl.h" #include "clang/AST/Type.h" #include "clang/Basic/LLVM.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/SourceLocation.h" #include "clang/Sema/Sema.h" #include "clang/Sema/SemaConsumer.h" diff --git a/clang/include/clang/Serialization/ModuleFile.h b/clang/include/clang/Serialization/ModuleFile.h index 7d8cbe3d40f56..e395397158a3b 100644 --- a/clang/include/clang/Serialization/ModuleFile.h +++ b/clang/include/clang/Serialization/ModuleFile.h @@ -15,7 +15,7 @@ #define LLVM_CLANG_SERIALIZATION_MODULEFILE_H #include "clang/Basic/FileManager.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/SourceLocation.h" #include "clang/Serialization/ASTBitCodes.h" #include "clang/Serialization/ContinuousRangeMap.h" diff --git a/clang/include/clang/Serialization/ModuleManager.h b/clang/include/clang/Serialization/ModuleManager.h index 3bd379acf7eda..eed803aa40d07 100644 --- a/clang/include/clang/Serialization/ModuleManager.h +++ b/clang/include/clang/Serialization/ModuleManager.h @@ -15,7 +15,7 @@ #define LLVM_CLANG_SERIALIZATION_MODULEMANAGER_H #include "clang/Basic/LLVM.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/SourceLocation.h" #include "clang/Serialization/ModuleFile.h" #include "llvm/ADT/DenseMap.h" diff --git a/clang/include/clang/Serialization/PCHContainerOperations.h b/clang/include/clang/Serialization/PCHContainerOperations.h index c9a7e334ce6eb..26d45fea66e2e 100644 --- a/clang/include/clang/Serialization/PCHContainerOperations.h +++ b/clang/include/clang/Serialization/PCHContainerOperations.h @@ -9,7 +9,7 @@ #ifndef LLVM_CLANG_SERIALIZATION_PCHCONTAINEROPERATIONS_H #define LLVM_CLANG_SERIALIZATION_PCHCONTAINEROPERATIONS_H -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringMap.h" #include "llvm/Support/MemoryBufferRef.h" diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index a2398fef623ea..98675bd206946 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -56,7 +56,7 @@ #include "clang/Basic/LLVM.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/Linkage.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/NoSanitizeList.h" #include "clang/Basic/ObjCRuntime.h" #include "clang/Basic/ProfileList.h" diff --git a/clang/lib/AST/ASTDumper.cpp b/clang/lib/AST/ASTDumper.cpp index 6efc5bb92e28d..203c48a9dc3d1 100644 --- a/clang/lib/AST/ASTDumper.cpp +++ b/clang/lib/AST/ASTDumper.cpp @@ -17,7 +17,7 @@ #include "clang/AST/DeclLookups.h" #include "clang/AST/JSONNodeDumper.h" #include "clang/Basic/Builtins.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/SourceManager.h" #include "llvm/Support/raw_ostream.h" diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 41fbfe281ef65..fe01d2606e4dc 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -42,7 +42,7 @@ #include "clang/Basic/LLVM.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/Linkage.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/NoSanitizeList.h" #include "clang/Basic/PartialDiagnostic.h" #include "clang/Basic/Sanitizers.h" diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index 65d5eeb6354eb..a70f59f414212 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -29,7 +29,7 @@ #include "clang/AST/Type.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LLVM.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/ObjCRuntime.h" #include "clang/Basic/PartialDiagnostic.h" #include "clang/Basic/SourceLocation.h" diff --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp index 0cf4e64f83b8d..c07936ea2d3e9 100644 --- a/clang/lib/AST/DeclPrinter.cpp +++ b/clang/lib/AST/DeclPrinter.cpp @@ -20,7 +20,7 @@ #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" #include "clang/AST/PrettyPrinter.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/SourceManager.h" #include "llvm/Support/raw_ostream.h" using namespace clang; diff --git a/clang/lib/AST/ExternalASTSource.cpp b/clang/lib/AST/ExternalASTSource.cpp index a5b6f80bde694..fb16f41ced520 100644 --- a/clang/lib/AST/ExternalASTSource.cpp +++ b/clang/lib/AST/ExternalASTSource.cpp @@ -15,7 +15,7 @@ #include "clang/AST/ExternalASTSource.h" #include "clang/AST/ASTContext.h" #include "clang/AST/DeclarationName.h" -#include "clang/Basic/ASTSourceDescriptor.h" +#include "clang/Basic/Module/ASTSourceDescriptor.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LLVM.h" diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp index ed9e6eeb36c75..4d010b70cd8b4 100644 --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -29,7 +29,7 @@ #include "clang/AST/TypeLoc.h" #include "clang/Basic/ABI.h" #include "clang/Basic/DiagnosticAST.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/Thunk.h" diff --git a/clang/lib/AST/ODRDiagsEmitter.cpp b/clang/lib/AST/ODRDiagsEmitter.cpp index 37f0f68c92355..d262dd87cfff2 100644 --- a/clang/lib/AST/ODRDiagsEmitter.cpp +++ b/clang/lib/AST/ODRDiagsEmitter.cpp @@ -11,7 +11,7 @@ #include "clang/AST/DeclTemplate.h" #include "clang/AST/ODRHash.h" #include "clang/Basic/DiagnosticAST.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" using namespace clang; diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp index 4a1e94ffe283b..5299ebbfbfb42 100644 --- a/clang/lib/AST/TextNodeDumper.cpp +++ b/clang/lib/AST/TextNodeDumper.cpp @@ -19,7 +19,7 @@ #include "clang/AST/NestedNameSpecifier.h" #include "clang/AST/Type.h" #include "clang/AST/TypeLocVisitor.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/Specifiers.h" #include "clang/Basic/TypeTraits.h" diff --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt index f30680552e0f5..fae3ef13b8796 100644 --- a/clang/lib/Basic/CMakeLists.txt +++ b/clang/lib/Basic/CMakeLists.txt @@ -55,12 +55,11 @@ if(CLANG_VENDOR) endif() add_clang_library(clangBasic - ASTSourceDescriptor.cpp - Attributes.cpp - Builtins.cpp - CLWarnings.cpp - CharInfo.cpp - CodeGenOptions.cpp +Attributes.cpp +Builtins.cpp +CLWarnings.cpp +CharInfo.cpp +CodeGenOptions.cpp Cuda.cpp DarwinSDKInfo.cpp Diagnostic.cpp @@ -74,7 +73,8 @@ add_clang_library(clangBasic LangOptions.cpp LangStandards.cpp MakeSupport.cpp - Module.cpp + Module/ASTSourceDescriptor.cpp + Module/Module.cpp ObjCRuntime.cpp OpenCLOptions.cpp OpenMPKinds.cpp diff --git a/clang/lib/Basic/Module.cpp b/clang/lib/Basic/Module.cpp index 90b7b0d24bb6a..581509b888a5b 100644 --- a/clang/lib/Basic/Module.cpp +++ b/clang/lib/Basic/Module.cpp @@ -11,7 +11,7 @@ // //===----------------------------------------------------------------------===// -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/CharInfo.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/LangOptions.h" diff --git a/clang/lib/Basic/ASTSourceDescriptor.cpp b/clang/lib/Basic/Module/ASTSourceDescriptor.cpp similarity index 94% rename from clang/lib/Basic/ASTSourceDescriptor.cpp rename to clang/lib/Basic/Module/ASTSourceDescriptor.cpp index 8072c08a51d3a..b27cd45b4cb74 100644 --- a/clang/lib/Basic/ASTSourceDescriptor.cpp +++ b/clang/lib/Basic/Module/ASTSourceDescriptor.cpp @@ -11,7 +11,7 @@ // //===----------------------------------------------------------------------===// -#include "clang/Basic/ASTSourceDescriptor.h" +#include "clang/Basic/Module/ASTSourceDescriptor.h" namespace clang { diff --git a/clang/lib/Basic/Module/Module.cpp b/clang/lib/Basic/Module/Module.cpp new file mode 100644 index 0000000000000..581509b888a5b --- /dev/null +++ b/clang/lib/Basic/Module/Module.cpp @@ -0,0 +1,726 @@ +//===- Module.cpp - Describe a module -------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file defines the Module class, which describes a module in the source +// code. +// +//===----------------------------------------------------------------------===// + +#include "clang/Basic/Module/Module.h" +#include "clang/Basic/CharInfo.h" +#include "clang/Basic/FileManager.h" +#include "clang/Basic/LangOptions.h" +#include "clang/Basic/SourceLocation.h" +#include "clang/Basic/TargetInfo.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringMap.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/StringSwitch.h" +#include "llvm/Support/Compiler.h" +#include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/raw_ostream.h" +#include <algorithm> +#include <cassert> +#include <functional> +#include <string> +#include <utility> +#include <vector> + +using namespace clang; + +Module::Module(StringRef Name, SourceLocation DefinitionLoc, Module *Parent, + bool IsFramework, bool IsExplicit, unsigned VisibilityID) + : Name(Name), DefinitionLoc(DefinitionLoc), Parent(Parent), + VisibilityID(VisibilityID), IsUnimportable(false), + HasIncompatibleModuleFile(false), IsAvailable(true), + IsFromModuleFile(false), IsFramework(IsFramework), IsExplicit(IsExplicit), + IsSystem(false), IsExternC(false), IsInferred(false), + InferSubmodules(false), InferExplicitSubmodules(false), + InferExportWildcard(false), ConfigMacrosExhaustive(false), + NoUndeclaredIncludes(false), ModuleMapIsPrivate(false), + NamedModuleHasInit(true), NameVisibility(Hidden) { + if (Parent) { + IsAvailable = Parent->isAvailable(); + IsUnimportable = Parent->isUnimportable(); + IsSystem = Parent->IsSystem; + IsExternC = Parent->IsExternC; + NoUndeclaredIncludes = Parent->NoUndeclaredIncludes; + ModuleMapIsPrivate = Parent->ModuleMapIsPrivate; + + Parent->SubModuleIndex[Name] = Parent->SubModules.size(); + Parent->SubModules.push_back(this); + } +} + +Module::~Module() { + for (auto *Submodule : SubModules) { + delete Submodule; + } +} + +static bool isPlatformEnvironment(const TargetInfo &Target, StringRef Feature) { + StringRef Platform = Target.getPlatformName(); + StringRef Env = Target.getTriple().getEnvironmentName(); + + // Attempt to match platform and environment. + if (Platform == Feature || Target.getTriple().getOSName() == Feature || + Env == Feature) + return true; + + auto CmpPlatformEnv = [](StringRef LHS, StringRef RHS) { + auto Pos = LHS.find('-'); + if (Pos == StringRef::npos) + return false; + SmallString<128> NewLHS = LHS.slice(0, Pos); + NewLHS += LHS.slice(Pos+1, LHS.size()); + return NewLHS == RHS; + }; + + SmallString<128> PlatformEnv = Target.getTriple().getOSAndEnvironmentName(); + // Darwin has different but equivalent variants for simulators, example: + // 1. x86_64-apple-ios-simulator + // 2. x86_64-apple-iossimulator + // where both are valid examples of the same platform+environment but in the + // variant (2) the simulator is hardcoded as part of the platform name. Both + // forms above should match for "iossimulator" requirement. + if (Target.getTriple().isOSDarwin() && PlatformEnv.ends_with("simulator")) + return PlatformEnv == Feature || CmpPlatformEnv(PlatformEnv, Feature); + + return PlatformEnv == Feature; +} + +/// Determine whether a translation unit built using the current +/// language options has the given feature. +static bool hasFeature(StringRef Feature, const LangOptions &LangOpts, + const TargetInfo &Target) { + bool HasFeature = llvm::StringSwitch<bool>(Feature) + .Case("altivec", LangOpts.AltiVec) + .Case("blocks", LangOpts.Blocks) + .Case("coroutines", LangOpts.Coroutines) + .Case("cplusplus", LangOpts.CPlusPlus) + .Case("cplusplus11", LangOpts.CPlusPlus11) + .Case("cplusplus14", LangOpts.CPlusPlus14) + .Case("cplusplus17", LangOpts.CPlusPlus17) + .Case("cplusplus20", LangOpts.CPlusPlus20) + .Case("cplusplus23", LangOpts.CPlusPlus23) + .Case("cplusplus26", LangOpts.CPlusPlus26) + .Case("c99", LangOpts.C99) + .Case("c11", LangOpts.C11) + .Case("c17", LangOpts.C17) + .Case("c23", LangOpts.C23) + .Case("freestanding", LangOpts.Freestanding) + .Case("gnuinlineasm", LangOpts.GNUAsm) + .Case("objc", LangOpts.ObjC) + .Case("objc_arc", LangOpts.ObjCAutoRefCount) + .Case("opencl", LangOpts.OpenCL) + .Case("tls", Target.isTLSSupported()) + .Case("zvector", LangOpts.ZVector) + .Default(Target.hasFeature(Feature) || + isPlatformEnvironment(Target, Feature)); + if (!HasFeature) + HasFeature = llvm::is_contained(LangOpts.ModuleFeatures, Feature); + return HasFeature; +} + +bool Module::isUnimportable(const LangOptions &LangOpts, + const TargetInfo &Target, Requirement &Req, + Module *&ShadowingModule) const { + if (!IsUnimportable) + return false; + + for (const Module *Current = this; Current; Current = Current->Parent) { + if (Current->ShadowingModule) { + ShadowingModule = Current->ShadowingModule; + return true; + } + for (unsigned I = 0, N = Current->Requirements.size(); I != N; ++I) { + if (hasFeature(Current->Requirements[I].FeatureName, LangOpts, Target) != + Current->Requirements[I].RequiredState) { + Req = Current->Requirements[I]; + return true; + } + } + } + + llvm_unreachable("could not find a reason why module is unimportable"); +} + +// The -fmodule-name option tells the compiler to textually include headers in +// the specified module, meaning Clang won't build the specified module. This +// is useful in a number of situations, for instance, when building a library +// that vends a module map, one might want to avoid hitting intermediate build +// products containing the module map or avoid finding the system installed +// modulemap for that library. +bool Module::isForBuilding(const LangOptions &LangOpts) const { + StringRef TopLevelName = getTopLevelModuleName(); + StringRef CurrentModule = LangOpts.CurrentModule; + + // When building the implementation of framework Foo, we want to make sure + // that Foo *and* Foo_Private are textually included and no modules are built + // for either. + if (!LangOpts.isCompilingModule() && getTopLevelModule()->IsFramework && + CurrentModule == LangOpts.ModuleName && + !CurrentModule.ends_with("_Private") && + TopLevelName.ends_with("_Private")) + TopLevelName = TopLevelName.drop_back(8); + + return TopLevelName == CurrentModule; +} + +bool Module::isAvailable(const LangOptions &LangOpts, const TargetInfo &Target, + Requirement &Req, + UnresolvedHeaderDirective &MissingHeader, + Module *&ShadowingModule) const { + if (IsAvailable) + return true; + + if (isUnimportable(LangOpts, Target, Req, ShadowingModule)) + return false; + + // FIXME: All missing headers are listed on the top-level module. Should we + // just look there? + for (const Module *Current = this; Current; Current = Current->Parent) { + if (!Current->MissingHeaders.empty()) { + MissingHeader = Current->MissingHeaders.front(); + return false; + } + } + + llvm_unreachable("could not find a reason why module is unavailable"); +} + +bool Module::isSubModuleOf(const Module *Other) const { + for (auto *Parent = this; Parent; Parent = Parent->Parent) { + if (Parent == Other) + return true; + } + return false; +} + +const Module *Module::getTopLevelModule() const { + const Module *Result = this; + while (Result->Parent) + Result = Result->Parent; + + return Result; +} + +static StringRef getModuleNameFromComponent( + const std::pair<std::string, SourceLocation> &IdComponent) { + return IdComponent.first; +} + +static StringRef getModuleNameFromComponent(StringRef R) { return R; } + +template<typename InputIter> +static void printModuleId(raw_ostream &OS, InputIter Begin, InputIter End, + bool AllowStringLiterals = true) { + for (InputIter It = Begin; It != End; ++It) { + if (It != Begin) + OS << "."; + + StringRef Name = getModuleNameFromComponent(*It); + if (!AllowStringLiterals || isValidAsciiIdentifier(Name)) + OS << Name; + else { + OS << '"'; + OS.write_escaped(Name); + OS << '"'; + } + } +} + +template<typename Container> +static void printModuleId(raw_ostream &OS, const Container &C) { + return printModuleId(OS, C.begin(), C.end()); +} + +std::string Module::getFullModuleName(bool AllowStringLiterals) const { + SmallVector<StringRef, 2> Names; + + // Build up the set of module names (from innermost to outermost). + for (const Module *M = this; M; M = M->Parent) + Names.push_back(M->Name); + + std::string Result; + + llvm::raw_string_ostream Out(Result); + printModuleId(Out, Names.rbegin(), Names.rend(), AllowStringLiterals); + Out.flush(); + + return Result; +} + +bool Module::fullModuleNameIs(ArrayRef<StringRef> nameParts) const { + for (const Module *M = this; M; M = M->Parent) { + if (nameParts.empty() || M->Name != nameParts.back()) + return false; + nameParts = nameParts.drop_back(); + } + return nameParts.empty(); +} + +OptionalDirectoryEntryRef Module::getEffectiveUmbrellaDir() const { + if (const auto *Hdr = std::get_if<FileEntryRef>(&Umbrella)) + return Hdr->getDir(); + if (const auto *Dir = std::get_if<DirectoryEntryRef>(&Umbrella)) + return *Dir; + return std::nullopt; +} + +void Module::addTopHeader(FileEntryRef File) { + assert(File); + TopHeaders.insert(File); +} + +ArrayRef<FileEntryRef> Module::getTopHeaders(FileManager &FileMgr) { + if (!TopHeaderNames.empty()) { + for (StringRef TopHeaderName : TopHeaderNames) + if (auto FE = FileMgr.getOptionalFileRef(TopHeaderName)) + TopHeaders.insert(*FE); + TopHeaderNames.clear(); + } + + return llvm::ArrayRef(TopHeaders.begin(), TopHeaders.end()); +} + +bool Module::directlyUses(const Module *Requested) { + auto *Top = getTopLevelModule(); + + // A top-level module implicitly uses itself. + if (Requested->isSubModuleOf(Top)) + return true; + + for (auto *Use : Top->DirectUses) + if (Requested->isSubModuleOf(Use)) + return true; + + // Anyone is allowed to use our builtin stddef.h and its accompanying modules. + if (Requested->fullModuleNameIs({"_Builtin_stddef", "max_align_t"}) || + Requested->fullModuleNameIs({"_Builtin_stddef_wint_t"})) + return true; + // Darwin is allowed is to use our builtin 'ptrauth.h' and its accompanying + // module. + if (!Requested->Parent && Requested->Name == "ptrauth") + return true; + + if (NoUndeclaredIncludes) + UndeclaredUses.insert(Requested); + + return false; +} + +void Module::addRequirement(StringRef Feature, bool RequiredState, + const LangOptions &LangOpts, + const TargetInfo &Target) { + Requirements.push_back(Requirement{std::string(Feature), RequiredState}); + + // If this feature is currently available, we're done. + if (hasFeature(Feature, LangOpts, Target) == RequiredState) + return; + + markUnavailable(/*Unimportable*/true); +} + +void Module::markUnavailable(bool Unimportable) { + auto needUpdate = [Unimportable](Module *M) { + return M->IsAvailable || (!M->IsUnimportable && Unimportable); + }; + + if (!needUpdate(this)) + return; + + SmallVector<Module *, 2> Stack; + Stack.push_back(this); + while (!Stack.empty()) { + Module *Current = Stack.back(); + Stack.pop_back(); + + if (!needUpdate(Current)) + continue; + + Current->IsAvailable = false; + Current->IsUnimportable |= Unimportable; + for (auto *Submodule : Current->submodules()) { + if (needUpdate(Submodule)) + Stack.push_back(Submodule); + } + } +} + +Module *Module::findSubmodule(StringRef Name) const { + llvm::StringMap<unsigned>::const_iterator Pos = SubModuleIndex.find(Name); + if (Pos == SubModuleIndex.end()) + return nullptr; + + return SubModules[Pos->getValue()]; +} + +Module *Module::findOrInferSubmodule(StringRef Name) { + llvm::StringMap<unsigned>::const_iterator Pos = SubModuleIndex.find(Name); + if (Pos != SubModuleIndex.end()) + return SubModules[Pos->getValue()]; + if (!InferSubmodules) + return nullptr; + Module *Result = new Module(Name, SourceLocation(), this, false, InferExplicitSubmodules, 0); + Result->InferExplicitSubmodules = InferExplicitSubmodules; + Result->InferSubmodules = InferSubmodules; + Result->InferExportWildcard = InferExportWildcard; + if (Result->InferExportWildcard) + Result->Exports.push_back(Module::ExportDecl(nullptr, true)); + return Result; +} + +Module *Module::getGlobalModuleFragment() const { + assert(isNamedModuleUnit() && "We should only query the global module " + "fragment from the C++20 Named modules"); + + for (auto *SubModule : SubModules) + if (SubModule->isExplicitGlobalModule()) + return SubModule; + + return nullptr; +} + +Module *Module::getPrivateModuleFragment() const { + assert(isNamedModuleUnit() && "We should only query the private module " + "fragment from the C++20 Named modules"); + + for (auto *SubModule : SubModules) + if (SubModule->isPrivateModule()) + return SubModule; + + return nullptr; +} + +void Module::getExportedModules(SmallVectorImpl<Module *> &Exported) const { + // All non-explicit submodules are exported. + for (std::vector<Module *>::const_iterator I = SubModules.begin(), + E = SubModules.end(); + I != E; ++I) { + Module *Mod = *I; + if (!Mod->IsExplicit) + Exported.push_back(Mod); + } + + // Find re-exported modules by filtering the list of imported modules. + bool AnyWildcard = false; + bool UnrestrictedWildcard = false; + SmallVector<Module *, 4> WildcardRestrictions; + for (unsigned I = 0, N = Exports.size(); I != N; ++I) { + Module *Mod = Exports[I].getPointer(); + if (!Exports[I].getInt()) { + // Export a named module directly; no wildcards involved. + Exported.push_back(Mod); + + continue; + } + + // Wildcard export: export all of the imported modules that match + // the given pattern. + AnyWildcard = true; + if (UnrestrictedWildcard) + continue; + + if (Module *Restriction = Exports[I].getPointer()) + WildcardRestrictions.push_back(Restriction); + else { + WildcardRestrictions.clear(); + UnrestrictedWildcard = true; + } + } + + // If there were any wildcards, push any imported modules that were + // re-exported by the wildcard restriction. + if (!AnyWildcard) + return; + + for (unsigned I = 0, N = Imports.size(); I != N; ++I) { + Module *Mod = Imports[I]; + bool Acceptable = UnrestrictedWildcard; + if (!Acceptable) { + // Check whether this module meets one of the restrictions. + for (unsigned R = 0, NR = WildcardRestrictions.size(); R != NR; ++R) { + Module *Restriction = WildcardRestrictions[R]; + if (Mod == Restriction || Mod->isSubModuleOf(Restriction)) { + Acceptable = true; + break; + } + } + } + + if (!Acceptable) + continue; + + Exported.push_back(Mod); + } +} + +void Module::buildVisibleModulesCache() const { + assert(VisibleModulesCache.empty() && "cache does not need building"); + + // This module is visible to itself. + VisibleModulesCache.insert(this); + + // Every imported module is visible. + SmallVector<Module *, 16> Stack(Imports.begin(), Imports.end()); + while (!Stack.empty()) { + Module *CurrModule = Stack.pop_back_val(); + + // Every module transitively exported by an imported module is visible. + if (VisibleModulesCache.insert(CurrModule).second) + CurrModule->getExportedModules(Stack); + } +} + +void Module::print(raw_ostream &OS, unsigned Indent, bool Dump) const { + OS.indent(Indent); + if (IsFramework) + OS << "framework "; + if (IsExplicit) + OS << "explicit "; + OS << "module "; + printModuleId(OS, &Name, &Name + 1); + + if (IsSystem || IsExternC) { + OS.indent(Indent + 2); + if (IsSystem) + OS << " [system]"; + if (IsExternC) + OS << " [extern_c]"; + } + + OS << " {\n"; + + if (!Requirements.empty()) { + OS.indent(Indent + 2); + OS << "requires "; + for (unsigned I = 0, N = Requirements.size(); I != N; ++I) { + if (I) + OS << ", "; + if (!Requirements[I].RequiredState) + OS << "!"; + OS << Requirements[I].FeatureName; + } + OS << "\n"; + } + + if (std::optional<Header> H = getUmbrellaHeaderAsWritten()) { + OS.indent(Indent + 2); + OS << "umbrella header \""; + OS.write_escaped(H->NameAsWritten); + OS << "\"\n"; + } else if (std::optional<DirectoryName> D = getUmbrellaDirAsWritten()) { + OS.indent(Indent + 2); + OS << "umbrella \""; + OS.write_escaped(D->NameAsWritten); + OS << "\"\n"; + } + + if (!ConfigMacros.empty() || ConfigMacrosExhaustive) { + OS.indent(Indent + 2); + OS << "config_macros "; + if (ConfigMacrosExhaustive) + OS << "[exhaustive]"; + for (unsigned I = 0, N = ConfigMacros.size(); I != N; ++I) { + if (I) + OS << ", "; + OS << ConfigMacros[I]; + } + OS << "\n"; + } + + struct { + StringRef Prefix; + HeaderKind Kind; + } Kinds[] = {{"", HK_Normal}, + {"textual ", HK_Textual}, + {"private ", HK_Private}, + {"private textual ", HK_PrivateTextual}, + {"exclude ", HK_Excluded}}; + + for (auto &K : Kinds) { + assert(&K == &Kinds[K.Kind] && "kinds in wrong order"); + for (auto &H : Headers[K.Kind]) { + OS.indent(Indent + 2); + OS << K.Prefix << "header \""; + OS.write_escaped(H.NameAsWritten); + OS << "\" { size " << H.Entry.getSize() + << " mtime " << H.Entry.getModificationTime() << " }\n"; + } + } + for (auto *Unresolved : {&UnresolvedHeaders, &MissingHeaders}) { + for (auto &U : *Unresolved) { + OS.indent(Indent + 2); + OS << Kinds[U.Kind].Prefix << "header \""; + OS.write_escaped(U.FileName); + OS << "\""; + if (U.Size || U.ModTime) { + OS << " {"; + if (U.Size) + OS << " size " << *U.Size; + if (U.ModTime) + OS << " mtime " << *U.ModTime; + OS << " }"; + } + OS << "\n"; + } + } + + if (!ExportAsModule.empty()) { + OS.indent(Indent + 2); + OS << "export_as" << ExportAsModule << "\n"; + } + + for (auto *Submodule : submodules()) + // Print inferred subframework modules so that we don't need to re-infer + // them (requires expensive directory iteration + stat calls) when we build + // the module. Regular inferred submodules are OK, as we need to look at all + // those header files anyway. + if (!Submodule->IsInferred || Submodule->IsFramework) + Submodule->print(OS, Indent + 2, Dump); + + for (unsigned I = 0, N = Exports.size(); I != N; ++I) { + OS.indent(Indent + 2); + OS << "export "; + if (Module *Restriction = Exports[I].getPointer()) { + OS << Restriction->getFullModuleName(true); + if (Exports[I].getInt()) + OS << ".*"; + } else { + OS << "*"; + } + OS << "\n"; + } + + for (unsigned I = 0, N = UnresolvedExports.size(); I != N; ++I) { + OS.indent(Indent + 2); + OS << "export "; + printModuleId(OS, UnresolvedExports[I].Id); + if (UnresolvedExports[I].Wildcard) + OS << (UnresolvedExports[I].Id.empty() ? "*" : ".*"); + OS << "\n"; + } + + if (Dump) { + for (Module *M : Imports) { + OS.indent(Indent + 2); + llvm::errs() << "import " << M->getFullModuleName() << "\n"; + } + } + + for (unsigned I = 0, N = DirectUses.size(); I != N; ++I) { + OS.indent(Indent + 2); + OS << "use "; + OS << DirectUses[I]->getFullModuleName(true); + OS << "\n"; + } + + for (unsigned I = 0, N = UnresolvedDirectUses.size(); I != N; ++I) { + OS.indent(Indent + 2); + OS << "use "; + printModuleId(OS, UnresolvedDirectUses[I]); + OS << "\n"; + } + + for (unsigned I = 0, N = LinkLibraries.size(); I != N; ++I) { + OS.indent(Indent + 2); + OS << "link "; + if (LinkLibraries[I].IsFramework) + OS << "framework "; + OS << "\""; + OS.write_escaped(LinkLibraries[I].Library); + OS << "\""; + } + + for (unsigned I = 0, N = UnresolvedConflicts.size(); I != N; ++I) { + OS.indent(Indent + 2); + OS << "conflict "; + printModuleId(OS, UnresolvedConflicts[I].Id); + OS << ", \""; + OS.write_escaped(UnresolvedConflicts[I].Message); + OS << "\"\n"; + } + + for (unsigned I = 0, N = Conflicts.size(); I != N; ++I) { + OS.indent(Indent + 2); + OS << "conflict "; + OS << Conflicts[I].Other->getFullModuleName(true); + OS << ", \""; + OS.write_escaped(Conflicts[I].Message); + OS << "\"\n"; + } + + if (InferSubmodules) { + OS.indent(Indent + 2); + if (InferExplicitSubmodules) + OS << "explicit "; + OS << "module * {\n"; + if (InferExportWildcard) { + OS.indent(Indent + 4); + OS << "export *\n"; + } + OS.indent(Indent + 2); + OS << "}\n"; + } + + OS.indent(Indent); + OS << "}\n"; +} + +LLVM_DUMP_METHOD void Module::dump() const { + print(llvm::errs(), 0, true); +} + +void VisibleModuleSet::setVisible(Module *M, SourceLocation Loc, + VisibleCallback Vis, ConflictCallback Cb) { + // We can't import a global module fragment so the location can be invalid. + assert((M->isGlobalModule() || Loc.isValid()) && + "setVisible expects a valid import location"); + if (isVisible(M)) + return; + + ++Generation; + + struct Visiting { + Module *M; + Visiting *ExportedBy; + }; + + std::function<void(Visiting)> VisitModule = [&](Visiting V) { + // Nothing to do for a module that's already visible. + unsigned ID = V.M->getVisibilityID(); + if (ImportLocs.size() <= ID) + ImportLocs.resize(ID + 1); + else if (ImportLocs[ID].isValid()) + return; + + ImportLocs[ID] = Loc; + Vis(V.M); + + // Make any exported modules visible. + SmallVector<Module *, 16> Exports; + V.M->getExportedModules(Exports); + for (Module *E : Exports) { + // Don't import non-importable modules. + if (!E->isUnimportable()) + VisitModule({E, &V}); + } + + for (auto &C : V.M->Conflicts) { + if (isVisible(C.Other)) { + llvm::SmallVector<Module*, 8> Path; + for (Visiting *I = &V; I; I = I->ExportedBy) + Path.push_back(I->M); + Cb(Path, C.Other, C.Message); + } + } + }; + VisitModule({M, nullptr}); +} diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index 8fe738be21568..530c5eeedb74f 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -20,7 +20,7 @@ #include "clang/AST/PrettyPrinter.h" #include "clang/AST/Type.h" #include "clang/AST/TypeOrdering.h" -#include "clang/Basic/ASTSourceDescriptor.h" +#include "clang/Basic/Module/ASTSourceDescriptor.h" #include "clang/Basic/CodeGenOptions.h" #include "clang/Basic/SourceLocation.h" #include "llvm/ADT/DenseMap.h" diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index e4774a587707a..993699a3b2a93 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -42,7 +42,7 @@ #include "clang/Basic/CodeGenOptions.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/FileManager.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" #include "clang/Basic/Version.h" diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index 0f68418130ead..61d281670d420 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -24,7 +24,7 @@ #include "clang/AST/Mangle.h" #include "clang/Basic/ABI.h" #include "clang/Basic/LangOptions.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/NoSanitizeList.h" #include "clang/Basic/ProfileList.h" #include "clang/Basic/TargetInfo.h" diff --git a/clang/lib/ExtractAPI/API.cpp b/clang/lib/ExtractAPI/API.cpp index 96bef967d8591..233377d6f7317 100644 --- a/clang/lib/ExtractAPI/API.cpp +++ b/clang/lib/ExtractAPI/API.cpp @@ -14,7 +14,7 @@ #include "clang/ExtractAPI/API.h" #include "clang/AST/RawCommentList.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Index/USRGeneration.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/ErrorHandling.h" diff --git a/clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.cpp b/clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.cpp index 41e4e0cf1795f..cf105726ae6ff 100644 --- a/clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.cpp +++ b/clang/lib/ExtractAPI/TypedefUnderlyingTypeResolver.cpp @@ -12,7 +12,7 @@ //===----------------------------------------------------------------------===// #include "clang/ExtractAPI/TypedefUnderlyingTypeResolver.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Index/USRGeneration.h" using namespace clang; diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp index 8d24d5d422520..959ef895a0893 100644 --- a/clang/lib/Frontend/ASTUnit.cpp +++ b/clang/lib/Frontend/ASTUnit.cpp @@ -31,7 +31,7 @@ #include "clang/Basic/LLVM.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/LangStandard.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index 454653a31534c..e41dd4c796523 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -11,7 +11,7 @@ #include "clang/AST/Decl.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/LangStandard.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/TargetInfo.h" #include "clang/Frontend/ASTConsumers.h" #include "clang/Frontend/CompilerInstance.h" diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 574723b33866a..de930f8dabb46 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -14,7 +14,7 @@ #include "clang/Basic/Diagnostic.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/IdentifierTable.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/SourceManager.h" #include "clang/Lex/DirectoryLookup.h" #include "clang/Lex/ExternalPreprocessorSource.h" diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp index eed7eca2e7356..37c259d9da5ae 100644 --- a/clang/lib/Lex/ModuleMap.cpp +++ b/clang/lib/Lex/ModuleMap.cpp @@ -17,7 +17,7 @@ #include "clang/Basic/FileManager.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/LangOptions.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 8e7386449dced..95a14bee51874 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -16,7 +16,7 @@ #include "clang/Basic/FileManager.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LangOptions.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/TokenKinds.h" diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp index 10f0ab7180e62..6a0dffdc8788e 100644 --- a/clang/lib/Lex/Pragma.cpp +++ b/clang/lib/Lex/Pragma.cpp @@ -18,7 +18,7 @@ #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/LangOptions.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/TokenKinds.h" diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index 0b70192743a39..be9646cbb8d8e 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -31,7 +31,7 @@ #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/LangOptions.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 389ac4ed76240..d596082d2102f 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -40,7 +40,7 @@ #include "clang/AST/TypeLoc.h" #include "clang/AST/TypeLocVisitor.h" #include "clang/AST/UnresolvedSet.h" -#include "clang/Basic/ASTSourceDescriptor.h" +#include "clang/Basic/Module/ASTSourceDescriptor.h" #include "clang/Basic/CommentOptions.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/DiagnosticError.h" @@ -52,7 +52,7 @@ #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/LangOptions.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/ObjCRuntime.h" #include "clang/Basic/OpenACCKinds.h" #include "clang/Basic/OpenMPKinds.h" diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index 61cc99d4df687..8cb291d00eee0 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -45,7 +45,7 @@ #include "clang/Basic/Lambda.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/Linkage.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/PragmaKinds.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/Specifiers.h" diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 00b0e48083217..6a3173b74c0c3 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -43,7 +43,7 @@ #include "clang/Basic/LLVM.h" #include "clang/Basic/Lambda.h" #include "clang/Basic/LangOptions.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "clang/Basic/ObjCRuntime.h" #include "clang/Basic/OpenACCKinds.h" #include "clang/Basic/OpenCLOptions.h" diff --git a/libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp b/libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp index 0a48f855fba06..054cdf27d8ccc 100644 --- a/libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp +++ b/libcxx/test/tools/clang_tidy_checks/header_exportable_declarations.cpp @@ -9,7 +9,7 @@ #include "clang-tidy/ClangTidyCheck.h" #include "clang-tidy/ClangTidyModuleRegistry.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include "llvm/ADT/ArrayRef.h" diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.h b/lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.h index da2b1a15f7461..74cde0c89cb08 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.h @@ -9,7 +9,7 @@ #ifndef LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_ASTUTILS_H #define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_ASTUTILS_H -#include "clang/Basic/ASTSourceDescriptor.h" +#include "clang/Basic/Module/ASTSourceDescriptor.h" #include "clang/Sema/Lookup.h" #include "clang/Sema/MultiplexExternalSemaSource.h" #include "clang/Sema/Sema.h" diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.cpp index e746e6afe39be..c72d493a7288d 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.cpp +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.cpp @@ -11,7 +11,7 @@ #include "clang/AST/Decl.h" #include "clang/AST/DeclObjC.h" -#include "clang/Basic/Module.h" +#include "clang/Basic/Module/Module.h" #include <optional> using namespace lldb_private; diff --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h b/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h index 6bd18186a567d..c874e5be23547 100644 --- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h +++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExternalASTSourceCallbacks.h @@ -10,7 +10,7 @@ #define LLDB_SOURCE_PLUGINS_EXPRESSIONPARSER_CLANG_CLANGEXTERNALASTSOURCECALLBACKS_H #include "Plugins/TypeSystem/Clang/TypeSystemClang.h" -#include "clang/Basic/ASTSourceDescriptor.h" +#include "clang/Basic/Module/ASTSourceDescriptor.h" #include <optional> namespace clang { >From dc312662bc4c97c357f859a8c16c91842d4ff583 Mon Sep 17 00:00:00 2001 From: David Stone <davidfromonl...@gmail.com> Date: Sat, 25 May 2024 18:17:18 -0600 Subject: [PATCH 3/4] fix --- clang/include/clang/Basic/Module/ASTSourceDescriptor.h | 6 +++--- clang/include/clang/Basic/Module/Module.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clang/include/clang/Basic/Module/ASTSourceDescriptor.h b/clang/include/clang/Basic/Module/ASTSourceDescriptor.h index 32fc9d4856cbe..315fa3a4e8bcf 100644 --- a/clang/include/clang/Basic/Module/ASTSourceDescriptor.h +++ b/clang/include/clang/Basic/Module/ASTSourceDescriptor.h @@ -12,8 +12,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_BASIC_ASTSOURCEDESCRIPTOR_H -#define LLVM_CLANG_BASIC_ASTSOURCEDESCRIPTOR_H +#ifndef LLVM_CLANG_BASIC_MODULE_ASTSOURCEDESCRIPTOR_H +#define LLVM_CLANG_BASIC_MODULE_ASTSOURCEDESCRIPTOR_H #include "clang/Basic/Module/Module.h" #include "llvm/ADT/StringRef.h" @@ -49,4 +49,4 @@ class ASTSourceDescriptor { } // namespace clang -#endif // LLVM_CLANG_BASIC_ASTSOURCEDESCRIPTOR_H +#endif // LLVM_CLANG_BASIC_MODULE_ASTSOURCEDESCRIPTOR_H diff --git a/clang/include/clang/Basic/Module/Module.h b/clang/include/clang/Basic/Module/Module.h index e86f4303d732b..8c1d188a935dd 100644 --- a/clang/include/clang/Basic/Module/Module.h +++ b/clang/include/clang/Basic/Module/Module.h @@ -12,8 +12,8 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_BASIC_MODULE_H -#define LLVM_CLANG_BASIC_MODULE_H +#ifndef LLVM_CLANG_BASIC_MODULE_MODULE_H +#define LLVM_CLANG_BASIC_MODULE_MODULE_H #include "clang/Basic/DirectoryEntry.h" #include "clang/Basic/FileEntry.h" @@ -870,4 +870,4 @@ class VisibleModuleSet { } // namespace clang -#endif // LLVM_CLANG_BASIC_MODULE_H +#endif // LLVM_CLANG_BASIC_MODULE_MODULE_H >From da600ac630c9174317db999885778902e4e6fe21 Mon Sep 17 00:00:00 2001 From: David Stone <davidfromonl...@gmail.com> Date: Sat, 25 May 2024 20:05:30 -0600 Subject: [PATCH 4/4] formatting --- clang/include/clang/Basic/Module/Module.h | 38 +++++++++-------------- clang/lib/AST/ExternalASTSource.cpp | 2 +- clang/lib/Basic/Module/Module.cpp | 21 ++++++------- clang/lib/CodeGen/CGDebugInfo.h | 2 +- clang/lib/Lex/HeaderSearch.cpp | 2 +- clang/lib/Serialization/ASTReader.cpp | 2 +- 6 files changed, 28 insertions(+), 39 deletions(-) diff --git a/clang/include/clang/Basic/Module/Module.h b/clang/include/clang/Basic/Module/Module.h index 8c1d188a935dd..4aba0dd68391a 100644 --- a/clang/include/clang/Basic/Module/Module.h +++ b/clang/include/clang/Basic/Module/Module.h @@ -230,7 +230,7 @@ class alignas(8) Module { std::vector<std::string> TopHeaderNames; /// Cache of modules visible to lookup in this module. - mutable llvm::DenseSet<const Module*> VisibleModulesCache; + mutable llvm::DenseSet<const Module *> VisibleModulesCache; /// The ID used when referencing this module within a VisibleModuleSet. unsigned VisibilityID; @@ -545,10 +545,8 @@ class alignas(8) Module { /// /// \param ShadowingModule If this module is unavailable because it is /// shadowed, this parameter will be set to the shadowing module. - bool isAvailable(const LangOptions &LangOpts, - const TargetInfo &Target, - Requirement &Req, - UnresolvedHeaderDirective &MissingHeader, + bool isAvailable(const LangOptions &LangOpts, const TargetInfo &Target, + Requirement &Req, UnresolvedHeaderDirective &MissingHeader, Module *&ShadowingModule) const; /// Determine whether this module is a submodule. @@ -665,7 +663,7 @@ class alignas(8) Module { /// be this module. Module *getTopLevelModule() { return const_cast<Module *>( - const_cast<const Module *>(this)->getTopLevelModule()); + const_cast<const Module *>(this)->getTopLevelModule()); } /// Retrieve the top-level module for this (sub)module, which may @@ -673,9 +671,7 @@ class alignas(8) Module { const Module *getTopLevelModule() const; /// Retrieve the name of the top-level module. - StringRef getTopLevelModuleName() const { - return getTopLevelModule()->Name; - } + StringRef getTopLevelModuleName() const { return getTopLevelModule()->Name; } /// The serialized AST file for this module, if one was created. OptionalFileEntryRef getASTFile() const { @@ -739,8 +735,7 @@ class alignas(8) Module { /// \param Target The target options that will be used to evaluate the /// availability of this feature. void addRequirement(StringRef Feature, bool RequiredState, - const LangOptions &LangOpts, - const TargetInfo &Target); + const LangOptions &LangOpts, const TargetInfo &Target); /// Mark this module and all of its submodules as unavailable. void markUnavailable(bool Unimportable); @@ -793,9 +788,7 @@ class alignas(8) Module { /// directly exported), not the complete set of exported modules. void getExportedModules(SmallVectorImpl<Module *> &Exported) const; - static StringRef getModuleInputBufferName() { - return "<module-includes>"; - } + static StringRef getModuleInputBufferName() { return "<module-includes>"; } /// Print the module map for this module to the given stream. void print(raw_ostream &OS, unsigned Indent = 0, bool Dump = false) const; @@ -832,9 +825,7 @@ class VisibleModuleSet { unsigned getGeneration() const { return Generation; } /// Determine whether a module is visible. - bool isVisible(const Module *M) const { - return getImportLoc(M).isValid(); - } + bool isVisible(const Module *M) const { return getImportLoc(M).isValid(); } /// Get the location at which the import of a module was triggered. SourceLocation getImportLoc(const Module *M) const { @@ -850,15 +841,14 @@ class VisibleModuleSet { /// A callback to call when a module conflict is found. \p Path /// consists of a sequence of modules from the conflicting module to the one /// made visible, where each was exported by the next. - using ConflictCallback = - llvm::function_ref<void(ArrayRef<Module *> Path, Module *Conflict, - StringRef Message)>; + using ConflictCallback = llvm::function_ref<void( + ArrayRef<Module *> Path, Module *Conflict, StringRef Message)>; /// Make a specific module visible. - void setVisible(Module *M, SourceLocation Loc, - VisibleCallback Vis = [](Module *) {}, - ConflictCallback Cb = [](ArrayRef<Module *>, Module *, - StringRef) {}); + void setVisible( + Module *M, SourceLocation Loc, VisibleCallback Vis = [](Module *) {}, + ConflictCallback Cb = [](ArrayRef<Module *>, Module *, StringRef) {}); + private: /// Import locations for each visible module. Indexed by the module's /// VisibilityID. diff --git a/clang/lib/AST/ExternalASTSource.cpp b/clang/lib/AST/ExternalASTSource.cpp index fb16f41ced520..61c650d463791 100644 --- a/clang/lib/AST/ExternalASTSource.cpp +++ b/clang/lib/AST/ExternalASTSource.cpp @@ -15,10 +15,10 @@ #include "clang/AST/ExternalASTSource.h" #include "clang/AST/ASTContext.h" #include "clang/AST/DeclarationName.h" -#include "clang/Basic/Module/ASTSourceDescriptor.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LLVM.h" +#include "clang/Basic/Module/ASTSourceDescriptor.h" #include "clang/Basic/SourceManager.h" #include "llvm/Support/ErrorHandling.h" #include <cstdint> diff --git a/clang/lib/Basic/Module/Module.cpp b/clang/lib/Basic/Module/Module.cpp index 581509b888a5b..4bc8e63e3ecfe 100644 --- a/clang/lib/Basic/Module/Module.cpp +++ b/clang/lib/Basic/Module/Module.cpp @@ -78,7 +78,7 @@ static bool isPlatformEnvironment(const TargetInfo &Target, StringRef Feature) { if (Pos == StringRef::npos) return false; SmallString<128> NewLHS = LHS.slice(0, Pos); - NewLHS += LHS.slice(Pos+1, LHS.size()); + NewLHS += LHS.slice(Pos + 1, LHS.size()); return NewLHS == RHS; }; @@ -218,7 +218,7 @@ static StringRef getModuleNameFromComponent( static StringRef getModuleNameFromComponent(StringRef R) { return R; } -template<typename InputIter> +template <typename InputIter> static void printModuleId(raw_ostream &OS, InputIter Begin, InputIter End, bool AllowStringLiterals = true) { for (InputIter It = Begin; It != End; ++It) { @@ -236,7 +236,7 @@ static void printModuleId(raw_ostream &OS, InputIter Begin, InputIter End, } } -template<typename Container> +template <typename Container> static void printModuleId(raw_ostream &OS, const Container &C) { return printModuleId(OS, C.begin(), C.end()); } @@ -325,7 +325,7 @@ void Module::addRequirement(StringRef Feature, bool RequiredState, if (hasFeature(Feature, LangOpts, Target) == RequiredState) return; - markUnavailable(/*Unimportable*/true); + markUnavailable(/*Unimportable*/ true); } void Module::markUnavailable(bool Unimportable) { @@ -368,7 +368,8 @@ Module *Module::findOrInferSubmodule(StringRef Name) { return SubModules[Pos->getValue()]; if (!InferSubmodules) return nullptr; - Module *Result = new Module(Name, SourceLocation(), this, false, InferExplicitSubmodules, 0); + Module *Result = new Module(Name, SourceLocation(), this, false, + InferExplicitSubmodules, 0); Result->InferExplicitSubmodules = InferExplicitSubmodules; Result->InferSubmodules = InferSubmodules; Result->InferExportWildcard = InferExportWildcard; @@ -551,8 +552,8 @@ void Module::print(raw_ostream &OS, unsigned Indent, bool Dump) const { OS.indent(Indent + 2); OS << K.Prefix << "header \""; OS.write_escaped(H.NameAsWritten); - OS << "\" { size " << H.Entry.getSize() - << " mtime " << H.Entry.getModificationTime() << " }\n"; + OS << "\" { size " << H.Entry.getSize() << " mtime " + << H.Entry.getModificationTime() << " }\n"; } } for (auto *Unresolved : {&UnresolvedHeaders, &MissingHeaders}) { @@ -674,9 +675,7 @@ void Module::print(raw_ostream &OS, unsigned Indent, bool Dump) const { OS << "}\n"; } -LLVM_DUMP_METHOD void Module::dump() const { - print(llvm::errs(), 0, true); -} +LLVM_DUMP_METHOD void Module::dump() const { print(llvm::errs(), 0, true); } void VisibleModuleSet::setVisible(Module *M, SourceLocation Loc, VisibleCallback Vis, ConflictCallback Cb) { @@ -715,7 +714,7 @@ void VisibleModuleSet::setVisible(Module *M, SourceLocation Loc, for (auto &C : V.M->Conflicts) { if (isVisible(C.Other)) { - llvm::SmallVector<Module*, 8> Path; + llvm::SmallVector<Module *, 8> Path; for (Visiting *I = &V; I; I = I->ExportedBy) Path.push_back(I->M); Cb(Path, C.Other, C.Message); diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index 530c5eeedb74f..7a767508b0a8c 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -20,8 +20,8 @@ #include "clang/AST/PrettyPrinter.h" #include "clang/AST/Type.h" #include "clang/AST/TypeOrdering.h" -#include "clang/Basic/Module/ASTSourceDescriptor.h" #include "clang/Basic/CodeGenOptions.h" +#include "clang/Basic/Module/ASTSourceDescriptor.h" #include "clang/Basic/SourceLocation.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseSet.h" diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index de930f8dabb46..ad49de7cde754 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -25,11 +25,11 @@ #include "clang/Lex/Preprocessor.h" #include "llvm/ADT/APInt.h" #include "llvm/ADT/Hashing.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" #include "llvm/ADT/StringRef.h" -#include "llvm/ADT/STLExtras.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/Capacity.h" #include "llvm/Support/Errc.h" diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index d596082d2102f..95a62095d448a 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -40,7 +40,6 @@ #include "clang/AST/TypeLoc.h" #include "clang/AST/TypeLocVisitor.h" #include "clang/AST/UnresolvedSet.h" -#include "clang/Basic/Module/ASTSourceDescriptor.h" #include "clang/Basic/CommentOptions.h" #include "clang/Basic/Diagnostic.h" #include "clang/Basic/DiagnosticError.h" @@ -52,6 +51,7 @@ #include "clang/Basic/IdentifierTable.h" #include "clang/Basic/LLVM.h" #include "clang/Basic/LangOptions.h" +#include "clang/Basic/Module/ASTSourceDescriptor.h" #include "clang/Basic/Module/Module.h" #include "clang/Basic/ObjCRuntime.h" #include "clang/Basic/OpenACCKinds.h" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits