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