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