diff options
Diffstat (limited to 'include/clang/Lex/ModuleMap.h')
| -rw-r--r-- | include/clang/Lex/ModuleMap.h | 75 | 
1 files changed, 46 insertions, 29 deletions
diff --git a/include/clang/Lex/ModuleMap.h b/include/clang/Lex/ModuleMap.h index 11506939f9b1..41ed8e49b6c1 100644 --- a/include/clang/Lex/ModuleMap.h +++ b/include/clang/Lex/ModuleMap.h @@ -1,4 +1,4 @@ -//===--- ModuleMap.h - Describe the layout of modules -----------*- C++ -*-===// +//===- ModuleMap.h - Describe the layout of modules -------------*- C++ -*-===//  //  //                     The LLVM Compiler Infrastructure  // @@ -18,7 +18,6 @@  #include "clang/Basic/LangOptions.h"  #include "clang/Basic/Module.h"  #include "clang/Basic/SourceLocation.h" -#include "clang/Basic/SourceManager.h"  #include "llvm/ADT/ArrayRef.h"  #include "llvm/ADT/DenseMap.h"  #include "llvm/ADT/PointerIntPair.h" @@ -28,20 +27,19 @@  #include "llvm/ADT/StringRef.h"  #include "llvm/ADT/TinyPtrVector.h"  #include "llvm/ADT/Twine.h" -#include <algorithm> +#include <ctime>  #include <memory>  #include <string>  #include <utility>  namespace clang { +class DiagnosticsEngine;  class DirectoryEntry;  class FileEntry;  class FileManager; -class DiagnosticConsumer; -class DiagnosticsEngine;  class HeaderSearch; -class ModuleMapParser; +class SourceManager;  /// \brief A mechanism to observe the actions of the module map parser as it  /// reads module map files. @@ -82,33 +80,40 @@ class ModuleMap {    /// \brief The directory used for Clang-supplied, builtin include headers,    /// such as "stdint.h". -  const DirectoryEntry *BuiltinIncludeDir; +  const DirectoryEntry *BuiltinIncludeDir = nullptr;    /// \brief Language options used to parse the module map itself.    ///    /// These are always simple C language options.    LangOptions MMapLangOpts; -  // The module that the main source file is associated with (the module -  // named LangOpts::CurrentModule, if we've loaded it). -  Module *SourceModule; +  /// The module that the main source file is associated with (the module +  /// named LangOpts::CurrentModule, if we've loaded it). +  Module *SourceModule = nullptr; + +  /// The global module for the current TU, if we still own it. (Ownership is +  /// transferred if/when we create an enclosing module. +  std::unique_ptr<Module> PendingGlobalModule;    /// \brief The top-level modules that are known.    llvm::StringMap<Module *> Modules;    /// \brief The number of modules we have created in total. -  unsigned NumCreatedModules; +  unsigned NumCreatedModules = 0;  public:    /// \brief Flags describing the role of a module header.    enum ModuleHeaderRole {      /// \brief This header is normally included in the module.      NormalHeader  = 0x0, +      /// \brief This header is included but private.      PrivateHeader = 0x1, +      /// \brief This header is part of the module (for layering purposes) but      /// should be textually included.      TextualHeader = 0x2, +      // Caution: Adding an enumerator needs other changes.      // Adjust the number of bits for KnownHeader::Storage.      // Adjust the bitfield HeaderFileInfo::HeaderRole size. @@ -119,6 +124,7 @@ public:    /// Convert a header kind to a role. Requires Kind to not be HK_Excluded.    static ModuleHeaderRole headerKindToRole(Module::HeaderKind Kind); +    /// Convert a header role to a kind.    static Module::HeaderKind headerRoleToKind(ModuleHeaderRole Role); @@ -128,8 +134,8 @@ public:      llvm::PointerIntPair<Module *, 2, ModuleHeaderRole> Storage;    public: -    KnownHeader() : Storage(nullptr, NormalHeader) { } -    KnownHeader(Module *M, ModuleHeaderRole Role) : Storage(M, Role) { } +    KnownHeader() : Storage(nullptr, NormalHeader) {} +    KnownHeader(Module *M, ModuleHeaderRole Role) : Storage(M, Role) {}      friend bool operator==(const KnownHeader &A, const KnownHeader &B) {        return A.Storage == B.Storage; @@ -162,11 +168,13 @@ public:      }    }; -  typedef llvm::SmallPtrSet<const FileEntry *, 1> AdditionalModMapsSet; +  using AdditionalModMapsSet = llvm::SmallPtrSet<const FileEntry *, 1>;  private: -  typedef llvm::DenseMap<const FileEntry *, SmallVector<KnownHeader, 1>> -  HeadersMap; +  friend class ModuleMapParser; + +  using HeadersMap = +      llvm::DenseMap<const FileEntry *, SmallVector<KnownHeader, 1>>;    /// \brief Mapping from each header to the module that owns the contents of    /// that header. @@ -174,6 +182,7 @@ private:    /// Map from file sizes to modules with lazy header directives of that size.    mutable llvm::DenseMap<off_t, llvm::TinyPtrVector<Module*>> LazyHeadersBySize; +    /// Map from mtimes to modules with lazy header directives with those mtimes.    mutable llvm::DenseMap<time_t, llvm::TinyPtrVector<Module*>>                LazyHeadersByModTime; @@ -188,9 +197,6 @@ private:    /// \brief The set of attributes that can be attached to a module.    struct Attributes { -    Attributes() -        : IsSystem(), IsExternC(), IsExhaustive(), NoUndeclaredIncludes() {} -      /// \brief Whether this is a system module.      unsigned IsSystem : 1; @@ -203,12 +209,14 @@ private:      /// \brief Whether files in this module can only include non-modular headers      /// and headers from used modules.      unsigned NoUndeclaredIncludes : 1; + +    Attributes() +        : IsSystem(false), IsExternC(false), IsExhaustive(false), +          NoUndeclaredIncludes(false) {}    };    /// \brief A directory for which framework modules can be inferred.    struct InferredDirectory { -    InferredDirectory() : InferModules() {} -      /// \brief Whether to infer modules from this directory.      unsigned InferModules : 1; @@ -222,6 +230,8 @@ private:      /// \brief The names of modules that cannot be inferred within this      /// directory.      SmallVector<std::string, 2> ExcludedModules; + +    InferredDirectory() : InferModules(false) {}    };    /// \brief A mapping from directories to information about inferring @@ -238,8 +248,6 @@ private:    /// map.    llvm::DenseMap<const FileEntry *, bool> ParsedModuleMap; -  friend class ModuleMapParser; -      /// \brief Resolve the given export declaration into an actual export    /// declaration.    /// @@ -341,7 +349,6 @@ public:              HeaderSearch &HeaderInfo);    /// \brief Destroy the module map. -  ///    ~ModuleMap();    /// \brief Set the target information. @@ -460,7 +467,7 @@ public:    /// \param Name The name of the module to find or create.    ///    /// \param Parent The module that will act as the parent of this submodule, -  /// or NULL to indicate that this is a top-level module. +  /// or nullptr to indicate that this is a top-level module.    ///    /// \param IsFramework Whether this is a framework module.    /// @@ -472,6 +479,14 @@ public:                                                 bool IsFramework,                                                 bool IsExplicit); +  /// \brief Create a 'global module' for a C++ Modules TS module interface +  /// unit. +  /// +  /// We model the global module as a submodule of the module interface unit. +  /// Unfortunately, we can't create the module interface unit's Module until +  /// later, because we don't know what it will be called. +  Module *createGlobalModuleForInterfaceUnit(SourceLocation Loc); +    /// \brief Create a new module for a C++ Modules TS module interface unit.    /// The module must not already exist, and will be configured for the current    /// compilation. @@ -479,7 +494,8 @@ public:    /// Note that this also sets the current module to the newly-created module.    ///    /// \returns The newly-created module. -  Module *createModuleForInterfaceUnit(SourceLocation Loc, StringRef Name); +  Module *createModuleForInterfaceUnit(SourceLocation Loc, StringRef Name, +                                       Module *GlobalModule);    /// \brief Infer the contents of a framework module map from the given    /// framework directory. @@ -492,7 +508,7 @@ public:    /// \param Module The module whose module map file will be returned, if known.    ///    /// \returns The file entry for the module map file containing the given -  /// module, or NULL if the module definition was inferred. +  /// module, or nullptr if the module definition was inferred.    const FileEntry *getContainingModuleMapFile(const Module *Module) const;    /// \brief Get the module map file that (along with the module name) uniquely @@ -599,11 +615,12 @@ public:    /// \brief Dump the contents of the module map, for debugging purposes.    void dump(); -  typedef llvm::StringMap<Module *>::const_iterator module_iterator; +  using module_iterator = llvm::StringMap<Module *>::const_iterator; +    module_iterator module_begin() const { return Modules.begin(); }    module_iterator module_end()   const { return Modules.end(); }  }; -} // end namespace clang +} // namespace clang  #endif // LLVM_CLANG_LEX_MODULEMAP_H  | 
