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