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