clang  15.0.0git
ModuleMap.cpp
Go to the documentation of this file.
1 //===- ModuleMap.cpp - Describe the layout of modules ---------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines the ModuleMap implementation, which describes the layout
10 // of a module as it relates to headers.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/Lex/ModuleMap.h"
15 #include "clang/Basic/CharInfo.h"
16 #include "clang/Basic/Diagnostic.h"
18 #include "clang/Basic/LLVM.h"
20 #include "clang/Basic/Module.h"
23 #include "clang/Basic/TargetInfo.h"
24 #include "clang/Lex/HeaderSearch.h"
27 #include "clang/Lex/Lexer.h"
29 #include "clang/Lex/Token.h"
30 #include "llvm/ADT/DenseMap.h"
31 #include "llvm/ADT/None.h"
32 #include "llvm/ADT/STLExtras.h"
33 #include "llvm/ADT/SmallPtrSet.h"
34 #include "llvm/ADT/SmallString.h"
35 #include "llvm/ADT/SmallVector.h"
36 #include "llvm/ADT/StringMap.h"
37 #include "llvm/ADT/StringRef.h"
38 #include "llvm/ADT/StringSwitch.h"
39 #include "llvm/Support/Allocator.h"
40 #include "llvm/Support/Compiler.h"
41 #include "llvm/Support/ErrorHandling.h"
42 #include "llvm/Support/MemoryBuffer.h"
43 #include "llvm/Support/Path.h"
44 #include "llvm/Support/VirtualFileSystem.h"
45 #include "llvm/Support/raw_ostream.h"
46 #include <algorithm>
47 #include <cassert>
48 #include <cstdint>
49 #include <cstring>
50 #include <string>
51 #include <system_error>
52 #include <utility>
53 
54 using namespace clang;
55 
56 void ModuleMapCallbacks::anchor() {}
57 
59  auto PendingLinkAs = PendingLinkAsModule.find(Mod->Name);
60  if (PendingLinkAs != PendingLinkAsModule.end()) {
61  for (auto &Name : PendingLinkAs->second) {
62  auto *M = findModule(Name.getKey());
63  if (M)
64  M->UseExportAsModuleLinkName = true;
65  }
66  }
67 }
68 
70  if (findModule(Mod->ExportAsModule))
71  Mod->UseExportAsModuleLinkName = true;
72  else
73  PendingLinkAsModule[Mod->ExportAsModule].insert(Mod->Name);
74 }
75 
77  switch ((int)Role) {
78  default: llvm_unreachable("unknown header role");
79  case NormalHeader:
80  return Module::HK_Normal;
81  case PrivateHeader:
82  return Module::HK_Private;
83  case TextualHeader:
84  return Module::HK_Textual;
87  }
88 }
89 
92  switch ((int)Kind) {
93  case Module::HK_Normal:
94  return NormalHeader;
95  case Module::HK_Private:
96  return PrivateHeader;
97  case Module::HK_Textual:
98  return TextualHeader;
101  case Module::HK_Excluded:
102  llvm_unreachable("unexpected header kind");
103  }
104  llvm_unreachable("unknown header kind");
105 }
106 
108 ModuleMap::resolveExport(Module *Mod,
109  const Module::UnresolvedExportDecl &Unresolved,
110  bool Complain) const {
111  // We may have just a wildcard.
112  if (Unresolved.Id.empty()) {
113  assert(Unresolved.Wildcard && "Invalid unresolved export");
114  return Module::ExportDecl(nullptr, true);
115  }
116 
117  // Resolve the module-id.
118  Module *Context = resolveModuleId(Unresolved.Id, Mod, Complain);
119  if (!Context)
120  return {};
121 
122  return Module::ExportDecl(Context, Unresolved.Wildcard);
123 }
124 
125 Module *ModuleMap::resolveModuleId(const ModuleId &Id, Module *Mod,
126  bool Complain) const {
127  // Find the starting module.
128  Module *Context = lookupModuleUnqualified(Id[0].first, Mod);
129  if (!Context) {
130  if (Complain)
131  Diags.Report(Id[0].second, diag::err_mmap_missing_module_unqualified)
132  << Id[0].first << Mod->getFullModuleName();
133 
134  return nullptr;
135  }
136 
137  // Dig into the module path.
138  for (unsigned I = 1, N = Id.size(); I != N; ++I) {
139  Module *Sub = lookupModuleQualified(Id[I].first, Context);
140  if (!Sub) {
141  if (Complain)
142  Diags.Report(Id[I].second, diag::err_mmap_missing_module_qualified)
143  << Id[I].first << Context->getFullModuleName()
144  << SourceRange(Id[0].second, Id[I-1].second);
145 
146  return nullptr;
147  }
148 
149  Context = Sub;
150  }
151 
152  return Context;
153 }
154 
155 /// Append to \p Paths the set of paths needed to get to the
156 /// subframework in which the given module lives.
158  SmallVectorImpl<char> &Path) {
159  // Collect the framework names from the given module to the top-level module.
161  for (; Mod; Mod = Mod->Parent) {
162  if (Mod->IsFramework)
163  Paths.push_back(Mod->Name);
164  }
165 
166  if (Paths.empty())
167  return;
168 
169  // Add Frameworks/Name.framework for each subframework.
170  for (StringRef Framework : llvm::drop_begin(llvm::reverse(Paths)))
171  llvm::sys::path::append(Path, "Frameworks", Framework + ".framework");
172 }
173 
174 Optional<FileEntryRef> ModuleMap::findHeader(
175  Module *M, const Module::UnresolvedHeaderDirective &Header,
176  SmallVectorImpl<char> &RelativePathName, bool &NeedsFramework) {
177  // Search for the header file within the module's home directory.
178  auto *Directory = M->Directory;
179  SmallString<128> FullPathName(Directory->getName());
180 
181  auto GetFile = [&](StringRef Filename) -> Optional<FileEntryRef> {
182  auto File =
183  expectedToOptional(SourceMgr.getFileManager().getFileRef(Filename));
184  if (!File || (Header.Size && File->getSize() != *Header.Size) ||
185  (Header.ModTime && File->getModificationTime() != *Header.ModTime))
186  return None;
187  return *File;
188  };
189 
190  auto GetFrameworkFile = [&]() -> Optional<FileEntryRef> {
191  unsigned FullPathLength = FullPathName.size();
192  appendSubframeworkPaths(M, RelativePathName);
193  unsigned RelativePathLength = RelativePathName.size();
194 
195  // Check whether this file is in the public headers.
196  llvm::sys::path::append(RelativePathName, "Headers", Header.FileName);
197  llvm::sys::path::append(FullPathName, RelativePathName);
198  if (auto File = GetFile(FullPathName))
199  return File;
200 
201  // Check whether this file is in the private headers.
202  // Ideally, private modules in the form 'FrameworkName.Private' should
203  // be defined as 'module FrameworkName.Private', and not as
204  // 'framework module FrameworkName.Private', since a 'Private.Framework'
205  // does not usually exist. However, since both are currently widely used
206  // for private modules, make sure we find the right path in both cases.
207  if (M->IsFramework && M->Name == "Private")
208  RelativePathName.clear();
209  else
210  RelativePathName.resize(RelativePathLength);
211  FullPathName.resize(FullPathLength);
212  llvm::sys::path::append(RelativePathName, "PrivateHeaders",
213  Header.FileName);
214  llvm::sys::path::append(FullPathName, RelativePathName);
215  return GetFile(FullPathName);
216  };
217 
218  if (llvm::sys::path::is_absolute(Header.FileName)) {
219  RelativePathName.clear();
220  RelativePathName.append(Header.FileName.begin(), Header.FileName.end());
221  return GetFile(Header.FileName);
222  }
223 
224  if (M->isPartOfFramework())
225  return GetFrameworkFile();
226 
227  // Lookup for normal headers.
228  llvm::sys::path::append(RelativePathName, Header.FileName);
229  llvm::sys::path::append(FullPathName, RelativePathName);
230  auto NormalHdrFile = GetFile(FullPathName);
231 
232  if (!NormalHdrFile && Directory->getName().endswith(".framework")) {
233  // The lack of 'framework' keyword in a module declaration it's a simple
234  // mistake we can diagnose when the header exists within the proper
235  // framework style path.
236  FullPathName.assign(Directory->getName());
237  RelativePathName.clear();
238  if (GetFrameworkFile()) {
239  Diags.Report(Header.FileNameLoc,
240  diag::warn_mmap_incomplete_framework_module_declaration)
241  << Header.FileName << M->getFullModuleName();
242  NeedsFramework = true;
243  }
244  return None;
245  }
246 
247  return NormalHdrFile;
248 }
249 
250 void ModuleMap::resolveHeader(Module *Mod,
251  const Module::UnresolvedHeaderDirective &Header,
252  bool &NeedsFramework) {
253  SmallString<128> RelativePathName;
254  if (Optional<FileEntryRef> File =
255  findHeader(Mod, Header, RelativePathName, NeedsFramework)) {
256  if (Header.IsUmbrella) {
257  const DirectoryEntry *UmbrellaDir = &File->getDir().getDirEntry();
258  if (Module *UmbrellaMod = UmbrellaDirs[UmbrellaDir])
259  Diags.Report(Header.FileNameLoc, diag::err_mmap_umbrella_clash)
260  << UmbrellaMod->getFullModuleName();
261  else
262  // Record this umbrella header.
263  setUmbrellaHeader(Mod, *File, Header.FileName, RelativePathName.str());
264  } else {
265  Module::Header H = {Header.FileName, std::string(RelativePathName.str()),
266  *File};
267  if (Header.Kind == Module::HK_Excluded)
268  excludeHeader(Mod, H);
269  else
270  addHeader(Mod, H, headerKindToRole(Header.Kind));
271  }
272  } else if (Header.HasBuiltinHeader && !Header.Size && !Header.ModTime) {
273  // There's a builtin header but no corresponding on-disk header. Assume
274  // this was supposed to modularize the builtin header alone.
275  } else if (Header.Kind == Module::HK_Excluded) {
276  // Ignore missing excluded header files. They're optional anyway.
277  } else {
278  // If we find a module that has a missing header, we mark this module as
279  // unavailable and store the header directive for displaying diagnostics.
280  Mod->MissingHeaders.push_back(Header);
281  // A missing header with stat information doesn't make the module
282  // unavailable; this keeps our behavior consistent as headers are lazily
283  // resolved. (Such a module still can't be built though, except from
284  // preprocessed source.)
285  if (!Header.Size && !Header.ModTime)
286  Mod->markUnavailable(/*Unimportable=*/false);
287  }
288 }
289 
290 bool ModuleMap::resolveAsBuiltinHeader(
291  Module *Mod, const Module::UnresolvedHeaderDirective &Header) {
292  if (Header.Kind == Module::HK_Excluded ||
293  llvm::sys::path::is_absolute(Header.FileName) ||
294  Mod->isPartOfFramework() || !Mod->IsSystem || Header.IsUmbrella ||
295  !BuiltinIncludeDir || BuiltinIncludeDir == Mod->Directory ||
296  !isBuiltinHeader(Header.FileName))
297  return false;
298 
299  // This is a system module with a top-level header. This header
300  // may have a counterpart (or replacement) in the set of headers
301  // supplied by Clang. Find that builtin header.
302  SmallString<128> Path;
303  llvm::sys::path::append(Path, BuiltinIncludeDir->getName(), Header.FileName);
304  auto File = SourceMgr.getFileManager().getFile(Path);
305  if (!File)
306  return false;
307 
308  auto Role = headerKindToRole(Header.Kind);
309  Module::Header H = {Header.FileName, std::string(Path.str()), *File};
310  addHeader(Mod, H, Role);
311  return true;
312 }
313 
315  const LangOptions &LangOpts, const TargetInfo *Target,
316  HeaderSearch &HeaderInfo)
317  : SourceMgr(SourceMgr), Diags(Diags), LangOpts(LangOpts), Target(Target),
318  HeaderInfo(HeaderInfo) {
319  MMapLangOpts.LineComment = true;
320 }
321 
323  for (auto &M : Modules)
324  delete M.getValue();
325  for (auto *M : ShadowModules)
326  delete M;
327 }
328 
329 void ModuleMap::setTarget(const TargetInfo &Target) {
330  assert((!this->Target || this->Target == &Target) &&
331  "Improper target override");
332  this->Target = &Target;
333 }
334 
335 /// "Sanitize" a filename so that it can be used as an identifier.
336 static StringRef sanitizeFilenameAsIdentifier(StringRef Name,
337  SmallVectorImpl<char> &Buffer) {
338  if (Name.empty())
339  return Name;
340 
341  if (!isValidAsciiIdentifier(Name)) {
342  // If we don't already have something with the form of an identifier,
343  // create a buffer with the sanitized name.
344  Buffer.clear();
345  if (isDigit(Name[0]))
346  Buffer.push_back('_');
347  Buffer.reserve(Buffer.size() + Name.size());
348  for (unsigned I = 0, N = Name.size(); I != N; ++I) {
349  if (isAsciiIdentifierContinue(Name[I]))
350  Buffer.push_back(Name[I]);
351  else
352  Buffer.push_back('_');
353  }
354 
355  Name = StringRef(Buffer.data(), Buffer.size());
356  }
357 
358  while (llvm::StringSwitch<bool>(Name)
359 #define KEYWORD(Keyword,Conditions) .Case(#Keyword, true)
360 #define ALIAS(Keyword, AliasOf, Conditions) .Case(Keyword, true)
361 #include "clang/Basic/TokenKinds.def"
362  .Default(false)) {
363  if (Name.data() != Buffer.data())
364  Buffer.append(Name.begin(), Name.end());
365  Buffer.push_back('_');
366  Name = StringRef(Buffer.data(), Buffer.size());
367  }
368 
369  return Name;
370 }
371 
372 /// Determine whether the given file name is the name of a builtin
373 /// header, supplied by Clang to replace, override, or augment existing system
374 /// headers.
375 bool ModuleMap::isBuiltinHeader(StringRef FileName) {
376  return llvm::StringSwitch<bool>(FileName)
377  .Case("float.h", true)
378  .Case("iso646.h", true)
379  .Case("limits.h", true)
380  .Case("stdalign.h", true)
381  .Case("stdarg.h", true)
382  .Case("stdatomic.h", true)
383  .Case("stdbool.h", true)
384  .Case("stddef.h", true)
385  .Case("stdint.h", true)
386  .Case("tgmath.h", true)
387  .Case("unwind.h", true)
388  .Default(false);
389 }
390 
392  return File->getDir() == BuiltinIncludeDir &&
393  ModuleMap::isBuiltinHeader(llvm::sys::path::filename(File->getName()));
394 }
395 
396 ModuleMap::HeadersMap::iterator
397 ModuleMap::findKnownHeader(const FileEntry *File) {
399  HeadersMap::iterator Known = Headers.find(File);
400  if (HeaderInfo.getHeaderSearchOpts().ImplicitModuleMaps &&
401  Known == Headers.end() && ModuleMap::isBuiltinHeader(File)) {
402  HeaderInfo.loadTopLevelSystemModules();
403  return Headers.find(File);
404  }
405  return Known;
406 }
407 
409 ModuleMap::findHeaderInUmbrellaDirs(const FileEntry *File,
410  SmallVectorImpl<const DirectoryEntry *> &IntermediateDirs) {
411  if (UmbrellaDirs.empty())
412  return {};
413 
414  const DirectoryEntry *Dir = File->getDir();
415  assert(Dir && "file in no directory");
416 
417  // Note: as an egregious but useful hack we use the real path here, because
418  // frameworks moving from top-level frameworks to embedded frameworks tend
419  // to be symlinked from the top-level location to the embedded location,
420  // and we need to resolve lookups as if we had found the embedded location.
421  StringRef DirName = SourceMgr.getFileManager().getCanonicalName(Dir);
422 
423  // Keep walking up the directory hierarchy, looking for a directory with
424  // an umbrella header.
425  do {
426  auto KnownDir = UmbrellaDirs.find(Dir);
427  if (KnownDir != UmbrellaDirs.end())
428  return KnownHeader(KnownDir->second, NormalHeader);
429 
430  IntermediateDirs.push_back(Dir);
431 
432  // Retrieve our parent path.
433  DirName = llvm::sys::path::parent_path(DirName);
434  if (DirName.empty())
435  break;
436 
437  // Resolve the parent path to a directory entry.
438  if (auto DirEntry = SourceMgr.getFileManager().getDirectory(DirName))
439  Dir = *DirEntry;
440  else
441  Dir = nullptr;
442  } while (Dir);
443  return {};
444 }
445 
446 static bool violatesPrivateInclude(Module *RequestingModule,
447  const FileEntry *IncFileEnt,
448  ModuleMap::KnownHeader Header) {
449 #ifndef NDEBUG
450  if (Header.getRole() & ModuleMap::PrivateHeader) {
451  // Check for consistency between the module header role
452  // as obtained from the lookup and as obtained from the module.
453  // This check is not cheap, so enable it only for debugging.
454  bool IsPrivate = false;
455  SmallVectorImpl<Module::Header> *HeaderList[] = {
458  for (auto *Hs : HeaderList)
459  IsPrivate |=
460  std::find_if(Hs->begin(), Hs->end(), [&](const Module::Header &H) {
461  return H.Entry == IncFileEnt;
462  }) != Hs->end();
463  assert(IsPrivate && "inconsistent headers and roles");
464  }
465 #endif
466  return !Header.isAccessibleFrom(RequestingModule);
467 }
468 
470  return M ? M->getTopLevelModule() : nullptr;
471 }
472 
474  bool RequestingModuleIsModuleInterface,
475  SourceLocation FilenameLoc,
476  StringRef Filename, FileEntryRef File) {
477  // No errors for indirect modules. This may be a bit of a problem for modules
478  // with no source files.
479  if (getTopLevelOrNull(RequestingModule) != getTopLevelOrNull(SourceModule))
480  return;
481 
482  if (RequestingModule) {
483  resolveUses(RequestingModule, /*Complain=*/false);
484  resolveHeaderDirectives(RequestingModule, /*File=*/llvm::None);
485  }
486 
487  bool Excluded = false;
488  Module *Private = nullptr;
489  Module *NotUsed = nullptr;
490 
491  HeadersMap::iterator Known = findKnownHeader(File);
492  if (Known != Headers.end()) {
493  for (const KnownHeader &Header : Known->second) {
494  // Remember private headers for later printing of a diagnostic.
495  if (violatesPrivateInclude(RequestingModule, File, Header)) {
496  Private = Header.getModule();
497  continue;
498  }
499 
500  // If uses need to be specified explicitly, we are only allowed to return
501  // modules that are explicitly used by the requesting module.
502  if (RequestingModule && LangOpts.ModulesDeclUse &&
503  !RequestingModule->directlyUses(Header.getModule())) {
504  NotUsed = Header.getModule();
505  continue;
506  }
507 
508  // We have found a module that we can happily use.
509  return;
510  }
511 
512  Excluded = true;
513  }
514 
515  // We have found a header, but it is private.
516  if (Private) {
517  Diags.Report(FilenameLoc, diag::warn_use_of_private_header_outside_module)
518  << Filename;
519  return;
520  }
521 
522  // We have found a module, but we don't use it.
523  if (NotUsed) {
524  Diags.Report(FilenameLoc, diag::err_undeclared_use_of_module)
525  << RequestingModule->getTopLevelModule()->Name << Filename;
526  return;
527  }
528 
529  if (Excluded || isHeaderInUmbrellaDirs(File))
530  return;
531 
532  // At this point, only non-modular includes remain.
533 
534  if (RequestingModule && LangOpts.ModulesStrictDeclUse) {
535  Diags.Report(FilenameLoc, diag::err_undeclared_use_of_module)
536  << RequestingModule->getTopLevelModule()->Name << Filename;
537  } else if (RequestingModule && RequestingModuleIsModuleInterface &&
538  LangOpts.isCompilingModule()) {
539  // Do not diagnose when we are not compiling a module.
540  diag::kind DiagID = RequestingModule->getTopLevelModule()->IsFramework ?
541  diag::warn_non_modular_include_in_framework_module :
542  diag::warn_non_modular_include_in_module;
543  Diags.Report(FilenameLoc, DiagID) << RequestingModule->getFullModuleName()
544  << File.getName();
545  }
546 }
547 
549  const ModuleMap::KnownHeader &Old) {
550  // Prefer available modules.
551  // FIXME: Considering whether the module is available rather than merely
552  // importable is non-hermetic and can result in surprising behavior for
553  // prebuilt modules. Consider only checking for importability here.
554  if (New.getModule()->isAvailable() && !Old.getModule()->isAvailable())
555  return true;
556 
557  // Prefer a public header over a private header.
558  if ((New.getRole() & ModuleMap::PrivateHeader) !=
560  return !(New.getRole() & ModuleMap::PrivateHeader);
561 
562  // Prefer a non-textual header over a textual header.
563  if ((New.getRole() & ModuleMap::TextualHeader) !=
565  return !(New.getRole() & ModuleMap::TextualHeader);
566 
567  // Don't have a reason to choose between these. Just keep the first one.
568  return false;
569 }
570 
572  bool AllowTextual) {
573  auto MakeResult = [&](ModuleMap::KnownHeader R) -> ModuleMap::KnownHeader {
574  if (!AllowTextual && R.getRole() & ModuleMap::TextualHeader)
575  return {};
576  return R;
577  };
578 
579  HeadersMap::iterator Known = findKnownHeader(File);
580  if (Known != Headers.end()) {
581  ModuleMap::KnownHeader Result;
582  // Iterate over all modules that 'File' is part of to find the best fit.
583  for (KnownHeader &H : Known->second) {
584  // Prefer a header from the source module over all others.
585  if (H.getModule()->getTopLevelModule() == SourceModule)
586  return MakeResult(H);
587  if (!Result || isBetterKnownHeader(H, Result))
588  Result = H;
589  }
590  return MakeResult(Result);
591  }
592 
593  return MakeResult(findOrCreateModuleForHeaderInUmbrellaDir(File));
594 }
595 
597 ModuleMap::findOrCreateModuleForHeaderInUmbrellaDir(const FileEntry *File) {
598  assert(!Headers.count(File) && "already have a module for this header");
599 
601  KnownHeader H = findHeaderInUmbrellaDirs(File, SkippedDirs);
602  if (H) {
603  Module *Result = H.getModule();
604 
605  // Search up the module stack until we find a module with an umbrella
606  // directory.
607  Module *UmbrellaModule = Result;
608  while (!UmbrellaModule->getUmbrellaDir() && UmbrellaModule->Parent)
609  UmbrellaModule = UmbrellaModule->Parent;
610 
611  if (UmbrellaModule->InferSubmodules) {
612  const FileEntry *UmbrellaModuleMap =
613  getModuleMapFileForUniquing(UmbrellaModule);
614 
615  // Infer submodules for each of the directories we found between
616  // the directory of the umbrella header and the directory where
617  // the actual header is located.
618  bool Explicit = UmbrellaModule->InferExplicitSubmodules;
619 
620  for (const DirectoryEntry *SkippedDir : llvm::reverse(SkippedDirs)) {
621  // Find or create the module that corresponds to this directory name.
622  SmallString<32> NameBuf;
623  StringRef Name = sanitizeFilenameAsIdentifier(
624  llvm::sys::path::stem(SkippedDir->getName()), NameBuf);
625  Result = findOrCreateModule(Name, Result, /*IsFramework=*/false,
626  Explicit).first;
627  InferredModuleAllowedBy[Result] = UmbrellaModuleMap;
628  Result->IsInferred = true;
629 
630  // Associate the module and the directory.
631  UmbrellaDirs[SkippedDir] = Result;
632 
633  // If inferred submodules export everything they import, add a
634  // wildcard to the set of exports.
635  if (UmbrellaModule->InferExportWildcard && Result->Exports.empty())
636  Result->Exports.push_back(Module::ExportDecl(nullptr, true));
637  }
638 
639  // Infer a submodule with the same name as this header file.
640  SmallString<32> NameBuf;
641  StringRef Name = sanitizeFilenameAsIdentifier(
642  llvm::sys::path::stem(File->getName()), NameBuf);
643  Result = findOrCreateModule(Name, Result, /*IsFramework=*/false,
644  Explicit).first;
645  InferredModuleAllowedBy[Result] = UmbrellaModuleMap;
646  Result->IsInferred = true;
647  Result->addTopHeader(File);
648 
649  // If inferred submodules export everything they import, add a
650  // wildcard to the set of exports.
651  if (UmbrellaModule->InferExportWildcard && Result->Exports.empty())
652  Result->Exports.push_back(Module::ExportDecl(nullptr, true));
653  } else {
654  // Record each of the directories we stepped through as being part of
655  // the module we found, since the umbrella header covers them all.
656  for (unsigned I = 0, N = SkippedDirs.size(); I != N; ++I)
657  UmbrellaDirs[SkippedDirs[I]] = Result;
658  }
659 
660  KnownHeader Header(Result, NormalHeader);
661  Headers[File].push_back(Header);
662  return Header;
663  }
664 
665  return {};
666 }
667 
670  HeadersMap::iterator Known = findKnownHeader(File);
671  if (Known != Headers.end())
672  return Known->second;
673 
674  if (findOrCreateModuleForHeaderInUmbrellaDir(File))
675  return Headers.find(File)->second;
676 
677  return None;
678 }
679 
682  // FIXME: Is this necessary?
684  auto It = Headers.find(File);
685  if (It == Headers.end())
686  return None;
687  return It->second;
688 }
689 
691  return isHeaderUnavailableInModule(Header, nullptr);
692 }
693 
694 bool
696  const Module *RequestingModule) const {
697  resolveHeaderDirectives(Header);
698  HeadersMap::const_iterator Known = Headers.find(Header);
699  if (Known != Headers.end()) {
701  I = Known->second.begin(),
702  E = Known->second.end();
703  I != E; ++I) {
704 
705  if (I->isAvailable() &&
706  (!RequestingModule ||
707  I->getModule()->isSubModuleOf(RequestingModule))) {
708  // When no requesting module is available, the caller is looking if a
709  // header is part a module by only looking into the module map. This is
710  // done by warn_uncovered_module_header checks; don't consider textual
711  // headers part of it in this mode, otherwise we get misleading warnings
712  // that a umbrella header is not including a textual header.
713  if (!RequestingModule && I->getRole() == ModuleMap::TextualHeader)
714  continue;
715  return false;
716  }
717  }
718  return true;
719  }
720 
721  const DirectoryEntry *Dir = Header->getDir();
723  StringRef DirName = Dir->getName();
724 
725  auto IsUnavailable = [&](const Module *M) {
726  return !M->isAvailable() && (!RequestingModule ||
727  M->isSubModuleOf(RequestingModule));
728  };
729 
730  // Keep walking up the directory hierarchy, looking for a directory with
731  // an umbrella header.
732  do {
733  llvm::DenseMap<const DirectoryEntry *, Module *>::const_iterator KnownDir
734  = UmbrellaDirs.find(Dir);
735  if (KnownDir != UmbrellaDirs.end()) {
736  Module *Found = KnownDir->second;
737  if (IsUnavailable(Found))
738  return true;
739 
740  // Search up the module stack until we find a module with an umbrella
741  // directory.
742  Module *UmbrellaModule = Found;
743  while (!UmbrellaModule->getUmbrellaDir() && UmbrellaModule->Parent)
744  UmbrellaModule = UmbrellaModule->Parent;
745 
746  if (UmbrellaModule->InferSubmodules) {
747  for (const DirectoryEntry *SkippedDir : llvm::reverse(SkippedDirs)) {
748  // Find or create the module that corresponds to this directory name.
749  SmallString<32> NameBuf;
750  StringRef Name = sanitizeFilenameAsIdentifier(
751  llvm::sys::path::stem(SkippedDir->getName()), NameBuf);
752  Found = lookupModuleQualified(Name, Found);
753  if (!Found)
754  return false;
755  if (IsUnavailable(Found))
756  return true;
757  }
758 
759  // Infer a submodule with the same name as this header file.
760  SmallString<32> NameBuf;
761  StringRef Name = sanitizeFilenameAsIdentifier(
762  llvm::sys::path::stem(Header->getName()),
763  NameBuf);
764  Found = lookupModuleQualified(Name, Found);
765  if (!Found)
766  return false;
767  }
768 
769  return IsUnavailable(Found);
770  }
771 
772  SkippedDirs.push_back(Dir);
773 
774  // Retrieve our parent path.
775  DirName = llvm::sys::path::parent_path(DirName);
776  if (DirName.empty())
777  break;
778 
779  // Resolve the parent path to a directory entry.
780  if (auto DirEntry = SourceMgr.getFileManager().getDirectory(DirName))
781  Dir = *DirEntry;
782  else
783  Dir = nullptr;
784  } while (Dir);
785 
786  return false;
787 }
788 
789 Module *ModuleMap::findModule(StringRef Name) const {
790  llvm::StringMap<Module *>::const_iterator Known = Modules.find(Name);
791  if (Known != Modules.end())
792  return Known->getValue();
793 
794  return nullptr;
795 }
796 
798  Module *Context) const {
799  for(; Context; Context = Context->Parent) {
800  if (Module *Sub = lookupModuleQualified(Name, Context))
801  return Sub;
802  }
803 
804  return findModule(Name);
805 }
806 
807 Module *ModuleMap::lookupModuleQualified(StringRef Name, Module *Context) const{
808  if (!Context)
809  return findModule(Name);
810 
811  return Context->findSubmodule(Name);
812 }
813 
814 std::pair<Module *, bool> ModuleMap::findOrCreateModule(StringRef Name,
815  Module *Parent,
816  bool IsFramework,
817  bool IsExplicit) {
818  // Try to find an existing module with this name.
819  if (Module *Sub = lookupModuleQualified(Name, Parent))
820  return std::make_pair(Sub, false);
821 
822  // Create a new module with this name.
823  Module *Result = new Module(Name, SourceLocation(), Parent, IsFramework,
824  IsExplicit, NumCreatedModules++);
825  if (!Parent) {
826  if (LangOpts.CurrentModule == Name)
827  SourceModule = Result;
828  Modules[Name] = Result;
829  ModuleScopeIDs[Result] = CurrentModuleScopeID;
830  }
831  return std::make_pair(Result, true);
832 }
833 
835  Module *Parent) {
836  auto *Result = new Module("<global>", Loc, Parent, /*IsFramework*/ false,
837  /*IsExplicit*/ true, NumCreatedModules++);
839  // If the created module isn't owned by a parent, send it to PendingSubmodules
840  // to wait for its parent.
841  if (!Result->Parent)
842  PendingSubmodules.emplace_back(Result);
843  return Result;
844 }
845 
846 Module *
848  SourceLocation Loc) {
849  auto *Result =
850  new Module("<private>", Loc, Parent, /*IsFramework*/ false,
851  /*IsExplicit*/ true, NumCreatedModules++);
853  return Result;
854 }
855 
857  StringRef Name,
858  Module *GlobalModule) {
859  assert(LangOpts.CurrentModule == Name && "module name mismatch");
860  assert(!Modules[Name] && "redefining existing module");
861 
862  auto *Result =
863  new Module(Name, Loc, nullptr, /*IsFramework*/ false,
864  /*IsExplicit*/ false, NumCreatedModules++);
866  Modules[Name] = SourceModule = Result;
867 
868  // Reparent the current global module fragment as a submodule of this module.
869  for (auto &Submodule : PendingSubmodules) {
870  Submodule->setParent(Result);
871  Submodule.release(); // now owned by parent
872  }
873  PendingSubmodules.clear();
874 
875  // Mark the main source file as being within the newly-created module so that
876  // declarations and macros are properly visibility-restricted to it.
877  auto *MainFile = SourceMgr.getFileEntryForID(SourceMgr.getMainFileID());
878  assert(MainFile && "no input file for module interface");
879  Headers[MainFile].push_back(KnownHeader(Result, PrivateHeader));
880 
881  return Result;
882 }
883 
885  ArrayRef<Module::Header> Headers) {
886  assert(LangOpts.CurrentModule == Name && "module name mismatch");
887  assert(!Modules[Name] && "redefining existing module");
888 
889  auto *Result =
890  new Module(Name, SourceLocation(), nullptr, /*IsFramework*/ false,
891  /*IsExplicit*/ false, NumCreatedModules++);
893  Modules[Name] = SourceModule = Result;
894 
895  for (const Module::Header &H : Headers) {
896  auto *M = new Module(H.NameAsWritten, SourceLocation(), Result,
897  /*IsFramework*/ false,
898  /*IsExplicit*/ true, NumCreatedModules++);
899  // Header modules are implicitly 'export *'.
900  M->Exports.push_back(Module::ExportDecl(nullptr, true));
901  addHeader(M, H, NormalHeader);
902  }
903 
904  return Result;
905 }
906 
908  Module::Header H) {
909  assert(LangOpts.CurrentModule == Name && "module name mismatch");
910  assert(!Modules[Name] && "redefining existing module");
911 
912  auto *Result = new Module(Name, Loc, nullptr, /*IsFramework*/ false,
913  /*IsExplicit*/ false, NumCreatedModules++);
914  Result->Kind = Module::ModuleHeaderUnit;
915  Modules[Name] = SourceModule = Result;
916  addHeader(Result, H, NormalHeader);
917  return Result;
918 }
919 
920 /// For a framework module, infer the framework against which we
921 /// should link.
922 static void inferFrameworkLink(Module *Mod, const DirectoryEntry *FrameworkDir,
923  FileManager &FileMgr) {
924  assert(Mod->IsFramework && "Can only infer linking for framework modules");
925  assert(!Mod->isSubFramework() &&
926  "Can only infer linking for top-level frameworks");
927 
928  SmallString<128> LibName;
929  LibName += FrameworkDir->getName();
930  llvm::sys::path::append(LibName, Mod->Name);
931 
932  // The library name of a framework has more than one possible extension since
933  // the introduction of the text-based dynamic library format. We need to check
934  // for both before we give up.
935  for (const char *extension : {"", ".tbd"}) {
936  llvm::sys::path::replace_extension(LibName, extension);
937  if (FileMgr.getFile(LibName)) {
938  Mod->LinkLibraries.push_back(Module::LinkLibrary(Mod->Name,
939  /*IsFramework=*/true));
940  return;
941  }
942  }
943 }
944 
945 Module *ModuleMap::inferFrameworkModule(const DirectoryEntry *FrameworkDir,
946  bool IsSystem, Module *Parent) {
947  Attributes Attrs;
948  Attrs.IsSystem = IsSystem;
949  return inferFrameworkModule(FrameworkDir, Attrs, Parent);
950 }
951 
952 Module *ModuleMap::inferFrameworkModule(const DirectoryEntry *FrameworkDir,
953  Attributes Attrs, Module *Parent) {
954  // Note: as an egregious but useful hack we use the real path here, because
955  // we might be looking at an embedded framework that symlinks out to a
956  // top-level framework, and we need to infer as if we were naming the
957  // top-level framework.
958  StringRef FrameworkDirName =
959  SourceMgr.getFileManager().getCanonicalName(FrameworkDir);
960 
961  // In case this is a case-insensitive filesystem, use the canonical
962  // directory name as the ModuleName, since modules are case-sensitive.
963  // FIXME: we should be able to give a fix-it hint for the correct spelling.
964  SmallString<32> ModuleNameStorage;
965  StringRef ModuleName = sanitizeFilenameAsIdentifier(
966  llvm::sys::path::stem(FrameworkDirName), ModuleNameStorage);
967 
968  // Check whether we've already found this module.
969  if (Module *Mod = lookupModuleQualified(ModuleName, Parent))
970  return Mod;
971 
972  FileManager &FileMgr = SourceMgr.getFileManager();
973 
974  // If the framework has a parent path from which we're allowed to infer
975  // a framework module, do so.
976  const FileEntry *ModuleMapFile = nullptr;
977  if (!Parent) {
978  // Determine whether we're allowed to infer a module map.
979  bool canInfer = false;
980  if (llvm::sys::path::has_parent_path(FrameworkDirName)) {
981  // Figure out the parent path.
982  StringRef Parent = llvm::sys::path::parent_path(FrameworkDirName);
983  if (auto ParentDir = FileMgr.getDirectory(Parent)) {
984  // Check whether we have already looked into the parent directory
985  // for a module map.
986  llvm::DenseMap<const DirectoryEntry *, InferredDirectory>::const_iterator
987  inferred = InferredDirectories.find(*ParentDir);
988  if (inferred == InferredDirectories.end()) {
989  // We haven't looked here before. Load a module map, if there is
990  // one.
991  bool IsFrameworkDir = Parent.endswith(".framework");
992  if (const FileEntry *ModMapFile =
993  HeaderInfo.lookupModuleMapFile(*ParentDir, IsFrameworkDir)) {
994  parseModuleMapFile(ModMapFile, Attrs.IsSystem, *ParentDir);
995  inferred = InferredDirectories.find(*ParentDir);
996  }
997 
998  if (inferred == InferredDirectories.end())
999  inferred = InferredDirectories.insert(
1000  std::make_pair(*ParentDir, InferredDirectory())).first;
1001  }
1002 
1003  if (inferred->second.InferModules) {
1004  // We're allowed to infer for this directory, but make sure it's okay
1005  // to infer this particular module.
1006  StringRef Name = llvm::sys::path::stem(FrameworkDirName);
1007  canInfer =
1008  !llvm::is_contained(inferred->second.ExcludedModules, Name);
1009 
1010  Attrs.IsSystem |= inferred->second.Attrs.IsSystem;
1011  Attrs.IsExternC |= inferred->second.Attrs.IsExternC;
1012  Attrs.IsExhaustive |= inferred->second.Attrs.IsExhaustive;
1013  Attrs.NoUndeclaredIncludes |=
1014  inferred->second.Attrs.NoUndeclaredIncludes;
1015  ModuleMapFile = inferred->second.ModuleMapFile;
1016  }
1017  }
1018  }
1019 
1020  // If we're not allowed to infer a framework module, don't.
1021  if (!canInfer)
1022  return nullptr;
1023  } else
1024  ModuleMapFile = getModuleMapFileForUniquing(Parent);
1025 
1026 
1027  // Look for an umbrella header.
1028  SmallString<128> UmbrellaName = StringRef(FrameworkDir->getName());
1029  llvm::sys::path::append(UmbrellaName, "Headers", ModuleName + ".h");
1030  auto UmbrellaHeader = FileMgr.getFile(UmbrellaName);
1031 
1032  // FIXME: If there's no umbrella header, we could probably scan the
1033  // framework to load *everything*. But, it's not clear that this is a good
1034  // idea.
1035  if (!UmbrellaHeader)
1036  return nullptr;
1037 
1038  Module *Result = new Module(ModuleName, SourceLocation(), Parent,
1039  /*IsFramework=*/true, /*IsExplicit=*/false,
1040  NumCreatedModules++);
1041  InferredModuleAllowedBy[Result] = ModuleMapFile;
1042  Result->IsInferred = true;
1043  if (!Parent) {
1044  if (LangOpts.CurrentModule == ModuleName)
1045  SourceModule = Result;
1046  Modules[ModuleName] = Result;
1047  ModuleScopeIDs[Result] = CurrentModuleScopeID;
1048  }
1049 
1050  Result->IsSystem |= Attrs.IsSystem;
1051  Result->IsExternC |= Attrs.IsExternC;
1052  Result->ConfigMacrosExhaustive |= Attrs.IsExhaustive;
1053  Result->NoUndeclaredIncludes |= Attrs.NoUndeclaredIncludes;
1054  Result->Directory = FrameworkDir;
1055 
1056  // Chop off the first framework bit, as that is implied.
1057  StringRef RelativePath = UmbrellaName.str().substr(
1058  Result->getTopLevelModule()->Directory->getName().size());
1059  RelativePath = llvm::sys::path::relative_path(RelativePath);
1060 
1061  // umbrella header "umbrella-header-name"
1062  setUmbrellaHeader(Result, *UmbrellaHeader, ModuleName + ".h", RelativePath);
1063 
1064  // export *
1065  Result->Exports.push_back(Module::ExportDecl(nullptr, true));
1066 
1067  // module * { export * }
1068  Result->InferSubmodules = true;
1069  Result->InferExportWildcard = true;
1070 
1071  // Look for subframeworks.
1072  std::error_code EC;
1073  SmallString<128> SubframeworksDirName
1074  = StringRef(FrameworkDir->getName());
1075  llvm::sys::path::append(SubframeworksDirName, "Frameworks");
1076  llvm::sys::path::native(SubframeworksDirName);
1077  llvm::vfs::FileSystem &FS = FileMgr.getVirtualFileSystem();
1078  for (llvm::vfs::directory_iterator
1079  Dir = FS.dir_begin(SubframeworksDirName, EC),
1080  DirEnd;
1081  Dir != DirEnd && !EC; Dir.increment(EC)) {
1082  if (!StringRef(Dir->path()).endswith(".framework"))
1083  continue;
1084 
1085  if (auto SubframeworkDir =
1086  FileMgr.getDirectory(Dir->path())) {
1087  // Note: as an egregious but useful hack, we use the real path here and
1088  // check whether it is actually a subdirectory of the parent directory.
1089  // This will not be the case if the 'subframework' is actually a symlink
1090  // out to a top-level framework.
1091  StringRef SubframeworkDirName =
1092  FileMgr.getCanonicalName(*SubframeworkDir);
1093  bool FoundParent = false;
1094  do {
1095  // Get the parent directory name.
1096  SubframeworkDirName
1097  = llvm::sys::path::parent_path(SubframeworkDirName);
1098  if (SubframeworkDirName.empty())
1099  break;
1100 
1101  if (auto SubDir = FileMgr.getDirectory(SubframeworkDirName)) {
1102  if (*SubDir == FrameworkDir) {
1103  FoundParent = true;
1104  break;
1105  }
1106  }
1107  } while (true);
1108 
1109  if (!FoundParent)
1110  continue;
1111 
1112  // FIXME: Do we want to warn about subframeworks without umbrella headers?
1113  inferFrameworkModule(*SubframeworkDir, Attrs, Result);
1114  }
1115  }
1116 
1117  // If the module is a top-level framework, automatically link against the
1118  // framework.
1119  if (!Result->isSubFramework()) {
1120  inferFrameworkLink(Result, FrameworkDir, FileMgr);
1121  }
1122 
1123  return Result;
1124 }
1125 
1126 Module *ModuleMap::createShadowedModule(StringRef Name, bool IsFramework,
1127  Module *ShadowingModule) {
1128 
1129  // Create a new module with this name.
1130  Module *Result =
1131  new Module(Name, SourceLocation(), /*Parent=*/nullptr, IsFramework,
1132  /*IsExplicit=*/false, NumCreatedModules++);
1133  Result->ShadowingModule = ShadowingModule;
1134  Result->markUnavailable(/*Unimportable*/true);
1135  ModuleScopeIDs[Result] = CurrentModuleScopeID;
1136  ShadowModules.push_back(Result);
1137 
1138  return Result;
1139 }
1140 
1142  Module *Mod, const FileEntry *UmbrellaHeader, const Twine &NameAsWritten,
1143  const Twine &PathRelativeToRootModuleDirectory) {
1144  Headers[UmbrellaHeader].push_back(KnownHeader(Mod, NormalHeader));
1145  Mod->Umbrella = UmbrellaHeader;
1146  Mod->UmbrellaAsWritten = NameAsWritten.str();
1148  PathRelativeToRootModuleDirectory.str();
1149  UmbrellaDirs[UmbrellaHeader->getDir()] = Mod;
1150 
1151  // Notify callbacks that we just added a new header.
1152  for (const auto &Cb : Callbacks)
1153  Cb->moduleMapAddUmbrellaHeader(&SourceMgr.getFileManager(), UmbrellaHeader);
1154 }
1155 
1156 void ModuleMap::setUmbrellaDir(Module *Mod, const DirectoryEntry *UmbrellaDir,
1157  const Twine &NameAsWritten,
1158  const Twine &PathRelativeToRootModuleDirectory) {
1159  Mod->Umbrella = UmbrellaDir;
1160  Mod->UmbrellaAsWritten = NameAsWritten.str();
1162  PathRelativeToRootModuleDirectory.str();
1163  UmbrellaDirs[UmbrellaDir] = Mod;
1164 }
1165 
1166 void ModuleMap::addUnresolvedHeader(Module *Mod,
1168  bool &NeedsFramework) {
1169  // If there is a builtin counterpart to this file, add it now so it can
1170  // wrap the system header.
1171  if (resolveAsBuiltinHeader(Mod, Header)) {
1172  // If we have both a builtin and system version of the file, the
1173  // builtin version may want to inject macros into the system header, so
1174  // force the system header to be treated as a textual header in this
1175  // case.
1178  Header.HasBuiltinHeader = true;
1179  }
1180 
1181  // If possible, don't stat the header until we need to. This requires the
1182  // user to have provided us with some stat information about the file.
1183  // FIXME: Add support for lazily stat'ing umbrella headers and excluded
1184  // headers.
1185  if ((Header.Size || Header.ModTime) && !Header.IsUmbrella &&
1186  Header.Kind != Module::HK_Excluded) {
1187  // We expect more variation in mtime than size, so if we're given both,
1188  // use the mtime as the key.
1189  if (Header.ModTime)
1190  LazyHeadersByModTime[*Header.ModTime].push_back(Mod);
1191  else
1192  LazyHeadersBySize[*Header.Size].push_back(Mod);
1193  Mod->UnresolvedHeaders.push_back(Header);
1194  return;
1195  }
1196 
1197  // We don't have stat information or can't defer looking this file up.
1198  // Perform the lookup now.
1199  resolveHeader(Mod, Header, NeedsFramework);
1200 }
1201 
1203  auto BySize = LazyHeadersBySize.find(File->getSize());
1204  if (BySize != LazyHeadersBySize.end()) {
1205  for (auto *M : BySize->second)
1207  LazyHeadersBySize.erase(BySize);
1208  }
1209 
1210  auto ByModTime = LazyHeadersByModTime.find(File->getModificationTime());
1211  if (ByModTime != LazyHeadersByModTime.end()) {
1212  for (auto *M : ByModTime->second)
1214  LazyHeadersByModTime.erase(ByModTime);
1215  }
1216 }
1217 
1219  Module *Mod, llvm::Optional<const FileEntry *> File) const {
1220  bool NeedsFramework = false;
1222  const auto Size = File ? File.getValue()->getSize() : 0;
1223  const auto ModTime = File ? File.getValue()->getModificationTime() : 0;
1224 
1225  for (auto &Header : Mod->UnresolvedHeaders) {
1226  if (File && ((Header.ModTime && Header.ModTime != ModTime) ||
1227  (Header.Size && Header.Size != Size)))
1228  NewHeaders.push_back(Header);
1229  else
1230  // This operation is logically const; we're just changing how we represent
1231  // the header information for this file.
1232  const_cast<ModuleMap *>(this)->resolveHeader(Mod, Header, NeedsFramework);
1233  }
1234  Mod->UnresolvedHeaders.swap(NewHeaders);
1235 }
1236 
1238  ModuleHeaderRole Role, bool Imported) {
1239  KnownHeader KH(Mod, Role);
1240 
1241  // Only add each header to the headers list once.
1242  // FIXME: Should we diagnose if a header is listed twice in the
1243  // same module definition?
1244  auto &HeaderList = Headers[Header.Entry];
1245  if (llvm::is_contained(HeaderList, KH))
1246  return;
1247 
1248  HeaderList.push_back(KH);
1249  Mod->Headers[headerRoleToKind(Role)].push_back(Header);
1250 
1251  bool isCompilingModuleHeader =
1252  LangOpts.isCompilingModule() && Mod->getTopLevelModule() == SourceModule;
1253  if (!Imported || isCompilingModuleHeader) {
1254  // When we import HeaderFileInfo, the external source is expected to
1255  // set the isModuleHeader flag itself.
1256  HeaderInfo.MarkFileModuleHeader(Header.Entry, Role,
1257  isCompilingModuleHeader);
1258  }
1259 
1260  // Notify callbacks that we just added a new header.
1261  for (const auto &Cb : Callbacks)
1262  Cb->moduleMapAddHeader(Header.Entry->getName());
1263 }
1264 
1266  // Add this as a known header so we won't implicitly add it to any
1267  // umbrella directory module.
1268  // FIXME: Should we only exclude it from umbrella modules within the
1269  // specified module?
1270  (void) Headers[Header.Entry];
1271 
1272  Mod->Headers[Module::HK_Excluded].push_back(std::move(Header));
1273 }
1274 
1275 const FileEntry *
1278  return nullptr;
1279 
1280  return SourceMgr.getFileEntryForID(
1281  SourceMgr.getFileID(Module->DefinitionLoc));
1282 }
1283 
1285  if (M->IsInferred) {
1286  assert(InferredModuleAllowedBy.count(M) && "missing inferred module map");
1287  return InferredModuleAllowedBy.find(M)->second;
1288  }
1289  return getContainingModuleMapFile(M);
1290 }
1291 
1293  assert(M->IsInferred && "module not inferred");
1294  InferredModuleAllowedBy[M] = ModMap;
1295 }
1296 
1298  const FileEntry *ModuleMap) {
1299  AdditionalModMaps[M].insert(ModuleMap);
1300 }
1301 
1302 LLVM_DUMP_METHOD void ModuleMap::dump() {
1303  llvm::errs() << "Modules:";
1304  for (llvm::StringMap<Module *>::iterator M = Modules.begin(),
1305  MEnd = Modules.end();
1306  M != MEnd; ++M)
1307  M->getValue()->print(llvm::errs(), 2);
1308 
1309  llvm::errs() << "Headers:";
1310  for (HeadersMap::iterator H = Headers.begin(), HEnd = Headers.end();
1311  H != HEnd; ++H) {
1312  llvm::errs() << " \"" << H->first->getName() << "\" -> ";
1313  for (SmallVectorImpl<KnownHeader>::const_iterator I = H->second.begin(),
1314  E = H->second.end();
1315  I != E; ++I) {
1316  if (I != H->second.begin())
1317  llvm::errs() << ",";
1318  llvm::errs() << I->getModule()->getFullModuleName();
1319  }
1320  llvm::errs() << "\n";
1321  }
1322 }
1323 
1324 bool ModuleMap::resolveExports(Module *Mod, bool Complain) {
1325  auto Unresolved = std::move(Mod->UnresolvedExports);
1326  Mod->UnresolvedExports.clear();
1327  for (auto &UE : Unresolved) {
1328  Module::ExportDecl Export = resolveExport(Mod, UE, Complain);
1329  if (Export.getPointer() || Export.getInt())
1330  Mod->Exports.push_back(Export);
1331  else
1332  Mod->UnresolvedExports.push_back(UE);
1333  }
1334  return !Mod->UnresolvedExports.empty();
1335 }
1336 
1337 bool ModuleMap::resolveUses(Module *Mod, bool Complain) {
1338  auto Unresolved = std::move(Mod->UnresolvedDirectUses);
1339  Mod->UnresolvedDirectUses.clear();
1340  for (auto &UDU : Unresolved) {
1341  Module *DirectUse = resolveModuleId(UDU, Mod, Complain);
1342  if (DirectUse)
1343  Mod->DirectUses.push_back(DirectUse);
1344  else
1345  Mod->UnresolvedDirectUses.push_back(UDU);
1346  }
1347  return !Mod->UnresolvedDirectUses.empty();
1348 }
1349 
1350 bool ModuleMap::resolveConflicts(Module *Mod, bool Complain) {
1351  auto Unresolved = std::move(Mod->UnresolvedConflicts);
1352  Mod->UnresolvedConflicts.clear();
1353  for (auto &UC : Unresolved) {
1354  if (Module *OtherMod = resolveModuleId(UC.Id, Mod, Complain)) {
1355  Module::Conflict Conflict;
1356  Conflict.Other = OtherMod;
1357  Conflict.Message = UC.Message;
1358  Mod->Conflicts.push_back(Conflict);
1359  } else
1360  Mod->UnresolvedConflicts.push_back(UC);
1361  }
1362  return !Mod->UnresolvedConflicts.empty();
1363 }
1364 
1365 //----------------------------------------------------------------------------//
1366 // Module map file parser
1367 //----------------------------------------------------------------------------//
1368 
1369 namespace clang {
1370 
1371  /// A token in a module map file.
1372  struct MMToken {
1373  enum TokenKind {
1402  } Kind;
1403 
1405  unsigned StringLength;
1406  union {
1407  // If Kind != IntegerLiteral.
1408  const char *StringData;
1409 
1410  // If Kind == IntegerLiteral.
1411  uint64_t IntegerValue;
1412  };
1413 
1414  void clear() {
1415  Kind = EndOfFile;
1416  Location = 0;
1417  StringLength = 0;
1418  StringData = nullptr;
1419  }
1420 
1421  bool is(TokenKind K) const { return Kind == K; }
1422 
1425  }
1426 
1427  uint64_t getInteger() const {
1428  return Kind == IntegerLiteral ? IntegerValue : 0;
1429  }
1430 
1431  StringRef getString() const {
1432  return Kind == IntegerLiteral ? StringRef()
1433  : StringRef(StringData, StringLength);
1434  }
1435  };
1436 
1438  Lexer &L;
1439  SourceManager &SourceMgr;
1440 
1441  /// Default target information, used only for string literal
1442  /// parsing.
1443  const TargetInfo *Target;
1444 
1445  DiagnosticsEngine &Diags;
1446  ModuleMap &Map;
1447 
1448  /// The current module map file.
1449  const FileEntry *ModuleMapFile;
1450 
1451  /// Source location of most recent parsed module declaration
1452  SourceLocation CurrModuleDeclLoc;
1453 
1454  /// The directory that file names in this module map file should
1455  /// be resolved relative to.
1456  const DirectoryEntry *Directory;
1457 
1458  /// Whether this module map is in a system header directory.
1459  bool IsSystem;
1460 
1461  /// Whether an error occurred.
1462  bool HadError = false;
1463 
1464  /// Stores string data for the various string literals referenced
1465  /// during parsing.
1466  llvm::BumpPtrAllocator StringData;
1467 
1468  /// The current token.
1469  MMToken Tok;
1470 
1471  /// The active module.
1472  Module *ActiveModule = nullptr;
1473 
1474  /// Whether a module uses the 'requires excluded' hack to mark its
1475  /// contents as 'textual'.
1476  ///
1477  /// On older Darwin SDK versions, 'requires excluded' is used to mark the
1478  /// contents of the Darwin.C.excluded (assert.h) and Tcl.Private modules as
1479  /// non-modular headers. For backwards compatibility, we continue to
1480  /// support this idiom for just these modules, and map the headers to
1481  /// 'textual' to match the original intent.
1482  llvm::SmallPtrSet<Module *, 2> UsesRequiresExcludedHack;
1483 
1484  /// Consume the current token and return its location.
1485  SourceLocation consumeToken();
1486 
1487  /// Skip tokens until we reach the a token with the given kind
1488  /// (or the end of the file).
1489  void skipUntil(MMToken::TokenKind K);
1490 
1492 
1493  bool parseModuleId(ModuleId &Id);
1494  void parseModuleDecl();
1495  void parseExternModuleDecl();
1496  void parseRequiresDecl();
1497  void parseHeaderDecl(MMToken::TokenKind, SourceLocation LeadingLoc);
1498  void parseUmbrellaDirDecl(SourceLocation UmbrellaLoc);
1499  void parseExportDecl();
1500  void parseExportAsDecl();
1501  void parseUseDecl();
1502  void parseLinkDecl();
1503  void parseConfigMacros();
1504  void parseConflict();
1505  void parseInferredModuleDecl(bool Framework, bool Explicit);
1506 
1507  /// Private modules are canonicalized as Foo_Private. Clang provides extra
1508  /// module map search logic to find the appropriate private module when PCH
1509  /// is used with implicit module maps. Warn when private modules are written
1510  /// in other ways (FooPrivate and Foo.Private), providing notes and fixits.
1511  void diagnosePrivateModules(SourceLocation ExplicitLoc,
1512  SourceLocation FrameworkLoc);
1513 
1514  using Attributes = ModuleMap::Attributes;
1515 
1516  bool parseOptionalAttributes(Attributes &Attrs);
1517 
1518  public:
1519  explicit ModuleMapParser(Lexer &L, SourceManager &SourceMgr,
1520  const TargetInfo *Target, DiagnosticsEngine &Diags,
1521  ModuleMap &Map, const FileEntry *ModuleMapFile,
1522  const DirectoryEntry *Directory, bool IsSystem)
1523  : L(L), SourceMgr(SourceMgr), Target(Target), Diags(Diags), Map(Map),
1524  ModuleMapFile(ModuleMapFile), Directory(Directory),
1525  IsSystem(IsSystem) {
1526  Tok.clear();
1527  consumeToken();
1528  }
1529 
1530  bool parseModuleMapFile();
1531 
1532  bool terminatedByDirective() { return false; }
1534  };
1535 
1536 } // namespace clang
1537 
1538 SourceLocation ModuleMapParser::consumeToken() {
1539  SourceLocation Result = Tok.getLocation();
1540 
1541 retry:
1542  Tok.clear();
1543  Token LToken;
1544  L.LexFromRawLexer(LToken);
1545  Tok.Location = LToken.getLocation().getRawEncoding();
1546  switch (LToken.getKind()) {
1547  case tok::raw_identifier: {
1548  StringRef RI = LToken.getRawIdentifier();
1549  Tok.StringData = RI.data();
1550  Tok.StringLength = RI.size();
1551  Tok.Kind = llvm::StringSwitch<MMToken::TokenKind>(RI)
1552  .Case("config_macros", MMToken::ConfigMacros)
1553  .Case("conflict", MMToken::Conflict)
1554  .Case("exclude", MMToken::ExcludeKeyword)
1555  .Case("explicit", MMToken::ExplicitKeyword)
1556  .Case("export", MMToken::ExportKeyword)
1557  .Case("export_as", MMToken::ExportAsKeyword)
1558  .Case("extern", MMToken::ExternKeyword)
1559  .Case("framework", MMToken::FrameworkKeyword)
1560  .Case("header", MMToken::HeaderKeyword)
1561  .Case("link", MMToken::LinkKeyword)
1562  .Case("module", MMToken::ModuleKeyword)
1563  .Case("private", MMToken::PrivateKeyword)
1564  .Case("requires", MMToken::RequiresKeyword)
1565  .Case("textual", MMToken::TextualKeyword)
1566  .Case("umbrella", MMToken::UmbrellaKeyword)
1567  .Case("use", MMToken::UseKeyword)
1568  .Default(MMToken::Identifier);
1569  break;
1570  }
1571 
1572  case tok::comma:
1573  Tok.Kind = MMToken::Comma;
1574  break;
1575 
1576  case tok::eof:
1577  Tok.Kind = MMToken::EndOfFile;
1578  break;
1579 
1580  case tok::l_brace:
1581  Tok.Kind = MMToken::LBrace;
1582  break;
1583 
1584  case tok::l_square:
1585  Tok.Kind = MMToken::LSquare;
1586  break;
1587 
1588  case tok::period:
1589  Tok.Kind = MMToken::Period;
1590  break;
1591 
1592  case tok::r_brace:
1593  Tok.Kind = MMToken::RBrace;
1594  break;
1595 
1596  case tok::r_square:
1597  Tok.Kind = MMToken::RSquare;
1598  break;
1599 
1600  case tok::star:
1601  Tok.Kind = MMToken::Star;
1602  break;
1603 
1604  case tok::exclaim:
1605  Tok.Kind = MMToken::Exclaim;
1606  break;
1607 
1608  case tok::string_literal: {
1609  if (LToken.hasUDSuffix()) {
1610  Diags.Report(LToken.getLocation(), diag::err_invalid_string_udl);
1611  HadError = true;
1612  goto retry;
1613  }
1614 
1615  // Parse the string literal.
1616  LangOptions LangOpts;
1617  StringLiteralParser StringLiteral(LToken, SourceMgr, LangOpts, *Target);
1618  if (StringLiteral.hadError)
1619  goto retry;
1620 
1621  // Copy the string literal into our string data allocator.
1622  unsigned Length = StringLiteral.GetStringLength();
1623  char *Saved = StringData.Allocate<char>(Length + 1);
1624  memcpy(Saved, StringLiteral.GetString().data(), Length);
1625  Saved[Length] = 0;
1626 
1627  // Form the token.
1629  Tok.StringData = Saved;
1630  Tok.StringLength = Length;
1631  break;
1632  }
1633 
1634  case tok::numeric_constant: {
1635  // We don't support any suffixes or other complications.
1636  SmallString<32> SpellingBuffer;
1637  SpellingBuffer.resize(LToken.getLength() + 1);
1638  const char *Start = SpellingBuffer.data();
1639  unsigned Length =
1640  Lexer::getSpelling(LToken, Start, SourceMgr, Map.LangOpts);
1641  uint64_t Value;
1642  if (StringRef(Start, Length).getAsInteger(0, Value)) {
1643  Diags.Report(Tok.getLocation(), diag::err_mmap_unknown_token);
1644  HadError = true;
1645  goto retry;
1646  }
1647 
1649  Tok.IntegerValue = Value;
1650  break;
1651  }
1652 
1653  case tok::comment:
1654  goto retry;
1655 
1656  case tok::hash:
1657  // A module map can be terminated prematurely by
1658  // #pragma clang module contents
1659  // When building the module, we'll treat the rest of the file as the
1660  // contents of the module.
1661  {
1662  auto NextIsIdent = [&](StringRef Str) -> bool {
1663  L.LexFromRawLexer(LToken);
1664  return !LToken.isAtStartOfLine() && LToken.is(tok::raw_identifier) &&
1665  LToken.getRawIdentifier() == Str;
1666  };
1667  if (NextIsIdent("pragma") && NextIsIdent("clang") &&
1668  NextIsIdent("module") && NextIsIdent("contents")) {
1669  Tok.Kind = MMToken::EndOfFile;
1670  break;
1671  }
1672  }
1673  LLVM_FALLTHROUGH;
1674 
1675  default:
1676  Diags.Report(Tok.getLocation(), diag::err_mmap_unknown_token);
1677  HadError = true;
1678  goto retry;
1679  }
1680 
1681  return Result;
1682 }
1683 
1684 void ModuleMapParser::skipUntil(MMToken::TokenKind K) {
1685  unsigned braceDepth = 0;
1686  unsigned squareDepth = 0;
1687  do {
1688  switch (Tok.Kind) {
1689  case MMToken::EndOfFile:
1690  return;
1691 
1692  case MMToken::LBrace:
1693  if (Tok.is(K) && braceDepth == 0 && squareDepth == 0)
1694  return;
1695 
1696  ++braceDepth;
1697  break;
1698 
1699  case MMToken::LSquare:
1700  if (Tok.is(K) && braceDepth == 0 && squareDepth == 0)
1701  return;
1702 
1703  ++squareDepth;
1704  break;
1705 
1706  case MMToken::RBrace:
1707  if (braceDepth > 0)
1708  --braceDepth;
1709  else if (Tok.is(K))
1710  return;
1711  break;
1712 
1713  case MMToken::RSquare:
1714  if (squareDepth > 0)
1715  --squareDepth;
1716  else if (Tok.is(K))
1717  return;
1718  break;
1719 
1720  default:
1721  if (braceDepth == 0 && squareDepth == 0 && Tok.is(K))
1722  return;
1723  break;
1724  }
1725 
1726  consumeToken();
1727  } while (true);
1728 }
1729 
1730 /// Parse a module-id.
1731 ///
1732 /// module-id:
1733 /// identifier
1734 /// identifier '.' module-id
1735 ///
1736 /// \returns true if an error occurred, false otherwise.
1737 bool ModuleMapParser::parseModuleId(ModuleId &Id) {
1738  Id.clear();
1739  do {
1740  if (Tok.is(MMToken::Identifier) || Tok.is(MMToken::StringLiteral)) {
1741  Id.push_back(
1742  std::make_pair(std::string(Tok.getString()), Tok.getLocation()));
1743  consumeToken();
1744  } else {
1745  Diags.Report(Tok.getLocation(), diag::err_mmap_expected_module_name);
1746  return true;
1747  }
1748 
1749  if (!Tok.is(MMToken::Period))
1750  break;
1751 
1752  consumeToken();
1753  } while (true);
1754 
1755  return false;
1756 }
1757 
1758 namespace {
1759 
1760  /// Enumerates the known attributes.
1761  enum AttributeKind {
1762  /// An unknown attribute.
1763  AT_unknown,
1764 
1765  /// The 'system' attribute.
1766  AT_system,
1767 
1768  /// The 'extern_c' attribute.
1769  AT_extern_c,
1770 
1771  /// The 'exhaustive' attribute.
1772  AT_exhaustive,
1773 
1774  /// The 'no_undeclared_includes' attribute.
1775  AT_no_undeclared_includes
1776  };
1777 
1778 } // namespace
1779 
1780 /// Private modules are canonicalized as Foo_Private. Clang provides extra
1781 /// module map search logic to find the appropriate private module when PCH
1782 /// is used with implicit module maps. Warn when private modules are written
1783 /// in other ways (FooPrivate and Foo.Private), providing notes and fixits.
1784 void ModuleMapParser::diagnosePrivateModules(SourceLocation ExplicitLoc,
1785  SourceLocation FrameworkLoc) {
1786  auto GenNoteAndFixIt = [&](StringRef BadName, StringRef Canonical,
1787  const Module *M, SourceRange ReplLoc) {
1788  auto D = Diags.Report(ActiveModule->DefinitionLoc,
1789  diag::note_mmap_rename_top_level_private_module);
1790  D << BadName << M->Name;
1791  D << FixItHint::CreateReplacement(ReplLoc, Canonical);
1792  };
1793 
1794  for (auto E = Map.module_begin(); E != Map.module_end(); ++E) {
1795  auto const *M = E->getValue();
1796  if (M->Directory != ActiveModule->Directory)
1797  continue;
1798 
1799  SmallString<128> FullName(ActiveModule->getFullModuleName());
1800  if (!FullName.startswith(M->Name) && !FullName.endswith("Private"))
1801  continue;
1802  SmallString<128> FixedPrivModDecl;
1803  SmallString<128> Canonical(M->Name);
1804  Canonical.append("_Private");
1805 
1806  // Foo.Private -> Foo_Private
1807  if (ActiveModule->Parent && ActiveModule->Name == "Private" && !M->Parent &&
1808  M->Name == ActiveModule->Parent->Name) {
1809  Diags.Report(ActiveModule->DefinitionLoc,
1810  diag::warn_mmap_mismatched_private_submodule)
1811  << FullName;
1812 
1813  SourceLocation FixItInitBegin = CurrModuleDeclLoc;
1814  if (FrameworkLoc.isValid())
1815  FixItInitBegin = FrameworkLoc;
1816  if (ExplicitLoc.isValid())
1817  FixItInitBegin = ExplicitLoc;
1818 
1819  if (FrameworkLoc.isValid() || ActiveModule->Parent->IsFramework)
1820  FixedPrivModDecl.append("framework ");
1821  FixedPrivModDecl.append("module ");
1822  FixedPrivModDecl.append(Canonical);
1823 
1824  GenNoteAndFixIt(FullName, FixedPrivModDecl, M,
1825  SourceRange(FixItInitBegin, ActiveModule->DefinitionLoc));
1826  continue;
1827  }
1828 
1829  // FooPrivate and whatnots -> Foo_Private
1830  if (!ActiveModule->Parent && !M->Parent && M->Name != ActiveModule->Name &&
1831  ActiveModule->Name != Canonical) {
1832  Diags.Report(ActiveModule->DefinitionLoc,
1833  diag::warn_mmap_mismatched_private_module_name)
1834  << ActiveModule->Name;
1835  GenNoteAndFixIt(ActiveModule->Name, Canonical, M,
1836  SourceRange(ActiveModule->DefinitionLoc));
1837  }
1838  }
1839 }
1840 
1841 /// Parse a module declaration.
1842 ///
1843 /// module-declaration:
1844 /// 'extern' 'module' module-id string-literal
1845 /// 'explicit'[opt] 'framework'[opt] 'module' module-id attributes[opt]
1846 /// { module-member* }
1847 ///
1848 /// module-member:
1849 /// requires-declaration
1850 /// header-declaration
1851 /// submodule-declaration
1852 /// export-declaration
1853 /// export-as-declaration
1854 /// link-declaration
1855 ///
1856 /// submodule-declaration:
1857 /// module-declaration
1858 /// inferred-submodule-declaration
1859 void ModuleMapParser::parseModuleDecl() {
1860  assert(Tok.is(MMToken::ExplicitKeyword) || Tok.is(MMToken::ModuleKeyword) ||
1862  if (Tok.is(MMToken::ExternKeyword)) {
1863  parseExternModuleDecl();
1864  return;
1865  }
1866 
1867  // Parse 'explicit' or 'framework' keyword, if present.
1868  SourceLocation ExplicitLoc;
1869  SourceLocation FrameworkLoc;
1870  bool Explicit = false;
1871  bool Framework = false;
1872 
1873  // Parse 'explicit' keyword, if present.
1874  if (Tok.is(MMToken::ExplicitKeyword)) {
1875  ExplicitLoc = consumeToken();
1876  Explicit = true;
1877  }
1878 
1879  // Parse 'framework' keyword, if present.
1880  if (Tok.is(MMToken::FrameworkKeyword)) {
1881  FrameworkLoc = consumeToken();
1882  Framework = true;
1883  }
1884 
1885  // Parse 'module' keyword.
1886  if (!Tok.is(MMToken::ModuleKeyword)) {
1887  Diags.Report(Tok.getLocation(), diag::err_mmap_expected_module);
1888  consumeToken();
1889  HadError = true;
1890  return;
1891  }
1892  CurrModuleDeclLoc = consumeToken(); // 'module' keyword
1893 
1894  // If we have a wildcard for the module name, this is an inferred submodule.
1895  // Parse it.
1896  if (Tok.is(MMToken::Star))
1897  return parseInferredModuleDecl(Framework, Explicit);
1898 
1899  // Parse the module name.
1900  ModuleId Id;
1901  if (parseModuleId(Id)) {
1902  HadError = true;
1903  return;
1904  }
1905 
1906  if (ActiveModule) {
1907  if (Id.size() > 1) {
1908  Diags.Report(Id.front().second, diag::err_mmap_nested_submodule_id)
1909  << SourceRange(Id.front().second, Id.back().second);
1910 
1911  HadError = true;
1912  return;
1913  }
1914  } else if (Id.size() == 1 && Explicit) {
1915  // Top-level modules can't be explicit.
1916  Diags.Report(ExplicitLoc, diag::err_mmap_explicit_top_level);
1917  Explicit = false;
1918  ExplicitLoc = SourceLocation();
1919  HadError = true;
1920  }
1921 
1922  Module *PreviousActiveModule = ActiveModule;
1923  if (Id.size() > 1) {
1924  // This module map defines a submodule. Go find the module of which it
1925  // is a submodule.
1926  ActiveModule = nullptr;
1927  const Module *TopLevelModule = nullptr;
1928  for (unsigned I = 0, N = Id.size() - 1; I != N; ++I) {
1929  if (Module *Next = Map.lookupModuleQualified(Id[I].first, ActiveModule)) {
1930  if (I == 0)
1931  TopLevelModule = Next;
1932  ActiveModule = Next;
1933  continue;
1934  }
1935 
1936  Diags.Report(Id[I].second, diag::err_mmap_missing_parent_module)
1937  << Id[I].first << (ActiveModule != nullptr)
1938  << (ActiveModule
1939  ? ActiveModule->getTopLevelModule()->getFullModuleName()
1940  : "");
1941  HadError = true;
1942  }
1943 
1944  if (TopLevelModule &&
1945  ModuleMapFile != Map.getContainingModuleMapFile(TopLevelModule)) {
1946  assert(ModuleMapFile != Map.getModuleMapFileForUniquing(TopLevelModule) &&
1947  "submodule defined in same file as 'module *' that allowed its "
1948  "top-level module");
1949  Map.addAdditionalModuleMapFile(TopLevelModule, ModuleMapFile);
1950  }
1951  }
1952 
1953  StringRef ModuleName = Id.back().first;
1954  SourceLocation ModuleNameLoc = Id.back().second;
1955 
1956  // Parse the optional attribute list.
1957  Attributes Attrs;
1958  if (parseOptionalAttributes(Attrs))
1959  return;
1960 
1961  // Parse the opening brace.
1962  if (!Tok.is(MMToken::LBrace)) {
1963  Diags.Report(Tok.getLocation(), diag::err_mmap_expected_lbrace)
1964  << ModuleName;
1965  HadError = true;
1966  return;
1967  }
1968  SourceLocation LBraceLoc = consumeToken();
1969 
1970  // Determine whether this (sub)module has already been defined.
1971  Module *ShadowingModule = nullptr;
1972  if (Module *Existing = Map.lookupModuleQualified(ModuleName, ActiveModule)) {
1973  // We might see a (re)definition of a module that we already have a
1974  // definition for in two cases:
1975  // - If we loaded one definition from an AST file and we've just found a
1976  // corresponding definition in a module map file, or
1977  bool LoadedFromASTFile = Existing->DefinitionLoc.isInvalid();
1978  // - If we're building a (preprocessed) module and we've just loaded the
1979  // module map file from which it was created.
1980  bool ParsedAsMainInput =
1981  Map.LangOpts.getCompilingModule() == LangOptions::CMK_ModuleMap &&
1982  Map.LangOpts.CurrentModule == ModuleName &&
1983  SourceMgr.getDecomposedLoc(ModuleNameLoc).first !=
1984  SourceMgr.getDecomposedLoc(Existing->DefinitionLoc).first;
1985  if (!ActiveModule && (LoadedFromASTFile || ParsedAsMainInput)) {
1986  // Skip the module definition.
1987  skipUntil(MMToken::RBrace);
1988  if (Tok.is(MMToken::RBrace))
1989  consumeToken();
1990  else {
1991  Diags.Report(Tok.getLocation(), diag::err_mmap_expected_rbrace);
1992  Diags.Report(LBraceLoc, diag::note_mmap_lbrace_match);
1993  HadError = true;
1994  }
1995  return;
1996  }
1997 
1998  if (!Existing->Parent && Map.mayShadowNewModule(Existing)) {
1999  ShadowingModule = Existing;
2000  } else {
2001  // This is not a shawdowed module decl, it is an illegal redefinition.
2002  Diags.Report(ModuleNameLoc, diag::err_mmap_module_redefinition)
2003  << ModuleName;
2004  Diags.Report(Existing->DefinitionLoc, diag::note_mmap_prev_definition);
2005 
2006  // Skip the module definition.
2007  skipUntil(MMToken::RBrace);
2008  if (Tok.is(MMToken::RBrace))
2009  consumeToken();
2010 
2011  HadError = true;
2012  return;
2013  }
2014  }
2015 
2016  // Start defining this module.
2017  if (ShadowingModule) {
2018  ActiveModule =
2019  Map.createShadowedModule(ModuleName, Framework, ShadowingModule);
2020  } else {
2021  ActiveModule =
2022  Map.findOrCreateModule(ModuleName, ActiveModule, Framework, Explicit)
2023  .first;
2024  }
2025 
2026  ActiveModule->DefinitionLoc = ModuleNameLoc;
2027  if (Attrs.IsSystem || IsSystem)
2028  ActiveModule->IsSystem = true;
2029  if (Attrs.IsExternC)
2030  ActiveModule->IsExternC = true;
2031  if (Attrs.NoUndeclaredIncludes ||
2032  (!ActiveModule->Parent && ModuleName == "Darwin"))
2033  ActiveModule->NoUndeclaredIncludes = true;
2034  ActiveModule->Directory = Directory;
2035 
2036  StringRef MapFileName(ModuleMapFile->getName());
2037  if (MapFileName.endswith("module.private.modulemap") ||
2038  MapFileName.endswith("module_private.map")) {
2039  ActiveModule->ModuleMapIsPrivate = true;
2040  }
2041 
2042  // Private modules named as FooPrivate, Foo.Private or similar are likely a
2043  // user error; provide warnings, notes and fixits to direct users to use
2044  // Foo_Private instead.
2045  SourceLocation StartLoc =
2046  SourceMgr.getLocForStartOfFile(SourceMgr.getMainFileID());
2047  if (Map.HeaderInfo.getHeaderSearchOpts().ImplicitModuleMaps &&
2048  !Diags.isIgnored(diag::warn_mmap_mismatched_private_submodule,
2049  StartLoc) &&
2050  !Diags.isIgnored(diag::warn_mmap_mismatched_private_module_name,
2051  StartLoc) &&
2052  ActiveModule->ModuleMapIsPrivate)
2053  diagnosePrivateModules(ExplicitLoc, FrameworkLoc);
2054 
2055  bool Done = false;
2056  do {
2057  switch (Tok.Kind) {
2058  case MMToken::EndOfFile:
2059  case MMToken::RBrace:
2060  Done = true;
2061  break;
2062 
2063  case MMToken::ConfigMacros:
2064  parseConfigMacros();
2065  break;
2066 
2067  case MMToken::Conflict:
2068  parseConflict();
2069  break;
2070 
2075  parseModuleDecl();
2076  break;
2077 
2079  parseExportDecl();
2080  break;
2081 
2083  parseExportAsDecl();
2084  break;
2085 
2086  case MMToken::UseKeyword:
2087  parseUseDecl();
2088  break;
2089 
2091  parseRequiresDecl();
2092  break;
2093 
2095  parseHeaderDecl(MMToken::TextualKeyword, consumeToken());
2096  break;
2097 
2098  case MMToken::UmbrellaKeyword: {
2099  SourceLocation UmbrellaLoc = consumeToken();
2100  if (Tok.is(MMToken::HeaderKeyword))
2101  parseHeaderDecl(MMToken::UmbrellaKeyword, UmbrellaLoc);
2102  else
2103  parseUmbrellaDirDecl(UmbrellaLoc);
2104  break;
2105  }
2106 
2108  parseHeaderDecl(MMToken::ExcludeKeyword, consumeToken());
2109  break;
2110 
2112  parseHeaderDecl(MMToken::PrivateKeyword, consumeToken());
2113  break;
2114 
2116  parseHeaderDecl(MMToken::HeaderKeyword, consumeToken());
2117  break;
2118 
2119  case MMToken::LinkKeyword:
2120  parseLinkDecl();
2121  break;
2122 
2123  default:
2124  Diags.Report(Tok.getLocation(), diag::err_mmap_expected_member);
2125  consumeToken();
2126  break;
2127  }
2128  } while (!Done);
2129 
2130  if (Tok.is(MMToken::RBrace))
2131  consumeToken();
2132  else {
2133  Diags.Report(Tok.getLocation(), diag::err_mmap_expected_rbrace);
2134  Diags.Report(LBraceLoc, diag::note_mmap_lbrace_match);
2135  HadError = true;
2136  }
2137 
2138  // If the active module is a top-level framework, and there are no link
2139  // libraries, automatically link against the framework.
2140  if (ActiveModule->IsFramework && !ActiveModule->isSubFramework() &&
2141  ActiveModule->LinkLibraries.empty()) {
2142  inferFrameworkLink(ActiveModule, Directory, SourceMgr.getFileManager());
2143  }
2144 
2145  // If the module meets all requirements but is still unavailable, mark the
2146  // whole tree as unavailable to prevent it from building.
2147  if (!ActiveModule->IsAvailable && !ActiveModule->IsUnimportable &&
2148  ActiveModule->Parent) {
2149  ActiveModule->getTopLevelModule()->markUnavailable(/*Unimportable=*/false);
2150  ActiveModule->getTopLevelModule()->MissingHeaders.append(
2151  ActiveModule->MissingHeaders.begin(), ActiveModule->MissingHeaders.end());
2152  }
2153 
2154  // We're done parsing this module. Pop back to the previous module.
2155  ActiveModule = PreviousActiveModule;
2156 }
2157 
2158 /// Parse an extern module declaration.
2159 ///
2160 /// extern module-declaration:
2161 /// 'extern' 'module' module-id string-literal
2162 void ModuleMapParser::parseExternModuleDecl() {
2163  assert(Tok.is(MMToken::ExternKeyword));
2164  SourceLocation ExternLoc = consumeToken(); // 'extern' keyword
2165 
2166  // Parse 'module' keyword.
2167  if (!Tok.is(MMToken::ModuleKeyword)) {
2168  Diags.Report(Tok.getLocation(), diag::err_mmap_expected_module);
2169  consumeToken();
2170  HadError = true;
2171  return;
2172  }
2173  consumeToken(); // 'module' keyword
2174 
2175  // Parse the module name.
2176  ModuleId Id;
2177  if (parseModuleId(Id)) {
2178  HadError = true;
2179  return;
2180  }
2181 
2182  // Parse the referenced module map file name.
2183  if (!Tok.is(MMToken::StringLiteral)) {
2184  Diags.Report(Tok.getLocation(), diag::err_mmap_expected_mmap_file);
2185  HadError = true;
2186  return;
2187  }
2188  std::string FileName = std::string(Tok.getString());
2189  consumeToken(); // filename
2190 
2191  StringRef FileNameRef = FileName;
2192  SmallString<128> ModuleMapFileName;
2193  if (llvm::sys::path::is_relative(FileNameRef)) {
2194  ModuleMapFileName += Directory->getName();
2195  llvm::sys::path::append(ModuleMapFileName, FileName);
2196  FileNameRef = ModuleMapFileName;
2197  }
2198  if (auto File = SourceMgr.getFileManager().getFile(FileNameRef))
2199  Map.parseModuleMapFile(
2200  *File, IsSystem,
2202  ? Directory
2203  : (*File)->getDir(),
2204  FileID(), nullptr, ExternLoc);
2205 }
2206 
2207 /// Whether to add the requirement \p Feature to the module \p M.
2208 ///
2209 /// This preserves backwards compatibility for two hacks in the Darwin system
2210 /// module map files:
2211 ///
2212 /// 1. The use of 'requires excluded' to make headers non-modular, which
2213 /// should really be mapped to 'textual' now that we have this feature. We
2214 /// drop the 'excluded' requirement, and set \p IsRequiresExcludedHack to
2215 /// true. Later, this bit will be used to map all the headers inside this
2216 /// module to 'textual'.
2217 ///
2218 /// This affects Darwin.C.excluded (for assert.h) and Tcl.Private.
2219 ///
2220 /// 2. Removes a bogus cplusplus requirement from IOKit.avc. This requirement
2221 /// was never correct and causes issues now that we check it, so drop it.
2222 static bool shouldAddRequirement(Module *M, StringRef Feature,
2223  bool &IsRequiresExcludedHack) {
2224  if (Feature == "excluded" &&
2225  (M->fullModuleNameIs({"Darwin", "C", "excluded"}) ||
2226  M->fullModuleNameIs({"Tcl", "Private"}))) {
2227  IsRequiresExcludedHack = true;
2228  return false;
2229  } else if (Feature == "cplusplus" && M->fullModuleNameIs({"IOKit", "avc"})) {
2230  return false;
2231  }
2232 
2233  return true;
2234 }
2235 
2236 /// Parse a requires declaration.
2237 ///
2238 /// requires-declaration:
2239 /// 'requires' feature-list
2240 ///
2241 /// feature-list:
2242 /// feature ',' feature-list
2243 /// feature
2244 ///
2245 /// feature:
2246 /// '!'[opt] identifier
2247 void ModuleMapParser::parseRequiresDecl() {
2248  assert(Tok.is(MMToken::RequiresKeyword));
2249 
2250  // Parse 'requires' keyword.
2251  consumeToken();
2252 
2253  // Parse the feature-list.
2254  do {
2255  bool RequiredState = true;
2256  if (Tok.is(MMToken::Exclaim)) {
2257  RequiredState = false;
2258  consumeToken();
2259  }
2260 
2261  if (!Tok.is(MMToken::Identifier)) {
2262  Diags.Report(Tok.getLocation(), diag::err_mmap_expected_feature);
2263  HadError = true;
2264  return;
2265  }
2266 
2267  // Consume the feature name.
2268  std::string Feature = std::string(Tok.getString());
2269  consumeToken();
2270 
2271  bool IsRequiresExcludedHack = false;
2272  bool ShouldAddRequirement =
2273  shouldAddRequirement(ActiveModule, Feature, IsRequiresExcludedHack);
2274 
2275  if (IsRequiresExcludedHack)
2276  UsesRequiresExcludedHack.insert(ActiveModule);
2277 
2278  if (ShouldAddRequirement) {
2279  // Add this feature.
2280  ActiveModule->addRequirement(Feature, RequiredState, Map.LangOpts,
2281  *Map.Target);
2282  }
2283 
2284  if (!Tok.is(MMToken::Comma))
2285  break;
2286 
2287  // Consume the comma.
2288  consumeToken();
2289  } while (true);
2290 }
2291 
2292 /// Parse a header declaration.
2293 ///
2294 /// header-declaration:
2295 /// 'textual'[opt] 'header' string-literal
2296 /// 'private' 'textual'[opt] 'header' string-literal
2297 /// 'exclude' 'header' string-literal
2298 /// 'umbrella' 'header' string-literal
2299 ///
2300 /// FIXME: Support 'private textual header'.
2301 void ModuleMapParser::parseHeaderDecl(MMToken::TokenKind LeadingToken,
2302  SourceLocation LeadingLoc) {
2303  // We've already consumed the first token.
2305  if (LeadingToken == MMToken::PrivateKeyword) {
2306  Role = ModuleMap::PrivateHeader;
2307  // 'private' may optionally be followed by 'textual'.
2308  if (Tok.is(MMToken::TextualKeyword)) {
2309  LeadingToken = Tok.Kind;
2310  consumeToken();
2311  }
2312  }
2313 
2314  if (LeadingToken == MMToken::TextualKeyword)
2316 
2317  if (UsesRequiresExcludedHack.count(ActiveModule)) {
2318  // Mark this header 'textual' (see doc comment for
2319  // Module::UsesRequiresExcludedHack).
2321  }
2322 
2323  if (LeadingToken != MMToken::HeaderKeyword) {
2324  if (!Tok.is(MMToken::HeaderKeyword)) {
2325  Diags.Report(Tok.getLocation(), diag::err_mmap_expected_header)
2326  << (LeadingToken == MMToken::PrivateKeyword ? "private" :
2327  LeadingToken == MMToken::ExcludeKeyword ? "exclude" :
2328  LeadingToken == MMToken::TextualKeyword ? "textual" : "umbrella");
2329  return;
2330  }
2331  consumeToken();
2332  }
2333 
2334  // Parse the header name.
2335  if (!Tok.is(MMToken::StringLiteral)) {
2336  Diags.Report(Tok.getLocation(), diag::err_mmap_expected_header)
2337  << "header";
2338  HadError = true;
2339  return;
2340  }
2341  Module::UnresolvedHeaderDirective Header;
2342  Header.FileName = std::string(Tok.getString());
2343  Header.FileNameLoc = consumeToken();
2344  Header.IsUmbrella = LeadingToken == MMToken::UmbrellaKeyword;
2345  Header.Kind =
2346  (LeadingToken == MMToken::ExcludeKeyword ? Module::HK_Excluded
2347  : Map.headerRoleToKind(Role));
2348 
2349  // Check whether we already have an umbrella.
2350  if (Header.IsUmbrella && ActiveModule->Umbrella) {
2351  Diags.Report(Header.FileNameLoc, diag::err_mmap_umbrella_clash)
2352  << ActiveModule->getFullModuleName();
2353  HadError = true;
2354  return;
2355  }
2356 
2357  // If we were given stat information, parse it so we can skip looking for
2358  // the file.
2359  if (Tok.is(MMToken::LBrace)) {
2360  SourceLocation LBraceLoc = consumeToken();
2361 
2362  while (!Tok.is(MMToken::RBrace) && !Tok.is(MMToken::EndOfFile)) {
2363  enum Attribute { Size, ModTime, Unknown };
2364  StringRef Str = Tok.getString();
2365  SourceLocation Loc = consumeToken();
2366  switch (llvm::StringSwitch<Attribute>(Str)
2367  .Case("size", Size)
2368  .Case("mtime", ModTime)
2369  .Default(Unknown)) {
2370  case Size:
2371  if (Header.Size)
2372  Diags.Report(Loc, diag::err_mmap_duplicate_header_attribute) << Str;
2373  if (!Tok.is(MMToken::IntegerLiteral)) {
2374  Diags.Report(Tok.getLocation(),
2375  diag::err_mmap_invalid_header_attribute_value) << Str;
2376  skipUntil(MMToken::RBrace);
2377  break;
2378  }
2379  Header.Size = Tok.getInteger();
2380  consumeToken();
2381  break;
2382 
2383  case ModTime:
2384  if (Header.ModTime)
2385  Diags.Report(Loc, diag::err_mmap_duplicate_header_attribute) << Str;
2386  if (!Tok.is(MMToken::IntegerLiteral)) {
2387  Diags.Report(Tok.getLocation(),
2388  diag::err_mmap_invalid_header_attribute_value) << Str;
2389  skipUntil(MMToken::RBrace);
2390  break;
2391  }
2392  Header.ModTime = Tok.getInteger();
2393  consumeToken();
2394  break;
2395 
2396  case Unknown:
2397  Diags.Report(Loc, diag::err_mmap_expected_header_attribute);
2398  skipUntil(MMToken::RBrace);
2399  break;
2400  }
2401  }
2402 
2403  if (Tok.is(MMToken::RBrace))
2404  consumeToken();
2405  else {
2406  Diags.Report(Tok.getLocation(), diag::err_mmap_expected_rbrace);
2407  Diags.Report(LBraceLoc, diag::note_mmap_lbrace_match);
2408  HadError = true;
2409  }
2410  }
2411 
2412  bool NeedsFramework = false;
2413  Map.addUnresolvedHeader(ActiveModule, std::move(Header), NeedsFramework);
2414 
2415  if (NeedsFramework && ActiveModule)
2416  Diags.Report(CurrModuleDeclLoc, diag::note_mmap_add_framework_keyword)
2417  << ActiveModule->getFullModuleName()
2418  << FixItHint::CreateReplacement(CurrModuleDeclLoc, "framework module");
2419 }
2420 
2421 static int compareModuleHeaders(const Module::Header *A,
2422  const Module::Header *B) {
2423  return A->NameAsWritten.compare(B->NameAsWritten);
2424 }
2425 
2426 /// Parse an umbrella directory declaration.
2427 ///
2428 /// umbrella-dir-declaration:
2429 /// umbrella string-literal
2430 void ModuleMapParser::parseUmbrellaDirDecl(SourceLocation UmbrellaLoc) {
2431  // Parse the directory name.
2432  if (!Tok.is(MMToken::StringLiteral)) {
2433  Diags.Report(Tok.getLocation(), diag::err_mmap_expected_header)
2434  << "umbrella";
2435  HadError = true;
2436  return;
2437  }
2438 
2439  std::string DirName = std::string(Tok.getString());
2440  std::string DirNameAsWritten = DirName;
2441  SourceLocation DirNameLoc = consumeToken();
2442 
2443  // Check whether we already have an umbrella.
2444  if (ActiveModule->Umbrella) {
2445  Diags.Report(DirNameLoc, diag::err_mmap_umbrella_clash)
2446  << ActiveModule->getFullModuleName();
2447  HadError = true;
2448  return;
2449  }
2450 
2451  // Look for this file.
2452  const DirectoryEntry *Dir = nullptr;
2453  if (llvm::sys::path::is_absolute(DirName)) {
2454  if (auto D = SourceMgr.getFileManager().getDirectory(DirName))
2455  Dir = *D;
2456  } else {
2457  SmallString<128> PathName;
2458  PathName = Directory->getName();
2459  llvm::sys::path::append(PathName, DirName);
2460  if (auto D = SourceMgr.getFileManager().getDirectory(PathName))
2461  Dir = *D;
2462  }
2463 
2464  if (!Dir) {
2465  Diags.Report(DirNameLoc, diag::warn_mmap_umbrella_dir_not_found)
2466  << DirName;
2467  return;
2468  }
2469 
2470  if (UsesRequiresExcludedHack.count(ActiveModule)) {
2471  // Mark this header 'textual' (see doc comment for
2472  // ModuleMapParser::UsesRequiresExcludedHack). Although iterating over the
2473  // directory is relatively expensive, in practice this only applies to the
2474  // uncommonly used Tcl module on Darwin platforms.
2475  std::error_code EC;
2477  llvm::vfs::FileSystem &FS =
2478  SourceMgr.getFileManager().getVirtualFileSystem();
2479  for (llvm::vfs::recursive_directory_iterator I(FS, Dir->getName(), EC), E;
2480  I != E && !EC; I.increment(EC)) {
2481  if (auto FE = SourceMgr.getFileManager().getFile(I->path())) {
2482  Module::Header Header = {"", std::string(I->path()), *FE};
2483  Headers.push_back(std::move(Header));
2484  }
2485  }
2486 
2487  // Sort header paths so that the pcm doesn't depend on iteration order.
2488  llvm::array_pod_sort(Headers.begin(), Headers.end(), compareModuleHeaders);
2489 
2490  for (auto &Header : Headers)
2491  Map.addHeader(ActiveModule, std::move(Header), ModuleMap::TextualHeader);
2492  return;
2493  }
2494 
2495  if (Module *OwningModule = Map.UmbrellaDirs[Dir]) {
2496  Diags.Report(UmbrellaLoc, diag::err_mmap_umbrella_clash)
2497  << OwningModule->getFullModuleName();
2498  HadError = true;
2499  return;
2500  }
2501 
2502  // Record this umbrella directory.
2503  Map.setUmbrellaDir(ActiveModule, Dir, DirNameAsWritten, DirName);
2504 }
2505 
2506 /// Parse a module export declaration.
2507 ///
2508 /// export-declaration:
2509 /// 'export' wildcard-module-id
2510 ///
2511 /// wildcard-module-id:
2512 /// identifier
2513 /// '*'
2514 /// identifier '.' wildcard-module-id
2515 void ModuleMapParser::parseExportDecl() {
2516  assert(Tok.is(MMToken::ExportKeyword));
2517  SourceLocation ExportLoc = consumeToken();
2518 
2519  // Parse the module-id with an optional wildcard at the end.
2520  ModuleId ParsedModuleId;
2521  bool Wildcard = false;
2522  do {
2523  // FIXME: Support string-literal module names here.
2524  if (Tok.is(MMToken::Identifier)) {
2525  ParsedModuleId.push_back(
2526  std::make_pair(std::string(Tok.getString()), Tok.getLocation()));
2527  consumeToken();
2528 
2529  if (Tok.is(MMToken::Period)) {
2530  consumeToken();
2531  continue;
2532  }
2533 
2534  break;
2535  }
2536 
2537  if(Tok.is(MMToken::Star)) {
2538  Wildcard = true;
2539  consumeToken();
2540  break;
2541  }
2542 
2543  Diags.Report(Tok.getLocation(), diag::err_mmap_module_id);
2544  HadError = true;
2545  return;
2546  } while (true);
2547 
2548  Module::UnresolvedExportDecl Unresolved = {
2549  ExportLoc, ParsedModuleId, Wildcard
2550  };
2551  ActiveModule->UnresolvedExports.push_back(Unresolved);
2552 }
2553 
2554 /// Parse a module export_as declaration.
2555 ///
2556 /// export-as-declaration:
2557 /// 'export_as' identifier
2558 void ModuleMapParser::parseExportAsDecl() {
2559  assert(Tok.is(MMToken::ExportAsKeyword));
2560  consumeToken();
2561 
2562  if (!Tok.is(MMToken::Identifier)) {
2563  Diags.Report(Tok.getLocation(), diag::err_mmap_module_id);
2564  HadError = true;
2565  return;
2566  }
2567 
2568  if (ActiveModule->Parent) {
2569  Diags.Report(Tok.getLocation(), diag::err_mmap_submodule_export_as);
2570  consumeToken();
2571  return;
2572  }
2573 
2574  if (!ActiveModule->ExportAsModule.empty()) {
2575  if (ActiveModule->ExportAsModule == Tok.getString()) {
2576  Diags.Report(Tok.getLocation(), diag::warn_mmap_redundant_export_as)
2577  << ActiveModule->Name << Tok.getString();
2578  } else {
2579  Diags.Report(Tok.getLocation(), diag::err_mmap_conflicting_export_as)
2580  << ActiveModule->Name << ActiveModule->ExportAsModule
2581  << Tok.getString();
2582  }
2583  }
2584 
2585  ActiveModule->ExportAsModule = std::string(Tok.getString());
2586  Map.addLinkAsDependency(ActiveModule);
2587 
2588  consumeToken();
2589 }
2590 
2591 /// Parse a module use declaration.
2592 ///
2593 /// use-declaration:
2594 /// 'use' wildcard-module-id
2595 void ModuleMapParser::parseUseDecl() {
2596  assert(Tok.is(MMToken::UseKeyword));
2597  auto KWLoc = consumeToken();
2598  // Parse the module-id.
2599  ModuleId ParsedModuleId;
2600  parseModuleId(ParsedModuleId);
2601 
2602  if (ActiveModule->Parent)
2603  Diags.Report(KWLoc, diag::err_mmap_use_decl_submodule);
2604  else
2605  ActiveModule->UnresolvedDirectUses.push_back(ParsedModuleId);
2606 }
2607 
2608 /// Parse a link declaration.
2609 ///
2610 /// module-declaration:
2611 /// 'link' 'framework'[opt] string-literal
2612 void ModuleMapParser::parseLinkDecl() {
2613  assert(Tok.is(MMToken::LinkKeyword));
2614  SourceLocation LinkLoc = consumeToken();
2615 
2616  // Parse the optional 'framework' keyword.
2617  bool IsFramework = false;
2618  if (Tok.is(MMToken::FrameworkKeyword)) {
2619  consumeToken();
2620  IsFramework = true;
2621  }
2622 
2623  // Parse the library name
2624  if (!Tok.is(MMToken::StringLiteral)) {
2625  Diags.Report(Tok.getLocation(), diag::err_mmap_expected_library_name)
2626  << IsFramework << SourceRange(LinkLoc);
2627  HadError = true;
2628  return;
2629  }
2630 
2631  std::string LibraryName = std::string(Tok.getString());
2632  consumeToken();
2633  ActiveModule->LinkLibraries.push_back(Module::LinkLibrary(LibraryName,
2634  IsFramework));
2635 }
2636 
2637 /// Parse a configuration macro declaration.
2638 ///
2639 /// module-declaration:
2640 /// 'config_macros' attributes[opt] config-macro-list?
2641 ///
2642 /// config-macro-list:
2643 /// identifier (',' identifier)?
2644 void ModuleMapParser::parseConfigMacros() {
2645  assert(Tok.is(MMToken::ConfigMacros));
2646  SourceLocation ConfigMacrosLoc = consumeToken();
2647 
2648  // Only top-level modules can have configuration macros.
2649  if (ActiveModule->Parent) {
2650  Diags.Report(ConfigMacrosLoc, diag::err_mmap_config_macro_submodule);
2651  }
2652 
2653  // Parse the optional attributes.
2654  Attributes Attrs;
2655  if (parseOptionalAttributes(Attrs))
2656  return;
2657 
2658  if (Attrs.IsExhaustive && !ActiveModule->Parent) {
2659  ActiveModule->ConfigMacrosExhaustive = true;
2660  }
2661 
2662  // If we don't have an identifier, we're done.
2663  // FIXME: Support macros with the same name as a keyword here.
2664  if (!Tok.is(MMToken::Identifier))
2665  return;
2666 
2667  // Consume the first identifier.
2668  if (!ActiveModule->Parent) {
2669  ActiveModule->ConfigMacros.push_back(Tok.getString().str());
2670  }
2671  consumeToken();
2672 
2673  do {
2674  // If there's a comma, consume it.
2675  if (!Tok.is(MMToken::Comma))
2676  break;
2677  consumeToken();
2678 
2679  // We expect to see a macro name here.
2680  // FIXME: Support macros with the same name as a keyword here.
2681  if (!Tok.is(MMToken::Identifier)) {
2682  Diags.Report(Tok.getLocation(), diag::err_mmap_expected_config_macro);
2683  break;
2684  }
2685 
2686  // Consume the macro name.
2687  if (!ActiveModule->Parent) {
2688  ActiveModule->ConfigMacros.push_back(Tok.getString().str());
2689  }
2690  consumeToken();
2691  } while (true);
2692 }
2693 
2694 /// Format a module-id into a string.
2696  std::string result;
2697  {
2698  llvm::raw_string_ostream OS(result);
2699 
2700  for (unsigned I = 0, N = Id.size(); I != N; ++I) {
2701  if (I)
2702  OS << ".";
2703  OS << Id[I].first;
2704  }
2705  }
2706 
2707  return result;
2708 }
2709 
2710 /// Parse a conflict declaration.
2711 ///
2712 /// module-declaration:
2713 /// 'conflict' module-id ',' string-literal
2714 void ModuleMapParser::parseConflict() {
2715  assert(Tok.is(MMToken::Conflict));
2716  SourceLocation ConflictLoc = consumeToken();
2717  Module::UnresolvedConflict Conflict;
2718 
2719  // Parse the module-id.
2720  if (parseModuleId(Conflict.Id))
2721  return;
2722 
2723  // Parse the ','.
2724  if (!Tok.is(MMToken::Comma)) {
2725  Diags.Report(Tok.getLocation(), diag::err_mmap_expected_conflicts_comma)
2726  << SourceRange(ConflictLoc);
2727  return;
2728  }
2729  consumeToken();
2730 
2731  // Parse the message.
2732  if (!Tok.is(MMToken::StringLiteral)) {
2733  Diags.Report(Tok.getLocation(), diag::err_mmap_expected_conflicts_message)
2734  << formatModuleId(Conflict.Id);
2735  return;
2736  }
2737  Conflict.Message = Tok.getString().str();
2738  consumeToken();
2739 
2740  // Add this unresolved conflict.
2741  ActiveModule->UnresolvedConflicts.push_back(Conflict);
2742 }
2743 
2744 /// Parse an inferred module declaration (wildcard modules).
2745 ///
2746 /// module-declaration:
2747 /// 'explicit'[opt] 'framework'[opt] 'module' * attributes[opt]
2748 /// { inferred-module-member* }
2749 ///
2750 /// inferred-module-member:
2751 /// 'export' '*'
2752 /// 'exclude' identifier
2753 void ModuleMapParser::parseInferredModuleDecl(bool Framework, bool Explicit) {
2754  assert(Tok.is(MMToken::Star));
2755  SourceLocation StarLoc = consumeToken();
2756  bool Failed = false;
2757 
2758  // Inferred modules must be submodules.
2759  if (!ActiveModule && !Framework) {
2760  Diags.Report(StarLoc, diag::err_mmap_top_level_inferred_submodule);
2761  Failed = true;
2762  }
2763 
2764  if (ActiveModule) {
2765  // Inferred modules must have umbrella directories.
2766  if (!Failed && ActiveModule->IsAvailable &&
2767  !ActiveModule->getUmbrellaDir()) {
2768  Diags.Report(StarLoc, diag::err_mmap_inferred_no_umbrella);
2769  Failed = true;
2770  }
2771 
2772  // Check for redefinition of an inferred module.
2773  if (!Failed && ActiveModule->InferSubmodules) {
2774  Diags.Report(StarLoc, diag::err_mmap_inferred_redef);
2775  if (ActiveModule->InferredSubmoduleLoc.isValid())
2776  Diags.Report(ActiveModule->InferredSubmoduleLoc,
2777  diag::note_mmap_prev_definition);
2778  Failed = true;
2779  }
2780 
2781  // Check for the 'framework' keyword, which is not permitted here.
2782  if (Framework) {
2783  Diags.Report(StarLoc, diag::err_mmap_inferred_framework_submodule);
2784  Framework = false;
2785  }
2786  } else if (Explicit) {
2787  Diags.Report(StarLoc, diag::err_mmap_explicit_inferred_framework);
2788  Explicit = false;
2789  }
2790 
2791  // If there were any problems with this inferred submodule, skip its body.
2792  if (Failed) {
2793  if (Tok.is(MMToken::LBrace)) {
2794  consumeToken();
2795  skipUntil(MMToken::RBrace);
2796  if (Tok.is(MMToken::RBrace))
2797  consumeToken();
2798  }
2799  HadError = true;
2800  return;
2801  }
2802 
2803  // Parse optional attributes.
2804  Attributes Attrs;
2805  if (parseOptionalAttributes(Attrs))
2806  return;
2807 
2808  if (ActiveModule) {
2809  // Note that we have an inferred submodule.
2810  ActiveModule->InferSubmodules = true;
2811  ActiveModule->InferredSubmoduleLoc = StarLoc;
2812  ActiveModule->InferExplicitSubmodules = Explicit;
2813  } else {
2814  // We'll be inferring framework modules for this directory.
2815  Map.InferredDirectories[Directory].InferModules = true;
2816  Map.InferredDirectories[Directory].Attrs = Attrs;
2817  Map.InferredDirectories[Directory].ModuleMapFile = ModuleMapFile;
2818  // FIXME: Handle the 'framework' keyword.
2819  }
2820 
2821  // Parse the opening brace.
2822  if (!Tok.is(MMToken::LBrace)) {
2823  Diags.Report(Tok.getLocation(), diag::err_mmap_expected_lbrace_wildcard);
2824  HadError = true;
2825  return;
2826  }
2827  SourceLocation LBraceLoc = consumeToken();
2828 
2829  // Parse the body of the inferred submodule.
2830  bool Done = false;
2831  do {
2832  switch (Tok.Kind) {
2833  case MMToken::EndOfFile:
2834  case MMToken::RBrace:
2835  Done = true;
2836  break;
2837 
2839  if (ActiveModule) {
2840  Diags.Report(Tok.getLocation(), diag::err_mmap_expected_inferred_member)
2841  << (ActiveModule != nullptr);
2842  consumeToken();
2843  break;
2844  }
2845 
2846  consumeToken();
2847  // FIXME: Support string-literal module names here.
2848  if (!Tok.is(MMToken::Identifier)) {
2849  Diags.Report(Tok.getLocation(), diag::err_mmap_missing_exclude_name);
2850  break;
2851  }
2852 
2853  Map.InferredDirectories[Directory].ExcludedModules.push_back(
2854  std::string(Tok.getString()));
2855  consumeToken();
2856  break;
2857 
2859  if (!ActiveModule) {
2860  Diags.Report(Tok.getLocation(), diag::err_mmap_expected_inferred_member)
2861  << (ActiveModule != nullptr);
2862  consumeToken();
2863  break;
2864  }
2865 
2866  consumeToken();
2867  if (Tok.is(MMToken::Star))
2868  ActiveModule->InferExportWildcard = true;
2869  else
2870  Diags.Report(Tok.getLocation(),
2871  diag::err_mmap_expected_export_wildcard);
2872  consumeToken();
2873  break;
2874 
2880  default:
2881  Diags.Report(Tok.getLocation(), diag::err_mmap_expected_inferred_member)
2882  << (ActiveModule != nullptr);
2883  consumeToken();
2884  break;
2885  }
2886  } while (!Done);
2887 
2888  if (Tok.is(MMToken::RBrace))
2889  consumeToken();
2890  else {
2891  Diags.Report(Tok.getLocation(), diag::err_mmap_expected_rbrace);
2892  Diags.Report(LBraceLoc, diag::note_mmap_lbrace_match);
2893  HadError = true;
2894  }
2895 }
2896 
2897 /// Parse optional attributes.
2898 ///
2899 /// attributes:
2900 /// attribute attributes
2901 /// attribute
2902 ///
2903 /// attribute:
2904 /// [ identifier ]
2905 ///
2906 /// \param Attrs Will be filled in with the parsed attributes.
2907 ///
2908 /// \returns true if an error occurred, false otherwise.
2909 bool ModuleMapParser::parseOptionalAttributes(Attributes &Attrs) {
2910  bool HadError = false;
2911 
2912  while (Tok.is(MMToken::LSquare)) {
2913  // Consume the '['.
2914  SourceLocation LSquareLoc = consumeToken();
2915 
2916  // Check whether we have an attribute name here.
2917  if (!Tok.is(MMToken::Identifier)) {
2918  Diags.Report(Tok.getLocation(), diag::err_mmap_expected_attribute);
2919  skipUntil(MMToken::RSquare);
2920  if (Tok.is(MMToken::RSquare))
2921  consumeToken();
2922  HadError = true;
2923  }
2924 
2925  // Decode the attribute name.
2926  AttributeKind Attribute
2927  = llvm::StringSwitch<AttributeKind>(Tok.getString())
2928  .Case("exhaustive", AT_exhaustive)
2929  .Case("extern_c", AT_extern_c)
2930  .Case("no_undeclared_includes", AT_no_undeclared_includes)
2931  .Case("system", AT_system)
2932  .Default(AT_unknown);
2933  switch (Attribute) {
2934  case AT_unknown:
2935  Diags.Report(Tok.getLocation(), diag::warn_mmap_unknown_attribute)
2936  << Tok.getString();
2937  break;
2938 
2939  case AT_system:
2940  Attrs.IsSystem = true;
2941  break;
2942 
2943  case AT_extern_c:
2944  Attrs.IsExternC = true;
2945  break;
2946 
2947  case AT_exhaustive:
2948  Attrs.IsExhaustive = true;
2949  break;
2950 
2951  case AT_no_undeclared_includes:
2952  Attrs.NoUndeclaredIncludes = true;
2953  break;
2954  }
2955  consumeToken();
2956 
2957  // Consume the ']'.
2958  if (!Tok.is(MMToken::RSquare)) {
2959  Diags.Report(Tok.getLocation(), diag::err_mmap_expected_rsquare);
2960  Diags.Report(LSquareLoc, diag::note_mmap_lsquare_match);
2961  skipUntil(MMToken::RSquare);
2962  HadError = true;
2963  }
2964 
2965  if (Tok.is(MMToken::RSquare))
2966  consumeToken();
2967  }
2968 
2969  return HadError;
2970 }
2971 
2972 /// Parse a module map file.
2973 ///
2974 /// module-map-file:
2975 /// module-declaration*
2977  do {
2978  switch (Tok.Kind) {
2979  case MMToken::EndOfFile:
2980  return HadError;
2981 
2986  parseModuleDecl();
2987  break;
2988 
2989  case MMToken::Comma:
2990  case MMToken::ConfigMacros:
2991  case MMToken::Conflict:
2992  case MMToken::Exclaim:
2997  case MMToken::Identifier:
2998  case MMToken::LBrace:
2999  case MMToken::LinkKeyword:
3000  case MMToken::LSquare:
3001  case MMToken::Period:
3003  case MMToken::RBrace:
3004  case MMToken::RSquare:
3006  case MMToken::Star:
3011  case MMToken::UseKeyword:
3012  Diags.Report(Tok.getLocation(), diag::err_mmap_expected_module);
3013  HadError = true;
3014  consumeToken();
3015  break;
3016  }
3017  } while (true);
3018 }
3019 
3020 bool ModuleMap::parseModuleMapFile(const FileEntry *File, bool IsSystem,
3021  const DirectoryEntry *Dir, FileID ID,
3022  unsigned *Offset,
3023  SourceLocation ExternModuleLoc) {
3024  assert(Target && "Missing target information");
3025  llvm::DenseMap<const FileEntry *, bool>::iterator Known
3026  = ParsedModuleMap.find(File);
3027  if (Known != ParsedModuleMap.end())
3028  return Known->second;
3029 
3030  // If the module map file wasn't already entered, do so now.
3031  if (ID.isInvalid()) {
3032  auto FileCharacter =
3034  ID = SourceMgr.createFileID(File, ExternModuleLoc, FileCharacter);
3035  }
3036 
3037  assert(Target && "Missing target information");
3039  if (!Buffer)
3040  return ParsedModuleMap[File] = true;
3041  assert((!Offset || *Offset <= Buffer->getBufferSize()) &&
3042  "invalid buffer offset");
3043 
3044  // Parse this module map file.
3045  Lexer L(SourceMgr.getLocForStartOfFile(ID), MMapLangOpts,
3046  Buffer->getBufferStart(),
3047  Buffer->getBufferStart() + (Offset ? *Offset : 0),
3048  Buffer->getBufferEnd());
3049  SourceLocation Start = L.getSourceLocation();
3050  ModuleMapParser Parser(L, SourceMgr, Target, Diags, *this, File, Dir,
3051  IsSystem);
3052  bool Result = Parser.parseModuleMapFile();
3053  ParsedModuleMap[File] = Result;
3054 
3055  if (Offset) {
3056  auto Loc = SourceMgr.getDecomposedLoc(Parser.getLocation());
3057  assert(Loc.first == ID && "stopped in a different file?");
3058  *Offset = Loc.second;
3059  }
3060 
3061  // Notify callbacks that we parsed it.
3062  for (const auto &Cb : Callbacks)
3063  Cb->moduleMapFileRead(Start, *File, IsSystem);
3064 
3065  return Result;
3066 }
clang::ModuleMap::addLinkAsDependency
void addLinkAsDependency(Module *Mod)
Make module to use export_as as the link dependency name if enough information is available or add it...
Definition: ModuleMap.cpp:69
clang::Module::DirectUses
SmallVector< Module *, 2 > DirectUses
The directly used modules.
Definition: Module.h:374
clang::ModuleMap::getContainingModuleMapFile
const FileEntry * getContainingModuleMapFile(const Module *Module) const
Retrieve the module map file containing the definition of the given module.
Definition: ModuleMap.cpp:1276
clang::MMToken::Location
SourceLocation::UIntTy Location
Definition: ModuleMap.cpp:1404
clang::ModuleMap::resolveConflicts
bool resolveConflicts(Module *Mod, bool Complain)
Resolve all of the unresolved conflicts in the given module.
Definition: ModuleMap.cpp:1350
clang::LangOptions::CurrentModule
std::string CurrentModule
The name of the current module, of which the main source file is a part.
Definition: LangOptions.h:410
clang::Module::getTopLevelModule
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
Definition: Module.h:575
clang::ModuleMap::resolveUses
bool resolveUses(Module *Mod, bool Complain)
Resolve all of the unresolved uses in the given module.
Definition: ModuleMap.cpp:1337
clang::Module::InferSubmodules
unsigned InferSubmodules
Whether we should infer submodules for this module based on the headers.
Definition: Module.h:302
clang::MMToken
A token in a module map file.
Definition: ModuleMap.cpp:1372
clang::ModuleMap::createPrivateModuleFragmentForInterfaceUnit
Module * createPrivateModuleFragmentForInterfaceUnit(Module *Parent, SourceLocation Loc)
Create a global module fragment for a C++ module interface unit.
Definition: ModuleMap.cpp:847
clang::FileEntryRef
A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...
Definition: FileEntry.h:60
clang::FileEntry::getDir
const DirectoryEntry * getDir() const
Return the directory the file lives in.
Definition: FileEntry.h:371
clang::MMToken::StringLiteral
@ StringLiteral
Definition: ModuleMap.cpp:1395
clang::Module::fullModuleNameIs
bool fullModuleNameIs(ArrayRef< StringRef > nameParts) const
Whether the full name of this module is equal to joining nameParts with "."s.
Definition: Module.cpp:235
clang::ModuleMap::KnownHeader
A header that is known to reside within a given module, whether it was included or excluded.
Definition: ModuleMap.h:155
clang::DeclaratorContext::File
@ File
clang::Module::getUmbrellaDir
DirectoryName getUmbrellaDir() const
Retrieve the directory for which this module serves as the umbrella.
Definition: Module.cpp:244
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:210
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
appendSubframeworkPaths
static void appendSubframeworkPaths(Module *Mod, SmallVectorImpl< char > &Path)
Append to Paths the set of paths needed to get to the subframework in which the given module lives.
Definition: ModuleMap.cpp:157
clang::ExplicitSpecKind::Unresolved
@ Unresolved
clang::MMToken::getLocation
SourceLocation getLocation() const
Definition: ModuleMap.cpp:1423
ModuleMap.h
clang::MMToken::ExcludeKeyword
@ ExcludeKeyword
Definition: ModuleMap.cpp:1381
clang::Lexer::getSpelling
static unsigned getSpelling(const Token &Tok, const char *&Buffer, const SourceManager &SourceMgr, const LangOptions &LangOpts, bool *Invalid=nullptr)
getSpelling - This method is used to get the spelling of a token into a preallocated buffer,...
Definition: Lexer.cpp:405
include
include(CheckIncludeFiles) set(LLVM_LINK_COMPONENTS support) set(DIRECTORY_WATCHER_SOURCES DirectoryScanner.cpp) set(DIRECTORY_WATCHER_LINK_LIBS "") if(APPLE) check_include_files("CoreServices/CoreServices.h" HAVE_CORESERVICES) if(HAVE_CORESERVICES) list(APPEND DIRECTORY_WATCHER_SOURCES mac/DirectoryWatcher-mac.cpp) set(DIRECTORY_WATCHER_LINK_LIBS "-framework CoreServices") endif() elseif(CMAKE_SYSTEM_NAME MATCHES "Linux") check_include_files("sys/inotify.h" HAVE_INOTIFY) if(HAVE_INOTIFY) list(APPEND DIRECTORY_WATCHER_SOURCES linux/DirectoryWatcher-linux.cpp) find_package(Threads REQUIRED) endif() elseif(CMAKE_SYSTEM_NAME MATCHES "Windows") list(APPEND DIRECTORY_WATCHER_SOURCES windows/DirectoryWatcher-windows.cpp) else() list(APPEND DIRECTORY_WATCHER_SOURCES default/DirectoryWatcher-not-implemented.cpp) endif() add_clang_library(clangDirectoryWatcher $
Definition: CMakeLists.txt:1
clang::MMToken::Exclaim
@ Exclaim
Definition: ModuleMap.cpp:1380
llvm::SmallVector< std::pair< std::string, SourceLocation >, 2 >
clang::if
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T -> getSizeExpr()))
Definition: RecursiveASTVisitor.h:1098
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::LangOptions::isCompilingModule
bool isCompilingModule() const
Are we compiling a module interface (.cppm or module map)?
Definition: LangOptions.h:487
clang::Module::Conflict::Other
Module * Other
The module that this module conflicts with.
Definition: Module.h:428
clang::ModuleMap::createHeaderUnit
Module * createHeaderUnit(SourceLocation Loc, StringRef Name, Module::Header H)
Create a C++20 header unit.
Definition: ModuleMap.cpp:907
clang::DiagnosticsEngine::isIgnored
bool isIgnored(unsigned DiagID, SourceLocation Loc) const
Determine whether the diagnostic is known to be ignored.
Definition: Diagnostic.h:910
clang::Module::getFullModuleName
std::string getFullModuleName(bool AllowStringLiterals=false) const
Retrieve the full name of this module, including the path from its top-level module.
Definition: Module.cpp:219
clang::DirectoryEntry::getName
StringRef getName() const
Definition: DirectoryEntry.h:45
TargetInfo.h
clang::MultiVersionKind::Target
@ Target
clang::MMToken::IntegerLiteral
@ IntegerLiteral
Definition: ModuleMap.cpp:1396
clang::ModuleMap::module_begin
module_iterator module_begin() const
Definition: ModuleMap.h:715
clang::MMToken::PrivateKeyword
@ PrivateKeyword
Definition: ModuleMap.cpp:1390
shouldAddRequirement
static bool shouldAddRequirement(Module *M, StringRef Feature, bool &IsRequiresExcludedHack)
Whether to add the requirement Feature to the module M.
Definition: ModuleMap.cpp:2222
clang::Module::HK_PrivateTextual
@ HK_PrivateTextual
Definition: Module.h:202
clang::MMToken::Star
@ Star
Definition: ModuleMap.cpp:1394
clang::MMToken::LSquare
@ LSquare
Definition: ModuleMap.cpp:1400
clang::Module::Header::Entry
const FileEntry * Entry
Definition: Module.h:212
clang::FileManager::getFileRef
llvm::Expected< FileEntryRef > getFileRef(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Lookup, cache, and verify the specified file (real or virtual).
Definition: FileManager.cpp:205
clang::SourceManager::getBufferOrNone
llvm::Optional< llvm::MemoryBufferRef > getBufferOrNone(FileID FID, SourceLocation Loc=SourceLocation()) const
Return the buffer for the specified FileID.
Definition: SourceManager.h:1016
clang::MMToken::ExportKeyword
@ ExportKeyword
Definition: ModuleMap.cpp:1383
clang::ModuleMap::createGlobalModuleFragmentForModuleUnit
Module * createGlobalModuleFragmentForModuleUnit(SourceLocation Loc, Module *Parent=nullptr)
Create a global module fragment for a C++ module unit.
Definition: ModuleMap.cpp:834
Filename
StringRef Filename
Definition: Format.cpp:2551
clang::DiagnosticsEngine
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:192
clang::TargetInfo
Exposes information about the current target.
Definition: TargetInfo.h:186
memcpy
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
Definition: __clang_cuda_device_functions.h:1549
clang::MMToken::RSquare
@ RSquare
Definition: ModuleMap.cpp:1401
clang::ModuleMap::module_end
module_iterator module_end() const
Definition: ModuleMap.h:716
Module.h
clang::Token::isAtStartOfLine
bool isAtStartOfLine() const
isAtStartOfLine - Return true if this token is at the start of a line.
Definition: Token.h:267
clang::Module::Name
std::string Name
The name of this module.
Definition: Module.h:99
clang::MMToken::HeaderKeyword
@ HeaderKeyword
Definition: ModuleMap.cpp:1378
clang::Parser
Parser - This implements a parser for the C family of languages.
Definition: Parser.h:60
clang::LangOptions::CMK_ModuleMap
@ CMK_ModuleMap
Compiling a module from a module map.
Definition: LangOptions.h:108
llvm::Optional< FileEntryRef >
isBetterKnownHeader
static bool isBetterKnownHeader(const ModuleMap::KnownHeader &New, const ModuleMap::KnownHeader &Old)
Definition: ModuleMap.cpp:548
clang::MMToken::LBrace
@ LBrace
Definition: ModuleMap.cpp:1398
clang::ModuleMap::setUmbrellaDir
void setUmbrellaDir(Module *Mod, const DirectoryEntry *UmbrellaDir, const Twine &NameAsWritten, const Twine &PathRelativeToRootModuleDirectory)
Sets the umbrella directory of the given module to the given directory.
Definition: ModuleMap.cpp:1156
llvm::SmallPtrSet
Definition: ASTContext.h:82
SourceManager.h
clang::ModuleMapParser::ModuleMapParser
ModuleMapParser(Lexer &L, SourceManager &SourceMgr, const TargetInfo *Target, DiagnosticsEngine &Diags, ModuleMap &Map, const FileEntry *ModuleMapFile, const DirectoryEntry *Directory, bool IsSystem)
Definition: ModuleMap.cpp:1519
clang::MMToken::IntegerValue
uint64_t IntegerValue
Definition: ModuleMap.cpp:1411
clang::Module::InferExportWildcard
unsigned InferExportWildcard
Whether, when inferring submodules, the inferr submodules should export all modules they import (e....
Definition: Module.h:310
clang::MMToken::getString
StringRef getString() const
Definition: ModuleMap.cpp:1431
clang::MMToken::StringData
const char * StringData
Definition: ModuleMap.cpp:1408
clang::Module::ModuleMapIsPrivate
unsigned ModuleMapIsPrivate
Whether this module came from a "private" module map, found next to a regular (public) module map.
Definition: Module.h:325
clang::Lexer::LexFromRawLexer
bool LexFromRawLexer(Token &Result)
LexFromRawLexer - Lex a token from a designated raw lexer (one with no associated preprocessor object...
Definition: Lexer.h:211
clang::Token
Token - This structure provides full information about a lexed token.
Definition: Token.h:34
LiteralSupport.h
clang::Module::isAvailable
bool isAvailable() const
Determine whether this module is available for use within the current translation unit.
Definition: Module.h:464
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:627
clang::ModuleMap::setInferredModuleAllowedBy
void setInferredModuleAllowedBy(Module *M, const FileEntry *ModMap)
Definition: ModuleMap.cpp:1292
clang::Module::InferredSubmoduleLoc
SourceLocation InferredSubmoduleLoc
The location of the inferred submodule.
Definition: Module.h:340
clang::Module::UnresolvedExports
SmallVector< UnresolvedExportDecl, 2 > UnresolvedExports
The set of export declarations that have yet to be resolved.
Definition: Module.h:371
clang::HeaderSearch
Encapsulates the information needed to find the file referenced by a #include or #include_next,...
Definition: HeaderSearch.h:223
clang::Lexer
Lexer - This provides a simple interface that turns a text buffer into a stream of tokens.
Definition: Lexer.h:77
Offset
unsigned Offset
Definition: Format.cpp:2553
clang::MMToken::Kind
enum clang::MMToken::TokenKind Kind
clang::ModuleMap::KnownHeader::getModule
Module * getModule() const
Retrieve the module the header is stored in.
Definition: ModuleMap.h:170
clang::ModuleMap::ModuleHeaderRole
ModuleHeaderRole
Flags describing the role of a module header.
Definition: ModuleMap.h:128
clang::Module::UnresolvedDirectUses
SmallVector< ModuleId, 2 > UnresolvedDirectUses
The set of use declarations that have yet to be resolved.
Definition: Module.h:377
clang::ModuleMap::createHeaderModule
Module * createHeaderModule(StringRef Name, ArrayRef< Module::Header > Headers)
Create a header module from the specified list of headers.
Definition: ModuleMap.cpp:884
clang::MMToken::UseKeyword
@ UseKeyword
Definition: ModuleMap.cpp:1392
clang::ModuleMap::excludeHeader
void excludeHeader(Module *Mod, Module::Header Header)
Marks this header as being excluded from the given module.
Definition: ModuleMap.cpp:1265
clang::ModuleMapParser
Definition: ModuleMap.cpp:1437
clang::StructuralEquivalenceKind::Default
@ Default
clang::Module::NoUndeclaredIncludes
unsigned NoUndeclaredIncludes
Whether files in this module can only include non-modular headers and headers from used modules.
Definition: Module.h:321
clang::ModuleMap::dump
void dump()
Dump the contents of the module map, for debugging purposes.
Definition: ModuleMap.cpp:1302
clang::ModuleMap::PrivateHeader
@ PrivateHeader
This header is included but private.
Definition: ModuleMap.h:133
clang::ModuleMap::diagnoseHeaderInclusion
void diagnoseHeaderInclusion(Module *RequestingModule, bool RequestingModuleIsModuleInterface, SourceLocation FilenameLoc, StringRef Filename, FileEntryRef File)
Reports errors if a module must not include a specific file.
Definition: ModuleMap.cpp:473
clang::IntegerLiteral
Definition: Expr.h:1494
clang::prec::Unknown
@ Unknown
Definition: OperatorPrecedence.h:27
clang::Decl::Kind
Kind
Lists the kind of concrete classes of Decl.
Definition: DeclBase.h:86
clang::isValidAsciiIdentifier
LLVM_READONLY bool isValidAsciiIdentifier(StringRef S, bool AllowDollar=false)
Return true if this is a valid ASCII identifier.
Definition: CharInfo.h:228
clang::MMToken::TextualKeyword
@ TextualKeyword
Definition: ModuleMap.cpp:1397
clang::Module
Describes a module or submodule.
Definition: Module.h:96
getTopLevelOrNull
static Module * getTopLevelOrNull(Module *M)
Definition: ModuleMap.cpp:469
clang::ModuleMap::addHeader
void addHeader(Module *Mod, Module::Header Header, ModuleHeaderRole Role, bool Imported=false)
Adds this header to the given module.
Definition: ModuleMap.cpp:1237
HeaderSearchOptions.h
clang::FileManager::getVirtualFileSystem
llvm::vfs::FileSystem & getVirtualFileSystem() const
Definition: FileManager.h:245
clang::DirectoryEntry
Cached information about one directory (either on disk or in the virtual file system).
Definition: DirectoryEntry.h:34
Id
int Id
Definition: ASTDiff.cpp:191
clang::XRayInstrKind::None
constexpr XRayInstrMask None
Definition: XRayInstr.h:38
clang::Module::Exports
SmallVector< ExportDecl, 2 > Exports
The set of export declarations.
Definition: Module.h:353
clang::ModuleMap::findModule
Module * findModule(StringRef Name) const
Retrieve a module with the given name.
Definition: ModuleMap.cpp:789
clang::Module::ModuleInterfaceUnit
@ ModuleInterfaceUnit
This is a C++20 module interface unit.
Definition: Module.h:110
clang::Module::HK_Textual
@ HK_Textual
Definition: Module.h:200
clang::HeaderSearchOptions::ModuleMapFileHomeIsCwd
unsigned ModuleMapFileHomeIsCwd
Set the 'home directory' of a module map file to the current working directory (or the home directory...
Definition: HeaderSearchOptions.h:144
clang::Token::getKind
tok::TokenKind getKind() const
Definition: Token.h:92
clang::Module::IsFramework
unsigned IsFramework
Whether this is a framework module.
Definition: Module.h:281
clang::Module::UnresolvedHeaderDirective::Size
Optional< off_t > Size
Definition: Module.h:238
clang::SourceManager::getMainFileID
FileID getMainFileID() const
Returns the FileID of the main source file.
Definition: SourceManager.h:841
LangOptions.h
clang::MMToken::StringLength
unsigned StringLength
Definition: ModuleMap.cpp:1405
Diagnostic.h
LexDiagnostic.h
clang::Module::HeaderKind
HeaderKind
Definition: Module.h:198
clang::Module::GlobalModuleFragment
@ GlobalModuleFragment
This is a fragment of the global module within some C++ module.
Definition: Module.h:122
clang::Module::ModuleHeaderUnit
@ ModuleHeaderUnit
This is a C++ 20 header unit.
Definition: Module.h:113
clang::Module::DefinitionLoc
SourceLocation DefinitionLoc
The location of the module definition.
Definition: Module.h:102
clang::ModuleMap::addAdditionalModuleMapFile
void addAdditionalModuleMapFile(const Module *M, const FileEntry *ModuleMap)
Definition: ModuleMap.cpp:1297
clang::Token::is
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {....
Definition: Token.h:97
clang::MMToken::ModuleKeyword
@ ModuleKeyword
Definition: ModuleMap.cpp:1388
clang::Module::Conflicts
std::vector< Conflict > Conflicts
The list of conflicts.
Definition: Module.h:435
clang::ModuleMap::findModuleForHeader
KnownHeader findModuleForHeader(const FileEntry *File, bool AllowTextual=false)
Retrieve the module that owns the given header file, if any.
Definition: ModuleMap.cpp:571
clang::SourceManager::getFileID
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
Definition: SourceManager.h:1108
KEYWORD
#define KEYWORD(Keyword, Conditions)
clang::Module::UnresolvedConflicts
std::vector< UnresolvedConflict > UnresolvedConflicts
The list of conflicts for which the module-id has not yet been resolved.
Definition: Module.h:423
llvm::SmallString< 128 >
clang::ModuleMap::getModuleMapFileForUniquing
const FileEntry * getModuleMapFileForUniquing(const Module *M) const
Get the module map file that (along with the module name) uniquely identifies this module.
Definition: ModuleMap.cpp:1284
ALIAS
#define ALIAS(Keyword, AliasOf, Conditions)
clang::StringLiteral
StringLiteral - This represents a string literal expression, e.g.
Definition: Expr.h:1767
clang::Module::UnresolvedHeaderDirective::FileName
std::string FileName
Definition: Module.h:235
clang::ModuleMap::lookupModuleUnqualified
Module * lookupModuleUnqualified(StringRef Name, Module *Context) const
Retrieve a module with the given name using lexical name lookup, starting at the given context.
Definition: ModuleMap.cpp:797
clang::Module::isPartOfFramework
bool isPartOfFramework() const
Determine whether this module is a part of a framework, either because it is a framework module or be...
Definition: Module.h:503
clang::Module::MissingHeaders
SmallVector< UnresolvedHeaderDirective, 1 > MissingHeaders
Headers that are mentioned in the module map file but could not be found on the file system.
Definition: Module.h:248
clang::MMToken::clear
void clear()
Definition: ModuleMap.cpp:1414
clang::Lexer::getSourceLocation
SourceLocation getSourceLocation(const char *Loc, unsigned TokLen=1) const
getSourceLocation - Return a source location identifier for the specified offset in the current file.
Definition: Lexer.cpp:1149
formatModuleId
static std::string formatModuleId(const ModuleId &Id)
Format a module-id into a string.
Definition: ModuleMap.cpp:2695
clang::FileEntry
Cached information about one file (either on disk or in the virtual file system).
Definition: FileEntry.h:330
clang::SourceManager::getDecomposedLoc
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
Definition: SourceManager.h:1241
clang::ModuleMap
Definition: ModuleMap.h:75
clang::HeaderSearch::MarkFileModuleHeader
void MarkFileModuleHeader(const FileEntry *FE, ModuleMap::ModuleHeaderRole Role, bool isCompilingModuleHeader)
Mark the specified file as part of a module.
Definition: HeaderSearch.cpp:1347
inferFrameworkLink
static void inferFrameworkLink(Module *Mod, const DirectoryEntry *FrameworkDir, FileManager &FileMgr)
For a framework module, infer the framework against which we should link.
Definition: ModuleMap.cpp:922
clang::Token::getRawIdentifier
StringRef getRawIdentifier() const
getRawIdentifier - For a raw identifier token (i.e., an identifier lexed in raw mode),...
Definition: Token.h:204
clang::Module::Parent
Module * Parent
The parent of this module.
Definition: Module.h:133
clang::isAsciiIdentifierContinue
LLVM_READONLY bool isAsciiIdentifierContinue(unsigned char c, bool AllowDollar=false)
Returns true if this is a body character of a C identifier, which is [a-zA-Z0-9_].
Definition: CharInfo.h:64
clang::Token::getLength
unsigned getLength() const
Definition: Token.h:128
clang::MMToken::is
bool is(TokenKind K) const
Definition: ModuleMap.cpp:1421
clang::SourceManager::getLocForStartOfFile
SourceLocation getLocForStartOfFile(FileID FID) const
Return the source location corresponding to the first byte of the specified file.
Definition: SourceManager.h:1123
clang::MMToken::LinkKeyword
@ LinkKeyword
Definition: ModuleMap.cpp:1387
clang::Module::UmbrellaAsWritten
std::string UmbrellaAsWritten
The name of the umbrella entry, as written in the module map.
Definition: Module.h:151
clang::ModuleMap::findOrCreateModule
std::pair< Module *, bool > findOrCreateModule(StringRef Name, Module *Parent, bool IsFramework, bool IsExplicit)
Find a new module or submodule, or create it if it does not already exist.
Definition: ModuleMap.cpp:814
clang::ModuleMap::isBuiltinHeader
static bool isBuiltinHeader(StringRef FileName)
Is this a compiler builtin header?
Definition: ModuleMap.cpp:375
clang::Module::HK_Normal
@ HK_Normal
Definition: Module.h:199
clang::Module::markUnavailable
void markUnavailable(bool Unimportable)
Mark this module and all of its submodules as unavailable.
Definition: Module.cpp:303
clang::Module::LinkLibraries
llvm::SmallVector< LinkLibrary, 2 > LinkLibraries
The set of libraries or frameworks to link against when an entity from this module is used.
Definition: Module.h:402
SourceLocation.h
clang::ModuleMap::TextualHeader
@ TextualHeader
This header is part of the module (for layering purposes) but should be textually included.
Definition: ModuleMap.h:137
clang::Module::HK_Private
@ HK_Private
Definition: Module.h:201
clang::MMToken::ExternKeyword
@ ExternKeyword
Definition: ModuleMap.cpp:1385
clang::Module::Directory
const DirectoryEntry * Directory
The build directory of this module.
Definition: Module.h:138
clang::HeaderSearchOptions::ImplicitModuleMaps
unsigned ImplicitModuleMaps
Implicit module maps.
Definition: HeaderSearchOptions.h:135
clang::ModuleMap::KnownHeader::getRole
ModuleHeaderRole getRole() const
The role of this header within the module.
Definition: ModuleMap.h:173
clang::HeaderSearch::lookupModuleMapFile
const FileEntry * lookupModuleMapFile(const DirectoryEntry *Dir, bool IsFramework)
Try to find a module map file in the given directory, returning nullptr if none is found.
Definition: HeaderSearch.cpp:1704
clang::Module::Headers
SmallVector< Header, 2 > Headers[5]
The headers that are part of this module.
Definition: Module.h:228
clang::Module::Conflict::Message
std::string Message
The message provided to the user when there is a conflict.
Definition: Module.h:431
CharInfo.h
clang::MMToken::UmbrellaKeyword
@ UmbrellaKeyword
Definition: ModuleMap.cpp:1391
clang::MMToken::RequiresKeyword
@ RequiresKeyword
Definition: ModuleMap.cpp:1393
clang::syntax::NodeRole::Size
@ Size
clang::ModuleMap::headerRoleToKind
static Module::HeaderKind headerRoleToKind(ModuleHeaderRole Role)
Convert a header role to a kind.
Definition: ModuleMap.cpp:76
clang::MMToken::Period
@ Period
Definition: ModuleMap.cpp:1389
clang::Module::IsSystem
unsigned IsSystem
Whether this is a "system" module (which assumes that all headers in it are system headers).
Definition: Module.h:288
sanitizeFilenameAsIdentifier
static StringRef sanitizeFilenameAsIdentifier(StringRef Name, SmallVectorImpl< char > &Buffer)
"Sanitize" a filename so that it can be used as an identifier.
Definition: ModuleMap.cpp:336
clang::MMToken::Identifier
@ Identifier
Definition: ModuleMap.cpp:1379
clang::MMToken::getInteger
uint64_t getInteger() const
Definition: ModuleMap.cpp:1427
llvm::ArrayRef
Definition: LLVM.h:34
Lexer.h
Value
Value
Definition: UninitializedValues.cpp:102
clang::ModuleMap::createModuleForInterfaceUnit
Module * createModuleForInterfaceUnit(SourceLocation Loc, StringRef Name, Module *GlobalModule)
Create a new module for a C++ module interface unit.
Definition: ModuleMap.cpp:856
HeaderSearch.h
clang::Module::Umbrella
llvm::PointerUnion< const FileEntry *, const DirectoryEntry * > Umbrella
The umbrella header or directory.
Definition: Module.h:145
clang::Module::PrivateModuleFragment
@ PrivateModuleFragment
This is the private module fragment within some C++ module.
Definition: Module.h:125
LLVM.h
clang::ModuleMap::lookupModuleQualified
Module * lookupModuleQualified(StringRef Name, Module *Context) const
Retrieve a module with the given name within the given context, using direct (qualified) name lookup.
Definition: ModuleMap.cpp:807
clang::Module::UnresolvedHeaderDirective::HasBuiltinHeader
bool HasBuiltinHeader
Definition: Module.h:237
clang::ModuleMap::resolveHeaderDirectives
void resolveHeaderDirectives(const FileEntry *File) const
Resolve all lazy header directives for the specified file.
Definition: ModuleMap.cpp:1202
violatesPrivateInclude
static bool violatesPrivateInclude(Module *RequestingModule, const FileEntry *IncFileEnt, ModuleMap::KnownHeader Header)
Definition: ModuleMap.cpp:446
clang::Module::HK_Excluded
@ HK_Excluded
Definition: Module.h:203
clang::MMToken::ExportAsKeyword
@ ExportAsKeyword
Definition: ModuleMap.cpp:1384
clang::SrcMgr::C_System_ModuleMap
@ C_System_ModuleMap
Definition: SourceManager.h:84
clang::MMToken::FrameworkKeyword
@ FrameworkKeyword
Definition: ModuleMap.cpp:1386
clang::Module::IsAvailable
unsigned IsAvailable
Whether this module is available in the current translation unit.
Definition: Module.h:275
clang::Module::InferExplicitSubmodules
unsigned InferExplicitSubmodules
Whether, when inferring submodules, the inferred submodules should be explicit.
Definition: Module.h:306
clang::ModuleMap::isHeaderUnavailableInModule
bool isHeaderUnavailableInModule(const FileEntry *Header, const Module *RequestingModule) const
Determine whether the given header is unavailable as part of the specified module.
Definition: ModuleMap.cpp:695
clang::Token::getLocation
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
Definition: Token.h:125
clang::HeaderSearch::loadTopLevelSystemModules
void loadTopLevelSystemModules()
Load all known, top-level system modules.
Definition: HeaderSearch.cpp:1840
clang::SourceLocation::getFromRawEncoding
static SourceLocation getFromRawEncoding(UIntTy Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
Definition: SourceLocation.h:152
clang::ModuleMap::headerKindToRole
static ModuleHeaderRole headerKindToRole(Module::HeaderKind Kind)
Convert a header kind to a role. Requires Kind to not be HK_Excluded.
Definition: ModuleMap.cpp:91
clang::Module::UnresolvedHeaderDirective::IsUmbrella
bool IsUmbrella
Definition: Module.h:236
clang::Module::Conflict
A conflict between two modules.
Definition: Module.h:426
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:78
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::HeaderSearch::getHeaderSearchOpts
HeaderSearchOptions & getHeaderSearchOpts() const
Retrieve the header-search options with which this header search was initialized.
Definition: HeaderSearch.h:342
clang::ModuleMap::NormalHeader
@ NormalHeader
This header is normally included in the module.
Definition: ModuleMap.h:130
clang::Module::UnresolvedHeaderDirective
Stored information about a header directive that was found in the module map file but has not been re...
Definition: Module.h:232
clang::ModuleMap::resolveExports
bool resolveExports(Module *Mod, bool Complain)
Resolve all of the unresolved exports in the given module.
Definition: ModuleMap.cpp:1324
clang::ModuleMap::~ModuleMap
~ModuleMap()
Destroy the module map.
Definition: ModuleMap.cpp:322
clang::ModuleMapParser::terminatedByDirective
bool terminatedByDirective()
Definition: ModuleMap.cpp:1532
clang::ModuleMap::createShadowedModule
Module * createShadowedModule(StringRef Name, bool IsFramework, Module *ShadowingModule)
Create a new top-level module that is shadowed by ShadowingModule.
Definition: ModuleMap.cpp:1126
clang::ModuleMap::findAllModulesForHeader
ArrayRef< KnownHeader > findAllModulesForHeader(const FileEntry *File)
Retrieve all the modules that contain the given header file.
Definition: ModuleMap.cpp:669
clang::Builtin::ID
ID
Definition: Builtins.h:51
clang::SourceLocation::isInvalid
bool isInvalid() const
Definition: SourceLocation.h:111
clang
Definition: CalledOnceCheck.h:17
clang::FileManager
Implements support for file system lookup, file system caching, and directory search management.
Definition: FileManager.h:53
clang::SourceManager::createFileID
FileID createFileID(const FileEntry *SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, SourceLocation::UIntTy LoadedOffset=0)
Create a new FileID that represents the specified file being #included from the specified IncludePosi...
Definition: SourceManager.cpp:532
clang::Module::isSubModuleOf
bool isSubModuleOf(const Module *Other) const
Check if this module is a (possibly transitive) submodule of Other.
Definition: Module.cpp:173
clang::Module::ExportAsModule
std::string ExportAsModule
The module through which entities defined in this module will eventually be exposed,...
Definition: Module.h:158
clang::FileManager::getCanonicalName
StringRef getCanonicalName(const DirectoryEntry *Dir)
Retrieve the canonical name for a given directory.
Definition: FileManager.cpp:659
clang::Module::UnresolvedExportDecl
Describes an exported module that has not yet been resolved (perhaps because the module it refers to ...
Definition: Module.h:357
clang::Module::Header
Information about a header directive as found in the module map file.
Definition: Module.h:209
clang::ModuleMap::findResolvedModulesForHeader
ArrayRef< KnownHeader > findResolvedModulesForHeader(const FileEntry *File) const
Like findAllModulesForHeader, but do not attempt to infer module ownership from umbrella headers if w...
Definition: ModuleMap.cpp:681
clang::Module::print
void print(raw_ostream &OS, unsigned Indent=0, bool Dump=false) const
Print the module map for this module to the given stream.
Definition: Module.cpp:434
clang::Module::IsUnimportable
unsigned IsUnimportable
Whether this module has declared itself unimportable, either because it's missing a requirement from ...
Definition: Module.h:266
clang::isDigit
LLVM_READONLY bool isDigit(unsigned char c)
Return true if this character is an ASCII digit: [0-9].
Definition: CharInfo.h:99
clang::FileEntry::getName
StringRef getName() const
Definition: FileEntry.h:361
clang::FileID
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Definition: SourceLocation.h:38
clang::MMToken::ConfigMacros
@ ConfigMacros
Definition: ModuleMap.cpp:1375
clang::SourceLocation::isValid
bool isValid() const
Return true if this is a valid SourceLocation object.
Definition: SourceLocation.h:110
clang::SourceManager::getFileEntryForID
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
Definition: SourceManager.h:1035
clang::Module::ConfigMacros
std::vector< std::string > ConfigMacros
The set of "configuration macros", which are macros that (intentionally) change how this module is bu...
Definition: Module.h:410
clang::ModuleMapParser::parseModuleMapFile
bool parseModuleMapFile()
Parse a module map file.
Definition: ModuleMap.cpp:2976
clang::Module::IsExternC
unsigned IsExternC
Whether this is an 'extern "C"' module (which implicitly puts all headers in it within an 'extern "C"...
Definition: Module.h:293
clang::Module::ConfigMacrosExhaustive
unsigned ConfigMacrosExhaustive
Whether the set of configuration macros is exhaustive.
Definition: Module.h:317
unsigned
clang::FileManager::getDirectory
llvm::ErrorOr< const DirectoryEntry * > getDirectory(StringRef DirName, bool CacheFailure=true)
Lookup, cache, and verify the specified directory (real or virtual).
Definition: FileManager.cpp:189
clang::ModuleMap::resolveLinkAsDependencies
void resolveLinkAsDependencies(Module *Mod)
Use PendingLinkAsModule information to mark top level link names that are going to be replaced by exp...
Definition: ModuleMap.cpp:58
clang::Module::isSubFramework
bool isSubFramework() const
Determine whether this module is a subframework of another framework.
Definition: Module.h:513
clang::ModuleMap::ModuleMap
ModuleMap(SourceManager &SourceMgr, DiagnosticsEngine &Diags, const LangOptions &LangOpts, const TargetInfo *Target, HeaderSearch &HeaderInfo)
Construct a new module map.
Definition: ModuleMap.cpp:314
clang::SourceManager::getFileManager
FileManager & getFileManager() const
Definition: SourceManager.h:807
clang::FileManager::getFile
llvm::ErrorOr< const FileEntry * > getFile(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Lookup, cache, and verify the specified file (real or virtual).
Definition: FileManager.cpp:197
clang::ModuleMap::KnownHeader::isAccessibleFrom
bool isAccessibleFrom(Module *M) const
Whether this header is accessible from the specified module.
Definition: ModuleMap.h:181
Parent
NodeId Parent
Definition: ASTDiff.cpp:192
clang::ModuleMap::parseModuleMapFile
bool parseModuleMapFile(const FileEntry *File, bool IsSystem, const DirectoryEntry *HomeDir, FileID ID=FileID(), unsigned *Offset=nullptr, SourceLocation ExternModuleLoc=SourceLocation())
Parse the given module map file, and record any modules we encounter.
Definition: ModuleMap.cpp:3020
clang::MMToken::EndOfFile
@ EndOfFile
Definition: ModuleMap.cpp:1377
clang::Module::addRequirement
void addRequirement(StringRef Feature, bool RequiredState, const LangOptions &LangOpts, const TargetInfo &Target)
Add the given feature requirement to the list of features required by this module.
Definition: Module.cpp:291
clang::MMToken::RBrace
@ RBrace
Definition: ModuleMap.cpp:1399
clang::comments::tok::eof
@ eof
Definition: CommentLexer.h:33
llvm::SmallVectorImpl< char >
FileManager.h
clang::Module::directlyUses
bool directlyUses(const Module *Requested)
Determine whether this module has declared its intention to directly use another module.
Definition: Module.cpp:270
clang::Module::UnresolvedHeaderDirective::Kind
HeaderKind Kind
Definition: Module.h:233
Token.h
clang::MMToken::ExplicitKeyword
@ ExplicitKeyword
Definition: ModuleMap.cpp:1382
clang::StringLiteralParser
StringLiteralParser - This decodes string escape characters and performs wide string analysis and Tra...
Definition: LiteralSupport.h:218
clang::ModuleMap::setTarget
void setTarget(const TargetInfo &Target)
Set the target information.
Definition: ModuleMap.cpp:329
clang::SrcMgr::C_User_ModuleMap
@ C_User_ModuleMap
Definition: SourceManager.h:83
clang::MMToken::Conflict
@ Conflict
Definition: ModuleMap.cpp:1376
clang::ModuleMap::isHeaderInUnavailableModule
bool isHeaderInUnavailableModule(const FileEntry *Header) const
Determine whether the given header is part of a module marked 'unavailable'.
Definition: ModuleMap.cpp:690
clang::Module::UseExportAsModuleLinkName
bool UseExportAsModuleLinkName
Autolinking uses the framework name for linking purposes when this is false and the export_as name ot...
Definition: Module.h:406
clang::ModuleMap::setUmbrellaHeader
void setUmbrellaHeader(Module *Mod, const FileEntry *UmbrellaHeader, const Twine &NameAsWritten, const Twine &PathRelativeToRootModuleDirectory)
Sets the umbrella header of the given module to the given header.
Definition: ModuleMap.cpp:1141
clang::MMToken::TokenKind
TokenKind
Definition: ModuleMap.cpp:1373
clang::Module::UmbrellaRelativeToRootModuleDirectory
std::string UmbrellaRelativeToRootModuleDirectory
Definition: Module.h:154
clang::Module::ExportDecl
llvm::PointerIntPair< Module *, 1, bool > ExportDecl
Describes an exported module.
Definition: Module.h:350
compareModuleHeaders
static int compareModuleHeaders(const Module::Header *A, const Module::Header *B)
Definition: ModuleMap.cpp:2421
clang::interp::Sub
bool Sub(InterpState &S, CodePtr OpPC)
Definition: Interp.h:142
clang::MMToken::Comma
@ Comma
Definition: ModuleMap.cpp:1374
clang::Module::UnresolvedHeaderDirective::ModTime
Optional< time_t > ModTime
Definition: Module.h:239
clang::ModuleMapParser::getLocation
SourceLocation getLocation()
Definition: ModuleMap.cpp:1533
clang::Module::IsInferred
unsigned IsInferred
Whether this is an inferred submodule (module * { ... }).
Definition: Module.h:296
clang::FixItHint::CreateReplacement
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
Definition: Diagnostic.h:134
clang::SourceLocation::UIntTy
uint32_t UIntTy
Definition: SourceLocation.h:93
clang::Module::UnresolvedHeaders
SmallVector< UnresolvedHeaderDirective, 1 > UnresolvedHeaders
Headers that are mentioned in the module map file but that we have not yet attempted to resolve to a ...
Definition: Module.h:244
clang::Token::hasUDSuffix
bool hasUDSuffix() const
Return true if this token is a string or character literal which has a ud-suffix.
Definition: Token.h:292
clang::SourceLocation::getRawEncoding
UIntTy getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it.
Definition: SourceLocation.h:146
clang::DiagnosticsEngine::Report
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Definition: Diagnostic.h:1536
clang::ModuleMap::mayShadowNewModule
bool mayShadowNewModule(Module *ExistingModule)
Definition: ModuleMap.h:588
clang::NamedDecl::getName
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:274