clang  13.0.0git
Module.cpp
Go to the documentation of this file.
1 //===- Module.cpp - Describe a module -------------------------------------===//
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 Module class, which describes a module in the source
10 // code.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/Basic/Module.h"
15 #include "clang/Basic/CharInfo.h"
19 #include "clang/Basic/TargetInfo.h"
20 #include "llvm/ADT/ArrayRef.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/StringMap.h"
23 #include "llvm/ADT/StringRef.h"
24 #include "llvm/ADT/StringSwitch.h"
25 #include "llvm/Support/Compiler.h"
26 #include "llvm/Support/ErrorHandling.h"
27 #include "llvm/Support/raw_ostream.h"
28 #include <algorithm>
29 #include <cassert>
30 #include <functional>
31 #include <string>
32 #include <utility>
33 #include <vector>
34 
35 using namespace clang;
36 
37 Module::Module(StringRef Name, SourceLocation DefinitionLoc, Module *Parent,
38  bool IsFramework, bool IsExplicit, unsigned VisibilityID)
39  : Name(Name), DefinitionLoc(DefinitionLoc), Parent(Parent),
40  VisibilityID(VisibilityID), IsUnimportable(false),
41  HasIncompatibleModuleFile(false), IsAvailable(true),
42  IsFromModuleFile(false), IsFramework(IsFramework), IsExplicit(IsExplicit),
43  IsSystem(false), IsExternC(false), IsInferred(false),
44  InferSubmodules(false), InferExplicitSubmodules(false),
45  InferExportWildcard(false), ConfigMacrosExhaustive(false),
46  NoUndeclaredIncludes(false), ModuleMapIsPrivate(false),
47  NameVisibility(Hidden) {
48  if (Parent) {
55 
56  Parent->SubModuleIndex[Name] = Parent->SubModules.size();
57  Parent->SubModules.push_back(this);
58  }
59 }
60 
63  I != IEnd; ++I) {
64  delete *I;
65  }
66 }
67 
68 static bool isPlatformEnvironment(const TargetInfo &Target, StringRef Feature) {
69  StringRef Platform = Target.getPlatformName();
70  StringRef Env = Target.getTriple().getEnvironmentName();
71 
72  // Attempt to match platform and environment.
73  if (Platform == Feature || Target.getTriple().getOSName() == Feature ||
74  Env == Feature)
75  return true;
76 
77  auto CmpPlatformEnv = [](StringRef LHS, StringRef RHS) {
78  auto Pos = LHS.find('-');
79  if (Pos == StringRef::npos)
80  return false;
81  SmallString<128> NewLHS = LHS.slice(0, Pos);
82  NewLHS += LHS.slice(Pos+1, LHS.size());
83  return NewLHS == RHS;
84  };
85 
86  SmallString<128> PlatformEnv = Target.getTriple().getOSAndEnvironmentName();
87  // Darwin has different but equivalent variants for simulators, example:
88  // 1. x86_64-apple-ios-simulator
89  // 2. x86_64-apple-iossimulator
90  // where both are valid examples of the same platform+environment but in the
91  // variant (2) the simulator is hardcoded as part of the platform name. Both
92  // forms above should match for "iossimulator" requirement.
93  if (Target.getTriple().isOSDarwin() && PlatformEnv.endswith("simulator"))
94  return PlatformEnv == Feature || CmpPlatformEnv(PlatformEnv, Feature);
95 
96  return PlatformEnv == Feature;
97 }
98 
99 /// Determine whether a translation unit built using the current
100 /// language options has the given feature.
101 static bool hasFeature(StringRef Feature, const LangOptions &LangOpts,
102  const TargetInfo &Target) {
103  bool HasFeature = llvm::StringSwitch<bool>(Feature)
104  .Case("altivec", LangOpts.AltiVec)
105  .Case("blocks", LangOpts.Blocks)
106  .Case("coroutines", LangOpts.Coroutines)
107  .Case("cplusplus", LangOpts.CPlusPlus)
108  .Case("cplusplus11", LangOpts.CPlusPlus11)
109  .Case("cplusplus14", LangOpts.CPlusPlus14)
110  .Case("cplusplus17", LangOpts.CPlusPlus17)
111  .Case("c99", LangOpts.C99)
112  .Case("c11", LangOpts.C11)
113  .Case("c17", LangOpts.C17)
114  .Case("freestanding", LangOpts.Freestanding)
115  .Case("gnuinlineasm", LangOpts.GNUAsm)
116  .Case("objc", LangOpts.ObjC)
117  .Case("objc_arc", LangOpts.ObjCAutoRefCount)
118  .Case("opencl", LangOpts.OpenCL)
119  .Case("tls", Target.isTLSSupported())
120  .Case("zvector", LangOpts.ZVector)
121  .Default(Target.hasFeature(Feature) ||
122  isPlatformEnvironment(Target, Feature));
123  if (!HasFeature)
124  HasFeature = std::find(LangOpts.ModuleFeatures.begin(),
125  LangOpts.ModuleFeatures.end(),
126  Feature) != LangOpts.ModuleFeatures.end();
127  return HasFeature;
128 }
129 
130 bool Module::isUnimportable(const LangOptions &LangOpts,
131  const TargetInfo &Target, Requirement &Req,
132  Module *&ShadowingModule) const {
133  if (!IsUnimportable)
134  return false;
135 
136  for (const Module *Current = this; Current; Current = Current->Parent) {
137  if (Current->ShadowingModule) {
138  ShadowingModule = Current->ShadowingModule;
139  return true;
140  }
141  for (unsigned I = 0, N = Current->Requirements.size(); I != N; ++I) {
142  if (hasFeature(Current->Requirements[I].first, LangOpts, Target) !=
143  Current->Requirements[I].second) {
144  Req = Current->Requirements[I];
145  return true;
146  }
147  }
148  }
149 
150  llvm_unreachable("could not find a reason why module is unimportable");
151 }
152 
153 bool Module::isAvailable(const LangOptions &LangOpts, const TargetInfo &Target,
154  Requirement &Req,
155  UnresolvedHeaderDirective &MissingHeader,
156  Module *&ShadowingModule) const {
157  if (IsAvailable)
158  return true;
159 
160  if (isUnimportable(LangOpts, Target, Req, ShadowingModule))
161  return false;
162 
163  // FIXME: All missing headers are listed on the top-level module. Should we
164  // just look there?
165  for (const Module *Current = this; Current; Current = Current->Parent) {
166  if (!Current->MissingHeaders.empty()) {
167  MissingHeader = Current->MissingHeaders.front();
168  return false;
169  }
170  }
171 
172  llvm_unreachable("could not find a reason why module is unavailable");
173 }
174 
175 bool Module::isSubModuleOf(const Module *Other) const {
176  for (auto *Parent = this; Parent; Parent = Parent->Parent) {
177  if (Parent == Other)
178  return true;
179  }
180  return false;
181 }
182 
183 const Module *Module::getTopLevelModule() const {
184  const Module *Result = this;
185  while (Result->Parent)
186  Result = Result->Parent;
187 
188  return Result;
189 }
190 
191 static StringRef getModuleNameFromComponent(
192  const std::pair<std::string, SourceLocation> &IdComponent) {
193  return IdComponent.first;
194 }
195 
196 static StringRef getModuleNameFromComponent(StringRef R) { return R; }
197 
198 template<typename InputIter>
199 static void printModuleId(raw_ostream &OS, InputIter Begin, InputIter End,
200  bool AllowStringLiterals = true) {
201  for (InputIter It = Begin; It != End; ++It) {
202  if (It != Begin)
203  OS << ".";
204 
205  StringRef Name = getModuleNameFromComponent(*It);
206  if (!AllowStringLiterals || isValidIdentifier(Name))
207  OS << Name;
208  else {
209  OS << '"';
210  OS.write_escaped(Name);
211  OS << '"';
212  }
213  }
214 }
215 
216 template<typename Container>
217 static void printModuleId(raw_ostream &OS, const Container &C) {
218  return printModuleId(OS, C.begin(), C.end());
219 }
220 
221 std::string Module::getFullModuleName(bool AllowStringLiterals) const {
223 
224  // Build up the set of module names (from innermost to outermost).
225  for (const Module *M = this; M; M = M->Parent)
226  Names.push_back(M->Name);
227 
228  std::string Result;
229 
230  llvm::raw_string_ostream Out(Result);
231  printModuleId(Out, Names.rbegin(), Names.rend(), AllowStringLiterals);
232  Out.flush();
233 
234  return Result;
235 }
236 
238  for (const Module *M = this; M; M = M->Parent) {
239  if (nameParts.empty() || M->Name != nameParts.back())
240  return false;
241  nameParts = nameParts.drop_back();
242  }
243  return nameParts.empty();
244 }
245 
247  if (Header U = getUmbrellaHeader())
248  return {"", U.Entry->getDir()};
249 
250  return {UmbrellaAsWritten, Umbrella.dyn_cast<const DirectoryEntry *>()};
251 }
252 
253 void Module::addTopHeader(const FileEntry *File) {
254  assert(File);
255  TopHeaders.insert(File);
256 }
257 
259  if (!TopHeaderNames.empty()) {
260  for (std::vector<std::string>::iterator
261  I = TopHeaderNames.begin(), E = TopHeaderNames.end(); I != E; ++I) {
262  if (auto FE = FileMgr.getFile(*I))
263  TopHeaders.insert(*FE);
264  }
265  TopHeaderNames.clear();
266  }
267 
268  return llvm::makeArrayRef(TopHeaders.begin(), TopHeaders.end());
269 }
270 
271 bool Module::directlyUses(const Module *Requested) const {
272  auto *Top = getTopLevelModule();
273 
274  // A top-level module implicitly uses itself.
275  if (Requested->isSubModuleOf(Top))
276  return true;
277 
278  for (auto *Use : Top->DirectUses)
279  if (Requested->isSubModuleOf(Use))
280  return true;
281 
282  // Anyone is allowed to use our builtin stddef.h and its accompanying module.
283  if (!Requested->Parent && Requested->Name == "_Builtin_stddef_max_align_t")
284  return true;
285 
286  return false;
287 }
288 
289 void Module::addRequirement(StringRef Feature, bool RequiredState,
290  const LangOptions &LangOpts,
291  const TargetInfo &Target) {
292  Requirements.push_back(Requirement(std::string(Feature), RequiredState));
293 
294  // If this feature is currently available, we're done.
295  if (hasFeature(Feature, LangOpts, Target) == RequiredState)
296  return;
297 
298  markUnavailable(/*Unimportable*/true);
299 }
300 
301 void Module::markUnavailable(bool Unimportable) {
302  auto needUpdate = [Unimportable](Module *M) {
303  return M->IsAvailable || (!M->IsUnimportable && Unimportable);
304  };
305 
306  if (!needUpdate(this))
307  return;
308 
310  Stack.push_back(this);
311  while (!Stack.empty()) {
312  Module *Current = Stack.back();
313  Stack.pop_back();
314 
315  if (!needUpdate(Current))
316  continue;
317 
318  Current->IsAvailable = false;
319  Current->IsUnimportable |= Unimportable;
320  for (submodule_iterator Sub = Current->submodule_begin(),
321  SubEnd = Current->submodule_end();
322  Sub != SubEnd; ++Sub) {
323  if (needUpdate(*Sub))
324  Stack.push_back(*Sub);
325  }
326  }
327 }
328 
329 Module *Module::findSubmodule(StringRef Name) const {
330  llvm::StringMap<unsigned>::const_iterator Pos = SubModuleIndex.find(Name);
331  if (Pos == SubModuleIndex.end())
332  return nullptr;
333 
334  return SubModules[Pos->getValue()];
335 }
336 
338  llvm::StringMap<unsigned>::const_iterator Pos = SubModuleIndex.find(Name);
339  if (Pos != SubModuleIndex.end())
340  return SubModules[Pos->getValue()];
341  if (!InferSubmodules)
342  return nullptr;
343  Module *Result = new Module(Name, SourceLocation(), this, false, InferExplicitSubmodules, 0);
344  Result->InferExplicitSubmodules = InferExplicitSubmodules;
345  Result->InferSubmodules = InferSubmodules;
346  Result->InferExportWildcard = InferExportWildcard;
347  if (Result->InferExportWildcard)
348  Result->Exports.push_back(Module::ExportDecl(nullptr, true));
349  return Result;
350 }
351 
353  // All non-explicit submodules are exported.
354  for (std::vector<Module *>::const_iterator I = SubModules.begin(),
355  E = SubModules.end();
356  I != E; ++I) {
357  Module *Mod = *I;
358  if (!Mod->IsExplicit)
359  Exported.push_back(Mod);
360  }
361 
362  // Find re-exported modules by filtering the list of imported modules.
363  bool AnyWildcard = false;
364  bool UnrestrictedWildcard = false;
365  SmallVector<Module *, 4> WildcardRestrictions;
366  for (unsigned I = 0, N = Exports.size(); I != N; ++I) {
367  Module *Mod = Exports[I].getPointer();
368  if (!Exports[I].getInt()) {
369  // Export a named module directly; no wildcards involved.
370  Exported.push_back(Mod);
371 
372  continue;
373  }
374 
375  // Wildcard export: export all of the imported modules that match
376  // the given pattern.
377  AnyWildcard = true;
378  if (UnrestrictedWildcard)
379  continue;
380 
381  if (Module *Restriction = Exports[I].getPointer())
382  WildcardRestrictions.push_back(Restriction);
383  else {
384  WildcardRestrictions.clear();
385  UnrestrictedWildcard = true;
386  }
387  }
388 
389  // If there were any wildcards, push any imported modules that were
390  // re-exported by the wildcard restriction.
391  if (!AnyWildcard)
392  return;
393 
394  for (unsigned I = 0, N = Imports.size(); I != N; ++I) {
395  Module *Mod = Imports[I];
396  bool Acceptable = UnrestrictedWildcard;
397  if (!Acceptable) {
398  // Check whether this module meets one of the restrictions.
399  for (unsigned R = 0, NR = WildcardRestrictions.size(); R != NR; ++R) {
400  Module *Restriction = WildcardRestrictions[R];
401  if (Mod == Restriction || Mod->isSubModuleOf(Restriction)) {
402  Acceptable = true;
403  break;
404  }
405  }
406  }
407 
408  if (!Acceptable)
409  continue;
410 
411  Exported.push_back(Mod);
412  }
413 }
414 
415 void Module::buildVisibleModulesCache() const {
416  assert(VisibleModulesCache.empty() && "cache does not need building");
417 
418  // This module is visible to itself.
419  VisibleModulesCache.insert(this);
420 
421  // Every imported module is visible.
422  SmallVector<Module *, 16> Stack(Imports.begin(), Imports.end());
423  while (!Stack.empty()) {
424  Module *CurrModule = Stack.pop_back_val();
425 
426  // Every module transitively exported by an imported module is visible.
427  if (VisibleModulesCache.insert(CurrModule).second)
428  CurrModule->getExportedModules(Stack);
429  }
430 }
431 
432 void Module::print(raw_ostream &OS, unsigned Indent, bool Dump) const {
433  OS.indent(Indent);
434  if (IsFramework)
435  OS << "framework ";
436  if (IsExplicit)
437  OS << "explicit ";
438  OS << "module ";
439  printModuleId(OS, &Name, &Name + 1);
440 
441  if (IsSystem || IsExternC) {
442  OS.indent(Indent + 2);
443  if (IsSystem)
444  OS << " [system]";
445  if (IsExternC)
446  OS << " [extern_c]";
447  }
448 
449  OS << " {\n";
450 
451  if (!Requirements.empty()) {
452  OS.indent(Indent + 2);
453  OS << "requires ";
454  for (unsigned I = 0, N = Requirements.size(); I != N; ++I) {
455  if (I)
456  OS << ", ";
457  if (!Requirements[I].second)
458  OS << "!";
459  OS << Requirements[I].first;
460  }
461  OS << "\n";
462  }
463 
464  if (Header H = getUmbrellaHeader()) {
465  OS.indent(Indent + 2);
466  OS << "umbrella header \"";
467  OS.write_escaped(H.NameAsWritten);
468  OS << "\"\n";
469  } else if (DirectoryName D = getUmbrellaDir()) {
470  OS.indent(Indent + 2);
471  OS << "umbrella \"";
472  OS.write_escaped(D.NameAsWritten);
473  OS << "\"\n";
474  }
475 
476  if (!ConfigMacros.empty() || ConfigMacrosExhaustive) {
477  OS.indent(Indent + 2);
478  OS << "config_macros ";
480  OS << "[exhaustive]";
481  for (unsigned I = 0, N = ConfigMacros.size(); I != N; ++I) {
482  if (I)
483  OS << ", ";
484  OS << ConfigMacros[I];
485  }
486  OS << "\n";
487  }
488 
489  struct {
490  StringRef Prefix;
492  } Kinds[] = {{"", HK_Normal},
493  {"textual ", HK_Textual},
494  {"private ", HK_Private},
495  {"private textual ", HK_PrivateTextual},
496  {"exclude ", HK_Excluded}};
497 
498  for (auto &K : Kinds) {
499  assert(&K == &Kinds[K.Kind] && "kinds in wrong order");
500  for (auto &H : Headers[K.Kind]) {
501  OS.indent(Indent + 2);
502  OS << K.Prefix << "header \"";
503  OS.write_escaped(H.NameAsWritten);
504  OS << "\" { size " << H.Entry->getSize()
505  << " mtime " << H.Entry->getModificationTime() << " }\n";
506  }
507  }
508  for (auto *Unresolved : {&UnresolvedHeaders, &MissingHeaders}) {
509  for (auto &U : *Unresolved) {
510  OS.indent(Indent + 2);
511  OS << Kinds[U.Kind].Prefix << "header \"";
512  OS.write_escaped(U.FileName);
513  OS << "\"";
514  if (U.Size || U.ModTime) {
515  OS << " {";
516  if (U.Size)
517  OS << " size " << *U.Size;
518  if (U.ModTime)
519  OS << " mtime " << *U.ModTime;
520  OS << " }";
521  }
522  OS << "\n";
523  }
524  }
525 
526  if (!ExportAsModule.empty()) {
527  OS.indent(Indent + 2);
528  OS << "export_as" << ExportAsModule << "\n";
529  }
530 
532  MI != MIEnd; ++MI)
533  // Print inferred subframework modules so that we don't need to re-infer
534  // them (requires expensive directory iteration + stat calls) when we build
535  // the module. Regular inferred submodules are OK, as we need to look at all
536  // those header files anyway.
537  if (!(*MI)->IsInferred || (*MI)->IsFramework)
538  (*MI)->print(OS, Indent + 2, Dump);
539 
540  for (unsigned I = 0, N = Exports.size(); I != N; ++I) {
541  OS.indent(Indent + 2);
542  OS << "export ";
543  if (Module *Restriction = Exports[I].getPointer()) {
544  OS << Restriction->getFullModuleName(true);
545  if (Exports[I].getInt())
546  OS << ".*";
547  } else {
548  OS << "*";
549  }
550  OS << "\n";
551  }
552 
553  for (unsigned I = 0, N = UnresolvedExports.size(); I != N; ++I) {
554  OS.indent(Indent + 2);
555  OS << "export ";
557  if (UnresolvedExports[I].Wildcard)
558  OS << (UnresolvedExports[I].Id.empty() ? "*" : ".*");
559  OS << "\n";
560  }
561 
562  if (Dump) {
563  for (Module *M : Imports) {
564  OS.indent(Indent + 2);
565  llvm::errs() << "import " << M->getFullModuleName() << "\n";
566  }
567  }
568 
569  for (unsigned I = 0, N = DirectUses.size(); I != N; ++I) {
570  OS.indent(Indent + 2);
571  OS << "use ";
572  OS << DirectUses[I]->getFullModuleName(true);
573  OS << "\n";
574  }
575 
576  for (unsigned I = 0, N = UnresolvedDirectUses.size(); I != N; ++I) {
577  OS.indent(Indent + 2);
578  OS << "use ";
580  OS << "\n";
581  }
582 
583  for (unsigned I = 0, N = LinkLibraries.size(); I != N; ++I) {
584  OS.indent(Indent + 2);
585  OS << "link ";
586  if (LinkLibraries[I].IsFramework)
587  OS << "framework ";
588  OS << "\"";
589  OS.write_escaped(LinkLibraries[I].Library);
590  OS << "\"";
591  }
592 
593  for (unsigned I = 0, N = UnresolvedConflicts.size(); I != N; ++I) {
594  OS.indent(Indent + 2);
595  OS << "conflict ";
597  OS << ", \"";
598  OS.write_escaped(UnresolvedConflicts[I].Message);
599  OS << "\"\n";
600  }
601 
602  for (unsigned I = 0, N = Conflicts.size(); I != N; ++I) {
603  OS.indent(Indent + 2);
604  OS << "conflict ";
605  OS << Conflicts[I].Other->getFullModuleName(true);
606  OS << ", \"";
607  OS.write_escaped(Conflicts[I].Message);
608  OS << "\"\n";
609  }
610 
611  if (InferSubmodules) {
612  OS.indent(Indent + 2);
614  OS << "explicit ";
615  OS << "module * {\n";
616  if (InferExportWildcard) {
617  OS.indent(Indent + 4);
618  OS << "export *\n";
619  }
620  OS.indent(Indent + 2);
621  OS << "}\n";
622  }
623 
624  OS.indent(Indent);
625  OS << "}\n";
626 }
627 
628 LLVM_DUMP_METHOD void Module::dump() const {
629  print(llvm::errs(), 0, true);
630 }
631 
634  assert(Loc.isValid() && "setVisible expects a valid import location");
635  if (isVisible(M))
636  return;
637 
638  ++Generation;
639 
640  struct Visiting {
641  Module *M;
642  Visiting *ExportedBy;
643  };
644 
645  std::function<void(Visiting)> VisitModule = [&](Visiting V) {
646  // Nothing to do for a module that's already visible.
647  unsigned ID = V.M->getVisibilityID();
648  if (ImportLocs.size() <= ID)
649  ImportLocs.resize(ID + 1);
650  else if (ImportLocs[ID].isValid())
651  return;
652 
653  ImportLocs[ID] = Loc;
654  Vis(M);
655 
656  // Make any exported modules visible.
658  V.M->getExportedModules(Exports);
659  for (Module *E : Exports) {
660  // Don't import non-importable modules.
661  if (!E->isUnimportable())
662  VisitModule({E, &V});
663  }
664 
665  for (auto &C : V.M->Conflicts) {
666  if (isVisible(C.Other)) {
668  for (Visiting *I = &V; I; I = I->ExportedBy)
669  Path.push_back(I->M);
670  Cb(Path, C.Other, C.Message);
671  }
672  }
673  };
674  VisitModule({M, nullptr});
675 }
676 
678  : Signature(M.Signature), ClangModule(&M) {
679  if (M.Directory)
680  Path = M.Directory->getName();
681  if (auto File = M.getASTFile())
682  ASTFile = File->getName();
683 }
684 
686  if (ClangModule)
687  return ClangModule->Name;
688  else
689  return std::string(PCHModuleName);
690 }
clang::Module::DirectUses
SmallVector< Module *, 2 > DirectUses
The directly used modules.
Definition: Module.h:352
clang::Module::directlyUses
bool directlyUses(const Module *Requested) const
Determine whether this module has declared its intention to directly use another module.
Definition: Module.cpp:271
getModuleNameFromComponent
static StringRef getModuleNameFromComponent(const std::pair< std::string, SourceLocation > &IdComponent)
Definition: Module.cpp:191
clang::Module::Requirement
std::pair< std::string, bool > Requirement
An individual requirement: a feature name and a flag indicating the required state of that feature.
Definition: Module.h:230
clang::Module::getTopLevelModule
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
Definition: Module.h:514
clang::Module::InferSubmodules
unsigned InferSubmodules
Whether we should infer submodules for this module based on the headers.
Definition: Module.h:280
clang::Module::Requirements
SmallVector< Requirement, 2 > Requirements
The set of language features required to use this module.
Definition: Module.h:236
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:237
clang::DeclaratorContext::File
@ File
clang::Module::getUmbrellaDir
DirectoryName getUmbrellaDir() const
Retrieve the directory for which this module serves as the umbrella.
Definition: Module.cpp:246
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::ExplicitSpecKind::Unresolved
@ Unresolved
llvm::SmallVector
Definition: LLVM.h:38
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:89
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:221
clang::DirectoryEntry::getName
StringRef getName() const
Definition: DirectoryEntry.h:40
TargetInfo.h
clang::MultiVersionKind::Target
@ Target
printModuleId
static void printModuleId(raw_ostream &OS, InputIter Begin, InputIter End, bool AllowStringLiterals=true)
Definition: Module.cpp:199
clang::Module::HK_PrivateTextual
@ HK_PrivateTextual
Definition: Module.h:182
clang::Module::submodule_begin
submodule_iterator submodule_begin()
Definition: Module.h:617
clang::Module::Module
Module(StringRef Name, SourceLocation DefinitionLoc, Module *Parent, bool IsFramework, bool IsExplicit, unsigned VisibilityID)
Construct a new module or submodule.
Definition: Module.cpp:37
clang::TargetInfo
Exposes information about the current target.
Definition: TargetInfo.h:188
Module.h
clang::Module::Name
std::string Name
The name of this module.
Definition: Module.h:99
clang::Module::InferExportWildcard
unsigned InferExportWildcard
Whether, when inferring submodules, the inferr submodules should export all modules they import (e....
Definition: Module.h:288
clang::Module::findSubmodule
Module * findSubmodule(StringRef Name) const
Find the submodule with the given name.
Definition: Module.cpp:329
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:303
clang::VisibleModuleSet::isVisible
bool isVisible(const Module *M) const
Determine whether a module is visible.
Definition: Module.h:674
End
SourceLocation End
Definition: USRLocFinder.cpp:167
clang::Module::isAvailable
bool isAvailable() const
Determine whether this module is available for use within the current translation unit.
Definition: Module.h:438
clang::Module::~Module
~Module()
Definition: Module.cpp:61
clang::Module::UnresolvedExports
SmallVector< UnresolvedExportDecl, 2 > UnresolvedExports
The set of export declarations that have yet to be resolved.
Definition: Module.h:349
clang::Module::UnresolvedDirectUses
SmallVector< ModuleId, 2 > UnresolvedDirectUses
The set of use declarations that have yet to be resolved.
Definition: Module.h:355
U
clang::Module::NoUndeclaredIncludes
unsigned NoUndeclaredIncludes
Whether files in this module can only include non-modular headers and headers from used modules.
Definition: Module.h:299
V
#define V(N, I)
Definition: ASTContext.h:3018
clang::Module::getTopHeaders
ArrayRef< const FileEntry * > getTopHeaders(FileManager &FileMgr)
The top-level headers associated with this module.
Definition: Module.cpp:258
clang::Module::submodule_const_iterator
std::vector< Module * >::const_iterator submodule_const_iterator
Definition: Module.h:615
clang::Module::isUnimportable
bool isUnimportable() const
Determine whether this module has been declared unimportable.
Definition: Module.h:418
clang::Module
Describes a module or submodule.
Definition: Module.h:96
clang::Module::findOrInferSubmodule
Module * findOrInferSubmodule(StringRef Name)
Definition: Module.cpp:337
clang::DirectoryEntry
Cached information about one directory (either on disk or in the virtual file system).
Definition: DirectoryEntry.h:33
Id
int Id
Definition: ASTDiff.cpp:191
clang::Module::Exports
SmallVector< ExportDecl, 2 > Exports
The set of export declarations.
Definition: Module.h:331
clang::Module::HK_Textual
@ HK_Textual
Definition: Module.h:180
clang::Module::IsFramework
unsigned IsFramework
Whether this is a framework module.
Definition: Module.h:259
LangOptions.h
clang::Module::HeaderKind
HeaderKind
Definition: Module.h:178
clang::LangOptions::ModuleFeatures
std::vector< std::string > ModuleFeatures
The names of any features to enable in module 'requires' decls in addition to the hard-coded list in ...
Definition: LangOptions.h:319
clang::Module::Conflicts
std::vector< Conflict > Conflicts
The list of conflicts.
Definition: Module.h:409
clang::Module::UnresolvedConflicts
std::vector< UnresolvedConflict > UnresolvedConflicts
The list of conflicts for which the module-id has not yet been resolved.
Definition: Module.h:397
llvm::SmallString< 128 >
HasFeature
static bool HasFeature(const Preprocessor &PP, StringRef Feature)
HasFeature - Return true if we recognize and implement the feature specified by the identifier as a s...
Definition: PPMacroExpansion.cpp:1110
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:226
clang::Module::IsExplicit
unsigned IsExplicit
Whether this is an explicit submodule.
Definition: Module.h:262
clang::Module::getASTFile
OptionalFileEntryRefDegradesToFileEntryPtr getASTFile() const
The serialized AST file for this module, if one was created.
Definition: Module.h:529
clang::VisibleModuleSet::setVisible
void setVisible(Module *M, SourceLocation Loc, VisibleCallback Vis=[](Module *) {}, ConflictCallback Cb=[](ArrayRef< Module * >, Module *, StringRef) {})
Make a specific module visible.
Definition: Module.cpp:632
clang::FileEntry
Cached information about one file (either on disk or in the virtual file system).
Definition: FileEntry.h:331
clang::ASTSourceDescriptor::getModuleName
std::string getModuleName() const
Definition: Module.cpp:685
clang::Module::Parent
Module * Parent
The parent of this module.
Definition: Module.h:124
clang::Module::submodule_iterator
std::vector< Module * >::iterator submodule_iterator
Definition: Module.h:614
clang::Module::UmbrellaAsWritten
std::string UmbrellaAsWritten
The name of the umbrella entry, as written in the module map.
Definition: Module.h:142
clang::Module::HK_Normal
@ HK_Normal
Definition: Module.h:179
clang::Module::markUnavailable
void markUnavailable(bool Unimportable)
Mark this module and all of its submodules as unavailable.
Definition: Module.cpp:301
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:376
SourceLocation.h
clang::Indent
raw_ostream & Indent(raw_ostream &Out, const unsigned int Space, bool IsDot)
Definition: JsonSupport.h:20
clang::Module::HK_Private
@ HK_Private
Definition: Module.h:181
clang::Module::Directory
const DirectoryEntry * Directory
The build directory of this module.
Definition: Module.h:129
clang::Module::Headers
SmallVector< Header, 2 > Headers[5]
The headers that are part of this module.
Definition: Module.h:206
CharInfo.h
isPlatformEnvironment
static bool isPlatformEnvironment(const TargetInfo &Target, StringRef Feature)
Definition: Module.cpp:68
false
#define false
Definition: stdbool.h:17
clang::Module::IsSystem
unsigned IsSystem
Whether this is a "system" module (which assumes that all headers in it are system headers).
Definition: Module.h:266
Begin
SourceLocation Begin
Definition: USRLocFinder.cpp:165
llvm::ArrayRef
Definition: LLVM.h:34
clang::Module::Umbrella
llvm::PointerUnion< const FileEntry *, const DirectoryEntry * > Umbrella
The umbrella header or directory.
Definition: Module.h:136
clang::Module::Imports
llvm::SmallSetVector< Module *, 2 > Imports
The set of modules imported by this module, and on which this module depends.
Definition: Module.h:322
clang::Module::HK_Excluded
@ HK_Excluded
Definition: Module.h:183
clang::Module::InferExplicitSubmodules
unsigned InferExplicitSubmodules
Whether, when inferring submodules, the inferred submodules should be explicit.
Definition: Module.h:284
clang::Module::IsAvailable
unsigned IsAvailable
Whether this module is available in the current translation unit.
Definition: Module.h:253
clang::VisibleModuleSet::ConflictCallback
llvm::function_ref< void(ArrayRef< Module * > Path, Module *Conflict, StringRef Message)> ConflictCallback
A callback to call when a module conflict is found.
Definition: Module.h:694
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:58
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:210
clang::Module::Kind
ModuleKind Kind
The kind of this module.
Definition: Module.h:120
clang::Module::DirectoryName
Information about a directory name as found in the module map file.
Definition: Module.h:198
clang::Builtin::ID
ID
Definition: Builtins.h:47
clang
Dataflow Directional Tag Classes.
Definition: CalledOnceCheck.h:17
clang::FileManager
Implements support for file system lookup, file system caching, and directory search management.
Definition: FileManager.h:53
clang::Module::isSubModuleOf
bool isSubModuleOf(const Module *Other) const
Check if this module is a (possibly transitive) submodule of Other.
Definition: Module.cpp:175
clang::Module::ExportAsModule
std::string ExportAsModule
The module through which entities defined in this module will eventually be exposed,...
Definition: Module.h:146
clang::VisibleModuleSet::VisibleCallback
llvm::function_ref< void(Module *M)> VisibleCallback
A callback to call when a module is made visible (directly or indirectly) by a call to setVisible.
Definition: Module.h:687
clang::ASTSourceDescriptor::ASTSourceDescriptor
ASTSourceDescriptor()=default
clang::Module::Header
Information about a header directive as found in the module map file.
Definition: Module.h:189
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:432
clang::Module::IsUnimportable
unsigned IsUnimportable
Whether this module has declared itself unimportable, either because it's missing a requirement from ...
Definition: Module.h:244
clang::Module::getUmbrellaHeader
Header getUmbrellaHeader() const
Retrieve the header that serves as the umbrella header for this module.
Definition: Module.h:546
clang::SourceLocation::isValid
bool isValid() const
Return true if this is a valid SourceLocation object.
Definition: SourceLocation.h:110
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:384
clang::Module::dump
void dump() const
Dump the contents of this module to the given output stream.
Definition: APINotesYAMLCompiler.cpp:577
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:271
clang::Module::ConfigMacrosExhaustive
unsigned ConfigMacrosExhaustive
Whether the set of configuration macros is exhaustive.
Definition: Module.h:295
clang::Module::submodule_end
submodule_iterator submodule_end()
Definition: Module.h:619
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:196
clang::Module::getExportedModules
void getExportedModules(SmallVectorImpl< Module * > &Exported) const
Appends this module's list of exported modules to Exported.
Definition: Module.cpp:352
Parent
NodeId Parent
Definition: ASTDiff.cpp:192
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:289
clang::Module::addTopHeader
void addTopHeader(const FileEntry *File)
Add a top-level header associated with this module.
Definition: Module.cpp:253
llvm::SmallVectorImpl
Definition: LLVM.h:39
FileManager.h
true
#define true
Definition: stdbool.h:16
clang::isValidIdentifier
LLVM_READONLY bool isValidIdentifier(StringRef S, bool AllowDollar=false)
Return true if this is a valid ASCII identifier.
Definition: CharInfo.h:184
clang::Module::ShadowingModule
Module * ShadowingModule
A module with the same name that shadows this module.
Definition: Module.h:239
clang::Module::ExportDecl
llvm::PointerIntPair< Module *, 1, bool > ExportDecl
Describes an exported module.
Definition: Module.h:328
clang::interp::Sub
bool Sub(InterpState &S, CodePtr OpPC)
Definition: Interp.h:140
hasFeature
static bool hasFeature(StringRef Feature, const LangOptions &LangOpts, const TargetInfo &Target)
Determine whether a translation unit built using the current language options has the given feature.
Definition: Module.cpp:101
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:222