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