1 //===- ASTReader.h - AST File Reader ----------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file defines the ASTReader class, which reads AST files.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_SERIALIZATION_ASTREADER_H
14 #define LLVM_CLANG_SERIALIZATION_ASTREADER_H
16 #include "clang/AST/DeclCXX.h"
17 #include "clang/AST/DeclObjC.h"
18 #include "clang/AST/DeclarationName.h"
19 #include "clang/AST/NestedNameSpecifier.h"
20 #include "clang/AST/OpenMPClause.h"
21 #include "clang/AST/TemplateBase.h"
22 #include "clang/AST/TemplateName.h"
23 #include "clang/AST/Type.h"
24 #include "clang/Basic/Diagnostic.h"
25 #include "clang/Basic/DiagnosticOptions.h"
26 #include "clang/Basic/IdentifierTable.h"
27 #include "clang/Basic/Module.h"
28 #include "clang/Basic/OpenCLOptions.h"
29 #include "clang/Basic/SourceLocation.h"
30 #include "clang/Basic/Version.h"
31 #include "clang/Lex/ExternalPreprocessorSource.h"
32 #include "clang/Lex/HeaderSearch.h"
33 #include "clang/Lex/PreprocessingRecord.h"
34 #include "clang/Lex/Token.h"
35 #include "clang/Sema/ExternalSemaSource.h"
36 #include "clang/Sema/IdentifierResolver.h"
37 #include "clang/Serialization/ASTBitCodes.h"
38 #include "clang/Serialization/ContinuousRangeMap.h"
39 #include "clang/Serialization/Module.h"
40 #include "clang/Serialization/ModuleFileExtension.h"
41 #include "clang/Serialization/ModuleManager.h"
42 #include "llvm/ADT/APFloat.h"
43 #include "llvm/ADT/APInt.h"
44 #include "llvm/ADT/APSInt.h"
45 #include "llvm/ADT/ArrayRef.h"
46 #include "llvm/ADT/DenseMap.h"
47 #include "llvm/ADT/DenseSet.h"
48 #include "llvm/ADT/IntrusiveRefCntPtr.h"
49 #include "llvm/ADT/MapVector.h"
50 #include "llvm/ADT/Optional.h"
51 #include "llvm/ADT/STLExtras.h"
52 #include "llvm/ADT/SetVector.h"
53 #include "llvm/ADT/SmallPtrSet.h"
54 #include "llvm/ADT/SmallVector.h"
55 #include "llvm/ADT/StringMap.h"
56 #include "llvm/ADT/StringRef.h"
57 #include "llvm/ADT/iterator.h"
58 #include "llvm/ADT/iterator_range.h"
59 #include "llvm/Bitstream/BitstreamReader.h"
60 #include "llvm/Support/Casting.h"
61 #include "llvm/Support/Endian.h"
62 #include "llvm/Support/MemoryBuffer.h"
63 #include "llvm/Support/Timer.h"
64 #include "llvm/Support/VersionTuple.h"
80 class ASTDeserializationListener;
82 class ASTRecordReader;
92 class FileSystemOptions;
94 class GlobalModuleIndex;
95 struct HeaderFileInfo;
96 class HeaderSearchOptions;
98 class LazyASTUnresolvedSet;
100 class InMemoryModuleCache;
103 class ObjCCategoryDecl;
104 class ObjCInterfaceDecl;
105 class PCHContainerReader;
107 class PreprocessorOptions;
108 struct QualifierInfo;
114 class TemplateParameterList;
115 class TypedefNameDecl;
116 class TypeSourceInfo;
120 /// Abstract interface for callback invocations by the ASTReader.
122 /// While reading an AST file, the ASTReader will call the methods of the
123 /// listener to pass on specific information. Some of the listener methods can
124 /// return true to indicate to the ASTReader that the information (and
125 /// consequently the AST file) is invalid.
126 class ASTReaderListener {
128 virtual ~ASTReaderListener();
130 /// Receives the full Clang version information.
132 /// \returns true to indicate that the version is invalid. Subclasses should
133 /// generally defer to this implementation.
134 virtual bool ReadFullVersionInformation(StringRef FullVersion) {
135 return FullVersion != getClangFullRepositoryVersion();
138 virtual void ReadModuleName(StringRef ModuleName) {}
139 virtual void ReadModuleMapFile(StringRef ModuleMapPath) {}
141 /// Receives the language options.
143 /// \returns true to indicate the options are invalid or false otherwise.
144 virtual bool ReadLanguageOptions(const LangOptions &LangOpts,
146 bool AllowCompatibleDifferences) {
150 /// Receives the target options.
152 /// \returns true to indicate the target options are invalid, or false
154 virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
155 bool AllowCompatibleDifferences) {
159 /// Receives the diagnostic options.
161 /// \returns true to indicate the diagnostic options are invalid, or false
164 ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
169 /// Receives the file system options.
171 /// \returns true to indicate the file system options are invalid, or false
173 virtual bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
178 /// Receives the header search options.
180 /// \returns true to indicate the header search options are invalid, or false
182 virtual bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
183 StringRef SpecificModuleCachePath,
188 /// Receives the preprocessor options.
190 /// \param SuggestedPredefines Can be filled in with the set of predefines
191 /// that are suggested by the preprocessor options. Typically only used when
192 /// loading a precompiled header.
194 /// \returns true to indicate the preprocessor options are invalid, or false
196 virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
198 std::string &SuggestedPredefines) {
202 /// Receives __COUNTER__ value.
203 virtual void ReadCounter(const serialization::ModuleFile &M,
206 /// This is called for each AST file loaded.
207 virtual void visitModuleFile(StringRef Filename,
208 serialization::ModuleKind Kind) {}
210 /// Returns true if this \c ASTReaderListener wants to receive the
211 /// input files of the AST file via \c visitInputFile, false otherwise.
212 virtual bool needsInputFileVisitation() { return false; }
214 /// Returns true if this \c ASTReaderListener wants to receive the
215 /// system input files of the AST file via \c visitInputFile, false otherwise.
216 virtual bool needsSystemInputFileVisitation() { return false; }
218 /// if \c needsInputFileVisitation returns true, this is called for
219 /// each non-system input file of the AST File. If
220 /// \c needsSystemInputFileVisitation is true, then it is called for all
221 /// system input files as well.
223 /// \returns true to continue receiving the next input file, false to stop.
224 virtual bool visitInputFile(StringRef Filename, bool isSystem,
225 bool isOverridden, bool isExplicitModule) {
229 /// Returns true if this \c ASTReaderListener wants to receive the
230 /// imports of the AST file via \c visitImport, false otherwise.
231 virtual bool needsImportVisitation() const { return false; }
233 /// If needsImportVisitation returns \c true, this is called for each
234 /// AST file imported by this AST file.
235 virtual void visitImport(StringRef ModuleName, StringRef Filename) {}
237 /// Indicates that a particular module file extension has been read.
238 virtual void readModuleFileExtension(
239 const ModuleFileExtensionMetadata &Metadata) {}
242 /// Simple wrapper class for chaining listeners.
243 class ChainedASTReaderListener : public ASTReaderListener {
244 std::unique_ptr<ASTReaderListener> First;
245 std::unique_ptr<ASTReaderListener> Second;
248 /// Takes ownership of \p First and \p Second.
249 ChainedASTReaderListener(std::unique_ptr<ASTReaderListener> First,
250 std::unique_ptr<ASTReaderListener> Second)
251 : First(std::move(First)), Second(std::move(Second)) {}
253 std::unique_ptr<ASTReaderListener> takeFirst() { return std::move(First); }
254 std::unique_ptr<ASTReaderListener> takeSecond() { return std::move(Second); }
256 bool ReadFullVersionInformation(StringRef FullVersion) override;
257 void ReadModuleName(StringRef ModuleName) override;
258 void ReadModuleMapFile(StringRef ModuleMapPath) override;
259 bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
260 bool AllowCompatibleDifferences) override;
261 bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
262 bool AllowCompatibleDifferences) override;
263 bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
264 bool Complain) override;
265 bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
266 bool Complain) override;
268 bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
269 StringRef SpecificModuleCachePath,
270 bool Complain) override;
271 bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
273 std::string &SuggestedPredefines) override;
275 void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
276 bool needsInputFileVisitation() override;
277 bool needsSystemInputFileVisitation() override;
278 void visitModuleFile(StringRef Filename,
279 serialization::ModuleKind Kind) override;
280 bool visitInputFile(StringRef Filename, bool isSystem,
281 bool isOverridden, bool isExplicitModule) override;
282 void readModuleFileExtension(
283 const ModuleFileExtensionMetadata &Metadata) override;
286 /// ASTReaderListener implementation to validate the information of
287 /// the PCH file against an initialized Preprocessor.
288 class PCHValidator : public ASTReaderListener {
293 PCHValidator(Preprocessor &PP, ASTReader &Reader)
294 : PP(PP), Reader(Reader) {}
296 bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
297 bool AllowCompatibleDifferences) override;
298 bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
299 bool AllowCompatibleDifferences) override;
300 bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
301 bool Complain) override;
302 bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain,
303 std::string &SuggestedPredefines) override;
304 bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
305 StringRef SpecificModuleCachePath,
306 bool Complain) override;
307 void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
310 void Error(const char *Msg);
313 /// ASTReaderListenter implementation to set SuggestedPredefines of
314 /// ASTReader which is required to use a pch file. This is the replacement
315 /// of PCHValidator or SimplePCHValidator when using a pch file without
317 class SimpleASTReaderListener : public ASTReaderListener {
321 SimpleASTReaderListener(Preprocessor &PP) : PP(PP) {}
323 bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain,
324 std::string &SuggestedPredefines) override;
327 namespace serialization {
329 class ReadMethodPoolVisitor;
333 class ASTIdentifierLookupTrait;
335 /// The on-disk hash table(s) used for DeclContext name lookup.
336 struct DeclContextLookupTable;
338 } // namespace reader
340 } // namespace serialization
342 /// Reads an AST files chain containing the contents of a translation
345 /// The ASTReader class reads bitstreams (produced by the ASTWriter
346 /// class) containing the serialized representation of a given
347 /// abstract syntax tree and its supporting data structures. An
348 /// instance of the ASTReader can be attached to an ASTContext object,
349 /// which will provide access to the contents of the AST files.
351 /// The AST reader provides lazy de-serialization of declarations, as
352 /// required when traversing the AST. Only those AST nodes that are
353 /// actually required will be de-serialized.
355 : public ExternalPreprocessorSource,
356 public ExternalPreprocessingRecordSource,
357 public ExternalHeaderFileInfoSource,
358 public ExternalSemaSource,
359 public IdentifierInfoLookup,
360 public ExternalSLocEntrySource
363 /// Types of AST files.
364 friend class ASTDeclReader;
365 friend class ASTIdentifierIterator;
366 friend class ASTRecordReader;
367 friend class ASTStmtReader;
368 friend class ASTUnit; // ASTUnit needs to remap source locations.
369 friend class ASTWriter;
370 friend class PCHValidator;
371 friend class serialization::reader::ASTIdentifierLookupTrait;
372 friend class serialization::ReadMethodPoolVisitor;
373 friend class TypeLocReader;
375 using RecordData = SmallVector<uint64_t, 64>;
376 using RecordDataImpl = SmallVectorImpl<uint64_t>;
378 /// The result of reading the control block of an AST file, which
379 /// can fail for various reasons.
381 /// The control block was read successfully. Aside from failures,
382 /// the AST file is safe to read into the current context.
385 /// The AST file itself appears corrupted.
388 /// The AST file was missing.
391 /// The AST file is out-of-date relative to its input files,
392 /// and needs to be regenerated.
395 /// The AST file was written by a different version of Clang.
398 /// The AST file was writtten with a different language/target
400 ConfigurationMismatch,
402 /// The AST file has errors.
406 using ModuleFile = serialization::ModuleFile;
407 using ModuleKind = serialization::ModuleKind;
408 using ModuleManager = serialization::ModuleManager;
409 using ModuleIterator = ModuleManager::ModuleIterator;
410 using ModuleConstIterator = ModuleManager::ModuleConstIterator;
411 using ModuleReverseIterator = ModuleManager::ModuleReverseIterator;
414 /// The receiver of some callbacks invoked by ASTReader.
415 std::unique_ptr<ASTReaderListener> Listener;
417 /// The receiver of deserialization events.
418 ASTDeserializationListener *DeserializationListener = nullptr;
420 bool OwnsDeserializationListener = false;
422 SourceManager &SourceMgr;
423 FileManager &FileMgr;
424 const PCHContainerReader &PCHContainerRdr;
425 DiagnosticsEngine &Diags;
427 /// The semantic analysis object that will be processing the
428 /// AST files and the translation unit that uses it.
429 Sema *SemaObj = nullptr;
431 /// The preprocessor that will be loading the source file.
434 /// The AST context into which we'll read the AST files.
435 ASTContext *ContextObj = nullptr;
437 /// The AST consumer.
438 ASTConsumer *Consumer = nullptr;
440 /// The module manager which manages modules and their dependencies
441 ModuleManager ModuleMgr;
443 /// A dummy identifier resolver used to merge TU-scope declarations in
444 /// C, for the cases where we don't have a Sema object to provide a real
445 /// identifier resolver.
446 IdentifierResolver DummyIdResolver;
448 /// A mapping from extension block names to module file extensions.
449 llvm::StringMap<std::shared_ptr<ModuleFileExtension>> ModuleFileExtensions;
451 /// A timer used to track the time spent deserializing.
452 std::unique_ptr<llvm::Timer> ReadTimer;
454 /// The location where the module file will be considered as
455 /// imported from. For non-module AST types it should be invalid.
456 SourceLocation CurrentImportLoc;
458 /// The global module index, if loaded.
459 std::unique_ptr<GlobalModuleIndex> GlobalIndex;
461 /// A map of global bit offsets to the module that stores entities
462 /// at those bit offsets.
463 ContinuousRangeMap<uint64_t, ModuleFile*, 4> GlobalBitOffsetsMap;
465 /// A map of negated SLocEntryIDs to the modules containing them.
466 ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocEntryMap;
468 using GlobalSLocOffsetMapType =
469 ContinuousRangeMap<unsigned, ModuleFile *, 64>;
471 /// A map of reversed (SourceManager::MaxLoadedOffset - SLocOffset)
472 /// SourceLocation offsets to the modules containing them.
473 GlobalSLocOffsetMapType GlobalSLocOffsetMap;
475 /// Types that have already been loaded from the chain.
477 /// When the pointer at index I is non-NULL, the type with
478 /// ID = (I + 1) << FastQual::Width has already been loaded
479 std::vector<QualType> TypesLoaded;
481 using GlobalTypeMapType =
482 ContinuousRangeMap<serialization::TypeID, ModuleFile *, 4>;
484 /// Mapping from global type IDs to the module in which the
485 /// type resides along with the offset that should be added to the
486 /// global type ID to produce a local ID.
487 GlobalTypeMapType GlobalTypeMap;
489 /// Declarations that have already been loaded from the chain.
491 /// When the pointer at index I is non-NULL, the declaration with ID
492 /// = I + 1 has already been loaded.
493 std::vector<Decl *> DeclsLoaded;
495 using GlobalDeclMapType =
496 ContinuousRangeMap<serialization::DeclID, ModuleFile *, 4>;
498 /// Mapping from global declaration IDs to the module in which the
499 /// declaration resides.
500 GlobalDeclMapType GlobalDeclMap;
502 using FileOffset = std::pair<ModuleFile *, uint64_t>;
503 using FileOffsetsTy = SmallVector<FileOffset, 2>;
504 using DeclUpdateOffsetsMap =
505 llvm::DenseMap<serialization::DeclID, FileOffsetsTy>;
507 /// Declarations that have modifications residing in a later file
509 DeclUpdateOffsetsMap DeclUpdateOffsets;
511 struct PendingUpdateRecord {
513 serialization::GlobalDeclID ID;
515 // Whether the declaration was just deserialized.
518 PendingUpdateRecord(serialization::GlobalDeclID ID, Decl *D,
520 : D(D), ID(ID), JustLoaded(JustLoaded) {}
523 /// Declaration updates for already-loaded declarations that we need
524 /// to apply once we finish processing an import.
525 llvm::SmallVector<PendingUpdateRecord, 16> PendingUpdateRecords;
527 enum class PendingFakeDefinitionKind { NotFake, Fake, FakeLoaded };
529 /// The DefinitionData pointers that we faked up for class definitions
530 /// that we needed but hadn't loaded yet.
531 llvm::DenseMap<void *, PendingFakeDefinitionKind> PendingFakeDefinitionData;
533 /// Exception specification updates that have been loaded but not yet
534 /// propagated across the relevant redeclaration chain. The map key is the
535 /// canonical declaration (used only for deduplication) and the value is a
536 /// declaration that has an exception specification.
537 llvm::SmallMapVector<Decl *, FunctionDecl *, 4> PendingExceptionSpecUpdates;
539 /// Deduced return type updates that have been loaded but not yet propagated
540 /// across the relevant redeclaration chain. The map key is the canonical
541 /// declaration and the value is the deduced return type.
542 llvm::SmallMapVector<FunctionDecl *, QualType, 4> PendingDeducedTypeUpdates;
544 /// Declarations that have been imported and have typedef names for
545 /// linkage purposes.
546 llvm::DenseMap<std::pair<DeclContext *, IdentifierInfo *>, NamedDecl *>
547 ImportedTypedefNamesForLinkage;
549 /// Mergeable declaration contexts that have anonymous declarations
550 /// within them, and those anonymous declarations.
551 llvm::DenseMap<Decl*, llvm::SmallVector<NamedDecl*, 2>>
552 AnonymousDeclarationsForMerging;
554 struct FileDeclsInfo {
555 ModuleFile *Mod = nullptr;
556 ArrayRef<serialization::LocalDeclID> Decls;
558 FileDeclsInfo() = default;
559 FileDeclsInfo(ModuleFile *Mod, ArrayRef<serialization::LocalDeclID> Decls)
560 : Mod(Mod), Decls(Decls) {}
563 /// Map from a FileID to the file-level declarations that it contains.
564 llvm::DenseMap<FileID, FileDeclsInfo> FileDeclIDs;
566 /// An array of lexical contents of a declaration context, as a sequence of
567 /// Decl::Kind, DeclID pairs.
568 using LexicalContents = ArrayRef<llvm::support::unaligned_uint32_t>;
570 /// Map from a DeclContext to its lexical contents.
571 llvm::DenseMap<const DeclContext*, std::pair<ModuleFile*, LexicalContents>>
574 /// Map from the TU to its lexical contents from each module file.
575 std::vector<std::pair<ModuleFile*, LexicalContents>> TULexicalDecls;
577 /// Map from a DeclContext to its lookup tables.
578 llvm::DenseMap<const DeclContext *,
579 serialization::reader::DeclContextLookupTable> Lookups;
581 // Updates for visible decls can occur for other contexts than just the
582 // TU, and when we read those update records, the actual context may not
583 // be available yet, so have this pending map using the ID as a key. It
584 // will be realized when the context is actually loaded.
585 struct PendingVisibleUpdate {
587 const unsigned char *Data;
589 using DeclContextVisibleUpdates = SmallVector<PendingVisibleUpdate, 1>;
591 /// Updates to the visible declarations of declaration contexts that
592 /// haven't been loaded yet.
593 llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates>
594 PendingVisibleUpdates;
596 /// The set of C++ or Objective-C classes that have forward
597 /// declarations that have not yet been linked to their definitions.
598 llvm::SmallPtrSet<Decl *, 4> PendingDefinitions;
600 using PendingBodiesMap =
601 llvm::MapVector<Decl *, uint64_t,
602 llvm::SmallDenseMap<Decl *, unsigned, 4>,
603 SmallVector<std::pair<Decl *, uint64_t>, 4>>;
605 /// Functions or methods that have bodies that will be attached.
606 PendingBodiesMap PendingBodies;
608 /// Definitions for which we have added merged definitions but not yet
609 /// performed deduplication.
610 llvm::SetVector<NamedDecl *> PendingMergedDefinitionsToDeduplicate;
612 /// Read the record that describes the lexical contents of a DC.
613 bool ReadLexicalDeclContextStorage(ModuleFile &M,
614 llvm::BitstreamCursor &Cursor,
615 uint64_t Offset, DeclContext *DC);
617 /// Read the record that describes the visible contents of a DC.
618 bool ReadVisibleDeclContextStorage(ModuleFile &M,
619 llvm::BitstreamCursor &Cursor,
620 uint64_t Offset, serialization::DeclID ID);
622 /// A vector containing identifiers that have already been
625 /// If the pointer at index I is non-NULL, then it refers to the
626 /// IdentifierInfo for the identifier with ID=I+1 that has already
628 std::vector<IdentifierInfo *> IdentifiersLoaded;
630 using GlobalIdentifierMapType =
631 ContinuousRangeMap<serialization::IdentID, ModuleFile *, 4>;
633 /// Mapping from global identifier IDs to the module in which the
634 /// identifier resides along with the offset that should be added to the
635 /// global identifier ID to produce a local ID.
636 GlobalIdentifierMapType GlobalIdentifierMap;
638 /// A vector containing macros that have already been
641 /// If the pointer at index I is non-NULL, then it refers to the
642 /// MacroInfo for the identifier with ID=I+1 that has already
644 std::vector<MacroInfo *> MacrosLoaded;
646 using LoadedMacroInfo =
647 std::pair<IdentifierInfo *, serialization::SubmoduleID>;
649 /// A set of #undef directives that we have loaded; used to
650 /// deduplicate the same #undef information coming from multiple module
652 llvm::DenseSet<LoadedMacroInfo> LoadedUndefs;
654 using GlobalMacroMapType =
655 ContinuousRangeMap<serialization::MacroID, ModuleFile *, 4>;
657 /// Mapping from global macro IDs to the module in which the
658 /// macro resides along with the offset that should be added to the
659 /// global macro ID to produce a local ID.
660 GlobalMacroMapType GlobalMacroMap;
662 /// A vector containing submodules that have already been loaded.
664 /// This vector is indexed by the Submodule ID (-1). NULL submodule entries
665 /// indicate that the particular submodule ID has not yet been loaded.
666 SmallVector<Module *, 2> SubmodulesLoaded;
668 using GlobalSubmoduleMapType =
669 ContinuousRangeMap<serialization::SubmoduleID, ModuleFile *, 4>;
671 /// Mapping from global submodule IDs to the module file in which the
672 /// submodule resides along with the offset that should be added to the
673 /// global submodule ID to produce a local ID.
674 GlobalSubmoduleMapType GlobalSubmoduleMap;
676 /// A set of hidden declarations.
677 using HiddenNames = SmallVector<Decl *, 2>;
678 using HiddenNamesMapType = llvm::DenseMap<Module *, HiddenNames>;
680 /// A mapping from each of the hidden submodules to the deserialized
681 /// declarations in that submodule that could be made visible.
682 HiddenNamesMapType HiddenNamesMap;
684 /// A module import, export, or conflict that hasn't yet been resolved.
685 struct UnresolvedModuleRef {
686 /// The file in which this module resides.
689 /// The module that is importing or exporting.
692 /// The kind of module reference.
693 enum { Import, Export, Conflict } Kind;
695 /// The local ID of the module that is being exported.
698 /// Whether this is a wildcard export.
699 unsigned IsWildcard : 1;
705 /// The set of module imports and exports that still need to be
707 SmallVector<UnresolvedModuleRef, 2> UnresolvedModuleRefs;
709 /// A vector containing selectors that have already been loaded.
711 /// This vector is indexed by the Selector ID (-1). NULL selector
712 /// entries indicate that the particular selector ID has not yet
714 SmallVector<Selector, 16> SelectorsLoaded;
716 using GlobalSelectorMapType =
717 ContinuousRangeMap<serialization::SelectorID, ModuleFile *, 4>;
719 /// Mapping from global selector IDs to the module in which the
720 /// global selector ID to produce a local ID.
721 GlobalSelectorMapType GlobalSelectorMap;
723 /// The generation number of the last time we loaded data from the
724 /// global method pool for this selector.
725 llvm::DenseMap<Selector, unsigned> SelectorGeneration;
727 /// Whether a selector is out of date. We mark a selector as out of date
728 /// if we load another module after the method pool entry was pulled in.
729 llvm::DenseMap<Selector, bool> SelectorOutOfDate;
731 struct PendingMacroInfo {
733 uint64_t MacroDirectivesOffset;
735 PendingMacroInfo(ModuleFile *M, uint64_t MacroDirectivesOffset)
736 : M(M), MacroDirectivesOffset(MacroDirectivesOffset) {}
739 using PendingMacroIDsMap =
740 llvm::MapVector<IdentifierInfo *, SmallVector<PendingMacroInfo, 2>>;
742 /// Mapping from identifiers that have a macro history to the global
743 /// IDs have not yet been deserialized to the global IDs of those macros.
744 PendingMacroIDsMap PendingMacroIDs;
746 using GlobalPreprocessedEntityMapType =
747 ContinuousRangeMap<unsigned, ModuleFile *, 4>;
749 /// Mapping from global preprocessing entity IDs to the module in
750 /// which the preprocessed entity resides along with the offset that should be
751 /// added to the global preprocessing entity ID to produce a local ID.
752 GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap;
754 using GlobalSkippedRangeMapType =
755 ContinuousRangeMap<unsigned, ModuleFile *, 4>;
757 /// Mapping from global skipped range base IDs to the module in which
758 /// the skipped ranges reside.
759 GlobalSkippedRangeMapType GlobalSkippedRangeMap;
761 /// \name CodeGen-relevant special data
762 /// Fields containing data that is relevant to CodeGen.
765 /// The IDs of all declarations that fulfill the criteria of
766 /// "interesting" decls.
768 /// This contains the data loaded from all EAGERLY_DESERIALIZED_DECLS blocks
769 /// in the chain. The referenced declarations are deserialized and passed to
770 /// the consumer eagerly.
771 SmallVector<uint64_t, 16> EagerlyDeserializedDecls;
773 /// The IDs of all tentative definitions stored in the chain.
775 /// Sema keeps track of all tentative definitions in a TU because it has to
776 /// complete them and pass them on to CodeGen. Thus, tentative definitions in
777 /// the PCH chain must be eagerly deserialized.
778 SmallVector<uint64_t, 16> TentativeDefinitions;
780 /// The IDs of all CXXRecordDecls stored in the chain whose VTables are
783 /// CodeGen has to emit VTables for these records, so they have to be eagerly
785 SmallVector<uint64_t, 64> VTableUses;
787 /// A snapshot of the pending instantiations in the chain.
789 /// This record tracks the instantiations that Sema has to perform at the
790 /// end of the TU. It consists of a pair of values for every pending
791 /// instantiation where the first value is the ID of the decl and the second
792 /// is the instantiation location.
793 SmallVector<uint64_t, 64> PendingInstantiations;
797 /// \name DiagnosticsEngine-relevant special data
798 /// Fields containing data that is used for generating diagnostics
801 /// A snapshot of Sema's unused file-scoped variable tracking, for
802 /// generating warnings.
803 SmallVector<uint64_t, 16> UnusedFileScopedDecls;
805 /// A list of all the delegating constructors we've seen, to diagnose
807 SmallVector<uint64_t, 4> DelegatingCtorDecls;
809 /// Method selectors used in a @selector expression. Used for
810 /// implementation of -Wselector.
811 SmallVector<uint64_t, 64> ReferencedSelectorsData;
813 /// A snapshot of Sema's weak undeclared identifier tracking, for
814 /// generating warnings.
815 SmallVector<uint64_t, 64> WeakUndeclaredIdentifiers;
817 /// The IDs of type aliases for ext_vectors that exist in the chain.
819 /// Used by Sema for finding sugared names for ext_vectors in diagnostics.
820 SmallVector<uint64_t, 4> ExtVectorDecls;
824 /// \name Sema-relevant special data
825 /// Fields containing data that is used for semantic analysis
828 /// The IDs of all potentially unused typedef names in the chain.
830 /// Sema tracks these to emit warnings.
831 SmallVector<uint64_t, 16> UnusedLocalTypedefNameCandidates;
833 /// Our current depth in #pragma cuda force_host_device begin/end
835 unsigned ForceCUDAHostDeviceDepth = 0;
837 /// The IDs of the declarations Sema stores directly.
839 /// Sema tracks a few important decls, such as namespace std, directly.
840 SmallVector<uint64_t, 4> SemaDeclRefs;
842 /// The IDs of the types ASTContext stores directly.
844 /// The AST context tracks a few important types, such as va_list, directly.
845 SmallVector<uint64_t, 16> SpecialTypes;
847 /// The IDs of CUDA-specific declarations ASTContext stores directly.
849 /// The AST context tracks a few important decls, currently cudaConfigureCall,
851 SmallVector<uint64_t, 2> CUDASpecialDeclRefs;
853 /// The floating point pragma option settings.
854 SmallVector<uint64_t, 1> FPPragmaOptions;
856 /// The pragma clang optimize location (if the pragma state is "off").
857 SourceLocation OptimizeOffPragmaLocation;
859 /// The PragmaMSStructKind pragma ms_struct state if set, or -1.
860 int PragmaMSStructState = -1;
862 /// The PragmaMSPointersToMembersKind pragma pointers_to_members state.
863 int PragmaMSPointersToMembersState = -1;
864 SourceLocation PointersToMembersPragmaLocation;
866 /// The pragma pack state.
867 Optional<unsigned> PragmaPackCurrentValue;
868 SourceLocation PragmaPackCurrentLocation;
869 struct PragmaPackStackEntry {
871 SourceLocation Location;
872 SourceLocation PushLocation;
875 llvm::SmallVector<PragmaPackStackEntry, 2> PragmaPackStack;
876 llvm::SmallVector<std::string, 2> PragmaPackStrings;
878 /// The OpenCL extension settings.
879 OpenCLOptions OpenCLExtensions;
881 /// Extensions required by an OpenCL type.
882 llvm::DenseMap<const Type *, std::set<std::string>> OpenCLTypeExtMap;
884 /// Extensions required by an OpenCL declaration.
885 llvm::DenseMap<const Decl *, std::set<std::string>> OpenCLDeclExtMap;
887 /// A list of the namespaces we've seen.
888 SmallVector<uint64_t, 4> KnownNamespaces;
890 /// A list of undefined decls with internal linkage followed by the
891 /// SourceLocation of a matching ODR-use.
892 SmallVector<uint64_t, 8> UndefinedButUsed;
894 /// Delete expressions to analyze at the end of translation unit.
895 SmallVector<uint64_t, 8> DelayedDeleteExprs;
897 // A list of late parsed template function data.
898 SmallVector<uint64_t, 1> LateParsedTemplates;
901 struct ImportedSubmodule {
902 serialization::SubmoduleID ID;
903 SourceLocation ImportLoc;
905 ImportedSubmodule(serialization::SubmoduleID ID, SourceLocation ImportLoc)
906 : ID(ID), ImportLoc(ImportLoc) {}
910 /// A list of modules that were imported by precompiled headers or
911 /// any other non-module AST file.
912 SmallVector<ImportedSubmodule, 2> ImportedModules;
915 /// The system include root to be used when loading the
916 /// precompiled header.
917 std::string isysroot;
919 /// Whether to disable the normal validation performed on precompiled
920 /// headers when they are loaded.
921 bool DisableValidation;
923 /// Whether to accept an AST file with compiler errors.
924 bool AllowASTWithCompilerErrors;
926 /// Whether to accept an AST file that has a different configuration
927 /// from the current compiler instance.
928 bool AllowConfigurationMismatch;
930 /// Whether validate system input files.
931 bool ValidateSystemInputs;
933 /// Whether validate headers and module maps using hash based on contents.
934 bool ValidateASTInputFilesContent;
936 /// Whether we are allowed to use the global module index.
939 /// Whether we have tried loading the global module index yet.
940 bool TriedLoadingGlobalIndex = false;
942 ///Whether we are currently processing update records.
943 bool ProcessingUpdateRecords = false;
945 using SwitchCaseMapTy = llvm::DenseMap<unsigned, SwitchCase *>;
947 /// Mapping from switch-case IDs in the chain to switch-case statements
949 /// Statements usually don't have IDs, but switch cases need them, so that the
950 /// switch statement can refer to them.
951 SwitchCaseMapTy SwitchCaseStmts;
953 SwitchCaseMapTy *CurrSwitchCaseStmts;
955 /// The number of source location entries de-serialized from
957 unsigned NumSLocEntriesRead = 0;
959 /// The number of source location entries in the chain.
960 unsigned TotalNumSLocEntries = 0;
962 /// The number of statements (and expressions) de-serialized
964 unsigned NumStatementsRead = 0;
966 /// The total number of statements (and expressions) stored
968 unsigned TotalNumStatements = 0;
970 /// The number of macros de-serialized from the chain.
971 unsigned NumMacrosRead = 0;
973 /// The total number of macros stored in the chain.
974 unsigned TotalNumMacros = 0;
976 /// The number of lookups into identifier tables.
977 unsigned NumIdentifierLookups = 0;
979 /// The number of lookups into identifier tables that succeed.
980 unsigned NumIdentifierLookupHits = 0;
982 /// The number of selectors that have been read.
983 unsigned NumSelectorsRead = 0;
985 /// The number of method pool entries that have been read.
986 unsigned NumMethodPoolEntriesRead = 0;
988 /// The number of times we have looked up a selector in the method
990 unsigned NumMethodPoolLookups = 0;
992 /// The number of times we have looked up a selector in the method
993 /// pool and found something.
994 unsigned NumMethodPoolHits = 0;
996 /// The number of times we have looked up a selector in the method
997 /// pool within a specific module.
998 unsigned NumMethodPoolTableLookups = 0;
1000 /// The number of times we have looked up a selector in the method
1001 /// pool within a specific module and found something.
1002 unsigned NumMethodPoolTableHits = 0;
1004 /// The total number of method pool entries in the selector table.
1005 unsigned TotalNumMethodPoolEntries = 0;
1007 /// Number of lexical decl contexts read/total.
1008 unsigned NumLexicalDeclContextsRead = 0, TotalLexicalDeclContexts = 0;
1010 /// Number of visible decl contexts read/total.
1011 unsigned NumVisibleDeclContextsRead = 0, TotalVisibleDeclContexts = 0;
1013 /// Total size of modules, in bits, currently loaded
1014 uint64_t TotalModulesSizeInBits = 0;
1016 /// Number of Decl/types that are currently deserializing.
1017 unsigned NumCurrentElementsDeserializing = 0;
1019 /// Set true while we are in the process of passing deserialized
1020 /// "interesting" decls to consumer inside FinishedDeserializing().
1021 /// This is used as a guard to avoid recursively repeating the process of
1022 /// passing decls to consumer.
1023 bool PassingDeclsToConsumer = false;
1025 /// The set of identifiers that were read while the AST reader was
1026 /// (recursively) loading declarations.
1028 /// The declarations on the identifier chain for these identifiers will be
1029 /// loaded once the recursive loading has completed.
1030 llvm::MapVector<IdentifierInfo *, SmallVector<uint32_t, 4>>
1031 PendingIdentifierInfos;
1033 /// The set of lookup results that we have faked in order to support
1034 /// merging of partially deserialized decls but that we have not yet removed.
1035 llvm::SmallMapVector<IdentifierInfo *, SmallVector<NamedDecl*, 2>, 16>
1036 PendingFakeLookupResults;
1038 /// The generation number of each identifier, which keeps track of
1039 /// the last time we loaded information about this identifier.
1040 llvm::DenseMap<IdentifierInfo *, unsigned> IdentifierGeneration;
1042 class InterestingDecl {
1044 bool DeclHasPendingBody;
1047 InterestingDecl(Decl *D, bool HasBody)
1048 : D(D), DeclHasPendingBody(HasBody) {}
1050 Decl *getDecl() { return D; }
1052 /// Whether the declaration has a pending body.
1053 bool hasPendingBody() { return DeclHasPendingBody; }
1056 /// Contains declarations and definitions that could be
1057 /// "interesting" to the ASTConsumer, when we get that AST consumer.
1059 /// "Interesting" declarations are those that have data that may
1060 /// need to be emitted, such as inline function definitions or
1061 /// Objective-C protocols.
1062 std::deque<InterestingDecl> PotentiallyInterestingDecls;
1064 /// The list of deduced function types that we have not yet read, because
1065 /// they might contain a deduced return type that refers to a local type
1066 /// declared within the function.
1067 SmallVector<std::pair<FunctionDecl *, serialization::TypeID>, 16>
1068 PendingFunctionTypes;
1070 /// The list of redeclaration chains that still need to be
1071 /// reconstructed, and the local offset to the corresponding list
1072 /// of redeclarations.
1073 SmallVector<std::pair<Decl *, uint64_t>, 16> PendingDeclChains;
1075 /// The list of canonical declarations whose redeclaration chains
1076 /// need to be marked as incomplete once we're done deserializing things.
1077 SmallVector<Decl *, 16> PendingIncompleteDeclChains;
1079 /// The Decl IDs for the Sema/Lexical DeclContext of a Decl that has
1080 /// been loaded but its DeclContext was not set yet.
1081 struct PendingDeclContextInfo {
1083 serialization::GlobalDeclID SemaDC;
1084 serialization::GlobalDeclID LexicalDC;
1087 /// The set of Decls that have been loaded but their DeclContexts are
1090 /// The DeclContexts for these Decls will be set once recursive loading has
1092 std::deque<PendingDeclContextInfo> PendingDeclContextInfos;
1094 /// The set of NamedDecls that have been loaded, but are members of a
1095 /// context that has been merged into another context where the corresponding
1096 /// declaration is either missing or has not yet been loaded.
1098 /// We will check whether the corresponding declaration is in fact missing
1099 /// once recursing loading has been completed.
1100 llvm::SmallVector<NamedDecl *, 16> PendingOdrMergeChecks;
1102 using DataPointers =
1103 std::pair<CXXRecordDecl *, struct CXXRecordDecl::DefinitionData *>;
1105 /// Record definitions in which we found an ODR violation.
1106 llvm::SmallDenseMap<CXXRecordDecl *, llvm::SmallVector<DataPointers, 2>, 2>
1107 PendingOdrMergeFailures;
1109 /// Function definitions in which we found an ODR violation.
1110 llvm::SmallDenseMap<FunctionDecl *, llvm::SmallVector<FunctionDecl *, 2>, 2>
1111 PendingFunctionOdrMergeFailures;
1113 /// Enum definitions in which we found an ODR violation.
1114 llvm::SmallDenseMap<EnumDecl *, llvm::SmallVector<EnumDecl *, 2>, 2>
1115 PendingEnumOdrMergeFailures;
1117 /// DeclContexts in which we have diagnosed an ODR violation.
1118 llvm::SmallPtrSet<DeclContext*, 2> DiagnosedOdrMergeFailures;
1120 /// The set of Objective-C categories that have been deserialized
1121 /// since the last time the declaration chains were linked.
1122 llvm::SmallPtrSet<ObjCCategoryDecl *, 16> CategoriesDeserialized;
1124 /// The set of Objective-C class definitions that have already been
1125 /// loaded, for which we will need to check for categories whenever a new
1126 /// module is loaded.
1127 SmallVector<ObjCInterfaceDecl *, 16> ObjCClassesLoaded;
1130 llvm::DenseMap<Decl *, SmallVector<serialization::DeclID, 2>>;
1132 /// A mapping from canonical declarations to the set of global
1133 /// declaration IDs for key declaration that have been merged with that
1134 /// canonical declaration. A key declaration is a formerly-canonical
1135 /// declaration whose module did not import any other key declaration for that
1136 /// entity. These are the IDs that we use as keys when finding redecl chains.
1137 KeyDeclsMap KeyDecls;
1139 /// A mapping from DeclContexts to the semantic DeclContext that we
1140 /// are treating as the definition of the entity. This is used, for instance,
1141 /// when merging implicit instantiations of class templates across modules.
1142 llvm::DenseMap<DeclContext *, DeclContext *> MergedDeclContexts;
1144 /// A mapping from canonical declarations of enums to their canonical
1145 /// definitions. Only populated when using modules in C++.
1146 llvm::DenseMap<EnumDecl *, EnumDecl *> EnumDefinitions;
1148 /// When reading a Stmt tree, Stmt operands are placed in this stack.
1149 SmallVector<Stmt *, 16> StmtStack;
1151 /// What kind of records we are reading.
1153 Read_None, Read_Decl, Read_Type, Read_Stmt
1156 /// What kind of records we are reading.
1157 ReadingKind ReadingKind = Read_None;
1159 /// RAII object to change the reading kind.
1160 class ReadingKindTracker {
1162 enum ReadingKind PrevKind;
1165 ReadingKindTracker(enum ReadingKind newKind, ASTReader &reader)
1166 : Reader(reader), PrevKind(Reader.ReadingKind) {
1167 Reader.ReadingKind = newKind;
1170 ReadingKindTracker(const ReadingKindTracker &) = delete;
1171 ReadingKindTracker &operator=(const ReadingKindTracker &) = delete;
1172 ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; }
1175 /// RAII object to mark the start of processing updates.
1176 class ProcessingUpdatesRAIIObj {
1181 ProcessingUpdatesRAIIObj(ASTReader &reader)
1182 : Reader(reader), PrevState(Reader.ProcessingUpdateRecords) {
1183 Reader.ProcessingUpdateRecords = true;
1186 ProcessingUpdatesRAIIObj(const ProcessingUpdatesRAIIObj &) = delete;
1187 ProcessingUpdatesRAIIObj &
1188 operator=(const ProcessingUpdatesRAIIObj &) = delete;
1189 ~ProcessingUpdatesRAIIObj() { Reader.ProcessingUpdateRecords = PrevState; }
1192 /// Suggested contents of the predefines buffer, after this
1193 /// PCH file has been processed.
1195 /// In most cases, this string will be empty, because the predefines
1196 /// buffer computed to build the PCH file will be identical to the
1197 /// predefines buffer computed from the command line. However, when
1198 /// there are differences that the PCH reader can work around, this
1199 /// predefines buffer may contain additional definitions.
1200 std::string SuggestedPredefines;
1202 llvm::DenseMap<const Decl *, bool> DefinitionSource;
1204 /// Reads a statement from the specified cursor.
1205 Stmt *ReadStmtFromStream(ModuleFile &F);
1207 struct InputFileInfo {
1208 std::string Filename;
1209 uint64_t ContentHash;
1214 bool TopLevelModuleMap;
1217 /// Reads the stored information about an input file.
1218 InputFileInfo readInputFileInfo(ModuleFile &F, unsigned ID);
1220 /// Retrieve the file entry and 'overridden' bit for an input
1221 /// file in the given module file.
1222 serialization::InputFile getInputFile(ModuleFile &F, unsigned ID,
1223 bool Complain = true);
1226 void ResolveImportedPath(ModuleFile &M, std::string &Filename);
1227 static void ResolveImportedPath(std::string &Filename, StringRef Prefix);
1229 /// Returns the first key declaration for the given declaration. This
1230 /// is one that is formerly-canonical (or still canonical) and whose module
1231 /// did not import any other key declaration of the entity.
1232 Decl *getKeyDeclaration(Decl *D) {
1233 D = D->getCanonicalDecl();
1234 if (D->isFromASTFile())
1237 auto I = KeyDecls.find(D);
1238 if (I == KeyDecls.end() || I->second.empty())
1240 return GetExistingDecl(I->second[0]);
1242 const Decl *getKeyDeclaration(const Decl *D) {
1243 return getKeyDeclaration(const_cast<Decl*>(D));
1246 /// Run a callback on each imported key declaration of \p D.
1247 template <typename Fn>
1248 void forEachImportedKeyDecl(const Decl *D, Fn Visit) {
1249 D = D->getCanonicalDecl();
1250 if (D->isFromASTFile())
1253 auto It = KeyDecls.find(const_cast<Decl*>(D));
1254 if (It != KeyDecls.end())
1255 for (auto ID : It->second)
1256 Visit(GetExistingDecl(ID));
1259 /// Get the loaded lookup tables for \p Primary, if any.
1260 const serialization::reader::DeclContextLookupTable *
1261 getLoadedLookupTables(DeclContext *Primary) const;
1264 struct ImportedModule {
1266 ModuleFile *ImportedBy;
1267 SourceLocation ImportLoc;
1269 ImportedModule(ModuleFile *Mod,
1270 ModuleFile *ImportedBy,
1271 SourceLocation ImportLoc)
1272 : Mod(Mod), ImportedBy(ImportedBy), ImportLoc(ImportLoc) {}
1275 ASTReadResult ReadASTCore(StringRef FileName, ModuleKind Type,
1276 SourceLocation ImportLoc, ModuleFile *ImportedBy,
1277 SmallVectorImpl<ImportedModule> &Loaded,
1278 off_t ExpectedSize, time_t ExpectedModTime,
1279 ASTFileSignature ExpectedSignature,
1280 unsigned ClientLoadCapabilities);
1281 ASTReadResult ReadControlBlock(ModuleFile &F,
1282 SmallVectorImpl<ImportedModule> &Loaded,
1283 const ModuleFile *ImportedBy,
1284 unsigned ClientLoadCapabilities);
1285 static ASTReadResult ReadOptionsBlock(
1286 llvm::BitstreamCursor &Stream, unsigned ClientLoadCapabilities,
1287 bool AllowCompatibleConfigurationMismatch, ASTReaderListener &Listener,
1288 std::string &SuggestedPredefines);
1290 /// Read the unhashed control block.
1292 /// This has no effect on \c F.Stream, instead creating a fresh cursor from
1293 /// \c F.Data and reading ahead.
1294 ASTReadResult readUnhashedControlBlock(ModuleFile &F, bool WasImportedBy,
1295 unsigned ClientLoadCapabilities);
1297 static ASTReadResult
1298 readUnhashedControlBlockImpl(ModuleFile *F, llvm::StringRef StreamData,
1299 unsigned ClientLoadCapabilities,
1300 bool AllowCompatibleConfigurationMismatch,
1301 ASTReaderListener *Listener,
1302 bool ValidateDiagnosticOptions);
1304 ASTReadResult ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities);
1305 ASTReadResult ReadExtensionBlock(ModuleFile &F);
1306 void ReadModuleOffsetMap(ModuleFile &F) const;
1307 bool ParseLineTable(ModuleFile &F, const RecordData &Record);
1308 bool ReadSourceManagerBlock(ModuleFile &F);
1309 llvm::BitstreamCursor &SLocCursorForID(int ID);
1310 SourceLocation getImportLocation(ModuleFile *F);
1311 ASTReadResult ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F,
1312 const ModuleFile *ImportedBy,
1313 unsigned ClientLoadCapabilities);
1314 ASTReadResult ReadSubmoduleBlock(ModuleFile &F,
1315 unsigned ClientLoadCapabilities);
1316 static bool ParseLanguageOptions(const RecordData &Record, bool Complain,
1317 ASTReaderListener &Listener,
1318 bool AllowCompatibleDifferences);
1319 static bool ParseTargetOptions(const RecordData &Record, bool Complain,
1320 ASTReaderListener &Listener,
1321 bool AllowCompatibleDifferences);
1322 static bool ParseDiagnosticOptions(const RecordData &Record, bool Complain,
1323 ASTReaderListener &Listener);
1324 static bool ParseFileSystemOptions(const RecordData &Record, bool Complain,
1325 ASTReaderListener &Listener);
1326 static bool ParseHeaderSearchOptions(const RecordData &Record, bool Complain,
1327 ASTReaderListener &Listener);
1328 static bool ParsePreprocessorOptions(const RecordData &Record, bool Complain,
1329 ASTReaderListener &Listener,
1330 std::string &SuggestedPredefines);
1332 struct RecordLocation {
1336 RecordLocation(ModuleFile *M, uint64_t O) : F(M), Offset(O) {}
1339 QualType readTypeRecord(unsigned Index);
1340 void readExceptionSpec(ModuleFile &ModuleFile,
1341 SmallVectorImpl<QualType> &ExceptionStorage,
1342 FunctionProtoType::ExceptionSpecInfo &ESI,
1343 const RecordData &Record, unsigned &Index);
1344 RecordLocation TypeCursorForIndex(unsigned Index);
1345 void LoadedDecl(unsigned Index, Decl *D);
1346 Decl *ReadDeclRecord(serialization::DeclID ID);
1347 void markIncompleteDeclChain(Decl *Canon);
1349 /// Returns the most recent declaration of a declaration (which must be
1350 /// of a redeclarable kind) that is either local or has already been loaded
1351 /// merged into its redecl chain.
1352 Decl *getMostRecentExistingDecl(Decl *D);
1354 RecordLocation DeclCursorForID(serialization::DeclID ID,
1355 SourceLocation &Location);
1356 void loadDeclUpdateRecords(PendingUpdateRecord &Record);
1357 void loadPendingDeclChain(Decl *D, uint64_t LocalOffset);
1358 void loadObjCCategories(serialization::GlobalDeclID ID, ObjCInterfaceDecl *D,
1359 unsigned PreviousGeneration = 0);
1361 RecordLocation getLocalBitOffset(uint64_t GlobalOffset);
1362 uint64_t getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset);
1364 /// Returns the first preprocessed entity ID that begins or ends after
1366 serialization::PreprocessedEntityID
1367 findPreprocessedEntity(SourceLocation Loc, bool EndsAfter) const;
1369 /// Find the next module that contains entities and return the ID
1370 /// of the first entry.
1372 /// \param SLocMapI points at a chunk of a module that contains no
1373 /// preprocessed entities or the entities it contains are not the
1374 /// ones we are looking for.
1375 serialization::PreprocessedEntityID
1376 findNextPreprocessedEntity(
1377 GlobalSLocOffsetMapType::const_iterator SLocMapI) const;
1379 /// Returns (ModuleFile, Local index) pair for \p GlobalIndex of a
1380 /// preprocessed entity.
1381 std::pair<ModuleFile *, unsigned>
1382 getModulePreprocessedEntity(unsigned GlobalIndex);
1384 /// Returns (begin, end) pair for the preprocessed entities of a
1385 /// particular module.
1386 llvm::iterator_range<PreprocessingRecord::iterator>
1387 getModulePreprocessedEntities(ModuleFile &Mod) const;
1390 class ModuleDeclIterator
1391 : public llvm::iterator_adaptor_base<
1392 ModuleDeclIterator, const serialization::LocalDeclID *,
1393 std::random_access_iterator_tag, const Decl *, ptrdiff_t,
1394 const Decl *, const Decl *> {
1395 ASTReader *Reader = nullptr;
1396 ModuleFile *Mod = nullptr;
1399 ModuleDeclIterator() : iterator_adaptor_base(nullptr) {}
1401 ModuleDeclIterator(ASTReader *Reader, ModuleFile *Mod,
1402 const serialization::LocalDeclID *Pos)
1403 : iterator_adaptor_base(Pos), Reader(Reader), Mod(Mod) {}
1405 value_type operator*() const {
1406 return Reader->GetDecl(Reader->getGlobalDeclID(*Mod, *I));
1409 value_type operator->() const { return **this; }
1411 bool operator==(const ModuleDeclIterator &RHS) const {
1412 assert(Reader == RHS.Reader && Mod == RHS.Mod);
1417 llvm::iterator_range<ModuleDeclIterator>
1418 getModuleFileLevelDecls(ModuleFile &Mod);
1421 void PassInterestingDeclsToConsumer();
1422 void PassInterestingDeclToConsumer(Decl *D);
1424 void finishPendingActions();
1425 void diagnoseOdrViolations();
1427 void pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name);
1429 void addPendingDeclContextInfo(Decl *D,
1430 serialization::GlobalDeclID SemaDC,
1431 serialization::GlobalDeclID LexicalDC) {
1433 PendingDeclContextInfo Info = { D, SemaDC, LexicalDC };
1434 PendingDeclContextInfos.push_back(Info);
1437 /// Produce an error diagnostic and return true.
1439 /// This routine should only be used for fatal errors that have to
1440 /// do with non-routine failures (e.g., corrupted AST file).
1441 void Error(StringRef Msg) const;
1442 void Error(unsigned DiagID, StringRef Arg1 = StringRef(),
1443 StringRef Arg2 = StringRef()) const;
1444 void Error(unsigned DiagID, StringRef Arg1, StringRef Arg2,
1445 unsigned Select) const;
1446 void Error(llvm::Error &&Err) const;
1449 /// Load the AST file and validate its contents against the given
1452 /// \param PP the preprocessor associated with the context in which this
1453 /// precompiled header will be loaded.
1455 /// \param Context the AST context that this precompiled header will be
1456 /// loaded into, if any.
1458 /// \param PCHContainerRdr the PCHContainerOperations to use for loading and
1459 /// creating modules.
1461 /// \param Extensions the list of module file extensions that can be loaded
1462 /// from the AST files.
1464 /// \param isysroot If non-NULL, the system include path specified by the
1465 /// user. This is only used with relocatable PCH files. If non-NULL,
1466 /// a relocatable PCH file will use the default path "/".
1468 /// \param DisableValidation If true, the AST reader will suppress most
1469 /// of its regular consistency checking, allowing the use of precompiled
1470 /// headers that cannot be determined to be compatible.
1472 /// \param AllowASTWithCompilerErrors If true, the AST reader will accept an
1473 /// AST file the was created out of an AST with compiler errors,
1474 /// otherwise it will reject it.
1476 /// \param AllowConfigurationMismatch If true, the AST reader will not check
1477 /// for configuration differences between the AST file and the invocation.
1479 /// \param ValidateSystemInputs If true, the AST reader will validate
1480 /// system input files in addition to user input files. This is only
1481 /// meaningful if \p DisableValidation is false.
1483 /// \param UseGlobalIndex If true, the AST reader will try to load and use
1484 /// the global module index.
1486 /// \param ReadTimer If non-null, a timer used to track the time spent
1488 ASTReader(Preprocessor &PP, InMemoryModuleCache &ModuleCache,
1489 ASTContext *Context, const PCHContainerReader &PCHContainerRdr,
1490 ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
1491 StringRef isysroot = "", bool DisableValidation = false,
1492 bool AllowASTWithCompilerErrors = false,
1493 bool AllowConfigurationMismatch = false,
1494 bool ValidateSystemInputs = false,
1495 bool ValidateASTInputFilesContent = false,
1496 bool UseGlobalIndex = true,
1497 std::unique_ptr<llvm::Timer> ReadTimer = {});
1498 ASTReader(const ASTReader &) = delete;
1499 ASTReader &operator=(const ASTReader &) = delete;
1500 ~ASTReader() override;
1502 SourceManager &getSourceManager() const { return SourceMgr; }
1503 FileManager &getFileManager() const { return FileMgr; }
1504 DiagnosticsEngine &getDiags() const { return Diags; }
1506 /// Flags that indicate what kind of AST loading failures the client
1507 /// of the AST reader can directly handle.
1509 /// When a client states that it can handle a particular kind of failure,
1510 /// the AST reader will not emit errors when producing that kind of failure.
1511 enum LoadFailureCapabilities {
1512 /// The client can't handle any AST loading failures.
1515 /// The client can handle an AST file that cannot load because it
1519 /// The client can handle an AST file that cannot load because it
1520 /// is out-of-date relative to its input files.
1521 ARR_OutOfDate = 0x2,
1523 /// The client can handle an AST file that cannot load because it
1524 /// was built with a different version of Clang.
1525 ARR_VersionMismatch = 0x4,
1527 /// The client can handle an AST file that cannot load because it's
1528 /// compiled configuration doesn't match that of the context it was
1530 ARR_ConfigurationMismatch = 0x8
1533 /// Load the AST file designated by the given file name.
1535 /// \param FileName The name of the AST file to load.
1537 /// \param Type The kind of AST being loaded, e.g., PCH, module, main file,
1540 /// \param ImportLoc the location where the module file will be considered as
1541 /// imported from. For non-module AST types it should be invalid.
1543 /// \param ClientLoadCapabilities The set of client load-failure
1544 /// capabilities, represented as a bitset of the enumerators of
1545 /// LoadFailureCapabilities.
1547 /// \param Imported optional out-parameter to append the list of modules
1548 /// that were imported by precompiled headers or any other non-module AST file
1549 ASTReadResult ReadAST(StringRef FileName, ModuleKind Type,
1550 SourceLocation ImportLoc,
1551 unsigned ClientLoadCapabilities,
1552 SmallVectorImpl<ImportedSubmodule> *Imported = nullptr);
1554 /// Make the entities in the given module and any of its (non-explicit)
1555 /// submodules visible to name lookup.
1557 /// \param Mod The module whose names should be made visible.
1559 /// \param NameVisibility The level of visibility to give the names in the
1560 /// module. Visibility can only be increased over time.
1562 /// \param ImportLoc The location at which the import occurs.
1563 void makeModuleVisible(Module *Mod,
1564 Module::NameVisibilityKind NameVisibility,
1565 SourceLocation ImportLoc);
1567 /// Make the names within this set of hidden names visible.
1568 void makeNamesVisible(const HiddenNames &Names, Module *Owner);
1570 /// Note that MergedDef is a redefinition of the canonical definition
1571 /// Def, so Def should be visible whenever MergedDef is.
1572 void mergeDefinitionVisibility(NamedDecl *Def, NamedDecl *MergedDef);
1574 /// Take the AST callbacks listener.
1575 std::unique_ptr<ASTReaderListener> takeListener() {
1576 return std::move(Listener);
1579 /// Set the AST callbacks listener.
1580 void setListener(std::unique_ptr<ASTReaderListener> Listener) {
1581 this->Listener = std::move(Listener);
1584 /// Add an AST callback listener.
1586 /// Takes ownership of \p L.
1587 void addListener(std::unique_ptr<ASTReaderListener> L) {
1589 L = std::make_unique<ChainedASTReaderListener>(std::move(L),
1590 std::move(Listener));
1591 Listener = std::move(L);
1594 /// RAII object to temporarily add an AST callback listener.
1595 class ListenerScope {
1597 bool Chained = false;
1600 ListenerScope(ASTReader &Reader, std::unique_ptr<ASTReaderListener> L)
1602 auto Old = Reader.takeListener();
1605 L = std::make_unique<ChainedASTReaderListener>(std::move(L),
1608 Reader.setListener(std::move(L));
1612 auto New = Reader.takeListener();
1614 Reader.setListener(static_cast<ChainedASTReaderListener *>(New.get())
1619 /// Set the AST deserialization listener.
1620 void setDeserializationListener(ASTDeserializationListener *Listener,
1621 bool TakeOwnership = false);
1623 /// Get the AST deserialization listener.
1624 ASTDeserializationListener *getDeserializationListener() {
1625 return DeserializationListener;
1628 /// Determine whether this AST reader has a global index.
1629 bool hasGlobalIndex() const { return (bool)GlobalIndex; }
1631 /// Return global module index.
1632 GlobalModuleIndex *getGlobalIndex() { return GlobalIndex.get(); }
1634 /// Reset reader for a reload try.
1635 void resetForReload() { TriedLoadingGlobalIndex = false; }
1637 /// Attempts to load the global index.
1639 /// \returns true if loading the global index has failed for any reason.
1640 bool loadGlobalIndex();
1642 /// Determine whether we tried to load the global index, but failed,
1643 /// e.g., because it is out-of-date or does not exist.
1644 bool isGlobalIndexUnavailable() const;
1646 /// Initializes the ASTContext
1647 void InitializeContext();
1649 /// Update the state of Sema after loading some additional modules.
1652 /// Add in-memory (virtual file) buffer.
1653 void addInMemoryBuffer(StringRef &FileName,
1654 std::unique_ptr<llvm::MemoryBuffer> Buffer) {
1655 ModuleMgr.addInMemoryBuffer(FileName, std::move(Buffer));
1658 /// Finalizes the AST reader's state before writing an AST file to
1661 /// This operation may undo temporary state in the AST that should not be
1663 void finalizeForWriting();
1665 /// Retrieve the module manager.
1666 ModuleManager &getModuleManager() { return ModuleMgr; }
1668 /// Retrieve the preprocessor.
1669 Preprocessor &getPreprocessor() const { return PP; }
1671 /// Retrieve the name of the original source file name for the primary
1673 StringRef getOriginalSourceFile() {
1674 return ModuleMgr.getPrimaryModule().OriginalSourceFileName;
1677 /// Retrieve the name of the original source file name directly from
1678 /// the AST file, without actually loading the AST file.
1680 getOriginalSourceFile(const std::string &ASTFileName, FileManager &FileMgr,
1681 const PCHContainerReader &PCHContainerRdr,
1682 DiagnosticsEngine &Diags);
1684 /// Read the control block for the named AST file.
1686 /// \returns true if an error occurred, false otherwise.
1688 readASTFileControlBlock(StringRef Filename, FileManager &FileMgr,
1689 const PCHContainerReader &PCHContainerRdr,
1690 bool FindModuleFileExtensions,
1691 ASTReaderListener &Listener,
1692 bool ValidateDiagnosticOptions);
1694 /// Determine whether the given AST file is acceptable to load into a
1695 /// translation unit with the given language and target options.
1696 static bool isAcceptableASTFile(StringRef Filename, FileManager &FileMgr,
1697 const PCHContainerReader &PCHContainerRdr,
1698 const LangOptions &LangOpts,
1699 const TargetOptions &TargetOpts,
1700 const PreprocessorOptions &PPOpts,
1701 StringRef ExistingModuleCachePath);
1703 /// Returns the suggested contents of the predefines buffer,
1704 /// which contains a (typically-empty) subset of the predefines
1705 /// build prior to including the precompiled header.
1706 const std::string &getSuggestedPredefines() { return SuggestedPredefines; }
1708 /// Read a preallocated preprocessed entity from the external source.
1710 /// \returns null if an error occurred that prevented the preprocessed
1711 /// entity from being loaded.
1712 PreprocessedEntity *ReadPreprocessedEntity(unsigned Index) override;
1714 /// Returns a pair of [Begin, End) indices of preallocated
1715 /// preprocessed entities that \p Range encompasses.
1716 std::pair<unsigned, unsigned>
1717 findPreprocessedEntitiesInRange(SourceRange Range) override;
1719 /// Optionally returns true or false if the preallocated preprocessed
1720 /// entity with index \p Index came from file \p FID.
1721 Optional<bool> isPreprocessedEntityInFileID(unsigned Index,
1722 FileID FID) override;
1724 /// Read a preallocated skipped range from the external source.
1725 SourceRange ReadSkippedRange(unsigned Index) override;
1727 /// Read the header file information for the given file entry.
1728 HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE) override;
1730 void ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag);
1732 /// Returns the number of source locations found in the chain.
1733 unsigned getTotalNumSLocs() const {
1734 return TotalNumSLocEntries;
1737 /// Returns the number of identifiers found in the chain.
1738 unsigned getTotalNumIdentifiers() const {
1739 return static_cast<unsigned>(IdentifiersLoaded.size());
1742 /// Returns the number of macros found in the chain.
1743 unsigned getTotalNumMacros() const {
1744 return static_cast<unsigned>(MacrosLoaded.size());
1747 /// Returns the number of types found in the chain.
1748 unsigned getTotalNumTypes() const {
1749 return static_cast<unsigned>(TypesLoaded.size());
1752 /// Returns the number of declarations found in the chain.
1753 unsigned getTotalNumDecls() const {
1754 return static_cast<unsigned>(DeclsLoaded.size());
1757 /// Returns the number of submodules known.
1758 unsigned getTotalNumSubmodules() const {
1759 return static_cast<unsigned>(SubmodulesLoaded.size());
1762 /// Returns the number of selectors found in the chain.
1763 unsigned getTotalNumSelectors() const {
1764 return static_cast<unsigned>(SelectorsLoaded.size());
1767 /// Returns the number of preprocessed entities known to the AST
1769 unsigned getTotalNumPreprocessedEntities() const {
1770 unsigned Result = 0;
1771 for (const auto &M : ModuleMgr)
1772 Result += M.NumPreprocessedEntities;
1776 /// Reads a TemplateArgumentLocInfo appropriate for the
1777 /// given TemplateArgument kind.
1778 TemplateArgumentLocInfo
1779 GetTemplateArgumentLocInfo(ModuleFile &F, TemplateArgument::ArgKind Kind,
1780 const RecordData &Record, unsigned &Idx);
1782 /// Reads a TemplateArgumentLoc.
1784 ReadTemplateArgumentLoc(ModuleFile &F,
1785 const RecordData &Record, unsigned &Idx);
1787 const ASTTemplateArgumentListInfo*
1788 ReadASTTemplateArgumentListInfo(ModuleFile &F,
1789 const RecordData &Record, unsigned &Index);
1791 /// Reads a declarator info from the given record.
1792 TypeSourceInfo *GetTypeSourceInfo(ModuleFile &F,
1793 const RecordData &Record, unsigned &Idx);
1795 /// Raad the type locations for the given TInfo.
1796 void ReadTypeLoc(ModuleFile &F, const RecordData &Record, unsigned &Idx,
1799 /// Resolve a type ID into a type, potentially building a new
1801 QualType GetType(serialization::TypeID ID);
1803 /// Resolve a local type ID within a given AST file into a type.
1804 QualType getLocalType(ModuleFile &F, unsigned LocalID);
1806 /// Map a local type ID within a given AST file into a global type ID.
1807 serialization::TypeID getGlobalTypeID(ModuleFile &F, unsigned LocalID) const;
1809 /// Read a type from the current position in the given record, which
1810 /// was read from the given AST file.
1811 QualType readType(ModuleFile &F, const RecordData &Record, unsigned &Idx) {
1812 if (Idx >= Record.size())
1815 return getLocalType(F, Record[Idx++]);
1818 /// Map from a local declaration ID within a given module to a
1819 /// global declaration ID.
1820 serialization::DeclID getGlobalDeclID(ModuleFile &F,
1821 serialization::LocalDeclID LocalID) const;
1823 /// Returns true if global DeclID \p ID originated from module \p M.
1824 bool isDeclIDFromModule(serialization::GlobalDeclID ID, ModuleFile &M) const;
1826 /// Retrieve the module file that owns the given declaration, or NULL
1827 /// if the declaration is not from a module file.
1828 ModuleFile *getOwningModuleFile(const Decl *D);
1830 /// Get the best name we know for the module that owns the given
1831 /// declaration, or an empty string if the declaration is not from a module.
1832 std::string getOwningModuleNameForDiagnostic(const Decl *D);
1834 /// Returns the source location for the decl \p ID.
1835 SourceLocation getSourceLocationForDeclID(serialization::GlobalDeclID ID);
1837 /// Resolve a declaration ID into a declaration, potentially
1838 /// building a new declaration.
1839 Decl *GetDecl(serialization::DeclID ID);
1840 Decl *GetExternalDecl(uint32_t ID) override;
1842 /// Resolve a declaration ID into a declaration. Return 0 if it's not
1843 /// been loaded yet.
1844 Decl *GetExistingDecl(serialization::DeclID ID);
1846 /// Reads a declaration with the given local ID in the given module.
1847 Decl *GetLocalDecl(ModuleFile &F, uint32_t LocalID) {
1848 return GetDecl(getGlobalDeclID(F, LocalID));
1851 /// Reads a declaration with the given local ID in the given module.
1853 /// \returns The requested declaration, casted to the given return type.
1854 template<typename T>
1855 T *GetLocalDeclAs(ModuleFile &F, uint32_t LocalID) {
1856 return cast_or_null<T>(GetLocalDecl(F, LocalID));
1859 /// Map a global declaration ID into the declaration ID used to
1860 /// refer to this declaration within the given module fule.
1862 /// \returns the global ID of the given declaration as known in the given
1864 serialization::DeclID
1865 mapGlobalIDToModuleFileGlobalID(ModuleFile &M,
1866 serialization::DeclID GlobalID);
1868 /// Reads a declaration ID from the given position in a record in the
1871 /// \returns The declaration ID read from the record, adjusted to a global ID.
1872 serialization::DeclID ReadDeclID(ModuleFile &F, const RecordData &Record,
1875 /// Reads a declaration from the given position in a record in the
1877 Decl *ReadDecl(ModuleFile &F, const RecordData &R, unsigned &I) {
1878 return GetDecl(ReadDeclID(F, R, I));
1881 /// Reads a declaration from the given position in a record in the
1884 /// \returns The declaration read from this location, casted to the given
1886 template<typename T>
1887 T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1888 return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1891 /// If any redeclarations of \p D have been imported since it was
1892 /// last checked, this digs out those redeclarations and adds them to the
1893 /// redeclaration chain for \p D.
1894 void CompleteRedeclChain(const Decl *D) override;
1896 CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override;
1898 /// Resolve the offset of a statement into a statement.
1900 /// This operation will read a new statement from the external
1901 /// source each time it is called, and is meant to be used via a
1902 /// LazyOffsetPtr (which is used by Decls for the body of functions, etc).
1903 Stmt *GetExternalDeclStmt(uint64_t Offset) override;
1905 /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the
1906 /// specified cursor. Read the abbreviations that are at the top of the block
1907 /// and then leave the cursor pointing into the block.
1908 static bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID);
1910 /// Finds all the visible declarations with a given name.
1911 /// The current implementation of this method just loads the entire
1912 /// lookup table as unmaterialized references.
1913 bool FindExternalVisibleDeclsByName(const DeclContext *DC,
1914 DeclarationName Name) override;
1916 /// Read all of the declarations lexically stored in a
1917 /// declaration context.
1919 /// \param DC The declaration context whose declarations will be
1922 /// \param IsKindWeWant A predicate indicating which declaration kinds
1923 /// we are interested in.
1925 /// \param Decls Vector that will contain the declarations loaded
1926 /// from the external source. The caller is responsible for merging
1927 /// these declarations with any declarations already stored in the
1928 /// declaration context.
1930 FindExternalLexicalDecls(const DeclContext *DC,
1931 llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
1932 SmallVectorImpl<Decl *> &Decls) override;
1934 /// Get the decls that are contained in a file in the Offset/Length
1935 /// range. \p Length can be 0 to indicate a point at \p Offset instead of
1937 void FindFileRegionDecls(FileID File, unsigned Offset, unsigned Length,
1938 SmallVectorImpl<Decl *> &Decls) override;
1940 /// Notify ASTReader that we started deserialization of
1941 /// a decl or type so until FinishedDeserializing is called there may be
1942 /// decls that are initializing. Must be paired with FinishedDeserializing.
1943 void StartedDeserializing() override;
1945 /// Notify ASTReader that we finished the deserialization of
1946 /// a decl or type. Must be paired with StartedDeserializing.
1947 void FinishedDeserializing() override;
1949 /// Function that will be invoked when we begin parsing a new
1950 /// translation unit involving this external AST source.
1952 /// This function will provide all of the external definitions to
1953 /// the ASTConsumer.
1954 void StartTranslationUnit(ASTConsumer *Consumer) override;
1956 /// Print some statistics about AST usage.
1957 void PrintStats() override;
1959 /// Dump information about the AST reader to standard error.
1962 /// Return the amount of memory used by memory buffers, breaking down
1963 /// by heap-backed versus mmap'ed memory.
1964 void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override;
1966 /// Initialize the semantic source with the Sema instance
1967 /// being used to perform semantic analysis on the abstract syntax
1969 void InitializeSema(Sema &S) override;
1971 /// Inform the semantic consumer that Sema is no longer available.
1972 void ForgetSema() override { SemaObj = nullptr; }
1974 /// Retrieve the IdentifierInfo for the named identifier.
1976 /// This routine builds a new IdentifierInfo for the given identifier. If any
1977 /// declarations with this name are visible from translation unit scope, their
1978 /// declarations will be deserialized and introduced into the declaration
1979 /// chain of the identifier.
1980 IdentifierInfo *get(StringRef Name) override;
1982 /// Retrieve an iterator into the set of all identifiers
1983 /// in all loaded AST files.
1984 IdentifierIterator *getIdentifiers() override;
1986 /// Load the contents of the global method pool for a given
1988 void ReadMethodPool(Selector Sel) override;
1990 /// Load the contents of the global method pool for a given
1991 /// selector if necessary.
1992 void updateOutOfDateSelector(Selector Sel) override;
1994 /// Load the set of namespaces that are known to the external source,
1995 /// which will be used during typo correction.
1996 void ReadKnownNamespaces(
1997 SmallVectorImpl<NamespaceDecl *> &Namespaces) override;
1999 void ReadUndefinedButUsed(
2000 llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) override;
2002 void ReadMismatchingDeleteExpressions(llvm::MapVector<
2003 FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &
2006 void ReadTentativeDefinitions(
2007 SmallVectorImpl<VarDecl *> &TentativeDefs) override;
2009 void ReadUnusedFileScopedDecls(
2010 SmallVectorImpl<const DeclaratorDecl *> &Decls) override;
2012 void ReadDelegatingConstructors(
2013 SmallVectorImpl<CXXConstructorDecl *> &Decls) override;
2015 void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) override;
2017 void ReadUnusedLocalTypedefNameCandidates(
2018 llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) override;
2020 void ReadReferencedSelectors(
2021 SmallVectorImpl<std::pair<Selector, SourceLocation>> &Sels) override;
2023 void ReadWeakUndeclaredIdentifiers(
2024 SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo>> &WI) override;
2026 void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) override;
2028 void ReadPendingInstantiations(
2029 SmallVectorImpl<std::pair<ValueDecl *,
2030 SourceLocation>> &Pending) override;
2032 void ReadLateParsedTemplates(
2033 llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
2036 /// Load a selector from disk, registering its ID if it exists.
2037 void LoadSelector(Selector Sel);
2039 void SetIdentifierInfo(unsigned ID, IdentifierInfo *II);
2040 void SetGloballyVisibleDecls(IdentifierInfo *II,
2041 const SmallVectorImpl<uint32_t> &DeclIDs,
2042 SmallVectorImpl<Decl *> *Decls = nullptr);
2044 /// Report a diagnostic.
2045 DiagnosticBuilder Diag(unsigned DiagID) const;
2047 /// Report a diagnostic.
2048 DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const;
2050 IdentifierInfo *DecodeIdentifierInfo(serialization::IdentifierID ID);
2052 IdentifierInfo *GetIdentifierInfo(ModuleFile &M, const RecordData &Record,
2054 return DecodeIdentifierInfo(getGlobalIdentifierID(M, Record[Idx++]));
2057 IdentifierInfo *GetIdentifier(serialization::IdentifierID ID) override {
2058 // Note that we are loading an identifier.
2059 Deserializing AnIdentifier(this);
2061 return DecodeIdentifierInfo(ID);
2064 IdentifierInfo *getLocalIdentifier(ModuleFile &M, unsigned LocalID);
2066 serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M,
2069 void resolvePendingMacro(IdentifierInfo *II, const PendingMacroInfo &PMInfo);
2071 /// Retrieve the macro with the given ID.
2072 MacroInfo *getMacro(serialization::MacroID ID);
2074 /// Retrieve the global macro ID corresponding to the given local
2075 /// ID within the given module file.
2076 serialization::MacroID getGlobalMacroID(ModuleFile &M, unsigned LocalID);
2078 /// Read the source location entry with index ID.
2079 bool ReadSLocEntry(int ID) override;
2081 /// Retrieve the module import location and module name for the
2082 /// given source manager entry ID.
2083 std::pair<SourceLocation, StringRef> getModuleImportLoc(int ID) override;
2085 /// Retrieve the global submodule ID given a module and its local ID
2087 serialization::SubmoduleID
2088 getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID);
2090 /// Retrieve the submodule that corresponds to a global submodule ID.
2092 Module *getSubmodule(serialization::SubmoduleID GlobalID);
2094 /// Retrieve the module that corresponds to the given module ID.
2096 /// Note: overrides method in ExternalASTSource
2097 Module *getModule(unsigned ID) override;
2099 bool DeclIsFromPCHWithObjectFile(const Decl *D) override;
2101 /// Retrieve the module file with a given local ID within the specified
2103 ModuleFile *getLocalModuleFile(ModuleFile &M, unsigned ID);
2105 /// Get an ID for the given module file.
2106 unsigned getModuleFileID(ModuleFile *M);
2108 /// Return a descriptor for the corresponding module.
2109 llvm::Optional<ASTSourceDescriptor> getSourceDescriptor(unsigned ID) override;
2111 ExtKind hasExternalDefinitions(const Decl *D) override;
2113 /// Retrieve a selector from the given module with its local ID
2115 Selector getLocalSelector(ModuleFile &M, unsigned LocalID);
2117 Selector DecodeSelector(serialization::SelectorID Idx);
2119 Selector GetExternalSelector(serialization::SelectorID ID) override;
2120 uint32_t GetNumExternalSelectors() override;
2122 Selector ReadSelector(ModuleFile &M, const RecordData &Record, unsigned &Idx) {
2123 return getLocalSelector(M, Record[Idx++]);
2126 /// Retrieve the global selector ID that corresponds to this
2127 /// the local selector ID in a given module.
2128 serialization::SelectorID getGlobalSelectorID(ModuleFile &F,
2129 unsigned LocalID) const;
2131 /// Read a declaration name.
2132 DeclarationName ReadDeclarationName(ModuleFile &F,
2133 const RecordData &Record, unsigned &Idx);
2134 void ReadDeclarationNameLoc(ModuleFile &F,
2135 DeclarationNameLoc &DNLoc, DeclarationName Name,
2136 const RecordData &Record, unsigned &Idx);
2137 void ReadDeclarationNameInfo(ModuleFile &F, DeclarationNameInfo &NameInfo,
2138 const RecordData &Record, unsigned &Idx);
2140 void ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info,
2141 const RecordData &Record, unsigned &Idx);
2143 NestedNameSpecifier *ReadNestedNameSpecifier(ModuleFile &F,
2144 const RecordData &Record,
2147 NestedNameSpecifierLoc ReadNestedNameSpecifierLoc(ModuleFile &F,
2148 const RecordData &Record,
2151 /// Read a template name.
2152 TemplateName ReadTemplateName(ModuleFile &F, const RecordData &Record,
2155 /// Read a template argument.
2156 TemplateArgument ReadTemplateArgument(ModuleFile &F, const RecordData &Record,
2158 bool Canonicalize = false);
2160 /// Read a template parameter list.
2161 TemplateParameterList *ReadTemplateParameterList(ModuleFile &F,
2162 const RecordData &Record,
2165 /// Read a template argument array.
2166 void ReadTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs,
2167 ModuleFile &F, const RecordData &Record,
2168 unsigned &Idx, bool Canonicalize = false);
2170 /// Read a UnresolvedSet structure.
2171 void ReadUnresolvedSet(ModuleFile &F, LazyASTUnresolvedSet &Set,
2172 const RecordData &Record, unsigned &Idx);
2174 /// Read a C++ base specifier.
2175 CXXBaseSpecifier ReadCXXBaseSpecifier(ModuleFile &F,
2176 const RecordData &Record,unsigned &Idx);
2178 /// Read a CXXCtorInitializer array.
2179 CXXCtorInitializer **
2180 ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record,
2183 /// Read the contents of a CXXCtorInitializer array.
2184 CXXCtorInitializer **GetExternalCXXCtorInitializers(uint64_t Offset) override;
2186 /// Read a source location from raw form and return it in its
2187 /// originating module file's source location space.
2188 SourceLocation ReadUntranslatedSourceLocation(uint32_t Raw) const {
2189 return SourceLocation::getFromRawEncoding((Raw >> 1) | (Raw << 31));
2192 /// Read a source location from raw form.
2193 SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, uint32_t Raw) const {
2194 SourceLocation Loc = ReadUntranslatedSourceLocation(Raw);
2195 return TranslateSourceLocation(ModuleFile, Loc);
2198 /// Translate a source location from another module file's source
2199 /// location space into ours.
2200 SourceLocation TranslateSourceLocation(ModuleFile &ModuleFile,
2201 SourceLocation Loc) const {
2202 if (!ModuleFile.ModuleOffsetMap.empty())
2203 ReadModuleOffsetMap(ModuleFile);
2204 assert(ModuleFile.SLocRemap.find(Loc.getOffset()) !=
2205 ModuleFile.SLocRemap.end() &&
2206 "Cannot find offset to remap.");
2207 int Remap = ModuleFile.SLocRemap.find(Loc.getOffset())->second;
2208 return Loc.getLocWithOffset(Remap);
2211 /// Read a source location.
2212 SourceLocation ReadSourceLocation(ModuleFile &ModuleFile,
2213 const RecordDataImpl &Record,
2215 return ReadSourceLocation(ModuleFile, Record[Idx++]);
2218 /// Read a source range.
2219 SourceRange ReadSourceRange(ModuleFile &F,
2220 const RecordData &Record, unsigned &Idx);
2222 /// Read an integral value
2223 llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx);
2225 /// Read a signed integral value
2226 llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx);
2228 /// Read a floating-point value
2229 llvm::APFloat ReadAPFloat(const RecordData &Record,
2230 const llvm::fltSemantics &Sem, unsigned &Idx);
2233 APValue ReadAPValue(const RecordData &Record, unsigned &Idx);
2236 static std::string ReadString(const RecordData &Record, unsigned &Idx);
2239 static void SkipString(const RecordData &Record, unsigned &Idx) {
2240 Idx += Record[Idx] + 1;
2244 std::string ReadPath(ModuleFile &F, const RecordData &Record, unsigned &Idx);
2247 std::string ReadPath(StringRef BaseDirectory, const RecordData &Record,
2251 static void SkipPath(const RecordData &Record, unsigned &Idx) {
2252 SkipString(Record, Idx);
2255 /// Read a version tuple.
2256 static VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx);
2258 CXXTemporary *ReadCXXTemporary(ModuleFile &F, const RecordData &Record,
2261 /// Reads one attribute from the current stream position.
2262 Attr *ReadAttr(ModuleFile &M, const RecordData &Record, unsigned &Idx);
2264 /// Reads attributes from the current stream position.
2265 void ReadAttributes(ASTRecordReader &Record, AttrVec &Attrs);
2267 /// Reads a statement.
2268 Stmt *ReadStmt(ModuleFile &F);
2270 /// Reads an expression.
2271 Expr *ReadExpr(ModuleFile &F);
2273 /// Reads a sub-statement operand during statement reading.
2274 Stmt *ReadSubStmt() {
2275 assert(ReadingKind == Read_Stmt &&
2276 "Should be called only during statement reading!");
2277 // Subexpressions are stored from last to first, so the next Stmt we need
2278 // is at the back of the stack.
2279 assert(!StmtStack.empty() && "Read too many sub-statements!");
2280 return StmtStack.pop_back_val();
2283 /// Reads a sub-expression operand during statement reading.
2284 Expr *ReadSubExpr();
2286 /// Reads a token out of a record.
2287 Token ReadToken(ModuleFile &M, const RecordDataImpl &Record, unsigned &Idx);
2289 /// Reads the macro record located at the given offset.
2290 MacroInfo *ReadMacroRecord(ModuleFile &F, uint64_t Offset);
2292 /// Determine the global preprocessed entity ID that corresponds to
2293 /// the given local ID within the given module.
2294 serialization::PreprocessedEntityID
2295 getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const;
2297 /// Add a macro to deserialize its macro directive history.
2299 /// \param II The name of the macro.
2300 /// \param M The module file.
2301 /// \param MacroDirectivesOffset Offset of the serialized macro directive
2303 void addPendingMacro(IdentifierInfo *II, ModuleFile *M,
2304 uint64_t MacroDirectivesOffset);
2306 /// Read the set of macros defined by this external macro source.
2307 void ReadDefinedMacros() override;
2309 /// Update an out-of-date identifier.
2310 void updateOutOfDateIdentifier(IdentifierInfo &II) override;
2312 /// Note that this identifier is up-to-date.
2313 void markIdentifierUpToDate(IdentifierInfo *II);
2315 /// Load all external visible decls in the given DeclContext.
2316 void completeVisibleDeclsMap(const DeclContext *DC) override;
2318 /// Retrieve the AST context that this AST reader supplements.
2319 ASTContext &getContext() {
2320 assert(ContextObj && "requested AST context when not loading AST");
2324 // Contains the IDs for declarations that were requested before we have
2325 // access to a Sema object.
2326 SmallVector<uint64_t, 16> PreloadedDeclIDs;
2328 /// Retrieve the semantic analysis object used to analyze the
2329 /// translation unit in which the precompiled header is being
2331 Sema *getSema() { return SemaObj; }
2333 /// Get the identifier resolver used for name lookup / updates
2334 /// in the translation unit scope. We have one of these even if we don't
2335 /// have a Sema object.
2336 IdentifierResolver &getIdResolver();
2338 /// Retrieve the identifier table associated with the
2340 IdentifierTable &getIdentifierTable();
2342 /// Record that the given ID maps to the given switch-case
2344 void RecordSwitchCaseID(SwitchCase *SC, unsigned ID);
2346 /// Retrieve the switch-case statement with the given ID.
2347 SwitchCase *getSwitchCaseWithID(unsigned ID);
2349 void ClearSwitchCaseIDs();
2351 /// Cursors for comments blocks.
2352 SmallVector<std::pair<llvm::BitstreamCursor,
2353 serialization::ModuleFile *>, 8> CommentsCursors;
2355 /// Loads comments ranges.
2356 void ReadComments() override;
2358 /// Visit all the input files of the given module file.
2359 void visitInputFiles(serialization::ModuleFile &MF,
2360 bool IncludeSystem, bool Complain,
2361 llvm::function_ref<void(const serialization::InputFile &IF,
2362 bool isSystem)> Visitor);
2364 /// Visit all the top-level module maps loaded when building the given module
2366 void visitTopLevelModuleMaps(serialization::ModuleFile &MF,
2368 void(const FileEntry *)> Visitor);
2370 bool isProcessingUpdateRecords() { return ProcessingUpdateRecords; }
2373 /// An object for streaming information from a record.
2374 class ASTRecordReader {
2375 using ModuleFile = serialization::ModuleFile;
2380 ASTReader::RecordData Record;
2382 using RecordData = ASTReader::RecordData;
2383 using RecordDataImpl = ASTReader::RecordDataImpl;
2386 /// Construct an ASTRecordReader that uses the default encoding scheme.
2387 ASTRecordReader(ASTReader &Reader, ModuleFile &F) : Reader(&Reader), F(&F) {}
2389 /// Reads a record with id AbbrevID from Cursor, resetting the
2391 Expected<unsigned> readRecord(llvm::BitstreamCursor &Cursor,
2394 /// Is this a module file for a module (rather than a PCH or similar).
2395 bool isModule() const { return F->isModule(); }
2397 /// Retrieve the AST context that this AST reader supplements.
2398 ASTContext &getContext() { return Reader->getContext(); }
2400 /// The current position in this record.
2401 unsigned getIdx() const { return Idx; }
2403 /// The length of this record.
2404 size_t size() const { return Record.size(); }
2406 /// An arbitrary index in this record.
2407 const uint64_t &operator[](size_t N) { return Record[N]; }
2409 /// The last element in this record.
2410 const uint64_t &back() const { return Record.back(); }
2412 /// Returns the current value in this record, and advances to the
2414 const uint64_t &readInt() { return Record[Idx++]; }
2416 /// Returns the current value in this record, without advancing.
2417 const uint64_t &peekInt() { return Record[Idx]; }
2419 /// Skips the specified number of values.
2420 void skipInts(unsigned N) { Idx += N; }
2422 /// Retrieve the global submodule ID its local ID number.
2423 serialization::SubmoduleID
2424 getGlobalSubmoduleID(unsigned LocalID) {
2425 return Reader->getGlobalSubmoduleID(*F, LocalID);
2428 /// Retrieve the submodule that corresponds to a global submodule ID.
2429 Module *getSubmodule(serialization::SubmoduleID GlobalID) {
2430 return Reader->getSubmodule(GlobalID);
2433 /// Read the record that describes the lexical contents of a DC.
2434 bool readLexicalDeclContextStorage(uint64_t Offset, DeclContext *DC) {
2435 return Reader->ReadLexicalDeclContextStorage(*F, F->DeclsCursor, Offset,
2439 /// Read the record that describes the visible contents of a DC.
2440 bool readVisibleDeclContextStorage(uint64_t Offset,
2441 serialization::DeclID ID) {
2442 return Reader->ReadVisibleDeclContextStorage(*F, F->DeclsCursor, Offset,
2446 ExplicitSpecifier readExplicitSpec() {
2447 uint64_t Kind = readInt();
2448 bool HasExpr = Kind & 0x1;
2450 return ExplicitSpecifier(HasExpr ? readExpr() : nullptr,
2451 static_cast<ExplicitSpecKind>(Kind));
2454 void readExceptionSpec(SmallVectorImpl<QualType> &ExceptionStorage,
2455 FunctionProtoType::ExceptionSpecInfo &ESI) {
2456 return Reader->readExceptionSpec(*F, ExceptionStorage, ESI, Record, Idx);
2459 /// Get the global offset corresponding to a local offset.
2460 uint64_t getGlobalBitOffset(uint32_t LocalOffset) {
2461 return Reader->getGlobalBitOffset(*F, LocalOffset);
2464 /// Reads a statement.
2465 Stmt *readStmt() { return Reader->ReadStmt(*F); }
2467 /// Reads an expression.
2468 Expr *readExpr() { return Reader->ReadExpr(*F); }
2470 /// Reads a sub-statement operand during statement reading.
2471 Stmt *readSubStmt() { return Reader->ReadSubStmt(); }
2473 /// Reads a sub-expression operand during statement reading.
2474 Expr *readSubExpr() { return Reader->ReadSubExpr(); }
2476 /// Reads a declaration with the given local ID in the given module.
2478 /// \returns The requested declaration, casted to the given return type.
2479 template<typename T>
2480 T *GetLocalDeclAs(uint32_t LocalID) {
2481 return cast_or_null<T>(Reader->GetLocalDecl(*F, LocalID));
2484 /// Reads a TemplateArgumentLocInfo appropriate for the
2485 /// given TemplateArgument kind, advancing Idx.
2486 TemplateArgumentLocInfo
2487 getTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind) {
2488 return Reader->GetTemplateArgumentLocInfo(*F, Kind, Record, Idx);
2491 /// Reads a TemplateArgumentLoc, advancing Idx.
2493 readTemplateArgumentLoc() {
2494 return Reader->ReadTemplateArgumentLoc(*F, Record, Idx);
2497 const ASTTemplateArgumentListInfo*
2498 readASTTemplateArgumentListInfo() {
2499 return Reader->ReadASTTemplateArgumentListInfo(*F, Record, Idx);
2502 /// Reads a declarator info from the given record, advancing Idx.
2503 TypeSourceInfo *getTypeSourceInfo() {
2504 return Reader->GetTypeSourceInfo(*F, Record, Idx);
2507 /// Reads the location information for a type.
2508 void readTypeLoc(TypeLoc TL) {
2509 return Reader->ReadTypeLoc(*F, Record, Idx, TL);
2512 /// Map a local type ID within a given AST file to a global type ID.
2513 serialization::TypeID getGlobalTypeID(unsigned LocalID) const {
2514 return Reader->getGlobalTypeID(*F, LocalID);
2517 /// Read a type from the current position in the record.
2518 QualType readType() {
2519 return Reader->readType(*F, Record, Idx);
2522 /// Reads a declaration ID from the given position in this record.
2524 /// \returns The declaration ID read from the record, adjusted to a global ID.
2525 serialization::DeclID readDeclID() {
2526 return Reader->ReadDeclID(*F, Record, Idx);
2529 /// Reads a declaration from the given position in a record in the
2530 /// given module, advancing Idx.
2532 return Reader->ReadDecl(*F, Record, Idx);
2535 /// Reads a declaration from the given position in the record,
2538 /// \returns The declaration read from this location, casted to the given
2540 template<typename T>
2542 return Reader->ReadDeclAs<T>(*F, Record, Idx);
2545 IdentifierInfo *getIdentifierInfo() {
2546 return Reader->GetIdentifierInfo(*F, Record, Idx);
2549 /// Read a selector from the Record, advancing Idx.
2550 Selector readSelector() {
2551 return Reader->ReadSelector(*F, Record, Idx);
2554 /// Read a declaration name, advancing Idx.
2555 DeclarationName readDeclarationName() {
2556 return Reader->ReadDeclarationName(*F, Record, Idx);
2558 void readDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name) {
2559 return Reader->ReadDeclarationNameLoc(*F, DNLoc, Name, Record, Idx);
2561 void readDeclarationNameInfo(DeclarationNameInfo &NameInfo) {
2562 return Reader->ReadDeclarationNameInfo(*F, NameInfo, Record, Idx);
2565 void readQualifierInfo(QualifierInfo &Info) {
2566 return Reader->ReadQualifierInfo(*F, Info, Record, Idx);
2569 NestedNameSpecifier *readNestedNameSpecifier() {
2570 return Reader->ReadNestedNameSpecifier(*F, Record, Idx);
2573 NestedNameSpecifierLoc readNestedNameSpecifierLoc() {
2574 return Reader->ReadNestedNameSpecifierLoc(*F, Record, Idx);
2577 /// Read a template name, advancing Idx.
2578 TemplateName readTemplateName() {
2579 return Reader->ReadTemplateName(*F, Record, Idx);
2582 /// Read a template argument, advancing Idx.
2583 TemplateArgument readTemplateArgument(bool Canonicalize = false) {
2584 return Reader->ReadTemplateArgument(*F, Record, Idx, Canonicalize);
2587 /// Read a template parameter list, advancing Idx.
2588 TemplateParameterList *readTemplateParameterList() {
2589 return Reader->ReadTemplateParameterList(*F, Record, Idx);
2592 /// Read a template argument array, advancing Idx.
2593 void readTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs,
2594 bool Canonicalize = false) {
2595 return Reader->ReadTemplateArgumentList(TemplArgs, *F, Record, Idx,
2599 /// Read a UnresolvedSet structure, advancing Idx.
2600 void readUnresolvedSet(LazyASTUnresolvedSet &Set) {
2601 return Reader->ReadUnresolvedSet(*F, Set, Record, Idx);
2604 /// Read a C++ base specifier, advancing Idx.
2605 CXXBaseSpecifier readCXXBaseSpecifier() {
2606 return Reader->ReadCXXBaseSpecifier(*F, Record, Idx);
2609 /// Read a CXXCtorInitializer array, advancing Idx.
2610 CXXCtorInitializer **readCXXCtorInitializers() {
2611 return Reader->ReadCXXCtorInitializers(*F, Record, Idx);
2614 CXXTemporary *readCXXTemporary() {
2615 return Reader->ReadCXXTemporary(*F, Record, Idx);
2618 /// Read a source location, advancing Idx.
2619 SourceLocation readSourceLocation() {
2620 return Reader->ReadSourceLocation(*F, Record, Idx);
2623 /// Read a source range, advancing Idx.
2624 SourceRange readSourceRange() {
2625 return Reader->ReadSourceRange(*F, Record, Idx);
2628 APValue readAPValue() { return Reader->ReadAPValue(Record, Idx); }
2630 /// Read an integral value, advancing Idx.
2631 llvm::APInt readAPInt() {
2632 return Reader->ReadAPInt(Record, Idx);
2635 /// Read a signed integral value, advancing Idx.
2636 llvm::APSInt readAPSInt() {
2637 return Reader->ReadAPSInt(Record, Idx);
2640 /// Read a floating-point value, advancing Idx.
2641 llvm::APFloat readAPFloat(const llvm::fltSemantics &Sem) {
2642 return Reader->ReadAPFloat(Record, Sem,Idx);
2645 /// Read a string, advancing Idx.
2646 std::string readString() {
2647 return Reader->ReadString(Record, Idx);
2650 /// Read a path, advancing Idx.
2651 std::string readPath() {
2652 return Reader->ReadPath(*F, Record, Idx);
2655 /// Read a version tuple, advancing Idx.
2656 VersionTuple readVersionTuple() {
2657 return ASTReader::ReadVersionTuple(Record, Idx);
2660 /// Reads one attribute from the current stream position, advancing Idx.
2662 return Reader->ReadAttr(*F, Record, Idx);
2665 /// Reads attributes from the current stream position, advancing Idx.
2666 void readAttributes(AttrVec &Attrs) {
2667 return Reader->ReadAttributes(*this, Attrs);
2670 /// Reads a token out of a record, advancing Idx.
2672 return Reader->ReadToken(*F, Record, Idx);
2675 void recordSwitchCaseID(SwitchCase *SC, unsigned ID) {
2676 Reader->RecordSwitchCaseID(SC, ID);
2679 /// Retrieve the switch-case statement with the given ID.
2680 SwitchCase *getSwitchCaseWithID(unsigned ID) {
2681 return Reader->getSwitchCaseWithID(ID);
2685 /// Helper class that saves the current stream position and
2686 /// then restores it when destroyed.
2687 struct SavedStreamPosition {
2688 explicit SavedStreamPosition(llvm::BitstreamCursor &Cursor)
2689 : Cursor(Cursor), Offset(Cursor.GetCurrentBitNo()) {}
2691 ~SavedStreamPosition() {
2692 if (llvm::Error Err = Cursor.JumpToBit(Offset))
2693 llvm::report_fatal_error(
2694 "Cursor should always be able to go back, failed: " +
2695 toString(std::move(Err)));
2699 llvm::BitstreamCursor &Cursor;
2703 inline void PCHValidator::Error(const char *Msg) {
2707 class OMPClauseReader : public OMPClauseVisitor<OMPClauseReader> {
2708 ASTRecordReader &Record;
2709 ASTContext &Context;
2712 OMPClauseReader(ASTRecordReader &Record)
2713 : Record(Record), Context(Record.getContext()) {}
2715 #define OPENMP_CLAUSE(Name, Class) void Visit##Class(Class *C);
2716 #include "clang/Basic/OpenMPKinds.def"
2717 OMPClause *readClause();
2718 void VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C);
2719 void VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C);
2722 } // namespace clang
2724 #endif // LLVM_CLANG_SERIALIZATION_ASTREADER_H