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