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