clang: include/clang/Lex/ModuleMap.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef LLVM_CLANG_LEX_MODULEMAP_H
15#define LLVM_CLANG_LEX_MODULEMAP_H
16
21#include "llvm/ADT/ArrayRef.h"
22#include "llvm/ADT/DenseMap.h"
23#include "llvm/ADT/DenseSet.h"
24#include "llvm/ADT/PointerIntPair.h"
25#include "llvm/ADT/SmallVector.h"
26#include "llvm/ADT/StringMap.h"
27#include "llvm/ADT/StringRef.h"
28#include "llvm/ADT/StringSet.h"
29#include "llvm/ADT/TinyPtrVector.h"
30#include "llvm/ADT/Twine.h"
31#include
32#include
33#include
34#include
35#include
36
38
39class DiagnosticsEngine;
40class DirectoryEntry;
41class FileEntry;
42class FileManager;
44class SourceManager;
45
46
47
49 virtual void anchor();
50
51public:
53
54
55
56
57
58
59
61 bool IsSystem) {}
62
63
64
65
67
68
69
70
72};
73
80
82
83
84
86
87
88
89
91
92
93
94 Module *SourceModule = nullptr;
95
96
97 llvm::SpecificBumpPtrAllocator ModulesAlloc;
98
99
100
102
103
104 llvm::StringMap<Module *> Modules;
105
106
107
108 llvm::DenseMap<const IdentifierInfo *, Module *> CachedModuleLoads;
109
110
112
113
114 unsigned NumCreatedModules = 0;
115
116
117
118 llvm::StringMap<llvm::StringSet<>> PendingLinkAsModule;
119
120public:
121
122
124
125
126
128
129
131
133
134
136
137
138
140
141
143
144
145
146
147
148
149 };
150
151
153
154
156
157
159
160
161
163 llvm::PointerIntPair<Module *, 3, ModuleHeaderRole> Storage;
164
165 public:
168
170 return A.Storage == B.Storage;
171 }
173 return A.Storage != B.Storage;
174 }
175
176
178
179
181
182
185 }
186
187
191 }
192
193
194
195 explicit operator bool() const {
196 return Storage.getPointer() != nullptr;
197 }
198 };
199
201
202private:
204
205 using HeadersMap = llvm::DenseMap<FileEntryRef, SmallVector<KnownHeader, 1>>;
206
207
208
209 HeadersMap Headers;
210
211
212 mutable llvm::DenseMap<off_t, llvm::TinyPtrVector<Module*>> LazyHeadersBySize;
213
214
215 mutable llvm::DenseMap<time_t, llvm::TinyPtrVector<Module*>>
216 LazyHeadersByModTime;
217
218
219
220
221
222
223
224 llvm::DenseMap<const DirectoryEntry *, Module *> UmbrellaDirs;
225
226
227
228
229
230
231 unsigned CurrentModuleScopeID = 0;
232
233 llvm::DenseMap<Module *, unsigned> ModuleScopeIDs;
234
235
236 struct Attributes {
237
238 LLVM_PREFERRED_TYPE(bool)
239 unsigned IsSystem : 1;
240
241
242 LLVM_PREFERRED_TYPE(bool)
243 unsigned IsExternC : 1;
244
245
246 LLVM_PREFERRED_TYPE(bool)
247 unsigned IsExhaustive : 1;
248
249
250
251 LLVM_PREFERRED_TYPE(bool)
252 unsigned NoUndeclaredIncludes : 1;
253
254 Attributes()
255 : IsSystem(false), IsExternC(false), IsExhaustive(false),
256 NoUndeclaredIncludes(false) {}
257 };
258
259
260 struct InferredDirectory {
261
262 LLVM_PREFERRED_TYPE(bool)
263 unsigned InferModules : 1;
264
265
266 Attributes Attrs;
267
268
269
270 FileID ModuleMapFID;
271
272
273
274 SmallVector<std::string, 2> ExcludedModules;
275
276 InferredDirectory() : InferModules(false) {}
277 };
278
279
280
281 llvm::DenseMap<const DirectoryEntry *, InferredDirectory> InferredDirectories;
282
283
284
285 llvm::DenseMap<const Module *, FileID> InferredModuleAllowedBy;
286
287 llvm::DenseMap<const Module *, AdditionalModMapsSet> AdditionalModMaps;
288
289
290
291 llvm::DenseMap<const FileEntry *, bool> ParsedModuleMap;
292
293
294
295
296
297
298
299
300
301
302
303
304
306 resolveExport(Module *Mod, const Module::UnresolvedExportDecl &Unresolved,
307 bool Complain) const;
308
309
310
311
312
313
314
315
316
317
318
319
320 Module *resolveModuleId(const ModuleId &Id, Module *Mod, bool Complain) const;
321
322
323
324
325
326
327
328
329 void addUnresolvedHeader(Module *Mod,
330 Module::UnresolvedHeaderDirective Header,
331 bool &NeedsFramework);
332
333
334
335
336
337
338
339
340
341
343 findHeader(Module *M, const Module::UnresolvedHeaderDirective &Header,
344 SmallVectorImpl &RelativePathName, bool &NeedsFramework);
345
346
347
348
349
350
351
352 void resolveHeader(Module *M, const Module::UnresolvedHeaderDirective &Header,
353 bool &NeedsFramework);
354
355
356
357
358 bool resolveAsBuiltinHeader(Module *M,
359 const Module::UnresolvedHeaderDirective &Header);
360
361
362
363
364
365
366 HeadersMap::iterator findKnownHeader(FileEntryRef File);
367
368
369
370
371
372
373
374 KnownHeader findHeaderInUmbrellaDirs(
375 FileEntryRef File, SmallVectorImpl &IntermediateDirs);
376
377
378
379 KnownHeader findOrCreateModuleForHeaderInUmbrellaDir(FileEntryRef File);
380
381
382
383 bool isHeaderInUmbrellaDirs(FileEntryRef File) {
384 SmallVector<DirectoryEntryRef, 2> IntermediateDirs;
385 return static_cast<bool>(findHeaderInUmbrellaDirs(File, IntermediateDirs));
386 }
387
388 Module *inferFrameworkModule(DirectoryEntryRef FrameworkDir, Attributes Attrs,
390
391public:
392
393
394
395
396
397
398
399
400
401
402
403 ModuleMap(SourceManager &SourceMgr, DiagnosticsEngine &Diags,
404 const LangOptions &LangOpts, const TargetInfo *Target,
405 HeaderSearch &HeaderInfo);
406
407
409
410
412
413
414
416
417
419
420
422
425
426
428 Callbacks.push_back(std::move(Callback));
429 }
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
446 bool AllowExcluded = false);
447
448
449
450
451
452
453
454
456
457
458
460
461
462
463
464
466
467
468
469
471 std::optional<const FileEntry *> File) const;
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
488 bool RequestingModuleIsModuleInterface,
491
492
493
495
496
497
499 const Module *RequestingModule) const;
500
501
502
503
504
505
507
509
510
511
512
513
514
515
516
517
518
520
521
522
523
524
525
526
527
528
529
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
547 bool IsFramework,
548 bool IsExplicit);
549
550
552 bool IsFramework, bool IsExplicit) {
554 }
555
556
557
559 bool IsExplicit);
560
561
562
563
564
565
566
567
572
573
576
577
578
581
582
583
584
585
586
587
588
590
591
592
593
594
595
597
598
601
602
603
606
607
608
610 Module *ShadowingModule);
611
612
613
614
615
616
618
620 assert(!ExistingModule->Parent && "expected top-level module");
621 assert(ModuleScopeIDs.count(ExistingModule) && "unknown module");
622 return ModuleScopeIDs[ExistingModule] < CurrentModuleScopeID;
623 }
624
625
627 auto It = InferredDirectories.find(Dir);
628 return It != InferredDirectories.end() && It->getSecond().InferModules;
629 }
630
631
632
633
634
635
636
637
640
641
642
643
644
645
646
647
648
649
652
654
655
656
657
658
659
660
661
663
664
665
666
667
669 auto I = AdditionalModMaps.find(M);
670 if (I == AdditionalModMaps.end())
671 return nullptr;
672 return &I->second;
673 }
674
676
677
678
679
680
681
682
683
684
686
687
688
689
690
691
692
693
694
696
697
698
699
700
701
702
703
704
706
707
708 void
710 const Twine &NameAsWritten,
711 const Twine &PathRelativeToRootModuleDirectory);
712
713
715 const Twine &NameAsWritten,
716 const Twine &PathRelativeToRootModuleDirectory);
717
718
719
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
745 unsigned *Offset = nullptr,
747
748
750
752
755 llvm::iterator_range<module_iterator> modules() const {
757 }
758
759
761 CachedModuleLoads[&II] = M;
762 }
763
764
766 auto I = CachedModuleLoads.find(&II);
767 if (I == CachedModuleLoads.end())
768 return std::nullopt;
769 return I->second;
770 }
771};
772
773}
774
775#endif
enum clang::sema::@1725::IndirectLocalPathEntry::EntryKind Kind
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Defines the clang::LangOptions interface.
llvm::MachO::Target Target
Defines the clang::Module class, which describes a module in the source code.
Defines the clang::SourceLocation class and associated facilities.
Concrete class used by the front-end to report problems and issues.
A reference to a DirectoryEntry that includes the name of the directory as it was accessed by the Fil...
Cached information about one directory (either on disk or in the virtual file system).
A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...
Cached information about one file (either on disk or in the virtual file system).
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
One of these records is kept for each identifier that is lexed.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
A mechanism to observe the actions of the module map parser as it reads module map files.
virtual void moduleMapFileRead(SourceLocation FileStart, FileEntryRef File, bool IsSystem)
Called when a module map file has been read.
virtual ~ModuleMapCallbacks()=default
virtual void moduleMapAddHeader(StringRef Filename)
Called when a header is added during module map parsing.
virtual void moduleMapAddUmbrellaHeader(FileEntryRef Header)
Called when an umbrella header is added during module map parsing.
Module * createShadowedModule(StringRef Name, bool IsFramework, Module *ShadowingModule)
Create a new top-level module that is shadowed by ShadowingModule.
bool resolveExports(Module *Mod, bool Complain)
Resolve all of the unresolved exports in the given module.
void addLinkAsDependency(Module *Mod)
Make module to use export_as as the link dependency name if enough information is available or add it...
void dump()
Dump the contents of the module map, for debugging purposes.
std::pair< Module *, bool > findOrCreateModule(StringRef Name, Module *Parent, bool IsFramework, bool IsExplicit)
Find a new module or submodule, or create it if it does not already exist.
llvm::StringMap< Module * >::const_iterator module_iterator
void setUmbrellaDirAsWritten(Module *Mod, DirectoryEntryRef UmbrellaDir, const Twine &NameAsWritten, const Twine &PathRelativeToRootModuleDirectory)
Sets the umbrella directory of the given module to the given directory.
void diagnoseHeaderInclusion(Module *RequestingModule, bool RequestingModuleIsModuleInterface, SourceLocation FilenameLoc, StringRef Filename, FileEntryRef File)
Reports errors if a module must not include a specific file.
void addAdditionalModuleMapFile(const Module *M, FileEntryRef ModuleMap)
OptionalFileEntryRef getContainingModuleMapFile(const Module *Module) const
static Module::HeaderKind headerRoleToKind(ModuleHeaderRole Role)
Convert a header role to a kind.
Module * findModule(StringRef Name) const
Retrieve a module with the given name.
void finishModuleDeclarationScope()
Creates a new declaration scope for module names, allowing previously defined modules to shadow defin...
bool canInferFrameworkModule(const DirectoryEntry *Dir) const
Check whether a framework module can be inferred in the given directory.
bool mayShadowNewModule(Module *ExistingModule)
KnownHeader findModuleForHeader(FileEntryRef File, bool AllowTextual=false, bool AllowExcluded=false)
Retrieve the module that owns the given header file, if any.
Module * createHeaderUnit(SourceLocation Loc, StringRef Name, Module::Header H)
Create a C++20 header unit.
void addModuleMapCallbacks(std::unique_ptr< ModuleMapCallbacks > Callback)
Add a module map callback.
void setBuiltinIncludeDir(DirectoryEntryRef Dir)
Set the directory that contains Clang-supplied include files, such as our stdarg.h or tgmath....
static bool isModular(ModuleHeaderRole Role)
Check if the header with the given role is a modular one.
bool resolveConflicts(Module *Mod, bool Complain)
Resolve all of the unresolved conflicts in the given module.
bool isHeaderUnavailableInModule(FileEntryRef Header, const Module *RequestingModule) const
Determine whether the given header is unavailable as part of the specified module.
void resolveHeaderDirectives(const FileEntry *File) const
Resolve all lazy header directives for the specified file.
module_iterator module_begin() const
ArrayRef< KnownHeader > findResolvedModulesForHeader(FileEntryRef File) const
Like findAllModulesForHeader, but do not attempt to infer module ownership from umbrella headers if w...
OptionalFileEntryRef getModuleMapFileForUniquing(const Module *M) const
bool shouldImportRelativeToBuiltinIncludeDir(StringRef FileName, Module *Module) const
Module * createModuleForImplementationUnit(SourceLocation Loc, StringRef Name)
Create a new module for a C++ module implementation unit.
ModuleMap(SourceManager &SourceMgr, DiagnosticsEngine &Diags, const LangOptions &LangOpts, const TargetInfo *Target, HeaderSearch &HeaderInfo)
Construct a new module map.
std::optional< Module * > getCachedModuleLoad(const IdentifierInfo &II)
Return a cached module load.
std::error_code canonicalizeModuleMapPath(SmallVectorImpl< char > &Path)
Canonicalize Path in a manner suitable for a module map file.
FileID getModuleMapFileIDForUniquing(const Module *M) const
Get the module map file that (along with the module name) uniquely identifies this module.
void setInferredModuleAllowedBy(Module *M, FileID ModMapFID)
void setUmbrellaHeaderAsWritten(Module *Mod, FileEntryRef UmbrellaHeader, const Twine &NameAsWritten, const Twine &PathRelativeToRootModuleDirectory)
Sets the umbrella header of the given module to the given header.
llvm::DenseSet< FileEntryRef > AdditionalModMapsSet
Module * findOrCreateModuleFirst(StringRef Name, Module *Parent, bool IsFramework, bool IsExplicit)
Call ModuleMap::findOrCreateModule and throw away the information whether the module was found or cre...
Module * lookupModuleUnqualified(StringRef Name, Module *Context) const
Retrieve a module with the given name using lexical name lookup, starting at the given context.
bool isBuiltinHeader(FileEntryRef File)
Is this a compiler builtin header?
Module * createModule(StringRef Name, Module *Parent, bool IsFramework, bool IsExplicit)
Create new submodule, assuming it does not exist.
module_iterator module_end() const
AdditionalModMapsSet * getAdditionalModuleMapFiles(const Module *M)
Get any module map files other than getModuleMapFileForUniquing(M) that define submodules of a top-le...
bool isHeaderInUnavailableModule(FileEntryRef Header) const
Determine whether the given header is part of a module marked 'unavailable'.
FileID getContainingModuleMapFileID(const Module *Module) const
Retrieve the module map file containing the definition of the given module.
OptionalDirectoryEntryRef getBuiltinDir() const
Get the directory that contains Clang-supplied include files.
bool parseModuleMapFile(FileEntryRef File, bool IsSystem, DirectoryEntryRef HomeDir, FileID ID=FileID(), unsigned *Offset=nullptr, SourceLocation ExternModuleLoc=SourceLocation())
Parse the given module map file, and record any modules we encounter.
~ModuleMap()
Destroy the module map.
Module * createGlobalModuleFragmentForModuleUnit(SourceLocation Loc, Module *Parent=nullptr)
Create a global module fragment for a C++ module unit.
void setTarget(const TargetInfo &Target)
Set the target information.
Module * lookupModuleQualified(StringRef Name, Module *Context) const
Retrieve a module with the given name within the given context, using direct (qualified) name lookup.
void resolveLinkAsDependencies(Module *Mod)
Use PendingLinkAsModule information to mark top level link names that are going to be replaced by exp...
void cacheModuleLoad(const IdentifierInfo &II, Module *M)
Cache a module load. M might be nullptr.
ModuleHeaderRole
Flags describing the role of a module header.
@ PrivateHeader
This header is included but private.
@ ExcludedHeader
This header is explicitly excluded from the module.
@ NormalHeader
This header is normally included in the module.
@ TextualHeader
This header is part of the module (for layering purposes) but should be textually included.
Module * createModuleForInterfaceUnit(SourceLocation Loc, StringRef Name)
Create a new module for a C++ module interface unit.
void addHeader(Module *Mod, Module::Header Header, ModuleHeaderRole Role, bool Imported=false)
Adds this header to the given module.
Module * createPrivateModuleFragmentForInterfaceUnit(Module *Parent, SourceLocation Loc)
Create a global module fragment for a C++ module interface unit.
Module * findOrInferSubmodule(Module *Parent, StringRef Name)
ArrayRef< KnownHeader > findAllModulesForHeader(FileEntryRef File)
Retrieve all the modules that contain the given header file.
Module * createImplicitGlobalModuleFragmentForModuleUnit(SourceLocation Loc, Module *Parent)
Module * createModuleUnitWithKind(SourceLocation Loc, StringRef Name, Module::ModuleKind Kind)
Create a new C++ module with the specified kind, and reparent any pending global module fragment(s) t...
static ModuleHeaderRole headerKindToRole(Module::HeaderKind Kind)
Convert a header kind to a role. Requires Kind to not be HK_Excluded.
llvm::iterator_range< module_iterator > modules() const
bool resolveUses(Module *Mod, bool Complain)
Resolve all of the unresolved uses in the given module.
Describes a module or submodule.
Module * Parent
The parent of this module.
bool isAvailable() const
Determine whether this module is available for use within the current translation unit.
llvm::PointerIntPair< Module *, 1, bool > ExportDecl
Describes an exported module.
Module * getTopLevelModule()
Retrieve the top-level module for this (sub)module, which may be this module.
Encodes a location in the source.
This class handles loading and caching of source files into memory.
Exposes information about the current target.
The JSON file list parser is used to communicate input to InstallAPI.
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
CustomizableOptional< FileEntryRef > OptionalFileEntryRef
SmallVector< std::pair< std::string, SourceLocation >, 2 > ModuleId
Describes the name of a module.