clang 23.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 <cassert>
29#include <functional>
30#include <string>
31#include <utility>
32#include <vector>
33
34using namespace clang;
35
38 bool IsExplicit, unsigned VisibilityID)
40 VisibilityID(VisibilityID), IsUnimportable(false),
48 if (Parent) {
49 IsAvailable = Parent->isAvailable();
50 IsUnimportable = Parent->isUnimportable();
51 IsSystem = Parent->IsSystem;
52 IsExternC = Parent->IsExternC;
53 NoUndeclaredIncludes = Parent->NoUndeclaredIncludes;
54 ModuleMapIsPrivate = Parent->ModuleMapIsPrivate;
55
56 Parent->SubModuleIndex[Name] = Parent->SubModules.size();
57 Parent->SubModules.push_back(this);
58 }
59}
60
61Module::~Module() = default;
62
63static bool isPlatformEnvironment(const TargetInfo &Target, StringRef Feature) {
64 StringRef Platform = Target.getPlatformName();
65 StringRef Env = Target.getTriple().getEnvironmentName();
66
67 // Attempt to match platform and environment.
68 if (Platform == Feature || Target.getTriple().getOSName() == Feature ||
69 Env == Feature)
70 return true;
71
72 auto CmpPlatformEnv = [](StringRef LHS, StringRef RHS) {
73 auto Pos = LHS.find('-');
74 if (Pos == StringRef::npos)
75 return false;
76 SmallString<128> NewLHS = LHS.slice(0, Pos);
77 NewLHS += LHS.slice(Pos+1, LHS.size());
78 return NewLHS == RHS;
79 };
80
81 SmallString<128> PlatformEnv = Target.getTriple().getOSAndEnvironmentName();
82 // Darwin has different but equivalent variants for simulators, example:
83 // 1. x86_64-apple-ios-simulator
84 // 2. x86_64-apple-iossimulator
85 // where both are valid examples of the same platform+environment but in the
86 // variant (2) the simulator is hardcoded as part of the platform name. Both
87 // forms above should match for "iossimulator" requirement.
88 if (Target.getTriple().isOSDarwin() && PlatformEnv.ends_with("simulator"))
89 return PlatformEnv == Feature || CmpPlatformEnv(PlatformEnv, Feature);
90
91 return PlatformEnv == Feature;
92}
93
94/// Determine whether a translation unit built using the current
95/// language options has the given feature.
96static bool hasFeature(StringRef Feature, const LangOptions &LangOpts,
97 const TargetInfo &Target) {
98 bool HasFeature = llvm::StringSwitch<bool>(Feature)
99 .Case("altivec", LangOpts.AltiVec)
100 .Case("blocks", LangOpts.Blocks)
101 .Case("coroutines", LangOpts.Coroutines)
102 .Case("cplusplus", LangOpts.CPlusPlus)
103 .Case("cplusplus11", LangOpts.CPlusPlus11)
104 .Case("cplusplus14", LangOpts.CPlusPlus14)
105 .Case("cplusplus17", LangOpts.CPlusPlus17)
106 .Case("cplusplus20", LangOpts.CPlusPlus20)
107 .Case("cplusplus23", LangOpts.CPlusPlus23)
108 .Case("cplusplus26", LangOpts.CPlusPlus26)
109 .Case("c99", LangOpts.C99)
110 .Case("c11", LangOpts.C11)
111 .Case("c17", LangOpts.C17)
112 .Case("c23", LangOpts.C23)
113 .Case("freestanding", LangOpts.Freestanding)
114 .Case("gnuinlineasm", LangOpts.GNUAsm)
115 .Case("objc", LangOpts.ObjC)
116 .Case("objc_arc", LangOpts.ObjCAutoRefCount)
117 .Case("opencl", LangOpts.OpenCL)
118 .Case("tls", Target.isTLSSupported())
119 .Case("zvector", LangOpts.ZVector)
120 .Default(Target.hasFeature(Feature) ||
122 if (!HasFeature)
123 HasFeature = llvm::is_contained(LangOpts.ModuleFeatures, Feature);
124 return HasFeature;
125}
126
128 const TargetInfo &Target, Requirement &Req,
129 Module *&ShadowingModule) const {
130 if (!IsUnimportable)
131 return false;
132
133 for (const Module *Current = this; Current; Current = Current->Parent) {
134 if (Current->ShadowingModule) {
135 ShadowingModule = Current->ShadowingModule;
136 return true;
137 }
138 for (unsigned I = 0, N = Current->Requirements.size(); I != N; ++I) {
139 if (hasFeature(Current->Requirements[I].FeatureName, LangOpts, Target) !=
140 Current->Requirements[I].RequiredState) {
141 Req = Current->Requirements[I];
142 return true;
143 }
144 }
145 }
146
147 llvm_unreachable("could not find a reason why module is unimportable");
148}
149
150// The -fmodule-name option tells the compiler to textually include headers in
151// the specified module, meaning Clang won't build the specified module. This
152// is useful in a number of situations, for instance, when building a library
153// that vends a module map, one might want to avoid hitting intermediate build
154// products containing the module map or avoid finding the system installed
155// modulemap for that library.
156bool Module::isForBuilding(const LangOptions &LangOpts) const {
157 StringRef TopLevelName = getTopLevelModuleName();
158 StringRef CurrentModule = LangOpts.CurrentModule;
159
160 // When building the implementation of framework Foo, we want to make sure
161 // that Foo *and* Foo_Private are textually included and no modules are built
162 // for either.
163 if (!LangOpts.isCompilingModule() && getTopLevelModule()->IsFramework &&
164 CurrentModule == LangOpts.ModuleName &&
165 !CurrentModule.ends_with("_Private") &&
166 TopLevelName.ends_with("_Private"))
167 TopLevelName = TopLevelName.drop_back(8);
168
169 return TopLevelName == CurrentModule;
170}
171
173 Requirement &Req,
174 UnresolvedHeaderDirective &MissingHeader,
175 Module *&ShadowingModule) const {
176 if (IsAvailable)
177 return true;
178
179 if (isUnimportable(LangOpts, Target, Req, ShadowingModule))
180 return false;
181
182 // FIXME: All missing headers are listed on the top-level module. Should we
183 // just look there?
184 for (const Module *Current = this; Current; Current = Current->Parent) {
185 if (!Current->MissingHeaders.empty()) {
186 MissingHeader = Current->MissingHeaders.front();
187 return false;
188 }
189 }
190
191 llvm_unreachable("could not find a reason why module is unavailable");
192}
193
195 for (auto *Parent = this; Parent; Parent = Parent->Parent) {
196 if (Parent == Other)
197 return true;
198 }
199 return false;
200}
201
203 const Module *Result = this;
204 while (Result->Parent)
205 Result = Result->Parent;
206
207 return Result;
208}
209
211 const std::pair<std::string, SourceLocation> &IdComponent) {
212 return IdComponent.first;
213}
214
215static StringRef getModuleNameFromComponent(StringRef R) { return R; }
216
217template<typename InputIter>
218static void printModuleId(raw_ostream &OS, InputIter Begin, InputIter End,
219 bool AllowStringLiterals = true) {
220 for (InputIter It = Begin; It != End; ++It) {
221 if (It != Begin)
222 OS << ".";
223
224 StringRef Name = getModuleNameFromComponent(*It);
225 if (!AllowStringLiterals || isValidAsciiIdentifier(Name))
226 OS << Name;
227 else {
228 OS << '"';
229 OS.write_escaped(Name);
230 OS << '"';
231 }
232 }
233}
234
235template<typename Container>
236static void printModuleId(raw_ostream &OS, const Container &C) {
237 return printModuleId(OS, C.begin(), C.end());
238}
239
240std::string Module::getFullModuleName(bool AllowStringLiterals) const {
242
243 // Build up the set of module names (from innermost to outermost).
244 for (const Module *M = this; M; M = M->Parent)
245 Names.push_back(M->Name);
246
247 std::string Result;
248
249 llvm::raw_string_ostream Out(Result);
250 printModuleId(Out, Names.rbegin(), Names.rend(), AllowStringLiterals);
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 (const auto *Hdr = std::get_if<FileEntryRef>(&Umbrella))
266 return Hdr->getDir();
267 if (const auto *Dir = std::get_if<DirectoryEntryRef>(&Umbrella))
268 return *Dir;
269 return std::nullopt;
270}
271
273 assert(File);
274 TopHeaders.insert(File);
275}
276
278 if (!TopHeaderNames.empty()) {
279 for (StringRef TopHeaderName : TopHeaderNames)
280 if (auto FE = FileMgr.getOptionalFileRef(TopHeaderName))
281 TopHeaders.insert(*FE);
282 TopHeaderNames.clear();
283 }
284
285 return llvm::ArrayRef(TopHeaders.begin(), TopHeaders.end());
286}
287
288bool Module::directlyUses(const Module *Requested) {
289 auto *Top = getTopLevelModule();
290
291 // A top-level module implicitly uses itself.
292 if (Requested->isSubModuleOf(Top))
293 return true;
294
295 for (auto *Use : Top->DirectUses)
296 if (Requested->isSubModuleOf(Use))
297 return true;
298
299 // Anyone is allowed to use our builtin stddef.h and its accompanying modules.
300 if (Requested->fullModuleNameIs({"_Builtin_stddef", "max_align_t"}) ||
301 Requested->fullModuleNameIs({"_Builtin_stddef_wint_t"}))
302 return true;
303 // Darwin is allowed is to use our builtin 'ptrauth.h' and its accompanying
304 // module.
305 if (!Requested->Parent && Requested->Name == "ptrauth")
306 return true;
307
309 UndeclaredUses.insert(Requested);
310
311 return false;
312}
313
314void Module::addRequirement(StringRef Feature, bool RequiredState,
315 const LangOptions &LangOpts,
316 const TargetInfo &Target) {
317 Requirements.push_back(Requirement{std::string(Feature), RequiredState});
318
319 // If this feature is currently available, we're done.
320 if (hasFeature(Feature, LangOpts, Target) == RequiredState)
321 return;
322
323 markUnavailable(/*Unimportable*/true);
324}
325
326void Module::markUnavailable(bool Unimportable) {
327 auto needUpdate = [Unimportable](Module *M) {
328 return M->IsAvailable || (!M->IsUnimportable && Unimportable);
329 };
330
331 if (!needUpdate(this))
332 return;
333
335 Stack.push_back(this);
336 while (!Stack.empty()) {
337 Module *Current = Stack.pop_back_val();
338
339 if (!needUpdate(Current))
340 continue;
341
342 Current->IsAvailable = false;
343 Current->IsUnimportable |= Unimportable;
344 for (Module *Submodule : Current->submodules()) {
345 if (needUpdate(Submodule))
346 Stack.push_back(Submodule);
347 }
348 }
349}
350
352 if (auto It = SubModuleIndex.find(Name); It != SubModuleIndex.end())
353 return SubModules[It->second];
354
355 return nullptr;
356}
357
359 assert(isNamedModuleUnit() && "We should only query the global module "
360 "fragment from the C++20 Named modules");
361
362 for (Module *SubModule : submodules())
363 if (SubModule->isExplicitGlobalModule())
364 return SubModule;
365
366 return nullptr;
367}
368
370 assert(isNamedModuleUnit() && "We should only query the private module "
371 "fragment from the C++20 Named modules");
372
373 for (Module *SubModule : submodules())
374 if (SubModule->isPrivateModule())
375 return SubModule;
376
377 return nullptr;
378}
379
381 // All non-explicit submodules are exported.
382 for (Module *Mod : submodules())
383 if (!Mod->IsExplicit)
384 Exported.push_back(Mod);
385
386 // Find re-exported modules by filtering the list of imported modules.
387 bool AnyWildcard = false;
388 bool UnrestrictedWildcard = false;
389 SmallVector<Module *, 4> WildcardRestrictions;
390 for (unsigned I = 0, N = Exports.size(); I != N; ++I) {
391 Module *Mod = Exports[I].first;
392 if (!Exports[I].second) {
393 // Export a named module directly; no wildcards involved.
394 Exported.push_back(Mod);
395
396 continue;
397 }
398
399 // Wildcard export: export all of the imported modules that match
400 // the given pattern.
401 AnyWildcard = true;
402 if (UnrestrictedWildcard)
403 continue;
404
405 if (Module *Restriction = Exports[I].first)
406 WildcardRestrictions.push_back(Restriction);
407 else {
408 WildcardRestrictions.clear();
409 UnrestrictedWildcard = true;
410 }
411 }
412
413 // If there were any wildcards, push any imported modules that were
414 // re-exported by the wildcard restriction.
415 if (!AnyWildcard)
416 return;
417
418 for (unsigned I = 0, N = Imports.size(); I != N; ++I) {
419 Module *Mod = Imports[I];
420 bool Acceptable = UnrestrictedWildcard;
421 if (!Acceptable) {
422 // Check whether this module meets one of the restrictions.
423 for (unsigned R = 0, NR = WildcardRestrictions.size(); R != NR; ++R) {
424 Module *Restriction = WildcardRestrictions[R];
425 if (Mod == Restriction || Mod->isSubModuleOf(Restriction)) {
426 Acceptable = true;
427 break;
428 }
429 }
430 }
431
432 if (!Acceptable)
433 continue;
434
435 Exported.push_back(Mod);
436 }
437}
438
439void Module::buildVisibleModulesCache() const {
440 assert(VisibleModulesCache.empty() && "cache does not need building");
441
442 // This module is visible to itself.
443 VisibleModulesCache.insert(this);
444
445 // Every imported module is visible.
446 SmallVector<Module *, 16> Stack(Imports.begin(), Imports.end());
447 while (!Stack.empty()) {
448 Module *CurrModule = Stack.pop_back_val();
449
450 // Every module transitively exported by an imported module is visible.
451 if (VisibleModulesCache.insert(CurrModule).second)
452 CurrModule->getExportedModules(Stack);
453 }
454}
455
456void Module::print(raw_ostream &OS, unsigned Indent, bool Dump) const {
457 OS.indent(Indent);
458 if (IsFramework)
459 OS << "framework ";
460 if (IsExplicit)
461 OS << "explicit ";
462 OS << "module ";
463 printModuleId(OS, &Name, &Name + 1);
464
465 if (IsSystem || IsExternC) {
466 OS.indent(Indent + 2);
467 if (IsSystem)
468 OS << " [system]";
469 if (IsExternC)
470 OS << " [extern_c]";
471 }
472
473 OS << " {\n";
474
475 if (!Requirements.empty()) {
476 OS.indent(Indent + 2);
477 OS << "requires ";
478 for (unsigned I = 0, N = Requirements.size(); I != N; ++I) {
479 if (I)
480 OS << ", ";
481 if (!Requirements[I].RequiredState)
482 OS << "!";
483 OS << Requirements[I].FeatureName;
484 }
485 OS << "\n";
486 }
487
488 if (std::optional<Header> H = getUmbrellaHeaderAsWritten()) {
489 OS.indent(Indent + 2);
490 OS << "umbrella header \"";
491 OS.write_escaped(H->NameAsWritten);
492 OS << "\"\n";
493 } else if (std::optional<DirectoryName> D = getUmbrellaDirAsWritten()) {
494 OS.indent(Indent + 2);
495 OS << "umbrella \"";
496 OS.write_escaped(D->NameAsWritten);
497 OS << "\"\n";
498 }
499
500 if (!ConfigMacros.empty() || ConfigMacrosExhaustive) {
501 OS.indent(Indent + 2);
502 OS << "config_macros ";
504 OS << "[exhaustive]";
505 for (unsigned I = 0, N = ConfigMacros.size(); I != N; ++I) {
506 if (I)
507 OS << ", ";
508 OS << ConfigMacros[I];
509 }
510 OS << "\n";
511 }
512
513 struct {
514 StringRef Prefix;
516 } Kinds[] = {{"", HK_Normal},
517 {"textual ", HK_Textual},
518 {"private ", HK_Private},
519 {"private textual ", HK_PrivateTextual},
520 {"exclude ", HK_Excluded}};
521
522 for (auto &K : Kinds) {
523 assert(&K == &Kinds[K.Kind] && "kinds in wrong order");
524 for (auto &H : getHeaders(K.Kind)) {
525 OS.indent(Indent + 2);
526 OS << K.Prefix << "header \"";
527 OS.write_escaped(H.NameAsWritten);
528 OS << "\" { size " << H.Entry.getSize()
529 << " mtime " << H.Entry.getModificationTime() << " }\n";
530 }
531 }
532 for (auto *Unresolved : {&UnresolvedHeaders, &MissingHeaders}) {
533 for (auto &U : *Unresolved) {
534 OS.indent(Indent + 2);
535 OS << Kinds[U.Kind].Prefix << "header \"";
536 OS.write_escaped(U.FileName);
537 OS << "\"";
538 if (U.Size || U.ModTime) {
539 OS << " {";
540 if (U.Size)
541 OS << " size " << *U.Size;
542 if (U.ModTime)
543 OS << " mtime " << *U.ModTime;
544 OS << " }";
545 }
546 OS << "\n";
547 }
548 }
549
550 if (!ExportAsModule.empty()) {
551 OS.indent(Indent + 2);
552 OS << "export_as" << ExportAsModule << "\n";
553 }
554
555 for (Module *Submodule : submodules())
556 // Print inferred subframework modules so that we don't need to re-infer
557 // them (requires expensive directory iteration + stat calls) when we build
558 // the module. Regular inferred submodules are OK, as we need to look at all
559 // those header files anyway.
560 if (!Submodule->IsInferred || Submodule->IsFramework)
561 Submodule->print(OS, Indent + 2, Dump);
562
563 for (unsigned I = 0, N = Exports.size(); I != N; ++I) {
564 OS.indent(Indent + 2);
565 OS << "export ";
566 if (Module *Restriction = Exports[I].first) {
567 OS << Restriction->getFullModuleName(true);
568 if (Exports[I].second)
569 OS << ".*";
570 } else {
571 OS << "*";
572 }
573 OS << "\n";
574 }
575
576 for (unsigned I = 0, N = UnresolvedExports.size(); I != N; ++I) {
577 OS.indent(Indent + 2);
578 OS << "export ";
580 if (UnresolvedExports[I].Wildcard)
581 OS << (UnresolvedExports[I].Id.empty() ? "*" : ".*");
582 OS << "\n";
583 }
584
585 if (Dump) {
586 for (Module *M : Imports) {
587 OS.indent(Indent + 2);
588 llvm::errs() << "import " << M->getFullModuleName() << "\n";
589 }
590 }
591
592 for (unsigned I = 0, N = DirectUses.size(); I != N; ++I) {
593 OS.indent(Indent + 2);
594 OS << "use ";
595 OS << DirectUses[I]->getFullModuleName(true);
596 OS << "\n";
597 }
598
599 for (unsigned I = 0, N = UnresolvedDirectUses.size(); I != N; ++I) {
600 OS.indent(Indent + 2);
601 OS << "use ";
603 OS << "\n";
604 }
605
606 for (unsigned I = 0, N = LinkLibraries.size(); I != N; ++I) {
607 OS.indent(Indent + 2);
608 OS << "link ";
610 OS << "framework ";
611 OS << "\"";
612 OS.write_escaped(LinkLibraries[I].Library);
613 OS << "\"";
614 }
615
616 for (unsigned I = 0, N = UnresolvedConflicts.size(); I != N; ++I) {
617 OS.indent(Indent + 2);
618 OS << "conflict ";
620 OS << ", \"";
621 OS.write_escaped(UnresolvedConflicts[I].Message);
622 OS << "\"\n";
623 }
624
625 for (unsigned I = 0, N = Conflicts.size(); I != N; ++I) {
626 OS.indent(Indent + 2);
627 OS << "conflict ";
628 OS << Conflicts[I].Other->getFullModuleName(true);
629 OS << ", \"";
630 OS.write_escaped(Conflicts[I].Message);
631 OS << "\"\n";
632 }
633
634 if (InferSubmodules) {
635 OS.indent(Indent + 2);
637 OS << "explicit ";
638 OS << "module * {\n";
640 OS.indent(Indent + 4);
641 OS << "export *\n";
642 }
643 OS.indent(Indent + 2);
644 OS << "}\n";
645 }
646
647 OS.indent(Indent);
648 OS << "}\n";
649}
650
651LLVM_DUMP_METHOD void Module::dump() const {
652 print(llvm::errs(), 0, true);
653}
654
656 bool IncludeExports, VisibleCallback Vis,
657 ConflictCallback Cb) {
658 // We can't import a global module fragment so the location can be invalid.
659 assert((M->isGlobalModule() || Loc.isValid()) &&
660 "setVisible expects a valid import location");
661 if (isVisible(M))
662 return;
663
664 ++Generation;
665
666 struct Visiting {
667 Module *M;
668 Visiting *ExportedBy;
669 };
670
671 std::function<void(Visiting)> VisitModule = [&](Visiting V) {
672 // Nothing to do for a module that's already visible.
673 unsigned ID = V.M->getVisibilityID();
674 if (ImportLocs.size() <= ID)
675 ImportLocs.resize(ID + 1);
676 else if (ImportLocs[ID].isValid())
677 return;
678
679 ImportLocs[ID] = Loc;
680 Vis(V.M);
681
682 // Make any exported modules visible.
683 if (IncludeExports) {
685 V.M->getExportedModules(Exports);
686 for (Module *E : Exports) {
687 // Don't import non-importable modules.
688 if (!E->isUnimportable())
689 VisitModule({E, &V});
690 }
691 }
692
693 for (auto &C : V.M->Conflicts) {
694 if (isVisible(C.Other)) {
696 for (Visiting *I = &V; I; I = I->ExportedBy)
697 Path.push_back(I->M);
698 Cb(Path, C.Other, C.Message);
699 }
700 }
701 };
702 VisitModule({M, nullptr});
703}
#define V(N, I)
Defines the clang::FileManager interface and associated types.
Defines the clang::LangOptions interface.
llvm::MachO::Target Target
Definition MachO.h:51
static bool isPlatformEnvironment(const TargetInfo &Target, StringRef Feature)
Definition Module.cpp:63
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:96
static void printModuleId(raw_ostream &OS, InputIter Begin, InputIter End, bool AllowStringLiterals=true)
Definition Module.cpp:218
static StringRef getModuleNameFromComponent(const std::pair< std::string, SourceLocation > &IdComponent)
Definition Module.cpp:210
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.
A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...
Definition FileEntry.h:57
Implements support for file system lookup, file system caching, and directory search management.
Definition FileManager.h:53
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
std::string ModuleName
The module currently being compiled as specified by -fmodule-name.
bool isCompilingModule() const
Are we compiling a module?
std::string CurrentModule
The name of the current module, of which the main source file is a part.
std::vector< std::string > ModuleFeatures
The names of any features to enable in module 'requires' decls in addition to the hard-coded list in ...
Required to construct a Module.
Definition Module.h:229
Describes a module or submodule.
Definition Module.h:237
StringRef getTopLevelModuleName() const
Retrieve the name of the top-level module.
Definition Module.h:830
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:314
unsigned IsExplicit
Whether this is an explicit submodule.
Definition Module.h:481
SmallVector< ExportDecl, 2 > Exports
The set of export declarations.
Definition Module.h:568
bool isForBuilding(const LangOptions &LangOpts) const
Determine whether this module can be built in this compilation.
Definition Module.cpp:156
std::variant< std::monostate, FileEntryRef, DirectoryEntryRef > Umbrella
The umbrella header or directory.
Definition Module.h:298
unsigned InferSubmodules
Whether we should infer submodules for this module based on the headers.
Definition Module.h:503
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:288
std::vector< std::string > ConfigMacros
The set of "configuration macros", which are macros that (intentionally) change how this module is bu...
Definition Module.h:625
unsigned IsUnimportable
Whether this module has declared itself unimportable, either because it's missing a requirement from ...
Definition Module.h:458
NameVisibilityKind NameVisibility
The visibility of names within this particular module.
Definition Module.h:548
@ Hidden
All of the names in this module are hidden.
Definition Module.h:542
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:456
bool isNamedModuleUnit() const
Is this a C++20 named module unit.
Definition Module.h:774
SourceLocation DefinitionLoc
The location of the module definition.
Definition Module.h:243
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:438
Module(ModuleConstructorTag, StringRef Name, SourceLocation DefinitionLoc, Module *Parent, bool IsFramework, bool IsExplicit, unsigned VisibilityID)
Construct a new module or submodule.
Definition Module.cpp:36
Module * Parent
The parent of this module.
Definition Module.h:286
void markUnavailable(bool Unimportable)
Mark this module and all of its submodules as unavailable.
Definition Module.cpp:326
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:434
ModuleKind Kind
The kind of this module.
Definition Module.h:282
@ HK_PrivateTextual
Definition Module.h:379
bool isUnimportable() const
Determine whether this module has been declared unimportable.
Definition Module.h:660
bool fullModuleNameIs(ArrayRef< StringRef > nameParts) const
Whether the full name of this module is equal to joining nameParts with "."s.
Definition Module.cpp:255
Module * getPrivateModuleFragment() const
Get the Private Module Fragment (sub-module) for this module, it there is one.
Definition Module.cpp:369
unsigned IsInferred
Whether this is an inferred submodule (module * { ... }).
Definition Module.h:496
llvm::SmallSetVector< Module *, 2 > Imports
The set of modules imported by this module, and on which this module depends.
Definition Module.h:555
unsigned IsSystem
Whether this is a "system" module (which assumes that all headers in it are system headers).
Definition Module.h:486
std::string Name
The name of this module.
Definition Module.h:240
Module * getGlobalModuleFragment() const
Get the Global Module Fragment (sub-module) for this module, it there is one.
Definition Module.cpp:358
llvm::iterator_range< submodule_iterator > submodules()
Definition Module.h:947
unsigned IsExternC
Whether this is an 'extern "C"' module (which implicitly puts all headers in it within an 'extern "C"...
Definition Module.h:492
unsigned ModuleMapIsPrivate
Whether this module came from a "private" module map, found next to a regular (public) module map.
Definition Module.h:531
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:617
SmallVector< UnresolvedExportDecl, 2 > UnresolvedExports
The set of export declarations that have yet to be resolved.
Definition Module.h:586
std::optional< Header > getUmbrellaHeaderAsWritten() const
Retrieve the umbrella header as written.
Definition Module.h:865
SmallVector< Requirement, 2 > Requirements
The set of language features required to use this module.
Definition Module.h:449
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:596
SmallVector< ModuleId, 2 > UnresolvedDirectUses
The set of use declarations that have yet to be resolved.
Definition Module.h:592
unsigned NamedModuleHasInit
Whether this C++20 named modules doesn't need an initializer.
Definition Module.h:536
unsigned NoUndeclaredIncludes
Whether files in this module can only include non-modular headers and headers from used modules.
Definition Module.h:526
SmallVector< Module *, 2 > DirectUses
The directly used modules.
Definition Module.h:589
unsigned ConfigMacrosExhaustive
Whether the set of configuration macros is exhaustive.
Definition Module.h:521
ArrayRef< Header > getHeaders(HeaderKind HK) const
Definition Module.h:399
bool isGlobalModule() const
Does this Module scope describe a fragment of the global module within some C++ module.
Definition Module.h:335
unsigned InferExportWildcard
Whether, when inferring submodules, the inferr submodules should export all modules they import (e....
Definition Module.h:513
void getExportedModules(SmallVectorImpl< Module * > &Exported) const
Appends this module's list of exported modules to Exported.
Definition Module.cpp:380
std::vector< UnresolvedConflict > UnresolvedConflicts
The list of conflicts for which the module-id has not yet been resolved.
Definition Module.h:638
unsigned IsFromModuleFile
Whether this module was loaded from a module file.
Definition Module.h:473
bool isSubModuleOf(const Module *Other) const
Check if this module is a (possibly transitive) submodule of Other.
Definition Module.cpp:194
ArrayRef< FileEntryRef > getTopHeaders(FileManager &FileMgr)
The top-level headers associated with this module.
Definition Module.cpp:277
bool isAvailable() const
Determine whether this module is available for use within the current translation unit.
Definition Module.h:683
std::optional< DirectoryName > getUmbrellaDirAsWritten() const
Retrieve the umbrella directory as written.
Definition Module.h:857
unsigned HasIncompatibleModuleFile
Whether we tried and failed to load a module file for this module.
Definition Module.h:462
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:452
unsigned IsFramework
Whether this is a framework module.
Definition Module.h:477
std::string ExportAsModule
The module through which entities defined in this module will eventually be exposed,...
Definition Module.h:314
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:240
void addTopHeader(FileEntryRef File)
Add a top-level header associated with this module.
Definition Module.cpp:272
unsigned IsAvailable
Whether this module is available in the current translation unit.
Definition Module.h:469
unsigned InferExplicitSubmodules
Whether, when inferring submodules, the inferred submodules should be explicit.
Definition Module.h:508
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
Definition Module.h:820
OptionalDirectoryEntryRef getEffectiveUmbrellaDir() const
Get the effective umbrella directory for this module: either the one explicitly written in the module...
Definition Module.cpp:264
std::vector< Conflict > Conflicts
The list of conflicts.
Definition Module.h:650
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:227
void setVisible(Module *M, SourceLocation Loc, bool IncludeExports=true, VisibleCallback Vis=[](Module *) {}, ConflictCallback Cb=[](ArrayRef< Module * >, Module *, StringRef) {})
Make a specific module visible.
Definition Module.cpp:655
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:1012
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:1017
bool isVisible(const Module *M) const
Determine whether a module is visible.
Definition Module.h:999
Defines the clang::TargetInfo interface.
The JSON file list parser is used to communicate input to InstallAPI.
LLVM_READONLY bool isValidAsciiIdentifier(StringRef S, bool AllowDollar=false)
Return true if this is a valid ASCII identifier.
Definition CharInfo.h:244
raw_ostream & Indent(raw_ostream &Out, const unsigned int Space, bool IsDot)
Definition JsonSupport.h:21
@ Result
The result type of a method or function.
Definition TypeBase.h:905
CustomizableOptional< DirectoryEntryRef > OptionalDirectoryEntryRef
@ Other
Other implicit parameter.
Definition Decl.h:1763
int const char * function
Definition c++config.h:31
#define false
Definition stdbool.h:26
#define true
Definition stdbool.h:25
Stored information about a header directive that was found in the module map file but has not been re...
Definition Module.h:422