Coverage Report

Created: 2018-11-16 02:38

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/Lex/ModuleMap.h
Line
Count
Source (jump to first uncovered line)
1
//===- ModuleMap.h - Describe the layout of modules -------------*- C++ -*-===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
// This file defines the ModuleMap interface, which describes the layout of a
11
// module as it relates to headers.
12
//
13
//===----------------------------------------------------------------------===//
14
15
#ifndef LLVM_CLANG_LEX_MODULEMAP_H
16
#define LLVM_CLANG_LEX_MODULEMAP_H
17
18
#include "clang/Basic/LangOptions.h"
19
#include "clang/Basic/Module.h"
20
#include "clang/Basic/SourceLocation.h"
21
#include "llvm/ADT/ArrayRef.h"
22
#include "llvm/ADT/DenseMap.h"
23
#include "llvm/ADT/PointerIntPair.h"
24
#include "llvm/ADT/StringSet.h"
25
#include "llvm/ADT/SmallPtrSet.h"
26
#include "llvm/ADT/SmallVector.h"
27
#include "llvm/ADT/StringMap.h"
28
#include "llvm/ADT/StringRef.h"
29
#include "llvm/ADT/TinyPtrVector.h"
30
#include "llvm/ADT/Twine.h"
31
#include <ctime>
32
#include <memory>
33
#include <string>
34
#include <utility>
35
36
namespace clang {
37
38
class DiagnosticsEngine;
39
class DirectoryEntry;
40
class FileEntry;
41
class FileManager;
42
class HeaderSearch;
43
class SourceManager;
44
45
/// A mechanism to observe the actions of the module map parser as it
46
/// reads module map files.
47
class ModuleMapCallbacks {
48
public:
49
136
  virtual ~ModuleMapCallbacks() = default;
50
51
  /// Called when a module map file has been read.
52
  ///
53
  /// \param FileStart A SourceLocation referring to the start of the file's
54
  /// contents.
55
  /// \param File The file itself.
56
  /// \param IsSystem Whether this is a module map from a system include path.
57
  virtual void moduleMapFileRead(SourceLocation FileStart,
58
42
                                 const FileEntry &File, bool IsSystem) {}
59
60
  /// Called when a header is added during module map parsing.
61
  ///
62
  /// \param Filename The header file itself.
63
588
  virtual void moduleMapAddHeader(StringRef Filename) {}
64
65
  /// Called when an umbrella header is added during module map parsing.
66
  ///
67
  /// \param FileMgr FileManager instance
68
  /// \param Header The umbrella header to collect.
69
  virtual void moduleMapAddUmbrellaHeader(FileManager *FileMgr,
70
2
                                          const FileEntry *Header) {}
71
};
72
73
class ModuleMap {
74
  SourceManager &SourceMgr;
75
  DiagnosticsEngine &Diags;
76
  const LangOptions &LangOpts;
77
  const TargetInfo *Target;
78
  HeaderSearch &HeaderInfo;
79
80
  llvm::SmallVector<std::unique_ptr<ModuleMapCallbacks>, 1> Callbacks;
81
82
  /// The directory used for Clang-supplied, builtin include headers,
83
  /// such as "stdint.h".
84
  const DirectoryEntry *BuiltinIncludeDir = nullptr;
85
86
  /// Language options used to parse the module map itself.
87
  ///
88
  /// These are always simple C language options.
89
  LangOptions MMapLangOpts;
90
91
  /// The module that the main source file is associated with (the module
92
  /// named LangOpts::CurrentModule, if we've loaded it).
93
  Module *SourceModule = nullptr;
94
95
  /// Submodules of the current module that have not yet been attached to it.
96
  /// (Ownership is transferred if/when we create an enclosing module.)
97
  llvm::SmallVector<std::unique_ptr<Module>, 8> PendingSubmodules;
98
99
  /// The top-level modules that are known.
100
  llvm::StringMap<Module *> Modules;
101
102
  /// Shadow modules created while building this module map.
103
  llvm::SmallVector<Module*, 2> ShadowModules;
104
105
  /// The number of modules we have created in total.
106
  unsigned NumCreatedModules = 0;
107
108
  /// In case a module has a export_as entry, it might have a pending link
109
  /// name to be determined if that module is imported.
110
  llvm::StringMap<llvm::StringSet<>> PendingLinkAsModule;
111
112
public:
113
  /// Use PendingLinkAsModule information to mark top level link names that
114
  /// are going to be replaced by export_as aliases.
115
  void resolveLinkAsDependencies(Module *Mod);
116
117
  /// Make module to use export_as as the link dependency name if enough
118
  /// information is available or add it to a pending list otherwise.
119
  void addLinkAsDependency(Module *Mod);
120
121
  /// Flags describing the role of a module header.
122
  enum ModuleHeaderRole {
123
    /// This header is normally included in the module.
124
    NormalHeader  = 0x0,
125
126
    /// This header is included but private.
127
    PrivateHeader = 0x1,
128
129
    /// This header is part of the module (for layering purposes) but
130
    /// should be textually included.
131
    TextualHeader = 0x2,
132
133
    // Caution: Adding an enumerator needs other changes.
134
    // Adjust the number of bits for KnownHeader::Storage.
135
    // Adjust the bitfield HeaderFileInfo::HeaderRole size.
136
    // Adjust the HeaderFileInfoTrait::ReadData streaming.
137
    // Adjust the HeaderFileInfoTrait::EmitData streaming.
138
    // Adjust ModuleMap::addHeader.
139
  };
140
141
  /// Convert a header kind to a role. Requires Kind to not be HK_Excluded.
142
  static ModuleHeaderRole headerKindToRole(Module::HeaderKind Kind);
143
144
  /// Convert a header role to a kind.
145
  static Module::HeaderKind headerRoleToKind(ModuleHeaderRole Role);
146
147
  /// A header that is known to reside within a given module,
148
  /// whether it was included or excluded.
149
  class KnownHeader {
150
    llvm::PointerIntPair<Module *, 2, ModuleHeaderRole> Storage;
151
152
  public:
153
7.86M
    KnownHeader() : Storage(nullptr, NormalHeader) {}
154
96.6k
    KnownHeader(Module *M, ModuleHeaderRole Role) : Storage(M, Role) {}
155
156
3.47k
    friend bool operator==(const KnownHeader &A, const KnownHeader &B) {
157
3.47k
      return A.Storage == B.Storage;
158
3.47k
    }
159
0
    friend bool operator!=(const KnownHeader &A, const KnownHeader &B) {
160
0
      return A.Storage != B.Storage;
161
0
    }
162
163
    /// Retrieve the module the header is stored in.
164
3.98M
    Module *getModule() const { return Storage.getPointer(); }
165
166
    /// The role of this header within the module.
167
1.96M
    ModuleHeaderRole getRole() const { return Storage.getInt(); }
168
169
    /// Whether this header is available in the module.
170
82
    bool isAvailable() const {
171
82
      return getModule()->isAvailable();
172
82
    }
173
174
    /// Whether this header is accessible from the specified module.
175
4.43k
    bool isAccessibleFrom(Module *M) const {
176
4.43k
      return !(getRole() & PrivateHeader) ||
177
4.43k
             
(62
M62
&&
M->getTopLevelModule() == getModule()->getTopLevelModule()46
);
178
4.43k
    }
179
180
    // Whether this known header is valid (i.e., it has an
181
    // associated module).
182
3.92M
    explicit operator bool() const {
183
3.92M
      return Storage.getPointer() != nullptr;
184
3.92M
    }
185
  };
186
187
  using AdditionalModMapsSet = llvm::SmallPtrSet<const FileEntry *, 1>;
188
189
private:
190
  friend class ModuleMapParser;
191
192
  using HeadersMap =
193
      llvm::DenseMap<const FileEntry *, SmallVector<KnownHeader, 1>>;
194
195
  /// Mapping from each header to the module that owns the contents of
196
  /// that header.
197
  HeadersMap Headers;
198
199
  /// Map from file sizes to modules with lazy header directives of that size.
200
  mutable llvm::DenseMap<off_t, llvm::TinyPtrVector<Module*>> LazyHeadersBySize;
201
202
  /// Map from mtimes to modules with lazy header directives with those mtimes.
203
  mutable llvm::DenseMap<time_t, llvm::TinyPtrVector<Module*>>
204
              LazyHeadersByModTime;
205
206
  /// Mapping from directories with umbrella headers to the module
207
  /// that is generated from the umbrella header.
208
  ///
209
  /// This mapping is used to map headers that haven't explicitly been named
210
  /// in the module map over to the module that includes them via its umbrella
211
  /// header.
212
  llvm::DenseMap<const DirectoryEntry *, Module *> UmbrellaDirs;
213
214
  /// A generation counter that is used to test whether modules of the
215
  /// same name may shadow or are illegal redefinitions.
216
  ///
217
  /// Modules from earlier scopes may shadow modules from later ones.
218
  /// Modules from the same scope may not have the same name.
219
  unsigned CurrentModuleScopeID = 0;
220
221
  llvm::DenseMap<Module *, unsigned> ModuleScopeIDs;
222
223
  /// The set of attributes that can be attached to a module.
224
  struct Attributes {
225
    /// Whether this is a system module.
226
    unsigned IsSystem : 1;
227
228
    /// Whether this is an extern "C" module.
229
    unsigned IsExternC : 1;
230
231
    /// Whether this is an exhaustive set of configuration macros.
232
    unsigned IsExhaustive : 1;
233
234
    /// Whether files in this module can only include non-modular headers
235
    /// and headers from used modules.
236
    unsigned NoUndeclaredIncludes : 1;
237
238
    Attributes()
239
        : IsSystem(false), IsExternC(false), IsExhaustive(false),
240
113k
          NoUndeclaredIncludes(false) {}
241
  };
242
243
  /// A directory for which framework modules can be inferred.
244
  struct InferredDirectory {
245
    /// Whether to infer modules from this directory.
246
    unsigned InferModules : 1;
247
248
    /// The attributes to use for inferred modules.
249
    Attributes Attrs;
250
251
    /// If \c InferModules is non-zero, the module map file that allowed
252
    /// inferred modules.  Otherwise, nullptr.
253
    const FileEntry *ModuleMapFile;
254
255
    /// The names of modules that cannot be inferred within this
256
    /// directory.
257
    SmallVector<std::string, 2> ExcludedModules;
258
259
654
    InferredDirectory() : InferModules(false) {}
260
  };
261
262
  /// A mapping from directories to information about inferring
263
  /// framework modules from within those directories.
264
  llvm::DenseMap<const DirectoryEntry *, InferredDirectory> InferredDirectories;
265
266
  /// A mapping from an inferred module to the module map that allowed the
267
  /// inference.
268
  llvm::DenseMap<const Module *, const FileEntry *> InferredModuleAllowedBy;
269
270
  llvm::DenseMap<const Module *, AdditionalModMapsSet> AdditionalModMaps;
271
272
  /// Describes whether we haved parsed a particular file as a module
273
  /// map.
274
  llvm::DenseMap<const FileEntry *, bool> ParsedModuleMap;
275
276
  /// Resolve the given export declaration into an actual export
277
  /// declaration.
278
  ///
279
  /// \param Mod The module in which we're resolving the export declaration.
280
  ///
281
  /// \param Unresolved The export declaration to resolve.
282
  ///
283
  /// \param Complain Whether this routine should complain about unresolvable
284
  /// exports.
285
  ///
286
  /// \returns The resolved export declaration, which will have a NULL pointer
287
  /// if the export could not be resolved.
288
  Module::ExportDecl
289
  resolveExport(Module *Mod, const Module::UnresolvedExportDecl &Unresolved,
290
                bool Complain) const;
291
292
  /// Resolve the given module id to an actual module.
293
  ///
294
  /// \param Id The module-id to resolve.
295
  ///
296
  /// \param Mod The module in which we're resolving the module-id.
297
  ///
298
  /// \param Complain Whether this routine should complain about unresolvable
299
  /// module-ids.
300
  ///
301
  /// \returns The resolved module, or null if the module-id could not be
302
  /// resolved.
303
  Module *resolveModuleId(const ModuleId &Id, Module *Mod, bool Complain) const;
304
305
  /// Add an unresolved header to a module.
306
  ///
307
  /// \param Mod The module in which we're adding the unresolved header
308
  ///        directive.
309
  /// \param Header The unresolved header directive.
310
  /// \param NeedsFramework If Mod is not a framework but a missing header would
311
  ///        be found in case Mod was, set it to true. False otherwise.
312
  void addUnresolvedHeader(Module *Mod,
313
                           Module::UnresolvedHeaderDirective Header,
314
                           bool &NeedsFramework);
315
316
  /// Look up the given header directive to find an actual header file.
317
  ///
318
  /// \param M The module in which we're resolving the header directive.
319
  /// \param Header The header directive to resolve.
320
  /// \param RelativePathName Filled in with the relative path name from the
321
  ///        module to the resolved header.
322
  /// \param NeedsFramework If M is not a framework but a missing header would
323
  ///        be found in case M was, set it to true. False otherwise.
324
  /// \return The resolved file, if any.
325
  const FileEntry *findHeader(Module *M,
326
                              const Module::UnresolvedHeaderDirective &Header,
327
                              SmallVectorImpl<char> &RelativePathName,
328
                              bool &NeedsFramework);
329
330
  /// Resolve the given header directive.
331
  ///
332
  /// \param M The module in which we're resolving the header directive.
333
  /// \param Header The header directive to resolve.
334
  /// \param NeedsFramework If M is not a framework but a missing header would
335
  ///        be found in case M was, set it to true. False otherwise.
336
  void resolveHeader(Module *M, const Module::UnresolvedHeaderDirective &Header,
337
                     bool &NeedsFramework);
338
339
  /// Attempt to resolve the specified header directive as naming a builtin
340
  /// header.
341
  /// \return \c true if a corresponding builtin header was found.
342
  bool resolveAsBuiltinHeader(Module *M,
343
                              const Module::UnresolvedHeaderDirective &Header);
344
345
  /// Looks up the modules that \p File corresponds to.
346
  ///
347
  /// If \p File represents a builtin header within Clang's builtin include
348
  /// directory, this also loads all of the module maps to see if it will get
349
  /// associated with a specific module (e.g. in /usr/include).
350
  HeadersMap::iterator findKnownHeader(const FileEntry *File);
351
352
  /// Searches for a module whose umbrella directory contains \p File.
353
  ///
354
  /// \param File The header to search for.
355
  ///
356
  /// \param IntermediateDirs On success, contains the set of directories
357
  /// searched before finding \p File.
358
  KnownHeader findHeaderInUmbrellaDirs(const FileEntry *File,
359
                    SmallVectorImpl<const DirectoryEntry *> &IntermediateDirs);
360
361
  /// Given that \p File is not in the Headers map, look it up within
362
  /// umbrella directories and find or create a module for it.
363
  KnownHeader findOrCreateModuleForHeaderInUmbrellaDir(const FileEntry *File);
364
365
  /// A convenience method to determine if \p File is (possibly nested)
366
  /// in an umbrella directory.
367
980k
  bool isHeaderInUmbrellaDirs(const FileEntry *File) {
368
980k
    SmallVector<const DirectoryEntry *, 2> IntermediateDirs;
369
980k
    return static_cast<bool>(findHeaderInUmbrellaDirs(File, IntermediateDirs));
370
980k
  }
371
372
  Module *inferFrameworkModule(const DirectoryEntry *FrameworkDir,
373
                               Attributes Attrs, Module *Parent);
374
375
public:
376
  /// Construct a new module map.
377
  ///
378
  /// \param SourceMgr The source manager used to find module files and headers.
379
  /// This source manager should be shared with the header-search mechanism,
380
  /// since they will refer to the same headers.
381
  ///
382
  /// \param Diags A diagnostic engine used for diagnostics.
383
  ///
384
  /// \param LangOpts Language options for this translation unit.
385
  ///
386
  /// \param Target The target for this translation unit.
387
  ModuleMap(SourceManager &SourceMgr, DiagnosticsEngine &Diags,
388
            const LangOptions &LangOpts, const TargetInfo *Target,
389
            HeaderSearch &HeaderInfo);
390
391
  /// Destroy the module map.
392
  ~ModuleMap();
393
394
  /// Set the target information.
395
  void setTarget(const TargetInfo &Target);
396
397
  /// Set the directory that contains Clang-supplied include
398
  /// files, such as our stdarg.h or tgmath.h.
399
35.4k
  void setBuiltinIncludeDir(const DirectoryEntry *Dir) {
400
35.4k
    BuiltinIncludeDir = Dir;
401
35.4k
  }
402
403
  /// Get the directory that contains Clang-supplied include files.
404
80
  const DirectoryEntry *getBuiltinDir() const {
405
80
    return BuiltinIncludeDir;
406
80
  }
407
408
  /// Is this a compiler builtin header?
409
  static bool isBuiltinHeader(StringRef FileName);
410
411
  /// Add a module map callback.
412
8.82k
  void addModuleMapCallbacks(std::unique_ptr<ModuleMapCallbacks> Callback) {
413
8.82k
    Callbacks.push_back(std::move(Callback));
414
8.82k
  }
415
416
  /// Retrieve the module that owns the given header file, if any.
417
  ///
418
  /// \param File The header file that is likely to be included.
419
  ///
420
  /// \param AllowTextual If \c true and \p File is a textual header, return
421
  /// its owning module. Otherwise, no KnownHeader will be returned if the
422
  /// file is only known as a textual header.
423
  ///
424
  /// \returns The module KnownHeader, which provides the module that owns the
425
  /// given header file.  The KnownHeader is default constructed to indicate
426
  /// that no module owns this header file.
427
  KnownHeader findModuleForHeader(const FileEntry *File,
428
                                  bool AllowTextual = false);
429
430
  /// Retrieve all the modules that contain the given header file. This
431
  /// may not include umbrella modules, nor information from external sources,
432
  /// if they have not yet been inferred / loaded.
433
  ///
434
  /// Typically, \ref findModuleForHeader should be used instead, as it picks
435
  /// the preferred module for the header.
436
  ArrayRef<KnownHeader> findAllModulesForHeader(const FileEntry *File) const;
437
438
  /// Resolve all lazy header directives for the specified file.
439
  ///
440
  /// This ensures that the HeaderFileInfo on HeaderSearch is up to date. This
441
  /// is effectively internal, but is exposed so HeaderSearch can call it.
442
  void resolveHeaderDirectives(const FileEntry *File) const;
443
444
  /// Resolve all lazy header directives for the specified module.
445
  void resolveHeaderDirectives(Module *Mod) const;
446
447
  /// Reports errors if a module must not include a specific file.
448
  ///
449
  /// \param RequestingModule The module including a file.
450
  ///
451
  /// \param RequestingModuleIsModuleInterface \c true if the inclusion is in
452
  ///        the interface of RequestingModule, \c false if it's in the
453
  ///        implementation of RequestingModule. Value is ignored and
454
  ///        meaningless if RequestingModule is nullptr.
455
  ///
456
  /// \param FilenameLoc The location of the inclusion's filename.
457
  ///
458
  /// \param Filename The included filename as written.
459
  ///
460
  /// \param File The included file.
461
  void diagnoseHeaderInclusion(Module *RequestingModule,
462
                               bool RequestingModuleIsModuleInterface,
463
                               SourceLocation FilenameLoc, StringRef Filename,
464
                               const FileEntry *File);
465
466
  /// Determine whether the given header is part of a module
467
  /// marked 'unavailable'.
468
  bool isHeaderInUnavailableModule(const FileEntry *Header) const;
469
470
  /// Determine whether the given header is unavailable as part
471
  /// of the specified module.
472
  bool isHeaderUnavailableInModule(const FileEntry *Header,
473
                                   const Module *RequestingModule) const;
474
475
  /// Retrieve a module with the given name.
476
  ///
477
  /// \param Name The name of the module to look up.
478
  ///
479
  /// \returns The named module, if known; otherwise, returns null.
480
  Module *findModule(StringRef Name) const;
481
482
  /// Retrieve a module with the given name using lexical name lookup,
483
  /// starting at the given context.
484
  ///
485
  /// \param Name The name of the module to look up.
486
  ///
487
  /// \param Context The module context, from which we will perform lexical
488
  /// name lookup.
489
  ///
490
  /// \returns The named module, if known; otherwise, returns null.
491
  Module *lookupModuleUnqualified(StringRef Name, Module *Context) const;
492
493
  /// Retrieve a module with the given name within the given context,
494
  /// using direct (qualified) name lookup.
495
  ///
496
  /// \param Name The name of the module to look up.
497
  ///
498
  /// \param Context The module for which we will look for a submodule. If
499
  /// null, we will look for a top-level module.
500
  ///
501
  /// \returns The named submodule, if known; otherwose, returns null.
502
  Module *lookupModuleQualified(StringRef Name, Module *Context) const;
503
504
  /// Find a new module or submodule, or create it if it does not already
505
  /// exist.
506
  ///
507
  /// \param Name The name of the module to find or create.
508
  ///
509
  /// \param Parent The module that will act as the parent of this submodule,
510
  /// or nullptr to indicate that this is a top-level module.
511
  ///
512
  /// \param IsFramework Whether this is a framework module.
513
  ///
514
  /// \param IsExplicit Whether this is an explicit submodule.
515
  ///
516
  /// \returns The found or newly-created module, along with a boolean value
517
  /// that will be true if the module is newly-created.
518
  std::pair<Module *, bool> findOrCreateModule(StringRef Name, Module *Parent,
519
                                               bool IsFramework,
520
                                               bool IsExplicit);
521
522
  /// Create a 'global module' for a C++ Modules TS module interface unit.
523
  ///
524
  /// We model the global module as a submodule of the module interface unit.
525
  /// Unfortunately, we can't create the module interface unit's Module until
526
  /// later, because we don't know what it will be called.
527
  Module *createGlobalModuleForInterfaceUnit(SourceLocation Loc);
528
529
  /// Create a new module for a C++ Modules TS module interface unit.
530
  /// The module must not already exist, and will be configured for the current
531
  /// compilation.
532
  ///
533
  /// Note that this also sets the current module to the newly-created module.
534
  ///
535
  /// \returns The newly-created module.
536
  Module *createModuleForInterfaceUnit(SourceLocation Loc, StringRef Name,
537
                                       Module *GlobalModule);
538
539
  /// Create a header module from the specified list of headers.
540
  Module *createHeaderModule(StringRef Name, ArrayRef<Module::Header> Headers);
541
542
  /// Infer the contents of a framework module map from the given
543
  /// framework directory.
544
  Module *inferFrameworkModule(const DirectoryEntry *FrameworkDir,
545
                               bool IsSystem, Module *Parent);
546
547
  /// Create a new top-level module that is shadowed by
548
  /// \p ShadowingModule.
549
  Module *createShadowedModule(StringRef Name, bool IsFramework,
550
                               Module *ShadowingModule);
551
552
  /// Creates a new declaration scope for module names, allowing
553
  /// previously defined modules to shadow definitions from the new scope.
554
  ///
555
  /// \note Module names from earlier scopes will shadow names from the new
556
  /// scope, which is the opposite of how shadowing works for variables.
557
40.0k
  void finishModuleDeclarationScope() { CurrentModuleScopeID += 1; }
558
559
161
  bool mayShadowNewModule(Module *ExistingModule) {
560
161
    assert(!ExistingModule->Parent && "expected top-level module");
561
161
    assert(ModuleScopeIDs.count(ExistingModule) && "unknown module");
562
161
    return ModuleScopeIDs[ExistingModule] < CurrentModuleScopeID;
563
161
  }
564
565
  /// Retrieve the module map file containing the definition of the given
566
  /// module.
567
  ///
568
  /// \param Module The module whose module map file will be returned, if known.
569
  ///
570
  /// \returns The file entry for the module map file containing the given
571
  /// module, or nullptr if the module definition was inferred.
572
  const FileEntry *getContainingModuleMapFile(const Module *Module) const;
573
574
  /// Get the module map file that (along with the module name) uniquely
575
  /// identifies this module.
576
  ///
577
  /// The particular module that \c Name refers to may depend on how the module
578
  /// was found in header search. However, the combination of \c Name and
579
  /// this module map will be globally unique for top-level modules. In the case
580
  /// of inferred modules, returns the module map that allowed the inference
581
  /// (e.g. contained 'module *'). Otherwise, returns
582
  /// getContainingModuleMapFile().
583
  const FileEntry *getModuleMapFileForUniquing(const Module *M) const;
584
585
  void setInferredModuleAllowedBy(Module *M, const FileEntry *ModMap);
586
587
  /// Get any module map files other than getModuleMapFileForUniquing(M)
588
  /// that define submodules of a top-level module \p M. This is cheaper than
589
  /// getting the module map file for each submodule individually, since the
590
  /// expected number of results is very small.
591
3.52k
  AdditionalModMapsSet *getAdditionalModuleMapFiles(const Module *M) {
592
3.52k
    auto I = AdditionalModMaps.find(M);
593
3.52k
    if (I == AdditionalModMaps.end())
594
3.43k
      return nullptr;
595
95
    return &I->second;
596
95
  }
597
598
119
  void addAdditionalModuleMapFile(const Module *M, const FileEntry *ModuleMap) {
599
119
    AdditionalModMaps[M].insert(ModuleMap);
600
119
  }
601
602
  /// Resolve all of the unresolved exports in the given module.
603
  ///
604
  /// \param Mod The module whose exports should be resolved.
605
  ///
606
  /// \param Complain Whether to emit diagnostics for failures.
607
  ///
608
  /// \returns true if any errors were encountered while resolving exports,
609
  /// false otherwise.
610
  bool resolveExports(Module *Mod, bool Complain);
611
612
  /// Resolve all of the unresolved uses in the given module.
613
  ///
614
  /// \param Mod The module whose uses should be resolved.
615
  ///
616
  /// \param Complain Whether to emit diagnostics for failures.
617
  ///
618
  /// \returns true if any errors were encountered while resolving uses,
619
  /// false otherwise.
620
  bool resolveUses(Module *Mod, bool Complain);
621
622
  /// Resolve all of the unresolved conflicts in the given module.
623
  ///
624
  /// \param Mod The module whose conflicts should be resolved.
625
  ///
626
  /// \param Complain Whether to emit diagnostics for failures.
627
  ///
628
  /// \returns true if any errors were encountered while resolving conflicts,
629
  /// false otherwise.
630
  bool resolveConflicts(Module *Mod, bool Complain);
631
632
  /// Sets the umbrella header of the given module to the given
633
  /// header.
634
  void setUmbrellaHeader(Module *Mod, const FileEntry *UmbrellaHeader,
635
                         Twine NameAsWritten);
636
637
  /// Sets the umbrella directory of the given module to the given
638
  /// directory.
639
  void setUmbrellaDir(Module *Mod, const DirectoryEntry *UmbrellaDir,
640
                      Twine NameAsWritten);
641
642
  /// Adds this header to the given module.
643
  /// \param Role The role of the header wrt the module.
644
  void addHeader(Module *Mod, Module::Header Header,
645
                 ModuleHeaderRole Role, bool Imported = false);
646
647
  /// Marks this header as being excluded from the given module.
648
  void excludeHeader(Module *Mod, Module::Header Header);
649
650
  /// Parse the given module map file, and record any modules we
651
  /// encounter.
652
  ///
653
  /// \param File The file to be parsed.
654
  ///
655
  /// \param IsSystem Whether this module map file is in a system header
656
  /// directory, and therefore should be considered a system module.
657
  ///
658
  /// \param HomeDir The directory in which relative paths within this module
659
  ///        map file will be resolved.
660
  ///
661
  /// \param ID The FileID of the file to process, if we've already entered it.
662
  ///
663
  /// \param Offset [inout] On input the offset at which to start parsing. On
664
  ///        output, the offset at which the module map terminated.
665
  ///
666
  /// \param ExternModuleLoc The location of the "extern module" declaration
667
  ///        that caused us to load this module map file, if any.
668
  ///
669
  /// \returns true if an error occurred, false otherwise.
670
  bool parseModuleMapFile(const FileEntry *File, bool IsSystem,
671
                          const DirectoryEntry *HomeDir,
672
                          FileID ID = FileID(), unsigned *Offset = nullptr,
673
                          SourceLocation ExternModuleLoc = SourceLocation());
674
675
  /// Dump the contents of the module map, for debugging purposes.
676
  void dump();
677
678
  using module_iterator = llvm::StringMap<Module *>::const_iterator;
679
680
133
  module_iterator module_begin() const { return Modules.begin(); }
681
1.40k
  module_iterator module_end()   const { return Modules.end(); }
682
};
683
684
} // namespace clang
685
686
#endif // LLVM_CLANG_LEX_MODULEMAP_H