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