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