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/DeclObjC.h"
18 #include "clang/AST/DeclarationName.h"
19 #include "clang/AST/TemplateBase.h"
20 #include "clang/Basic/Diagnostic.h"
21 #include "clang/Basic/FileManager.h"
22 #include "clang/Basic/FileSystemOptions.h"
23 #include "clang/Basic/IdentifierTable.h"
24 #include "clang/Basic/SourceManager.h"
25 #include "clang/Basic/Version.h"
26 #include "clang/Lex/ExternalPreprocessorSource.h"
27 #include "clang/Lex/HeaderSearch.h"
28 #include "clang/Lex/PreprocessingRecord.h"
29 #include "clang/Sema/ExternalSemaSource.h"
30 #include "clang/Serialization/ASTBitCodes.h"
31 #include "clang/Serialization/ContinuousRangeMap.h"
32 #include "clang/Serialization/Module.h"
33 #include "clang/Serialization/ModuleManager.h"
34 #include "llvm/ADT/APFloat.h"
35 #include "llvm/ADT/APInt.h"
36 #include "llvm/ADT/APSInt.h"
37 #include "llvm/ADT/MapVector.h"
38 #include "llvm/ADT/SmallPtrSet.h"
39 #include "llvm/ADT/SmallSet.h"
40 #include "llvm/ADT/SmallVector.h"
41 #include "llvm/ADT/StringRef.h"
42 #include "llvm/ADT/TinyPtrVector.h"
43 #include "llvm/Bitcode/BitstreamReader.h"
44 #include "llvm/Support/DataTypes.h"
45 #include "llvm/Support/Timer.h"
62 class ASTIdentifierIterator;
63 class ASTUnit; // FIXME: Layering violation and egregious hack.
67 class DefMacroDirective;
68 class DiagnosticOptions;
69 class NestedNameSpecifier;
70 class CXXBaseSpecifier;
71 class CXXConstructorDecl;
72 class CXXCtorInitializer;
73 class GlobalModuleIndex;
75 class MacroDefinition;
79 class OpaqueValueExpr;
81 class PreprocessorOptions;
84 class ASTDeserializationListener;
90 struct HeaderFileInfo;
93 class LazyASTUnresolvedSet;
95 /// \brief Abstract interface for callback invocations by the ASTReader.
97 /// While reading an AST file, the ASTReader will call the methods of the
98 /// listener to pass on specific information. Some of the listener methods can
99 /// return true to indicate to the ASTReader that the information (and
100 /// consequently the AST file) is invalid.
101 class ASTReaderListener {
103 virtual ~ASTReaderListener();
105 /// \brief Receives the full Clang version information.
107 /// \returns true to indicate that the version is invalid. Subclasses should
108 /// generally defer to this implementation.
109 virtual bool ReadFullVersionInformation(StringRef FullVersion) {
110 return FullVersion != getClangFullRepositoryVersion();
113 virtual void ReadModuleName(StringRef ModuleName) {}
114 virtual void ReadModuleMapFile(StringRef ModuleMapPath) {}
116 /// \brief Receives the language options.
118 /// \returns true to indicate the options are invalid or false otherwise.
119 virtual bool ReadLanguageOptions(const LangOptions &LangOpts,
121 bool AllowCompatibleDifferences) {
125 /// \brief Receives the target options.
127 /// \returns true to indicate the target options are invalid, or false
129 virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
130 bool AllowCompatibleDifferences) {
134 /// \brief Receives the diagnostic options.
136 /// \returns true to indicate the diagnostic options are invalid, or false
139 ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
144 /// \brief Receives the file system options.
146 /// \returns true to indicate the file system options are invalid, or false
148 virtual bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
153 /// \brief Receives the header search options.
155 /// \returns true to indicate the header search options are invalid, or false
157 virtual bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
158 StringRef SpecificModuleCachePath,
163 /// \brief Receives the preprocessor options.
165 /// \param SuggestedPredefines Can be filled in with the set of predefines
166 /// that are suggested by the preprocessor options. Typically only used when
167 /// loading a precompiled header.
169 /// \returns true to indicate the preprocessor options are invalid, or false
171 virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
173 std::string &SuggestedPredefines) {
177 /// \brief Receives __COUNTER__ value.
178 virtual void ReadCounter(const serialization::ModuleFile &M,
181 /// This is called for each AST file loaded.
182 virtual void visitModuleFile(StringRef Filename) {}
184 /// \brief Returns true if this \c ASTReaderListener wants to receive the
185 /// input files of the AST file via \c visitInputFile, false otherwise.
186 virtual bool needsInputFileVisitation() { return false; }
187 /// \brief Returns true if this \c ASTReaderListener wants to receive the
188 /// system input files of the AST file via \c visitInputFile, false otherwise.
189 virtual bool needsSystemInputFileVisitation() { return false; }
190 /// \brief if \c needsInputFileVisitation returns true, this is called for
191 /// each non-system input file of the AST File. If
192 /// \c needsSystemInputFileVisitation is true, then it is called for all
193 /// system input files as well.
195 /// \returns true to continue receiving the next input file, false to stop.
196 virtual bool visitInputFile(StringRef Filename, bool isSystem,
201 /// \brief Returns true if this \c ASTReaderListener wants to receive the
202 /// imports of the AST file via \c visitImport, false otherwise.
203 virtual bool needsImportVisitation() const { return false; }
204 /// \brief If needsImportVisitation returns \c true, this is called for each
205 /// AST file imported by this AST file.
206 virtual void visitImport(StringRef Filename) {}
209 /// \brief Simple wrapper class for chaining listeners.
210 class ChainedASTReaderListener : public ASTReaderListener {
211 std::unique_ptr<ASTReaderListener> First;
212 std::unique_ptr<ASTReaderListener> Second;
215 /// Takes ownership of \p First and \p Second.
216 ChainedASTReaderListener(std::unique_ptr<ASTReaderListener> First,
217 std::unique_ptr<ASTReaderListener> Second)
218 : First(std::move(First)), Second(std::move(Second)) {}
220 std::unique_ptr<ASTReaderListener> takeFirst() { return std::move(First); }
221 std::unique_ptr<ASTReaderListener> takeSecond() { return std::move(Second); }
223 bool ReadFullVersionInformation(StringRef FullVersion) override;
224 void ReadModuleName(StringRef ModuleName) override;
225 void ReadModuleMapFile(StringRef ModuleMapPath) override;
226 bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
227 bool AllowCompatibleDifferences) override;
228 bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
229 bool AllowCompatibleDifferences) override;
230 bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
231 bool Complain) override;
232 bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
233 bool Complain) override;
235 bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
236 StringRef SpecificModuleCachePath,
237 bool Complain) override;
238 bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
240 std::string &SuggestedPredefines) override;
242 void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
243 bool needsInputFileVisitation() override;
244 bool needsSystemInputFileVisitation() override;
245 void visitModuleFile(StringRef Filename) override;
246 bool visitInputFile(StringRef Filename, bool isSystem,
247 bool isOverridden) override;
250 /// \brief ASTReaderListener implementation to validate the information of
251 /// the PCH file against an initialized Preprocessor.
252 class PCHValidator : public ASTReaderListener {
257 PCHValidator(Preprocessor &PP, ASTReader &Reader)
258 : PP(PP), Reader(Reader) {}
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 ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain,
267 std::string &SuggestedPredefines) override;
268 bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
269 StringRef SpecificModuleCachePath,
270 bool Complain) override;
271 void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
274 void Error(const char *Msg);
277 namespace serialization {
279 class ReadMethodPoolVisitor;
282 class ASTIdentifierLookupTrait;
283 /// \brief The on-disk hash table used for the DeclContext's Name lookup table.
284 typedef llvm::OnDiskIterableChainedHashTable<ASTDeclContextNameLookupTrait>
285 ASTDeclContextNameLookupTable;
288 } // end namespace serialization
290 /// \brief Reads an AST files chain containing the contents of a translation
293 /// The ASTReader class reads bitstreams (produced by the ASTWriter
294 /// class) containing the serialized representation of a given
295 /// abstract syntax tree and its supporting data structures. An
296 /// instance of the ASTReader can be attached to an ASTContext object,
297 /// which will provide access to the contents of the AST files.
299 /// The AST reader provides lazy de-serialization of declarations, as
300 /// required when traversing the AST. Only those AST nodes that are
301 /// actually required will be de-serialized.
303 : public ExternalPreprocessorSource,
304 public ExternalPreprocessingRecordSource,
305 public ExternalHeaderFileInfoSource,
306 public ExternalSemaSource,
307 public IdentifierInfoLookup,
308 public ExternalSLocEntrySource
311 typedef SmallVector<uint64_t, 64> RecordData;
312 typedef SmallVectorImpl<uint64_t> RecordDataImpl;
314 /// \brief The result of reading the control block of an AST file, which
315 /// can fail for various reasons.
317 /// \brief The control block was read successfully. Aside from failures,
318 /// the AST file is safe to read into the current context.
320 /// \brief The AST file itself appears corrupted.
322 /// \brief The AST file was missing.
324 /// \brief The AST file is out-of-date relative to its input files,
325 /// and needs to be regenerated.
327 /// \brief The AST file was written by a different version of Clang.
329 /// \brief The AST file was writtten with a different language/target
331 ConfigurationMismatch,
332 /// \brief The AST file has errors.
336 /// \brief Types of AST files.
337 friend class PCHValidator;
338 friend class ASTDeclReader;
339 friend class ASTStmtReader;
340 friend class ASTIdentifierIterator;
341 friend class serialization::reader::ASTIdentifierLookupTrait;
342 friend class TypeLocReader;
343 friend class ASTWriter;
344 friend class ASTUnit; // ASTUnit needs to remap source locations.
345 friend class serialization::ReadMethodPoolVisitor;
347 typedef serialization::ModuleFile ModuleFile;
348 typedef serialization::ModuleKind ModuleKind;
349 typedef serialization::ModuleManager ModuleManager;
351 typedef ModuleManager::ModuleIterator ModuleIterator;
352 typedef ModuleManager::ModuleConstIterator ModuleConstIterator;
353 typedef ModuleManager::ModuleReverseIterator ModuleReverseIterator;
356 /// \brief The receiver of some callbacks invoked by ASTReader.
357 std::unique_ptr<ASTReaderListener> Listener;
359 /// \brief The receiver of deserialization events.
360 ASTDeserializationListener *DeserializationListener;
361 bool OwnsDeserializationListener;
363 SourceManager &SourceMgr;
364 FileManager &FileMgr;
365 const PCHContainerReader &PCHContainerRdr;
366 DiagnosticsEngine &Diags;
368 /// \brief The semantic analysis object that will be processing the
369 /// AST files and the translation unit that uses it.
372 /// \brief The preprocessor that will be loading the source file.
375 /// \brief The AST context into which we'll read the AST files.
378 /// \brief The AST consumer.
379 ASTConsumer *Consumer;
381 /// \brief The module manager which manages modules and their dependencies
382 ModuleManager ModuleMgr;
384 /// \brief A timer used to track the time spent deserializing.
385 std::unique_ptr<llvm::Timer> ReadTimer;
387 /// \brief The location where the module file will be considered as
388 /// imported from. For non-module AST types it should be invalid.
389 SourceLocation CurrentImportLoc;
391 /// \brief The global module index, if loaded.
392 std::unique_ptr<GlobalModuleIndex> GlobalIndex;
394 /// \brief A map of global bit offsets to the module that stores entities
395 /// at those bit offsets.
396 ContinuousRangeMap<uint64_t, ModuleFile*, 4> GlobalBitOffsetsMap;
398 /// \brief A map of negated SLocEntryIDs to the modules containing them.
399 ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocEntryMap;
401 typedef ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocOffsetMapType;
403 /// \brief A map of reversed (SourceManager::MaxLoadedOffset - SLocOffset)
404 /// SourceLocation offsets to the modules containing them.
405 GlobalSLocOffsetMapType GlobalSLocOffsetMap;
407 /// \brief Types that have already been loaded from the chain.
409 /// When the pointer at index I is non-NULL, the type with
410 /// ID = (I + 1) << FastQual::Width has already been loaded
411 std::vector<QualType> TypesLoaded;
413 typedef ContinuousRangeMap<serialization::TypeID, ModuleFile *, 4>
416 /// \brief Mapping from global type IDs to the module in which the
417 /// type resides along with the offset that should be added to the
418 /// global type ID to produce a local ID.
419 GlobalTypeMapType GlobalTypeMap;
421 /// \brief Declarations that have already been loaded from the chain.
423 /// When the pointer at index I is non-NULL, the declaration with ID
424 /// = I + 1 has already been loaded.
425 std::vector<Decl *> DeclsLoaded;
427 typedef ContinuousRangeMap<serialization::DeclID, ModuleFile *, 4>
430 /// \brief Mapping from global declaration IDs to the module in which the
431 /// declaration resides.
432 GlobalDeclMapType GlobalDeclMap;
434 typedef std::pair<ModuleFile *, uint64_t> FileOffset;
435 typedef SmallVector<FileOffset, 2> FileOffsetsTy;
436 typedef llvm::DenseMap<serialization::DeclID, FileOffsetsTy>
437 DeclUpdateOffsetsMap;
439 /// \brief Declarations that have modifications residing in a later file
441 DeclUpdateOffsetsMap DeclUpdateOffsets;
443 /// \brief Declaration updates for already-loaded declarations that we need
444 /// to apply once we finish processing an import.
445 llvm::SmallVector<std::pair<serialization::GlobalDeclID, Decl*>, 16>
446 PendingUpdateRecords;
448 enum class PendingFakeDefinitionKind { NotFake, Fake, FakeLoaded };
450 /// \brief The DefinitionData pointers that we faked up for class definitions
451 /// that we needed but hadn't loaded yet.
452 llvm::DenseMap<void *, PendingFakeDefinitionKind> PendingFakeDefinitionData;
454 /// \brief Exception specification updates that have been loaded but not yet
455 /// propagated across the relevant redeclaration chain. The map key is the
456 /// canonical declaration (used only for deduplication) and the value is a
457 /// declaration that has an exception specification.
458 llvm::SmallMapVector<Decl *, FunctionDecl *, 4> PendingExceptionSpecUpdates;
460 struct ReplacedDeclInfo {
465 ReplacedDeclInfo() : Mod(nullptr), Offset(0), RawLoc(0) {}
466 ReplacedDeclInfo(ModuleFile *Mod, uint64_t Offset, unsigned RawLoc)
467 : Mod(Mod), Offset(Offset), RawLoc(RawLoc) {}
470 typedef llvm::DenseMap<serialization::DeclID, ReplacedDeclInfo>
472 /// \brief Declarations that have been replaced in a later file in the chain.
473 DeclReplacementMap ReplacedDecls;
475 /// \brief Declarations that have been imported and have typedef names for
476 /// linkage purposes.
477 llvm::DenseMap<std::pair<DeclContext*, IdentifierInfo*>, NamedDecl*>
478 ImportedTypedefNamesForLinkage;
480 /// \brief Mergeable declaration contexts that have anonymous declarations
481 /// within them, and those anonymous declarations.
482 llvm::DenseMap<DeclContext*, llvm::SmallVector<NamedDecl*, 2>>
483 AnonymousDeclarationsForMerging;
485 struct FileDeclsInfo {
487 ArrayRef<serialization::LocalDeclID> Decls;
489 FileDeclsInfo() : Mod(nullptr) {}
490 FileDeclsInfo(ModuleFile *Mod, ArrayRef<serialization::LocalDeclID> Decls)
491 : Mod(Mod), Decls(Decls) {}
494 /// \brief Map from a FileID to the file-level declarations that it contains.
495 llvm::DenseMap<FileID, FileDeclsInfo> FileDeclIDs;
497 // Updates for visible decls can occur for other contexts than just the
498 // TU, and when we read those update records, the actual context will not
499 // be available yet (unless it's the TU), so have this pending map using the
500 // ID as a key. It will be realized when the context is actually loaded.
502 SmallVector<std::pair<serialization::reader::ASTDeclContextNameLookupTable *,
503 ModuleFile*>, 1> DeclContextVisibleUpdates;
504 typedef llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates>
505 DeclContextVisibleUpdatesPending;
507 /// \brief Updates to the visible declarations of declaration contexts that
508 /// haven't been loaded yet.
509 DeclContextVisibleUpdatesPending PendingVisibleUpdates;
511 /// \brief The set of C++ or Objective-C classes that have forward
512 /// declarations that have not yet been linked to their definitions.
513 llvm::SmallPtrSet<Decl *, 4> PendingDefinitions;
515 typedef llvm::MapVector<Decl *, uint64_t,
516 llvm::SmallDenseMap<Decl *, unsigned, 4>,
517 SmallVector<std::pair<Decl *, uint64_t>, 4> >
520 /// \brief Functions or methods that have bodies that will be attached.
521 PendingBodiesMap PendingBodies;
523 /// \brief Definitions for which we have added merged definitions but not yet
524 /// performed deduplication.
525 llvm::SetVector<NamedDecl*> PendingMergedDefinitionsToDeduplicate;
527 /// \brief Read the records that describe the contents of declcontexts.
528 bool ReadDeclContextStorage(ModuleFile &M,
529 llvm::BitstreamCursor &Cursor,
530 const std::pair<uint64_t, uint64_t> &Offsets,
531 serialization::DeclContextInfo &Info);
533 /// \brief A vector containing identifiers that have already been
536 /// If the pointer at index I is non-NULL, then it refers to the
537 /// IdentifierInfo for the identifier with ID=I+1 that has already
539 std::vector<IdentifierInfo *> IdentifiersLoaded;
541 typedef ContinuousRangeMap<serialization::IdentID, ModuleFile *, 4>
542 GlobalIdentifierMapType;
544 /// \brief Mapping from global identifier IDs to the module in which the
545 /// identifier resides along with the offset that should be added to the
546 /// global identifier ID to produce a local ID.
547 GlobalIdentifierMapType GlobalIdentifierMap;
549 /// \brief A vector containing macros that have already been
552 /// If the pointer at index I is non-NULL, then it refers to the
553 /// MacroInfo for the identifier with ID=I+1 that has already
555 std::vector<MacroInfo *> MacrosLoaded;
557 typedef std::pair<IdentifierInfo *, serialization::SubmoduleID>
560 /// \brief A set of #undef directives that we have loaded; used to
561 /// deduplicate the same #undef information coming from multiple module
563 llvm::DenseSet<LoadedMacroInfo> LoadedUndefs;
565 typedef ContinuousRangeMap<serialization::MacroID, ModuleFile *, 4>
568 /// \brief Mapping from global macro IDs to the module in which the
569 /// macro resides along with the offset that should be added to the
570 /// global macro ID to produce a local ID.
571 GlobalMacroMapType GlobalMacroMap;
573 /// \brief A vector containing submodules that have already been loaded.
575 /// This vector is indexed by the Submodule ID (-1). NULL submodule entries
576 /// indicate that the particular submodule ID has not yet been loaded.
577 SmallVector<Module *, 2> SubmodulesLoaded;
579 typedef ContinuousRangeMap<serialization::SubmoduleID, ModuleFile *, 4>
580 GlobalSubmoduleMapType;
582 /// \brief Mapping from global submodule IDs to the module file in which the
583 /// submodule resides along with the offset that should be added to the
584 /// global submodule ID to produce a local ID.
585 GlobalSubmoduleMapType GlobalSubmoduleMap;
587 /// \brief A set of hidden declarations.
588 typedef SmallVector<Decl*, 2> HiddenNames;
589 typedef llvm::DenseMap<Module *, HiddenNames> HiddenNamesMapType;
591 /// \brief A mapping from each of the hidden submodules to the deserialized
592 /// declarations in that submodule that could be made visible.
593 HiddenNamesMapType HiddenNamesMap;
596 /// \brief A module import, export, or conflict that hasn't yet been resolved.
597 struct UnresolvedModuleRef {
598 /// \brief The file in which this module resides.
601 /// \brief The module that is importing or exporting.
604 /// \brief The kind of module reference.
605 enum { Import, Export, Conflict } Kind;
607 /// \brief The local ID of the module that is being exported.
610 /// \brief Whether this is a wildcard export.
611 unsigned IsWildcard : 1;
613 /// \brief String data.
617 /// \brief The set of module imports and exports that still need to be
619 SmallVector<UnresolvedModuleRef, 2> UnresolvedModuleRefs;
621 /// \brief A vector containing selectors that have already been loaded.
623 /// This vector is indexed by the Selector ID (-1). NULL selector
624 /// entries indicate that the particular selector ID has not yet
626 SmallVector<Selector, 16> SelectorsLoaded;
628 typedef ContinuousRangeMap<serialization::SelectorID, ModuleFile *, 4>
629 GlobalSelectorMapType;
631 /// \brief Mapping from global selector IDs to the module in which the
633 /// global selector ID to produce a local ID.
634 GlobalSelectorMapType GlobalSelectorMap;
636 /// \brief The generation number of the last time we loaded data from the
637 /// global method pool for this selector.
638 llvm::DenseMap<Selector, unsigned> SelectorGeneration;
640 struct PendingMacroInfo {
642 uint64_t MacroDirectivesOffset;
644 PendingMacroInfo(ModuleFile *M, uint64_t MacroDirectivesOffset)
645 : M(M), MacroDirectivesOffset(MacroDirectivesOffset) {}
648 typedef llvm::MapVector<IdentifierInfo *, SmallVector<PendingMacroInfo, 2> >
651 /// \brief Mapping from identifiers that have a macro history to the global
652 /// IDs have not yet been deserialized to the global IDs of those macros.
653 PendingMacroIDsMap PendingMacroIDs;
655 typedef ContinuousRangeMap<unsigned, ModuleFile *, 4>
656 GlobalPreprocessedEntityMapType;
658 /// \brief Mapping from global preprocessing entity IDs to the module in
659 /// which the preprocessed entity resides along with the offset that should be
660 /// added to the global preprocessing entitiy ID to produce a local ID.
661 GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap;
663 /// \name CodeGen-relevant special data
664 /// \brief Fields containing data that is relevant to CodeGen.
667 /// \brief The IDs of all declarations that fulfill the criteria of
668 /// "interesting" decls.
670 /// This contains the data loaded from all EAGERLY_DESERIALIZED_DECLS blocks
671 /// in the chain. The referenced declarations are deserialized and passed to
672 /// the consumer eagerly.
673 SmallVector<uint64_t, 16> EagerlyDeserializedDecls;
675 /// \brief The IDs of all tentative definitions stored in the chain.
677 /// Sema keeps track of all tentative definitions in a TU because it has to
678 /// complete them and pass them on to CodeGen. Thus, tentative definitions in
679 /// the PCH chain must be eagerly deserialized.
680 SmallVector<uint64_t, 16> TentativeDefinitions;
682 /// \brief The IDs of all CXXRecordDecls stored in the chain whose VTables are
685 /// CodeGen has to emit VTables for these records, so they have to be eagerly
687 SmallVector<uint64_t, 64> VTableUses;
689 /// \brief A snapshot of the pending instantiations in the chain.
691 /// This record tracks the instantiations that Sema has to perform at the
692 /// end of the TU. It consists of a pair of values for every pending
693 /// instantiation where the first value is the ID of the decl and the second
694 /// is the instantiation location.
695 SmallVector<uint64_t, 64> PendingInstantiations;
699 /// \name DiagnosticsEngine-relevant special data
700 /// \brief Fields containing data that is used for generating diagnostics
703 /// \brief A snapshot of Sema's unused file-scoped variable tracking, for
704 /// generating warnings.
705 SmallVector<uint64_t, 16> UnusedFileScopedDecls;
707 /// \brief A list of all the delegating constructors we've seen, to diagnose
709 SmallVector<uint64_t, 4> DelegatingCtorDecls;
711 /// \brief Method selectors used in a @selector expression. Used for
712 /// implementation of -Wselector.
713 SmallVector<uint64_t, 64> ReferencedSelectorsData;
715 /// \brief A snapshot of Sema's weak undeclared identifier tracking, for
716 /// generating warnings.
717 SmallVector<uint64_t, 64> WeakUndeclaredIdentifiers;
719 /// \brief The IDs of type aliases for ext_vectors that exist in the chain.
721 /// Used by Sema for finding sugared names for ext_vectors in diagnostics.
722 SmallVector<uint64_t, 4> ExtVectorDecls;
726 /// \name Sema-relevant special data
727 /// \brief Fields containing data that is used for semantic analysis
730 /// \brief The IDs of all potentially unused typedef names in the chain.
732 /// Sema tracks these to emit warnings.
733 SmallVector<uint64_t, 16> UnusedLocalTypedefNameCandidates;
735 /// \brief The IDs of the declarations Sema stores directly.
737 /// Sema tracks a few important decls, such as namespace std, directly.
738 SmallVector<uint64_t, 4> SemaDeclRefs;
740 /// \brief The IDs of the types ASTContext stores directly.
742 /// The AST context tracks a few important types, such as va_list, directly.
743 SmallVector<uint64_t, 16> SpecialTypes;
745 /// \brief The IDs of CUDA-specific declarations ASTContext stores directly.
747 /// The AST context tracks a few important decls, currently cudaConfigureCall,
749 SmallVector<uint64_t, 2> CUDASpecialDeclRefs;
751 /// \brief The floating point pragma option settings.
752 SmallVector<uint64_t, 1> FPPragmaOptions;
754 /// \brief The pragma clang optimize location (if the pragma state is "off").
755 SourceLocation OptimizeOffPragmaLocation;
757 /// \brief The OpenCL extension settings.
758 SmallVector<uint64_t, 1> OpenCLExtensions;
760 /// \brief A list of the namespaces we've seen.
761 SmallVector<uint64_t, 4> KnownNamespaces;
763 /// \brief A list of undefined decls with internal linkage followed by the
764 /// SourceLocation of a matching ODR-use.
765 SmallVector<uint64_t, 8> UndefinedButUsed;
767 /// \brief Delete expressions to analyze at the end of translation unit.
768 SmallVector<uint64_t, 8> DelayedDeleteExprs;
770 // \brief A list of late parsed template function data.
771 SmallVector<uint64_t, 1> LateParsedTemplates;
773 struct ImportedSubmodule {
774 serialization::SubmoduleID ID;
775 SourceLocation ImportLoc;
777 ImportedSubmodule(serialization::SubmoduleID ID, SourceLocation ImportLoc)
778 : ID(ID), ImportLoc(ImportLoc) {}
781 /// \brief A list of modules that were imported by precompiled headers or
782 /// any other non-module AST file.
783 SmallVector<ImportedSubmodule, 2> ImportedModules;
786 /// \brief The directory that the PCH we are reading is stored in.
787 std::string CurrentDir;
789 /// \brief The system include root to be used when loading the
790 /// precompiled header.
791 std::string isysroot;
793 /// \brief Whether to disable the normal validation performed on precompiled
794 /// headers when they are loaded.
795 bool DisableValidation;
797 /// \brief Whether to accept an AST file with compiler errors.
798 bool AllowASTWithCompilerErrors;
800 /// \brief Whether to accept an AST file that has a different configuration
801 /// from the current compiler instance.
802 bool AllowConfigurationMismatch;
804 /// \brief Whether validate system input files.
805 bool ValidateSystemInputs;
807 /// \brief Whether we are allowed to use the global module index.
810 /// \brief Whether we have tried loading the global module index yet.
811 bool TriedLoadingGlobalIndex;
813 typedef llvm::DenseMap<unsigned, SwitchCase *> SwitchCaseMapTy;
814 /// \brief Mapping from switch-case IDs in the chain to switch-case statements
816 /// Statements usually don't have IDs, but switch cases need them, so that the
817 /// switch statement can refer to them.
818 SwitchCaseMapTy SwitchCaseStmts;
820 SwitchCaseMapTy *CurrSwitchCaseStmts;
822 /// \brief The number of source location entries de-serialized from
824 unsigned NumSLocEntriesRead;
826 /// \brief The number of source location entries in the chain.
827 unsigned TotalNumSLocEntries;
829 /// \brief The number of statements (and expressions) de-serialized
831 unsigned NumStatementsRead;
833 /// \brief The total number of statements (and expressions) stored
835 unsigned TotalNumStatements;
837 /// \brief The number of macros de-serialized from the chain.
838 unsigned NumMacrosRead;
840 /// \brief The total number of macros stored in the chain.
841 unsigned TotalNumMacros;
843 /// \brief The number of lookups into identifier tables.
844 unsigned NumIdentifierLookups;
846 /// \brief The number of lookups into identifier tables that succeed.
847 unsigned NumIdentifierLookupHits;
849 /// \brief The number of selectors that have been read.
850 unsigned NumSelectorsRead;
852 /// \brief The number of method pool entries that have been read.
853 unsigned NumMethodPoolEntriesRead;
855 /// \brief The number of times we have looked up a selector in the method
857 unsigned NumMethodPoolLookups;
859 /// \brief The number of times we have looked up a selector in the method
860 /// pool and found something.
861 unsigned NumMethodPoolHits;
863 /// \brief The number of times we have looked up a selector in the method
864 /// pool within a specific module.
865 unsigned NumMethodPoolTableLookups;
867 /// \brief The number of times we have looked up a selector in the method
868 /// pool within a specific module and found something.
869 unsigned NumMethodPoolTableHits;
871 /// \brief The total number of method pool entries in the selector table.
872 unsigned TotalNumMethodPoolEntries;
874 /// Number of lexical decl contexts read/total.
875 unsigned NumLexicalDeclContextsRead, TotalLexicalDeclContexts;
877 /// Number of visible decl contexts read/total.
878 unsigned NumVisibleDeclContextsRead, TotalVisibleDeclContexts;
880 /// Total size of modules, in bits, currently loaded
881 uint64_t TotalModulesSizeInBits;
883 /// \brief Number of Decl/types that are currently deserializing.
884 unsigned NumCurrentElementsDeserializing;
886 /// \brief Set true while we are in the process of passing deserialized
887 /// "interesting" decls to consumer inside FinishedDeserializing().
888 /// This is used as a guard to avoid recursively repeating the process of
889 /// passing decls to consumer.
890 bool PassingDeclsToConsumer;
892 /// \brief The set of identifiers that were read while the AST reader was
893 /// (recursively) loading declarations.
895 /// The declarations on the identifier chain for these identifiers will be
896 /// loaded once the recursive loading has completed.
897 llvm::MapVector<IdentifierInfo *, SmallVector<uint32_t, 4> >
898 PendingIdentifierInfos;
900 /// \brief The set of lookup results that we have faked in order to support
901 /// merging of partially deserialized decls but that we have not yet removed.
902 llvm::SmallMapVector<IdentifierInfo *, SmallVector<NamedDecl*, 2>, 16>
903 PendingFakeLookupResults;
905 /// \brief The generation number of each identifier, which keeps track of
906 /// the last time we loaded information about this identifier.
907 llvm::DenseMap<IdentifierInfo *, unsigned> IdentifierGeneration;
909 /// \brief Contains declarations and definitions that will be
910 /// "interesting" to the ASTConsumer, when we get that AST consumer.
912 /// "Interesting" declarations are those that have data that may
913 /// need to be emitted, such as inline function definitions or
914 /// Objective-C protocols.
915 std::deque<Decl *> InterestingDecls;
917 /// \brief The set of redeclarable declarations that have been deserialized
918 /// since the last time the declaration chains were linked.
919 llvm::SmallPtrSet<Decl *, 16> RedeclsDeserialized;
921 /// \brief The list of redeclaration chains that still need to be
924 /// Each element is the canonical declaration of the chain.
925 /// Elements in this vector should be unique; use
926 /// PendingDeclChainsKnown to ensure uniqueness.
927 SmallVector<Decl *, 16> PendingDeclChains;
929 /// \brief Keeps track of the elements added to PendingDeclChains.
930 llvm::SmallSet<Decl *, 16> PendingDeclChainsKnown;
932 /// \brief The list of canonical declarations whose redeclaration chains
933 /// need to be marked as incomplete once we're done deserializing things.
934 SmallVector<Decl *, 16> PendingIncompleteDeclChains;
936 /// \brief The Decl IDs for the Sema/Lexical DeclContext of a Decl that has
937 /// been loaded but its DeclContext was not set yet.
938 struct PendingDeclContextInfo {
940 serialization::GlobalDeclID SemaDC;
941 serialization::GlobalDeclID LexicalDC;
944 /// \brief The set of Decls that have been loaded but their DeclContexts are
947 /// The DeclContexts for these Decls will be set once recursive loading has
949 std::deque<PendingDeclContextInfo> PendingDeclContextInfos;
951 /// \brief The set of NamedDecls that have been loaded, but are members of a
952 /// context that has been merged into another context where the corresponding
953 /// declaration is either missing or has not yet been loaded.
955 /// We will check whether the corresponding declaration is in fact missing
956 /// once recursing loading has been completed.
957 llvm::SmallVector<NamedDecl *, 16> PendingOdrMergeChecks;
959 /// \brief Record definitions in which we found an ODR violation.
960 llvm::SmallDenseMap<CXXRecordDecl *, llvm::TinyPtrVector<CXXRecordDecl *>, 2>
961 PendingOdrMergeFailures;
963 /// \brief DeclContexts in which we have diagnosed an ODR violation.
964 llvm::SmallPtrSet<DeclContext*, 2> DiagnosedOdrMergeFailures;
966 /// \brief The set of Objective-C categories that have been deserialized
967 /// since the last time the declaration chains were linked.
968 llvm::SmallPtrSet<ObjCCategoryDecl *, 16> CategoriesDeserialized;
970 /// \brief The set of Objective-C class definitions that have already been
971 /// loaded, for which we will need to check for categories whenever a new
972 /// module is loaded.
973 SmallVector<ObjCInterfaceDecl *, 16> ObjCClassesLoaded;
975 /// \brief A mapping from a primary context for a declaration chain to the
976 /// other declarations of that entity that also have name lookup tables.
977 /// Used when we merge together two class definitions that have different
978 /// sets of declared special member functions.
979 llvm::DenseMap<const DeclContext*, SmallVector<const DeclContext*, 2>>
982 typedef llvm::DenseMap<Decl *, SmallVector<serialization::DeclID, 2> >
985 /// \brief A mapping from canonical declarations to the set of global
986 /// declaration IDs for key declaration that have been merged with that
987 /// canonical declaration. A key declaration is a formerly-canonical
988 /// declaration whose module did not import any other key declaration for that
989 /// entity. These are the IDs that we use as keys when finding redecl chains.
990 KeyDeclsMap KeyDecls;
992 /// \brief A mapping from DeclContexts to the semantic DeclContext that we
993 /// are treating as the definition of the entity. This is used, for instance,
994 /// when merging implicit instantiations of class templates across modules.
995 llvm::DenseMap<DeclContext *, DeclContext *> MergedDeclContexts;
997 /// \brief A mapping from canonical declarations of enums to their canonical
998 /// definitions. Only populated when using modules in C++.
999 llvm::DenseMap<EnumDecl *, EnumDecl *> EnumDefinitions;
1001 /// \brief When reading a Stmt tree, Stmt operands are placed in this stack.
1002 SmallVector<Stmt *, 16> StmtStack;
1004 /// \brief What kind of records we are reading.
1006 Read_None, Read_Decl, Read_Type, Read_Stmt
1009 /// \brief What kind of records we are reading.
1010 ReadingKind ReadingKind;
1012 /// \brief RAII object to change the reading kind.
1013 class ReadingKindTracker {
1015 enum ReadingKind PrevKind;
1017 ReadingKindTracker(const ReadingKindTracker &) = delete;
1018 void operator=(const ReadingKindTracker &) = delete;
1021 ReadingKindTracker(enum ReadingKind newKind, ASTReader &reader)
1022 : Reader(reader), PrevKind(Reader.ReadingKind) {
1023 Reader.ReadingKind = newKind;
1026 ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; }
1029 /// \brief Suggested contents of the predefines buffer, after this
1030 /// PCH file has been processed.
1032 /// In most cases, this string will be empty, because the predefines
1033 /// buffer computed to build the PCH file will be identical to the
1034 /// predefines buffer computed from the command line. However, when
1035 /// there are differences that the PCH reader can work around, this
1036 /// predefines buffer may contain additional definitions.
1037 std::string SuggestedPredefines;
1039 /// \brief Reads a statement from the specified cursor.
1040 Stmt *ReadStmtFromStream(ModuleFile &F);
1042 struct InputFileInfo {
1043 std::string Filename;
1049 /// \brief Reads the stored information about an input file.
1050 InputFileInfo readInputFileInfo(ModuleFile &F, unsigned ID);
1051 /// \brief A convenience method to read the filename from an input file.
1052 std::string getInputFileName(ModuleFile &F, unsigned ID);
1054 /// \brief Retrieve the file entry and 'overridden' bit for an input
1055 /// file in the given module file.
1056 serialization::InputFile getInputFile(ModuleFile &F, unsigned ID,
1057 bool Complain = true);
1060 void ResolveImportedPath(ModuleFile &M, std::string &Filename);
1061 static void ResolveImportedPath(std::string &Filename, StringRef Prefix);
1063 /// \brief Returns the first key declaration for the given declaration. This
1064 /// is one that is formerly-canonical (or still canonical) and whose module
1065 /// did not import any other key declaration of the entity.
1066 Decl *getKeyDeclaration(Decl *D) {
1067 D = D->getCanonicalDecl();
1068 if (D->isFromASTFile())
1071 auto I = KeyDecls.find(D);
1072 if (I == KeyDecls.end() || I->second.empty())
1074 return GetExistingDecl(I->second[0]);
1076 const Decl *getKeyDeclaration(const Decl *D) {
1077 return getKeyDeclaration(const_cast<Decl*>(D));
1080 /// \brief Run a callback on each imported key declaration of \p D.
1081 template <typename Fn>
1082 void forEachImportedKeyDecl(const Decl *D, Fn Visit) {
1083 D = D->getCanonicalDecl();
1084 if (D->isFromASTFile())
1087 auto It = KeyDecls.find(const_cast<Decl*>(D));
1088 if (It != KeyDecls.end())
1089 for (auto ID : It->second)
1090 Visit(GetExistingDecl(ID));
1094 struct ImportedModule {
1096 ModuleFile *ImportedBy;
1097 SourceLocation ImportLoc;
1099 ImportedModule(ModuleFile *Mod,
1100 ModuleFile *ImportedBy,
1101 SourceLocation ImportLoc)
1102 : Mod(Mod), ImportedBy(ImportedBy), ImportLoc(ImportLoc) { }
1105 ASTReadResult ReadASTCore(StringRef FileName, ModuleKind Type,
1106 SourceLocation ImportLoc, ModuleFile *ImportedBy,
1107 SmallVectorImpl<ImportedModule> &Loaded,
1108 off_t ExpectedSize, time_t ExpectedModTime,
1109 serialization::ASTFileSignature ExpectedSignature,
1110 unsigned ClientLoadCapabilities);
1111 ASTReadResult ReadControlBlock(ModuleFile &F,
1112 SmallVectorImpl<ImportedModule> &Loaded,
1113 const ModuleFile *ImportedBy,
1114 unsigned ClientLoadCapabilities);
1115 ASTReadResult ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities);
1116 bool ParseLineTable(ModuleFile &F, const RecordData &Record);
1117 bool ReadSourceManagerBlock(ModuleFile &F);
1118 llvm::BitstreamCursor &SLocCursorForID(int ID);
1119 SourceLocation getImportLocation(ModuleFile *F);
1120 ASTReadResult ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F,
1121 const ModuleFile *ImportedBy,
1122 unsigned ClientLoadCapabilities);
1123 ASTReadResult ReadSubmoduleBlock(ModuleFile &F,
1124 unsigned ClientLoadCapabilities);
1125 static bool ParseLanguageOptions(const RecordData &Record, bool Complain,
1126 ASTReaderListener &Listener,
1127 bool AllowCompatibleDifferences);
1128 static bool ParseTargetOptions(const RecordData &Record, bool Complain,
1129 ASTReaderListener &Listener,
1130 bool AllowCompatibleDifferences);
1131 static bool ParseDiagnosticOptions(const RecordData &Record, bool Complain,
1132 ASTReaderListener &Listener);
1133 static bool ParseFileSystemOptions(const RecordData &Record, bool Complain,
1134 ASTReaderListener &Listener);
1135 static bool ParseHeaderSearchOptions(const RecordData &Record, bool Complain,
1136 ASTReaderListener &Listener);
1137 static bool ParsePreprocessorOptions(const RecordData &Record, bool Complain,
1138 ASTReaderListener &Listener,
1139 std::string &SuggestedPredefines);
1141 struct RecordLocation {
1142 RecordLocation(ModuleFile *M, uint64_t O)
1143 : F(M), Offset(O) {}
1148 QualType readTypeRecord(unsigned Index);
1149 void readExceptionSpec(ModuleFile &ModuleFile,
1150 SmallVectorImpl<QualType> &ExceptionStorage,
1151 FunctionProtoType::ExceptionSpecInfo &ESI,
1152 const RecordData &Record, unsigned &Index);
1153 RecordLocation TypeCursorForIndex(unsigned Index);
1154 void LoadedDecl(unsigned Index, Decl *D);
1155 Decl *ReadDeclRecord(serialization::DeclID ID);
1156 void markIncompleteDeclChain(Decl *Canon);
1158 /// \brief Returns the most recent declaration of a declaration (which must be
1159 /// of a redeclarable kind) that is either local or has already been loaded
1160 /// merged into its redecl chain.
1161 Decl *getMostRecentExistingDecl(Decl *D);
1163 RecordLocation DeclCursorForID(serialization::DeclID ID,
1164 unsigned &RawLocation);
1165 void loadDeclUpdateRecords(serialization::DeclID ID, Decl *D);
1166 void loadPendingDeclChain(Decl *D);
1167 void loadObjCCategories(serialization::GlobalDeclID ID, ObjCInterfaceDecl *D,
1168 unsigned PreviousGeneration = 0);
1170 RecordLocation getLocalBitOffset(uint64_t GlobalOffset);
1171 uint64_t getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset);
1173 /// \brief Returns the first preprocessed entity ID that begins or ends after
1175 serialization::PreprocessedEntityID
1176 findPreprocessedEntity(SourceLocation Loc, bool EndsAfter) const;
1178 /// \brief Find the next module that contains entities and return the ID
1179 /// of the first entry.
1181 /// \param SLocMapI points at a chunk of a module that contains no
1182 /// preprocessed entities or the entities it contains are not the
1183 /// ones we are looking for.
1184 serialization::PreprocessedEntityID
1185 findNextPreprocessedEntity(
1186 GlobalSLocOffsetMapType::const_iterator SLocMapI) const;
1188 /// \brief Returns (ModuleFile, Local index) pair for \p GlobalIndex of a
1189 /// preprocessed entity.
1190 std::pair<ModuleFile *, unsigned>
1191 getModulePreprocessedEntity(unsigned GlobalIndex);
1193 /// \brief Returns (begin, end) pair for the preprocessed entities of a
1194 /// particular module.
1195 llvm::iterator_range<PreprocessingRecord::iterator>
1196 getModulePreprocessedEntities(ModuleFile &Mod) const;
1198 class ModuleDeclIterator
1199 : public llvm::iterator_adaptor_base<
1200 ModuleDeclIterator, const serialization::LocalDeclID *,
1201 std::random_access_iterator_tag, const Decl *, ptrdiff_t,
1202 const Decl *, const Decl *> {
1207 ModuleDeclIterator()
1208 : iterator_adaptor_base(nullptr), Reader(nullptr), Mod(nullptr) {}
1210 ModuleDeclIterator(ASTReader *Reader, ModuleFile *Mod,
1211 const serialization::LocalDeclID *Pos)
1212 : iterator_adaptor_base(Pos), Reader(Reader), Mod(Mod) {}
1214 value_type operator*() const {
1215 return Reader->GetDecl(Reader->getGlobalDeclID(*Mod, *I));
1217 value_type operator->() const { return **this; }
1219 bool operator==(const ModuleDeclIterator &RHS) const {
1220 assert(Reader == RHS.Reader && Mod == RHS.Mod);
1225 llvm::iterator_range<ModuleDeclIterator>
1226 getModuleFileLevelDecls(ModuleFile &Mod);
1228 void PassInterestingDeclsToConsumer();
1229 void PassInterestingDeclToConsumer(Decl *D);
1231 void finishPendingActions();
1232 void diagnoseOdrViolations();
1234 void pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name);
1236 void addPendingDeclContextInfo(Decl *D,
1237 serialization::GlobalDeclID SemaDC,
1238 serialization::GlobalDeclID LexicalDC) {
1240 PendingDeclContextInfo Info = { D, SemaDC, LexicalDC };
1241 PendingDeclContextInfos.push_back(Info);
1244 /// \brief Produce an error diagnostic and return true.
1246 /// This routine should only be used for fatal errors that have to
1247 /// do with non-routine failures (e.g., corrupted AST file).
1248 void Error(StringRef Msg);
1249 void Error(unsigned DiagID, StringRef Arg1 = StringRef(),
1250 StringRef Arg2 = StringRef());
1252 ASTReader(const ASTReader &) = delete;
1253 void operator=(const ASTReader &) = delete;
1255 /// \brief Load the AST file and validate its contents against the given
1258 /// \param PP the preprocessor associated with the context in which this
1259 /// precompiled header will be loaded.
1261 /// \param Context the AST context that this precompiled header will be
1264 /// \param PCHContainerOps the PCHContainerOperations to use for loading and
1265 /// creating modules.
1267 /// \param isysroot If non-NULL, the system include path specified by the
1268 /// user. This is only used with relocatable PCH files. If non-NULL,
1269 /// a relocatable PCH file will use the default path "/".
1271 /// \param DisableValidation If true, the AST reader will suppress most
1272 /// of its regular consistency checking, allowing the use of precompiled
1273 /// headers that cannot be determined to be compatible.
1275 /// \param AllowASTWithCompilerErrors If true, the AST reader will accept an
1276 /// AST file the was created out of an AST with compiler errors,
1277 /// otherwise it will reject it.
1279 /// \param AllowConfigurationMismatch If true, the AST reader will not check
1280 /// for configuration differences between the AST file and the invocation.
1282 /// \param ValidateSystemInputs If true, the AST reader will validate
1283 /// system input files in addition to user input files. This is only
1284 /// meaningful if \p DisableValidation is false.
1286 /// \param UseGlobalIndex If true, the AST reader will try to load and use
1287 /// the global module index.
1289 /// \param ReadTimer If non-null, a timer used to track the time spent
1291 ASTReader(Preprocessor &PP, ASTContext &Context,
1292 const PCHContainerReader &PCHContainerRdr,
1293 StringRef isysroot = "", bool DisableValidation = false,
1294 bool AllowASTWithCompilerErrors = false,
1295 bool AllowConfigurationMismatch = false,
1296 bool ValidateSystemInputs = false, bool UseGlobalIndex = true,
1297 std::unique_ptr<llvm::Timer> ReadTimer = {});
1299 ~ASTReader() override;
1301 SourceManager &getSourceManager() const { return SourceMgr; }
1302 FileManager &getFileManager() const { return FileMgr; }
1304 /// \brief Flags that indicate what kind of AST loading failures the client
1305 /// of the AST reader can directly handle.
1307 /// When a client states that it can handle a particular kind of failure,
1308 /// the AST reader will not emit errors when producing that kind of failure.
1309 enum LoadFailureCapabilities {
1310 /// \brief The client can't handle any AST loading failures.
1312 /// \brief The client can handle an AST file that cannot load because it
1315 /// \brief The client can handle an AST file that cannot load because it
1316 /// is out-of-date relative to its input files.
1317 ARR_OutOfDate = 0x2,
1318 /// \brief The client can handle an AST file that cannot load because it
1319 /// was built with a different version of Clang.
1320 ARR_VersionMismatch = 0x4,
1321 /// \brief The client can handle an AST file that cannot load because it's
1322 /// compiled configuration doesn't match that of the context it was
1324 ARR_ConfigurationMismatch = 0x8
1327 /// \brief Load the AST file designated by the given file name.
1329 /// \param FileName The name of the AST file to load.
1331 /// \param Type The kind of AST being loaded, e.g., PCH, module, main file,
1334 /// \param ImportLoc the location where the module file will be considered as
1335 /// imported from. For non-module AST types it should be invalid.
1337 /// \param ClientLoadCapabilities The set of client load-failure
1338 /// capabilities, represented as a bitset of the enumerators of
1339 /// LoadFailureCapabilities.
1340 ASTReadResult ReadAST(const std::string &FileName, ModuleKind Type,
1341 SourceLocation ImportLoc,
1342 unsigned ClientLoadCapabilities);
1344 /// \brief Make the entities in the given module and any of its (non-explicit)
1345 /// submodules visible to name lookup.
1347 /// \param Mod The module whose names should be made visible.
1349 /// \param NameVisibility The level of visibility to give the names in the
1350 /// module. Visibility can only be increased over time.
1352 /// \param ImportLoc The location at which the import occurs.
1353 void makeModuleVisible(Module *Mod,
1354 Module::NameVisibilityKind NameVisibility,
1355 SourceLocation ImportLoc);
1357 /// \brief Make the names within this set of hidden names visible.
1358 void makeNamesVisible(const HiddenNames &Names, Module *Owner);
1360 /// \brief Take the AST callbacks listener.
1361 std::unique_ptr<ASTReaderListener> takeListener() {
1362 return std::move(Listener);
1365 /// \brief Set the AST callbacks listener.
1366 void setListener(std::unique_ptr<ASTReaderListener> Listener) {
1367 this->Listener = std::move(Listener);
1370 /// \brief Add an AST callback listener.
1372 /// Takes ownership of \p L.
1373 void addListener(std::unique_ptr<ASTReaderListener> L) {
1375 L = llvm::make_unique<ChainedASTReaderListener>(std::move(L),
1376 std::move(Listener));
1377 Listener = std::move(L);
1380 /// RAII object to temporarily add an AST callback listener.
1381 class ListenerScope {
1386 ListenerScope(ASTReader &Reader, std::unique_ptr<ASTReaderListener> L)
1387 : Reader(Reader), Chained(false) {
1388 auto Old = Reader.takeListener();
1391 L = llvm::make_unique<ChainedASTReaderListener>(std::move(L),
1394 Reader.setListener(std::move(L));
1397 auto New = Reader.takeListener();
1399 Reader.setListener(static_cast<ChainedASTReaderListener *>(New.get())
1404 /// \brief Set the AST deserialization listener.
1405 void setDeserializationListener(ASTDeserializationListener *Listener,
1406 bool TakeOwnership = false);
1408 /// \brief Determine whether this AST reader has a global index.
1409 bool hasGlobalIndex() const { return (bool)GlobalIndex; }
1411 /// \brief Return global module index.
1412 GlobalModuleIndex *getGlobalIndex() { return GlobalIndex.get(); }
1414 /// \brief Reset reader for a reload try.
1415 void resetForReload() { TriedLoadingGlobalIndex = false; }
1417 /// \brief Attempts to load the global index.
1419 /// \returns true if loading the global index has failed for any reason.
1420 bool loadGlobalIndex();
1422 /// \brief Determine whether we tried to load the global index, but failed,
1423 /// e.g., because it is out-of-date or does not exist.
1424 bool isGlobalIndexUnavailable() const;
1426 /// \brief Initializes the ASTContext
1427 void InitializeContext();
1429 /// \brief Update the state of Sema after loading some additional modules.
1432 /// \brief Add in-memory (virtual file) buffer.
1433 void addInMemoryBuffer(StringRef &FileName,
1434 std::unique_ptr<llvm::MemoryBuffer> Buffer) {
1435 ModuleMgr.addInMemoryBuffer(FileName, std::move(Buffer));
1438 /// \brief Finalizes the AST reader's state before writing an AST file to
1441 /// This operation may undo temporary state in the AST that should not be
1443 void finalizeForWriting();
1445 /// \brief Retrieve the module manager.
1446 ModuleManager &getModuleManager() { return ModuleMgr; }
1448 /// \brief Retrieve the preprocessor.
1449 Preprocessor &getPreprocessor() const { return PP; }
1451 /// \brief Retrieve the name of the original source file name for the primary
1453 StringRef getOriginalSourceFile() {
1454 return ModuleMgr.getPrimaryModule().OriginalSourceFileName;
1457 /// \brief Retrieve the name of the original source file name directly from
1458 /// the AST file, without actually loading the AST file.
1460 getOriginalSourceFile(const std::string &ASTFileName, FileManager &FileMgr,
1461 const PCHContainerReader &PCHContainerRdr,
1462 DiagnosticsEngine &Diags);
1464 /// \brief Read the control block for the named AST file.
1466 /// \returns true if an error occurred, false otherwise.
1468 readASTFileControlBlock(StringRef Filename, FileManager &FileMgr,
1469 const PCHContainerReader &PCHContainerRdr,
1470 ASTReaderListener &Listener);
1472 /// \brief Determine whether the given AST file is acceptable to load into a
1473 /// translation unit with the given language and target options.
1474 static bool isAcceptableASTFile(StringRef Filename, FileManager &FileMgr,
1475 const PCHContainerReader &PCHContainerRdr,
1476 const LangOptions &LangOpts,
1477 const TargetOptions &TargetOpts,
1478 const PreprocessorOptions &PPOpts,
1479 std::string ExistingModuleCachePath);
1481 /// \brief Returns the suggested contents of the predefines buffer,
1482 /// which contains a (typically-empty) subset of the predefines
1483 /// build prior to including the precompiled header.
1484 const std::string &getSuggestedPredefines() { return SuggestedPredefines; }
1486 /// \brief Read a preallocated preprocessed entity from the external source.
1488 /// \returns null if an error occurred that prevented the preprocessed
1489 /// entity from being loaded.
1490 PreprocessedEntity *ReadPreprocessedEntity(unsigned Index) override;
1492 /// \brief Returns a pair of [Begin, End) indices of preallocated
1493 /// preprocessed entities that \p Range encompasses.
1494 std::pair<unsigned, unsigned>
1495 findPreprocessedEntitiesInRange(SourceRange Range) override;
1497 /// \brief Optionally returns true or false if the preallocated preprocessed
1498 /// entity with index \p Index came from file \p FID.
1499 Optional<bool> isPreprocessedEntityInFileID(unsigned Index,
1500 FileID FID) override;
1502 /// \brief Read the header file information for the given file entry.
1503 HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE) override;
1505 void ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag);
1507 /// \brief Returns the number of source locations found in the chain.
1508 unsigned getTotalNumSLocs() const {
1509 return TotalNumSLocEntries;
1512 /// \brief Returns the number of identifiers found in the chain.
1513 unsigned getTotalNumIdentifiers() const {
1514 return static_cast<unsigned>(IdentifiersLoaded.size());
1517 /// \brief Returns the number of macros found in the chain.
1518 unsigned getTotalNumMacros() const {
1519 return static_cast<unsigned>(MacrosLoaded.size());
1522 /// \brief Returns the number of types found in the chain.
1523 unsigned getTotalNumTypes() const {
1524 return static_cast<unsigned>(TypesLoaded.size());
1527 /// \brief Returns the number of declarations found in the chain.
1528 unsigned getTotalNumDecls() const {
1529 return static_cast<unsigned>(DeclsLoaded.size());
1532 /// \brief Returns the number of submodules known.
1533 unsigned getTotalNumSubmodules() const {
1534 return static_cast<unsigned>(SubmodulesLoaded.size());
1537 /// \brief Returns the number of selectors found in the chain.
1538 unsigned getTotalNumSelectors() const {
1539 return static_cast<unsigned>(SelectorsLoaded.size());
1542 /// \brief Returns the number of preprocessed entities known to the AST
1544 unsigned getTotalNumPreprocessedEntities() const {
1545 unsigned Result = 0;
1546 for (ModuleConstIterator I = ModuleMgr.begin(),
1547 E = ModuleMgr.end(); I != E; ++I) {
1548 Result += (*I)->NumPreprocessedEntities;
1554 /// \brief Reads a TemplateArgumentLocInfo appropriate for the
1555 /// given TemplateArgument kind.
1556 TemplateArgumentLocInfo
1557 GetTemplateArgumentLocInfo(ModuleFile &F, TemplateArgument::ArgKind Kind,
1558 const RecordData &Record, unsigned &Idx);
1560 /// \brief Reads a TemplateArgumentLoc.
1562 ReadTemplateArgumentLoc(ModuleFile &F,
1563 const RecordData &Record, unsigned &Idx);
1565 const ASTTemplateArgumentListInfo*
1566 ReadASTTemplateArgumentListInfo(ModuleFile &F,
1567 const RecordData &Record, unsigned &Index);
1569 /// \brief Reads a declarator info from the given record.
1570 TypeSourceInfo *GetTypeSourceInfo(ModuleFile &F,
1571 const RecordData &Record, unsigned &Idx);
1573 /// \brief Resolve a type ID into a type, potentially building a new
1575 QualType GetType(serialization::TypeID ID);
1577 /// \brief Resolve a local type ID within a given AST file into a type.
1578 QualType getLocalType(ModuleFile &F, unsigned LocalID);
1580 /// \brief Map a local type ID within a given AST file into a global type ID.
1581 serialization::TypeID getGlobalTypeID(ModuleFile &F, unsigned LocalID) const;
1583 /// \brief Read a type from the current position in the given record, which
1584 /// was read from the given AST file.
1585 QualType readType(ModuleFile &F, const RecordData &Record, unsigned &Idx) {
1586 if (Idx >= Record.size())
1589 return getLocalType(F, Record[Idx++]);
1592 /// \brief Map from a local declaration ID within a given module to a
1593 /// global declaration ID.
1594 serialization::DeclID getGlobalDeclID(ModuleFile &F,
1595 serialization::LocalDeclID LocalID) const;
1597 /// \brief Returns true if global DeclID \p ID originated from module \p M.
1598 bool isDeclIDFromModule(serialization::GlobalDeclID ID, ModuleFile &M) const;
1600 /// \brief Retrieve the module file that owns the given declaration, or NULL
1601 /// if the declaration is not from a module file.
1602 ModuleFile *getOwningModuleFile(const Decl *D);
1604 /// \brief Get the best name we know for the module that owns the given
1605 /// declaration, or an empty string if the declaration is not from a module.
1606 std::string getOwningModuleNameForDiagnostic(const Decl *D);
1608 /// \brief Returns the source location for the decl \p ID.
1609 SourceLocation getSourceLocationForDeclID(serialization::GlobalDeclID ID);
1611 /// \brief Resolve a declaration ID into a declaration, potentially
1612 /// building a new declaration.
1613 Decl *GetDecl(serialization::DeclID ID);
1614 Decl *GetExternalDecl(uint32_t ID) override;
1616 /// \brief Resolve a declaration ID into a declaration. Return 0 if it's not
1617 /// been loaded yet.
1618 Decl *GetExistingDecl(serialization::DeclID ID);
1620 /// \brief Reads a declaration with the given local ID in the given module.
1621 Decl *GetLocalDecl(ModuleFile &F, uint32_t LocalID) {
1622 return GetDecl(getGlobalDeclID(F, LocalID));
1625 /// \brief Reads a declaration with the given local ID in the given module.
1627 /// \returns The requested declaration, casted to the given return type.
1628 template<typename T>
1629 T *GetLocalDeclAs(ModuleFile &F, uint32_t LocalID) {
1630 return cast_or_null<T>(GetLocalDecl(F, LocalID));
1633 /// \brief Map a global declaration ID into the declaration ID used to
1634 /// refer to this declaration within the given module fule.
1636 /// \returns the global ID of the given declaration as known in the given
1638 serialization::DeclID
1639 mapGlobalIDToModuleFileGlobalID(ModuleFile &M,
1640 serialization::DeclID GlobalID);
1642 /// \brief Reads a declaration ID from the given position in a record in the
1645 /// \returns The declaration ID read from the record, adjusted to a global ID.
1646 serialization::DeclID ReadDeclID(ModuleFile &F, const RecordData &Record,
1649 /// \brief Reads a declaration from the given position in a record in the
1651 Decl *ReadDecl(ModuleFile &F, const RecordData &R, unsigned &I) {
1652 return GetDecl(ReadDeclID(F, R, I));
1655 /// \brief Reads a declaration from the given position in a record in the
1658 /// \returns The declaration read from this location, casted to the given
1660 template<typename T>
1661 T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1662 return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1665 /// \brief If any redeclarations of \p D have been imported since it was
1666 /// last checked, this digs out those redeclarations and adds them to the
1667 /// redeclaration chain for \p D.
1668 void CompleteRedeclChain(const Decl *D) override;
1670 /// \brief Read a CXXBaseSpecifiers ID form the given record and
1671 /// return its global bit offset.
1672 uint64_t readCXXBaseSpecifiers(ModuleFile &M, const RecordData &Record,
1675 CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override;
1677 /// \brief Resolve the offset of a statement into a statement.
1679 /// This operation will read a new statement from the external
1680 /// source each time it is called, and is meant to be used via a
1681 /// LazyOffsetPtr (which is used by Decls for the body of functions, etc).
1682 Stmt *GetExternalDeclStmt(uint64_t Offset) override;
1684 /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the
1685 /// specified cursor. Read the abbreviations that are at the top of the block
1686 /// and then leave the cursor pointing into the block.
1687 bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID);
1689 /// \brief Finds all the visible declarations with a given name.
1690 /// The current implementation of this method just loads the entire
1691 /// lookup table as unmaterialized references.
1692 bool FindExternalVisibleDeclsByName(const DeclContext *DC,
1693 DeclarationName Name) override;
1695 /// \brief Read all of the declarations lexically stored in a
1696 /// declaration context.
1698 /// \param DC The declaration context whose declarations will be
1701 /// \param Decls Vector that will contain the declarations loaded
1702 /// from the external source. The caller is responsible for merging
1703 /// these declarations with any declarations already stored in the
1704 /// declaration context.
1706 /// \returns true if there was an error while reading the
1707 /// declarations for this declaration context.
1708 ExternalLoadResult FindExternalLexicalDecls(const DeclContext *DC,
1709 bool (*isKindWeWant)(Decl::Kind),
1710 SmallVectorImpl<Decl*> &Decls) override;
1712 /// \brief Get the decls that are contained in a file in the Offset/Length
1713 /// range. \p Length can be 0 to indicate a point at \p Offset instead of
1715 void FindFileRegionDecls(FileID File, unsigned Offset, unsigned Length,
1716 SmallVectorImpl<Decl *> &Decls) override;
1718 /// \brief Notify ASTReader that we started deserialization of
1719 /// a decl or type so until FinishedDeserializing is called there may be
1720 /// decls that are initializing. Must be paired with FinishedDeserializing.
1721 void StartedDeserializing() override;
1723 /// \brief Notify ASTReader that we finished the deserialization of
1724 /// a decl or type. Must be paired with StartedDeserializing.
1725 void FinishedDeserializing() override;
1727 /// \brief Function that will be invoked when we begin parsing a new
1728 /// translation unit involving this external AST source.
1730 /// This function will provide all of the external definitions to
1731 /// the ASTConsumer.
1732 void StartTranslationUnit(ASTConsumer *Consumer) override;
1734 /// \brief Print some statistics about AST usage.
1735 void PrintStats() override;
1737 /// \brief Dump information about the AST reader to standard error.
1740 /// Return the amount of memory used by memory buffers, breaking down
1741 /// by heap-backed versus mmap'ed memory.
1742 void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override;
1744 /// \brief Initialize the semantic source with the Sema instance
1745 /// being used to perform semantic analysis on the abstract syntax
1747 void InitializeSema(Sema &S) override;
1749 /// \brief Inform the semantic consumer that Sema is no longer available.
1750 void ForgetSema() override { SemaObj = nullptr; }
1752 /// \brief Retrieve the IdentifierInfo for the named identifier.
1754 /// This routine builds a new IdentifierInfo for the given identifier. If any
1755 /// declarations with this name are visible from translation unit scope, their
1756 /// declarations will be deserialized and introduced into the declaration
1757 /// chain of the identifier.
1758 virtual IdentifierInfo *get(const char *NameStart, const char *NameEnd);
1759 IdentifierInfo *get(StringRef Name) override {
1760 return get(Name.begin(), Name.end());
1763 /// \brief Retrieve an iterator into the set of all identifiers
1764 /// in all loaded AST files.
1765 IdentifierIterator *getIdentifiers() override;
1767 /// \brief Load the contents of the global method pool for a given
1769 void ReadMethodPool(Selector Sel) override;
1771 /// \brief Load the set of namespaces that are known to the external source,
1772 /// which will be used during typo correction.
1773 void ReadKnownNamespaces(
1774 SmallVectorImpl<NamespaceDecl *> &Namespaces) override;
1776 void ReadUndefinedButUsed(
1777 llvm::DenseMap<NamedDecl *, SourceLocation> &Undefined) override;
1779 void ReadMismatchingDeleteExpressions(llvm::MapVector<
1780 FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &
1783 void ReadTentativeDefinitions(
1784 SmallVectorImpl<VarDecl *> &TentativeDefs) override;
1786 void ReadUnusedFileScopedDecls(
1787 SmallVectorImpl<const DeclaratorDecl *> &Decls) override;
1789 void ReadDelegatingConstructors(
1790 SmallVectorImpl<CXXConstructorDecl *> &Decls) override;
1792 void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) override;
1794 void ReadUnusedLocalTypedefNameCandidates(
1795 llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) override;
1797 void ReadReferencedSelectors(
1798 SmallVectorImpl<std::pair<Selector, SourceLocation> > &Sels) override;
1800 void ReadWeakUndeclaredIdentifiers(
1801 SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo> > &WI) override;
1803 void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) override;
1805 void ReadPendingInstantiations(
1806 SmallVectorImpl<std::pair<ValueDecl *,
1807 SourceLocation> > &Pending) override;
1809 void ReadLateParsedTemplates(
1810 llvm::MapVector<const FunctionDecl *, LateParsedTemplate *> &LPTMap)
1813 /// \brief Load a selector from disk, registering its ID if it exists.
1814 void LoadSelector(Selector Sel);
1816 void SetIdentifierInfo(unsigned ID, IdentifierInfo *II);
1817 void SetGloballyVisibleDecls(IdentifierInfo *II,
1818 const SmallVectorImpl<uint32_t> &DeclIDs,
1819 SmallVectorImpl<Decl *> *Decls = nullptr);
1821 /// \brief Report a diagnostic.
1822 DiagnosticBuilder Diag(unsigned DiagID);
1824 /// \brief Report a diagnostic.
1825 DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID);
1827 IdentifierInfo *DecodeIdentifierInfo(serialization::IdentifierID ID);
1829 IdentifierInfo *GetIdentifierInfo(ModuleFile &M, const RecordData &Record,
1831 return DecodeIdentifierInfo(getGlobalIdentifierID(M, Record[Idx++]));
1834 IdentifierInfo *GetIdentifier(serialization::IdentifierID ID) override {
1835 // Note that we are loading an identifier.
1836 Deserializing AnIdentifier(this);
1838 return DecodeIdentifierInfo(ID);
1841 IdentifierInfo *getLocalIdentifier(ModuleFile &M, unsigned LocalID);
1843 serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M,
1846 void resolvePendingMacro(IdentifierInfo *II, const PendingMacroInfo &PMInfo);
1848 /// \brief Retrieve the macro with the given ID.
1849 MacroInfo *getMacro(serialization::MacroID ID);
1851 /// \brief Retrieve the global macro ID corresponding to the given local
1852 /// ID within the given module file.
1853 serialization::MacroID getGlobalMacroID(ModuleFile &M, unsigned LocalID);
1855 /// \brief Read the source location entry with index ID.
1856 bool ReadSLocEntry(int ID) override;
1858 /// \brief Retrieve the module import location and module name for the
1859 /// given source manager entry ID.
1860 std::pair<SourceLocation, StringRef> getModuleImportLoc(int ID) override;
1862 /// \brief Retrieve the global submodule ID given a module and its local ID
1864 serialization::SubmoduleID
1865 getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID);
1867 /// \brief Retrieve the submodule that corresponds to a global submodule ID.
1869 Module *getSubmodule(serialization::SubmoduleID GlobalID);
1871 /// \brief Retrieve the module that corresponds to the given module ID.
1873 /// Note: overrides method in ExternalASTSource
1874 Module *getModule(unsigned ID) override;
1876 /// \brief Return a descriptor for the corresponding module.
1877 llvm::Optional<ASTSourceDescriptor> getSourceDescriptor(unsigned ID) override;
1878 /// \brief Return a descriptor for the module.
1879 ASTSourceDescriptor getSourceDescriptor(const Module &M) override;
1881 /// \brief Retrieve a selector from the given module with its local ID
1883 Selector getLocalSelector(ModuleFile &M, unsigned LocalID);
1885 Selector DecodeSelector(serialization::SelectorID Idx);
1887 Selector GetExternalSelector(serialization::SelectorID ID) override;
1888 uint32_t GetNumExternalSelectors() override;
1890 Selector ReadSelector(ModuleFile &M, const RecordData &Record, unsigned &Idx) {
1891 return getLocalSelector(M, Record[Idx++]);
1894 /// \brief Retrieve the global selector ID that corresponds to this
1895 /// the local selector ID in a given module.
1896 serialization::SelectorID getGlobalSelectorID(ModuleFile &F,
1897 unsigned LocalID) const;
1899 /// \brief Read a declaration name.
1900 DeclarationName ReadDeclarationName(ModuleFile &F,
1901 const RecordData &Record, unsigned &Idx);
1902 void ReadDeclarationNameLoc(ModuleFile &F,
1903 DeclarationNameLoc &DNLoc, DeclarationName Name,
1904 const RecordData &Record, unsigned &Idx);
1905 void ReadDeclarationNameInfo(ModuleFile &F, DeclarationNameInfo &NameInfo,
1906 const RecordData &Record, unsigned &Idx);
1908 void ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info,
1909 const RecordData &Record, unsigned &Idx);
1911 NestedNameSpecifier *ReadNestedNameSpecifier(ModuleFile &F,
1912 const RecordData &Record,
1915 NestedNameSpecifierLoc ReadNestedNameSpecifierLoc(ModuleFile &F,
1916 const RecordData &Record,
1919 /// \brief Read a template name.
1920 TemplateName ReadTemplateName(ModuleFile &F, const RecordData &Record,
1923 /// \brief Read a template argument.
1924 TemplateArgument ReadTemplateArgument(ModuleFile &F,
1925 const RecordData &Record,unsigned &Idx);
1927 /// \brief Read a template parameter list.
1928 TemplateParameterList *ReadTemplateParameterList(ModuleFile &F,
1929 const RecordData &Record,
1932 /// \brief Read a template argument array.
1934 ReadTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs,
1935 ModuleFile &F, const RecordData &Record,
1938 /// \brief Read a UnresolvedSet structure.
1939 void ReadUnresolvedSet(ModuleFile &F, LazyASTUnresolvedSet &Set,
1940 const RecordData &Record, unsigned &Idx);
1942 /// \brief Read a C++ base specifier.
1943 CXXBaseSpecifier ReadCXXBaseSpecifier(ModuleFile &F,
1944 const RecordData &Record,unsigned &Idx);
1946 /// \brief Read a CXXCtorInitializer array.
1947 CXXCtorInitializer **
1948 ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record,
1951 /// \brief Read a CXXCtorInitializers ID from the given record and
1952 /// return its global bit offset.
1953 uint64_t ReadCXXCtorInitializersRef(ModuleFile &M, const RecordData &Record,
1956 /// \brief Read the contents of a CXXCtorInitializer array.
1957 CXXCtorInitializer **GetExternalCXXCtorInitializers(uint64_t Offset) override;
1959 /// \brief Read a source location from raw form.
1960 SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, unsigned Raw) const {
1961 SourceLocation Loc = SourceLocation::getFromRawEncoding(Raw);
1962 assert(ModuleFile.SLocRemap.find(Loc.getOffset()) != ModuleFile.SLocRemap.end() &&
1963 "Cannot find offset to remap.");
1964 int Remap = ModuleFile.SLocRemap.find(Loc.getOffset())->second;
1965 return Loc.getLocWithOffset(Remap);
1968 /// \brief Read a source location.
1969 SourceLocation ReadSourceLocation(ModuleFile &ModuleFile,
1970 const RecordDataImpl &Record,
1972 return ReadSourceLocation(ModuleFile, Record[Idx++]);
1975 /// \brief Read a source range.
1976 SourceRange ReadSourceRange(ModuleFile &F,
1977 const RecordData &Record, unsigned &Idx);
1979 /// \brief Read an integral value
1980 llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx);
1982 /// \brief Read a signed integral value
1983 llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx);
1985 /// \brief Read a floating-point value
1986 llvm::APFloat ReadAPFloat(const RecordData &Record,
1987 const llvm::fltSemantics &Sem, unsigned &Idx);
1989 // \brief Read a string
1990 static std::string ReadString(const RecordData &Record, unsigned &Idx);
1992 // \brief Read a path
1993 std::string ReadPath(ModuleFile &F, const RecordData &Record, unsigned &Idx);
1995 /// \brief Read a version tuple.
1996 static VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx);
1998 CXXTemporary *ReadCXXTemporary(ModuleFile &F, const RecordData &Record,
2001 /// \brief Reads attributes from the current stream position.
2002 void ReadAttributes(ModuleFile &F, AttrVec &Attrs,
2003 const RecordData &Record, unsigned &Idx);
2005 /// \brief Reads a statement.
2006 Stmt *ReadStmt(ModuleFile &F);
2008 /// \brief Reads an expression.
2009 Expr *ReadExpr(ModuleFile &F);
2011 /// \brief Reads a sub-statement operand during statement reading.
2012 Stmt *ReadSubStmt() {
2013 assert(ReadingKind == Read_Stmt &&
2014 "Should be called only during statement reading!");
2015 // Subexpressions are stored from last to first, so the next Stmt we need
2016 // is at the back of the stack.
2017 assert(!StmtStack.empty() && "Read too many sub-statements!");
2018 return StmtStack.pop_back_val();
2021 /// \brief Reads a sub-expression operand during statement reading.
2022 Expr *ReadSubExpr();
2024 /// \brief Reads a token out of a record.
2025 Token ReadToken(ModuleFile &M, const RecordDataImpl &Record, unsigned &Idx);
2027 /// \brief Reads the macro record located at the given offset.
2028 MacroInfo *ReadMacroRecord(ModuleFile &F, uint64_t Offset);
2030 /// \brief Determine the global preprocessed entity ID that corresponds to
2031 /// the given local ID within the given module.
2032 serialization::PreprocessedEntityID
2033 getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const;
2035 /// \brief Add a macro to deserialize its macro directive history.
2037 /// \param II The name of the macro.
2038 /// \param M The module file.
2039 /// \param MacroDirectivesOffset Offset of the serialized macro directive
2041 void addPendingMacro(IdentifierInfo *II, ModuleFile *M,
2042 uint64_t MacroDirectivesOffset);
2044 /// \brief Read the set of macros defined by this external macro source.
2045 void ReadDefinedMacros() override;
2047 /// \brief Update an out-of-date identifier.
2048 void updateOutOfDateIdentifier(IdentifierInfo &II) override;
2050 /// \brief Note that this identifier is up-to-date.
2051 void markIdentifierUpToDate(IdentifierInfo *II);
2053 /// \brief Load all external visible decls in the given DeclContext.
2054 void completeVisibleDeclsMap(const DeclContext *DC) override;
2056 /// \brief Retrieve the AST context that this AST reader supplements.
2057 ASTContext &getContext() { return Context; }
2059 // \brief Contains the IDs for declarations that were requested before we have
2060 // access to a Sema object.
2061 SmallVector<uint64_t, 16> PreloadedDeclIDs;
2063 /// \brief Retrieve the semantic analysis object used to analyze the
2064 /// translation unit in which the precompiled header is being
2066 Sema *getSema() { return SemaObj; }
2068 /// \brief Retrieve the identifier table associated with the
2070 IdentifierTable &getIdentifierTable();
2072 /// \brief Record that the given ID maps to the given switch-case
2074 void RecordSwitchCaseID(SwitchCase *SC, unsigned ID);
2076 /// \brief Retrieve the switch-case statement with the given ID.
2077 SwitchCase *getSwitchCaseWithID(unsigned ID);
2079 void ClearSwitchCaseIDs();
2081 /// \brief Cursors for comments blocks.
2082 SmallVector<std::pair<llvm::BitstreamCursor,
2083 serialization::ModuleFile *>, 8> CommentsCursors;
2085 //RIDErief Loads comments ranges.
2086 void ReadComments() override;
2088 /// Return all input files for the given module file.
2089 void getInputFiles(ModuleFile &F,
2090 SmallVectorImpl<serialization::InputFile> &Files);
2093 /// \brief Helper class that saves the current stream position and
2094 /// then restores it when destroyed.
2095 struct SavedStreamPosition {
2096 explicit SavedStreamPosition(llvm::BitstreamCursor &Cursor)
2097 : Cursor(Cursor), Offset(Cursor.GetCurrentBitNo()) { }
2099 ~SavedStreamPosition() {
2100 Cursor.JumpToBit(Offset);
2104 llvm::BitstreamCursor &Cursor;
2108 inline void PCHValidator::Error(const char *Msg) {
2112 } // end namespace clang