1a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor//===--- ModuleMap.h - Describe the layout of modules -----------*- C++ -*-===//
2a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor//
3a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor//                     The LLVM Compiler Infrastructure
4a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor//
5a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor// This file is distributed under the University of Illinois Open Source
6a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor// License. See LICENSE.TXT for details.
7a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor//
8a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor//===----------------------------------------------------------------------===//
9a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor//
10a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor// This file defines the ModuleMap interface, which describes the layout of a
11a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor// module as it relates to headers.
12a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor//
13a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor//===----------------------------------------------------------------------===//
14a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor
15a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor
16a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor#ifndef LLVM_CLANG_LEX_MODULEMAP_H
17a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor#define LLVM_CLANG_LEX_MODULEMAP_H
18a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor
19a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor#include "clang/Basic/LangOptions.h"
201a4761edca58c6b559de825b9abfb66f7f1ba94aDouglas Gregor#include "clang/Basic/Module.h"
21a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor#include "clang/Basic/SourceManager.h"
22a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor#include "llvm/ADT/DenseMap.h"
23a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor#include "llvm/ADT/IntrusiveRefCntPtr.h"
24a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor#include "llvm/ADT/SmallVector.h"
25a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor#include "llvm/ADT/StringMap.h"
2630a2e16f6c27f888dd11eba6bbbae1e980078fcbChandler Carruth#include "llvm/ADT/StringRef.h"
27a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor#include <string>
28a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor
29a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregornamespace clang {
30a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor
31adb979924ade3e25342c38a5b564400b4e0540c1Douglas Gregorclass DirectoryEntry;
32a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregorclass FileEntry;
33a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregorclass FileManager;
34a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregorclass DiagnosticConsumer;
35a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregorclass DiagnosticsEngine;
3655ea75bf61a5d76f6453513d937944ce68181c6aArgyrios Kyrtzidisclass HeaderSearch;
37a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregorclass ModuleMapParser;
38a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar
39a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar/// \brief A mechanism to observe the actions of the module map parser as it
40a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar/// reads module map files.
41a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarclass ModuleMapCallbacks {
42a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainarpublic:
43a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  virtual ~ModuleMapCallbacks() {}
44a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar
45a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  /// \brief Called when a module map file has been read.
46a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  ///
47a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  /// \param FileStart A SourceLocation referring to the start of the file's
48a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  /// contents.
49a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  /// \param File The file itself.
50a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  /// \param IsSystem Whether this is a module map from a system include path.
51a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  virtual void moduleMapFileRead(SourceLocation FileStart,
52a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar                                 const FileEntry &File, bool IsSystem) {}
53a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar};
54a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor
55a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregorclass ModuleMap {
56ee0cd37fe4a9f4e2ee73ae34cf93c410cb299a82Manuel Klimek  SourceManager &SourceMgr;
57651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  DiagnosticsEngine &Diags;
5851f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor  const LangOptions &LangOpts;
59dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor  const TargetInfo *Target;
6055ea75bf61a5d76f6453513d937944ce68181c6aArgyrios Kyrtzidis  HeaderSearch &HeaderInfo;
61a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar
62a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  llvm::SmallVector<std::unique_ptr<ModuleMapCallbacks>, 1> Callbacks;
63dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor
642f04f1843ca0ffca13b8b0d4dadd1f50dffb38b8Douglas Gregor  /// \brief The directory used for Clang-supplied, builtin include headers,
652f04f1843ca0ffca13b8b0d4dadd1f50dffb38b8Douglas Gregor  /// such as "stdint.h".
662f04f1843ca0ffca13b8b0d4dadd1f50dffb38b8Douglas Gregor  const DirectoryEntry *BuiltinIncludeDir;
672f04f1843ca0ffca13b8b0d4dadd1f50dffb38b8Douglas Gregor
6851f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor  /// \brief Language options used to parse the module map itself.
6951f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor  ///
7051f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor  /// These are always simple C language options.
7151f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor  LangOptions MMapLangOpts;
7251f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor
73d3220dbeeadc4ac54ceecea8cf63f8d8be291d2aArgyrios Kyrtzidis  // The module that we are building; related to \c LangOptions::CurrentModule.
74d3220dbeeadc4ac54ceecea8cf63f8d8be291d2aArgyrios Kyrtzidis  Module *CompilingModule;
75d3220dbeeadc4ac54ceecea8cf63f8d8be291d2aArgyrios Kyrtzidis
76ddd2dfc1d3f4a36cbe8cd775c588623a17049f9fDaniel Jasperpublic:
77ddd2dfc1d3f4a36cbe8cd775c588623a17049f9fDaniel Jasper  // The module that the .cc source file is associated with.
78ddd2dfc1d3f4a36cbe8cd775c588623a17049f9fDaniel Jasper  Module *SourceModule;
79ddd2dfc1d3f4a36cbe8cd775c588623a17049f9fDaniel Jasper  std::string SourceModuleName;
80ddd2dfc1d3f4a36cbe8cd775c588623a17049f9fDaniel Jasper
81ddd2dfc1d3f4a36cbe8cd775c588623a17049f9fDaniel Jasperprivate:
82484535e45b4d301847a157e943c7823da5d40884Douglas Gregor  /// \brief The top-level modules that are known.
83a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor  llvm::StringMap<Module *> Modules;
842b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor
85b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar  /// \brief The number of modules we have created in total.
86b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar  unsigned NumCreatedModules;
87b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar
88bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowlpublic:
89176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// \brief Flags describing the role of a module header.
90bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl  enum ModuleHeaderRole {
91bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl    /// \brief This header is normally included in the module.
92176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    NormalHeader  = 0x0,
93bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl    /// \brief This header is included but private.
94176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    PrivateHeader = 0x1,
95176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    /// \brief This header is part of the module (for layering purposes) but
96176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    /// should be textually included.
97176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    TextualHeader = 0x2,
98bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl    // Caution: Adding an enumerator needs other changes.
99bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl    // Adjust the number of bits for KnownHeader::Storage.
100bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl    // Adjust the bitfield HeaderFileInfo::HeaderRole size.
101bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl    // Adjust the HeaderFileInfoTrait::ReadData streaming.
102bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl    // Adjust the HeaderFileInfoTrait::EmitData streaming.
103176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    // Adjust ModuleMap::addHeader.
104bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl  };
105bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl
1062b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor  /// \brief A header that is known to reside within a given module,
1072b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor  /// whether it was included or excluded.
1082b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor  class KnownHeader {
109bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl    llvm::PointerIntPair<Module *, 2, ModuleHeaderRole> Storage;
1102b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor
1112b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor  public:
1126bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    KnownHeader() : Storage(nullptr, NormalHeader) { }
113bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl    KnownHeader(Module *M, ModuleHeaderRole Role) : Storage(M, Role) { }
1142b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor
115a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar    friend bool operator==(const KnownHeader &A, const KnownHeader &B) {
116a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar      return A.Storage == B.Storage;
117a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar    }
118a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar    friend bool operator!=(const KnownHeader &A, const KnownHeader &B) {
119a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar      return A.Storage != B.Storage;
120a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar    }
121a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar
1222b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor    /// \brief Retrieve the module the header is stored in.
1232b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor    Module *getModule() const { return Storage.getPointer(); }
1242b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor
125bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl    /// \brief The role of this header within the module.
126bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl    ModuleHeaderRole getRole() const { return Storage.getInt(); }
1272b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor
1282b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor    /// \brief Whether this header is available in the module.
129176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    bool isAvailable() const {
130176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines      return getModule()->isAvailable();
1312b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor    }
1322b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor
1332b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor    // \brief Whether this known header is valid (i.e., it has an
1342b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor    // associated module).
1350e2c34f92f00628d48968dfea096d36381f494cbStephen Hines    explicit operator bool() const {
1366bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines      return Storage.getPointer() != nullptr;
1376bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    }
1382b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor  };
1392b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor
140176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  typedef llvm::SmallPtrSet<const FileEntry *, 1> AdditionalModMapsSet;
141176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
142bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowlprivate:
143c641709607d45bf97772e925647db6c94866c50aDaniel Jasper  typedef llvm::DenseMap<const FileEntry *, SmallVector<KnownHeader, 1> >
144c641709607d45bf97772e925647db6c94866c50aDaniel Jasper  HeadersMap;
1452b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor
146cdeba0b0127e0d97b10752a1e875901da4426810Lawrence Crowl  /// \brief Mapping from each header to the module that owns the contents of
147a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor  /// that header.
1482b49d1f0ad790a8a5d514af1be211591a746cb73Douglas Gregor  HeadersMap Headers;
149a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor
150adb979924ade3e25342c38a5b564400b4e0540c1Douglas Gregor  /// \brief Mapping from directories with umbrella headers to the module
151adb979924ade3e25342c38a5b564400b4e0540c1Douglas Gregor  /// that is generated from the umbrella header.
152adb979924ade3e25342c38a5b564400b4e0540c1Douglas Gregor  ///
153adb979924ade3e25342c38a5b564400b4e0540c1Douglas Gregor  /// This mapping is used to map headers that haven't explicitly been named
154adb979924ade3e25342c38a5b564400b4e0540c1Douglas Gregor  /// in the module map over to the module that includes them via its umbrella
155adb979924ade3e25342c38a5b564400b4e0540c1Douglas Gregor  /// header.
156adb979924ade3e25342c38a5b564400b4e0540c1Douglas Gregor  llvm::DenseMap<const DirectoryEntry *, Module *> UmbrellaDirs;
15782e52377bd76ed71e8c09edc5f2f452e388b16adDouglas Gregor
1580e2c34f92f00628d48968dfea096d36381f494cbStephen Hines  /// \brief The set of attributes that can be attached to a module.
1590e2c34f92f00628d48968dfea096d36381f494cbStephen Hines  struct Attributes {
1600e2c34f92f00628d48968dfea096d36381f494cbStephen Hines    Attributes() : IsSystem(), IsExternC(), IsExhaustive() {}
1610e2c34f92f00628d48968dfea096d36381f494cbStephen Hines
1620e2c34f92f00628d48968dfea096d36381f494cbStephen Hines    /// \brief Whether this is a system module.
1630e2c34f92f00628d48968dfea096d36381f494cbStephen Hines    unsigned IsSystem : 1;
1640e2c34f92f00628d48968dfea096d36381f494cbStephen Hines
1650e2c34f92f00628d48968dfea096d36381f494cbStephen Hines    /// \brief Whether this is an extern "C" module.
1660e2c34f92f00628d48968dfea096d36381f494cbStephen Hines    unsigned IsExternC : 1;
1670e2c34f92f00628d48968dfea096d36381f494cbStephen Hines
1680e2c34f92f00628d48968dfea096d36381f494cbStephen Hines    /// \brief Whether this is an exhaustive set of configuration macros.
1690e2c34f92f00628d48968dfea096d36381f494cbStephen Hines    unsigned IsExhaustive : 1;
1700e2c34f92f00628d48968dfea096d36381f494cbStephen Hines  };
1710e2c34f92f00628d48968dfea096d36381f494cbStephen Hines
17282e52377bd76ed71e8c09edc5f2f452e388b16adDouglas Gregor  /// \brief A directory for which framework modules can be inferred.
17382e52377bd76ed71e8c09edc5f2f452e388b16adDouglas Gregor  struct InferredDirectory {
1740e2c34f92f00628d48968dfea096d36381f494cbStephen Hines    InferredDirectory() : InferModules() {}
17582e52377bd76ed71e8c09edc5f2f452e388b16adDouglas Gregor
17682e52377bd76ed71e8c09edc5f2f452e388b16adDouglas Gregor    /// \brief Whether to infer modules from this directory.
17782e52377bd76ed71e8c09edc5f2f452e388b16adDouglas Gregor    unsigned InferModules : 1;
17882e52377bd76ed71e8c09edc5f2f452e388b16adDouglas Gregor
1790e2c34f92f00628d48968dfea096d36381f494cbStephen Hines    /// \brief The attributes to use for inferred modules.
1800e2c34f92f00628d48968dfea096d36381f494cbStephen Hines    Attributes Attrs;
18182e52377bd76ed71e8c09edc5f2f452e388b16adDouglas Gregor
1826bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    /// \brief If \c InferModules is non-zero, the module map file that allowed
1836bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    /// inferred modules.  Otherwise, nullptr.
1846bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    const FileEntry *ModuleMapFile;
1856bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
18682e52377bd76ed71e8c09edc5f2f452e388b16adDouglas Gregor    /// \brief The names of modules that cannot be inferred within this
18782e52377bd76ed71e8c09edc5f2f452e388b16adDouglas Gregor    /// directory.
188cfa88f893915ceb8ae4ce2f17c46c24a4d67502fDmitri Gribenko    SmallVector<std::string, 2> ExcludedModules;
18982e52377bd76ed71e8c09edc5f2f452e388b16adDouglas Gregor  };
19082e52377bd76ed71e8c09edc5f2f452e388b16adDouglas Gregor
19182e52377bd76ed71e8c09edc5f2f452e388b16adDouglas Gregor  /// \brief A mapping from directories to information about inferring
19282e52377bd76ed71e8c09edc5f2f452e388b16adDouglas Gregor  /// framework modules from within those directories.
19382e52377bd76ed71e8c09edc5f2f452e388b16adDouglas Gregor  llvm::DenseMap<const DirectoryEntry *, InferredDirectory> InferredDirectories;
19482e52377bd76ed71e8c09edc5f2f452e388b16adDouglas Gregor
195176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// A mapping from an inferred module to the module map that allowed the
196176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// inference.
197176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  llvm::DenseMap<const Module *, const FileEntry *> InferredModuleAllowedBy;
198176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
199176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  llvm::DenseMap<const Module *, AdditionalModMapsSet> AdditionalModMaps;
200176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
2017005b907ea159c8e74e81f85269777429bc18d3cDouglas Gregor  /// \brief Describes whether we haved parsed a particular file as a module
2027005b907ea159c8e74e81f85269777429bc18d3cDouglas Gregor  /// map.
2037005b907ea159c8e74e81f85269777429bc18d3cDouglas Gregor  llvm::DenseMap<const FileEntry *, bool> ParsedModuleMap;
2047005b907ea159c8e74e81f85269777429bc18d3cDouglas Gregor
205a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor  friend class ModuleMapParser;
206a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor
20790db26000aefe9335370013eec64c85232d80227Douglas Gregor  /// \brief Resolve the given export declaration into an actual export
20890db26000aefe9335370013eec64c85232d80227Douglas Gregor  /// declaration.
20990db26000aefe9335370013eec64c85232d80227Douglas Gregor  ///
21090db26000aefe9335370013eec64c85232d80227Douglas Gregor  /// \param Mod The module in which we're resolving the export declaration.
21190db26000aefe9335370013eec64c85232d80227Douglas Gregor  ///
21290db26000aefe9335370013eec64c85232d80227Douglas Gregor  /// \param Unresolved The export declaration to resolve.
21390db26000aefe9335370013eec64c85232d80227Douglas Gregor  ///
21490db26000aefe9335370013eec64c85232d80227Douglas Gregor  /// \param Complain Whether this routine should complain about unresolvable
21590db26000aefe9335370013eec64c85232d80227Douglas Gregor  /// exports.
21690db26000aefe9335370013eec64c85232d80227Douglas Gregor  ///
21790db26000aefe9335370013eec64c85232d80227Douglas Gregor  /// \returns The resolved export declaration, which will have a NULL pointer
21890db26000aefe9335370013eec64c85232d80227Douglas Gregor  /// if the export could not be resolved.
21990db26000aefe9335370013eec64c85232d80227Douglas Gregor  Module::ExportDecl
22090db26000aefe9335370013eec64c85232d80227Douglas Gregor  resolveExport(Module *Mod, const Module::UnresolvedExportDecl &Unresolved,
2210be5e567e3a48592fd6b11f88cc77efb20c76f26Argyrios Kyrtzidis                bool Complain) const;
222906d66acc5cf2679453e10a4f0a67feedd765b21Douglas Gregor
223906d66acc5cf2679453e10a4f0a67feedd765b21Douglas Gregor  /// \brief Resolve the given module id to an actual module.
224906d66acc5cf2679453e10a4f0a67feedd765b21Douglas Gregor  ///
225906d66acc5cf2679453e10a4f0a67feedd765b21Douglas Gregor  /// \param Id The module-id to resolve.
226906d66acc5cf2679453e10a4f0a67feedd765b21Douglas Gregor  ///
227906d66acc5cf2679453e10a4f0a67feedd765b21Douglas Gregor  /// \param Mod The module in which we're resolving the module-id.
228906d66acc5cf2679453e10a4f0a67feedd765b21Douglas Gregor  ///
229906d66acc5cf2679453e10a4f0a67feedd765b21Douglas Gregor  /// \param Complain Whether this routine should complain about unresolvable
230906d66acc5cf2679453e10a4f0a67feedd765b21Douglas Gregor  /// module-ids.
231906d66acc5cf2679453e10a4f0a67feedd765b21Douglas Gregor  ///
232906d66acc5cf2679453e10a4f0a67feedd765b21Douglas Gregor  /// \returns The resolved module, or null if the module-id could not be
233906d66acc5cf2679453e10a4f0a67feedd765b21Douglas Gregor  /// resolved.
234906d66acc5cf2679453e10a4f0a67feedd765b21Douglas Gregor  Module *resolveModuleId(const ModuleId &Id, Module *Mod, bool Complain) const;
235906d66acc5cf2679453e10a4f0a67feedd765b21Douglas Gregor
236651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// \brief Looks up the modules that \p File corresponds to.
237651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  ///
238651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// If \p File represents a builtin header within Clang's builtin include
239651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// directory, this also loads all of the module maps to see if it will get
240651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// associated with a specific module (e.g. in /usr/include).
241651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  HeadersMap::iterator findKnownHeader(const FileEntry *File);
242651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
2436bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  /// \brief Searches for a module whose umbrella directory contains \p File.
2446bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  ///
2456bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  /// \param File The header to search for.
2466bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  ///
2476bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  /// \param IntermediateDirs On success, contains the set of directories
2486bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  /// searched before finding \p File.
2496bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  KnownHeader findHeaderInUmbrellaDirs(const FileEntry *File,
2506bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines                    SmallVectorImpl<const DirectoryEntry *> &IntermediateDirs);
2516bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
252a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  /// \brief Given that \p File is not in the Headers map, look it up within
253a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  /// umbrella directories and find or create a module for it.
254a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  KnownHeader findOrCreateModuleForHeaderInUmbrellaDir(const FileEntry *File);
255a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar
2566bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  /// \brief A convenience method to determine if \p File is (possibly nested)
2576bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  /// in an umbrella directory.
2586bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  bool isHeaderInUmbrellaDirs(const FileEntry *File) {
2596bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    SmallVector<const DirectoryEntry *, 2> IntermediateDirs;
2606bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines    return static_cast<bool>(findHeaderInUmbrellaDirs(File, IntermediateDirs));
2616bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  }
2626bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
263a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  Module *inferFrameworkModule(const DirectoryEntry *FrameworkDir,
2640e2c34f92f00628d48968dfea096d36381f494cbStephen Hines                               Attributes Attrs, Module *Parent);
2650e2c34f92f00628d48968dfea096d36381f494cbStephen Hines
266a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregorpublic:
267a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor  /// \brief Construct a new module map.
268a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor  ///
269ee0cd37fe4a9f4e2ee73ae34cf93c410cb299a82Manuel Klimek  /// \param SourceMgr The source manager used to find module files and headers.
270ee0cd37fe4a9f4e2ee73ae34cf93c410cb299a82Manuel Klimek  /// This source manager should be shared with the header-search mechanism,
271ee0cd37fe4a9f4e2ee73ae34cf93c410cb299a82Manuel Klimek  /// since they will refer to the same headers.
272a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor  ///
273651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// \param Diags A diagnostic engine used for diagnostics.
27451f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor  ///
27551f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor  /// \param LangOpts Language options for this translation unit.
276dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor  ///
277dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor  /// \param Target The target for this translation unit.
278651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  ModuleMap(SourceManager &SourceMgr, DiagnosticsEngine &Diags,
27955ea75bf61a5d76f6453513d937944ce68181c6aArgyrios Kyrtzidis            const LangOptions &LangOpts, const TargetInfo *Target,
28055ea75bf61a5d76f6453513d937944ce68181c6aArgyrios Kyrtzidis            HeaderSearch &HeaderInfo);
28165f3b5e99009f49d51eb00a859dbd2c2ee660718Douglas Gregor
28265f3b5e99009f49d51eb00a859dbd2c2ee660718Douglas Gregor  /// \brief Destroy the module map.
28365f3b5e99009f49d51eb00a859dbd2c2ee660718Douglas Gregor  ///
284a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor  ~ModuleMap();
285dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor
286dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor  /// \brief Set the target information.
287dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor  void setTarget(const TargetInfo &Target);
288dc58aa71026cce539ca9b5c2c52cc4efc7bd77feDouglas Gregor
2892f04f1843ca0ffca13b8b0d4dadd1f50dffb38b8Douglas Gregor  /// \brief Set the directory that contains Clang-supplied include
2902f04f1843ca0ffca13b8b0d4dadd1f50dffb38b8Douglas Gregor  /// files, such as our stdarg.h or tgmath.h.
2912f04f1843ca0ffca13b8b0d4dadd1f50dffb38b8Douglas Gregor  void setBuiltinIncludeDir(const DirectoryEntry *Dir) {
2922f04f1843ca0ffca13b8b0d4dadd1f50dffb38b8Douglas Gregor    BuiltinIncludeDir = Dir;
2932f04f1843ca0ffca13b8b0d4dadd1f50dffb38b8Douglas Gregor  }
2942f04f1843ca0ffca13b8b0d4dadd1f50dffb38b8Douglas Gregor
295a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  /// \brief Add a module map callback.
296a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  void addModuleMapCallbacks(std::unique_ptr<ModuleMapCallbacks> Callback) {
297a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar    Callbacks.push_back(std::move(Callback));
298a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  }
299a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar
30065f3b5e99009f49d51eb00a859dbd2c2ee660718Douglas Gregor  /// \brief Retrieve the module that owns the given header file, if any.
30165f3b5e99009f49d51eb00a859dbd2c2ee660718Douglas Gregor  ///
30265f3b5e99009f49d51eb00a859dbd2c2ee660718Douglas Gregor  /// \param File The header file that is likely to be included.
30365f3b5e99009f49d51eb00a859dbd2c2ee660718Douglas Gregor  ///
304bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl  /// \returns The module KnownHeader, which provides the module that owns the
305bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl  /// given header file.  The KnownHeader is default constructed to indicate
30665f3b5e99009f49d51eb00a859dbd2c2ee660718Douglas Gregor  /// that no module owns this header file.
307b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar  KnownHeader findModuleForHeader(const FileEntry *File);
30865f3b5e99009f49d51eb00a859dbd2c2ee660718Douglas Gregor
309a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  /// \brief Retrieve all the modules that contain the given header file. This
310a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  /// may not include umbrella modules, nor information from external sources,
311a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  /// if they have not yet been inferred / loaded.
312a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  ///
313a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  /// Typically, \ref findModuleForHeader should be used instead, as it picks
314a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  /// the preferred module for the header.
315a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  ArrayRef<KnownHeader> findAllModulesForHeader(const FileEntry *File) const;
316a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar
317651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// \brief Reports errors if a module must not include a specific file.
318651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  ///
319651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// \param RequestingModule The module including a file.
320651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  ///
321651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// \param FilenameLoc The location of the inclusion's filename.
322651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  ///
323651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// \param Filename The included filename as written.
324651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  ///
325651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  /// \param File The included file.
326651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines  void diagnoseHeaderInclusion(Module *RequestingModule,
327651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines                               SourceLocation FilenameLoc, StringRef Filename,
328651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines                               const FileEntry *File);
329651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines
33051f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor  /// \brief Determine whether the given header is part of a module
33151f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor  /// marked 'unavailable'.
3320be5e567e3a48592fd6b11f88cc77efb20c76f26Argyrios Kyrtzidis  bool isHeaderInUnavailableModule(const FileEntry *Header) const;
33351f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor
3346bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  /// \brief Determine whether the given header is unavailable as part
3356bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  /// of the specified module.
3366bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  bool isHeaderUnavailableInModule(const FileEntry *Header,
3376bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines                                   const Module *RequestingModule) const;
3386bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines
339484535e45b4d301847a157e943c7823da5d40884Douglas Gregor  /// \brief Retrieve a module with the given name.
340484535e45b4d301847a157e943c7823da5d40884Douglas Gregor  ///
341260328c27ddbad6e6d81a84e68a9a4aedccbfbf3James Dennett  /// \param Name The name of the module to look up.
342484535e45b4d301847a157e943c7823da5d40884Douglas Gregor  ///
343484535e45b4d301847a157e943c7823da5d40884Douglas Gregor  /// \returns The named module, if known; otherwise, returns null.
3440be5e567e3a48592fd6b11f88cc77efb20c76f26Argyrios Kyrtzidis  Module *findModule(StringRef Name) const;
34590db26000aefe9335370013eec64c85232d80227Douglas Gregor
34690db26000aefe9335370013eec64c85232d80227Douglas Gregor  /// \brief Retrieve a module with the given name using lexical name lookup,
34790db26000aefe9335370013eec64c85232d80227Douglas Gregor  /// starting at the given context.
34890db26000aefe9335370013eec64c85232d80227Douglas Gregor  ///
349260328c27ddbad6e6d81a84e68a9a4aedccbfbf3James Dennett  /// \param Name The name of the module to look up.
35090db26000aefe9335370013eec64c85232d80227Douglas Gregor  ///
35190db26000aefe9335370013eec64c85232d80227Douglas Gregor  /// \param Context The module context, from which we will perform lexical
35290db26000aefe9335370013eec64c85232d80227Douglas Gregor  /// name lookup.
35390db26000aefe9335370013eec64c85232d80227Douglas Gregor  ///
35490db26000aefe9335370013eec64c85232d80227Douglas Gregor  /// \returns The named module, if known; otherwise, returns null.
3550be5e567e3a48592fd6b11f88cc77efb20c76f26Argyrios Kyrtzidis  Module *lookupModuleUnqualified(StringRef Name, Module *Context) const;
35690db26000aefe9335370013eec64c85232d80227Douglas Gregor
35790db26000aefe9335370013eec64c85232d80227Douglas Gregor  /// \brief Retrieve a module with the given name within the given context,
35890db26000aefe9335370013eec64c85232d80227Douglas Gregor  /// using direct (qualified) name lookup.
35990db26000aefe9335370013eec64c85232d80227Douglas Gregor  ///
3603d7e24e1887fade254cf8b304834f30de2f8d662James Dennett  /// \param Name The name of the module to look up.
36190db26000aefe9335370013eec64c85232d80227Douglas Gregor  ///
36290db26000aefe9335370013eec64c85232d80227Douglas Gregor  /// \param Context The module for which we will look for a submodule. If
36390db26000aefe9335370013eec64c85232d80227Douglas Gregor  /// null, we will look for a top-level module.
36490db26000aefe9335370013eec64c85232d80227Douglas Gregor  ///
36590db26000aefe9335370013eec64c85232d80227Douglas Gregor  /// \returns The named submodule, if known; otherwose, returns null.
3660be5e567e3a48592fd6b11f88cc77efb20c76f26Argyrios Kyrtzidis  Module *lookupModuleQualified(StringRef Name, Module *Context) const;
367484535e45b4d301847a157e943c7823da5d40884Douglas Gregor
368392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor  /// \brief Find a new module or submodule, or create it if it does not already
369392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor  /// exist.
370392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor  ///
371392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor  /// \param Name The name of the module to find or create.
372392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor  ///
373392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor  /// \param Parent The module that will act as the parent of this submodule,
374392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor  /// or NULL to indicate that this is a top-level module.
375392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor  ///
376392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor  /// \param IsFramework Whether this is a framework module.
377392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor  ///
378392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor  /// \param IsExplicit Whether this is an explicit submodule.
379392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor  ///
380392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor  /// \returns The found or newly-created module, along with a boolean value
381392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor  /// that will be true if the module is newly-created.
3826bcf27bb9a4b5c3f79cb44c0e4654a6d7619ad89Stephen Hines  std::pair<Module *, bool> findOrCreateModule(StringRef Name, Module *Parent,
383392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor                                               bool IsFramework,
384392ed2b717d86ebdd202cb9bb58d18d8b3b4cd87Douglas Gregor                                               bool IsExplicit);
38582e52377bd76ed71e8c09edc5f2f452e388b16adDouglas Gregor
3862821c7f8870629b56b9c41e1c50c7a091edd544dDouglas Gregor  /// \brief Infer the contents of a framework module map from the given
3872821c7f8870629b56b9c41e1c50c7a091edd544dDouglas Gregor  /// framework directory.
388a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  Module *inferFrameworkModule(const DirectoryEntry *FrameworkDir,
389a1f1fad8b60e1cb9d21a40a37f2e03150bcbeb6fDouglas Gregor                               bool IsSystem, Module *Parent);
390a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar
391f9e357d8a66c606a86a6e1aef678898b8843bd30Douglas Gregor  /// \brief Retrieve the module map file containing the definition of the given
392f9e357d8a66c606a86a6e1aef678898b8843bd30Douglas Gregor  /// module.
393f9e357d8a66c606a86a6e1aef678898b8843bd30Douglas Gregor  ///
394f9e357d8a66c606a86a6e1aef678898b8843bd30Douglas Gregor  /// \param Module The module whose module map file will be returned, if known.
395f9e357d8a66c606a86a6e1aef678898b8843bd30Douglas Gregor  ///
396f9e357d8a66c606a86a6e1aef678898b8843bd30Douglas Gregor  /// \returns The file entry for the module map file containing the given
397f9e357d8a66c606a86a6e1aef678898b8843bd30Douglas Gregor  /// module, or NULL if the module definition was inferred.
398176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  const FileEntry *getContainingModuleMapFile(const Module *Module) const;
399176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
400176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// \brief Get the module map file that (along with the module name) uniquely
401176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// identifies this module.
402176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  ///
403176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// The particular module that \c Name refers to may depend on how the module
404176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// was found in header search. However, the combination of \c Name and
405176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// this module map will be globally unique for top-level modules. In the case
406176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// of inferred modules, returns the module map that allowed the inference
407176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// (e.g. contained 'module *'). Otherwise, returns
408176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// getContainingModuleMapFile().
409176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  const FileEntry *getModuleMapFileForUniquing(const Module *M) const;
410176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
411176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  void setInferredModuleAllowedBy(Module *M, const FileEntry *ModuleMap);
412176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
413176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// \brief Get any module map files other than getModuleMapFileForUniquing(M)
414176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// that define submodules of a top-level module \p M. This is cheaper than
415176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// getting the module map file for each submodule individually, since the
416176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// expected number of results is very small.
417176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  AdditionalModMapsSet *getAdditionalModuleMapFiles(const Module *M) {
418176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    auto I = AdditionalModMaps.find(M);
419176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    if (I == AdditionalModMaps.end())
420176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines      return nullptr;
421176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    return &I->second;
422176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  }
423176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
424176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  void addAdditionalModuleMapFile(const Module *M, const FileEntry *ModuleMap) {
425176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines    AdditionalModMaps[M].insert(ModuleMap);
426176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  }
42790db26000aefe9335370013eec64c85232d80227Douglas Gregor
42890db26000aefe9335370013eec64c85232d80227Douglas Gregor  /// \brief Resolve all of the unresolved exports in the given module.
42990db26000aefe9335370013eec64c85232d80227Douglas Gregor  ///
43090db26000aefe9335370013eec64c85232d80227Douglas Gregor  /// \param Mod The module whose exports should be resolved.
43190db26000aefe9335370013eec64c85232d80227Douglas Gregor  ///
43290db26000aefe9335370013eec64c85232d80227Douglas Gregor  /// \param Complain Whether to emit diagnostics for failures.
43390db26000aefe9335370013eec64c85232d80227Douglas Gregor  ///
43490db26000aefe9335370013eec64c85232d80227Douglas Gregor  /// \returns true if any errors were encountered while resolving exports,
43590db26000aefe9335370013eec64c85232d80227Douglas Gregor  /// false otherwise.
43690db26000aefe9335370013eec64c85232d80227Douglas Gregor  bool resolveExports(Module *Mod, bool Complain);
43790db26000aefe9335370013eec64c85232d80227Douglas Gregor
438ddd2dfc1d3f4a36cbe8cd775c588623a17049f9fDaniel Jasper  /// \brief Resolve all of the unresolved uses in the given module.
439ddd2dfc1d3f4a36cbe8cd775c588623a17049f9fDaniel Jasper  ///
440ddd2dfc1d3f4a36cbe8cd775c588623a17049f9fDaniel Jasper  /// \param Mod The module whose uses should be resolved.
441ddd2dfc1d3f4a36cbe8cd775c588623a17049f9fDaniel Jasper  ///
442ddd2dfc1d3f4a36cbe8cd775c588623a17049f9fDaniel Jasper  /// \param Complain Whether to emit diagnostics for failures.
443ddd2dfc1d3f4a36cbe8cd775c588623a17049f9fDaniel Jasper  ///
444ddd2dfc1d3f4a36cbe8cd775c588623a17049f9fDaniel Jasper  /// \returns true if any errors were encountered while resolving uses,
445ddd2dfc1d3f4a36cbe8cd775c588623a17049f9fDaniel Jasper  /// false otherwise.
446ddd2dfc1d3f4a36cbe8cd775c588623a17049f9fDaniel Jasper  bool resolveUses(Module *Mod, bool Complain);
447ddd2dfc1d3f4a36cbe8cd775c588623a17049f9fDaniel Jasper
448906d66acc5cf2679453e10a4f0a67feedd765b21Douglas Gregor  /// \brief Resolve all of the unresolved conflicts in the given module.
449906d66acc5cf2679453e10a4f0a67feedd765b21Douglas Gregor  ///
450906d66acc5cf2679453e10a4f0a67feedd765b21Douglas Gregor  /// \param Mod The module whose conflicts should be resolved.
451906d66acc5cf2679453e10a4f0a67feedd765b21Douglas Gregor  ///
452906d66acc5cf2679453e10a4f0a67feedd765b21Douglas Gregor  /// \param Complain Whether to emit diagnostics for failures.
453906d66acc5cf2679453e10a4f0a67feedd765b21Douglas Gregor  ///
454906d66acc5cf2679453e10a4f0a67feedd765b21Douglas Gregor  /// \returns true if any errors were encountered while resolving conflicts,
455906d66acc5cf2679453e10a4f0a67feedd765b21Douglas Gregor  /// false otherwise.
456906d66acc5cf2679453e10a4f0a67feedd765b21Douglas Gregor  bool resolveConflicts(Module *Mod, bool Complain);
457906d66acc5cf2679453e10a4f0a67feedd765b21Douglas Gregor
458906d66acc5cf2679453e10a4f0a67feedd765b21Douglas Gregor  /// \brief Infers the (sub)module based on the given source location and
45955988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor  /// source manager.
46055988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor  ///
46155988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor  /// \param Loc The location within the source that we are querying, along
46255988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor  /// with its source manager.
46355988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor  ///
46455988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor  /// \returns The module that owns this source location, or null if no
46555988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor  /// module owns this source location.
46655988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor  Module *inferModuleFromLocation(FullSourceLoc Loc);
46755988680ece66b8e505ee136b35e74fcb1173aeeDouglas Gregor
468e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregor  /// \brief Sets the umbrella header of the given module to the given
469e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregor  /// header.
470b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar  void setUmbrellaHeader(Module *Mod, const FileEntry *UmbrellaHeader,
471b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar                         Twine NameAsWritten);
47277d029f6a24dbf70d97e61757945df53fb250ea0Douglas Gregor
47377d029f6a24dbf70d97e61757945df53fb250ea0Douglas Gregor  /// \brief Sets the umbrella directory of the given module to the given
47477d029f6a24dbf70d97e61757945df53fb250ea0Douglas Gregor  /// directory.
475b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar  void setUmbrellaDir(Module *Mod, const DirectoryEntry *UmbrellaDir,
476b6d6993e6e6d3daf4d9876794254d20a134e37c2Pirama Arumuga Nainar                      Twine NameAsWritten);
47777d029f6a24dbf70d97e61757945df53fb250ea0Douglas Gregor
478e209e5026892cb07294f733c72bd51359c0f0e72Douglas Gregor  /// \brief Adds this header to the given module.
479bc3f628815b3841dc99109e7f67f9afa7793bc94Lawrence Crowl  /// \param Role The role of the header wrt the module.
4800e2c34f92f00628d48968dfea096d36381f494cbStephen Hines  void addHeader(Module *Mod, Module::Header Header,
481a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar                 ModuleHeaderRole Role, bool Imported = false);
48251f564f80d9f71e175635b452ffeeeff899e9bf1Douglas Gregor
483176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines  /// \brief Marks this header as being excluded from the given module.
4840e2c34f92f00628d48968dfea096d36381f494cbStephen Hines  void excludeHeader(Module *Mod, Module::Header Header);
485176edba5311f6eff0cad2631449885ddf4fbc9eaStephen Hines
486a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor  /// \brief Parse the given module map file, and record any modules we
487a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor  /// encounter.
488a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor  ///
489a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor  /// \param File The file to be parsed.
490a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor  ///
4918f5d7d1d1f990f174c7f2682271a83acf64dd93dDouglas Gregor  /// \param IsSystem Whether this module map file is in a system header
4928f5d7d1d1f990f174c7f2682271a83acf64dd93dDouglas Gregor  /// directory, and therefore should be considered a system module.
4938f5d7d1d1f990f174c7f2682271a83acf64dd93dDouglas Gregor  ///
4940e2c34f92f00628d48968dfea096d36381f494cbStephen Hines  /// \param HomeDir The directory in which relative paths within this module
4950e2c34f92f00628d48968dfea096d36381f494cbStephen Hines  ///        map file will be resolved.
4960e2c34f92f00628d48968dfea096d36381f494cbStephen Hines  ///
497a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  /// \param ExternModuleLoc The location of the "extern module" declaration
498a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  ///        that caused us to load this module map file, if any.
499a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar  ///
500a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor  /// \returns true if an error occurred, false otherwise.
5010e2c34f92f00628d48968dfea096d36381f494cbStephen Hines  bool parseModuleMapFile(const FileEntry *File, bool IsSystem,
502a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar                          const DirectoryEntry *HomeDir,
503a4de17562d13d7a8188108243c4cfbd52f33229aPirama Arumuga Nainar                          SourceLocation ExternModuleLoc = SourceLocation());
50465f3b5e99009f49d51eb00a859dbd2c2ee660718Douglas Gregor
505a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor  /// \brief Dump the contents of the module map, for debugging purposes.
506a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor  void dump();
507c5b2e58840748145d1706c1d1481369d1863fabfDouglas Gregor
508c5b2e58840748145d1706c1d1481369d1863fabfDouglas Gregor  typedef llvm::StringMap<Module *>::const_iterator module_iterator;
509c5b2e58840748145d1706c1d1481369d1863fabfDouglas Gregor  module_iterator module_begin() const { return Modules.begin(); }
510c5b2e58840748145d1706c1d1481369d1863fabfDouglas Gregor  module_iterator module_end()   const { return Modules.end(); }
511a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor};
512a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor
513a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor}
514a30cfe5026b12c28b7b575b48176e0a3543ce939Douglas Gregor#endif
515