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