clang  7.0.0svn
ModuleMap.h
Go to the documentation of this file.
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 
19 #include "clang/Basic/Module.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.
48 public:
49  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  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  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  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 
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  /// The global module for the current TU, if we still own it. (Ownership is
96  /// transferred if/when we create an enclosing module.
97  std::unique_ptr<Module> PendingGlobalModule;
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.
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  KnownHeader() : Storage(nullptr, NormalHeader) {}
154  KnownHeader(Module *M, ModuleHeaderRole Role) : Storage(M, Role) {}
155 
156  friend bool operator==(const KnownHeader &A, const KnownHeader &B) {
157  return A.Storage == B.Storage;
158  }
159  friend bool operator!=(const KnownHeader &A, const KnownHeader &B) {
160  return A.Storage != B.Storage;
161  }
162 
163  /// Retrieve the module the header is stored in.
164  Module *getModule() const { return Storage.getPointer(); }
165 
166  /// The role of this header within the module.
167  ModuleHeaderRole getRole() const { return Storage.getInt(); }
168 
169  /// Whether this header is available in the module.
170  bool isAvailable() const {
171  return getModule()->isAvailable();
172  }
173 
174  /// Whether this header is accessible from the specified module.
175  bool isAccessibleFrom(Module *M) const {
176  return !(getRole() & PrivateHeader) ||
177  (M && M->getTopLevelModule() == getModule()->getTopLevelModule());
178  }
179 
180  // Whether this known header is valid (i.e., it has an
181  // associated module).
182  explicit operator bool() const {
183  return Storage.getPointer() != nullptr;
184  }
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  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  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.
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,
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  bool isHeaderInUmbrellaDirs(const FileEntry *File) {
369  return static_cast<bool>(findHeaderInUmbrellaDirs(File, IntermediateDirs));
370  }
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.
400  BuiltinIncludeDir = Dir;
401  }
402 
403  /// Get the directory that contains Clang-supplied include files.
404  const DirectoryEntry *getBuiltinDir() const {
405  return BuiltinIncludeDir;
406  }
407 
408  /// Is this a compiler builtin header?
409  static bool isBuiltinHeader(StringRef FileName);
410 
411  /// Add a module map callback.
412  void addModuleMapCallbacks(std::unique_ptr<ModuleMapCallbacks> Callback) {
413  Callbacks.push_back(std::move(Callback));
414  }
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
523  /// unit.
524  ///
525  /// We model the global module as a submodule of the module interface unit.
526  /// Unfortunately, we can't create the module interface unit's Module until
527  /// later, because we don't know what it will be called.
528  Module *createGlobalModuleForInterfaceUnit(SourceLocation Loc);
529 
530  /// Create a new module for a C++ Modules TS module interface unit.
531  /// The module must not already exist, and will be configured for the current
532  /// compilation.
533  ///
534  /// Note that this also sets the current module to the newly-created module.
535  ///
536  /// \returns The newly-created module.
537  Module *createModuleForInterfaceUnit(SourceLocation Loc, StringRef Name,
538  Module *GlobalModule);
539 
540  /// Infer the contents of a framework module map from the given
541  /// framework directory.
542  Module *inferFrameworkModule(const DirectoryEntry *FrameworkDir,
543  bool IsSystem, Module *Parent);
544 
545  /// Create a new top-level module that is shadowed by
546  /// \p ShadowingModule.
547  Module *createShadowedModule(StringRef Name, bool IsFramework,
548  Module *ShadowingModule);
549 
550  /// Creates a new declaration scope for module names, allowing
551  /// previously defined modules to shadow definitions from the new scope.
552  ///
553  /// \note Module names from earlier scopes will shadow names from the new
554  /// scope, which is the opposite of how shadowing works for variables.
555  void finishModuleDeclarationScope() { CurrentModuleScopeID += 1; }
556 
557  bool mayShadowNewModule(Module *ExistingModule) {
558  assert(!ExistingModule->Parent && "expected top-level module");
559  assert(ModuleScopeIDs.count(ExistingModule) && "unknown module");
560  return ModuleScopeIDs[ExistingModule] < CurrentModuleScopeID;
561  }
562 
563  /// Retrieve the module map file containing the definition of the given
564  /// module.
565  ///
566  /// \param Module The module whose module map file will be returned, if known.
567  ///
568  /// \returns The file entry for the module map file containing the given
569  /// module, or nullptr if the module definition was inferred.
570  const FileEntry *getContainingModuleMapFile(const Module *Module) const;
571 
572  /// Get the module map file that (along with the module name) uniquely
573  /// identifies this module.
574  ///
575  /// The particular module that \c Name refers to may depend on how the module
576  /// was found in header search. However, the combination of \c Name and
577  /// this module map will be globally unique for top-level modules. In the case
578  /// of inferred modules, returns the module map that allowed the inference
579  /// (e.g. contained 'module *'). Otherwise, returns
580  /// getContainingModuleMapFile().
581  const FileEntry *getModuleMapFileForUniquing(const Module *M) const;
582 
583  void setInferredModuleAllowedBy(Module *M, const FileEntry *ModuleMap);
584 
585  /// Get any module map files other than getModuleMapFileForUniquing(M)
586  /// that define submodules of a top-level module \p M. This is cheaper than
587  /// getting the module map file for each submodule individually, since the
588  /// expected number of results is very small.
590  auto I = AdditionalModMaps.find(M);
591  if (I == AdditionalModMaps.end())
592  return nullptr;
593  return &I->second;
594  }
595 
596  void addAdditionalModuleMapFile(const Module *M, const FileEntry *ModuleMap) {
597  AdditionalModMaps[M].insert(ModuleMap);
598  }
599 
600  /// Resolve all of the unresolved exports in the given module.
601  ///
602  /// \param Mod The module whose exports should be resolved.
603  ///
604  /// \param Complain Whether to emit diagnostics for failures.
605  ///
606  /// \returns true if any errors were encountered while resolving exports,
607  /// false otherwise.
608  bool resolveExports(Module *Mod, bool Complain);
609 
610  /// Resolve all of the unresolved uses in the given module.
611  ///
612  /// \param Mod The module whose uses should be resolved.
613  ///
614  /// \param Complain Whether to emit diagnostics for failures.
615  ///
616  /// \returns true if any errors were encountered while resolving uses,
617  /// false otherwise.
618  bool resolveUses(Module *Mod, bool Complain);
619 
620  /// Resolve all of the unresolved conflicts in the given module.
621  ///
622  /// \param Mod The module whose conflicts should be resolved.
623  ///
624  /// \param Complain Whether to emit diagnostics for failures.
625  ///
626  /// \returns true if any errors were encountered while resolving conflicts,
627  /// false otherwise.
628  bool resolveConflicts(Module *Mod, bool Complain);
629 
630  /// Sets the umbrella header of the given module to the given
631  /// header.
632  void setUmbrellaHeader(Module *Mod, const FileEntry *UmbrellaHeader,
633  Twine NameAsWritten);
634 
635  /// Sets the umbrella directory of the given module to the given
636  /// directory.
637  void setUmbrellaDir(Module *Mod, const DirectoryEntry *UmbrellaDir,
638  Twine NameAsWritten);
639 
640  /// Adds this header to the given module.
641  /// \param Role The role of the header wrt the module.
642  void addHeader(Module *Mod, Module::Header Header,
643  ModuleHeaderRole Role, bool Imported = false);
644 
645  /// Marks this header as being excluded from the given module.
646  void excludeHeader(Module *Mod, Module::Header Header);
647 
648  /// Parse the given module map file, and record any modules we
649  /// encounter.
650  ///
651  /// \param File The file to be parsed.
652  ///
653  /// \param IsSystem Whether this module map file is in a system header
654  /// directory, and therefore should be considered a system module.
655  ///
656  /// \param HomeDir The directory in which relative paths within this module
657  /// map file will be resolved.
658  ///
659  /// \param ID The FileID of the file to process, if we've already entered it.
660  ///
661  /// \param Offset [inout] On input the offset at which to start parsing. On
662  /// output, the offset at which the module map terminated.
663  ///
664  /// \param ExternModuleLoc The location of the "extern module" declaration
665  /// that caused us to load this module map file, if any.
666  ///
667  /// \returns true if an error occurred, false otherwise.
668  bool parseModuleMapFile(const FileEntry *File, bool IsSystem,
669  const DirectoryEntry *HomeDir,
670  FileID ID = FileID(), unsigned *Offset = nullptr,
671  SourceLocation ExternModuleLoc = SourceLocation());
672 
673  /// Dump the contents of the module map, for debugging purposes.
674  void dump();
675 
676  using module_iterator = llvm::StringMap<Module *>::const_iterator;
677 
678  module_iterator module_begin() const { return Modules.begin(); }
679  module_iterator module_end() const { return Modules.end(); }
680 };
681 
682 } // namespace clang
683 
684 #endif // LLVM_CLANG_LEX_MODULEMAP_H
ModuleHeaderRole getRole() const
The role of this header within the module.
Definition: ModuleMap.h:167
Implements support for file system lookup, file system caching, and directory search management...
Definition: FileManager.h:116
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
Definition: Module.h:451
Defines the clang::Module class, which describes a module in the source code.
friend bool operator!=(const KnownHeader &A, const KnownHeader &B)
Definition: ModuleMap.h:159
llvm::StringMap< Module * >::const_iterator module_iterator
Definition: ModuleMap.h:676
void finishModuleDeclarationScope()
Creates a new declaration scope for module names, allowing previously defined modules to shadow defin...
Definition: ModuleMap.h:555
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:50
Describes a module or submodule.
Definition: Module.h:65
bool isAccessibleFrom(Module *M) const
Whether this header is accessible from the specified module.
Definition: ModuleMap.h:175
uint32_t Offset
Definition: CacheTokens.cpp:43
static void dump(llvm::raw_ostream &OS, StringRef FunctionName, ArrayRef< CounterExpression > Expressions, ArrayRef< CounterMappingRegion > Regions)
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:149
Module * Parent
The parent of this module.
Definition: Module.h:91
bool isAvailable() const
Whether this header is available in the module.
Definition: ModuleMap.h:170
void addModuleMapCallbacks(std::unique_ptr< ModuleMapCallbacks > Callback)
Add a module map callback.
Definition: ModuleMap.h:412
Encapsulates the information needed to find the file referenced by a #include or #include_next, (sub-)framework lookup, etc.
Definition: HeaderSearch.h:148
NodeId Parent
Definition: ASTDiff.cpp:192
ModuleHeaderRole
Flags describing the role of a module header.
Definition: ModuleMap.h:122
StringRef Filename
Definition: Format.cpp:1598
SmallVector< std::pair< std::string, SourceLocation >, 2 > ModuleId
Describes the name of a module.
Definition: Module.h:52
Exposes information about the current target.
Definition: TargetInfo.h:54
Defines the clang::LangOptions interface.
int Id
Definition: ASTDiff.cpp:191
virtual void moduleMapFileRead(SourceLocation FileStart, const FileEntry &File, bool IsSystem)
Called when a module map file has been read.
Definition: ModuleMap.h:57
llvm::SmallPtrSet< const FileEntry *, 1 > AdditionalModMapsSet
Definition: ModuleMap.h:187
#define bool
Definition: stdbool.h:31
module_iterator module_begin() const
Definition: ModuleMap.h:678
A mechanism to observe the actions of the module map parser as it reads module map files...
Definition: ModuleMap.h:47
Information about a header directive as found in the module map file.
Definition: Module.h:151
void addAdditionalModuleMapFile(const Module *M, const FileEntry *ModuleMap)
Definition: ModuleMap.h:596
const DirectoryEntry * getBuiltinDir() const
Get the directory that contains Clang-supplied include files.
Definition: ModuleMap.h:404
#define false
Definition: stdbool.h:33
Kind
void setBuiltinIncludeDir(const DirectoryEntry *Dir)
Set the directory that contains Clang-supplied include files, such as our stdarg.h or tgmath...
Definition: ModuleMap.h:399
Encodes a location in the source.
virtual void moduleMapAddUmbrellaHeader(FileManager *FileMgr, const FileEntry *Header)
Called when an umbrella header is added during module map parsing.
Definition: ModuleMap.h:69
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:59
virtual void moduleMapAddHeader(StringRef Filename)
Called when a header is added during module map parsing.
Definition: ModuleMap.h:63
module_iterator module_end() const
Definition: ModuleMap.h:679
bool mayShadowNewModule(Module *ExistingModule)
Definition: ModuleMap.h:557
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Dataflow Directional Tag Classes.
Stored information about a header directive that was found in the module map file but has not been re...
Definition: Module.h:172
virtual ~ModuleMapCallbacks()=default
llvm::PointerIntPair< Module *, 1, bool > ExportDecl
Describes an exported module.
Definition: Module.h:288
AdditionalModMapsSet * getAdditionalModuleMapFiles(const Module *M)
Get any module map files other than getModuleMapFileForUniquing(M) that define submodules of a top-le...
Definition: ModuleMap.h:589
Describes an exported module that has not yet been resolved (perhaps because the module it refers to ...
Definition: Module.h:295
Cached information about one directory (either on disk or in the virtual file system).
Definition: FileManager.h:45
KnownHeader(Module *M, ModuleHeaderRole Role)
Definition: ModuleMap.h:154
Defines the clang::SourceLocation class and associated facilities.
Module * getModule() const
Retrieve the module the header is stored in.
Definition: ModuleMap.h:164
friend bool operator==(const KnownHeader &A, const KnownHeader &B)
Definition: ModuleMap.h:156
A header that is known to reside within a given module, whether it was included or excluded...
Definition: ModuleMap.h:149
This class handles loading and caching of source files into memory.