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