clang  12.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  HasUmbrellaDir(false), NameVisibility(Hidden) {
48  if (Parent) {
49  IsAvailable = Parent->isAvailable();
50  IsUnimportable = Parent->isUnimportable();
51  IsSystem = Parent->IsSystem;
52  IsExternC = Parent->IsExternC;
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  const Module *This = this;
177  do {
178  if (This == Other)
179  return true;
180 
181  This = This->Parent;
182  } while (This);
183 
184  return false;
185 }
186 
188  const Module *Result = this;
189  while (Result->Parent)
190  Result = Result->Parent;
191 
192  return Result;
193 }
194 
195 static StringRef getModuleNameFromComponent(
196  const std::pair<std::string, SourceLocation> &IdComponent) {
197  return IdComponent.first;
198 }
199 
200 static StringRef getModuleNameFromComponent(StringRef R) { return R; }
201 
202 template<typename InputIter>
203 static void printModuleId(raw_ostream &OS, InputIter Begin, InputIter End,
204  bool AllowStringLiterals = true) {
205  for (InputIter It = Begin; It != End; ++It) {
206  if (It != Begin)
207  OS << ".";
208 
209  StringRef Name = getModuleNameFromComponent(*It);
210  if (!AllowStringLiterals || isValidIdentifier(Name))
211  OS << Name;
212  else {
213  OS << '"';
214  OS.write_escaped(Name);
215  OS << '"';
216  }
217  }
218 }
219 
220 template<typename Container>
221 static void printModuleId(raw_ostream &OS, const Container &C) {
222  return printModuleId(OS, C.begin(), C.end());
223 }
224 
225 std::string Module::getFullModuleName(bool AllowStringLiterals) const {
227 
228  // Build up the set of module names (from innermost to outermost).
229  for (const Module *M = this; M; M = M->Parent)
230  Names.push_back(M->Name);
231 
232  std::string Result;
233 
234  llvm::raw_string_ostream Out(Result);
235  printModuleId(Out, Names.rbegin(), Names.rend(), AllowStringLiterals);
236  Out.flush();
237 
238  return Result;
239 }
240 
242  for (const Module *M = this; M; M = M->Parent) {
243  if (nameParts.empty() || M->Name != nameParts.back())
244  return false;
245  nameParts = nameParts.drop_back();
246  }
247  return nameParts.empty();
248 }
249 
251  if (Header U = getUmbrellaHeader())
252  return {"", U.Entry->getDir()};
253 
254  return {UmbrellaAsWritten, static_cast<const DirectoryEntry *>(Umbrella)};
255 }
256 
257 void Module::addTopHeader(const FileEntry *File) {
258  assert(File);
259  TopHeaders.insert(File);
260 }
261 
263  if (!TopHeaderNames.empty()) {
264  for (std::vector<std::string>::iterator
265  I = TopHeaderNames.begin(), E = TopHeaderNames.end(); I != E; ++I) {
266  if (auto FE = FileMgr.getFile(*I))
267  TopHeaders.insert(*FE);
268  }
269  TopHeaderNames.clear();
270  }
271 
272  return llvm::makeArrayRef(TopHeaders.begin(), TopHeaders.end());
273 }
274 
275 bool Module::directlyUses(const Module *Requested) const {
276  auto *Top = getTopLevelModule();
277 
278  // A top-level module implicitly uses itself.
279  if (Requested->isSubModuleOf(Top))
280  return true;
281 
282  for (auto *Use : Top->DirectUses)
283  if (Requested->isSubModuleOf(Use))
284  return true;
285 
286  // Anyone is allowed to use our builtin stddef.h and its accompanying module.
287  if (!Requested->Parent && Requested->Name == "_Builtin_stddef_max_align_t")
288  return true;
289 
290  return false;
291 }
292 
293 void Module::addRequirement(StringRef Feature, bool RequiredState,
294  const LangOptions &LangOpts,
295  const TargetInfo &Target) {
296  Requirements.push_back(Requirement(std::string(Feature), RequiredState));
297 
298  // If this feature is currently available, we're done.
299  if (hasFeature(Feature, LangOpts, Target) == RequiredState)
300  return;
301 
302  markUnavailable(/*Unimportable*/true);
303 }
304 
305 void Module::markUnavailable(bool Unimportable) {
306  auto needUpdate = [Unimportable](Module *M) {
307  return M->IsAvailable || (!M->IsUnimportable && Unimportable);
308  };
309 
310  if (!needUpdate(this))
311  return;
312 
314  Stack.push_back(this);
315  while (!Stack.empty()) {
316  Module *Current = Stack.back();
317  Stack.pop_back();
318 
319  if (!needUpdate(Current))
320  continue;
321 
322  Current->IsAvailable = false;
323  Current->IsUnimportable |= Unimportable;
324  for (submodule_iterator Sub = Current->submodule_begin(),
325  SubEnd = Current->submodule_end();
326  Sub != SubEnd; ++Sub) {
327  if (needUpdate(*Sub))
328  Stack.push_back(*Sub);
329  }
330  }
331 }
332 
333 Module *Module::findSubmodule(StringRef Name) const {
334  llvm::StringMap<unsigned>::const_iterator Pos = SubModuleIndex.find(Name);
335  if (Pos == SubModuleIndex.end())
336  return nullptr;
337 
338  return SubModules[Pos->getValue()];
339 }
340 
342  llvm::StringMap<unsigned>::const_iterator Pos = SubModuleIndex.find(Name);
343  if (Pos != SubModuleIndex.end())
344  return SubModules[Pos->getValue()];
345  if (!InferSubmodules)
346  return nullptr;
347  Module *Result = new Module(Name, SourceLocation(), this, false, InferExplicitSubmodules, 0);
351  if (Result->InferExportWildcard)
352  Result->Exports.push_back(Module::ExportDecl(nullptr, true));
353  return Result;
354 }
355 
357  // All non-explicit submodules are exported.
358  for (std::vector<Module *>::const_iterator I = SubModules.begin(),
359  E = SubModules.end();
360  I != E; ++I) {
361  Module *Mod = *I;
362  if (!Mod->IsExplicit)
363  Exported.push_back(Mod);
364  }
365 
366  // Find re-exported modules by filtering the list of imported modules.
367  bool AnyWildcard = false;
368  bool UnrestrictedWildcard = false;
369  SmallVector<Module *, 4> WildcardRestrictions;
370  for (unsigned I = 0, N = Exports.size(); I != N; ++I) {
371  Module *Mod = Exports[I].getPointer();
372  if (!Exports[I].getInt()) {
373  // Export a named module directly; no wildcards involved.
374  Exported.push_back(Mod);
375 
376  continue;
377  }
378 
379  // Wildcard export: export all of the imported modules that match
380  // the given pattern.
381  AnyWildcard = true;
382  if (UnrestrictedWildcard)
383  continue;
384 
385  if (Module *Restriction = Exports[I].getPointer())
386  WildcardRestrictions.push_back(Restriction);
387  else {
388  WildcardRestrictions.clear();
389  UnrestrictedWildcard = true;
390  }
391  }
392 
393  // If there were any wildcards, push any imported modules that were
394  // re-exported by the wildcard restriction.
395  if (!AnyWildcard)
396  return;
397 
398  for (unsigned I = 0, N = Imports.size(); I != N; ++I) {
399  Module *Mod = Imports[I];
400  bool Acceptable = UnrestrictedWildcard;
401  if (!Acceptable) {
402  // Check whether this module meets one of the restrictions.
403  for (unsigned R = 0, NR = WildcardRestrictions.size(); R != NR; ++R) {
404  Module *Restriction = WildcardRestrictions[R];
405  if (Mod == Restriction || Mod->isSubModuleOf(Restriction)) {
406  Acceptable = true;
407  break;
408  }
409  }
410  }
411 
412  if (!Acceptable)
413  continue;
414 
415  Exported.push_back(Mod);
416  }
417 }
418 
419 void Module::buildVisibleModulesCache() const {
420  assert(VisibleModulesCache.empty() && "cache does not need building");
421 
422  // This module is visible to itself.
423  VisibleModulesCache.insert(this);
424 
425  // Every imported module is visible.
426  SmallVector<Module *, 16> Stack(Imports.begin(), Imports.end());
427  while (!Stack.empty()) {
428  Module *CurrModule = Stack.pop_back_val();
429 
430  // Every module transitively exported by an imported module is visible.
431  if (VisibleModulesCache.insert(CurrModule).second)
432  CurrModule->getExportedModules(Stack);
433  }
434 }
435 
436 void Module::print(raw_ostream &OS, unsigned Indent) const {
437  OS.indent(Indent);
438  if (IsFramework)
439  OS << "framework ";
440  if (IsExplicit)
441  OS << "explicit ";
442  OS << "module ";
443  printModuleId(OS, &Name, &Name + 1);
444 
445  if (IsSystem || IsExternC) {
446  OS.indent(Indent + 2);
447  if (IsSystem)
448  OS << " [system]";
449  if (IsExternC)
450  OS << " [extern_c]";
451  }
452 
453  OS << " {\n";
454 
455  if (!Requirements.empty()) {
456  OS.indent(Indent + 2);
457  OS << "requires ";
458  for (unsigned I = 0, N = Requirements.size(); I != N; ++I) {
459  if (I)
460  OS << ", ";
461  if (!Requirements[I].second)
462  OS << "!";
463  OS << Requirements[I].first;
464  }
465  OS << "\n";
466  }
467 
468  if (Header H = getUmbrellaHeader()) {
469  OS.indent(Indent + 2);
470  OS << "umbrella header \"";
471  OS.write_escaped(H.NameAsWritten);
472  OS << "\"\n";
473  } else if (DirectoryName D = getUmbrellaDir()) {
474  OS.indent(Indent + 2);
475  OS << "umbrella \"";
476  OS.write_escaped(D.NameAsWritten);
477  OS << "\"\n";
478  }
479 
480  if (!ConfigMacros.empty() || ConfigMacrosExhaustive) {
481  OS.indent(Indent + 2);
482  OS << "config_macros ";
484  OS << "[exhaustive]";
485  for (unsigned I = 0, N = ConfigMacros.size(); I != N; ++I) {
486  if (I)
487  OS << ", ";
488  OS << ConfigMacros[I];
489  }
490  OS << "\n";
491  }
492 
493  struct {
494  StringRef Prefix;
496  } Kinds[] = {{"", HK_Normal},
497  {"textual ", HK_Textual},
498  {"private ", HK_Private},
499  {"private textual ", HK_PrivateTextual},
500  {"exclude ", HK_Excluded}};
501 
502  for (auto &K : Kinds) {
503  assert(&K == &Kinds[K.Kind] && "kinds in wrong order");
504  for (auto &H : Headers[K.Kind]) {
505  OS.indent(Indent + 2);
506  OS << K.Prefix << "header \"";
507  OS.write_escaped(H.NameAsWritten);
508  OS << "\" { size " << H.Entry->getSize()
509  << " mtime " << H.Entry->getModificationTime() << " }\n";
510  }
511  }
512  for (auto *Unresolved : {&UnresolvedHeaders, &MissingHeaders}) {
513  for (auto &U : *Unresolved) {
514  OS.indent(Indent + 2);
515  OS << Kinds[U.Kind].Prefix << "header \"";
516  OS.write_escaped(U.FileName);
517  OS << "\"";
518  if (U.Size || U.ModTime) {
519  OS << " {";
520  if (U.Size)
521  OS << " size " << *U.Size;
522  if (U.ModTime)
523  OS << " mtime " << *U.ModTime;
524  OS << " }";
525  }
526  OS << "\n";
527  }
528  }
529 
530  if (!ExportAsModule.empty()) {
531  OS.indent(Indent + 2);
532  OS << "export_as" << ExportAsModule << "\n";
533  }
534 
536  MI != MIEnd; ++MI)
537  // Print inferred subframework modules so that we don't need to re-infer
538  // them (requires expensive directory iteration + stat calls) when we build
539  // the module. Regular inferred submodules are OK, as we need to look at all
540  // those header files anyway.
541  if (!(*MI)->IsInferred || (*MI)->IsFramework)
542  (*MI)->print(OS, Indent + 2);
543 
544  for (unsigned I = 0, N = Exports.size(); I != N; ++I) {
545  OS.indent(Indent + 2);
546  OS << "export ";
547  if (Module *Restriction = Exports[I].getPointer()) {
548  OS << Restriction->getFullModuleName(true);
549  if (Exports[I].getInt())
550  OS << ".*";
551  } else {
552  OS << "*";
553  }
554  OS << "\n";
555  }
556 
557  for (unsigned I = 0, N = UnresolvedExports.size(); I != N; ++I) {
558  OS.indent(Indent + 2);
559  OS << "export ";
561  if (UnresolvedExports[I].Wildcard)
562  OS << (UnresolvedExports[I].Id.empty() ? "*" : ".*");
563  OS << "\n";
564  }
565 
566  for (unsigned I = 0, N = DirectUses.size(); I != N; ++I) {
567  OS.indent(Indent + 2);
568  OS << "use ";
569  OS << DirectUses[I]->getFullModuleName(true);
570  OS << "\n";
571  }
572 
573  for (unsigned I = 0, N = UnresolvedDirectUses.size(); I != N; ++I) {
574  OS.indent(Indent + 2);
575  OS << "use ";
577  OS << "\n";
578  }
579 
580  for (unsigned I = 0, N = LinkLibraries.size(); I != N; ++I) {
581  OS.indent(Indent + 2);
582  OS << "link ";
583  if (LinkLibraries[I].IsFramework)
584  OS << "framework ";
585  OS << "\"";
586  OS.write_escaped(LinkLibraries[I].Library);
587  OS << "\"";
588  }
589 
590  for (unsigned I = 0, N = UnresolvedConflicts.size(); I != N; ++I) {
591  OS.indent(Indent + 2);
592  OS << "conflict ";
594  OS << ", \"";
595  OS.write_escaped(UnresolvedConflicts[I].Message);
596  OS << "\"\n";
597  }
598 
599  for (unsigned I = 0, N = Conflicts.size(); I != N; ++I) {
600  OS.indent(Indent + 2);
601  OS << "conflict ";
602  OS << Conflicts[I].Other->getFullModuleName(true);
603  OS << ", \"";
604  OS.write_escaped(Conflicts[I].Message);
605  OS << "\"\n";
606  }
607 
608  if (InferSubmodules) {
609  OS.indent(Indent + 2);
611  OS << "explicit ";
612  OS << "module * {\n";
613  if (InferExportWildcard) {
614  OS.indent(Indent + 4);
615  OS << "export *\n";
616  }
617  OS.indent(Indent + 2);
618  OS << "}\n";
619  }
620 
621  OS.indent(Indent);
622  OS << "}\n";
623 }
624 
625 LLVM_DUMP_METHOD void Module::dump() const {
626  print(llvm::errs());
627 }
628 
631  assert(Loc.isValid() && "setVisible expects a valid import location");
632  if (isVisible(M))
633  return;
634 
635  ++Generation;
636 
637  struct Visiting {
638  Module *M;
639  Visiting *ExportedBy;
640  };
641 
642  std::function<void(Visiting)> VisitModule = [&](Visiting V) {
643  // Nothing to do for a module that's already visible.
644  unsigned ID = V.M->getVisibilityID();
645  if (ImportLocs.size() <= ID)
646  ImportLocs.resize(ID + 1);
647  else if (ImportLocs[ID].isValid())
648  return;
649 
650  ImportLocs[ID] = Loc;
651  Vis(M);
652 
653  // Make any exported modules visible.
655  V.M->getExportedModules(Exports);
656  for (Module *E : Exports) {
657  // Don't import non-importable modules.
658  if (!E->isUnimportable())
659  VisitModule({E, &V});
660  }
661 
662  for (auto &C : V.M->Conflicts) {
663  if (isVisible(C.Other)) {
665  for (Visiting *I = &V; I; I = I->ExportedBy)
666  Path.push_back(I->M);
667  Cb(Path, C.Other, C.Message);
668  }
669  }
670  };
671  VisitModule({M, nullptr});
672 }
673 
675  : Signature(M.Signature), ClangModule(&M) {
676  if (M.Directory)
677  Path = M.Directory->getName();
678  if (auto *File = M.getASTFile())
679  ASTFile = File->getName();
680 }
681 
683  if (ClangModule)
684  return ClangModule->Name;
685  else
686  return std::string(PCHModuleName);
687 }
unsigned IsAvailable
Whether this module is available in the current translation unit.
Definition: Module.h:244
SmallVector< UnresolvedExportDecl, 2 > UnresolvedExports
The set of export declarations that have yet to be resolved.
Definition: Module.h:343
ASTFileSignature Signature
The module signature.
Definition: Module.h:130
std::string Name
The name of this module.
Definition: Module.h:90
const void * Umbrella
The umbrella header or directory.
Definition: Module.h:127
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:217
std::vector< Module * >::iterator submodule_iterator
Definition: Module.h:603
Implements support for file system lookup, file system caching, and directory search management...
Definition: FileManager.h:172
Defines the clang::FileManager interface and associated types.
submodule_iterator submodule_begin()
Definition: Module.h:606
unsigned IsExternC
Whether this is an &#39;extern "C"&#39; module (which implicitly puts all headers in it within an &#39;extern "C"...
Definition: Module.h:262
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:1060
std::vector< UnresolvedConflict > UnresolvedConflicts
The list of conflicts for which the module-id has not yet been resolved.
Definition: Module.h:391
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
Definition: Module.h:504
unsigned IsFramework
Whether this is a framework module.
Definition: Module.h:250
const FileEntry * getASTFile() const
The serialized AST file for this module, if one was created.
Definition: Module.h:519
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:293
bool This(InterpState &S, CodePtr OpPC)
Definition: Interp.h:827
static bool isPlatformEnvironment(const TargetInfo &Target, StringRef Feature)
Definition: Module.cpp:68
ModuleKind Kind
The kind of this module.
Definition: Module.h:111
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...
SmallVector< Requirement, 2 > Requirements
The set of language features required to use this module.
Definition: Module.h:227
Header getUmbrellaHeader() const
Retrieve the header that serves as the umbrella header for this module.
Definition: Module.h:536
void setVisible(Module *M, SourceLocation Loc, VisibleCallback Vis=[](Module *) {}, ConflictCallback Cb=[](ArrayRef< Module *>, Module *, StringRef) {})
Make a specific module visible.
Definition: Module.cpp:629
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:54
Describes a module or submodule.
Definition: Module.h:87
unsigned InferExportWildcard
Whether, when inferring submodules, the inferr submodules should export all modules they import (e...
Definition: Module.h:279
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:225
static void printModuleId(raw_ostream &OS, InputIter Begin, InputIter End, bool AllowStringLiterals=true)
Definition: Module.cpp:203
bool isSubModuleOf(const Module *Other) const
Determine whether this module is a submodule of the given other module.
Definition: Module.cpp:175
Module * Parent
The parent of this module.
Definition: Module.h:115
submodule_iterator submodule_end()
Definition: Module.h:608
std::vector< std::string > ModuleFeatures
The names of any features to enable in module &#39;requires&#39; decls in addition to the hard-coded list in ...
Definition: LangOptions.h:280
unsigned NoUndeclaredIncludes
Whether files in this module can only include non-modular headers and headers from used modules...
Definition: Module.h:290
void getExportedModules(SmallVectorImpl< Module *> &Exported) const
Appends this module&#39;s list of exported modules to Exported.
Definition: Module.cpp:356
unsigned IsSystem
Whether this is a "system" module (which assumes that all headers in it are system headers)...
Definition: Module.h:257
NodeId Parent
Definition: ASTDiff.cpp:192
std::string getModuleName() const
Definition: Module.cpp:682
Module * findSubmodule(StringRef Name) const
Find the submodule with the given name.
Definition: Module.cpp:333
llvm::SmallSetVector< Module *, 2 > Imports
The set of modules imported by this module, and on which this module depends.
Definition: Module.h:316
const DirectoryEntry * Entry
Definition: Module.h:191
Exposes information about the current target.
Definition: TargetInfo.h:179
Defines the clang::LangOptions interface.
SmallVector< ModuleId, 2 > UnresolvedDirectUses
The set of use declarations that have yet to be resolved.
Definition: Module.h:349
SourceLocation End
int Id
Definition: ASTDiff.cpp:191
void markUnavailable(bool Unimportable)
Mark this module and all of its submodules as unavailable.
Definition: Module.cpp:305
unsigned ConfigMacrosExhaustive
Whether the set of configuration macros is exhaustive.
Definition: Module.h:286
#define V(N, I)
Definition: ASTContext.h:2899
void print(raw_ostream &OS, unsigned Indent=0) const
Print the module map for this module to the given stream.
Definition: Module.cpp:436
SourceLocation Begin
ArrayRef< const FileEntry * > getTopHeaders(FileManager &FileMgr)
The top-level headers associated with this module.
Definition: Module.cpp:262
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:370
Module(StringRef Name, SourceLocation DefinitionLoc, Module *Parent, bool IsFramework, bool IsExplicit, unsigned VisibilityID)
Construct a new module or submodule.
Definition: Module.cpp:37
bool isAvailable() const
Determine whether this module is available for use within the current translation unit...
Definition: Module.h:432
Information about a header directive as found in the module map file.
Definition: Module.h:180
The result type of a method or function.
SmallVector< ExportDecl, 2 > Exports
The set of export declarations.
Definition: Module.h:325
const DirectoryEntry * Directory
The build directory of this module.
Definition: Module.h:120
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:683
bool fullModuleNameIs(ArrayRef< StringRef > nameParts) const
Whether the full name of this module is equal to joining nameParts with "."s.
Definition: Module.cpp:241
#define false
Definition: stdbool.h:17
LLVM_READONLY bool isValidIdentifier(StringRef S, bool AllowDollar=false)
Return true if this is a valid ASCII identifier.
Definition: CharInfo.h:184
bool isUnimportable() const
Determine whether this module has been declared unimportable.
Definition: Module.h:412
StringRef getPlatformName() const
Retrieve the name of the platform as it is used in the availability attribute.
Definition: TargetInfo.h:1341
Encodes a location in the source.
std::string ExportAsModule
The module through which entities defined in this module will eventually be exposed, for use in "private" modules.
Definition: Module.h:137
Module * findOrInferSubmodule(StringRef Name)
Definition: Module.cpp:341
Information about a directory name as found in the module map file.
Definition: Module.h:189
Cached information about one file (either on disk or in the virtual file system). ...
Definition: FileManager.h:79
SmallVector< Header, 2 > Headers[5]
The headers that are part of this module.
Definition: Module.h:197
unsigned IsUnimportable
Whether this module has declared itself unimportable, either because it&#39;s missing a requirement from ...
Definition: Module.h:235
Defines the clang::Module class, which describes a module in the source code.
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:221
static StringRef getModuleNameFromComponent(const std::pair< std::string, SourceLocation > &IdComponent)
Definition: Module.cpp:195
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:213
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
Stored information about a header directive that was found in the module map file but has not been re...
Definition: Module.h:201
Module * ShadowingModule
A module with the same name that shadows this module.
Definition: Module.h:230
llvm::PointerIntPair< Module *, 1, bool > ExportDecl
Describes an exported module.
Definition: Module.h:322
virtual bool hasFeature(StringRef Feature) const
Determine whether the given target has the given feature.
Definition: TargetInfo.h:1209
unsigned ModuleMapIsPrivate
Whether this module came from a "private" module map, found next to a regular (public) module map...
Definition: Module.h:294
llvm::ErrorOr< const FileEntry * > getFile(StringRef Filename, bool OpenFile=false, bool CacheFailure=true)
Lookup, cache, and verify the specified file (real or virtual).
std::vector< Conflict > Conflicts
The list of conflicts.
Definition: Module.h:403
SmallVector< Module *, 2 > DirectUses
The directly used modules.
Definition: Module.h:346
void dump() const
Dump the contents of this module to the given output stream.
Definition: Module.cpp:625
DirectoryName getUmbrellaDir() const
Retrieve the directory for which this module serves as the umbrella.
Definition: Module.cpp:250
Cached information about one directory (either on disk or in the virtual file system).
Definition: FileManager.h:46
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:676
Defines the clang::SourceLocation class and associated facilities.
unsigned InferSubmodules
Whether we should infer submodules for this module based on the headers.
Definition: Module.h:271
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
bool isTLSSupported() const
Whether the target supports thread-local storage.
Definition: TargetInfo.h:1266
void addTopHeader(const FileEntry *File)
Add a top-level header associated with this module.
Definition: Module.cpp:257
bool directlyUses(const Module *Requested) const
Determine whether this module has declared its intention to directly use another module.
Definition: Module.cpp:275
Defines the clang::TargetInfo interface.
std::vector< std::string > ConfigMacros
The set of "configuration macros", which are macros that (intentionally) change how this module is bu...
Definition: Module.h:378
raw_ostream & Indent(raw_ostream &Out, const unsigned int Space, bool IsDot)
Definition: JsonSupport.h:20
std::string UmbrellaAsWritten
The name of the umbrella entry, as written in the module map.
Definition: Module.h:133
#define true
Definition: stdbool.h:16
unsigned IsExplicit
Whether this is an explicit submodule.
Definition: Module.h:253
bool Sub(InterpState &S, CodePtr OpPC)
Definition: Interp.h:140
std::vector< Module * >::const_iterator submodule_const_iterator
Definition: Module.h:604
unsigned InferExplicitSubmodules
Whether, when inferring submodules, the inferred submodules should be explicit.
Definition: Module.h:275
StringRef getName() const
Definition: FileManager.h:53