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