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