clang 23.0.0git
ASTReader.h
Go to the documentation of this file.
1//===- ASTReader.h - AST File Reader ----------------------------*- C++ -*-===//
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 ASTReader class, which reads AST files.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_SERIALIZATION_ASTREADER_H
14#define LLVM_CLANG_SERIALIZATION_ASTREADER_H
15
16#include "clang/AST/Type.h"
23#include "clang/Basic/Version.h"
30#include "clang/Sema/Sema.h"
37#include "llvm/ADT/ArrayRef.h"
38#include "llvm/ADT/DenseMap.h"
39#include "llvm/ADT/DenseSet.h"
40#include "llvm/ADT/IntrusiveRefCntPtr.h"
41#include "llvm/ADT/MapVector.h"
42#include "llvm/ADT/PagedVector.h"
43#include "llvm/ADT/STLExtras.h"
44#include "llvm/ADT/SetVector.h"
45#include "llvm/ADT/SmallPtrSet.h"
46#include "llvm/ADT/SmallVector.h"
47#include "llvm/ADT/StringMap.h"
48#include "llvm/ADT/StringRef.h"
49#include "llvm/ADT/iterator.h"
50#include "llvm/ADT/iterator_range.h"
51#include "llvm/Bitstream/BitstreamReader.h"
52#include "llvm/Support/MemoryBuffer.h"
53#include "llvm/Support/SaveAndRestore.h"
54#include "llvm/Support/Timer.h"
55#include "llvm/Support/VersionTuple.h"
56#include <cassert>
57#include <cstddef>
58#include <cstdint>
59#include <ctime>
60#include <deque>
61#include <memory>
62#include <optional>
63#include <set>
64#include <string>
65#include <utility>
66#include <vector>
67
68namespace clang {
69
70class ASTConsumer;
71class ASTContext;
73class ASTReader;
74class ASTRecordReader;
75class CodeGenOptions;
76class CXXTemporary;
77class Decl;
78class DeclarationName;
79class DeclaratorDecl;
80class DeclContext;
81class EnumDecl;
82class Expr;
83class FieldDecl;
84class FileEntry;
85class FileManager;
87class FunctionDecl;
89struct HeaderFileInfo;
91class LangOptions;
92class MacroInfo;
93class ModuleCache;
94class NamedDecl;
95class NamespaceDecl;
99class Preprocessor;
101class Sema;
102class SourceManager;
103class Stmt;
104class SwitchCase;
105class TargetOptions;
106class Token;
107class TypedefNameDecl;
108class ValueDecl;
109class VarDecl;
110
111/// Abstract interface for callback invocations by the ASTReader.
112///
113/// While reading an AST file, the ASTReader will call the methods of the
114/// listener to pass on specific information. Some of the listener methods can
115/// return true to indicate to the ASTReader that the information (and
116/// consequently the AST file) is invalid.
118public:
120
121 /// Receives the full Clang version information.
122 ///
123 /// \returns true to indicate that the version is invalid. Subclasses should
124 /// generally defer to this implementation.
125 virtual bool ReadFullVersionInformation(StringRef FullVersion) {
126 return FullVersion != getClangFullRepositoryVersion();
127 }
128
129 virtual void ReadModuleName(StringRef ModuleName) {}
130 virtual void ReadModuleMapFile(StringRef ModuleMapPath) {}
131
132 /// Receives the language options.
133 ///
134 /// \returns true to indicate the options are invalid or false otherwise.
135 virtual bool ReadLanguageOptions(const LangOptions &LangOpts,
136 StringRef ModuleFilename, bool Complain,
137 bool AllowCompatibleDifferences) {
138 return false;
139 }
140
141 /// Receives the codegen options.
142 ///
143 /// \returns true to indicate the options are invalid or false otherwise.
144 virtual bool ReadCodeGenOptions(const CodeGenOptions &CGOpts,
145 StringRef ModuleFilename, bool Complain,
146 bool AllowCompatibleDifferences) {
147 return false;
148 }
149
150 /// Receives the target options.
151 ///
152 /// \returns true to indicate the target options are invalid, or false
153 /// otherwise.
154 virtual bool ReadTargetOptions(const TargetOptions &TargetOpts,
155 StringRef ModuleFilename, bool Complain,
156 bool AllowCompatibleDifferences) {
157 return false;
158 }
159
160 /// Receives the diagnostic options.
161 ///
162 /// \returns true to indicate the diagnostic options are invalid, or false
163 /// otherwise.
165 StringRef ModuleFilename, bool Complain) {
166 return false;
167 }
168
169 /// Receives the file system options.
170 ///
171 /// \returns true to indicate the file system options are invalid, or false
172 /// otherwise.
173 virtual bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
174 bool Complain) {
175 return false;
176 }
177
178 /// Receives the header search options.
179 ///
180 /// \param HSOpts The read header search options. The following fields are
181 /// missing and are reported in ReadHeaderSearchPaths():
182 /// UserEntries, SystemHeaderPrefixes, VFSOverlayFiles.
183 ///
184 /// \returns true to indicate the header search options are invalid, or false
185 /// otherwise.
187 StringRef ModuleFilename,
188 StringRef SpecificModuleCachePath,
189 bool Complain) {
190 return false;
191 }
192
193 /// Receives the header search paths.
194 ///
195 /// \param HSOpts The read header search paths. Only the following fields are
196 /// initialized: UserEntries, SystemHeaderPrefixes,
197 /// VFSOverlayFiles. The rest is reported in
198 /// ReadHeaderSearchOptions().
199 ///
200 /// \returns true to indicate the header search paths are invalid, or false
201 /// otherwise.
202 virtual bool ReadHeaderSearchPaths(const HeaderSearchOptions &HSOpts,
203 bool Complain) {
204 return false;
205 }
206
207 /// Receives the preprocessor options.
208 ///
209 /// \param SuggestedPredefines Can be filled in with the set of predefines
210 /// that are suggested by the preprocessor options. Typically only used when
211 /// loading a precompiled header.
212 ///
213 /// \returns true to indicate the preprocessor options are invalid, or false
214 /// otherwise.
216 StringRef ModuleFilename,
217 bool ReadMacros, bool Complain,
218 std::string &SuggestedPredefines) {
219 return false;
220 }
221
222 /// Receives __COUNTER__ value.
223 virtual void ReadCounter(const serialization::ModuleFile &M, uint32_t Value) {
224 }
225
226 /// This is called for each AST file loaded.
227 virtual void visitModuleFile(StringRef Filename,
229
230 /// Returns true if this \c ASTReaderListener wants to receive the
231 /// input files of the AST file via \c visitInputFile, false otherwise.
232 virtual bool needsInputFileVisitation() { return false; }
233
234 /// Returns true if this \c ASTReaderListener wants to receive the
235 /// system input files of the AST file via \c visitInputFile, false otherwise.
236 virtual bool needsSystemInputFileVisitation() { return false; }
237
238 /// if \c needsInputFileVisitation returns true, this is called for
239 /// each non-system input file of the AST File. If
240 /// \c needsSystemInputFileVisitation is true, then it is called for all
241 /// system input files as well.
242 ///
243 /// \returns true to continue receiving the next input file, false to stop.
244 virtual bool visitInputFile(StringRef Filename, bool isSystem,
245 bool isOverridden, bool isExplicitModule) {
246 return true;
247 }
248
249 /// Similiar to member function of \c visitInputFile but should
250 /// be defined when there is a distinction between the file name
251 /// and the name-as-requested. For example, when deserializing input
252 /// files from precompiled AST files.
253 ///
254 /// \returns true to continue receiving the next input file, false to stop.
255 virtual bool visitInputFileAsRequested(StringRef FilenameAsRequested,
256 StringRef Filename, bool isSystem,
257 bool isOverridden, time_t StoredTime,
258 bool isExplicitModule) {
259 return true;
260 }
261
262 /// Returns true if this \c ASTReaderListener wants to receive the
263 /// imports of the AST file via \c visitImport, false otherwise.
264 virtual bool needsImportVisitation() const { return false; }
265
266 /// If needsImportVisitation returns \c true, this is called for each
267 /// AST file imported by this AST file.
268 virtual void visitImport(StringRef ModuleName, StringRef Filename) {}
269
270 /// Indicates that a particular module file extension has been read.
272 const ModuleFileExtensionMetadata &Metadata) {}
273};
274
275/// Simple wrapper class for chaining listeners.
277 std::unique_ptr<ASTReaderListener> First;
278 std::unique_ptr<ASTReaderListener> Second;
279
280public:
281 /// Takes ownership of \p First and \p Second.
282 ChainedASTReaderListener(std::unique_ptr<ASTReaderListener> First,
283 std::unique_ptr<ASTReaderListener> Second)
284 : First(std::move(First)), Second(std::move(Second)) {}
285
286 std::unique_ptr<ASTReaderListener> takeFirst() { return std::move(First); }
287 std::unique_ptr<ASTReaderListener> takeSecond() { return std::move(Second); }
288
289 bool ReadFullVersionInformation(StringRef FullVersion) override;
290 void ReadModuleName(StringRef ModuleName) override;
291 void ReadModuleMapFile(StringRef ModuleMapPath) override;
292 bool ReadLanguageOptions(const LangOptions &LangOpts,
293 StringRef ModuleFilename, bool Complain,
294 bool AllowCompatibleDifferences) override;
295 bool ReadCodeGenOptions(const CodeGenOptions &CGOpts,
296 StringRef ModuleFilename, bool Complain,
297 bool AllowCompatibleDifferences) override;
298 bool ReadTargetOptions(const TargetOptions &TargetOpts,
299 StringRef ModuleFilename, bool Complain,
300 bool AllowCompatibleDifferences) override;
302 StringRef ModuleFilename, bool Complain) override;
303 bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
304 bool Complain) override;
305
307 StringRef ModuleFilename,
308 StringRef SpecificModuleCachePath,
309 bool Complain) override;
311 StringRef ModuleFilename, bool ReadMacros,
312 bool Complain,
313 std::string &SuggestedPredefines) override;
314
315 void ReadCounter(const serialization::ModuleFile &M, uint32_t Value) override;
316 bool needsInputFileVisitation() override;
317 bool needsSystemInputFileVisitation() override;
318 void visitModuleFile(StringRef Filename,
319 serialization::ModuleKind Kind) override;
320 bool visitInputFile(StringRef Filename, bool isSystem,
321 bool isOverridden, bool isExplicitModule) override;
323 const ModuleFileExtensionMetadata &Metadata) override;
324};
325
326/// ASTReaderListener implementation to validate the information of
327/// the PCH file against an initialized Preprocessor.
329 Preprocessor &PP;
330 ASTReader &Reader;
331
332public:
334 : PP(PP), Reader(Reader) {}
335
336 bool ReadLanguageOptions(const LangOptions &LangOpts,
337 StringRef ModuleFilename, bool Complain,
338 bool AllowCompatibleDifferences) override;
339 bool ReadCodeGenOptions(const CodeGenOptions &CGOpts,
340 StringRef ModuleFilename, bool Complain,
341 bool AllowCompatibleDifferences) override;
342 bool ReadTargetOptions(const TargetOptions &TargetOpts,
343 StringRef ModuleFilename, bool Complain,
344 bool AllowCompatibleDifferences) override;
346 StringRef ModuleFilename, bool Complain) override;
348 StringRef ModuleFilename, bool ReadMacros,
349 bool Complain,
350 std::string &SuggestedPredefines) override;
352 StringRef ModuleFilename,
353 StringRef SpecificModuleCachePath,
354 bool Complain) override;
355 void ReadCounter(const serialization::ModuleFile &M, uint32_t Value) override;
356};
357
358/// ASTReaderListenter implementation to set SuggestedPredefines of
359/// ASTReader which is required to use a pch file. This is the replacement
360/// of PCHValidator or SimplePCHValidator when using a pch file without
361/// validating it.
363 Preprocessor &PP;
364
365public:
367
369 StringRef ModuleFilename, bool ReadMacros,
370 bool Complain,
371 std::string &SuggestedPredefines) override;
372};
373
374namespace serialization {
375
376class ReadMethodPoolVisitor;
377
378namespace reader {
379
381
382/// The on-disk hash table(s) used for DeclContext name lookup.
385
386/// The on-disk hash table(s) used for specialization decls.
388
389} // namespace reader
390
391} // namespace serialization
392
394 uint64_t VisibleOffset = 0;
395 uint64_t ModuleLocalOffset = 0;
396 uint64_t TULocalOffset = 0;
397
398 operator bool() const {
400 }
401};
402
404 uint64_t LexicalOffset = 0;
405
406 operator bool() const {
407 return VisibleLookupBlockOffsets::operator bool() || LexicalOffset;
408 }
409};
410
411/// Reads an AST files chain containing the contents of a translation
412/// unit.
413///
414/// The ASTReader class reads bitstreams (produced by the ASTWriter
415/// class) containing the serialized representation of a given
416/// abstract syntax tree and its supporting data structures. An
417/// instance of the ASTReader can be attached to an ASTContext object,
418/// which will provide access to the contents of the AST files.
419///
420/// The AST reader provides lazy de-serialization of declarations, as
421/// required when traversing the AST. Only those AST nodes that are
422/// actually required will be de-serialized.
427 public ExternalSemaSource,
430{
431public:
432 /// Types of AST files.
433 friend class ASTDeclMerger;
434 friend class ASTDeclReader;
436 friend class ASTRecordReader;
437 friend class ASTUnit; // ASTUnit needs to remap source locations.
438 friend class ASTWriter;
439 friend class PCHValidator;
442 friend class TypeLocReader;
443 friend class LocalDeclID;
444
447
448 /// The result of reading the control block of an AST file, which
449 /// can fail for various reasons.
451 /// The control block was read successfully. Aside from failures,
452 /// the AST file is safe to read into the current context.
454
455 /// The AST file itself appears corrupted.
457
458 /// The AST file was missing.
460
461 /// The AST file is out-of-date relative to its input files,
462 /// and needs to be regenerated.
464
465 /// The AST file was written by a different version of Clang.
467
468 /// The AST file was written with a different language/target
469 /// configuration.
471
472 /// The AST file has errors.
474 };
475
482
483private:
484 /// The receiver of some callbacks invoked by ASTReader.
485 std::unique_ptr<ASTReaderListener> Listener;
486
487 /// The receiver of deserialization events.
488 ASTDeserializationListener *DeserializationListener = nullptr;
489
490 bool OwnsDeserializationListener = false;
491
492 SourceManager &SourceMgr;
493 FileManager &FileMgr;
494 const PCHContainerReader &PCHContainerRdr;
495 DiagnosticsEngine &Diags;
496 // Sema has duplicate logic, but SemaObj can sometimes be null so ASTReader
497 // has its own version.
498 StackExhaustionHandler StackHandler;
499
500 /// The semantic analysis object that will be processing the
501 /// AST files and the translation unit that uses it.
502 Sema *SemaObj = nullptr;
503
504 /// The preprocessor that will be loading the source file.
505 Preprocessor &PP;
506
507 /// The AST context into which we'll read the AST files.
508 ASTContext *ContextObj = nullptr;
509
510 /// The AST consumer.
511 ASTConsumer *Consumer = nullptr;
512
513 /// The codegen options.
514 const CodeGenOptions &CodeGenOpts;
515
516 /// The module manager which manages modules and their dependencies
517 ModuleManager ModuleMgr;
518
519 /// A dummy identifier resolver used to merge TU-scope declarations in
520 /// C, for the cases where we don't have a Sema object to provide a real
521 /// identifier resolver.
522 IdentifierResolver DummyIdResolver;
523
524 /// A mapping from extension block names to module file extensions.
525 llvm::StringMap<std::shared_ptr<ModuleFileExtension>> ModuleFileExtensions;
526
527 /// A timer used to track the time spent deserializing.
528 std::unique_ptr<llvm::Timer> ReadTimer;
529
530 // A TimeRegion used to start and stop ReadTimer via RAII.
531 std::optional<llvm::TimeRegion> ReadTimeRegion;
532
533 /// The location where the module file will be considered as
534 /// imported from. For non-module AST types it should be invalid.
535 SourceLocation CurrentImportLoc;
536
537 /// The module kind that is currently deserializing.
538 std::optional<ModuleKind> CurrentDeserializingModuleKind;
539
540 /// The global module index, if loaded.
541 std::unique_ptr<GlobalModuleIndex> GlobalIndex;
542
543 /// A map of global bit offsets to the module that stores entities
544 /// at those bit offsets.
546
547 /// A map of negated SLocEntryIDs to the modules containing them.
549
550 using GlobalSLocOffsetMapType =
552
553 /// A map of reversed (SourceManager::MaxLoadedOffset - SLocOffset)
554 /// SourceLocation offsets to the modules containing them.
555 GlobalSLocOffsetMapType GlobalSLocOffsetMap;
556
557 /// Types that have already been loaded from the chain.
558 ///
559 /// When the pointer at index I is non-NULL, the type with
560 /// ID = (I + 1) << FastQual::Width has already been loaded
561 llvm::PagedVector<QualType> TypesLoaded;
562
563 /// Declarations that have already been loaded from the chain.
564 ///
565 /// When the pointer at index I is non-NULL, the declaration with ID
566 /// = I + 1 has already been loaded.
567 llvm::PagedVector<Decl *> DeclsLoaded;
568
569 using FileOffset = std::pair<ModuleFile *, uint64_t>;
570 using FileOffsetsTy = SmallVector<FileOffset, 2>;
571 using DeclUpdateOffsetsMap = llvm::DenseMap<GlobalDeclID, FileOffsetsTy>;
572
573 /// Declarations that have modifications residing in a later file
574 /// in the chain.
575 DeclUpdateOffsetsMap DeclUpdateOffsets;
576
577 using DelayedNamespaceOffsetMapTy =
578 llvm::DenseMap<GlobalDeclID, LookupBlockOffsets>;
579
580 /// Mapping from global declaration IDs to the lexical and visible block
581 /// offset for delayed namespace in reduced BMI.
582 ///
583 /// We can't use the existing DeclUpdate mechanism since the DeclUpdate
584 /// may only be applied in an outer most read. However, we need to know
585 /// whether or not a DeclContext has external storage during the recursive
586 /// reading. So we need to apply the offset immediately after we read the
587 /// namespace as if it is not delayed.
588 DelayedNamespaceOffsetMapTy DelayedNamespaceOffsetMap;
589
590 /// Mapping from main decl ID to the related decls IDs.
591 ///
592 /// The key is the main decl ID, and the value is a vector of related decls
593 /// that must be loaded immediately after the main decl. This is necessary
594 /// to ensure that the definition for related decls comes from the same module
595 /// as the enclosing main decl. Without this, due to lazy deserialization,
596 /// the definition for the main decl and related decls may come from different
597 /// modules. It is used for the following cases:
598 /// - Lambda inside a template function definition: The main declaration is
599 /// the enclosing function, and the related declarations are the lambda
600 /// call operators.
601 /// - Friend function defined inside a template CXXRecord declaration: The
602 /// main declaration is the enclosing record, and the related declarations
603 /// are the friend functions.
604 llvm::DenseMap<GlobalDeclID, SmallVector<GlobalDeclID, 4>> RelatedDeclsMap;
605
606 struct PendingUpdateRecord {
607 Decl *D;
608 GlobalDeclID ID;
609
610 // Whether the declaration was just deserialized.
611 bool JustLoaded;
612
613 PendingUpdateRecord(GlobalDeclID ID, Decl *D, bool JustLoaded)
614 : D(D), ID(ID), JustLoaded(JustLoaded) {}
615 };
616
617 /// Declaration updates for already-loaded declarations that we need
618 /// to apply once we finish processing an import.
620
621 enum class PendingFakeDefinitionKind { NotFake, Fake, FakeLoaded };
622
623 /// The DefinitionData pointers that we faked up for class definitions
624 /// that we needed but hadn't loaded yet.
625 llvm::DenseMap<void *, PendingFakeDefinitionKind> PendingFakeDefinitionData;
626
627 /// Exception specification updates that have been loaded but not yet
628 /// propagated across the relevant redeclaration chain. The map key is the
629 /// canonical declaration (used only for deduplication) and the value is a
630 /// declaration that has an exception specification.
631 llvm::SmallMapVector<Decl *, FunctionDecl *, 4> PendingExceptionSpecUpdates;
632
633 /// Deduced return type updates that have been loaded but not yet propagated
634 /// across the relevant redeclaration chain. The map key is the canonical
635 /// declaration and the value is the deduced return type.
636 llvm::SmallMapVector<FunctionDecl *, QualType, 4> PendingDeducedTypeUpdates;
637
638 /// Functions has undededuced return type and we wish we can find the deduced
639 /// return type by iterating the redecls in other modules.
640 llvm::SmallVector<FunctionDecl *, 4> PendingUndeducedFunctionDecls;
641
642 /// Declarations that have been imported and have typedef names for
643 /// linkage purposes.
644 llvm::DenseMap<std::pair<DeclContext *, IdentifierInfo *>, NamedDecl *>
645 ImportedTypedefNamesForLinkage;
646
647 /// Mergeable declaration contexts that have anonymous declarations
648 /// within them, and those anonymous declarations.
649 llvm::DenseMap<Decl*, llvm::SmallVector<NamedDecl*, 2>>
650 AnonymousDeclarationsForMerging;
651
652 /// Map from numbering information for lambdas to the corresponding lambdas.
653 llvm::DenseMap<std::pair<const Decl *, unsigned>, NamedDecl *>
654 LambdaDeclarationsForMerging;
655
656 /// Key used to identify LifetimeExtendedTemporaryDecl for merging,
657 /// containing the lifetime-extending declaration and the mangling number.
658 using LETemporaryKey = std::pair<Decl *, unsigned>;
659
660 /// Map of already deserialiazed temporaries.
661 llvm::DenseMap<LETemporaryKey, LifetimeExtendedTemporaryDecl *>
662 LETemporaryForMerging;
663
664 struct FileDeclsInfo {
665 ModuleFile *Mod = nullptr;
667
668 FileDeclsInfo() = default;
669 FileDeclsInfo(ModuleFile *Mod,
671 : Mod(Mod), Decls(Decls) {}
672 };
673
674 /// Map from a FileID to the file-level declarations that it contains.
675 llvm::DenseMap<FileID, FileDeclsInfo> FileDeclIDs;
676
677 /// An array of lexical contents of a declaration context, as a sequence of
678 /// Decl::Kind, DeclID pairs.
679 using LexicalContents = ArrayRef<serialization::unaligned_decl_id_t>;
680
681 /// Map from a DeclContext to its lexical contents.
682 llvm::DenseMap<const DeclContext*, std::pair<ModuleFile*, LexicalContents>>
683 LexicalDecls;
684
685 /// Map from the TU to its lexical contents from each module file.
686 std::vector<std::pair<ModuleFile*, LexicalContents>> TULexicalDecls;
687
688 /// Map from a DeclContext to its lookup tables.
689 llvm::DenseMap<const DeclContext *,
690 serialization::reader::DeclContextLookupTable> Lookups;
691 llvm::DenseMap<const DeclContext *,
692 serialization::reader::ModuleLocalLookupTable>
693 ModuleLocalLookups;
694 llvm::DenseMap<const DeclContext *,
695 serialization::reader::DeclContextLookupTable>
696 TULocalLookups;
697
698 using SpecLookupTableTy =
699 llvm::DenseMap<const Decl *,
700 serialization::reader::LazySpecializationInfoLookupTable>;
701 /// Map from decls to specialized decls.
702 SpecLookupTableTy SpecializationsLookups;
703 /// Split partial specialization from specialization to speed up lookups.
704 SpecLookupTableTy PartialSpecializationsLookups;
705
706 bool LoadExternalSpecializationsImpl(SpecLookupTableTy &SpecLookups,
707 const Decl *D);
708 bool LoadExternalSpecializationsImpl(SpecLookupTableTy &SpecLookups,
709 const Decl *D,
710 ArrayRef<TemplateArgument> TemplateArgs);
711
712 // Updates for visible decls can occur for other contexts than just the
713 // TU, and when we read those update records, the actual context may not
714 // be available yet, so have this pending map using the ID as a key. It
715 // will be realized when the data is actually loaded.
716 struct UpdateData {
717 ModuleFile *Mod;
718 const unsigned char *Data;
719 };
720 using DeclContextVisibleUpdates = SmallVector<UpdateData, 1>;
721
722 /// Updates to the visible declarations of declaration contexts that
723 /// haven't been loaded yet.
724 llvm::DenseMap<GlobalDeclID, DeclContextVisibleUpdates> PendingVisibleUpdates;
725 llvm::DenseMap<GlobalDeclID, DeclContextVisibleUpdates>
726 PendingModuleLocalVisibleUpdates;
727 llvm::DenseMap<GlobalDeclID, DeclContextVisibleUpdates> TULocalUpdates;
728
729 using SpecializationsUpdate = SmallVector<UpdateData, 1>;
730 using SpecializationsUpdateMap =
731 llvm::DenseMap<GlobalDeclID, SpecializationsUpdate>;
732 SpecializationsUpdateMap PendingSpecializationsUpdates;
733 SpecializationsUpdateMap PendingPartialSpecializationsUpdates;
734
735 /// The set of C++ or Objective-C classes that have forward
736 /// declarations that have not yet been linked to their definitions.
737 llvm::SmallPtrSet<Decl *, 4> PendingDefinitions;
738
739 using PendingBodiesMap =
740 llvm::MapVector<Decl *, uint64_t,
741 llvm::SmallDenseMap<Decl *, unsigned, 4>,
742 SmallVector<std::pair<Decl *, uint64_t>, 4>>;
743
744 /// Functions or methods that have bodies that will be attached.
745 PendingBodiesMap PendingBodies;
746
747 /// Definitions for which we have added merged definitions but not yet
748 /// performed deduplication.
749 llvm::SetVector<NamedDecl *> PendingMergedDefinitionsToDeduplicate;
750
751 /// The duplicated definitions in module units which are pending to be warned.
752 /// We need to delay it to wait for the loading of definitions since we don't
753 /// want to warn for forward declarations.
754 llvm::SmallVector<std::pair<Decl *, Decl *>>
755 PendingWarningForDuplicatedDefsInModuleUnits;
756
757 /// Read the record that describes the lexical contents of a DC.
758 bool ReadLexicalDeclContextStorage(ModuleFile &M,
759 llvm::BitstreamCursor &Cursor,
760 uint64_t Offset, DeclContext *DC);
761
762 enum class VisibleDeclContextStorageKind {
763 GenerallyVisible,
764 ModuleLocalVisible,
765 TULocalVisible,
766 };
767
768 /// Read the record that describes the visible contents of a DC.
769 bool ReadVisibleDeclContextStorage(ModuleFile &M,
770 llvm::BitstreamCursor &Cursor,
771 uint64_t Offset, GlobalDeclID ID,
772 VisibleDeclContextStorageKind VisibleKind);
773
774 bool ReadSpecializations(ModuleFile &M, llvm::BitstreamCursor &Cursor,
775 uint64_t Offset, Decl *D, bool IsPartial);
776 void AddSpecializations(const Decl *D, const unsigned char *Data,
777 ModuleFile &M, bool IsPartial);
778
779 /// A vector containing identifiers that have already been
780 /// loaded.
781 ///
782 /// If the pointer at index I is non-NULL, then it refers to the
783 /// IdentifierInfo for the identifier with ID=I+1 that has already
784 /// been loaded.
785 std::vector<IdentifierInfo *> IdentifiersLoaded;
786
787 /// A vector containing macros that have already been
788 /// loaded.
789 ///
790 /// If the pointer at index I is non-NULL, then it refers to the
791 /// MacroInfo for the identifier with ID=I+1 that has already
792 /// been loaded.
793 std::vector<MacroInfo *> MacrosLoaded;
794
795 using LoadedMacroInfo =
796 std::pair<IdentifierInfo *, serialization::SubmoduleID>;
797
798 /// A set of #undef directives that we have loaded; used to
799 /// deduplicate the same #undef information coming from multiple module
800 /// files.
801 llvm::DenseSet<LoadedMacroInfo> LoadedUndefs;
802
803 /// A vector containing submodules that have already been loaded.
804 ///
805 /// This vector is indexed by the Submodule ID (-1). NULL submodule entries
806 /// indicate that the particular submodule ID has not yet been loaded.
807 SmallVector<Module *, 2> SubmodulesLoaded;
808
809 using GlobalSubmoduleMapType =
810 ContinuousRangeMap<serialization::SubmoduleID, ModuleFile *, 4>;
811
812 /// Mapping from global submodule IDs to the module file in which the
813 /// submodule resides along with the offset that should be added to the
814 /// global submodule ID to produce a local ID.
815 GlobalSubmoduleMapType GlobalSubmoduleMap;
816
817 /// A set of hidden declarations.
818 using HiddenNames = SmallVector<Decl *, 2>;
819 using HiddenNamesMapType = llvm::DenseMap<Module *, HiddenNames>;
820
821 /// A mapping from each of the hidden submodules to the deserialized
822 /// declarations in that submodule that could be made visible.
823 HiddenNamesMapType HiddenNamesMap;
824
825 /// A module import, export, or conflict that hasn't yet been resolved.
826 struct UnresolvedModuleRef {
827 /// The file in which this module resides.
828 ModuleFile *File;
829
830 /// The module that is importing or exporting.
831 Module *Mod;
832
833 /// The kind of module reference.
834 enum { Import, Export, Conflict, Affecting } Kind;
835
836 /// The local ID of the module that is being exported.
837 unsigned ID;
838
839 /// Whether this is a wildcard export.
840 LLVM_PREFERRED_TYPE(bool)
841 unsigned IsWildcard : 1;
842
843 /// String data.
844 StringRef String;
845 };
846
847 /// The set of module imports and exports that still need to be
848 /// resolved.
849 SmallVector<UnresolvedModuleRef, 2> UnresolvedModuleRefs;
850
851 /// A vector containing selectors that have already been loaded.
852 ///
853 /// This vector is indexed by the Selector ID (-1). NULL selector
854 /// entries indicate that the particular selector ID has not yet
855 /// been loaded.
856 SmallVector<Selector, 16> SelectorsLoaded;
857
858 using GlobalSelectorMapType =
859 ContinuousRangeMap<serialization::SelectorID, ModuleFile *, 4>;
860
861 /// Mapping from global selector IDs to the module in which the
862 /// global selector ID to produce a local ID.
863 GlobalSelectorMapType GlobalSelectorMap;
864
865 /// The generation number of the last time we loaded data from the
866 /// global method pool for this selector.
867 llvm::DenseMap<Selector, unsigned> SelectorGeneration;
868
869 /// Whether a selector is out of date. We mark a selector as out of date
870 /// if we load another module after the method pool entry was pulled in.
871 llvm::DenseMap<Selector, bool> SelectorOutOfDate;
872
873 struct PendingMacroInfo {
874 ModuleFile *M;
875 /// Offset relative to ModuleFile::MacroOffsetsBase.
876 uint32_t MacroDirectivesOffset;
877
878 PendingMacroInfo(ModuleFile *M, uint32_t MacroDirectivesOffset)
879 : M(M), MacroDirectivesOffset(MacroDirectivesOffset) {}
880 };
881
882 using PendingMacroIDsMap =
883 llvm::MapVector<IdentifierInfo *, SmallVector<PendingMacroInfo, 2>>;
884
885 /// Mapping from identifiers that have a macro history to the global
886 /// IDs have not yet been deserialized to the global IDs of those macros.
887 PendingMacroIDsMap PendingMacroIDs;
888
889 using GlobalPreprocessedEntityMapType =
890 ContinuousRangeMap<unsigned, ModuleFile *, 4>;
891
892 /// Mapping from global preprocessing entity IDs to the module in
893 /// which the preprocessed entity resides along with the offset that should be
894 /// added to the global preprocessing entity ID to produce a local ID.
895 GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap;
896
897 using GlobalSkippedRangeMapType =
898 ContinuousRangeMap<unsigned, ModuleFile *, 4>;
899
900 /// Mapping from global skipped range base IDs to the module in which
901 /// the skipped ranges reside.
902 GlobalSkippedRangeMapType GlobalSkippedRangeMap;
903
904 /// \name CodeGen-relevant special data
905 /// Fields containing data that is relevant to CodeGen.
906 //@{
907
908 /// The IDs of all declarations that fulfill the criteria of
909 /// "interesting" decls.
910 ///
911 /// This contains the data loaded from all EAGERLY_DESERIALIZED_DECLS blocks
912 /// in the chain. The referenced declarations are deserialized and passed to
913 /// the consumer eagerly.
914 SmallVector<GlobalDeclID, 16> EagerlyDeserializedDecls;
915
916 /// The IDs of all vtables to emit. The referenced declarations are passed
917 /// to the consumers' HandleVTable eagerly after passing
918 /// EagerlyDeserializedDecls.
919 SmallVector<GlobalDeclID, 16> VTablesToEmit;
920
921 /// The IDs of all tentative definitions stored in the chain.
922 ///
923 /// Sema keeps track of all tentative definitions in a TU because it has to
924 /// complete them and pass them on to CodeGen. Thus, tentative definitions in
925 /// the PCH chain must be eagerly deserialized.
926 SmallVector<GlobalDeclID, 16> TentativeDefinitions;
927
928 /// The IDs of all CXXRecordDecls stored in the chain whose VTables are
929 /// used.
930 ///
931 /// CodeGen has to emit VTables for these records, so they have to be eagerly
932 /// deserialized.
933 struct VTableUse {
934 GlobalDeclID ID;
936 bool Used;
937 };
938 SmallVector<VTableUse> VTableUses;
939
940 /// A snapshot of the pending instantiations in the chain.
941 ///
942 /// This record tracks the instantiations that Sema has to perform at the
943 /// end of the TU. It consists of a pair of values for every pending
944 /// instantiation where the first value is the ID of the decl and the second
945 /// is the instantiation location.
946 struct PendingInstantiation {
947 GlobalDeclID ID;
949 };
950 SmallVector<PendingInstantiation, 64> PendingInstantiations;
951
952 //@}
953
954 /// \name DiagnosticsEngine-relevant special data
955 /// Fields containing data that is used for generating diagnostics
956 //@{
957
958 /// A snapshot of Sema's unused file-scoped variable tracking, for
959 /// generating warnings.
960 SmallVector<GlobalDeclID, 16> UnusedFileScopedDecls;
961
962 /// A list of all the delegating constructors we've seen, to diagnose
963 /// cycles.
964 SmallVector<GlobalDeclID, 4> DelegatingCtorDecls;
965
966 /// Method selectors used in a @selector expression. Used for
967 /// implementation of -Wselector.
968 SmallVector<serialization::SelectorID, 64> ReferencedSelectorsData;
969
970 /// A snapshot of Sema's weak undeclared identifier tracking, for
971 /// generating warnings.
972 SmallVector<serialization::IdentifierID, 64> WeakUndeclaredIdentifiers;
973
974 /// The IDs of type aliases for ext_vectors that exist in the chain.
975 ///
976 /// Used by Sema for finding sugared names for ext_vectors in diagnostics.
977 SmallVector<GlobalDeclID, 4> ExtVectorDecls;
978
979 //@}
980
981 /// \name Sema-relevant special data
982 /// Fields containing data that is used for semantic analysis
983 //@{
984
985 /// The IDs of all potentially unused typedef names in the chain.
986 ///
987 /// Sema tracks these to emit warnings.
988 SmallVector<GlobalDeclID, 16> UnusedLocalTypedefNameCandidates;
989
990 /// Our current depth in #pragma cuda force_host_device begin/end
991 /// macros.
992 unsigned ForceHostDeviceDepth = 0;
993
994 /// The IDs of the declarations Sema stores directly.
995 ///
996 /// Sema tracks a few important decls, such as namespace std, directly.
997 SmallVector<GlobalDeclID, 4> SemaDeclRefs;
998
999 /// The IDs of the types ASTContext stores directly.
1000 ///
1001 /// The AST context tracks a few important types, such as va_list, directly.
1002 SmallVector<serialization::TypeID, 16> SpecialTypes;
1003
1004 /// The IDs of CUDA-specific declarations ASTContext stores directly.
1005 ///
1006 /// The AST context tracks a few important decls, currently cudaConfigureCall,
1007 /// directly.
1008 SmallVector<GlobalDeclID, 4> CUDASpecialDeclRefs;
1009
1010 /// The floating point pragma option settings.
1011 SmallVector<uint64_t, 1> FPPragmaOptions;
1012
1013 /// The pragma clang optimize location (if the pragma state is "off").
1014 SourceLocation OptimizeOffPragmaLocation;
1015
1016 /// The PragmaMSStructKind pragma ms_struct state if set, or -1.
1017 int PragmaMSStructState = -1;
1018
1019 /// The PragmaMSPointersToMembersKind pragma pointers_to_members state.
1020 int PragmaMSPointersToMembersState = -1;
1021 SourceLocation PointersToMembersPragmaLocation;
1022
1023 /// The pragma float_control state.
1024 std::optional<FPOptionsOverride> FpPragmaCurrentValue;
1025 SourceLocation FpPragmaCurrentLocation;
1026 struct FpPragmaStackEntry {
1027 FPOptionsOverride Value;
1028 SourceLocation Location;
1029 SourceLocation PushLocation;
1030 StringRef SlotLabel;
1031 };
1032 llvm::SmallVector<FpPragmaStackEntry, 2> FpPragmaStack;
1033 llvm::SmallVector<std::string, 2> FpPragmaStrings;
1034
1035 /// The pragma align/pack state.
1036 std::optional<Sema::AlignPackInfo> PragmaAlignPackCurrentValue;
1037 SourceLocation PragmaAlignPackCurrentLocation;
1038 struct PragmaAlignPackStackEntry {
1039 Sema::AlignPackInfo Value;
1040 SourceLocation Location;
1041 SourceLocation PushLocation;
1042 StringRef SlotLabel;
1043 };
1044 llvm::SmallVector<PragmaAlignPackStackEntry, 2> PragmaAlignPackStack;
1045 llvm::SmallVector<std::string, 2> PragmaAlignPackStrings;
1046
1047 /// The OpenCL extension settings.
1048 OpenCLOptions OpenCLExtensions;
1049
1050 /// Extensions required by an OpenCL type.
1051 llvm::DenseMap<const Type *, std::set<std::string>> OpenCLTypeExtMap;
1052
1053 /// Extensions required by an OpenCL declaration.
1054 llvm::DenseMap<const Decl *, std::set<std::string>> OpenCLDeclExtMap;
1055
1056 /// A list of the namespaces we've seen.
1057 SmallVector<GlobalDeclID, 4> KnownNamespaces;
1058
1059 /// A list of undefined decls with internal linkage followed by the
1060 /// SourceLocation of a matching ODR-use.
1061 struct UndefinedButUsedDecl {
1062 GlobalDeclID ID;
1064 };
1065 SmallVector<UndefinedButUsedDecl, 8> UndefinedButUsed;
1066
1067 /// Delete expressions to analyze at the end of translation unit.
1068 SmallVector<uint64_t, 8> DelayedDeleteExprs;
1069
1070 // A list of late parsed template function data with their module files.
1071 SmallVector<std::pair<ModuleFile *, SmallVector<uint64_t, 1>>, 4>
1072 LateParsedTemplates;
1073
1074 /// The IDs of all decls to be checked for deferred diags.
1075 ///
1076 /// Sema tracks these to emit deferred diags.
1077 llvm::SmallSetVector<GlobalDeclID, 4> DeclsToCheckForDeferredDiags;
1078
1079 /// The IDs of all decls with function effects to be checked.
1080 SmallVector<GlobalDeclID> DeclsWithEffectsToVerify;
1081
1082 /// The RISC-V intrinsic pragma(including RVV, SiFive and Andes).
1083 SmallVector<bool, 3> RISCVVecIntrinsicPragma;
1084
1085private:
1086 struct ImportedSubmodule {
1088 SourceLocation ImportLoc;
1089
1090 ImportedSubmodule(serialization::SubmoduleID ID, SourceLocation ImportLoc)
1091 : ID(ID), ImportLoc(ImportLoc) {}
1092 };
1093
1094 /// A list of modules that were imported by precompiled headers or
1095 /// any other non-module AST file and have not yet been made visible. If a
1096 /// module is made visible in the ASTReader, it will be transfered to
1097 /// \c PendingImportedModulesSema.
1098 SmallVector<ImportedSubmodule, 2> PendingImportedModules;
1099
1100 /// A list of modules that were imported by precompiled headers or
1101 /// any other non-module AST file and have not yet been made visible for Sema.
1102 SmallVector<ImportedSubmodule, 2> PendingImportedModulesSema;
1103 //@}
1104
1105 /// The system include root to be used when loading the
1106 /// precompiled header.
1107 std::string isysroot;
1108
1109 /// Whether to disable the normal validation performed on precompiled
1110 /// headers and module files when they are loaded.
1111 DisableValidationForModuleKind DisableValidationKind;
1112
1113 /// Whether to accept an AST file with compiler errors.
1114 bool AllowASTWithCompilerErrors;
1115
1116 /// Whether to accept an AST file that has a different configuration
1117 /// from the current compiler instance.
1118 bool AllowConfigurationMismatch;
1119
1120 /// Whether to validate system input files.
1121 bool ValidateSystemInputs;
1122
1123 /// Whether to force the validation of user input files.
1124 bool ForceValidateUserInputs;
1125
1126 /// Whether validate headers and module maps using hash based on contents.
1127 bool ValidateASTInputFilesContent;
1128
1129 /// Whether we are allowed to use the global module index.
1130 bool UseGlobalIndex;
1131
1132 /// Whether we have tried loading the global module index yet.
1133 bool TriedLoadingGlobalIndex = false;
1134
1135 ///Whether we are currently processing update records.
1136 bool ProcessingUpdateRecords = false;
1137
1138 using SwitchCaseMapTy = llvm::DenseMap<unsigned, SwitchCase *>;
1139
1140 /// Mapping from switch-case IDs in the chain to switch-case statements
1141 ///
1142 /// Statements usually don't have IDs, but switch cases need them, so that the
1143 /// switch statement can refer to them.
1144 SwitchCaseMapTy SwitchCaseStmts;
1145
1146 SwitchCaseMapTy *CurrSwitchCaseStmts;
1147
1148 /// The number of source location entries de-serialized from
1149 /// the PCH file.
1150 unsigned NumSLocEntriesRead = 0;
1151
1152 /// The number of source location entries in the chain.
1153 unsigned TotalNumSLocEntries = 0;
1154
1155 /// The number of statements (and expressions) de-serialized
1156 /// from the chain.
1157 unsigned NumStatementsRead = 0;
1158
1159 /// The total number of statements (and expressions) stored
1160 /// in the chain.
1161 unsigned TotalNumStatements = 0;
1162
1163 /// The number of macros de-serialized from the chain.
1164 unsigned NumMacrosRead = 0;
1165
1166 /// The total number of macros stored in the chain.
1167 unsigned TotalNumMacros = 0;
1168
1169 /// The number of lookups into identifier tables.
1170 unsigned NumIdentifierLookups = 0;
1171
1172 /// The number of lookups into identifier tables that succeed.
1173 unsigned NumIdentifierLookupHits = 0;
1174
1175 /// The number of selectors that have been read.
1176 unsigned NumSelectorsRead = 0;
1177
1178 /// The number of method pool entries that have been read.
1179 unsigned NumMethodPoolEntriesRead = 0;
1180
1181 /// The number of times we have looked up a selector in the method
1182 /// pool.
1183 unsigned NumMethodPoolLookups = 0;
1184
1185 /// The number of times we have looked up a selector in the method
1186 /// pool and found something.
1187 unsigned NumMethodPoolHits = 0;
1188
1189 /// The number of times we have looked up a selector in the method
1190 /// pool within a specific module.
1191 unsigned NumMethodPoolTableLookups = 0;
1192
1193 /// The number of times we have looked up a selector in the method
1194 /// pool within a specific module and found something.
1195 unsigned NumMethodPoolTableHits = 0;
1196
1197 /// The total number of method pool entries in the selector table.
1198 unsigned TotalNumMethodPoolEntries = 0;
1199
1200 /// Number of lexical decl contexts read/total.
1201 unsigned NumLexicalDeclContextsRead = 0, TotalLexicalDeclContexts = 0;
1202
1203 /// Number of visible decl contexts read/total.
1204 unsigned NumVisibleDeclContextsRead = 0, TotalVisibleDeclContexts = 0;
1205
1206 /// Number of module local visible decl contexts read/total.
1207 unsigned NumModuleLocalVisibleDeclContexts = 0,
1208 TotalModuleLocalVisibleDeclContexts = 0;
1209
1210 /// Number of TU Local decl contexts read/total
1211 unsigned NumTULocalVisibleDeclContexts = 0,
1212 TotalTULocalVisibleDeclContexts = 0;
1213
1214 /// Total size of modules, in bits, currently loaded
1215 uint64_t TotalModulesSizeInBits = 0;
1216
1217 /// Number of Decl/types that are currently deserializing.
1218 unsigned NumCurrentElementsDeserializing = 0;
1219
1220 /// Set false while we are in a state where we cannot safely pass deserialized
1221 /// "interesting" decls to the consumer inside FinishedDeserializing().
1222 /// This is used as a guard to avoid recursively entering the process of
1223 /// passing decls to consumer.
1224 bool CanPassDeclsToConsumer = true;
1225
1226 /// The set of identifiers that were read while the AST reader was
1227 /// (recursively) loading declarations.
1228 ///
1229 /// The declarations on the identifier chain for these identifiers will be
1230 /// loaded once the recursive loading has completed.
1231 llvm::MapVector<IdentifierInfo *, SmallVector<GlobalDeclID, 4>>
1232 PendingIdentifierInfos;
1233
1234 /// The set of lookup results that we have faked in order to support
1235 /// merging of partially deserialized decls but that we have not yet removed.
1236 llvm::SmallMapVector<const IdentifierInfo *, SmallVector<NamedDecl *, 2>, 16>
1237 PendingFakeLookupResults;
1238
1239 /// The generation number of each identifier, which keeps track of
1240 /// the last time we loaded information about this identifier.
1241 llvm::DenseMap<const IdentifierInfo *, unsigned> IdentifierGeneration;
1242
1243 /// Contains declarations and definitions that could be
1244 /// "interesting" to the ASTConsumer, when we get that AST consumer.
1245 ///
1246 /// "Interesting" declarations are those that have data that may
1247 /// need to be emitted, such as inline function definitions or
1248 /// Objective-C protocols.
1249 std::deque<Decl *> PotentiallyInterestingDecls;
1250
1251 /// The list of deduced function types that we have not yet read, because
1252 /// they might contain a deduced return type that refers to a local type
1253 /// declared within the function.
1254 SmallVector<std::pair<FunctionDecl *, serialization::TypeID>, 16>
1255 PendingDeducedFunctionTypes;
1256
1257 /// The list of deduced variable types that we have not yet read, because
1258 /// they might contain a deduced type that refers to a local type declared
1259 /// within the variable.
1260 SmallVector<std::pair<VarDecl *, serialization::TypeID>, 16>
1261 PendingDeducedVarTypes;
1262
1263 /// The list of redeclaration chains that still need to be
1264 /// reconstructed, and the local offset to the corresponding list
1265 /// of redeclarations.
1266 SmallVector<std::pair<Decl *, uint64_t>, 16> PendingDeclChains;
1267
1268 /// The list of canonical declarations whose redeclaration chains
1269 /// need to be marked as incomplete once we're done deserializing things.
1270 SmallVector<Decl *, 16> PendingIncompleteDeclChains;
1271
1272 /// The Decl IDs for the Sema/Lexical DeclContext of a Decl that has
1273 /// been loaded but its DeclContext was not set yet.
1274 struct PendingDeclContextInfo {
1275 Decl *D;
1276 GlobalDeclID SemaDC;
1277 GlobalDeclID LexicalDC;
1278 };
1279
1280 /// The set of Decls that have been loaded but their DeclContexts are
1281 /// not set yet.
1282 ///
1283 /// The DeclContexts for these Decls will be set once recursive loading has
1284 /// been completed.
1285 std::deque<PendingDeclContextInfo> PendingDeclContextInfos;
1286
1287 template <typename DeclTy>
1288 using DuplicateObjCDecls = std::pair<DeclTy *, DeclTy *>;
1289
1290 /// When resolving duplicate ivars from Objective-C extensions we don't error
1291 /// out immediately but check if can merge identical extensions. Not checking
1292 /// extensions for equality immediately because ivar deserialization isn't
1293 /// over yet at that point.
1294 llvm::SmallMapVector<DuplicateObjCDecls<ObjCCategoryDecl>,
1295 llvm::SmallVector<DuplicateObjCDecls<ObjCIvarDecl>, 4>,
1296 2>
1297 PendingObjCExtensionIvarRedeclarations;
1298
1299 /// Members that have been added to classes, for which the class has not yet
1300 /// been notified. CXXRecordDecl::addedMember will be called for each of
1301 /// these once recursive deserialization is complete.
1302 SmallVector<std::pair<CXXRecordDecl*, Decl*>, 4> PendingAddedClassMembers;
1303
1304 /// The set of NamedDecls that have been loaded, but are members of a
1305 /// context that has been merged into another context where the corresponding
1306 /// declaration is either missing or has not yet been loaded.
1307 ///
1308 /// We will check whether the corresponding declaration is in fact missing
1309 /// once recursing loading has been completed.
1310 llvm::SmallVector<NamedDecl *, 16> PendingOdrMergeChecks;
1311
1312 using DataPointers =
1313 std::pair<CXXRecordDecl *, struct CXXRecordDecl::DefinitionData *>;
1314 using ObjCInterfaceDataPointers =
1315 std::pair<ObjCInterfaceDecl *,
1316 struct ObjCInterfaceDecl::DefinitionData *>;
1317 using ObjCProtocolDataPointers =
1318 std::pair<ObjCProtocolDecl *, struct ObjCProtocolDecl::DefinitionData *>;
1319
1320 /// Record definitions in which we found an ODR violation.
1321 llvm::SmallDenseMap<CXXRecordDecl *, llvm::SmallVector<DataPointers, 2>, 2>
1322 PendingOdrMergeFailures;
1323
1324 /// C/ObjC record definitions in which we found an ODR violation.
1325 llvm::SmallDenseMap<RecordDecl *, llvm::SmallVector<RecordDecl *, 2>, 2>
1326 PendingRecordOdrMergeFailures;
1327
1328 /// Function definitions in which we found an ODR violation.
1329 llvm::SmallDenseMap<FunctionDecl *, llvm::SmallVector<FunctionDecl *, 2>, 2>
1330 PendingFunctionOdrMergeFailures;
1331
1332 /// Enum definitions in which we found an ODR violation.
1333 llvm::SmallDenseMap<EnumDecl *, llvm::SmallVector<EnumDecl *, 2>, 2>
1334 PendingEnumOdrMergeFailures;
1335
1336 /// ObjCInterfaceDecl in which we found an ODR violation.
1337 llvm::SmallDenseMap<ObjCInterfaceDecl *,
1338 llvm::SmallVector<ObjCInterfaceDataPointers, 2>, 2>
1339 PendingObjCInterfaceOdrMergeFailures;
1340
1341 /// ObjCProtocolDecl in which we found an ODR violation.
1342 llvm::SmallDenseMap<ObjCProtocolDecl *,
1343 llvm::SmallVector<ObjCProtocolDataPointers, 2>, 2>
1344 PendingObjCProtocolOdrMergeFailures;
1345
1346 /// DeclContexts in which we have diagnosed an ODR violation.
1347 llvm::SmallPtrSet<DeclContext*, 2> DiagnosedOdrMergeFailures;
1348
1349 /// The set of Objective-C categories that have been deserialized
1350 /// since the last time the declaration chains were linked.
1351 llvm::SmallPtrSet<ObjCCategoryDecl *, 16> CategoriesDeserialized;
1352
1353 /// The set of Objective-C class definitions that have already been
1354 /// loaded, for which we will need to check for categories whenever a new
1355 /// module is loaded.
1356 SmallVector<ObjCInterfaceDecl *, 16> ObjCClassesLoaded;
1357
1358 using KeyDeclsMap = llvm::DenseMap<Decl *, SmallVector<GlobalDeclID, 2>>;
1359
1360 /// A mapping from canonical declarations to the set of global
1361 /// declaration IDs for key declaration that have been merged with that
1362 /// canonical declaration. A key declaration is a formerly-canonical
1363 /// declaration whose module did not import any other key declaration for that
1364 /// entity. These are the IDs that we use as keys when finding redecl chains.
1365 KeyDeclsMap KeyDecls;
1366
1367 /// A mapping from DeclContexts to the semantic DeclContext that we
1368 /// are treating as the definition of the entity. This is used, for instance,
1369 /// when merging implicit instantiations of class templates across modules.
1370 llvm::DenseMap<DeclContext *, DeclContext *> MergedDeclContexts;
1371
1372 /// A mapping from canonical declarations of enums to their canonical
1373 /// definitions. Only populated when using modules in C++.
1374 llvm::DenseMap<EnumDecl *, EnumDecl *> EnumDefinitions;
1375
1376 /// A mapping from canonical declarations of records to their canonical
1377 /// definitions. Doesn't cover CXXRecordDecl.
1378 llvm::DenseMap<RecordDecl *, RecordDecl *> RecordDefinitions;
1379
1380 /// When reading a Stmt tree, Stmt operands are placed in this stack.
1381 SmallVector<Stmt *, 16> StmtStack;
1382
1383 /// What kind of records we are reading.
1384 enum ReadingKind {
1385 Read_None, Read_Decl, Read_Type, Read_Stmt
1386 };
1387
1388 /// What kind of records we are reading.
1389 ReadingKind ReadingKind = Read_None;
1390
1391 /// RAII object to change the reading kind.
1392 class ReadingKindTracker {
1393 ASTReader &Reader;
1394 enum ReadingKind PrevKind;
1395
1396 public:
1397 ReadingKindTracker(enum ReadingKind newKind, ASTReader &reader)
1398 : Reader(reader), PrevKind(Reader.ReadingKind) {
1399 Reader.ReadingKind = newKind;
1400 }
1401
1402 ReadingKindTracker(const ReadingKindTracker &) = delete;
1403 ReadingKindTracker &operator=(const ReadingKindTracker &) = delete;
1404 ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; }
1405 };
1406
1407 /// RAII object to mark the start of processing updates.
1408 class ProcessingUpdatesRAIIObj {
1409 ASTReader &Reader;
1410 bool PrevState;
1411
1412 public:
1413 ProcessingUpdatesRAIIObj(ASTReader &reader)
1414 : Reader(reader), PrevState(Reader.ProcessingUpdateRecords) {
1415 Reader.ProcessingUpdateRecords = true;
1416 }
1417
1418 ProcessingUpdatesRAIIObj(const ProcessingUpdatesRAIIObj &) = delete;
1419 ProcessingUpdatesRAIIObj &
1420 operator=(const ProcessingUpdatesRAIIObj &) = delete;
1421 ~ProcessingUpdatesRAIIObj() { Reader.ProcessingUpdateRecords = PrevState; }
1422 };
1423
1424 /// Suggested contents of the predefines buffer, after this
1425 /// PCH file has been processed.
1426 ///
1427 /// In most cases, this string will be empty, because the predefines
1428 /// buffer computed to build the PCH file will be identical to the
1429 /// predefines buffer computed from the command line. However, when
1430 /// there are differences that the PCH reader can work around, this
1431 /// predefines buffer may contain additional definitions.
1432 std::string SuggestedPredefines;
1433
1434 llvm::DenseMap<const Decl *, bool> DefinitionSource;
1435
1436 /// Friend functions that were defined but might have had their bodies
1437 /// removed.
1438 llvm::DenseSet<const FunctionDecl *> ThisDeclarationWasADefinitionSet;
1439
1440 bool shouldDisableValidationForFile(const serialization::ModuleFile &M) const;
1441
1442 /// Reads a statement from the specified cursor.
1443 Stmt *ReadStmtFromStream(ModuleFile &F);
1444
1445 /// Retrieve the stored information about an input file.
1446 serialization::InputFileInfo getInputFileInfo(ModuleFile &F, unsigned ID);
1447
1448 /// Retrieve the file entry and 'overridden' bit for an input
1449 /// file in the given module file.
1450 serialization::InputFile getInputFile(ModuleFile &F, unsigned ID,
1451 bool Complain = true);
1452
1453 /// The buffer used as the temporary backing storage for resolved paths.
1454 SmallString<0> PathBuf;
1455
1456 /// A wrapper around StringRef that temporarily borrows the underlying buffer.
1457 class TemporarilyOwnedStringRef {
1458 StringRef String;
1459 llvm::SaveAndRestore<SmallString<0>> UnderlyingBuffer;
1460
1461 public:
1462 TemporarilyOwnedStringRef(StringRef S, SmallString<0> &UnderlyingBuffer)
1463 : String(S), UnderlyingBuffer(UnderlyingBuffer, {}) {}
1464
1465 /// Return the wrapped \c StringRef that must be outlived by \c this.
1466 const StringRef *operator->() const & { return &String; }
1467 const StringRef &operator*() const & { return String; }
1468
1469 /// Make it harder to get a \c StringRef that outlives \c this.
1470 const StringRef *operator->() && = delete;
1471 const StringRef &operator*() && = delete;
1472 };
1473
1474public:
1475 /// Get the buffer for resolving paths.
1476 SmallString<0> &getPathBuf() { return PathBuf; }
1477
1478 /// Resolve \c Path in the context of module file \c M. The return value
1479 /// must go out of scope before the next call to \c ResolveImportedPath.
1480 static TemporarilyOwnedStringRef
1481 ResolveImportedPath(SmallString<0> &Buf, StringRef Path, ModuleFile &ModF);
1482 /// Resolve \c Path in the context of the \c Prefix directory. The return
1483 /// value must go out of scope before the next call to \c ResolveImportedPath.
1484 static TemporarilyOwnedStringRef
1485 ResolveImportedPath(SmallString<0> &Buf, StringRef Path, StringRef Prefix);
1486
1487 /// Resolve \c Path in the context of module file \c M.
1488 static std::string ResolveImportedPathAndAllocate(SmallString<0> &Buf,
1489 StringRef Path,
1490 ModuleFile &ModF);
1491 /// Resolve \c Path in the context of the \c Prefix directory.
1492 static std::string ResolveImportedPathAndAllocate(SmallString<0> &Buf,
1493 StringRef Path,
1494 StringRef Prefix);
1495
1496 /// Returns the first key declaration for the given declaration. This
1497 /// is one that is formerly-canonical (or still canonical) and whose module
1498 /// did not import any other key declaration of the entity.
1500 D = D->getCanonicalDecl();
1501 if (D->isFromASTFile())
1502 return D;
1503
1504 auto I = KeyDecls.find(D);
1505 if (I == KeyDecls.end() || I->second.empty())
1506 return D;
1507 return GetExistingDecl(I->second[0]);
1508 }
1509 const Decl *getKeyDeclaration(const Decl *D) {
1510 return getKeyDeclaration(const_cast<Decl*>(D));
1511 }
1512
1513 /// Run a callback on each imported key declaration of \p D.
1514 template <typename Fn>
1515 void forEachImportedKeyDecl(const Decl *D, Fn Visit) {
1516 D = D->getCanonicalDecl();
1517 if (D->isFromASTFile())
1518 Visit(D);
1519
1520 auto It = KeyDecls.find(const_cast<Decl*>(D));
1521 if (It != KeyDecls.end())
1522 for (auto ID : It->second)
1523 Visit(GetExistingDecl(ID));
1524 }
1525
1526 /// Get the loaded lookup tables for \p Primary, if any.
1528 getLoadedLookupTables(DeclContext *Primary) const;
1529
1532
1534 getTULocalLookupTables(DeclContext *Primary) const;
1535
1536 /// Get the loaded specializations lookup tables for \p D,
1537 /// if any.
1539 getLoadedSpecializationsLookupTables(const Decl *D, bool IsPartial);
1540
1541 /// If we have any unloaded specialization for \p D
1542 bool haveUnloadedSpecializations(const Decl *D) const;
1543
1554
1555 ASTReadResult ReadASTCore(StringRef FileName, ModuleKind Type,
1556 SourceLocation ImportLoc, ModuleFile *ImportedBy,
1558 off_t ExpectedSize, time_t ExpectedModTime,
1559 ASTFileSignature ExpectedSignature,
1560 unsigned ClientLoadCapabilities);
1561
1562private:
1563 ASTReadResult ReadControlBlock(ModuleFile &F,
1565 const ModuleFile *ImportedBy,
1566 unsigned ClientLoadCapabilities);
1567 static ASTReadResult
1568 ReadOptionsBlock(llvm::BitstreamCursor &Stream, StringRef Filename,
1569 unsigned ClientLoadCapabilities,
1570 bool AllowCompatibleConfigurationMismatch,
1571 ASTReaderListener &Listener,
1572 std::string &SuggestedPredefines);
1573
1574 /// Read the unhashed control block.
1575 ///
1576 /// This has no effect on \c F.Stream, instead creating a fresh cursor from
1577 /// \c F.Data and reading ahead.
1578 ASTReadResult readUnhashedControlBlock(ModuleFile &F, bool WasImportedBy,
1579 unsigned ClientLoadCapabilities);
1580
1581 static ASTReadResult readUnhashedControlBlockImpl(
1582 ModuleFile *F, llvm::StringRef StreamData, StringRef Filename,
1583 unsigned ClientLoadCapabilities,
1584 bool AllowCompatibleConfigurationMismatch, ASTReaderListener *Listener,
1585 bool ValidateDiagnosticOptions);
1586
1587 llvm::Error ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities);
1588 llvm::Error ReadExtensionBlock(ModuleFile &F);
1589 void ReadModuleOffsetMap(ModuleFile &F) const;
1590 void ParseLineTable(ModuleFile &F, const RecordData &Record);
1591 llvm::Error ReadSourceManagerBlock(ModuleFile &F);
1592 SourceLocation getImportLocation(ModuleFile *F);
1593
1594 /// The first element is `std::nullopt` if relocation check should be skipped.
1595 /// Otherwise, the optional holds a pointer to the discovered module.
1596 /// The pointer can be `nullptr` if the discovery was unsuccessful.
1597 /// The second element determines whether to emit related errors.
1598 using RelocationResult = std::pair<std::optional<Module *>, bool>;
1599
1600 /// Determine whether a relocation check for a module should be performed
1601 /// by attempting to resolve the same module via lookup.
1602 /// If so, also determine whether to emit errors for the relocation.
1603 /// A relocated module is defined as a module that is either no longer
1604 /// resolvable from the modulemap or search path it originally compiled it's
1605 /// definition from.
1606 RelocationResult getModuleForRelocationChecks(ModuleFile &F,
1607 bool DirectoryCheck = false);
1608 ASTReadResult ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F,
1609 const ModuleFile *ImportedBy,
1610 unsigned ClientLoadCapabilities);
1611 llvm::Error ReadSubmoduleBlock(ModuleFile &F,
1612 unsigned ClientLoadCapabilities);
1613 static bool ParseLanguageOptions(const RecordData &Record,
1614 StringRef ModuleFilename, bool Complain,
1615 ASTReaderListener &Listener,
1616 bool AllowCompatibleDifferences);
1617 static bool ParseCodeGenOptions(const RecordData &Record,
1618 StringRef ModuleFilename, bool Complain,
1619 ASTReaderListener &Listener,
1620 bool AllowCompatibleDifferences);
1621 static bool ParseTargetOptions(const RecordData &Record,
1622 StringRef ModuleFilename, bool Complain,
1623 ASTReaderListener &Listener,
1624 bool AllowCompatibleDifferences);
1625 static bool ParseDiagnosticOptions(const RecordData &Record,
1626 StringRef ModuleFilename, bool Complain,
1627 ASTReaderListener &Listener);
1628 static bool ParseFileSystemOptions(const RecordData &Record, bool Complain,
1629 ASTReaderListener &Listener);
1630 static bool ParseHeaderSearchOptions(const RecordData &Record,
1631 StringRef ModuleFilename, bool Complain,
1632 ASTReaderListener &Listener);
1633 static bool ParseHeaderSearchPaths(const RecordData &Record, bool Complain,
1634 ASTReaderListener &Listener);
1635 static bool ParsePreprocessorOptions(const RecordData &Record,
1636 StringRef ModuleFilename, bool Complain,
1637 ASTReaderListener &Listener,
1638 std::string &SuggestedPredefines);
1639
1640 struct RecordLocation {
1641 ModuleFile *F;
1642 uint64_t Offset;
1643
1644 RecordLocation(ModuleFile *M, uint64_t O) : F(M), Offset(O) {}
1645 };
1646
1647 QualType readTypeRecord(serialization::TypeID ID);
1648 RecordLocation TypeCursorForIndex(serialization::TypeID ID);
1649 void LoadedDecl(unsigned Index, Decl *D);
1650 Decl *ReadDeclRecord(GlobalDeclID ID);
1651 void markIncompleteDeclChain(Decl *D);
1652
1653 /// Returns the most recent declaration of a declaration (which must be
1654 /// of a redeclarable kind) that is either local or has already been loaded
1655 /// merged into its redecl chain.
1656 Decl *getMostRecentExistingDecl(Decl *D);
1657
1658 RecordLocation DeclCursorForID(GlobalDeclID ID, SourceLocation &Location);
1659 void loadDeclUpdateRecords(PendingUpdateRecord &Record);
1660 void loadPendingDeclChain(Decl *D, uint64_t LocalOffset);
1661 void loadObjCCategories(GlobalDeclID ID, ObjCInterfaceDecl *D,
1662 unsigned PreviousGeneration = 0);
1663
1664 RecordLocation getLocalBitOffset(uint64_t GlobalOffset);
1665 uint64_t getGlobalBitOffset(ModuleFile &M, uint64_t LocalOffset);
1666
1667 /// Returns the first preprocessed entity ID that begins or ends after
1668 /// \arg Loc.
1669 unsigned findPreprocessedEntity(SourceLocation Loc, bool EndsAfter) const;
1670
1671 /// Find the next module that contains entities and return the ID
1672 /// of the first entry.
1673 ///
1674 /// \param SLocMapI points at a chunk of a module that contains no
1675 /// preprocessed entities or the entities it contains are not the
1676 /// ones we are looking for.
1677 unsigned findNextPreprocessedEntity(
1679
1680 /// Returns (ModuleFile, Local index) pair for \p GlobalIndex of a
1681 /// preprocessed entity.
1682 std::pair<ModuleFile *, unsigned>
1683 getModulePreprocessedEntity(unsigned GlobalIndex);
1684
1685 /// Returns (begin, end) pair for the preprocessed entities of a
1686 /// particular module.
1687 llvm::iterator_range<PreprocessingRecord::iterator>
1688 getModulePreprocessedEntities(ModuleFile &Mod) const;
1689
1690 bool canRecoverFromOutOfDate(StringRef ModuleFileName,
1691 unsigned ClientLoadCapabilities);
1692
1693public:
1695 : public llvm::iterator_adaptor_base<
1696 ModuleDeclIterator, const serialization::unaligned_decl_id_t *,
1697 std::random_access_iterator_tag, const Decl *, ptrdiff_t,
1698 const Decl *, const Decl *> {
1699 ASTReader *Reader = nullptr;
1700 ModuleFile *Mod = nullptr;
1701
1702 public:
1703 ModuleDeclIterator() : iterator_adaptor_base(nullptr) {}
1704
1707 : iterator_adaptor_base(Pos), Reader(Reader), Mod(Mod) {}
1708
1709 value_type operator*() const {
1710 LocalDeclID ID = LocalDeclID::get(*Reader, *Mod, *I);
1711 return Reader->GetDecl(Reader->getGlobalDeclID(*Mod, ID));
1712 }
1713
1714 value_type operator->() const { return **this; }
1715
1716 bool operator==(const ModuleDeclIterator &RHS) const {
1717 assert(Reader == RHS.Reader && Mod == RHS.Mod);
1718 return I == RHS.I;
1719 }
1720 };
1721
1722 llvm::iterator_range<ModuleDeclIterator>
1724
1725private:
1726 bool isConsumerInterestedIn(Decl *D);
1727 void PassInterestingDeclsToConsumer();
1728 void PassInterestingDeclToConsumer(Decl *D);
1729 void PassVTableToConsumer(CXXRecordDecl *RD);
1730
1731 void finishPendingActions();
1732 void diagnoseOdrViolations();
1733
1734 void pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name);
1735
1736 void addPendingDeclContextInfo(Decl *D, GlobalDeclID SemaDC,
1737 GlobalDeclID LexicalDC) {
1738 assert(D);
1739 PendingDeclContextInfo Info = { D, SemaDC, LexicalDC };
1740 PendingDeclContextInfos.push_back(Info);
1741 }
1742
1743 /// Produce an error diagnostic and return true.
1744 ///
1745 /// This routine should only be used for fatal errors that have to
1746 /// do with non-routine failures (e.g., corrupted AST file).
1747 void Error(StringRef Msg) const;
1748 void Error(unsigned DiagID, StringRef Arg1 = StringRef(),
1749 StringRef Arg2 = StringRef(), StringRef Arg3 = StringRef()) const;
1750 void Error(llvm::Error &&Err) const;
1751
1752 /// Translate a \param GlobalDeclID to the index of DeclsLoaded array.
1753 unsigned translateGlobalDeclIDToIndex(GlobalDeclID ID) const;
1754
1755 /// Translate an \param IdentifierID ID to the index of IdentifiersLoaded
1756 /// array and the corresponding module file.
1757 std::pair<ModuleFile *, unsigned>
1758 translateIdentifierIDToIndex(serialization::IdentifierID ID) const;
1759
1760 /// Translate an \param MacroID ID to the index of MacrosLoaded
1761 /// array and the corresponding module file.
1762 std::pair<ModuleFile *, unsigned>
1763 translateMacroIDToIndex(serialization::MacroID ID) const;
1764
1765 unsigned translatePreprocessedEntityIDToIndex(
1767
1768 /// Translate an \param TypeID ID to the index of TypesLoaded
1769 /// array and the corresponding module file.
1770 std::pair<ModuleFile *, unsigned>
1771 translateTypeIDToIndex(serialization::TypeID ID) const;
1772
1773 /// Get a predefined Decl from ASTContext.
1774 Decl *getPredefinedDecl(PredefinedDeclIDs ID);
1775
1776public:
1777 /// Load the AST file and validate its contents against the given
1778 /// Preprocessor.
1779 ///
1780 /// \param PP the preprocessor associated with the context in which this
1781 /// precompiled header will be loaded.
1782 ///
1783 /// \param Context the AST context that this precompiled header will be
1784 /// loaded into, if any.
1785 ///
1786 /// \param PCHContainerRdr the PCHContainerOperations to use for loading and
1787 /// creating modules.
1788 ///
1789 /// \param Extensions the list of module file extensions that can be loaded
1790 /// from the AST files.
1791 ///
1792 /// \param isysroot If non-NULL, the system include path specified by the
1793 /// user. This is only used with relocatable PCH files. If non-NULL,
1794 /// a relocatable PCH file will use the default path "/".
1795 ///
1796 /// \param DisableValidationKind If set, the AST reader will suppress most
1797 /// of its regular consistency checking, allowing the use of precompiled
1798 /// headers and module files that cannot be determined to be compatible.
1799 ///
1800 /// \param AllowASTWithCompilerErrors If true, the AST reader will accept an
1801 /// AST file the was created out of an AST with compiler errors,
1802 /// otherwise it will reject it.
1803 ///
1804 /// \param AllowConfigurationMismatch If true, the AST reader will not check
1805 /// for configuration differences between the AST file and the invocation.
1806 ///
1807 /// \param ValidateSystemInputs If true, the AST reader will validate
1808 /// system input files in addition to user input files. This is only
1809 /// meaningful if \p DisableValidation is false.
1810 ///
1811 /// \param UseGlobalIndex If true, the AST reader will try to load and use
1812 /// the global module index.
1813 ///
1814 /// \param ReadTimer If non-null, a timer used to track the time spent
1815 /// deserializing.
1816 ASTReader(Preprocessor &PP, ModuleCache &ModCache, ASTContext *Context,
1817 const PCHContainerReader &PCHContainerRdr,
1818 const CodeGenOptions &CodeGenOpts,
1819 ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
1820 StringRef isysroot = "",
1821 DisableValidationForModuleKind DisableValidationKind =
1823 bool AllowASTWithCompilerErrors = false,
1824 bool AllowConfigurationMismatch = false,
1825 bool ValidateSystemInputs = false,
1826 bool ForceValidateUserInputs = true,
1827 bool ValidateASTInputFilesContent = false,
1828 bool UseGlobalIndex = true,
1829 std::unique_ptr<llvm::Timer> ReadTimer = {});
1830 ASTReader(const ASTReader &) = delete;
1831 ASTReader &operator=(const ASTReader &) = delete;
1832 ~ASTReader() override;
1833
1834 SourceManager &getSourceManager() const { return SourceMgr; }
1835 FileManager &getFileManager() const { return FileMgr; }
1836 DiagnosticsEngine &getDiags() const { return Diags; }
1837 const CodeGenOptions &getCodeGenOpts() const { return CodeGenOpts; }
1838
1839 /// Flags that indicate what kind of AST loading failures the client
1840 /// of the AST reader can directly handle.
1841 ///
1842 /// When a client states that it can handle a particular kind of failure,
1843 /// the AST reader will not emit errors when producing that kind of failure.
1845 /// The client can't handle any AST loading failures.
1847
1848 /// The client can handle an AST file that cannot load because it
1849 /// is missing.
1851
1852 /// The client can handle an AST file that cannot load because it
1853 /// is out-of-date relative to its input files.
1855
1856 /// The client can handle an AST file that cannot load because it
1857 /// was built with a different version of Clang.
1859
1860 /// The client can handle an AST file that cannot load because it's
1861 /// compiled configuration doesn't match that of the context it was
1862 /// loaded into.
1864
1865 /// If a module file is marked with errors treat it as out-of-date so the
1866 /// caller can rebuild it.
1868 };
1869
1870 /// Load the AST file designated by the given file name.
1871 ///
1872 /// \param FileName The name of the AST file to load.
1873 ///
1874 /// \param Type The kind of AST being loaded, e.g., PCH, module, main file,
1875 /// or preamble.
1876 ///
1877 /// \param ImportLoc the location where the module file will be considered as
1878 /// imported from. For non-module AST types it should be invalid.
1879 ///
1880 /// \param ClientLoadCapabilities The set of client load-failure
1881 /// capabilities, represented as a bitset of the enumerators of
1882 /// LoadFailureCapabilities.
1883 ///
1884 /// \param LoadedModuleFile The optional out-parameter refers to the new
1885 /// loaded modules. In case the module specified by FileName is already
1886 /// loaded, the module file pointer referred by NewLoadedModuleFile wouldn't
1887 /// change. Otherwise if the AST file get loaded successfully,
1888 /// NewLoadedModuleFile would refer to the address of the new loaded top level
1889 /// module. The state of NewLoadedModuleFile is unspecified if the AST file
1890 /// isn't loaded successfully.
1891 ASTReadResult ReadAST(StringRef FileName, ModuleKind Type,
1892 SourceLocation ImportLoc,
1893 unsigned ClientLoadCapabilities,
1894 ModuleFile **NewLoadedModuleFile = nullptr);
1895
1896 /// Make the entities in the given module and any of its (non-explicit)
1897 /// submodules visible to name lookup.
1898 ///
1899 /// \param Mod The module whose names should be made visible.
1900 ///
1901 /// \param NameVisibility The level of visibility to give the names in the
1902 /// module. Visibility can only be increased over time.
1903 ///
1904 /// \param ImportLoc The location at which the import occurs.
1905 void makeModuleVisible(Module *Mod,
1906 Module::NameVisibilityKind NameVisibility,
1907 SourceLocation ImportLoc);
1908
1909 /// Make the names within this set of hidden names visible.
1910 void makeNamesVisible(const HiddenNames &Names, Module *Owner);
1911
1912 /// Note that MergedDef is a redefinition of the canonical definition
1913 /// Def, so Def should be visible whenever MergedDef is.
1914 void mergeDefinitionVisibility(NamedDecl *Def, NamedDecl *MergedDef);
1915
1916 /// Take the AST callbacks listener.
1917 std::unique_ptr<ASTReaderListener> takeListener() {
1918 return std::move(Listener);
1919 }
1920
1921 /// Set the AST callbacks listener.
1922 void setListener(std::unique_ptr<ASTReaderListener> Listener) {
1923 this->Listener = std::move(Listener);
1924 }
1925
1926 /// Add an AST callback listener.
1927 ///
1928 /// Takes ownership of \p L.
1929 void addListener(std::unique_ptr<ASTReaderListener> L) {
1930 if (Listener)
1931 L = std::make_unique<ChainedASTReaderListener>(std::move(L),
1932 std::move(Listener));
1933 Listener = std::move(L);
1934 }
1935
1936 /// RAII object to temporarily add an AST callback listener.
1938 ASTReader &Reader;
1939 bool Chained = false;
1940
1941 public:
1942 ListenerScope(ASTReader &Reader, std::unique_ptr<ASTReaderListener> L)
1943 : Reader(Reader) {
1944 auto Old = Reader.takeListener();
1945 if (Old) {
1946 Chained = true;
1947 L = std::make_unique<ChainedASTReaderListener>(std::move(L),
1948 std::move(Old));
1949 }
1950 Reader.setListener(std::move(L));
1951 }
1952
1954 auto New = Reader.takeListener();
1955 if (Chained)
1956 Reader.setListener(static_cast<ChainedASTReaderListener *>(New.get())
1957 ->takeSecond());
1958 }
1959 };
1960
1961 /// Set the AST deserialization listener.
1963 bool TakeOwnership = false);
1964
1965 /// Get the AST deserialization listener.
1967 return DeserializationListener;
1968 }
1969
1970 /// Determine whether this AST reader has a global index.
1971 bool hasGlobalIndex() const { return (bool)GlobalIndex; }
1972
1973 /// Return global module index.
1974 GlobalModuleIndex *getGlobalIndex() { return GlobalIndex.get(); }
1975
1976 /// Reset reader for a reload try.
1977 void resetForReload() { TriedLoadingGlobalIndex = false; }
1978
1979 /// Attempts to load the global index.
1980 ///
1981 /// \returns true if loading the global index has failed for any reason.
1982 bool loadGlobalIndex();
1983
1984 /// Determine whether we tried to load the global index, but failed,
1985 /// e.g., because it is out-of-date or does not exist.
1986 bool isGlobalIndexUnavailable() const;
1987
1988 /// Initializes the ASTContext
1989 void InitializeContext();
1990
1991 /// Update the state of Sema after loading some additional modules.
1992 void UpdateSema();
1993
1994 /// Add in-memory (virtual file) buffer.
1996 std::unique_ptr<llvm::MemoryBuffer> Buffer) {
1997 ModuleMgr.addInMemoryBuffer(FileName, std::move(Buffer));
1998 }
1999
2000 /// Finalizes the AST reader's state before writing an AST file to
2001 /// disk.
2002 ///
2003 /// This operation may undo temporary state in the AST that should not be
2004 /// emitted.
2005 void finalizeForWriting();
2006
2007 /// Retrieve the module manager.
2008 ModuleManager &getModuleManager() { return ModuleMgr; }
2009 const ModuleManager &getModuleManager() const { return ModuleMgr; }
2010
2011 /// Retrieve the preprocessor.
2012 Preprocessor &getPreprocessor() const { return PP; }
2013
2014 /// Retrieve the name of the original source file name for the primary
2015 /// module file.
2017 return ModuleMgr.getPrimaryModule().OriginalSourceFileName;
2018 }
2019
2020 /// Retrieve the name of the original source file name directly from
2021 /// the AST file, without actually loading the AST file.
2022 static std::string
2023 getOriginalSourceFile(const std::string &ASTFileName, FileManager &FileMgr,
2024 const PCHContainerReader &PCHContainerRdr,
2025 DiagnosticsEngine &Diags);
2026
2027 /// Read the control block for the named AST file.
2028 ///
2029 /// \returns true if an error occurred, false otherwise.
2030 static bool readASTFileControlBlock(
2031 StringRef Filename, FileManager &FileMgr, const ModuleCache &ModCache,
2032 const PCHContainerReader &PCHContainerRdr, bool FindModuleFileExtensions,
2033 ASTReaderListener &Listener, bool ValidateDiagnosticOptions,
2034 unsigned ClientLoadCapabilities = ARR_ConfigurationMismatch |
2036
2037 /// Determine whether the given AST file is acceptable to load into a
2038 /// translation unit with the given language and target options.
2039 static bool isAcceptableASTFile(
2040 StringRef Filename, FileManager &FileMgr, const ModuleCache &ModCache,
2041 const PCHContainerReader &PCHContainerRdr, const LangOptions &LangOpts,
2042 const CodeGenOptions &CGOpts, const TargetOptions &TargetOpts,
2043 const PreprocessorOptions &PPOpts, const HeaderSearchOptions &HSOpts,
2044 StringRef SpecificModuleCachePath,
2045 bool RequireStrictOptionMatches = false);
2046
2047 /// Returns the suggested contents of the predefines buffer,
2048 /// which contains a (typically-empty) subset of the predefines
2049 /// build prior to including the precompiled header.
2050 const std::string &getSuggestedPredefines() { return SuggestedPredefines; }
2051
2052 /// Read a preallocated preprocessed entity from the external source.
2053 ///
2054 /// \returns null if an error occurred that prevented the preprocessed
2055 /// entity from being loaded.
2056 PreprocessedEntity *ReadPreprocessedEntity(unsigned Index) override;
2057
2058 /// Returns a pair of [Begin, End) indices of preallocated
2059 /// preprocessed entities that \p Range encompasses.
2060 std::pair<unsigned, unsigned>
2062
2063 /// Optionally returns true or false if the preallocated preprocessed
2064 /// entity with index \p Index came from file \p FID.
2065 std::optional<bool> isPreprocessedEntityInFileID(unsigned Index,
2066 FileID FID) override;
2067
2068 /// Read a preallocated skipped range from the external source.
2069 SourceRange ReadSkippedRange(unsigned Index) override;
2070
2071 /// Read the header file information for the given file entry.
2073
2075
2076 /// Returns the number of source locations found in the chain.
2077 unsigned getTotalNumSLocs() const {
2078 return TotalNumSLocEntries;
2079 }
2080
2081 /// Returns the number of identifiers found in the chain.
2082 unsigned getTotalNumIdentifiers() const {
2083 return static_cast<unsigned>(IdentifiersLoaded.size());
2084 }
2085
2086 /// Returns the number of macros found in the chain.
2087 unsigned getTotalNumMacros() const {
2088 return static_cast<unsigned>(MacrosLoaded.size());
2089 }
2090
2091 /// Returns the number of types found in the chain.
2092 unsigned getTotalNumTypes() const {
2093 return static_cast<unsigned>(TypesLoaded.size());
2094 }
2095
2096 /// Returns the number of declarations found in the chain.
2097 unsigned getTotalNumDecls() const {
2098 return static_cast<unsigned>(DeclsLoaded.size());
2099 }
2100
2101 /// Returns the number of submodules known.
2102 unsigned getTotalNumSubmodules() const {
2103 return static_cast<unsigned>(SubmodulesLoaded.size());
2104 }
2105
2106 /// Returns the number of selectors found in the chain.
2107 unsigned getTotalNumSelectors() const {
2108 return static_cast<unsigned>(SelectorsLoaded.size());
2109 }
2110
2111 /// Returns the number of preprocessed entities known to the AST
2112 /// reader.
2114 unsigned Result = 0;
2115 for (const auto &M : ModuleMgr)
2116 Result += M.NumPreprocessedEntities;
2117 return Result;
2118 }
2119
2120 /// Resolve a type ID into a type, potentially building a new
2121 /// type.
2123
2124 /// Resolve a local type ID within a given AST file into a type.
2126
2127 /// Map a local type ID within a given AST file into a global type ID.
2130
2131 /// Read a type from the current position in the given record, which
2132 /// was read from the given AST file.
2133 QualType readType(ModuleFile &F, const RecordData &Record, unsigned &Idx) {
2134 if (Idx >= Record.size())
2135 return {};
2136
2137 return getLocalType(F, Record[Idx++]);
2138 }
2139
2140 /// Map from a local declaration ID within a given module to a
2141 /// global declaration ID.
2143
2144 /// Returns true if global DeclID \p ID originated from module \p M.
2145 bool isDeclIDFromModule(GlobalDeclID ID, ModuleFile &M) const;
2146
2147 /// Retrieve the module file that owns the given declaration, or NULL
2148 /// if the declaration is not from a module file.
2149 ModuleFile *getOwningModuleFile(const Decl *D) const;
2151
2152 /// Returns the source location for the decl \p ID.
2154
2155 /// Resolve a declaration ID into a declaration, potentially
2156 /// building a new declaration.
2158 Decl *GetExternalDecl(GlobalDeclID ID) override;
2159
2160 /// Resolve a declaration ID into a declaration. Return 0 if it's not
2161 /// been loaded yet.
2163
2164 /// Reads a declaration with the given local ID in the given module.
2166 return GetDecl(getGlobalDeclID(F, LocalID));
2167 }
2168
2169 /// Reads a declaration with the given local ID in the given module.
2170 ///
2171 /// \returns The requested declaration, casted to the given return type.
2172 template <typename T> T *GetLocalDeclAs(ModuleFile &F, LocalDeclID LocalID) {
2173 return cast_or_null<T>(GetLocalDecl(F, LocalID));
2174 }
2175
2176 /// Map a global declaration ID into the declaration ID used to
2177 /// refer to this declaration within the given module fule.
2178 ///
2179 /// \returns the global ID of the given declaration as known in the given
2180 /// module file.
2182 GlobalDeclID GlobalID);
2183
2184 /// Reads a macro ID from the given position in a record in the
2185 /// given module.
2186 ///
2187 /// \returns The declaration ID read from the record, adjusted to a global
2188 /// Macro ID.
2190 ReadMacroID(ModuleFile &F, const RecordDataImpl &Record, unsigned &Idx);
2191
2192 /// Reads a declaration ID from the given position in a record in the
2193 /// given module.
2194 ///
2195 /// \returns The declaration ID read from the record, adjusted to a global ID.
2197 unsigned &Idx);
2198
2199 /// Reads a declaration from the given position in a record in the
2200 /// given module.
2201 Decl *ReadDecl(ModuleFile &F, const RecordDataImpl &R, unsigned &I) {
2202 return GetDecl(ReadDeclID(F, R, I));
2203 }
2204
2205 /// Reads a declaration from the given position in a record in the
2206 /// given module.
2207 ///
2208 /// \returns The declaration read from this location, casted to the given
2209 /// result type.
2210 template <typename T>
2211 T *ReadDeclAs(ModuleFile &F, const RecordDataImpl &R, unsigned &I) {
2212 return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
2213 }
2214
2215 /// If any redeclarations of \p D have been imported since it was
2216 /// last checked, this digs out those redeclarations and adds them to the
2217 /// redeclaration chain for \p D.
2218 void CompleteRedeclChain(const Decl *D) override;
2219
2220 CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override;
2221
2222 /// Resolve the offset of a statement into a statement.
2223 ///
2224 /// This operation will read a new statement from the external
2225 /// source each time it is called, and is meant to be used via a
2226 /// LazyOffsetPtr (which is used by Decls for the body of functions, etc).
2227 Stmt *GetExternalDeclStmt(uint64_t Offset) override;
2228
2229 /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the
2230 /// specified cursor. Read the abbreviations that are at the top of the block
2231 /// and then leave the cursor pointing into the block.
2232 static llvm::Error ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor,
2233 unsigned BlockID,
2234 uint64_t *StartOfBlockOffset = nullptr);
2235
2236 bool LoadExternalSpecializations(const Decl *D, bool OnlyPartial) override;
2237
2238 bool
2240 ArrayRef<TemplateArgument> TemplateArgs) override;
2241
2242 /// Finds all the visible declarations with a given name.
2243 /// The current implementation of this method just loads the entire
2244 /// lookup table as unmaterialized references.
2246 DeclarationName Name,
2247 const DeclContext *OriginalDC) override;
2248
2249 /// Read all of the declarations lexically stored in a
2250 /// declaration context.
2251 ///
2252 /// \param DC The declaration context whose declarations will be
2253 /// read.
2254 ///
2255 /// \param IsKindWeWant A predicate indicating which declaration kinds
2256 /// we are interested in.
2257 ///
2258 /// \param Decls Vector that will contain the declarations loaded
2259 /// from the external source. The caller is responsible for merging
2260 /// these declarations with any declarations already stored in the
2261 /// declaration context.
2262 void
2264 llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
2265 SmallVectorImpl<Decl *> &Decls) override;
2266
2267 /// Get the decls that are contained in a file in the Offset/Length
2268 /// range. \p Length can be 0 to indicate a point at \p Offset instead of
2269 /// a range.
2270 void FindFileRegionDecls(FileID File, unsigned Offset, unsigned Length,
2271 SmallVectorImpl<Decl *> &Decls) override;
2272
2273 /// Notify ASTReader that we started deserialization of
2274 /// a decl or type so until FinishedDeserializing is called there may be
2275 /// decls that are initializing. Must be paired with FinishedDeserializing.
2276 void StartedDeserializing() override;
2277
2278 /// Notify ASTReader that we finished the deserialization of
2279 /// a decl or type. Must be paired with StartedDeserializing.
2280 void FinishedDeserializing() override;
2281
2282 /// Function that will be invoked when we begin parsing a new
2283 /// translation unit involving this external AST source.
2284 ///
2285 /// This function will provide all of the external definitions to
2286 /// the ASTConsumer.
2287 void StartTranslationUnit(ASTConsumer *Consumer) override;
2288
2289 /// Print some statistics about AST usage.
2290 void PrintStats() override;
2291
2292 /// Dump information about the AST reader to standard error.
2293 void dump();
2294
2295 /// Return the amount of memory used by memory buffers, breaking down
2296 /// by heap-backed versus mmap'ed memory.
2297 void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override;
2298
2299 /// Initialize the semantic source with the Sema instance
2300 /// being used to perform semantic analysis on the abstract syntax
2301 /// tree.
2302 void InitializeSema(Sema &S) override;
2303
2304 /// Inform the semantic consumer that Sema is no longer available.
2305 void ForgetSema() override { SemaObj = nullptr; }
2306
2307 /// Retrieve the IdentifierInfo for the named identifier.
2308 ///
2309 /// This routine builds a new IdentifierInfo for the given identifier. If any
2310 /// declarations with this name are visible from translation unit scope, their
2311 /// declarations will be deserialized and introduced into the declaration
2312 /// chain of the identifier.
2313 IdentifierInfo *get(StringRef Name) override;
2314
2315 /// Retrieve an iterator into the set of all identifiers
2316 /// in all loaded AST files.
2318
2319 /// Load the contents of the global method pool for a given
2320 /// selector.
2321 void ReadMethodPool(Selector Sel) override;
2322
2323 /// Load the contents of the global method pool for a given
2324 /// selector if necessary.
2325 void updateOutOfDateSelector(Selector Sel) override;
2326
2327 /// Load the set of namespaces that are known to the external source,
2328 /// which will be used during typo correction.
2330 SmallVectorImpl<NamespaceDecl *> &Namespaces) override;
2331
2333 llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) override;
2334
2335 void ReadMismatchingDeleteExpressions(llvm::MapVector<
2336 FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &
2337 Exprs) override;
2338
2340 SmallVectorImpl<VarDecl *> &TentativeDefs) override;
2341
2344
2347
2349
2352
2354 llvm::SmallSetVector<Decl *, 4> &Decls) override;
2355
2357 SmallVectorImpl<std::pair<Selector, SourceLocation>> &Sels) override;
2358
2360 SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo>> &WeakIDs) override;
2361
2363
2365 SmallVectorImpl<std::pair<ValueDecl *,
2366 SourceLocation>> &Pending) override;
2367
2369 llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
2370 &LPTMap) override;
2371
2372 void AssignedLambdaNumbering(CXXRecordDecl *Lambda) override;
2373
2374 /// Load a selector from disk, registering its ID if it exists.
2375 void LoadSelector(Selector Sel);
2376
2379 const SmallVectorImpl<GlobalDeclID> &DeclIDs,
2380 SmallVectorImpl<Decl *> *Decls = nullptr);
2381
2382 /// Report a diagnostic.
2383 DiagnosticBuilder Diag(unsigned DiagID) const;
2384
2385 /// Report a diagnostic.
2386 DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const;
2387
2389 llvm::function_ref<void()> Fn);
2390
2392
2394 unsigned &Idx) {
2396 }
2397
2399 // Note that we are loading an identifier.
2400 Deserializing AnIdentifier(this);
2401
2402 return DecodeIdentifierInfo(ID);
2403 }
2404
2405 IdentifierInfo *getLocalIdentifier(ModuleFile &M, uint64_t LocalID);
2406
2408 uint64_t LocalID);
2409
2410 void resolvePendingMacro(IdentifierInfo *II, const PendingMacroInfo &PMInfo);
2411
2412 /// Retrieve the macro with the given ID.
2414
2415 /// Retrieve the global macro ID corresponding to the given local
2416 /// ID within the given module file.
2418 serialization::MacroID LocalID);
2419
2420 /// Read the source location entry with index ID.
2421 bool ReadSLocEntry(int ID) override;
2422 /// Get the index ID for the loaded SourceLocation offset.
2423 int getSLocEntryID(SourceLocation::UIntTy SLocOffset) override;
2424 /// Try to read the offset of the SLocEntry at the given index in the given
2425 /// module file.
2427 unsigned Index);
2428
2429 /// Retrieve the module import location and module name for the
2430 /// given source manager entry ID.
2431 std::pair<SourceLocation, StringRef> getModuleImportLoc(int ID) override;
2432
2433 /// Retrieve the global submodule ID given a module and its local ID
2434 /// number.
2436 unsigned LocalID) const;
2437
2438 /// Retrieve the submodule that corresponds to a global submodule ID.
2439 ///
2441
2442 /// Retrieve the module that corresponds to the given module ID.
2443 ///
2444 /// Note: overrides method in ExternalASTSource
2445 Module *getModule(unsigned ID) override;
2446
2447 /// Retrieve the module file with a given local ID within the specified
2448 /// ModuleFile.
2449 ModuleFile *getLocalModuleFile(ModuleFile &M, unsigned ID) const;
2450
2451 /// Get an ID for the given module file.
2452 unsigned getModuleFileID(ModuleFile *M);
2453
2454 /// Return a descriptor for the corresponding module.
2455 std::optional<ASTSourceDescriptor> getSourceDescriptor(unsigned ID) override;
2456
2457 ExtKind hasExternalDefinitions(const Decl *D) override;
2458
2459 bool wasThisDeclarationADefinition(const FunctionDecl *FD) override;
2460
2461 /// Retrieve a selector from the given module with its local ID
2462 /// number.
2463 Selector getLocalSelector(ModuleFile &M, unsigned LocalID);
2464
2466
2468 uint32_t GetNumExternalSelectors() override;
2469
2470 Selector ReadSelector(ModuleFile &M, const RecordData &Record, unsigned &Idx) {
2471 return getLocalSelector(M, Record[Idx++]);
2472 }
2473
2474 /// Retrieve the global selector ID that corresponds to this
2475 /// the local selector ID in a given module.
2477 unsigned LocalID) const;
2478
2479 /// Read the contents of a CXXCtorInitializer array.
2480 CXXCtorInitializer **GetExternalCXXCtorInitializers(uint64_t Offset) override;
2481
2482 /// Read a AlignPackInfo from raw form.
2486
2488
2489 /// Read a source location from raw form and return it in its
2490 /// originating module file's source location space.
2491 std::pair<SourceLocation, unsigned>
2495
2496 /// Read a source location from raw form.
2498 if (!MF.ModuleOffsetMap.empty())
2499 ReadModuleOffsetMap(MF);
2500
2501 auto [Loc, ModuleFileIndex] = ReadUntranslatedSourceLocation(Raw);
2502 ModuleFile *OwningModuleFile =
2503 ModuleFileIndex == 0 ? &MF : MF.TransitiveImports[ModuleFileIndex - 1];
2504
2505 assert(!SourceMgr.isLoadedSourceLocation(Loc) &&
2506 "Run out source location space");
2507
2508 return TranslateSourceLocation(*OwningModuleFile, Loc);
2509 }
2510
2511 /// Translate a source location from another module file's source
2512 /// location space into ours.
2514 SourceLocation Loc) const {
2515 if (Loc.isInvalid())
2516 return Loc;
2517
2518 // FIXME: TranslateSourceLocation is not re-enterable. It is problematic
2519 // to call TranslateSourceLocation on a translated source location.
2520 // We either need a method to know whether or not a source location is
2521 // translated or refactor the code to make it clear that
2522 // TranslateSourceLocation won't be called with translated source location.
2523
2524 return Loc.getLocWithOffset(ModuleFile.SLocEntryBaseOffset - 2);
2525 }
2526
2527 /// Read a source location.
2529 const RecordDataImpl &Record,
2530 unsigned &Idx) {
2531 return ReadSourceLocation(ModuleFile, Record[Idx++]);
2532 }
2533
2534 /// Read a FileID.
2536 unsigned &Idx) const {
2537 return TranslateFileID(F, FileID::get(Record[Idx++]));
2538 }
2539
2540 /// Translate a FileID from another module file's FileID space into ours.
2542 assert(FID.ID >= 0 && "Reading non-local FileID.");
2543 if (FID.isInvalid())
2544 return FID;
2545 return FileID::get(F.SLocEntryBaseID + FID.ID - 1);
2546 }
2547
2548 /// Read a source range.
2550 unsigned &Idx);
2551
2552 static llvm::BitVector ReadBitVector(const RecordData &Record,
2553 const StringRef Blob);
2554
2555 // Read a string
2556 static std::string ReadString(const RecordDataImpl &Record, unsigned &Idx);
2557 static StringRef ReadStringBlob(const RecordDataImpl &Record, unsigned &Idx,
2558 StringRef &Blob);
2559
2560 // Read a path
2561 std::string ReadPath(ModuleFile &F, const RecordData &Record, unsigned &Idx);
2562
2563 // Read a path
2564 std::string ReadPath(StringRef BaseDirectory, const RecordData &Record,
2565 unsigned &Idx);
2566 std::string ReadPathBlob(StringRef BaseDirectory, const RecordData &Record,
2567 unsigned &Idx, StringRef &Blob);
2568
2569 /// Read a version tuple.
2570 static VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx);
2571
2573 unsigned &Idx);
2574
2575 /// Reads a statement.
2577
2578 /// Reads an expression.
2580
2581 /// Reads a sub-statement operand during statement reading.
2583 assert(ReadingKind == Read_Stmt &&
2584 "Should be called only during statement reading!");
2585 // Subexpressions are stored from last to first, so the next Stmt we need
2586 // is at the back of the stack.
2587 assert(!StmtStack.empty() && "Read too many sub-statements!");
2588 return StmtStack.pop_back_val();
2589 }
2590
2591 /// Reads a sub-expression operand during statement reading.
2592 Expr *ReadSubExpr();
2593
2594 /// Reads a token out of a record.
2595 Token ReadToken(ModuleFile &M, const RecordDataImpl &Record, unsigned &Idx);
2596
2597 /// Reads the macro record located at the given offset.
2598 MacroInfo *ReadMacroRecord(ModuleFile &F, uint64_t Offset);
2599
2600 /// Determine the global preprocessed entity ID that corresponds to
2601 /// the given local ID within the given module.
2604
2605 /// Add a macro to deserialize its macro directive history.
2606 ///
2607 /// \param II The name of the macro.
2608 /// \param M The module file.
2609 /// \param MacroDirectivesOffset Offset of the serialized macro directive
2610 /// history.
2612 uint32_t MacroDirectivesOffset);
2613
2614 /// Read the set of macros defined by this external macro source.
2615 void ReadDefinedMacros() override;
2616
2617 /// Update an out-of-date identifier.
2618 void updateOutOfDateIdentifier(const IdentifierInfo &II) override;
2619
2620 /// Note that this identifier is up-to-date.
2621 void markIdentifierUpToDate(const IdentifierInfo *II);
2622
2623 /// Load all external visible decls in the given DeclContext.
2624 void completeVisibleDeclsMap(const DeclContext *DC) override;
2625
2626 /// Retrieve the AST context that this AST reader supplements.
2628 assert(ContextObj && "requested AST context when not loading AST");
2629 return *ContextObj;
2630 }
2631
2632 // Contains the IDs for declarations that were requested before we have
2633 // access to a Sema object.
2635
2636 /// Retrieve the semantic analysis object used to analyze the
2637 /// translation unit in which the precompiled header is being
2638 /// imported.
2639 Sema *getSema() { return SemaObj; }
2640
2641 /// Get the identifier resolver used for name lookup / updates
2642 /// in the translation unit scope. We have one of these even if we don't
2643 /// have a Sema object.
2645
2646 /// Retrieve the identifier table associated with the
2647 /// preprocessor.
2649
2650 /// Record that the given ID maps to the given switch-case
2651 /// statement.
2652 void RecordSwitchCaseID(SwitchCase *SC, unsigned ID);
2653
2654 /// Retrieve the switch-case statement with the given ID.
2655 SwitchCase *getSwitchCaseWithID(unsigned ID);
2656
2657 void ClearSwitchCaseIDs();
2658
2659 /// Cursors for comments blocks.
2660 SmallVector<std::pair<llvm::BitstreamCursor,
2662
2663 /// Loads comments ranges.
2664 void ReadComments() override;
2665
2666 /// Visit all the input file infos of the given module file.
2668 serialization::ModuleFile &MF, bool IncludeSystem,
2669 llvm::function_ref<void(const serialization::InputFileInfo &IFI,
2670 bool IsSystem)>
2671 Visitor);
2672
2673 /// Visit all the input files of the given module file.
2675 bool IncludeSystem, bool Complain,
2676 llvm::function_ref<void(const serialization::InputFile &IF,
2677 bool isSystem)> Visitor);
2678
2679 /// Visit all the top-level module maps loaded when building the given module
2680 /// file.
2682 llvm::function_ref<void(FileEntryRef)> Visitor);
2683
2684 bool isProcessingUpdateRecords() { return ProcessingUpdateRecords; }
2685};
2686
2687/// A simple helper class to unpack an integer to bits and consuming
2688/// the bits in order.
2690 constexpr static uint32_t BitsIndexUpbound = 32;
2691
2692public:
2693 BitsUnpacker(uint32_t V) { updateValue(V); }
2694 BitsUnpacker(const BitsUnpacker &) = delete;
2698 ~BitsUnpacker() = default;
2699
2700 void updateValue(uint32_t V) {
2701 Value = V;
2702 CurrentBitsIndex = 0;
2703 }
2704
2705 void advance(uint32_t BitsWidth) { CurrentBitsIndex += BitsWidth; }
2706
2707 bool getNextBit() {
2708 assert(isValid());
2709 return Value & (1 << CurrentBitsIndex++);
2710 }
2711
2712 uint32_t getNextBits(uint32_t Width) {
2713 assert(isValid());
2714 assert(Width < BitsIndexUpbound);
2715 uint32_t Ret = (Value >> CurrentBitsIndex) & ((1 << Width) - 1);
2716 CurrentBitsIndex += Width;
2717 return Ret;
2718 }
2719
2720 bool canGetNextNBits(uint32_t Width) const {
2721 return CurrentBitsIndex + Width < BitsIndexUpbound;
2722 }
2723
2724private:
2725 bool isValid() const { return CurrentBitsIndex < BitsIndexUpbound; }
2726
2727 uint32_t Value;
2728 uint32_t CurrentBitsIndex = ~0;
2729};
2730
2731inline bool shouldSkipCheckingODR(const Decl *D) {
2732 return D->getASTContext().getLangOpts().SkipODRCheckInGMF &&
2733 (D->isFromGlobalModule() || D->isFromHeaderUnit());
2734}
2735
2736/// Calculate a hash value for the primary module name of the given module.
2737/// \returns std::nullopt if M is not a C++ standard module.
2738UnsignedOrNone getPrimaryModuleHash(const Module *M);
2739
2740} // namespace clang
2741
2742#endif // LLVM_CLANG_SERIALIZATION_ASTREADER_H
#define V(N, I)
Defines the Diagnostic-related interfaces.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
static DiagnosticBuilder Diag(DiagnosticsEngine *Diags, const LangOptions &Features, FullSourceLoc TokLoc, const char *TokBegin, const char *TokRangeBegin, const char *TokRangeEnd, unsigned DiagID)
Produce a diagnostic highlighting some portion of a literal.
llvm::MachO::Record Record
Definition MachO.h:31
Defines the clang::OpenCLOptions class.
Defines the clang::SourceLocation class and associated facilities.
Defines a utilitiy for warning once when close to out of stack space.
C Language Family Type Representation.
Defines version macros and version-related utility functions for Clang.
ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.
Definition ASTConsumer.h:35
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:226
const LangOptions & getLangOpts() const
Definition ASTContext.h:951
Abstract interface for callback invocations by the ASTReader.
Definition ASTReader.h:117
virtual void ReadModuleMapFile(StringRef ModuleMapPath)
Definition ASTReader.h:130
virtual bool needsInputFileVisitation()
Returns true if this ASTReaderListener wants to receive the input files of the AST file via visitInpu...
Definition ASTReader.h:232
virtual bool ReadDiagnosticOptions(DiagnosticOptions &DiagOpts, StringRef ModuleFilename, bool Complain)
Receives the diagnostic options.
Definition ASTReader.h:164
virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, StringRef ModuleFilename, bool Complain, bool AllowCompatibleDifferences)
Receives the target options.
Definition ASTReader.h:154
virtual bool visitInputFile(StringRef Filename, bool isSystem, bool isOverridden, bool isExplicitModule)
if needsInputFileVisitation returns true, this is called for each non-system input file of the AST Fi...
Definition ASTReader.h:244
virtual bool ReadHeaderSearchPaths(const HeaderSearchOptions &HSOpts, bool Complain)
Receives the header search paths.
Definition ASTReader.h:202
virtual bool ReadFileSystemOptions(const FileSystemOptions &FSOpts, bool Complain)
Receives the file system options.
Definition ASTReader.h:173
virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, StringRef ModuleFilename, bool ReadMacros, bool Complain, std::string &SuggestedPredefines)
Receives the preprocessor options.
Definition ASTReader.h:215
virtual bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, StringRef ModuleFilename, StringRef SpecificModuleCachePath, bool Complain)
Receives the header search options.
Definition ASTReader.h:186
virtual void readModuleFileExtension(const ModuleFileExtensionMetadata &Metadata)
Indicates that a particular module file extension has been read.
Definition ASTReader.h:271
virtual bool ReadLanguageOptions(const LangOptions &LangOpts, StringRef ModuleFilename, bool Complain, bool AllowCompatibleDifferences)
Receives the language options.
Definition ASTReader.h:135
virtual bool visitInputFileAsRequested(StringRef FilenameAsRequested, StringRef Filename, bool isSystem, bool isOverridden, time_t StoredTime, bool isExplicitModule)
Similiar to member function of visitInputFile but should be defined when there is a distinction betwe...
Definition ASTReader.h:255
virtual void visitImport(StringRef ModuleName, StringRef Filename)
If needsImportVisitation returns true, this is called for each AST file imported by this AST file.
Definition ASTReader.h:268
virtual void visitModuleFile(StringRef Filename, serialization::ModuleKind Kind)
This is called for each AST file loaded.
Definition ASTReader.h:227
virtual bool needsImportVisitation() const
Returns true if this ASTReaderListener wants to receive the imports of the AST file via visitImport,...
Definition ASTReader.h:264
virtual bool ReadFullVersionInformation(StringRef FullVersion)
Receives the full Clang version information.
Definition ASTReader.h:125
virtual void ReadModuleName(StringRef ModuleName)
Definition ASTReader.h:129
virtual void ReadCounter(const serialization::ModuleFile &M, uint32_t Value)
Receives COUNTER value.
Definition ASTReader.h:223
virtual bool needsSystemInputFileVisitation()
Returns true if this ASTReaderListener wants to receive the system input files of the AST file via vi...
Definition ASTReader.h:236
virtual bool ReadCodeGenOptions(const CodeGenOptions &CGOpts, StringRef ModuleFilename, bool Complain, bool AllowCompatibleDifferences)
Receives the codegen options.
Definition ASTReader.h:144
ListenerScope(ASTReader &Reader, std::unique_ptr< ASTReaderListener > L)
Definition ASTReader.h:1942
bool operator==(const ModuleDeclIterator &RHS) const
Definition ASTReader.h:1716
ModuleDeclIterator(ASTReader *Reader, ModuleFile *Mod, const serialization::unaligned_decl_id_t *Pos)
Definition ASTReader.h:1705
Reads an AST files chain containing the contents of a translation unit.
Definition ASTReader.h:430
std::optional< bool > isPreprocessedEntityInFileID(unsigned Index, FileID FID) override
Optionally returns true or false if the preallocated preprocessed entity with index Index came from f...
PreprocessedEntity * ReadPreprocessedEntity(unsigned Index) override
Read a preallocated preprocessed entity from the external source.
void markIdentifierUpToDate(const IdentifierInfo *II)
Note that this identifier is up-to-date.
void visitTopLevelModuleMaps(serialization::ModuleFile &MF, llvm::function_ref< void(FileEntryRef)> Visitor)
Visit all the top-level module maps loaded when building the given module file.
friend class ASTWriter
Definition ASTReader.h:438
void setDeserializationListener(ASTDeserializationListener *Listener, bool TakeOwnership=false)
Set the AST deserialization listener.
SmallVectorImpl< uint64_t > RecordDataImpl
Definition ASTReader.h:446
serialization::SubmoduleID getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID) const
Retrieve the global submodule ID given a module and its local ID number.
ExtKind hasExternalDefinitions(const Decl *D) override
IdentifierTable & getIdentifierTable()
Retrieve the identifier table associated with the preprocessor.
SourceLocationEncoding::RawLocEncoding RawLocEncoding
Definition ASTReader.h:2487
ModuleManager & getModuleManager()
Retrieve the module manager.
Definition ASTReader.h:2008
ASTReader & operator=(const ASTReader &)=delete
bool isDeclIDFromModule(GlobalDeclID ID, ModuleFile &M) const
Returns true if global DeclID ID originated from module M.
friend class ASTIdentifierIterator
Definition ASTReader.h:435
bool ReadSLocEntry(int ID) override
Read the source location entry with index ID.
void RecordSwitchCaseID(SwitchCase *SC, unsigned ID)
Record that the given ID maps to the given switch-case statement.
DiagnosticBuilder Diag(unsigned DiagID) const
Report a diagnostic.
unsigned getTotalNumPreprocessedEntities() const
Returns the number of preprocessed entities known to the AST reader.
Definition ASTReader.h:2113
ASTContext & getContext()
Retrieve the AST context that this AST reader supplements.
Definition ASTReader.h:2627
Decl * ReadDecl(ModuleFile &F, const RecordDataImpl &R, unsigned &I)
Reads a declaration from the given position in a record in the given module.
Definition ASTReader.h:2201
ModuleManager::ModuleIterator ModuleIterator
Definition ASTReader.h:479
static std::string ReadString(const RecordDataImpl &Record, unsigned &Idx)
void ReadDeclsToCheckForDeferredDiags(llvm::SmallSetVector< Decl *, 4 > &Decls) override
Read the set of decls to be checked for deferred diags.
void InitializeSema(Sema &S) override
Initialize the semantic source with the Sema instance being used to perform semantic analysis on the ...
LoadFailureCapabilities
Flags that indicate what kind of AST loading failures the client of the AST reader can directly handl...
Definition ASTReader.h:1844
@ ARR_Missing
The client can handle an AST file that cannot load because it is missing.
Definition ASTReader.h:1850
@ ARR_None
The client can't handle any AST loading failures.
Definition ASTReader.h:1846
@ ARR_ConfigurationMismatch
The client can handle an AST file that cannot load because it's compiled configuration doesn't match ...
Definition ASTReader.h:1863
@ ARR_OutOfDate
The client can handle an AST file that cannot load because it is out-of-date relative to its input fi...
Definition ASTReader.h:1854
@ ARR_TreatModuleWithErrorsAsOutOfDate
If a module file is marked with errors treat it as out-of-date so the caller can rebuild it.
Definition ASTReader.h:1867
@ ARR_VersionMismatch
The client can handle an AST file that cannot load because it was built with a different version of C...
Definition ASTReader.h:1858
void ReadMismatchingDeleteExpressions(llvm::MapVector< FieldDecl *, llvm::SmallVector< std::pair< SourceLocation, bool >, 4 > > &Exprs) override
void FindFileRegionDecls(FileID File, unsigned Offset, unsigned Length, SmallVectorImpl< Decl * > &Decls) override
Get the decls that are contained in a file in the Offset/Length range.
std::string ReadPathBlob(StringRef BaseDirectory, const RecordData &Record, unsigned &Idx, StringRef &Blob)
SourceRange ReadSkippedRange(unsigned Index) override
Read a preallocated skipped range from the external source.
serialization::TypeID getGlobalTypeID(ModuleFile &F, serialization::LocalTypeID LocalID) const
Map a local type ID within a given AST file into a global type ID.
const std::string & getSuggestedPredefines()
Returns the suggested contents of the predefines buffer, which contains a (typically-empty) subset of...
Definition ASTReader.h:2050
void dump()
Dump information about the AST reader to standard error.
MacroInfo * ReadMacroRecord(ModuleFile &F, uint64_t Offset)
Reads the macro record located at the given offset.
SmallVector< std::pair< llvm::BitstreamCursor, serialization::ModuleFile * >, 8 > CommentsCursors
Cursors for comments blocks.
Definition ASTReader.h:2661
Selector getLocalSelector(ModuleFile &M, unsigned LocalID)
Retrieve a selector from the given module with its local ID number.
void FindExternalLexicalDecls(const DeclContext *DC, llvm::function_ref< bool(Decl::Kind)> IsKindWeWant, SmallVectorImpl< Decl * > &Decls) override
Read all of the declarations lexically stored in a declaration context.
ModuleFile * getOwningModuleFile(const Decl *D) const
Retrieve the module file that owns the given declaration, or NULL if the declaration is not from a mo...
std::optional< ASTSourceDescriptor > getSourceDescriptor(unsigned ID) override
Return a descriptor for the corresponding module.
const serialization::reader::DeclContextLookupTable * getLoadedLookupTables(DeclContext *Primary) const
Get the loaded lookup tables for Primary, if any.
T * ReadDeclAs(ModuleFile &F, const RecordDataImpl &R, unsigned &I)
Reads a declaration from the given position in a record in the given module.
Definition ASTReader.h:2211
QualType getLocalType(ModuleFile &F, serialization::LocalTypeID LocalID)
Resolve a local type ID within a given AST file into a type.
friend class LocalDeclID
Definition ASTReader.h:443
Sema::AlignPackInfo ReadAlignPackInfo(uint32_t Raw) const
Read a AlignPackInfo from raw form.
Definition ASTReader.h:2483
QualType readType(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Read a type from the current position in the given record, which was read from the given AST file.
Definition ASTReader.h:2133
void SetGloballyVisibleDecls(IdentifierInfo *II, const SmallVectorImpl< GlobalDeclID > &DeclIDs, SmallVectorImpl< Decl * > *Decls=nullptr)
Set the globally-visible declarations associated with the given identifier.
serialization::ModuleKind ModuleKind
Definition ASTReader.h:477
bool loadGlobalIndex()
Attempts to load the global index.
void ReadComments() override
Loads comments ranges.
SourceManager & getSourceManager() const
Definition ASTReader.h:1834
const serialization::reader::ModuleLocalLookupTable * getModuleLocalLookupTables(DeclContext *Primary) const
SourceLocation getSourceLocationForDeclID(GlobalDeclID ID)
Returns the source location for the decl ID.
const CodeGenOptions & getCodeGenOpts() const
Definition ASTReader.h:1837
void makeModuleVisible(Module *Mod, Module::NameVisibilityKind NameVisibility, SourceLocation ImportLoc)
Make the entities in the given module and any of its (non-explicit) submodules visible to name lookup...
unsigned getTotalNumSubmodules() const
Returns the number of submodules known.
Definition ASTReader.h:2102
ASTReader(const ASTReader &)=delete
SourceRange ReadSourceRange(ModuleFile &F, const RecordData &Record, unsigned &Idx)
Read a source range.
bool LoadExternalSpecializations(const Decl *D, bool OnlyPartial) override
Load all the external specializations for the Decl.
void finalizeForWriting()
Finalizes the AST reader's state before writing an AST file to disk.
Sema * getSema()
Retrieve the semantic analysis object used to analyze the translation unit in which the precompiled h...
Definition ASTReader.h:2639
static std::string ResolveImportedPathAndAllocate(SmallString< 0 > &Buf, StringRef Path, ModuleFile &ModF)
Resolve Path in the context of module file M.
friend class ASTDeclMerger
Types of AST files.
Definition ASTReader.h:433
static StringRef ReadStringBlob(const RecordDataImpl &Record, unsigned &Idx, StringRef &Blob)
unsigned getTotalNumIdentifiers() const
Returns the number of identifiers found in the chain.
Definition ASTReader.h:2082
CXXCtorInitializer ** GetExternalCXXCtorInitializers(uint64_t Offset) override
Read the contents of a CXXCtorInitializer array.
void visitInputFileInfos(serialization::ModuleFile &MF, bool IncludeSystem, llvm::function_ref< void(const serialization::InputFileInfo &IFI, bool IsSystem)> Visitor)
Visit all the input file infos of the given module file.
const ModuleManager & getModuleManager() const
Definition ASTReader.h:2009
unsigned getTotalNumSLocs() const
Returns the number of source locations found in the chain.
Definition ASTReader.h:2077
void StartTranslationUnit(ASTConsumer *Consumer) override
Function that will be invoked when we begin parsing a new translation unit involving this external AS...
LocalDeclID mapGlobalIDToModuleFileGlobalID(ModuleFile &M, GlobalDeclID GlobalID)
Map a global declaration ID into the declaration ID used to refer to this declaration within the give...
void resolvePendingMacro(IdentifierInfo *II, const PendingMacroInfo &PMInfo)
void ReadTentativeDefinitions(SmallVectorImpl< VarDecl * > &TentativeDefs) override
Read the set of tentative definitions known to the external Sema source.
Decl * GetExternalDecl(GlobalDeclID ID) override
Resolve a declaration ID into a declaration, potentially building a new declaration.
serialization::MacroID ReadMacroID(ModuleFile &F, const RecordDataImpl &Record, unsigned &Idx)
Reads a macro ID from the given position in a record in the given module.
GlobalDeclID ReadDeclID(ModuleFile &F, const RecordDataImpl &Record, unsigned &Idx)
Reads a declaration ID from the given position in a record in the given module.
llvm::Expected< SourceLocation::UIntTy > readSLocOffset(ModuleFile *F, unsigned Index)
Try to read the offset of the SLocEntry at the given index in the given module file.
void forEachImportedKeyDecl(const Decl *D, Fn Visit)
Run a callback on each imported key declaration of D.
Definition ASTReader.h:1515
~ASTReader() override
bool haveUnloadedSpecializations(const Decl *D) const
If we have any unloaded specialization for D.
friend class TypeLocReader
Definition ASTReader.h:442
friend class PCHValidator
Definition ASTReader.h:439
Stmt * ReadSubStmt()
Reads a sub-statement operand during statement reading.
Definition ASTReader.h:2582
void CompleteRedeclChain(const Decl *D) override
If any redeclarations of D have been imported since it was last checked, this digs out those redeclar...
Expr * ReadSubExpr()
Reads a sub-expression operand during statement reading.
SourceLocation TranslateSourceLocation(ModuleFile &ModuleFile, SourceLocation Loc) const
Translate a source location from another module file's source location space into ours.
Definition ASTReader.h:2513
static llvm::Error ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID, uint64_t *StartOfBlockOffset=nullptr)
ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the specified cursor.
void SetIdentifierInfo(serialization::IdentifierID ID, IdentifierInfo *II)
std::pair< unsigned, unsigned > findPreprocessedEntitiesInRange(SourceRange Range) override
Returns a pair of [Begin, End) indices of preallocated preprocessed entities that Range encompasses.
IdentifierInfo * get(StringRef Name) override
Retrieve the IdentifierInfo for the named identifier.
IdentifierInfo * getLocalIdentifier(ModuleFile &M, uint64_t LocalID)
void visitInputFiles(serialization::ModuleFile &MF, bool IncludeSystem, bool Complain, llvm::function_ref< void(const serialization::InputFile &IF, bool isSystem)> Visitor)
Visit all the input files of the given module file.
Module * getModule(unsigned ID) override
Retrieve the module that corresponds to the given module ID.
friend class ASTDeclReader
Definition ASTReader.h:434
llvm::iterator_range< ModuleDeclIterator > getModuleFileLevelDecls(ModuleFile &Mod)
Stmt * GetExternalDeclStmt(uint64_t Offset) override
Resolve the offset of a statement into a statement.
Selector GetExternalSelector(serialization::SelectorID ID) override
Resolve a selector ID into a selector.
unsigned getTotalNumSelectors() const
Returns the number of selectors found in the chain.
Definition ASTReader.h:2107
MacroInfo * getMacro(serialization::MacroID ID)
Retrieve the macro with the given ID.
void ReadUndefinedButUsed(llvm::MapVector< NamedDecl *, SourceLocation > &Undefined) override
Load the set of used but not defined functions or variables with internal linkage,...
void ReadDelegatingConstructors(SmallVectorImpl< CXXConstructorDecl * > &Decls) override
Read the set of delegating constructors known to the external Sema source.
unsigned getTotalNumTypes() const
Returns the number of types found in the chain.
Definition ASTReader.h:2092
QualType GetType(serialization::TypeID ID)
Resolve a type ID into a type, potentially building a new type.
void addPendingMacro(IdentifierInfo *II, ModuleFile *M, uint32_t MacroDirectivesOffset)
Add a macro to deserialize its macro directive history.
GlobalDeclID getGlobalDeclID(ModuleFile &F, LocalDeclID LocalID) const
Map from a local declaration ID within a given module to a global declaration ID.
Expr * ReadExpr(ModuleFile &F)
Reads an expression.
void ReadWeakUndeclaredIdentifiers(SmallVectorImpl< std::pair< IdentifierInfo *, WeakInfo > > &WeakIDs) override
Read the set of weak, undeclared identifiers known to the external Sema source.
void completeVisibleDeclsMap(const DeclContext *DC) override
Load all external visible decls in the given DeclContext.
void AssignedLambdaNumbering(CXXRecordDecl *Lambda) override
Notify the external source that a lambda was assigned a mangling number.
void ReadUnusedLocalTypedefNameCandidates(llvm::SmallSetVector< const TypedefNameDecl *, 4 > &Decls) override
Read the set of potentially unused typedefs known to the source.
IdentifierResolver & getIdResolver()
Get the identifier resolver used for name lookup / updates in the translation unit scope.
static bool readASTFileControlBlock(StringRef Filename, FileManager &FileMgr, const ModuleCache &ModCache, const PCHContainerReader &PCHContainerRdr, bool FindModuleFileExtensions, ASTReaderListener &Listener, bool ValidateDiagnosticOptions, unsigned ClientLoadCapabilities=ARR_ConfigurationMismatch|ARR_OutOfDate)
Read the control block for the named AST file.
void ReadExtVectorDecls(SmallVectorImpl< TypedefNameDecl * > &Decls) override
Read the set of ext_vector type declarations known to the external Sema source.
SmallVector< GlobalDeclID, 16 > PreloadedDeclIDs
Definition ASTReader.h:2634
std::pair< SourceLocation, StringRef > getModuleImportLoc(int ID) override
Retrieve the module import location and module name for the given source manager entry ID.
void ReadUnusedFileScopedDecls(SmallVectorImpl< const DeclaratorDecl * > &Decls) override
Read the set of unused file-scope declarations known to the external Sema source.
void ReadReferencedSelectors(SmallVectorImpl< std::pair< Selector, SourceLocation > > &Sels) override
Read the set of referenced selectors known to the external Sema source.
Selector DecodeSelector(serialization::SelectorID Idx)
ASTReadResult ReadAST(StringRef FileName, ModuleKind Type, SourceLocation ImportLoc, unsigned ClientLoadCapabilities, ModuleFile **NewLoadedModuleFile=nullptr)
Load the AST file designated by the given file name.
StringRef getOriginalSourceFile()
Retrieve the name of the original source file name for the primary module file.
Definition ASTReader.h:2016
std::string ReadPath(ModuleFile &F, const RecordData &Record, unsigned &Idx)
ASTDeserializationListener * getDeserializationListener()
Get the AST deserialization listener.
Definition ASTReader.h:1966
void addListener(std::unique_ptr< ASTReaderListener > L)
Add an AST callback listener.
Definition ASTReader.h:1929
unsigned getModuleFileID(ModuleFile *M)
Get an ID for the given module file.
Decl * getKeyDeclaration(Decl *D)
Returns the first key declaration for the given declaration.
Definition ASTReader.h:1499
bool FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name, const DeclContext *OriginalDC) override
Finds all the visible declarations with a given name.
void setListener(std::unique_ptr< ASTReaderListener > Listener)
Set the AST callbacks listener.
Definition ASTReader.h:1922
Selector ReadSelector(ModuleFile &M, const RecordData &Record, unsigned &Idx)
Definition ASTReader.h:2470
ModuleManager::ModuleReverseIterator ModuleReverseIterator
Definition ASTReader.h:481
IdentifierInfo * DecodeIdentifierInfo(serialization::IdentifierID ID)
ASTReadResult
The result of reading the control block of an AST file, which can fail for various reasons.
Definition ASTReader.h:450
@ Success
The control block was read successfully.
Definition ASTReader.h:453
@ ConfigurationMismatch
The AST file was written with a different language/target configuration.
Definition ASTReader.h:470
@ OutOfDate
The AST file is out-of-date relative to its input files, and needs to be regenerated.
Definition ASTReader.h:463
@ Failure
The AST file itself appears corrupted.
Definition ASTReader.h:456
@ VersionMismatch
The AST file was written by a different version of Clang.
Definition ASTReader.h:466
@ HadErrors
The AST file has errors.
Definition ASTReader.h:473
@ Missing
The AST file was missing.
Definition ASTReader.h:459
void addInMemoryBuffer(StringRef &FileName, std::unique_ptr< llvm::MemoryBuffer > Buffer)
Add in-memory (virtual file) buffer.
Definition ASTReader.h:1995
static VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx)
Read a version tuple.
SmallString< 0 > & getPathBuf()
Get the buffer for resolving paths.
Definition ASTReader.h:1476
Token ReadToken(ModuleFile &M, const RecordDataImpl &Record, unsigned &Idx)
Reads a token out of a record.
SwitchCase * getSwitchCaseWithID(unsigned ID)
Retrieve the switch-case statement with the given ID.
serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M, uint64_t LocalID)
FileID TranslateFileID(ModuleFile &F, FileID FID) const
Translate a FileID from another module file's FileID space into ours.
Definition ASTReader.h:2541
void ReadLateParsedTemplates(llvm::MapVector< const FunctionDecl *, std::unique_ptr< LateParsedTemplate > > &LPTMap) override
Read the set of late parsed template functions for this source.
IdentifierIterator * getIdentifiers() override
Retrieve an iterator into the set of all identifiers in all loaded AST files.
serialization::ModuleManager ModuleManager
Definition ASTReader.h:478
void ReadUsedVTables(SmallVectorImpl< ExternalVTableUse > &VTables) override
Read the set of used vtables known to the external Sema source.
bool isGlobalIndexUnavailable() const
Determine whether we tried to load the global index, but failed, e.g., because it is out-of-date or d...
uint32_t GetNumExternalSelectors() override
Returns the number of selectors known to the external AST source.
static TemporarilyOwnedStringRef ResolveImportedPath(SmallString< 0 > &Buf, StringRef Path, ModuleFile &ModF)
Resolve Path in the context of module file M.
void updateOutOfDateSelector(Selector Sel) override
Load the contents of the global method pool for a given selector if necessary.
Decl * GetExistingDecl(GlobalDeclID ID)
Resolve a declaration ID into a declaration.
Stmt * ReadStmt(ModuleFile &F)
Reads a statement.
static llvm::BitVector ReadBitVector(const RecordData &Record, const StringRef Blob)
ModuleFile * getLocalModuleFile(ModuleFile &M, unsigned ID) const
Retrieve the module file with a given local ID within the specified ModuleFile.
SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, const RecordDataImpl &Record, unsigned &Idx)
Read a source location.
Definition ASTReader.h:2528
ASTReader(Preprocessor &PP, ModuleCache &ModCache, ASTContext *Context, const PCHContainerReader &PCHContainerRdr, const CodeGenOptions &CodeGenOpts, ArrayRef< std::shared_ptr< ModuleFileExtension > > Extensions, StringRef isysroot="", DisableValidationForModuleKind DisableValidationKind=DisableValidationForModuleKind::None, bool AllowASTWithCompilerErrors=false, bool AllowConfigurationMismatch=false, bool ValidateSystemInputs=false, bool ForceValidateUserInputs=true, bool ValidateASTInputFilesContent=false, bool UseGlobalIndex=true, std::unique_ptr< llvm::Timer > ReadTimer={})
Load the AST file and validate its contents against the given Preprocessor.
void ForgetSema() override
Inform the semantic consumer that Sema is no longer available.
Definition ASTReader.h:2305
DiagnosticsEngine & getDiags() const
Definition ASTReader.h:1836
void LoadSelector(Selector Sel)
Load a selector from disk, registering its ID if it exists.
void ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag)
void makeNamesVisible(const HiddenNames &Names, Module *Owner)
Make the names within this set of hidden names visible.
void UpdateSema()
Update the state of Sema after loading some additional modules.
Decl * GetDecl(GlobalDeclID ID)
Resolve a declaration ID into a declaration, potentially building a new declaration.
Decl * GetLocalDecl(ModuleFile &F, LocalDeclID LocalID)
Reads a declaration with the given local ID in the given module.
Definition ASTReader.h:2165
bool isProcessingUpdateRecords()
Definition ASTReader.h:2684
T * GetLocalDeclAs(ModuleFile &F, LocalDeclID LocalID)
Reads a declaration with the given local ID in the given module.
Definition ASTReader.h:2172
int getSLocEntryID(SourceLocation::UIntTy SLocOffset) override
Get the index ID for the loaded SourceLocation offset.
SourceLocation ReadSourceLocation(ModuleFile &MF, RawLocEncoding Raw) const
Read a source location from raw form.
Definition ASTReader.h:2497
void ReadPendingInstantiations(SmallVectorImpl< std::pair< ValueDecl *, SourceLocation > > &Pending) override
Read the set of pending instantiations known to the external Sema source.
Preprocessor & getPreprocessor() const
Retrieve the preprocessor.
Definition ASTReader.h:2012
ASTReadResult ReadASTCore(StringRef FileName, ModuleKind Type, SourceLocation ImportLoc, ModuleFile *ImportedBy, SmallVectorImpl< ImportedModule > &Loaded, off_t ExpectedSize, time_t ExpectedModTime, ASTFileSignature ExpectedSignature, unsigned ClientLoadCapabilities)
serialization::reader::LazySpecializationInfoLookupTable * getLoadedSpecializationsLookupTables(const Decl *D, bool IsPartial)
Get the loaded specializations lookup tables for D, if any.
CXXTemporary * ReadCXXTemporary(ModuleFile &F, const RecordData &Record, unsigned &Idx)
void ReadKnownNamespaces(SmallVectorImpl< NamespaceDecl * > &Namespaces) override
Load the set of namespaces that are known to the external source, which will be used during typo corr...
const Decl * getKeyDeclaration(const Decl *D)
Definition ASTReader.h:1509
ModuleManager::ModuleConstIterator ModuleConstIterator
Definition ASTReader.h:480
std::pair< SourceLocation, unsigned > ReadUntranslatedSourceLocation(RawLocEncoding Raw) const
Read a source location from raw form and return it in its originating module file's source location s...
Definition ASTReader.h:2492
Module * getSubmodule(serialization::SubmoduleID GlobalID)
Retrieve the submodule that corresponds to a global submodule ID.
void PrintStats() override
Print some statistics about AST usage.
static bool isAcceptableASTFile(StringRef Filename, FileManager &FileMgr, const ModuleCache &ModCache, const PCHContainerReader &PCHContainerRdr, const LangOptions &LangOpts, const CodeGenOptions &CGOpts, const TargetOptions &TargetOpts, const PreprocessorOptions &PPOpts, const HeaderSearchOptions &HSOpts, StringRef SpecificModuleCachePath, bool RequireStrictOptionMatches=false)
Determine whether the given AST file is acceptable to load into a translation unit with the given lan...
void mergeDefinitionVisibility(NamedDecl *Def, NamedDecl *MergedDef)
Note that MergedDef is a redefinition of the canonical definition Def, so Def should be visible whene...
serialization::SelectorID getGlobalSelectorID(ModuleFile &M, unsigned LocalID) const
Retrieve the global selector ID that corresponds to this the local selector ID in a given module.
void runWithSufficientStackSpace(SourceLocation Loc, llvm::function_ref< void()> Fn)
friend class ASTRecordReader
Definition ASTReader.h:436
SmallVector< uint64_t, 64 > RecordData
Definition ASTReader.h:445
unsigned getTotalNumMacros() const
Returns the number of macros found in the chain.
Definition ASTReader.h:2087
FileID ReadFileID(ModuleFile &F, const RecordDataImpl &Record, unsigned &Idx) const
Read a FileID.
Definition ASTReader.h:2535
void StartedDeserializing() override
Notify ASTReader that we started deserialization of a decl or type so until FinishedDeserializing is ...
serialization::MacroID getGlobalMacroID(ModuleFile &M, serialization::MacroID LocalID)
Retrieve the global macro ID corresponding to the given local ID within the given module file.
void ReadMethodPool(Selector Sel) override
Load the contents of the global method pool for a given selector.
void InitializeContext()
Initializes the ASTContext.
CXXBaseSpecifier * GetExternalCXXBaseSpecifiers(uint64_t Offset) override
Resolve the offset of a set of C++ base specifiers in the decl stream into an array of specifiers.
std::unique_ptr< ASTReaderListener > takeListener()
Take the AST callbacks listener.
Definition ASTReader.h:1917
const serialization::reader::DeclContextLookupTable * getTULocalLookupTables(DeclContext *Primary) const
void resetForReload()
Reset reader for a reload try.
Definition ASTReader.h:1977
FileManager & getFileManager() const
Definition ASTReader.h:1835
unsigned getTotalNumDecls() const
Returns the number of declarations found in the chain.
Definition ASTReader.h:2097
bool wasThisDeclarationADefinition(const FunctionDecl *FD) override
True if this function declaration was a definition before in its own module.
friend class ASTUnit
Definition ASTReader.h:437
void FinishedDeserializing() override
Notify ASTReader that we finished the deserialization of a decl or type.
IdentifierInfo * readIdentifier(ModuleFile &M, const RecordData &Record, unsigned &Idx)
Definition ASTReader.h:2393
void updateOutOfDateIdentifier(const IdentifierInfo &II) override
Update an out-of-date identifier.
void ReadDefinedMacros() override
Read the set of macros defined by this external macro source.
GlobalModuleIndex * getGlobalIndex()
Return global module index.
Definition ASTReader.h:1974
IdentifierInfo * GetIdentifier(serialization::IdentifierID ID) override
Return the identifier associated with the given ID number.
Definition ASTReader.h:2398
HeaderFileInfo GetHeaderFileInfo(FileEntryRef FE) override
Read the header file information for the given file entry.
serialization::ModuleFile ModuleFile
Definition ASTReader.h:476
bool hasGlobalIndex() const
Determine whether this AST reader has a global index.
Definition ASTReader.h:1971
serialization::PreprocessedEntityID getGlobalPreprocessedEntityID(ModuleFile &M, serialization::PreprocessedEntityID LocalID) const
Determine the global preprocessed entity ID that corresponds to the given local ID within the given m...
An object for streaming information from a record.
BitsUnpacker operator=(const BitsUnpacker &)=delete
uint32_t getNextBits(uint32_t Width)
Definition ASTReader.h:2712
void advance(uint32_t BitsWidth)
Definition ASTReader.h:2705
bool canGetNextNBits(uint32_t Width) const
Definition ASTReader.h:2720
BitsUnpacker(BitsUnpacker &&)=delete
BitsUnpacker(const BitsUnpacker &)=delete
void updateValue(uint32_t V)
Definition ASTReader.h:2700
BitsUnpacker operator=(BitsUnpacker &&)=delete
BitsUnpacker(uint32_t V)
Definition ASTReader.h:2693
~BitsUnpacker()=default
Represents a base class of a C++ class.
Definition DeclCXX.h:146
Represents a C++ base or member initializer.
Definition DeclCXX.h:2376
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
Represents a C++ temporary.
Definition ExprCXX.h:1460
Simple wrapper class for chaining listeners.
Definition ASTReader.h:276
void ReadCounter(const serialization::ModuleFile &M, uint32_t Value) override
Receives COUNTER value.
bool visitInputFile(StringRef Filename, bool isSystem, bool isOverridden, bool isExplicitModule) override
if needsInputFileVisitation returns true, this is called for each non-system input file of the AST Fi...
bool ReadCodeGenOptions(const CodeGenOptions &CGOpts, StringRef ModuleFilename, bool Complain, bool AllowCompatibleDifferences) override
Receives the codegen options.
std::unique_ptr< ASTReaderListener > takeSecond()
Definition ASTReader.h:287
bool ReadFullVersionInformation(StringRef FullVersion) override
Receives the full Clang version information.
bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, StringRef ModuleFilename, StringRef SpecificModuleCachePath, bool Complain) override
Receives the header search options.
bool ReadFileSystemOptions(const FileSystemOptions &FSOpts, bool Complain) override
Receives the file system options.
std::unique_ptr< ASTReaderListener > takeFirst()
Definition ASTReader.h:286
void ReadModuleMapFile(StringRef ModuleMapPath) override
bool ReadLanguageOptions(const LangOptions &LangOpts, StringRef ModuleFilename, bool Complain, bool AllowCompatibleDifferences) override
Receives the language options.
bool ReadTargetOptions(const TargetOptions &TargetOpts, StringRef ModuleFilename, bool Complain, bool AllowCompatibleDifferences) override
Receives the target options.
void ReadModuleName(StringRef ModuleName) override
bool needsInputFileVisitation() override
Returns true if this ASTReaderListener wants to receive the input files of the AST file via visitInpu...
bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, StringRef ModuleFilename, bool ReadMacros, bool Complain, std::string &SuggestedPredefines) override
Receives the preprocessor options.
ChainedASTReaderListener(std::unique_ptr< ASTReaderListener > First, std::unique_ptr< ASTReaderListener > Second)
Takes ownership of First and Second.
Definition ASTReader.h:282
void readModuleFileExtension(const ModuleFileExtensionMetadata &Metadata) override
Indicates that a particular module file extension has been read.
void visitModuleFile(StringRef Filename, serialization::ModuleKind Kind) override
This is called for each AST file loaded.
bool needsSystemInputFileVisitation() override
Returns true if this ASTReaderListener wants to receive the system input files of the AST file via vi...
bool ReadDiagnosticOptions(DiagnosticOptions &DiagOpts, StringRef ModuleFilename, bool Complain) override
Receives the diagnostic options.
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
A map from continuous integer ranges to some value, with a very specialized interface.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition DeclBase.h:1449
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
bool isFromGlobalModule() const
Whether this declaration comes from global module.
ASTContext & getASTContext() const LLVM_READONLY
Definition DeclBase.cpp:546
Kind
Lists the kind of concrete classes of Decl.
Definition DeclBase.h:89
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
Definition DeclBase.h:793
bool isFromHeaderUnit() const
Whether this declaration comes from a header unit.
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition DeclBase.h:978
The name of a declaration.
Represents a ValueDecl that came out of a declarator.
Definition Decl.h:780
A little helper class used to produce diagnostics.
Options for controlling the compiler diagnostics engine.
Concrete class used by the front-end to report problems and issues.
Definition Diagnostic.h:232
Represents an enum.
Definition Decl.h:4013
This represents one expression.
Definition Expr.h:112
RAII class for safely pairing a StartedDeserializing call with FinishedDeserializing.
MemoryBufferSizes getMemoryBufferSizes() const
Return the amount of memory used by memory buffers, breaking down by heap-backed versus mmap'ed memor...
An external source of header file information, which may supply information about header files alread...
An abstract class that should be subclassed by any external source of preprocessing record entries.
Abstract interface for external sources of preprocessor information.
External source of source location entries.
Represents a member of a struct/union/class.
Definition Decl.h:3160
A reference to a FileEntry that includes the name of the file as it was accessed by the FileManager's...
Definition FileEntry.h:57
Cached information about one file (either on disk or in the virtual file system).
Definition FileEntry.h:302
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
bool isInvalid() const
Implements support for file system lookup, file system caching, and directory search management.
Definition FileManager.h:53
Keeps track of options that affect how file operations are performed.
Represents a function declaration or definition.
Definition Decl.h:2000
A global index for a set of module files, providing information about the identifiers within those mo...
HeaderSearchOptions - Helper class for storing options related to the initialization of the HeaderSea...
Provides lookups to, and iteration over, IdentiferInfo objects.
One of these records is kept for each identifier that is lexed.
An iterator that walks over all of the known identifiers in the lookup table.
IdentifierResolver - Keeps track of shadowed decls on enclosing scopes.
Implements an efficient mapping from strings to IdentifierInfo nodes.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
static LocalDeclID get(ASTReader &Reader, serialization::ModuleFile &MF, DeclID ID)
Encapsulates the data about a macro definition (e.g.
Definition MacroInfo.h:39
The module cache used for compiling modules implicitly.
Definition ModuleCache.h:25
Describes a module or submodule.
Definition Module.h:144
NameVisibilityKind
Describes the visibility of the various names within a particular module.
Definition Module.h:443
This represents a decl that may have a name.
Definition Decl.h:274
Represent a C++ namespace.
Definition Decl.h:592
ObjCCategoryDecl - Represents a category declaration.
Definition DeclObjC.h:2329
Represents an ObjC class declaration.
Definition DeclObjC.h:1154
This abstract interface provides operations for unwrapping containers for serialized ASTs (precompile...
bool ReadDiagnosticOptions(DiagnosticOptions &DiagOpts, StringRef ModuleFilename, bool Complain) override
Receives the diagnostic options.
bool ReadLanguageOptions(const LangOptions &LangOpts, StringRef ModuleFilename, bool Complain, bool AllowCompatibleDifferences) override
Receives the language options.
bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts, StringRef ModuleFilename, StringRef SpecificModuleCachePath, bool Complain) override
Receives the header search options.
PCHValidator(Preprocessor &PP, ASTReader &Reader)
Definition ASTReader.h:333
void ReadCounter(const serialization::ModuleFile &M, uint32_t Value) override
Receives COUNTER value.
bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, StringRef ModuleFilename, bool ReadMacros, bool Complain, std::string &SuggestedPredefines) override
Receives the preprocessor options.
bool ReadCodeGenOptions(const CodeGenOptions &CGOpts, StringRef ModuleFilename, bool Complain, bool AllowCompatibleDifferences) override
Receives the codegen options.
bool ReadTargetOptions(const TargetOptions &TargetOpts, StringRef ModuleFilename, bool Complain, bool AllowCompatibleDifferences) override
Receives the target options.
Base class that describes a preprocessed entity, which may be a preprocessor directive or macro expan...
PreprocessorOptions - This class is used for passing the various options used in preprocessor initial...
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
A (possibly-)qualified type.
Definition TypeBase.h:937
Smart pointer class that efficiently represents Objective-C method names.
static AlignPackInfo getFromRawEncoding(unsigned Encoding)
Definition Sema.h:1897
Sema - This implements semantic analysis and AST building for C.
Definition Sema.h:868
SimpleASTReaderListener(Preprocessor &PP)
Definition ASTReader.h:366
bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, StringRef ModuleFilename, bool ReadMacros, bool Complain, std::string &SuggestedPredefines) override
Receives the preprocessor options.
static std::pair< SourceLocation, unsigned > decode(RawLocEncoding)
Encodes a location in the source.
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
Stmt - This represents one statement.
Definition Stmt.h:86
Options for controlling the target.
Token - This structure provides full information about a lexed token.
Definition Token.h:36
The base class of the type hierarchy.
Definition TypeBase.h:1839
Base class for declarations which introduce a typedef-name.
Definition Decl.h:3562
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Definition Decl.h:712
Represents a variable declaration or definition.
Definition Decl.h:926
The input file that has been loaded from this AST file, along with bools indicating whether this was ...
Definition ModuleFile.h:84
Information about a module that has been loaded by the ASTReader.
Definition ModuleFile.h:145
int SLocEntryBaseID
The base ID in the source manager's view of this module.
Definition ModuleFile.h:314
StringRef ModuleOffsetMap
The module offset map data for this file.
Definition ModuleFile.h:265
llvm::SmallVector< ModuleFile *, 16 > TransitiveImports
List of modules which this modules dependent on.
Definition ModuleFile.h:525
Manages the set of modules loaded by an AST reader.
llvm::pointee_iterator< SmallVectorImpl< std::unique_ptr< ModuleFile > >::iterator > ModuleIterator
llvm::pointee_iterator< SmallVectorImpl< std::unique_ptr< ModuleFile > >::const_iterator > ModuleConstIterator
llvm::pointee_iterator< SmallVectorImpl< std::unique_ptr< ModuleFile > >::reverse_iterator > ModuleReverseIterator
Class that performs lookup for an identifier stored in an AST file.
#define bool
Definition gpuintrin.h:32
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
uint32_t SelectorID
An ID number that refers to an ObjC selector in an AST file.
uint64_t PreprocessedEntityID
An ID number that refers to an entity in the detailed preprocessing record.
llvm::support::detail::packed_endian_specific_integral< serialization::DeclID, llvm::endianness::native, llvm::support::unaligned > unaligned_decl_id_t
uint64_t MacroID
An ID number that refers to a macro in an AST file.
uint64_t TypeID
An ID number that refers to a type in an AST file.
Definition ASTBitCodes.h:88
ModuleKind
Specifies the kind of module that has been loaded.
Definition ModuleFile.h:43
uint32_t SubmoduleID
An ID number that refers to a submodule in a module file.
TypeID LocalTypeID
Same with TypeID except that the LocalTypeID is only meaningful with the corresponding ModuleFile.
Definition ASTBitCodes.h:94
uint64_t IdentifierID
An ID number that refers to an identifier in an AST file.
Definition ASTBitCodes.h:63
The JSON file list parser is used to communicate input to InstallAPI.
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
Definition Linkage.h:54
PredefinedDeclIDs
Predefined declaration IDs.
Definition DeclID.h:31
@ Result
The result type of a method or function.
Definition TypeBase.h:905
DisableValidationForModuleKind
Whether to disable the normal validation performed on precompiled headers and module files when they ...
@ None
Perform validation, don't disable it.
bool shouldSkipCheckingODR(const Decl *D)
Definition ASTReader.h:2731
std::string getClangFullRepositoryVersion()
Retrieves the full repository version that is an amalgamation of the information in getClangRepositor...
Definition Version.cpp:68
UnsignedOrNone getPrimaryModuleHash(const Module *M)
Calculate a hash value for the primary module name of the given module.
unsigned long uint64_t
unsigned int uint32_t
The signature of a module, which is a hash of the AST content.
Definition Module.h:58
ImportedModule(ModuleFile *Mod, ModuleFile *ImportedBy, SourceLocation ImportLoc)
Definition ASTReader.h:1549
The preprocessor keeps track of this information for each file that is #included.
Metadata for a module file extension.
The input file info that has been loaded from an AST file.
Definition ModuleFile.h:64