1 //===- ASTReader.h - AST File Reader ----------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the ASTReader class, which reads AST files.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_SERIALIZATION_ASTREADER_H
15 #define LLVM_CLANG_SERIALIZATION_ASTREADER_H
17 #include "clang/AST/DeclCXX.h"
18 #include "clang/AST/DeclObjC.h"
19 #include "clang/AST/DeclarationName.h"
20 #include "clang/AST/NestedNameSpecifier.h"
21 #include "clang/AST/OpenMPClause.h"
22 #include "clang/AST/TemplateBase.h"
23 #include "clang/AST/TemplateName.h"
24 #include "clang/AST/Type.h"
25 #include "clang/Basic/Diagnostic.h"
26 #include "clang/Basic/DiagnosticOptions.h"
27 #include "clang/Basic/IdentifierTable.h"
28 #include "clang/Basic/Module.h"
29 #include "clang/Basic/OpenCLOptions.h"
30 #include "clang/Basic/SourceLocation.h"
31 #include "clang/Basic/Version.h"
32 #include "clang/Lex/ExternalPreprocessorSource.h"
33 #include "clang/Lex/HeaderSearch.h"
34 #include "clang/Lex/PreprocessingRecord.h"
35 #include "clang/Lex/Token.h"
36 #include "clang/Sema/ExternalSemaSource.h"
37 #include "clang/Sema/IdentifierResolver.h"
38 #include "clang/Serialization/ASTBitCodes.h"
39 #include "clang/Serialization/ContinuousRangeMap.h"
40 #include "clang/Serialization/Module.h"
41 #include "clang/Serialization/ModuleFileExtension.h"
42 #include "clang/Serialization/ModuleManager.h"
43 #include "llvm/ADT/APFloat.h"
44 #include "llvm/ADT/APInt.h"
45 #include "llvm/ADT/APSInt.h"
46 #include "llvm/ADT/ArrayRef.h"
47 #include "llvm/ADT/DenseMap.h"
48 #include "llvm/ADT/DenseSet.h"
49 #include "llvm/ADT/IntrusiveRefCntPtr.h"
50 #include "llvm/ADT/MapVector.h"
51 #include "llvm/ADT/Optional.h"
52 #include "llvm/ADT/STLExtras.h"
53 #include "llvm/ADT/SetVector.h"
54 #include "llvm/ADT/SmallPtrSet.h"
55 #include "llvm/ADT/SmallVector.h"
56 #include "llvm/ADT/StringMap.h"
57 #include "llvm/ADT/StringRef.h"
58 #include "llvm/ADT/iterator.h"
59 #include "llvm/ADT/iterator_range.h"
60 #include "llvm/Bitcode/BitstreamReader.h"
61 #include "llvm/Support/Casting.h"
62 #include "llvm/Support/Endian.h"
63 #include "llvm/Support/MemoryBuffer.h"
64 #include "llvm/Support/Timer.h"
65 #include "llvm/Support/VersionTuple.h"
81 class ASTDeserializationListener;
83 class ASTRecordReader;
93 class FileSystemOptions;
95 class GlobalModuleIndex;
96 struct HeaderFileInfo;
97 class HeaderSearchOptions;
99 class LazyASTUnresolvedSet;
101 class MemoryBufferCache;
104 class ObjCCategoryDecl;
105 class ObjCInterfaceDecl;
106 class PCHContainerReader;
108 class PreprocessorOptions;
109 struct QualifierInfo;
115 class TemplateParameterList;
116 class TypedefNameDecl;
117 class TypeSourceInfo;
121 /// Abstract interface for callback invocations by the ASTReader.
123 /// While reading an AST file, the ASTReader will call the methods of the
124 /// listener to pass on specific information. Some of the listener methods can
125 /// return true to indicate to the ASTReader that the information (and
126 /// consequently the AST file) is invalid.
127 class ASTReaderListener {
129 virtual ~ASTReaderListener();
131 /// Receives the full Clang version information.
133 /// \returns true to indicate that the version is invalid. Subclasses should
134 /// generally defer to this implementation.
135 virtual bool ReadFullVersionInformation(StringRef FullVersion) {
136 return FullVersion != getClangFullRepositoryVersion();
139 virtual void ReadModuleName(StringRef ModuleName) {}
140 virtual void ReadModuleMapFile(StringRef ModuleMapPath) {}
142 /// Receives the language options.
144 /// \returns true to indicate the options are invalid or false otherwise.
145 virtual bool ReadLanguageOptions(const LangOptions &LangOpts,
147 bool AllowCompatibleDifferences) {
151 /// Receives the target options.
153 /// \returns true to indicate the target options are invalid, or false
155 virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
156 bool AllowCompatibleDifferences) {
160 /// Receives the diagnostic options.
162 /// \returns true to indicate the diagnostic options are invalid, or false
165 ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
170 /// Receives the file system options.
172 /// \returns true to indicate the file system options are invalid, or false
174 virtual bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
179 /// Receives the header search options.
181 /// \returns true to indicate the header search options are invalid, or false
183 virtual bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
184 StringRef SpecificModuleCachePath,
189 /// Receives the preprocessor options.
191 /// \param SuggestedPredefines Can be filled in with the set of predefines
192 /// that are suggested by the preprocessor options. Typically only used when
193 /// loading a precompiled header.
195 /// \returns true to indicate the preprocessor options are invalid, or false
197 virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
199 std::string &SuggestedPredefines) {
203 /// Receives __COUNTER__ value.
204 virtual void ReadCounter(const serialization::ModuleFile &M,
207 /// This is called for each AST file loaded.
208 virtual void visitModuleFile(StringRef Filename,
209 serialization::ModuleKind Kind) {}
211 /// Returns true if this \c ASTReaderListener wants to receive the
212 /// input files of the AST file via \c visitInputFile, false otherwise.
213 virtual bool needsInputFileVisitation() { return false; }
215 /// Returns true if this \c ASTReaderListener wants to receive the
216 /// system input files of the AST file via \c visitInputFile, false otherwise.
217 virtual bool needsSystemInputFileVisitation() { return false; }
219 /// if \c needsInputFileVisitation returns true, this is called for
220 /// each non-system input file of the AST File. If
221 /// \c needsSystemInputFileVisitation is true, then it is called for all
222 /// system input files as well.
224 /// \returns true to continue receiving the next input file, false to stop.
225 virtual bool visitInputFile(StringRef Filename, bool isSystem,
226 bool isOverridden, bool isExplicitModule) {
230 /// Returns true if this \c ASTReaderListener wants to receive the
231 /// imports of the AST file via \c visitImport, false otherwise.
232 virtual bool needsImportVisitation() const { return false; }
234 /// If needsImportVisitation returns \c true, this is called for each
235 /// AST file imported by this AST file.
236 virtual void visitImport(StringRef ModuleName, StringRef Filename) {}
238 /// Indicates that a particular module file extension has been read.
239 virtual void readModuleFileExtension(
240 const ModuleFileExtensionMetadata &Metadata) {}
243 /// Simple wrapper class for chaining listeners.
244 class ChainedASTReaderListener : public ASTReaderListener {
245 std::unique_ptr<ASTReaderListener> First;
246 std::unique_ptr<ASTReaderListener> Second;
249 /// Takes ownership of \p First and \p Second.
250 ChainedASTReaderListener(std::unique_ptr<ASTReaderListener> First,
251 std::unique_ptr<ASTReaderListener> Second)
252 : First(std::move(First)), Second(std::move(Second)) {}
254 std::unique_ptr<ASTReaderListener> takeFirst() { return std::move(First); }
255 std::unique_ptr<ASTReaderListener> takeSecond() { return std::move(Second); }
257 bool ReadFullVersionInformation(StringRef FullVersion) override;
258 void ReadModuleName(StringRef ModuleName) override;
259 void ReadModuleMapFile(StringRef ModuleMapPath) override;
260 bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
261 bool AllowCompatibleDifferences) override;
262 bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
263 bool AllowCompatibleDifferences) override;
264 bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
265 bool Complain) override;
266 bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
267 bool Complain) override;
269 bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
270 StringRef SpecificModuleCachePath,
271 bool Complain) override;
272 bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
274 std::string &SuggestedPredefines) override;
276 void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
277 bool needsInputFileVisitation() override;
278 bool needsSystemInputFileVisitation() override;
279 void visitModuleFile(StringRef Filename,
280 serialization::ModuleKind Kind) override;
281 bool visitInputFile(StringRef Filename, bool isSystem,
282 bool isOverridden, bool isExplicitModule) override;
283 void readModuleFileExtension(
284 const ModuleFileExtensionMetadata &Metadata) override;
287 /// ASTReaderListener implementation to validate the information of
288 /// the PCH file against an initialized Preprocessor.
289 class PCHValidator : public ASTReaderListener {
294 PCHValidator(Preprocessor &PP, ASTReader &Reader)
295 : PP(PP), Reader(Reader) {}
297 bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
298 bool AllowCompatibleDifferences) override;
299 bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
300 bool AllowCompatibleDifferences) override;
301 bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
302 bool Complain) override;
303 bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain,
304 std::string &SuggestedPredefines) override;
305 bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
306 StringRef SpecificModuleCachePath,
307 bool Complain) override;
308 void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
311 void Error(const char *Msg);
314 /// ASTReaderListenter implementation to set SuggestedPredefines of
315 /// ASTReader which is required to use a pch file. This is the replacement
316 /// of PCHValidator or SimplePCHValidator when using a pch file without
318 class SimpleASTReaderListener : public ASTReaderListener {
322 SimpleASTReaderListener(Preprocessor &PP) : PP(PP) {}
324 bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain,
325 std::string &SuggestedPredefines) override;
328 namespace serialization {
330 class ReadMethodPoolVisitor;
334 class ASTIdentifierLookupTrait;
336 /// The on-disk hash table(s) used for DeclContext name lookup.
337 struct DeclContextLookupTable;
339 } // namespace reader
341 } // namespace serialization
343 /// Reads an AST files chain containing the contents of a translation
346 /// The ASTReader class reads bitstreams (produced by the ASTWriter
347 /// class) containing the serialized representation of a given
348 /// abstract syntax tree and its supporting data structures. An
349 /// instance of the ASTReader can be attached to an ASTContext object,
350 /// which will provide access to the contents of the AST files.
352 /// The AST reader provides lazy de-serialization of declarations, as
353 /// required when traversing the AST. Only those AST nodes that are
354 /// actually required will be de-serialized.
356 : public ExternalPreprocessorSource,
357 public ExternalPreprocessingRecordSource,
358 public ExternalHeaderFileInfoSource,
359 public ExternalSemaSource,
360 public IdentifierInfoLookup,
361 public ExternalSLocEntrySource
364 /// Types of AST files.
365 friend class ASTDeclReader;
366 friend class ASTIdentifierIterator;
367 friend class ASTRecordReader;
368 friend class ASTStmtReader;
369 friend class ASTUnit; // ASTUnit needs to remap source locations.
370 friend class ASTWriter;
371 friend class PCHValidator;
372 friend class serialization::reader::ASTIdentifierLookupTrait;
373 friend class serialization::ReadMethodPoolVisitor;
374 friend class TypeLocReader;
376 using RecordData = SmallVector<uint64_t, 64>;
377 using RecordDataImpl = SmallVectorImpl<uint64_t>;
379 /// The result of reading the control block of an AST file, which
380 /// can fail for various reasons.
382 /// The control block was read successfully. Aside from failures,
383 /// the AST file is safe to read into the current context.
386 /// The AST file itself appears corrupted.
389 /// The AST file was missing.
392 /// The AST file is out-of-date relative to its input files,
393 /// and needs to be regenerated.
396 /// The AST file was written by a different version of Clang.
399 /// The AST file was writtten with a different language/target
401 ConfigurationMismatch,
403 /// The AST file has errors.
407 using ModuleFile = serialization::ModuleFile;
408 using ModuleKind = serialization::ModuleKind;
409 using ModuleManager = serialization::ModuleManager;
410 using ModuleIterator = ModuleManager::ModuleIterator;
411 using ModuleConstIterator = ModuleManager::ModuleConstIterator;
412 using ModuleReverseIterator = ModuleManager::ModuleReverseIterator;
415 /// The receiver of some callbacks invoked by ASTReader.
416 std::unique_ptr<ASTReaderListener> Listener;
418 /// The receiver of deserialization events.
419 ASTDeserializationListener *DeserializationListener = nullptr;
421 bool OwnsDeserializationListener = false;
423 SourceManager &SourceMgr;
424 FileManager &FileMgr;
425 const PCHContainerReader &PCHContainerRdr;
426 DiagnosticsEngine &Diags;
428 /// The semantic analysis object that will be processing the
429 /// AST files and the translation unit that uses it.
430 Sema *SemaObj = nullptr;
432 /// The preprocessor that will be loading the source file.
435 /// The AST context into which we'll read the AST files.
436 ASTContext *ContextObj = nullptr;
438 /// The AST consumer.
439 ASTConsumer *Consumer = nullptr;
441 /// The module manager which manages modules and their dependencies
442 ModuleManager ModuleMgr;
444 /// The cache that manages memory buffers for PCM files.
445 MemoryBufferCache &PCMCache;
447 /// A dummy identifier resolver used to merge TU-scope declarations in
448 /// C, for the cases where we don't have a Sema object to provide a real
449 /// identifier resolver.
450 IdentifierResolver DummyIdResolver;
452 /// A mapping from extension block names to module file extensions.
453 llvm::StringMap<std::shared_ptr<ModuleFileExtension>> ModuleFileExtensions;
455 /// A timer used to track the time spent deserializing.
456 std::unique_ptr<llvm::Timer> ReadTimer;
458 /// The location where the module file will be considered as
459 /// imported from. For non-module AST types it should be invalid.
460 SourceLocation CurrentImportLoc;
462 /// The global module index, if loaded.
463 std::unique_ptr<GlobalModuleIndex> GlobalIndex;
465 /// A map of global bit offsets to the module that stores entities
466 /// at those bit offsets.
467 ContinuousRangeMap<uint64_t, ModuleFile*, 4> GlobalBitOffsetsMap;
469 /// A map of negated SLocEntryIDs to the modules containing them.
470 ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocEntryMap;
472 using GlobalSLocOffsetMapType =
473 ContinuousRangeMap<unsigned, ModuleFile *, 64>;
475 /// A map of reversed (SourceManager::MaxLoadedOffset - SLocOffset)
476 /// SourceLocation offsets to the modules containing them.
477 GlobalSLocOffsetMapType GlobalSLocOffsetMap;
479 /// Types that have already been loaded from the chain.
481 /// When the pointer at index I is non-NULL, the type with
482 /// ID = (I + 1) << FastQual::Width has already been loaded
483 std::vector<QualType> TypesLoaded;
485 using GlobalTypeMapType =
486 ContinuousRangeMap<serialization::TypeID, ModuleFile *, 4>;
488 /// Mapping from global type IDs to the module in which the
489 /// type resides along with the offset that should be added to the
490 /// global type ID to produce a local ID.
491 GlobalTypeMapType GlobalTypeMap;
493 /// Declarations that have already been loaded from the chain.
495 /// When the pointer at index I is non-NULL, the declaration with ID
496 /// = I + 1 has already been loaded.
497 std::vector<Decl *> DeclsLoaded;
499 using GlobalDeclMapType =
500 ContinuousRangeMap<serialization::DeclID, ModuleFile *, 4>;
502 /// Mapping from global declaration IDs to the module in which the
503 /// declaration resides.
504 GlobalDeclMapType GlobalDeclMap;
506 using FileOffset = std::pair<ModuleFile *, uint64_t>;
507 using FileOffsetsTy = SmallVector<FileOffset, 2>;
508 using DeclUpdateOffsetsMap =
509 llvm::DenseMap<serialization::DeclID, FileOffsetsTy>;
511 /// Declarations that have modifications residing in a later file
513 DeclUpdateOffsetsMap DeclUpdateOffsets;
515 struct PendingUpdateRecord {
517 serialization::GlobalDeclID ID;
519 // Whether the declaration was just deserialized.
522 PendingUpdateRecord(serialization::GlobalDeclID ID, Decl *D,
524 : D(D), ID(ID), JustLoaded(JustLoaded) {}
527 /// Declaration updates for already-loaded declarations that we need
528 /// to apply once we finish processing an import.
529 llvm::SmallVector<PendingUpdateRecord, 16> PendingUpdateRecords;
531 enum class PendingFakeDefinitionKind { NotFake, Fake, FakeLoaded };
533 /// The DefinitionData pointers that we faked up for class definitions
534 /// that we needed but hadn't loaded yet.
535 llvm::DenseMap<void *, PendingFakeDefinitionKind> PendingFakeDefinitionData;
537 /// Exception specification updates that have been loaded but not yet
538 /// propagated across the relevant redeclaration chain. The map key is the
539 /// canonical declaration (used only for deduplication) and the value is a
540 /// declaration that has an exception specification.
541 llvm::SmallMapVector<Decl *, FunctionDecl *, 4> PendingExceptionSpecUpdates;
543 /// Deduced return type updates that have been loaded but not yet propagated
544 /// across the relevant redeclaration chain. The map key is the canonical
545 /// declaration and the value is the deduced return type.
546 llvm::SmallMapVector<FunctionDecl *, QualType, 4> PendingDeducedTypeUpdates;
548 /// Declarations that have been imported and have typedef names for
549 /// linkage purposes.
550 llvm::DenseMap<std::pair<DeclContext *, IdentifierInfo *>, NamedDecl *>
551 ImportedTypedefNamesForLinkage;
553 /// Mergeable declaration contexts that have anonymous declarations
554 /// within them, and those anonymous declarations.
555 llvm::DenseMap<Decl*, llvm::SmallVector<NamedDecl*, 2>>
556 AnonymousDeclarationsForMerging;
558 struct FileDeclsInfo {
559 ModuleFile *Mod = nullptr;
560 ArrayRef<serialization::LocalDeclID> Decls;
562 FileDeclsInfo() = default;
563 FileDeclsInfo(ModuleFile *Mod, ArrayRef<serialization::LocalDeclID> Decls)
564 : Mod(Mod), Decls(Decls) {}
567 /// Map from a FileID to the file-level declarations that it contains.
568 llvm::DenseMap<FileID, FileDeclsInfo> FileDeclIDs;
570 /// An array of lexical contents of a declaration context, as a sequence of
571 /// Decl::Kind, DeclID pairs.
572 using LexicalContents = ArrayRef<llvm::support::unaligned_uint32_t>;
574 /// Map from a DeclContext to its lexical contents.
575 llvm::DenseMap<const DeclContext*, std::pair<ModuleFile*, LexicalContents>>
578 /// Map from the TU to its lexical contents from each module file.
579 std::vector<std::pair<ModuleFile*, LexicalContents>> TULexicalDecls;
581 /// Map from a DeclContext to its lookup tables.
582 llvm::DenseMap<const DeclContext *,
583 serialization::reader::DeclContextLookupTable> Lookups;
585 // Updates for visible decls can occur for other contexts than just the
586 // TU, and when we read those update records, the actual context may not
587 // be available yet, so have this pending map using the ID as a key. It
588 // will be realized when the context is actually loaded.
589 struct PendingVisibleUpdate {
591 const unsigned char *Data;
593 using DeclContextVisibleUpdates = SmallVector<PendingVisibleUpdate, 1>;
595 /// Updates to the visible declarations of declaration contexts that
596 /// haven't been loaded yet.
597 llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates>
598 PendingVisibleUpdates;
600 /// The set of C++ or Objective-C classes that have forward
601 /// declarations that have not yet been linked to their definitions.
602 llvm::SmallPtrSet<Decl *, 4> PendingDefinitions;
604 using PendingBodiesMap =
605 llvm::MapVector<Decl *, uint64_t,
606 llvm::SmallDenseMap<Decl *, unsigned, 4>,
607 SmallVector<std::pair<Decl *, uint64_t>, 4>>;
609 /// Functions or methods that have bodies that will be attached.
610 PendingBodiesMap PendingBodies;
612 /// Definitions for which we have added merged definitions but not yet
613 /// performed deduplication.
614 llvm::SetVector<NamedDecl *> PendingMergedDefinitionsToDeduplicate;
616 /// Read the record that describes the lexical contents of a DC.
617 bool ReadLexicalDeclContextStorage(ModuleFile &M,
618 llvm::BitstreamCursor &Cursor,
619 uint64_t Offset, DeclContext *DC);
621 /// Read the record that describes the visible contents of a DC.
622 bool ReadVisibleDeclContextStorage(ModuleFile &M,
623 llvm::BitstreamCursor &Cursor,
624 uint64_t Offset, serialization::DeclID ID);
626 /// A vector containing identifiers that have already been
629 /// If the pointer at index I is non-NULL, then it refers to the
630 /// IdentifierInfo for the identifier with ID=I+1 that has already
632 std::vector<IdentifierInfo *> IdentifiersLoaded;
634 using GlobalIdentifierMapType =
635 ContinuousRangeMap<serialization::IdentID, ModuleFile *, 4>;
637 /// Mapping from global identifier IDs to the module in which the
638 /// identifier resides along with the offset that should be added to the
639 /// global identifier ID to produce a local ID.
640 GlobalIdentifierMapType GlobalIdentifierMap;
642 /// A vector containing macros that have already been
645 /// If the pointer at index I is non-NULL, then it refers to the
646 /// MacroInfo for the identifier with ID=I+1 that has already
648 std::vector<MacroInfo *> MacrosLoaded;
650 using LoadedMacroInfo =
651 std::pair<IdentifierInfo *, serialization::SubmoduleID>;
653 /// A set of #undef directives that we have loaded; used to
654 /// deduplicate the same #undef information coming from multiple module
656 llvm::DenseSet<LoadedMacroInfo> LoadedUndefs;
658 using GlobalMacroMapType =
659 ContinuousRangeMap<serialization::MacroID, ModuleFile *, 4>;
661 /// Mapping from global macro IDs to the module in which the
662 /// macro resides along with the offset that should be added to the
663 /// global macro ID to produce a local ID.
664 GlobalMacroMapType GlobalMacroMap;
666 /// A vector containing submodules that have already been loaded.
668 /// This vector is indexed by the Submodule ID (-1). NULL submodule entries
669 /// indicate that the particular submodule ID has not yet been loaded.
670 SmallVector<Module *, 2> SubmodulesLoaded;
672 using GlobalSubmoduleMapType =
673 ContinuousRangeMap<serialization::SubmoduleID, ModuleFile *, 4>;
675 /// Mapping from global submodule IDs to the module file in which the
676 /// submodule resides along with the offset that should be added to the
677 /// global submodule ID to produce a local ID.
678 GlobalSubmoduleMapType GlobalSubmoduleMap;
680 /// A set of hidden declarations.
681 using HiddenNames = SmallVector<Decl *, 2>;
682 using HiddenNamesMapType = llvm::DenseMap<Module *, HiddenNames>;
684 /// A mapping from each of the hidden submodules to the deserialized
685 /// declarations in that submodule that could be made visible.
686 HiddenNamesMapType HiddenNamesMap;
688 /// A module import, export, or conflict that hasn't yet been resolved.
689 struct UnresolvedModuleRef {
690 /// The file in which this module resides.
693 /// The module that is importing or exporting.
696 /// The kind of module reference.
697 enum { Import, Export, Conflict } Kind;
699 /// The local ID of the module that is being exported.
702 /// Whether this is a wildcard export.
703 unsigned IsWildcard : 1;
709 /// The set of module imports and exports that still need to be
711 SmallVector<UnresolvedModuleRef, 2> UnresolvedModuleRefs;
713 /// A vector containing selectors that have already been loaded.
715 /// This vector is indexed by the Selector ID (-1). NULL selector
716 /// entries indicate that the particular selector ID has not yet
718 SmallVector<Selector, 16> SelectorsLoaded;
720 using GlobalSelectorMapType =
721 ContinuousRangeMap<serialization::SelectorID, ModuleFile *, 4>;
723 /// Mapping from global selector IDs to the module in which the
724 /// global selector ID to produce a local ID.
725 GlobalSelectorMapType GlobalSelectorMap;
727 /// The generation number of the last time we loaded data from the
728 /// global method pool for this selector.
729 llvm::DenseMap<Selector, unsigned> SelectorGeneration;
731 /// Whether a selector is out of date. We mark a selector as out of date
732 /// if we load another module after the method pool entry was pulled in.
733 llvm::DenseMap<Selector, bool> SelectorOutOfDate;
735 struct PendingMacroInfo {
737 uint64_t MacroDirectivesOffset;
739 PendingMacroInfo(ModuleFile *M, uint64_t MacroDirectivesOffset)
740 : M(M), MacroDirectivesOffset(MacroDirectivesOffset) {}
743 using PendingMacroIDsMap =
744 llvm::MapVector<IdentifierInfo *, SmallVector<PendingMacroInfo, 2>>;
746 /// Mapping from identifiers that have a macro history to the global
747 /// IDs have not yet been deserialized to the global IDs of those macros.
748 PendingMacroIDsMap PendingMacroIDs;
750 using GlobalPreprocessedEntityMapType =
751 ContinuousRangeMap<unsigned, ModuleFile *, 4>;
753 /// Mapping from global preprocessing entity IDs to the module in
754 /// which the preprocessed entity resides along with the offset that should be
755 /// added to the global preprocessing entity ID to produce a local ID.
756 GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap;
758 using GlobalSkippedRangeMapType =
759 ContinuousRangeMap<unsigned, ModuleFile *, 4>;
761 /// Mapping from global skipped range base IDs to the module in which
762 /// the skipped ranges reside.
763 GlobalSkippedRangeMapType GlobalSkippedRangeMap;
765 /// \name CodeGen-relevant special data
766 /// Fields containing data that is relevant to CodeGen.
769 /// The IDs of all declarations that fulfill the criteria of
770 /// "interesting" decls.
772 /// This contains the data loaded from all EAGERLY_DESERIALIZED_DECLS blocks
773 /// in the chain. The referenced declarations are deserialized and passed to
774 /// the consumer eagerly.
775 SmallVector<uint64_t, 16> EagerlyDeserializedDecls;
777 /// The IDs of all tentative definitions stored in the chain.
779 /// Sema keeps track of all tentative definitions in a TU because it has to
780 /// complete them and pass them on to CodeGen. Thus, tentative definitions in
781 /// the PCH chain must be eagerly deserialized.
782 SmallVector<uint64_t, 16> TentativeDefinitions;
784 /// The IDs of all CXXRecordDecls stored in the chain whose VTables are
787 /// CodeGen has to emit VTables for these records, so they have to be eagerly
789 SmallVector<uint64_t, 64> VTableUses;
791 /// A snapshot of the pending instantiations in the chain.
793 /// This record tracks the instantiations that Sema has to perform at the
794 /// end of the TU. It consists of a pair of values for every pending
795 /// instantiation where the first value is the ID of the decl and the second
796 /// is the instantiation location.
797 SmallVector<uint64_t, 64> PendingInstantiations;
801 /// \name DiagnosticsEngine-relevant special data
802 /// Fields containing data that is used for generating diagnostics
805 /// A snapshot of Sema's unused file-scoped variable tracking, for
806 /// generating warnings.
807 SmallVector<uint64_t, 16> UnusedFileScopedDecls;
809 /// A list of all the delegating constructors we've seen, to diagnose
811 SmallVector<uint64_t, 4> DelegatingCtorDecls;
813 /// Method selectors used in a @selector expression. Used for
814 /// implementation of -Wselector.
815 SmallVector<uint64_t, 64> ReferencedSelectorsData;
817 /// A snapshot of Sema's weak undeclared identifier tracking, for
818 /// generating warnings.
819 SmallVector<uint64_t, 64> WeakUndeclaredIdentifiers;
821 /// The IDs of type aliases for ext_vectors that exist in the chain.
823 /// Used by Sema for finding sugared names for ext_vectors in diagnostics.
824 SmallVector<uint64_t, 4> ExtVectorDecls;
828 /// \name Sema-relevant special data
829 /// Fields containing data that is used for semantic analysis
832 /// The IDs of all potentially unused typedef names in the chain.
834 /// Sema tracks these to emit warnings.
835 SmallVector<uint64_t, 16> UnusedLocalTypedefNameCandidates;
837 /// Our current depth in #pragma cuda force_host_device begin/end
839 unsigned ForceCUDAHostDeviceDepth = 0;
841 /// The IDs of the declarations Sema stores directly.
843 /// Sema tracks a few important decls, such as namespace std, directly.
844 SmallVector<uint64_t, 4> SemaDeclRefs;
846 /// The IDs of the types ASTContext stores directly.
848 /// The AST context tracks a few important types, such as va_list, directly.
849 SmallVector<uint64_t, 16> SpecialTypes;
851 /// The IDs of CUDA-specific declarations ASTContext stores directly.
853 /// The AST context tracks a few important decls, currently cudaConfigureCall,
855 SmallVector<uint64_t, 2> CUDASpecialDeclRefs;
857 /// The floating point pragma option settings.
858 SmallVector<uint64_t, 1> FPPragmaOptions;
860 /// The pragma clang optimize location (if the pragma state is "off").
861 SourceLocation OptimizeOffPragmaLocation;
863 /// The PragmaMSStructKind pragma ms_struct state if set, or -1.
864 int PragmaMSStructState = -1;
866 /// The PragmaMSPointersToMembersKind pragma pointers_to_members state.
867 int PragmaMSPointersToMembersState = -1;
868 SourceLocation PointersToMembersPragmaLocation;
870 /// The pragma pack state.
871 Optional<unsigned> PragmaPackCurrentValue;
872 SourceLocation PragmaPackCurrentLocation;
873 struct PragmaPackStackEntry {
875 SourceLocation Location;
876 SourceLocation PushLocation;
879 llvm::SmallVector<PragmaPackStackEntry, 2> PragmaPackStack;
880 llvm::SmallVector<std::string, 2> PragmaPackStrings;
882 /// The OpenCL extension settings.
883 OpenCLOptions OpenCLExtensions;
885 /// Extensions required by an OpenCL type.
886 llvm::DenseMap<const Type *, std::set<std::string>> OpenCLTypeExtMap;
888 /// Extensions required by an OpenCL declaration.
889 llvm::DenseMap<const Decl *, std::set<std::string>> OpenCLDeclExtMap;
891 /// A list of the namespaces we've seen.
892 SmallVector<uint64_t, 4> KnownNamespaces;
894 /// A list of undefined decls with internal linkage followed by the
895 /// SourceLocation of a matching ODR-use.
896 SmallVector<uint64_t, 8> UndefinedButUsed;
898 /// Delete expressions to analyze at the end of translation unit.
899 SmallVector<uint64_t, 8> DelayedDeleteExprs;
901 // A list of late parsed template function data.
902 SmallVector<uint64_t, 1> LateParsedTemplates;
905 struct ImportedSubmodule {
906 serialization::SubmoduleID ID;
907 SourceLocation ImportLoc;
909 ImportedSubmodule(serialization::SubmoduleID ID, SourceLocation ImportLoc)
910 : ID(ID), ImportLoc(ImportLoc) {}
914 /// A list of modules that were imported by precompiled headers or
915 /// any other non-module AST file.
916 SmallVector<ImportedSubmodule, 2> ImportedModules;
919 /// The system include root to be used when loading the
920 /// precompiled header.
921 std::string isysroot;
923 /// Whether to disable the normal validation performed on precompiled
924 /// headers when they are loaded.
925 bool DisableValidation;
927 /// Whether to accept an AST file with compiler errors.
928 bool AllowASTWithCompilerErrors;
930 /// Whether to accept an AST file that has a different configuration
931 /// from the current compiler instance.
932 bool AllowConfigurationMismatch;
934 /// Whether validate system input files.
935 bool ValidateSystemInputs;
937 /// Whether we are allowed to use the global module index.
940 /// Whether we have tried loading the global module index yet.
941 bool TriedLoadingGlobalIndex = false;
943 ///Whether we are currently processing update records.
944 bool ProcessingUpdateRecords = false;
946 using SwitchCaseMapTy = llvm::DenseMap<unsigned, SwitchCase *>;
948 /// Mapping from switch-case IDs in the chain to switch-case statements
950 /// Statements usually don't have IDs, but switch cases need them, so that the
951 /// switch statement can refer to them.
952 SwitchCaseMapTy SwitchCaseStmts;
954 SwitchCaseMapTy *CurrSwitchCaseStmts;
956 /// The number of source location entries de-serialized from
958 unsigned NumSLocEntriesRead = 0;
960 /// The number of source location entries in the chain.
961 unsigned TotalNumSLocEntries = 0;
963 /// The number of statements (and expressions) de-serialized
965 unsigned NumStatementsRead = 0;
967 /// The total number of statements (and expressions) stored
969 unsigned TotalNumStatements = 0;
971 /// The number of macros de-serialized from the chain.
972 unsigned NumMacrosRead = 0;
974 /// The total number of macros stored in the chain.
975 unsigned TotalNumMacros = 0;
977 /// The number of lookups into identifier tables.
978 unsigned NumIdentifierLookups = 0;
980 /// The number of lookups into identifier tables that succeed.
981 unsigned NumIdentifierLookupHits = 0;
983 /// The number of selectors that have been read.
984 unsigned NumSelectorsRead = 0;
986 /// The number of method pool entries that have been read.
987 unsigned NumMethodPoolEntriesRead = 0;
989 /// The number of times we have looked up a selector in the method
991 unsigned NumMethodPoolLookups = 0;
993 /// The number of times we have looked up a selector in the method
994 /// pool and found something.
995 unsigned NumMethodPoolHits = 0;
997 /// The number of times we have looked up a selector in the method
998 /// pool within a specific module.
999 unsigned NumMethodPoolTableLookups = 0;
1001 /// The number of times we have looked up a selector in the method
1002 /// pool within a specific module and found something.
1003 unsigned NumMethodPoolTableHits = 0;
1005 /// The total number of method pool entries in the selector table.
1006 unsigned TotalNumMethodPoolEntries = 0;
1008 /// Number of lexical decl contexts read/total.
1009 unsigned NumLexicalDeclContextsRead = 0, TotalLexicalDeclContexts = 0;
1011 /// Number of visible decl contexts read/total.
1012 unsigned NumVisibleDeclContextsRead = 0, TotalVisibleDeclContexts = 0;
1014 /// Total size of modules, in bits, currently loaded
1015 uint64_t TotalModulesSizeInBits = 0;
1017 /// Number of Decl/types that are currently deserializing.
1018 unsigned NumCurrentElementsDeserializing = 0;
1020 /// Set true while we are in the process of passing deserialized
1021 /// "interesting" decls to consumer inside FinishedDeserializing().
1022 /// This is used as a guard to avoid recursively repeating the process of
1023 /// passing decls to consumer.
1024 bool PassingDeclsToConsumer = false;
1026 /// The set of identifiers that were read while the AST reader was
1027 /// (recursively) loading declarations.
1029 /// The declarations on the identifier chain for these identifiers will be
1030 /// loaded once the recursive loading has completed.
1031 llvm::MapVector<IdentifierInfo *, SmallVector<uint32_t, 4>>
1032 PendingIdentifierInfos;
1034 /// The set of lookup results that we have faked in order to support
1035 /// merging of partially deserialized decls but that we have not yet removed.
1036 llvm::SmallMapVector<IdentifierInfo *, SmallVector<NamedDecl*, 2>, 16>
1037 PendingFakeLookupResults;
1039 /// The generation number of each identifier, which keeps track of
1040 /// the last time we loaded information about this identifier.
1041 llvm::DenseMap<IdentifierInfo *, unsigned> IdentifierGeneration;
1043 class InterestingDecl {
1045 bool DeclHasPendingBody;
1048 InterestingDecl(Decl *D, bool HasBody)
1049 : D(D), DeclHasPendingBody(HasBody) {}
1051 Decl *getDecl() { return D; }
1053 /// Whether the declaration has a pending body.
1054 bool hasPendingBody() { return DeclHasPendingBody; }
1057 /// Contains declarations and definitions that could be
1058 /// "interesting" to the ASTConsumer, when we get that AST consumer.
1060 /// "Interesting" declarations are those that have data that may
1061 /// need to be emitted, such as inline function definitions or
1062 /// Objective-C protocols.
1063 std::deque<InterestingDecl> PotentiallyInterestingDecls;
1065 /// The list of deduced function types that we have not yet read, because
1066 /// they might contain a deduced return type that refers to a local type
1067 /// declared within the function.
1068 SmallVector<std::pair<FunctionDecl *, serialization::TypeID>, 16>
1069 PendingFunctionTypes;
1071 /// The list of redeclaration chains that still need to be
1072 /// reconstructed, and the local offset to the corresponding list
1073 /// of redeclarations.
1074 SmallVector<std::pair<Decl *, uint64_t>, 16> PendingDeclChains;
1076 /// The list of canonical declarations whose redeclaration chains
1077 /// need to be marked as incomplete once we're done deserializing things.
1078 SmallVector<Decl *, 16> PendingIncompleteDeclChains;
1080 /// The Decl IDs for the Sema/Lexical DeclContext of a Decl that has
1081 /// been loaded but its DeclContext was not set yet.
1082 struct PendingDeclContextInfo {
1084 serialization::GlobalDeclID SemaDC;
1085 serialization::GlobalDeclID LexicalDC;
1088 /// The set of Decls that have been loaded but their DeclContexts are
1091 /// The DeclContexts for these Decls will be set once recursive loading has
1093 std::deque<PendingDeclContextInfo> PendingDeclContextInfos;
1095 /// The set of NamedDecls that have been loaded, but are members of a
1096 /// context that has been merged into another context where the corresponding
1097 /// declaration is either missing or has not yet been loaded.
1099 /// We will check whether the corresponding declaration is in fact missing
1100 /// once recursing loading has been completed.
1101 llvm::SmallVector<NamedDecl *, 16> PendingOdrMergeChecks;
1103 using DataPointers =
1104 std::pair<CXXRecordDecl *, struct CXXRecordDecl::DefinitionData *>;
1106 /// Record definitions in which we found an ODR violation.
1107 llvm::SmallDenseMap<CXXRecordDecl *, llvm::SmallVector<DataPointers, 2>, 2>
1108 PendingOdrMergeFailures;
1110 /// Function definitions in which we found an ODR violation.
1111 llvm::SmallDenseMap<FunctionDecl *, llvm::SmallVector<FunctionDecl *, 2>, 2>
1112 PendingFunctionOdrMergeFailures;
1114 /// Enum definitions in which we found an ODR violation.
1115 llvm::SmallDenseMap<EnumDecl *, llvm::SmallVector<EnumDecl *, 2>, 2>
1116 PendingEnumOdrMergeFailures;
1118 /// DeclContexts in which we have diagnosed an ODR violation.
1119 llvm::SmallPtrSet<DeclContext*, 2> DiagnosedOdrMergeFailures;
1121 /// The set of Objective-C categories that have been deserialized
1122 /// since the last time the declaration chains were linked.
1123 llvm::SmallPtrSet<ObjCCategoryDecl *, 16> CategoriesDeserialized;
1125 /// The set of Objective-C class definitions that have already been
1126 /// loaded, for which we will need to check for categories whenever a new
1127 /// module is loaded.
1128 SmallVector<ObjCInterfaceDecl *, 16> ObjCClassesLoaded;
1131 llvm::DenseMap<Decl *, SmallVector<serialization::DeclID, 2>>;
1133 /// A mapping from canonical declarations to the set of global
1134 /// declaration IDs for key declaration that have been merged with that
1135 /// canonical declaration. A key declaration is a formerly-canonical
1136 /// declaration whose module did not import any other key declaration for that
1137 /// entity. These are the IDs that we use as keys when finding redecl chains.
1138 KeyDeclsMap KeyDecls;
1140 /// A mapping from DeclContexts to the semantic DeclContext that we
1141 /// are treating as the definition of the entity. This is used, for instance,
1142 /// when merging implicit instantiations of class templates across modules.
1143 llvm::DenseMap<DeclContext *, DeclContext *> MergedDeclContexts;
1145 /// A mapping from canonical declarations of enums to their canonical
1146 /// definitions. Only populated when using modules in C++.
1147 llvm::DenseMap<EnumDecl *, EnumDecl *> EnumDefinitions;
1149 /// When reading a Stmt tree, Stmt operands are placed in this stack.
1150 SmallVector<Stmt *, 16> StmtStack;
1152 /// What kind of records we are reading.
1154 Read_None, Read_Decl, Read_Type, Read_Stmt
1157 /// What kind of records we are reading.
1158 ReadingKind ReadingKind = Read_None;
1160 /// RAII object to change the reading kind.
1161 class ReadingKindTracker {
1163 enum ReadingKind PrevKind;
1166 ReadingKindTracker(enum ReadingKind newKind, ASTReader &reader)
1167 : Reader(reader), PrevKind(Reader.ReadingKind) {
1168 Reader.ReadingKind = newKind;
1171 ReadingKindTracker(const ReadingKindTracker &) = delete;
1172 ReadingKindTracker &operator=(const ReadingKindTracker &) = delete;
1173 ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; }
1176 /// RAII object to mark the start of processing updates.
1177 class ProcessingUpdatesRAIIObj {
1182 ProcessingUpdatesRAIIObj(ASTReader &reader)
1183 : Reader(reader), PrevState(Reader.ProcessingUpdateRecords) {
1184 Reader.ProcessingUpdateRecords = true;
1187 ProcessingUpdatesRAIIObj(const ProcessingUpdatesRAIIObj &) = delete;
1188 ProcessingUpdatesRAIIObj &
1189 operator=(const ProcessingUpdatesRAIIObj &) = delete;
1190 ~ProcessingUpdatesRAIIObj() { Reader.ProcessingUpdateRecords = PrevState; }
1193 /// Suggested contents of the predefines buffer, after this
1194 /// PCH file has been processed.
1196 /// In most cases, this string will be empty, because the predefines
1197 /// buffer computed to build the PCH file will be identical to the
1198 /// predefines buffer computed from the command line. However, when
1199 /// there are differences that the PCH reader can work around, this
1200 /// predefines buffer may contain additional definitions.
1201 std::string SuggestedPredefines;
1203 llvm::DenseMap<const Decl *, bool> DefinitionSource;
1205 /// Reads a statement from the specified cursor.
1206 Stmt *ReadStmtFromStream(ModuleFile &F);
1208 struct InputFileInfo {
1209 std::string Filename;
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;
1446 /// Load the AST file and validate its contents against the given
1449 /// \param PP the preprocessor associated with the context in which this
1450 /// precompiled header will be loaded.
1452 /// \param Context the AST context that this precompiled header will be
1453 /// loaded into, if any.
1455 /// \param PCHContainerRdr the PCHContainerOperations to use for loading and
1456 /// creating modules.
1458 /// \param Extensions the list of module file extensions that can be loaded
1459 /// from the AST files.
1461 /// \param isysroot If non-NULL, the system include path specified by the
1462 /// user. This is only used with relocatable PCH files. If non-NULL,
1463 /// a relocatable PCH file will use the default path "/".
1465 /// \param DisableValidation If true, the AST reader will suppress most
1466 /// of its regular consistency checking, allowing the use of precompiled
1467 /// headers that cannot be determined to be compatible.
1469 /// \param AllowASTWithCompilerErrors If true, the AST reader will accept an
1470 /// AST file the was created out of an AST with compiler errors,
1471 /// otherwise it will reject it.
1473 /// \param AllowConfigurationMismatch If true, the AST reader will not check
1474 /// for configuration differences between the AST file and the invocation.
1476 /// \param ValidateSystemInputs If true, the AST reader will validate
1477 /// system input files in addition to user input files. This is only
1478 /// meaningful if \p DisableValidation is false.
1480 /// \param UseGlobalIndex If true, the AST reader will try to load and use
1481 /// the global module index.
1483 /// \param ReadTimer If non-null, a timer used to track the time spent
1485 ASTReader(Preprocessor &PP, ASTContext *Context,
1486 const PCHContainerReader &PCHContainerRdr,
1487 ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
1488 StringRef isysroot = "", bool DisableValidation = false,
1489 bool AllowASTWithCompilerErrors = false,
1490 bool AllowConfigurationMismatch = false,
1491 bool ValidateSystemInputs = false, bool UseGlobalIndex = true,
1492 std::unique_ptr<llvm::Timer> ReadTimer = {});
1493 ASTReader(const ASTReader &) = delete;
1494 ASTReader &operator=(const ASTReader &) = delete;
1495 ~ASTReader() override;
1497 SourceManager &getSourceManager() const { return SourceMgr; }
1498 FileManager &getFileManager() const { return FileMgr; }
1499 DiagnosticsEngine &getDiags() const { return Diags; }
1501 /// Flags that indicate what kind of AST loading failures the client
1502 /// of the AST reader can directly handle.
1504 /// When a client states that it can handle a particular kind of failure,
1505 /// the AST reader will not emit errors when producing that kind of failure.
1506 enum LoadFailureCapabilities {
1507 /// The client can't handle any AST loading failures.
1510 /// The client can handle an AST file that cannot load because it
1514 /// The client can handle an AST file that cannot load because it
1515 /// is out-of-date relative to its input files.
1516 ARR_OutOfDate = 0x2,
1518 /// The client can handle an AST file that cannot load because it
1519 /// was built with a different version of Clang.
1520 ARR_VersionMismatch = 0x4,
1522 /// The client can handle an AST file that cannot load because it's
1523 /// compiled configuration doesn't match that of the context it was
1525 ARR_ConfigurationMismatch = 0x8
1528 /// Load the AST file designated by the given file name.
1530 /// \param FileName The name of the AST file to load.
1532 /// \param Type The kind of AST being loaded, e.g., PCH, module, main file,
1535 /// \param ImportLoc the location where the module file will be considered as
1536 /// imported from. For non-module AST types it should be invalid.
1538 /// \param ClientLoadCapabilities The set of client load-failure
1539 /// capabilities, represented as a bitset of the enumerators of
1540 /// LoadFailureCapabilities.
1542 /// \param Imported optional out-parameter to append the list of modules
1543 /// that were imported by precompiled headers or any other non-module AST file
1544 ASTReadResult ReadAST(StringRef FileName, ModuleKind Type,
1545 SourceLocation ImportLoc,
1546 unsigned ClientLoadCapabilities,
1547 SmallVectorImpl<ImportedSubmodule> *Imported = nullptr);
1549 /// Make the entities in the given module and any of its (non-explicit)
1550 /// submodules visible to name lookup.
1552 /// \param Mod The module whose names should be made visible.
1554 /// \param NameVisibility The level of visibility to give the names in the
1555 /// module. Visibility can only be increased over time.
1557 /// \param ImportLoc The location at which the import occurs.
1558 void makeModuleVisible(Module *Mod,
1559 Module::NameVisibilityKind NameVisibility,
1560 SourceLocation ImportLoc);
1562 /// Make the names within this set of hidden names visible.
1563 void makeNamesVisible(const HiddenNames &Names, Module *Owner);
1565 /// Note that MergedDef is a redefinition of the canonical definition
1566 /// Def, so Def should be visible whenever MergedDef is.
1567 void mergeDefinitionVisibility(NamedDecl *Def, NamedDecl *MergedDef);
1569 /// Take the AST callbacks listener.
1570 std::unique_ptr<ASTReaderListener> takeListener() {
1571 return std::move(Listener);
1574 /// Set the AST callbacks listener.
1575 void setListener(std::unique_ptr<ASTReaderListener> Listener) {
1576 this->Listener = std::move(Listener);
1579 /// Add an AST callback listener.
1581 /// Takes ownership of \p L.
1582 void addListener(std::unique_ptr<ASTReaderListener> L) {
1584 L = llvm::make_unique<ChainedASTReaderListener>(std::move(L),
1585 std::move(Listener));
1586 Listener = std::move(L);
1589 /// RAII object to temporarily add an AST callback listener.
1590 class ListenerScope {
1592 bool Chained = false;
1595 ListenerScope(ASTReader &Reader, std::unique_ptr<ASTReaderListener> L)
1597 auto Old = Reader.takeListener();
1600 L = llvm::make_unique<ChainedASTReaderListener>(std::move(L),
1603 Reader.setListener(std::move(L));
1607 auto New = Reader.takeListener();
1609 Reader.setListener(static_cast<ChainedASTReaderListener *>(New.get())
1614 /// Set the AST deserialization listener.
1615 void setDeserializationListener(ASTDeserializationListener *Listener,
1616 bool TakeOwnership = false);
1618 /// Get the AST deserialization listener.
1619 ASTDeserializationListener *getDeserializationListener() {
1620 return DeserializationListener;
1623 /// Determine whether this AST reader has a global index.
1624 bool hasGlobalIndex() const { return (bool)GlobalIndex; }
1626 /// Return global module index.
1627 GlobalModuleIndex *getGlobalIndex() { return GlobalIndex.get(); }
1629 /// Reset reader for a reload try.
1630 void resetForReload() { TriedLoadingGlobalIndex = false; }
1632 /// Attempts to load the global index.
1634 /// \returns true if loading the global index has failed for any reason.
1635 bool loadGlobalIndex();
1637 /// Determine whether we tried to load the global index, but failed,
1638 /// e.g., because it is out-of-date or does not exist.
1639 bool isGlobalIndexUnavailable() const;
1641 /// Initializes the ASTContext
1642 void InitializeContext();
1644 /// Update the state of Sema after loading some additional modules.
1647 /// Add in-memory (virtual file) buffer.
1648 void addInMemoryBuffer(StringRef &FileName,
1649 std::unique_ptr<llvm::MemoryBuffer> Buffer) {
1650 ModuleMgr.addInMemoryBuffer(FileName, std::move(Buffer));
1653 /// Finalizes the AST reader's state before writing an AST file to
1656 /// This operation may undo temporary state in the AST that should not be
1658 void finalizeForWriting();
1660 /// Retrieve the module manager.
1661 ModuleManager &getModuleManager() { return ModuleMgr; }
1663 /// Retrieve the preprocessor.
1664 Preprocessor &getPreprocessor() const { return PP; }
1666 /// Retrieve the name of the original source file name for the primary
1668 StringRef getOriginalSourceFile() {
1669 return ModuleMgr.getPrimaryModule().OriginalSourceFileName;
1672 /// Retrieve the name of the original source file name directly from
1673 /// the AST file, without actually loading the AST file.
1675 getOriginalSourceFile(const std::string &ASTFileName, FileManager &FileMgr,
1676 const PCHContainerReader &PCHContainerRdr,
1677 DiagnosticsEngine &Diags);
1679 /// Read the control block for the named AST file.
1681 /// \returns true if an error occurred, false otherwise.
1683 readASTFileControlBlock(StringRef Filename, FileManager &FileMgr,
1684 const PCHContainerReader &PCHContainerRdr,
1685 bool FindModuleFileExtensions,
1686 ASTReaderListener &Listener,
1687 bool ValidateDiagnosticOptions);
1689 /// Determine whether the given AST file is acceptable to load into a
1690 /// translation unit with the given language and target options.
1691 static bool isAcceptableASTFile(StringRef Filename, FileManager &FileMgr,
1692 const PCHContainerReader &PCHContainerRdr,
1693 const LangOptions &LangOpts,
1694 const TargetOptions &TargetOpts,
1695 const PreprocessorOptions &PPOpts,
1696 StringRef ExistingModuleCachePath);
1698 /// Returns the suggested contents of the predefines buffer,
1699 /// which contains a (typically-empty) subset of the predefines
1700 /// build prior to including the precompiled header.
1701 const std::string &getSuggestedPredefines() { return SuggestedPredefines; }
1703 /// Read a preallocated preprocessed entity from the external source.
1705 /// \returns null if an error occurred that prevented the preprocessed
1706 /// entity from being loaded.
1707 PreprocessedEntity *ReadPreprocessedEntity(unsigned Index) override;
1709 /// Returns a pair of [Begin, End) indices of preallocated
1710 /// preprocessed entities that \p Range encompasses.
1711 std::pair<unsigned, unsigned>
1712 findPreprocessedEntitiesInRange(SourceRange Range) override;
1714 /// Optionally returns true or false if the preallocated preprocessed
1715 /// entity with index \p Index came from file \p FID.
1716 Optional<bool> isPreprocessedEntityInFileID(unsigned Index,
1717 FileID FID) override;
1719 /// Read a preallocated skipped range from the external source.
1720 SourceRange ReadSkippedRange(unsigned Index) override;
1722 /// Read the header file information for the given file entry.
1723 HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE) override;
1725 void ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag);
1727 /// Returns the number of source locations found in the chain.
1728 unsigned getTotalNumSLocs() const {
1729 return TotalNumSLocEntries;
1732 /// Returns the number of identifiers found in the chain.
1733 unsigned getTotalNumIdentifiers() const {
1734 return static_cast<unsigned>(IdentifiersLoaded.size());
1737 /// Returns the number of macros found in the chain.
1738 unsigned getTotalNumMacros() const {
1739 return static_cast<unsigned>(MacrosLoaded.size());
1742 /// Returns the number of types found in the chain.
1743 unsigned getTotalNumTypes() const {
1744 return static_cast<unsigned>(TypesLoaded.size());
1747 /// Returns the number of declarations found in the chain.
1748 unsigned getTotalNumDecls() const {
1749 return static_cast<unsigned>(DeclsLoaded.size());
1752 /// Returns the number of submodules known.
1753 unsigned getTotalNumSubmodules() const {
1754 return static_cast<unsigned>(SubmodulesLoaded.size());
1757 /// Returns the number of selectors found in the chain.
1758 unsigned getTotalNumSelectors() const {
1759 return static_cast<unsigned>(SelectorsLoaded.size());
1762 /// Returns the number of preprocessed entities known to the AST
1764 unsigned getTotalNumPreprocessedEntities() const {
1765 unsigned Result = 0;
1766 for (const auto &M : ModuleMgr)
1767 Result += M.NumPreprocessedEntities;
1771 /// Reads a TemplateArgumentLocInfo appropriate for the
1772 /// given TemplateArgument kind.
1773 TemplateArgumentLocInfo
1774 GetTemplateArgumentLocInfo(ModuleFile &F, TemplateArgument::ArgKind Kind,
1775 const RecordData &Record, unsigned &Idx);
1777 /// Reads a TemplateArgumentLoc.
1779 ReadTemplateArgumentLoc(ModuleFile &F,
1780 const RecordData &Record, unsigned &Idx);
1782 const ASTTemplateArgumentListInfo*
1783 ReadASTTemplateArgumentListInfo(ModuleFile &F,
1784 const RecordData &Record, unsigned &Index);
1786 /// Reads a declarator info from the given record.
1787 TypeSourceInfo *GetTypeSourceInfo(ModuleFile &F,
1788 const RecordData &Record, unsigned &Idx);
1790 /// Raad the type locations for the given TInfo.
1791 void ReadTypeLoc(ModuleFile &F, const RecordData &Record, unsigned &Idx,
1794 /// Resolve a type ID into a type, potentially building a new
1796 QualType GetType(serialization::TypeID ID);
1798 /// Resolve a local type ID within a given AST file into a type.
1799 QualType getLocalType(ModuleFile &F, unsigned LocalID);
1801 /// Map a local type ID within a given AST file into a global type ID.
1802 serialization::TypeID getGlobalTypeID(ModuleFile &F, unsigned LocalID) const;
1804 /// Read a type from the current position in the given record, which
1805 /// was read from the given AST file.
1806 QualType readType(ModuleFile &F, const RecordData &Record, unsigned &Idx) {
1807 if (Idx >= Record.size())
1810 return getLocalType(F, Record[Idx++]);
1813 /// Map from a local declaration ID within a given module to a
1814 /// global declaration ID.
1815 serialization::DeclID getGlobalDeclID(ModuleFile &F,
1816 serialization::LocalDeclID LocalID) const;
1818 /// Returns true if global DeclID \p ID originated from module \p M.
1819 bool isDeclIDFromModule(serialization::GlobalDeclID ID, ModuleFile &M) const;
1821 /// Retrieve the module file that owns the given declaration, or NULL
1822 /// if the declaration is not from a module file.
1823 ModuleFile *getOwningModuleFile(const Decl *D);
1825 /// Get the best name we know for the module that owns the given
1826 /// declaration, or an empty string if the declaration is not from a module.
1827 std::string getOwningModuleNameForDiagnostic(const Decl *D);
1829 /// Returns the source location for the decl \p ID.
1830 SourceLocation getSourceLocationForDeclID(serialization::GlobalDeclID ID);
1832 /// Resolve a declaration ID into a declaration, potentially
1833 /// building a new declaration.
1834 Decl *GetDecl(serialization::DeclID ID);
1835 Decl *GetExternalDecl(uint32_t ID) override;
1837 /// Resolve a declaration ID into a declaration. Return 0 if it's not
1838 /// been loaded yet.
1839 Decl *GetExistingDecl(serialization::DeclID ID);
1841 /// Reads a declaration with the given local ID in the given module.
1842 Decl *GetLocalDecl(ModuleFile &F, uint32_t LocalID) {
1843 return GetDecl(getGlobalDeclID(F, LocalID));
1846 /// Reads a declaration with the given local ID in the given module.
1848 /// \returns The requested declaration, casted to the given return type.
1849 template<typename T>
1850 T *GetLocalDeclAs(ModuleFile &F, uint32_t LocalID) {
1851 return cast_or_null<T>(GetLocalDecl(F, LocalID));
1854 /// Map a global declaration ID into the declaration ID used to
1855 /// refer to this declaration within the given module fule.
1857 /// \returns the global ID of the given declaration as known in the given
1859 serialization::DeclID
1860 mapGlobalIDToModuleFileGlobalID(ModuleFile &M,
1861 serialization::DeclID GlobalID);
1863 /// Reads a declaration ID from the given position in a record in the
1866 /// \returns The declaration ID read from the record, adjusted to a global ID.
1867 serialization::DeclID ReadDeclID(ModuleFile &F, const RecordData &Record,
1870 /// Reads a declaration from the given position in a record in the
1872 Decl *ReadDecl(ModuleFile &F, const RecordData &R, unsigned &I) {
1873 return GetDecl(ReadDeclID(F, R, I));
1876 /// Reads a declaration from the given position in a record in the
1879 /// \returns The declaration read from this location, casted to the given
1881 template<typename T>
1882 T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1883 return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1886 /// If any redeclarations of \p D have been imported since it was
1887 /// last checked, this digs out those redeclarations and adds them to the
1888 /// redeclaration chain for \p D.
1889 void CompleteRedeclChain(const Decl *D) override;
1891 CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override;
1893 /// Resolve the offset of a statement into a statement.
1895 /// This operation will read a new statement from the external
1896 /// source each time it is called, and is meant to be used via a
1897 /// LazyOffsetPtr (which is used by Decls for the body of functions, etc).
1898 Stmt *GetExternalDeclStmt(uint64_t Offset) override;
1900 /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the
1901 /// specified cursor. Read the abbreviations that are at the top of the block
1902 /// and then leave the cursor pointing into the block.
1903 static bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID);
1905 /// Finds all the visible declarations with a given name.
1906 /// The current implementation of this method just loads the entire
1907 /// lookup table as unmaterialized references.
1908 bool FindExternalVisibleDeclsByName(const DeclContext *DC,
1909 DeclarationName Name) override;
1911 /// Read all of the declarations lexically stored in a
1912 /// declaration context.
1914 /// \param DC The declaration context whose declarations will be
1917 /// \param IsKindWeWant A predicate indicating which declaration kinds
1918 /// we are interested in.
1920 /// \param Decls Vector that will contain the declarations loaded
1921 /// from the external source. The caller is responsible for merging
1922 /// these declarations with any declarations already stored in the
1923 /// declaration context.
1925 FindExternalLexicalDecls(const DeclContext *DC,
1926 llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
1927 SmallVectorImpl<Decl *> &Decls) override;
1929 /// Get the decls that are contained in a file in the Offset/Length
1930 /// range. \p Length can be 0 to indicate a point at \p Offset instead of
1932 void FindFileRegionDecls(FileID File, unsigned Offset, unsigned Length,
1933 SmallVectorImpl<Decl *> &Decls) override;
1935 /// Notify ASTReader that we started deserialization of
1936 /// a decl or type so until FinishedDeserializing is called there may be
1937 /// decls that are initializing. Must be paired with FinishedDeserializing.
1938 void StartedDeserializing() override;
1940 /// Notify ASTReader that we finished the deserialization of
1941 /// a decl or type. Must be paired with StartedDeserializing.
1942 void FinishedDeserializing() override;
1944 /// Function that will be invoked when we begin parsing a new
1945 /// translation unit involving this external AST source.
1947 /// This function will provide all of the external definitions to
1948 /// the ASTConsumer.
1949 void StartTranslationUnit(ASTConsumer *Consumer) override;
1951 /// Print some statistics about AST usage.
1952 void PrintStats() override;
1954 /// Dump information about the AST reader to standard error.
1957 /// Return the amount of memory used by memory buffers, breaking down
1958 /// by heap-backed versus mmap'ed memory.
1959 void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override;
1961 /// Initialize the semantic source with the Sema instance
1962 /// being used to perform semantic analysis on the abstract syntax
1964 void InitializeSema(Sema &S) override;
1966 /// Inform the semantic consumer that Sema is no longer available.
1967 void ForgetSema() override { SemaObj = nullptr; }
1969 /// Retrieve the IdentifierInfo for the named identifier.
1971 /// This routine builds a new IdentifierInfo for the given identifier. If any
1972 /// declarations with this name are visible from translation unit scope, their
1973 /// declarations will be deserialized and introduced into the declaration
1974 /// chain of the identifier.
1975 IdentifierInfo *get(StringRef Name) override;
1977 /// Retrieve an iterator into the set of all identifiers
1978 /// in all loaded AST files.
1979 IdentifierIterator *getIdentifiers() override;
1981 /// Load the contents of the global method pool for a given
1983 void ReadMethodPool(Selector Sel) override;
1985 /// Load the contents of the global method pool for a given
1986 /// selector if necessary.
1987 void updateOutOfDateSelector(Selector Sel) override;
1989 /// Load the set of namespaces that are known to the external source,
1990 /// which will be used during typo correction.
1991 void ReadKnownNamespaces(
1992 SmallVectorImpl<NamespaceDecl *> &Namespaces) override;
1994 void ReadUndefinedButUsed(
1995 llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) override;
1997 void ReadMismatchingDeleteExpressions(llvm::MapVector<
1998 FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &
2001 void ReadTentativeDefinitions(
2002 SmallVectorImpl<VarDecl *> &TentativeDefs) override;
2004 void ReadUnusedFileScopedDecls(
2005 SmallVectorImpl<const DeclaratorDecl *> &Decls) override;
2007 void ReadDelegatingConstructors(
2008 SmallVectorImpl<CXXConstructorDecl *> &Decls) override;
2010 void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) override;
2012 void ReadUnusedLocalTypedefNameCandidates(
2013 llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) override;
2015 void ReadReferencedSelectors(
2016 SmallVectorImpl<std::pair<Selector, SourceLocation>> &Sels) override;
2018 void ReadWeakUndeclaredIdentifiers(
2019 SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo>> &WI) override;
2021 void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) override;
2023 void ReadPendingInstantiations(
2024 SmallVectorImpl<std::pair<ValueDecl *,
2025 SourceLocation>> &Pending) override;
2027 void ReadLateParsedTemplates(
2028 llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
2031 /// Load a selector from disk, registering its ID if it exists.
2032 void LoadSelector(Selector Sel);
2034 void SetIdentifierInfo(unsigned ID, IdentifierInfo *II);
2035 void SetGloballyVisibleDecls(IdentifierInfo *II,
2036 const SmallVectorImpl<uint32_t> &DeclIDs,
2037 SmallVectorImpl<Decl *> *Decls = nullptr);
2039 /// Report a diagnostic.
2040 DiagnosticBuilder Diag(unsigned DiagID) const;
2042 /// Report a diagnostic.
2043 DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const;
2045 IdentifierInfo *DecodeIdentifierInfo(serialization::IdentifierID ID);
2047 IdentifierInfo *GetIdentifierInfo(ModuleFile &M, const RecordData &Record,
2049 return DecodeIdentifierInfo(getGlobalIdentifierID(M, Record[Idx++]));
2052 IdentifierInfo *GetIdentifier(serialization::IdentifierID ID) override {
2053 // Note that we are loading an identifier.
2054 Deserializing AnIdentifier(this);
2056 return DecodeIdentifierInfo(ID);
2059 IdentifierInfo *getLocalIdentifier(ModuleFile &M, unsigned LocalID);
2061 serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M,
2064 void resolvePendingMacro(IdentifierInfo *II, const PendingMacroInfo &PMInfo);
2066 /// Retrieve the macro with the given ID.
2067 MacroInfo *getMacro(serialization::MacroID ID);
2069 /// Retrieve the global macro ID corresponding to the given local
2070 /// ID within the given module file.
2071 serialization::MacroID getGlobalMacroID(ModuleFile &M, unsigned LocalID);
2073 /// Read the source location entry with index ID.
2074 bool ReadSLocEntry(int ID) override;
2076 /// Retrieve the module import location and module name for the
2077 /// given source manager entry ID.
2078 std::pair<SourceLocation, StringRef> getModuleImportLoc(int ID) override;
2080 /// Retrieve the global submodule ID given a module and its local ID
2082 serialization::SubmoduleID
2083 getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID);
2085 /// Retrieve the submodule that corresponds to a global submodule ID.
2087 Module *getSubmodule(serialization::SubmoduleID GlobalID);
2089 /// Retrieve the module that corresponds to the given module ID.
2091 /// Note: overrides method in ExternalASTSource
2092 Module *getModule(unsigned ID) override;
2094 bool DeclIsFromPCHWithObjectFile(const Decl *D) override;
2096 /// Retrieve the module file with a given local ID within the specified
2098 ModuleFile *getLocalModuleFile(ModuleFile &M, unsigned ID);
2100 /// Get an ID for the given module file.
2101 unsigned getModuleFileID(ModuleFile *M);
2103 /// Return a descriptor for the corresponding module.
2104 llvm::Optional<ASTSourceDescriptor> getSourceDescriptor(unsigned ID) override;
2106 ExtKind hasExternalDefinitions(const Decl *D) override;
2108 /// Retrieve a selector from the given module with its local ID
2110 Selector getLocalSelector(ModuleFile &M, unsigned LocalID);
2112 Selector DecodeSelector(serialization::SelectorID Idx);
2114 Selector GetExternalSelector(serialization::SelectorID ID) override;
2115 uint32_t GetNumExternalSelectors() override;
2117 Selector ReadSelector(ModuleFile &M, const RecordData &Record, unsigned &Idx) {
2118 return getLocalSelector(M, Record[Idx++]);
2121 /// Retrieve the global selector ID that corresponds to this
2122 /// the local selector ID in a given module.
2123 serialization::SelectorID getGlobalSelectorID(ModuleFile &F,
2124 unsigned LocalID) const;
2126 /// Read a declaration name.
2127 DeclarationName ReadDeclarationName(ModuleFile &F,
2128 const RecordData &Record, unsigned &Idx);
2129 void ReadDeclarationNameLoc(ModuleFile &F,
2130 DeclarationNameLoc &DNLoc, DeclarationName Name,
2131 const RecordData &Record, unsigned &Idx);
2132 void ReadDeclarationNameInfo(ModuleFile &F, DeclarationNameInfo &NameInfo,
2133 const RecordData &Record, unsigned &Idx);
2135 void ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info,
2136 const RecordData &Record, unsigned &Idx);
2138 NestedNameSpecifier *ReadNestedNameSpecifier(ModuleFile &F,
2139 const RecordData &Record,
2142 NestedNameSpecifierLoc ReadNestedNameSpecifierLoc(ModuleFile &F,
2143 const RecordData &Record,
2146 /// Read a template name.
2147 TemplateName ReadTemplateName(ModuleFile &F, const RecordData &Record,
2150 /// Read a template argument.
2151 TemplateArgument ReadTemplateArgument(ModuleFile &F, const RecordData &Record,
2153 bool Canonicalize = false);
2155 /// Read a template parameter list.
2156 TemplateParameterList *ReadTemplateParameterList(ModuleFile &F,
2157 const RecordData &Record,
2160 /// Read a template argument array.
2161 void ReadTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs,
2162 ModuleFile &F, const RecordData &Record,
2163 unsigned &Idx, bool Canonicalize = false);
2165 /// Read a UnresolvedSet structure.
2166 void ReadUnresolvedSet(ModuleFile &F, LazyASTUnresolvedSet &Set,
2167 const RecordData &Record, unsigned &Idx);
2169 /// Read a C++ base specifier.
2170 CXXBaseSpecifier ReadCXXBaseSpecifier(ModuleFile &F,
2171 const RecordData &Record,unsigned &Idx);
2173 /// Read a CXXCtorInitializer array.
2174 CXXCtorInitializer **
2175 ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record,
2178 /// Read the contents of a CXXCtorInitializer array.
2179 CXXCtorInitializer **GetExternalCXXCtorInitializers(uint64_t Offset) override;
2181 /// Read a source location from raw form and return it in its
2182 /// originating module file's source location space.
2183 SourceLocation ReadUntranslatedSourceLocation(uint32_t Raw) const {
2184 return SourceLocation::getFromRawEncoding((Raw >> 1) | (Raw << 31));
2187 /// Read a source location from raw form.
2188 SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, uint32_t Raw) const {
2189 SourceLocation Loc = ReadUntranslatedSourceLocation(Raw);
2190 return TranslateSourceLocation(ModuleFile, Loc);
2193 /// Translate a source location from another module file's source
2194 /// location space into ours.
2195 SourceLocation TranslateSourceLocation(ModuleFile &ModuleFile,
2196 SourceLocation Loc) const {
2197 if (!ModuleFile.ModuleOffsetMap.empty())
2198 ReadModuleOffsetMap(ModuleFile);
2199 assert(ModuleFile.SLocRemap.find(Loc.getOffset()) !=
2200 ModuleFile.SLocRemap.end() &&
2201 "Cannot find offset to remap.");
2202 int Remap = ModuleFile.SLocRemap.find(Loc.getOffset())->second;
2203 return Loc.getLocWithOffset(Remap);
2206 /// Read a source location.
2207 SourceLocation ReadSourceLocation(ModuleFile &ModuleFile,
2208 const RecordDataImpl &Record,
2210 return ReadSourceLocation(ModuleFile, Record[Idx++]);
2213 /// Read a source range.
2214 SourceRange ReadSourceRange(ModuleFile &F,
2215 const RecordData &Record, unsigned &Idx);
2217 /// Read an integral value
2218 llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx);
2220 /// Read a signed integral value
2221 llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx);
2223 /// Read a floating-point value
2224 llvm::APFloat ReadAPFloat(const RecordData &Record,
2225 const llvm::fltSemantics &Sem, unsigned &Idx);
2228 static std::string ReadString(const RecordData &Record, unsigned &Idx);
2231 static void SkipString(const RecordData &Record, unsigned &Idx) {
2232 Idx += Record[Idx] + 1;
2236 std::string ReadPath(ModuleFile &F, const RecordData &Record, unsigned &Idx);
2239 static void SkipPath(const RecordData &Record, unsigned &Idx) {
2240 SkipString(Record, Idx);
2243 /// Read a version tuple.
2244 static VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx);
2246 CXXTemporary *ReadCXXTemporary(ModuleFile &F, const RecordData &Record,
2249 /// Reads one attribute from the current stream position.
2250 Attr *ReadAttr(ModuleFile &M, const RecordData &Record, unsigned &Idx);
2252 /// Reads attributes from the current stream position.
2253 void ReadAttributes(ASTRecordReader &Record, AttrVec &Attrs);
2255 /// Reads a statement.
2256 Stmt *ReadStmt(ModuleFile &F);
2258 /// Reads an expression.
2259 Expr *ReadExpr(ModuleFile &F);
2261 /// Reads a sub-statement operand during statement reading.
2262 Stmt *ReadSubStmt() {
2263 assert(ReadingKind == Read_Stmt &&
2264 "Should be called only during statement reading!");
2265 // Subexpressions are stored from last to first, so the next Stmt we need
2266 // is at the back of the stack.
2267 assert(!StmtStack.empty() && "Read too many sub-statements!");
2268 return StmtStack.pop_back_val();
2271 /// Reads a sub-expression operand during statement reading.
2272 Expr *ReadSubExpr();
2274 /// Reads a token out of a record.
2275 Token ReadToken(ModuleFile &M, const RecordDataImpl &Record, unsigned &Idx);
2277 /// Reads the macro record located at the given offset.
2278 MacroInfo *ReadMacroRecord(ModuleFile &F, uint64_t Offset);
2280 /// Determine the global preprocessed entity ID that corresponds to
2281 /// the given local ID within the given module.
2282 serialization::PreprocessedEntityID
2283 getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const;
2285 /// Add a macro to deserialize its macro directive history.
2287 /// \param II The name of the macro.
2288 /// \param M The module file.
2289 /// \param MacroDirectivesOffset Offset of the serialized macro directive
2291 void addPendingMacro(IdentifierInfo *II, ModuleFile *M,
2292 uint64_t MacroDirectivesOffset);
2294 /// Read the set of macros defined by this external macro source.
2295 void ReadDefinedMacros() override;
2297 /// Update an out-of-date identifier.
2298 void updateOutOfDateIdentifier(IdentifierInfo &II) override;
2300 /// Note that this identifier is up-to-date.
2301 void markIdentifierUpToDate(IdentifierInfo *II);
2303 /// Load all external visible decls in the given DeclContext.
2304 void completeVisibleDeclsMap(const DeclContext *DC) override;
2306 /// Retrieve the AST context that this AST reader supplements.
2307 ASTContext &getContext() {
2308 assert(ContextObj && "requested AST context when not loading AST");
2312 // Contains the IDs for declarations that were requested before we have
2313 // access to a Sema object.
2314 SmallVector<uint64_t, 16> PreloadedDeclIDs;
2316 /// Retrieve the semantic analysis object used to analyze the
2317 /// translation unit in which the precompiled header is being
2319 Sema *getSema() { return SemaObj; }
2321 /// Get the identifier resolver used for name lookup / updates
2322 /// in the translation unit scope. We have one of these even if we don't
2323 /// have a Sema object.
2324 IdentifierResolver &getIdResolver();
2326 /// Retrieve the identifier table associated with the
2328 IdentifierTable &getIdentifierTable();
2330 /// Record that the given ID maps to the given switch-case
2332 void RecordSwitchCaseID(SwitchCase *SC, unsigned ID);
2334 /// Retrieve the switch-case statement with the given ID.
2335 SwitchCase *getSwitchCaseWithID(unsigned ID);
2337 void ClearSwitchCaseIDs();
2339 /// Cursors for comments blocks.
2340 SmallVector<std::pair<llvm::BitstreamCursor,
2341 serialization::ModuleFile *>, 8> CommentsCursors;
2343 /// Loads comments ranges.
2344 void ReadComments() override;
2346 /// Visit all the input files of the given module file.
2347 void visitInputFiles(serialization::ModuleFile &MF,
2348 bool IncludeSystem, bool Complain,
2349 llvm::function_ref<void(const serialization::InputFile &IF,
2350 bool isSystem)> Visitor);
2352 /// Visit all the top-level module maps loaded when building the given module
2354 void visitTopLevelModuleMaps(serialization::ModuleFile &MF,
2356 void(const FileEntry *)> Visitor);
2358 bool isProcessingUpdateRecords() { return ProcessingUpdateRecords; }
2361 /// An object for streaming information from a record.
2362 class ASTRecordReader {
2363 using ModuleFile = serialization::ModuleFile;
2368 ASTReader::RecordData Record;
2370 using RecordData = ASTReader::RecordData;
2371 using RecordDataImpl = ASTReader::RecordDataImpl;
2374 /// Construct an ASTRecordReader that uses the default encoding scheme.
2375 ASTRecordReader(ASTReader &Reader, ModuleFile &F) : Reader(&Reader), F(&F) {}
2377 /// Reads a record with id AbbrevID from Cursor, resetting the
2379 unsigned readRecord(llvm::BitstreamCursor &Cursor, unsigned AbbrevID);
2381 /// Is this a module file for a module (rather than a PCH or similar).
2382 bool isModule() const { return F->isModule(); }
2384 /// Retrieve the AST context that this AST reader supplements.
2385 ASTContext &getContext() { return Reader->getContext(); }
2387 /// The current position in this record.
2388 unsigned getIdx() const { return Idx; }
2390 /// The length of this record.
2391 size_t size() const { return Record.size(); }
2393 /// An arbitrary index in this record.
2394 const uint64_t &operator[](size_t N) { return Record[N]; }
2396 /// The last element in this record.
2397 const uint64_t &back() const { return Record.back(); }
2399 /// Returns the current value in this record, and advances to the
2401 const uint64_t &readInt() { return Record[Idx++]; }
2403 /// Returns the current value in this record, without advancing.
2404 const uint64_t &peekInt() { return Record[Idx]; }
2406 /// Skips the specified number of values.
2407 void skipInts(unsigned N) { Idx += N; }
2409 /// Retrieve the global submodule ID its local ID number.
2410 serialization::SubmoduleID
2411 getGlobalSubmoduleID(unsigned LocalID) {
2412 return Reader->getGlobalSubmoduleID(*F, LocalID);
2415 /// Retrieve the submodule that corresponds to a global submodule ID.
2416 Module *getSubmodule(serialization::SubmoduleID GlobalID) {
2417 return Reader->getSubmodule(GlobalID);
2420 /// Read the record that describes the lexical contents of a DC.
2421 bool readLexicalDeclContextStorage(uint64_t Offset, DeclContext *DC) {
2422 return Reader->ReadLexicalDeclContextStorage(*F, F->DeclsCursor, Offset,
2426 /// Read the record that describes the visible contents of a DC.
2427 bool readVisibleDeclContextStorage(uint64_t Offset,
2428 serialization::DeclID ID) {
2429 return Reader->ReadVisibleDeclContextStorage(*F, F->DeclsCursor, Offset,
2433 void readExceptionSpec(SmallVectorImpl<QualType> &ExceptionStorage,
2434 FunctionProtoType::ExceptionSpecInfo &ESI) {
2435 return Reader->readExceptionSpec(*F, ExceptionStorage, ESI, Record, Idx);
2438 /// Get the global offset corresponding to a local offset.
2439 uint64_t getGlobalBitOffset(uint32_t LocalOffset) {
2440 return Reader->getGlobalBitOffset(*F, LocalOffset);
2443 /// Reads a statement.
2444 Stmt *readStmt() { return Reader->ReadStmt(*F); }
2446 /// Reads an expression.
2447 Expr *readExpr() { return Reader->ReadExpr(*F); }
2449 /// Reads a sub-statement operand during statement reading.
2450 Stmt *readSubStmt() { return Reader->ReadSubStmt(); }
2452 /// Reads a sub-expression operand during statement reading.
2453 Expr *readSubExpr() { return Reader->ReadSubExpr(); }
2455 /// Reads a declaration with the given local ID in the given module.
2457 /// \returns The requested declaration, casted to the given return type.
2458 template<typename T>
2459 T *GetLocalDeclAs(uint32_t LocalID) {
2460 return cast_or_null<T>(Reader->GetLocalDecl(*F, LocalID));
2463 /// Reads a TemplateArgumentLocInfo appropriate for the
2464 /// given TemplateArgument kind, advancing Idx.
2465 TemplateArgumentLocInfo
2466 getTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind) {
2467 return Reader->GetTemplateArgumentLocInfo(*F, Kind, Record, Idx);
2470 /// Reads a TemplateArgumentLoc, advancing Idx.
2472 readTemplateArgumentLoc() {
2473 return Reader->ReadTemplateArgumentLoc(*F, Record, Idx);
2476 const ASTTemplateArgumentListInfo*
2477 readASTTemplateArgumentListInfo() {
2478 return Reader->ReadASTTemplateArgumentListInfo(*F, Record, Idx);
2481 /// Reads a declarator info from the given record, advancing Idx.
2482 TypeSourceInfo *getTypeSourceInfo() {
2483 return Reader->GetTypeSourceInfo(*F, Record, Idx);
2486 /// Reads the location information for a type.
2487 void readTypeLoc(TypeLoc TL) {
2488 return Reader->ReadTypeLoc(*F, Record, Idx, TL);
2491 /// Map a local type ID within a given AST file to a global type ID.
2492 serialization::TypeID getGlobalTypeID(unsigned LocalID) const {
2493 return Reader->getGlobalTypeID(*F, LocalID);
2496 /// Read a type from the current position in the record.
2497 QualType readType() {
2498 return Reader->readType(*F, Record, Idx);
2501 /// Reads a declaration ID from the given position in this record.
2503 /// \returns The declaration ID read from the record, adjusted to a global ID.
2504 serialization::DeclID readDeclID() {
2505 return Reader->ReadDeclID(*F, Record, Idx);
2508 /// Reads a declaration from the given position in a record in the
2509 /// given module, advancing Idx.
2511 return Reader->ReadDecl(*F, Record, Idx);
2514 /// Reads a declaration from the given position in the record,
2517 /// \returns The declaration read from this location, casted to the given
2519 template<typename T>
2521 return Reader->ReadDeclAs<T>(*F, Record, Idx);
2524 IdentifierInfo *getIdentifierInfo() {
2525 return Reader->GetIdentifierInfo(*F, Record, Idx);
2528 /// Read a selector from the Record, advancing Idx.
2529 Selector readSelector() {
2530 return Reader->ReadSelector(*F, Record, Idx);
2533 /// Read a declaration name, advancing Idx.
2534 DeclarationName readDeclarationName() {
2535 return Reader->ReadDeclarationName(*F, Record, Idx);
2537 void readDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name) {
2538 return Reader->ReadDeclarationNameLoc(*F, DNLoc, Name, Record, Idx);
2540 void readDeclarationNameInfo(DeclarationNameInfo &NameInfo) {
2541 return Reader->ReadDeclarationNameInfo(*F, NameInfo, Record, Idx);
2544 void readQualifierInfo(QualifierInfo &Info) {
2545 return Reader->ReadQualifierInfo(*F, Info, Record, Idx);
2548 NestedNameSpecifier *readNestedNameSpecifier() {
2549 return Reader->ReadNestedNameSpecifier(*F, Record, Idx);
2552 NestedNameSpecifierLoc readNestedNameSpecifierLoc() {
2553 return Reader->ReadNestedNameSpecifierLoc(*F, Record, Idx);
2556 /// Read a template name, advancing Idx.
2557 TemplateName readTemplateName() {
2558 return Reader->ReadTemplateName(*F, Record, Idx);
2561 /// Read a template argument, advancing Idx.
2562 TemplateArgument readTemplateArgument(bool Canonicalize = false) {
2563 return Reader->ReadTemplateArgument(*F, Record, Idx, Canonicalize);
2566 /// Read a template parameter list, advancing Idx.
2567 TemplateParameterList *readTemplateParameterList() {
2568 return Reader->ReadTemplateParameterList(*F, Record, Idx);
2571 /// Read a template argument array, advancing Idx.
2572 void readTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs,
2573 bool Canonicalize = false) {
2574 return Reader->ReadTemplateArgumentList(TemplArgs, *F, Record, Idx,
2578 /// Read a UnresolvedSet structure, advancing Idx.
2579 void readUnresolvedSet(LazyASTUnresolvedSet &Set) {
2580 return Reader->ReadUnresolvedSet(*F, Set, Record, Idx);
2583 /// Read a C++ base specifier, advancing Idx.
2584 CXXBaseSpecifier readCXXBaseSpecifier() {
2585 return Reader->ReadCXXBaseSpecifier(*F, Record, Idx);
2588 /// Read a CXXCtorInitializer array, advancing Idx.
2589 CXXCtorInitializer **readCXXCtorInitializers() {
2590 return Reader->ReadCXXCtorInitializers(*F, Record, Idx);
2593 CXXTemporary *readCXXTemporary() {
2594 return Reader->ReadCXXTemporary(*F, Record, Idx);
2597 /// Read a source location, advancing Idx.
2598 SourceLocation readSourceLocation() {
2599 return Reader->ReadSourceLocation(*F, Record, Idx);
2602 /// Read a source range, advancing Idx.
2603 SourceRange readSourceRange() {
2604 return Reader->ReadSourceRange(*F, Record, Idx);
2607 /// Read an integral value, advancing Idx.
2608 llvm::APInt readAPInt() {
2609 return Reader->ReadAPInt(Record, Idx);
2612 /// Read a signed integral value, advancing Idx.
2613 llvm::APSInt readAPSInt() {
2614 return Reader->ReadAPSInt(Record, Idx);
2617 /// Read a floating-point value, advancing Idx.
2618 llvm::APFloat readAPFloat(const llvm::fltSemantics &Sem) {
2619 return Reader->ReadAPFloat(Record, Sem,Idx);
2622 /// Read a string, advancing Idx.
2623 std::string readString() {
2624 return Reader->ReadString(Record, Idx);
2627 /// Read a path, advancing Idx.
2628 std::string readPath() {
2629 return Reader->ReadPath(*F, Record, Idx);
2632 /// Read a version tuple, advancing Idx.
2633 VersionTuple readVersionTuple() {
2634 return ASTReader::ReadVersionTuple(Record, Idx);
2637 /// Reads one attribute from the current stream position, advancing Idx.
2639 return Reader->ReadAttr(*F, Record, Idx);
2642 /// Reads attributes from the current stream position, advancing Idx.
2643 void readAttributes(AttrVec &Attrs) {
2644 return Reader->ReadAttributes(*this, Attrs);
2647 /// Reads a token out of a record, advancing Idx.
2649 return Reader->ReadToken(*F, Record, Idx);
2652 void recordSwitchCaseID(SwitchCase *SC, unsigned ID) {
2653 Reader->RecordSwitchCaseID(SC, ID);
2656 /// Retrieve the switch-case statement with the given ID.
2657 SwitchCase *getSwitchCaseWithID(unsigned ID) {
2658 return Reader->getSwitchCaseWithID(ID);
2662 /// Helper class that saves the current stream position and
2663 /// then restores it when destroyed.
2664 struct SavedStreamPosition {
2665 explicit SavedStreamPosition(llvm::BitstreamCursor &Cursor)
2666 : Cursor(Cursor), Offset(Cursor.GetCurrentBitNo()) {}
2668 ~SavedStreamPosition() {
2669 Cursor.JumpToBit(Offset);
2673 llvm::BitstreamCursor &Cursor;
2677 inline void PCHValidator::Error(const char *Msg) {
2681 class OMPClauseReader : public OMPClauseVisitor<OMPClauseReader> {
2682 ASTRecordReader &Record;
2683 ASTContext &Context;
2686 OMPClauseReader(ASTRecordReader &Record)
2687 : Record(Record), Context(Record.getContext()) {}
2689 #define OPENMP_CLAUSE(Name, Class) void Visit##Class(Class *C);
2690 #include "clang/Basic/OpenMPKinds.def"
2691 OMPClause *readClause();
2692 void VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C);
2693 void VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C);
2696 } // namespace clang
2698 #endif // LLVM_CLANG_SERIALIZATION_ASTREADER_H