Coverage Report

Created: 2019-02-21 13:17

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/Serialization/ASTReader.h
Line
Count
Source (jump to first uncovered line)
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/DeclCXX.h"
17
#include "clang/AST/DeclObjC.h"
18
#include "clang/AST/DeclarationName.h"
19
#include "clang/AST/NestedNameSpecifier.h"
20
#include "clang/AST/OpenMPClause.h"
21
#include "clang/AST/TemplateBase.h"
22
#include "clang/AST/TemplateName.h"
23
#include "clang/AST/Type.h"
24
#include "clang/Basic/Diagnostic.h"
25
#include "clang/Basic/DiagnosticOptions.h"
26
#include "clang/Basic/IdentifierTable.h"
27
#include "clang/Basic/Module.h"
28
#include "clang/Basic/OpenCLOptions.h"
29
#include "clang/Basic/SourceLocation.h"
30
#include "clang/Basic/Version.h"
31
#include "clang/Lex/ExternalPreprocessorSource.h"
32
#include "clang/Lex/HeaderSearch.h"
33
#include "clang/Lex/PreprocessingRecord.h"
34
#include "clang/Lex/Token.h"
35
#include "clang/Sema/ExternalSemaSource.h"
36
#include "clang/Sema/IdentifierResolver.h"
37
#include "clang/Serialization/ASTBitCodes.h"
38
#include "clang/Serialization/ContinuousRangeMap.h"
39
#include "clang/Serialization/Module.h"
40
#include "clang/Serialization/ModuleFileExtension.h"
41
#include "clang/Serialization/ModuleManager.h"
42
#include "llvm/ADT/APFloat.h"
43
#include "llvm/ADT/APInt.h"
44
#include "llvm/ADT/APSInt.h"
45
#include "llvm/ADT/ArrayRef.h"
46
#include "llvm/ADT/DenseMap.h"
47
#include "llvm/ADT/DenseSet.h"
48
#include "llvm/ADT/IntrusiveRefCntPtr.h"
49
#include "llvm/ADT/MapVector.h"
50
#include "llvm/ADT/Optional.h"
51
#include "llvm/ADT/STLExtras.h"
52
#include "llvm/ADT/SetVector.h"
53
#include "llvm/ADT/SmallPtrSet.h"
54
#include "llvm/ADT/SmallVector.h"
55
#include "llvm/ADT/StringMap.h"
56
#include "llvm/ADT/StringRef.h"
57
#include "llvm/ADT/iterator.h"
58
#include "llvm/ADT/iterator_range.h"
59
#include "llvm/Bitcode/BitstreamReader.h"
60
#include "llvm/Support/Casting.h"
61
#include "llvm/Support/Endian.h"
62
#include "llvm/Support/MemoryBuffer.h"
63
#include "llvm/Support/Timer.h"
64
#include "llvm/Support/VersionTuple.h"
65
#include <cassert>
66
#include <cstddef>
67
#include <cstdint>
68
#include <ctime>
69
#include <deque>
70
#include <memory>
71
#include <set>
72
#include <string>
73
#include <utility>
74
#include <vector>
75
76
namespace clang {
77
78
class ASTConsumer;
79
class ASTContext;
80
class ASTDeserializationListener;
81
class ASTReader;
82
class ASTRecordReader;
83
class CXXTemporary;
84
class Decl;
85
class DeclaratorDecl;
86
class DeclContext;
87
class EnumDecl;
88
class Expr;
89
class FieldDecl;
90
class FileEntry;
91
class FileManager;
92
class FileSystemOptions;
93
class FunctionDecl;
94
class GlobalModuleIndex;
95
struct HeaderFileInfo;
96
class HeaderSearchOptions;
97
class LangOptions;
98
class LazyASTUnresolvedSet;
99
class MacroInfo;
100
class MemoryBufferCache;
101
class NamedDecl;
102
class NamespaceDecl;
103
class ObjCCategoryDecl;
104
class ObjCInterfaceDecl;
105
class PCHContainerReader;
106
class Preprocessor;
107
class PreprocessorOptions;
108
struct QualifierInfo;
109
class Sema;
110
class SourceManager;
111
class Stmt;
112
class SwitchCase;
113
class TargetOptions;
114
class TemplateParameterList;
115
class TypedefNameDecl;
116
class TypeSourceInfo;
117
class ValueDecl;
118
class VarDecl;
119
120
/// Abstract interface for callback invocations by the ASTReader.
121
///
122
/// While reading an AST file, the ASTReader will call the methods of the
123
/// listener to pass on specific information. Some of the listener methods can
124
/// return true to indicate to the ASTReader that the information (and
125
/// consequently the AST file) is invalid.
126
class ASTReaderListener {
127
public:
128
  virtual ~ASTReaderListener();
129
130
  /// Receives the full Clang version information.
131
  ///
132
  /// \returns true to indicate that the version is invalid. Subclasses should
133
  /// generally defer to this implementation.
134
17
  virtual bool ReadFullVersionInformation(StringRef FullVersion) {
135
17
    return FullVersion != getClangFullRepositoryVersion();
136
17
  }
137
138
3.56k
  virtual void ReadModuleName(StringRef ModuleName) {}
139
4.56k
  virtual void ReadModuleMapFile(StringRef ModuleMapPath) {}
140
141
  /// Receives the language options.
142
  ///
143
  /// \returns true to indicate the options are invalid or false otherwise.
144
  virtual bool ReadLanguageOptions(const LangOptions &LangOpts,
145
                                   bool Complain,
146
809
                                   bool AllowCompatibleDifferences) {
147
809
    return false;
148
809
  }
149
150
  /// Receives the target options.
151
  ///
152
  /// \returns true to indicate the target options are invalid, or false
153
  /// otherwise.
154
  virtual bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
155
809
                                 bool AllowCompatibleDifferences) {
156
809
    return false;
157
809
  }
158
159
  /// Receives the diagnostic options.
160
  ///
161
  /// \returns true to indicate the diagnostic options are invalid, or false
162
  /// otherwise.
163
  virtual bool
164
  ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
165
558
                        bool Complain) {
166
558
    return false;
167
558
  }
168
169
  /// Receives the file system options.
170
  ///
171
  /// \returns true to indicate the file system options are invalid, or false
172
  /// otherwise.
173
  virtual bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
174
4.14k
                                     bool Complain) {
175
4.14k
    return false;
176
4.14k
  }
177
178
  /// Receives the header search options.
179
  ///
180
  /// \returns true to indicate the header search options are invalid, or false
181
  /// otherwise.
182
  virtual bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
183
                                       StringRef SpecificModuleCachePath,
184
424
                                       bool Complain) {
185
424
    return false;
186
424
  }
187
188
  /// Receives the preprocessor options.
189
  ///
190
  /// \param SuggestedPredefines Can be filled in with the set of predefines
191
  /// that are suggested by the preprocessor options. Typically only used when
192
  /// loading a precompiled header.
193
  ///
194
  /// \returns true to indicate the preprocessor options are invalid, or false
195
  /// otherwise.
196
  virtual bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
197
                                       bool Complain,
198
55
                                       std::string &SuggestedPredefines) {
199
55
    return false;
200
55
  }
201
202
  /// Receives __COUNTER__ value.
203
  virtual void ReadCounter(const serialization::ModuleFile &M,
204
0
                           unsigned Value) {}
205
206
  /// This is called for each AST file loaded.
207
  virtual void visitModuleFile(StringRef Filename,
208
7.21k
                               serialization::ModuleKind Kind) {}
209
210
  /// Returns true if this \c ASTReaderListener wants to receive the
211
  /// input files of the AST file via \c visitInputFile, false otherwise.
212
7.36k
  virtual bool needsInputFileVisitation() { return false; }
213
214
  /// Returns true if this \c ASTReaderListener wants to receive the
215
  /// system input files of the AST file via \c visitInputFile, false otherwise.
216
31
  virtual bool needsSystemInputFileVisitation() { return false; }
217
218
  /// if \c needsInputFileVisitation returns true, this is called for
219
  /// each non-system input file of the AST File. If
220
  /// \c needsSystemInputFileVisitation is true, then it is called for all
221
  /// system input files as well.
222
  ///
223
  /// \returns true to continue receiving the next input file, false to stop.
224
  virtual bool visitInputFile(StringRef Filename, bool isSystem,
225
0
                              bool isOverridden, bool isExplicitModule) {
226
0
    return true;
227
0
  }
228
229
  /// Returns true if this \c ASTReaderListener wants to receive the
230
  /// imports of the AST file via \c visitImport, false otherwise.
231
12
  virtual bool needsImportVisitation() const { return false; }
232
233
  /// If needsImportVisitation returns \c true, this is called for each
234
  /// AST file imported by this AST file.
235
0
  virtual void visitImport(StringRef ModuleName, StringRef Filename) {}
236
237
  /// Indicates that a particular module file extension has been read.
238
  virtual void readModuleFileExtension(
239
0
                 const ModuleFileExtensionMetadata &Metadata) {}
240
};
241
242
/// Simple wrapper class for chaining listeners.
243
class ChainedASTReaderListener : public ASTReaderListener {
244
  std::unique_ptr<ASTReaderListener> First;
245
  std::unique_ptr<ASTReaderListener> Second;
246
247
public:
248
  /// Takes ownership of \p First and \p Second.
249
  ChainedASTReaderListener(std::unique_ptr<ASTReaderListener> First,
250
                           std::unique_ptr<ASTReaderListener> Second)
251
465
      : First(std::move(First)), Second(std::move(Second)) {}
252
253
0
  std::unique_ptr<ASTReaderListener> takeFirst() { return std::move(First); }
254
387
  std::unique_ptr<ASTReaderListener> takeSecond() { return std::move(Second); }
255
256
  bool ReadFullVersionInformation(StringRef FullVersion) override;
257
  void ReadModuleName(StringRef ModuleName) override;
258
  void ReadModuleMapFile(StringRef ModuleMapPath) override;
259
  bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
260
                           bool AllowCompatibleDifferences) override;
261
  bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
262
                         bool AllowCompatibleDifferences) override;
263
  bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
264
                             bool Complain) override;
265
  bool ReadFileSystemOptions(const FileSystemOptions &FSOpts,
266
                             bool Complain) override;
267
268
  bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
269
                               StringRef SpecificModuleCachePath,
270
                               bool Complain) override;
271
  bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts,
272
                               bool Complain,
273
                               std::string &SuggestedPredefines) override;
274
275
  void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
276
  bool needsInputFileVisitation() override;
277
  bool needsSystemInputFileVisitation() override;
278
  void visitModuleFile(StringRef Filename,
279
                       serialization::ModuleKind Kind) override;
280
  bool visitInputFile(StringRef Filename, bool isSystem,
281
                      bool isOverridden, bool isExplicitModule) override;
282
  void readModuleFileExtension(
283
         const ModuleFileExtensionMetadata &Metadata) override;
284
};
285
286
/// ASTReaderListener implementation to validate the information of
287
/// the PCH file against an initialized Preprocessor.
288
class PCHValidator : public ASTReaderListener {
289
  Preprocessor &PP;
290
  ASTReader &Reader;
291
292
public:
293
  PCHValidator(Preprocessor &PP, ASTReader &Reader)
294
4.66k
      : PP(PP), Reader(Reader) {}
295
296
  bool ReadLanguageOptions(const LangOptions &LangOpts, bool Complain,
297
                           bool AllowCompatibleDifferences) override;
298
  bool ReadTargetOptions(const TargetOptions &TargetOpts, bool Complain,
299
                         bool AllowCompatibleDifferences) override;
300
  bool ReadDiagnosticOptions(IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts,
301
                             bool Complain) override;
302
  bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain,
303
                               std::string &SuggestedPredefines) override;
304
  bool ReadHeaderSearchOptions(const HeaderSearchOptions &HSOpts,
305
                               StringRef SpecificModuleCachePath,
306
                               bool Complain) override;
307
  void ReadCounter(const serialization::ModuleFile &M, unsigned Value) override;
308
309
private:
310
  void Error(const char *Msg);
311
};
312
313
/// ASTReaderListenter implementation to set SuggestedPredefines of
314
/// ASTReader which is required to use a pch file. This is the replacement
315
/// of PCHValidator or SimplePCHValidator when using a pch file without
316
/// validating it.
317
class SimpleASTReaderListener : public ASTReaderListener {
318
  Preprocessor &PP;
319
320
public:
321
374
  SimpleASTReaderListener(Preprocessor &PP) : PP(PP) {}
322
323
  bool ReadPreprocessorOptions(const PreprocessorOptions &PPOpts, bool Complain,
324
                               std::string &SuggestedPredefines) override;
325
};
326
327
namespace serialization {
328
329
class ReadMethodPoolVisitor;
330
331
namespace reader {
332
333
class ASTIdentifierLookupTrait;
334
335
/// The on-disk hash table(s) used for DeclContext name lookup.
336
struct DeclContextLookupTable;
337
338
} // namespace reader
339
340
} // namespace serialization
341
342
/// Reads an AST files chain containing the contents of a translation
343
/// unit.
344
///
345
/// The ASTReader class reads bitstreams (produced by the ASTWriter
346
/// class) containing the serialized representation of a given
347
/// abstract syntax tree and its supporting data structures. An
348
/// instance of the ASTReader can be attached to an ASTContext object,
349
/// which will provide access to the contents of the AST files.
350
///
351
/// The AST reader provides lazy de-serialization of declarations, as
352
/// required when traversing the AST. Only those AST nodes that are
353
/// actually required will be de-serialized.
354
class ASTReader
355
  : public ExternalPreprocessorSource,
356
    public ExternalPreprocessingRecordSource,
357
    public ExternalHeaderFileInfoSource,
358
    public ExternalSemaSource,
359
    public IdentifierInfoLookup,
360
    public ExternalSLocEntrySource
361
{
362
public:
363
  /// Types of AST files.
364
  friend class ASTDeclReader;
365
  friend class ASTIdentifierIterator;
366
  friend class ASTRecordReader;
367
  friend class ASTStmtReader;
368
  friend class ASTUnit; // ASTUnit needs to remap source locations.
369
  friend class ASTWriter;
370
  friend class PCHValidator;
371
  friend class serialization::reader::ASTIdentifierLookupTrait;
372
  friend class serialization::ReadMethodPoolVisitor;
373
  friend class TypeLocReader;
374
375
  using RecordData = SmallVector<uint64_t, 64>;
376
  using RecordDataImpl = SmallVectorImpl<uint64_t>;
377
378
  /// The result of reading the control block of an AST file, which
379
  /// can fail for various reasons.
380
  enum ASTReadResult {
381
    /// The control block was read successfully. Aside from failures,
382
    /// the AST file is safe to read into the current context.
383
    Success,
384
385
    /// The AST file itself appears corrupted.
386
    Failure,
387
388
    /// The AST file was missing.
389
    Missing,
390
391
    /// The AST file is out-of-date relative to its input files,
392
    /// and needs to be regenerated.
393
    OutOfDate,
394
395
    /// The AST file was written by a different version of Clang.
396
    VersionMismatch,
397
398
    /// The AST file was writtten with a different language/target
399
    /// configuration.
400
    ConfigurationMismatch,
401
402
    /// The AST file has errors.
403
    HadErrors
404
  };
405
406
  using ModuleFile = serialization::ModuleFile;
407
  using ModuleKind = serialization::ModuleKind;
408
  using ModuleManager = serialization::ModuleManager;
409
  using ModuleIterator = ModuleManager::ModuleIterator;
410
  using ModuleConstIterator = ModuleManager::ModuleConstIterator;
411
  using ModuleReverseIterator = ModuleManager::ModuleReverseIterator;
412
413
private:
414
  /// The receiver of some callbacks invoked by ASTReader.
415
  std::unique_ptr<ASTReaderListener> Listener;
416
417
  /// The receiver of deserialization events.
418
  ASTDeserializationListener *DeserializationListener = nullptr;
419
420
  bool OwnsDeserializationListener = false;
421
422
  SourceManager &SourceMgr;
423
  FileManager &FileMgr;
424
  const PCHContainerReader &PCHContainerRdr;
425
  DiagnosticsEngine &Diags;
426
427
  /// The semantic analysis object that will be processing the
428
  /// AST files and the translation unit that uses it.
429
  Sema *SemaObj = nullptr;
430
431
  /// The preprocessor that will be loading the source file.
432
  Preprocessor &PP;
433
434
  /// The AST context into which we'll read the AST files.
435
  ASTContext *ContextObj = nullptr;
436
437
  /// The AST consumer.
438
  ASTConsumer *Consumer = nullptr;
439
440
  /// The module manager which manages modules and their dependencies
441
  ModuleManager ModuleMgr;
442
443
  /// The cache that manages memory buffers for PCM files.
444
  MemoryBufferCache &PCMCache;
445
446
  /// A dummy identifier resolver used to merge TU-scope declarations in
447
  /// C, for the cases where we don't have a Sema object to provide a real
448
  /// identifier resolver.
449
  IdentifierResolver DummyIdResolver;
450
451
  /// A mapping from extension block names to module file extensions.
452
  llvm::StringMap<std::shared_ptr<ModuleFileExtension>> ModuleFileExtensions;
453
454
  /// A timer used to track the time spent deserializing.
455
  std::unique_ptr<llvm::Timer> ReadTimer;
456
457
  /// The location where the module file will be considered as
458
  /// imported from. For non-module AST types it should be invalid.
459
  SourceLocation CurrentImportLoc;
460
461
  /// The global module index, if loaded.
462
  std::unique_ptr<GlobalModuleIndex> GlobalIndex;
463
464
  /// A map of global bit offsets to the module that stores entities
465
  /// at those bit offsets.
466
  ContinuousRangeMap<uint64_t, ModuleFile*, 4> GlobalBitOffsetsMap;
467
468
  /// A map of negated SLocEntryIDs to the modules containing them.
469
  ContinuousRangeMap<unsigned, ModuleFile*, 64> GlobalSLocEntryMap;
470
471
  using GlobalSLocOffsetMapType =
472
      ContinuousRangeMap<unsigned, ModuleFile *, 64>;
473
474
  /// A map of reversed (SourceManager::MaxLoadedOffset - SLocOffset)
475
  /// SourceLocation offsets to the modules containing them.
476
  GlobalSLocOffsetMapType GlobalSLocOffsetMap;
477
478
  /// Types that have already been loaded from the chain.
479
  ///
480
  /// When the pointer at index I is non-NULL, the type with
481
  /// ID = (I + 1) << FastQual::Width has already been loaded
482
  std::vector<QualType> TypesLoaded;
483
484
  using GlobalTypeMapType =
485
      ContinuousRangeMap<serialization::TypeID, ModuleFile *, 4>;
486
487
  /// Mapping from global type IDs to the module in which the
488
  /// type resides along with the offset that should be added to the
489
  /// global type ID to produce a local ID.
490
  GlobalTypeMapType GlobalTypeMap;
491
492
  /// Declarations that have already been loaded from the chain.
493
  ///
494
  /// When the pointer at index I is non-NULL, the declaration with ID
495
  /// = I + 1 has already been loaded.
496
  std::vector<Decl *> DeclsLoaded;
497
498
  using GlobalDeclMapType =
499
      ContinuousRangeMap<serialization::DeclID, ModuleFile *, 4>;
500
501
  /// Mapping from global declaration IDs to the module in which the
502
  /// declaration resides.
503
  GlobalDeclMapType GlobalDeclMap;
504
505
  using FileOffset = std::pair<ModuleFile *, uint64_t>;
506
  using FileOffsetsTy = SmallVector<FileOffset, 2>;
507
  using DeclUpdateOffsetsMap =
508
      llvm::DenseMap<serialization::DeclID, FileOffsetsTy>;
509
510
  /// Declarations that have modifications residing in a later file
511
  /// in the chain.
512
  DeclUpdateOffsetsMap DeclUpdateOffsets;
513
514
  struct PendingUpdateRecord {
515
    Decl *D;
516
    serialization::GlobalDeclID ID;
517
518
    // Whether the declaration was just deserialized.
519
    bool JustLoaded;
520
521
    PendingUpdateRecord(serialization::GlobalDeclID ID, Decl *D,
522
                        bool JustLoaded)
523
252k
        : D(D), ID(ID), JustLoaded(JustLoaded) {}
524
  };
525
526
  /// Declaration updates for already-loaded declarations that we need
527
  /// to apply once we finish processing an import.
528
  llvm::SmallVector<PendingUpdateRecord, 16> PendingUpdateRecords;
529
530
  enum class PendingFakeDefinitionKind { NotFake, Fake, FakeLoaded };
531
532
  /// The DefinitionData pointers that we faked up for class definitions
533
  /// that we needed but hadn't loaded yet.
534
  llvm::DenseMap<void *, PendingFakeDefinitionKind> PendingFakeDefinitionData;
535
536
  /// Exception specification updates that have been loaded but not yet
537
  /// propagated across the relevant redeclaration chain. The map key is the
538
  /// canonical declaration (used only for deduplication) and the value is a
539
  /// declaration that has an exception specification.
540
  llvm::SmallMapVector<Decl *, FunctionDecl *, 4> PendingExceptionSpecUpdates;
541
542
  /// Deduced return type updates that have been loaded but not yet propagated
543
  /// across the relevant redeclaration chain. The map key is the canonical
544
  /// declaration and the value is the deduced return type.
545
  llvm::SmallMapVector<FunctionDecl *, QualType, 4> PendingDeducedTypeUpdates;
546
547
  /// Declarations that have been imported and have typedef names for
548
  /// linkage purposes.
549
  llvm::DenseMap<std::pair<DeclContext *, IdentifierInfo *>, NamedDecl *>
550
      ImportedTypedefNamesForLinkage;
551
552
  /// Mergeable declaration contexts that have anonymous declarations
553
  /// within them, and those anonymous declarations.
554
  llvm::DenseMap<Decl*, llvm::SmallVector<NamedDecl*, 2>>
555
    AnonymousDeclarationsForMerging;
556
557
  struct FileDeclsInfo {
558
    ModuleFile *Mod = nullptr;
559
    ArrayRef<serialization::LocalDeclID> Decls;
560
561
3.35k
    FileDeclsInfo() = default;
562
    FileDeclsInfo(ModuleFile *Mod, ArrayRef<serialization::LocalDeclID> Decls)
563
3.35k
        : Mod(Mod), Decls(Decls) {}
564
  };
565
566
  /// Map from a FileID to the file-level declarations that it contains.
567
  llvm::DenseMap<FileID, FileDeclsInfo> FileDeclIDs;
568
569
  /// An array of lexical contents of a declaration context, as a sequence of
570
  /// Decl::Kind, DeclID pairs.
571
  using LexicalContents = ArrayRef<llvm::support::unaligned_uint32_t>;
572
573
  /// Map from a DeclContext to its lexical contents.
574
  llvm::DenseMap<const DeclContext*, std::pair<ModuleFile*, LexicalContents>>
575
      LexicalDecls;
576
577
  /// Map from the TU to its lexical contents from each module file.
578
  std::vector<std::pair<ModuleFile*, LexicalContents>> TULexicalDecls;
579
580
  /// Map from a DeclContext to its lookup tables.
581
  llvm::DenseMap<const DeclContext *,
582
                 serialization::reader::DeclContextLookupTable> Lookups;
583
584
  // Updates for visible decls can occur for other contexts than just the
585
  // TU, and when we read those update records, the actual context may not
586
  // be available yet, so have this pending map using the ID as a key. It
587
  // will be realized when the context is actually loaded.
588
  struct PendingVisibleUpdate {
589
    ModuleFile *Mod;
590
    const unsigned char *Data;
591
  };
592
  using DeclContextVisibleUpdates = SmallVector<PendingVisibleUpdate, 1>;
593
594
  /// Updates to the visible declarations of declaration contexts that
595
  /// haven't been loaded yet.
596
  llvm::DenseMap<serialization::DeclID, DeclContextVisibleUpdates>
597
      PendingVisibleUpdates;
598
599
  /// The set of C++ or Objective-C classes that have forward
600
  /// declarations that have not yet been linked to their definitions.
601
  llvm::SmallPtrSet<Decl *, 4> PendingDefinitions;
602
603
  using PendingBodiesMap =
604
      llvm::MapVector<Decl *, uint64_t,
605
                      llvm::SmallDenseMap<Decl *, unsigned, 4>,
606
                      SmallVector<std::pair<Decl *, uint64_t>, 4>>;
607
608
  /// Functions or methods that have bodies that will be attached.
609
  PendingBodiesMap PendingBodies;
610
611
  /// Definitions for which we have added merged definitions but not yet
612
  /// performed deduplication.
613
  llvm::SetVector<NamedDecl *> PendingMergedDefinitionsToDeduplicate;
614
615
  /// Read the record that describes the lexical contents of a DC.
616
  bool ReadLexicalDeclContextStorage(ModuleFile &M,
617
                                     llvm::BitstreamCursor &Cursor,
618
                                     uint64_t Offset, DeclContext *DC);
619
620
  /// Read the record that describes the visible contents of a DC.
621
  bool ReadVisibleDeclContextStorage(ModuleFile &M,
622
                                     llvm::BitstreamCursor &Cursor,
623
                                     uint64_t Offset, serialization::DeclID ID);
624
625
  /// A vector containing identifiers that have already been
626
  /// loaded.
627
  ///
628
  /// If the pointer at index I is non-NULL, then it refers to the
629
  /// IdentifierInfo for the identifier with ID=I+1 that has already
630
  /// been loaded.
631
  std::vector<IdentifierInfo *> IdentifiersLoaded;
632
633
  using GlobalIdentifierMapType =
634
      ContinuousRangeMap<serialization::IdentID, ModuleFile *, 4>;
635
636
  /// Mapping from global identifier IDs to the module in which the
637
  /// identifier resides along with the offset that should be added to the
638
  /// global identifier ID to produce a local ID.
639
  GlobalIdentifierMapType GlobalIdentifierMap;
640
641
  /// A vector containing macros that have already been
642
  /// loaded.
643
  ///
644
  /// If the pointer at index I is non-NULL, then it refers to the
645
  /// MacroInfo for the identifier with ID=I+1 that has already
646
  /// been loaded.
647
  std::vector<MacroInfo *> MacrosLoaded;
648
649
  using LoadedMacroInfo =
650
      std::pair<IdentifierInfo *, serialization::SubmoduleID>;
651
652
  /// A set of #undef directives that we have loaded; used to
653
  /// deduplicate the same #undef information coming from multiple module
654
  /// files.
655
  llvm::DenseSet<LoadedMacroInfo> LoadedUndefs;
656
657
  using GlobalMacroMapType =
658
      ContinuousRangeMap<serialization::MacroID, ModuleFile *, 4>;
659
660
  /// Mapping from global macro IDs to the module in which the
661
  /// macro resides along with the offset that should be added to the
662
  /// global macro ID to produce a local ID.
663
  GlobalMacroMapType GlobalMacroMap;
664
665
  /// A vector containing submodules that have already been loaded.
666
  ///
667
  /// This vector is indexed by the Submodule ID (-1). NULL submodule entries
668
  /// indicate that the particular submodule ID has not yet been loaded.
669
  SmallVector<Module *, 2> SubmodulesLoaded;
670
671
  using GlobalSubmoduleMapType =
672
      ContinuousRangeMap<serialization::SubmoduleID, ModuleFile *, 4>;
673
674
  /// Mapping from global submodule IDs to the module file in which the
675
  /// submodule resides along with the offset that should be added to the
676
  /// global submodule ID to produce a local ID.
677
  GlobalSubmoduleMapType GlobalSubmoduleMap;
678
679
  /// A set of hidden declarations.
680
  using HiddenNames = SmallVector<Decl *, 2>;
681
  using HiddenNamesMapType = llvm::DenseMap<Module *, HiddenNames>;
682
683
  /// A mapping from each of the hidden submodules to the deserialized
684
  /// declarations in that submodule that could be made visible.
685
  HiddenNamesMapType HiddenNamesMap;
686
687
  /// A module import, export, or conflict that hasn't yet been resolved.
688
  struct UnresolvedModuleRef {
689
    /// The file in which this module resides.
690
    ModuleFile *File;
691
692
    /// The module that is importing or exporting.
693
    Module *Mod;
694
695
    /// The kind of module reference.
696
    enum { Import, Export, Conflict } Kind;
697
698
    /// The local ID of the module that is being exported.
699
    unsigned ID;
700
701
    /// Whether this is a wildcard export.
702
    unsigned IsWildcard : 1;
703
704
    /// String data.
705
    StringRef String;
706
  };
707
708
  /// The set of module imports and exports that still need to be
709
  /// resolved.
710
  SmallVector<UnresolvedModuleRef, 2> UnresolvedModuleRefs;
711
712
  /// A vector containing selectors that have already been loaded.
713
  ///
714
  /// This vector is indexed by the Selector ID (-1). NULL selector
715
  /// entries indicate that the particular selector ID has not yet
716
  /// been loaded.
717
  SmallVector<Selector, 16> SelectorsLoaded;
718
719
  using GlobalSelectorMapType =
720
      ContinuousRangeMap<serialization::SelectorID, ModuleFile *, 4>;
721
722
  /// Mapping from global selector IDs to the module in which the
723
  /// global selector ID to produce a local ID.
724
  GlobalSelectorMapType GlobalSelectorMap;
725
726
  /// The generation number of the last time we loaded data from the
727
  /// global method pool for this selector.
728
  llvm::DenseMap<Selector, unsigned> SelectorGeneration;
729
730
  /// Whether a selector is out of date. We mark a selector as out of date
731
  /// if we load another module after the method pool entry was pulled in.
732
  llvm::DenseMap<Selector, bool> SelectorOutOfDate;
733
734
  struct PendingMacroInfo {
735
    ModuleFile *M;
736
    uint64_t MacroDirectivesOffset;
737
738
    PendingMacroInfo(ModuleFile *M, uint64_t MacroDirectivesOffset)
739
31.4k
        : M(M), MacroDirectivesOffset(MacroDirectivesOffset) {}
740
  };
741
742
  using PendingMacroIDsMap =
743
      llvm::MapVector<IdentifierInfo *, SmallVector<PendingMacroInfo, 2>>;
744
745
  /// Mapping from identifiers that have a macro history to the global
746
  /// IDs have not yet been deserialized to the global IDs of those macros.
747
  PendingMacroIDsMap PendingMacroIDs;
748
749
  using GlobalPreprocessedEntityMapType =
750
      ContinuousRangeMap<unsigned, ModuleFile *, 4>;
751
752
  /// Mapping from global preprocessing entity IDs to the module in
753
  /// which the preprocessed entity resides along with the offset that should be
754
  /// added to the global preprocessing entity ID to produce a local ID.
755
  GlobalPreprocessedEntityMapType GlobalPreprocessedEntityMap;
756
757
  using GlobalSkippedRangeMapType =
758
      ContinuousRangeMap<unsigned, ModuleFile *, 4>;
759
760
  /// Mapping from global skipped range base IDs to the module in which
761
  /// the skipped ranges reside.
762
  GlobalSkippedRangeMapType GlobalSkippedRangeMap;
763
764
  /// \name CodeGen-relevant special data
765
  /// Fields containing data that is relevant to CodeGen.
766
  //@{
767
768
  /// The IDs of all declarations that fulfill the criteria of
769
  /// "interesting" decls.
770
  ///
771
  /// This contains the data loaded from all EAGERLY_DESERIALIZED_DECLS blocks
772
  /// in the chain. The referenced declarations are deserialized and passed to
773
  /// the consumer eagerly.
774
  SmallVector<uint64_t, 16> EagerlyDeserializedDecls;
775
776
  /// The IDs of all tentative definitions stored in the chain.
777
  ///
778
  /// Sema keeps track of all tentative definitions in a TU because it has to
779
  /// complete them and pass them on to CodeGen. Thus, tentative definitions in
780
  /// the PCH chain must be eagerly deserialized.
781
  SmallVector<uint64_t, 16> TentativeDefinitions;
782
783
  /// The IDs of all CXXRecordDecls stored in the chain whose VTables are
784
  /// used.
785
  ///
786
  /// CodeGen has to emit VTables for these records, so they have to be eagerly
787
  /// deserialized.
788
  SmallVector<uint64_t, 64> VTableUses;
789
790
  /// A snapshot of the pending instantiations in the chain.
791
  ///
792
  /// This record tracks the instantiations that Sema has to perform at the
793
  /// end of the TU. It consists of a pair of values for every pending
794
  /// instantiation where the first value is the ID of the decl and the second
795
  /// is the instantiation location.
796
  SmallVector<uint64_t, 64> PendingInstantiations;
797
798
  //@}
799
800
  /// \name DiagnosticsEngine-relevant special data
801
  /// Fields containing data that is used for generating diagnostics
802
  //@{
803
804
  /// A snapshot of Sema's unused file-scoped variable tracking, for
805
  /// generating warnings.
806
  SmallVector<uint64_t, 16> UnusedFileScopedDecls;
807
808
  /// A list of all the delegating constructors we've seen, to diagnose
809
  /// cycles.
810
  SmallVector<uint64_t, 4> DelegatingCtorDecls;
811
812
  /// Method selectors used in a @selector expression. Used for
813
  /// implementation of -Wselector.
814
  SmallVector<uint64_t, 64> ReferencedSelectorsData;
815
816
  /// A snapshot of Sema's weak undeclared identifier tracking, for
817
  /// generating warnings.
818
  SmallVector<uint64_t, 64> WeakUndeclaredIdentifiers;
819
820
  /// The IDs of type aliases for ext_vectors that exist in the chain.
821
  ///
822
  /// Used by Sema for finding sugared names for ext_vectors in diagnostics.
823
  SmallVector<uint64_t, 4> ExtVectorDecls;
824
825
  //@}
826
827
  /// \name Sema-relevant special data
828
  /// Fields containing data that is used for semantic analysis
829
  //@{
830
831
  /// The IDs of all potentially unused typedef names in the chain.
832
  ///
833
  /// Sema tracks these to emit warnings.
834
  SmallVector<uint64_t, 16> UnusedLocalTypedefNameCandidates;
835
836
  /// Our current depth in #pragma cuda force_host_device begin/end
837
  /// macros.
838
  unsigned ForceCUDAHostDeviceDepth = 0;
839
840
  /// The IDs of the declarations Sema stores directly.
841
  ///
842
  /// Sema tracks a few important decls, such as namespace std, directly.
843
  SmallVector<uint64_t, 4> SemaDeclRefs;
844
845
  /// The IDs of the types ASTContext stores directly.
846
  ///
847
  /// The AST context tracks a few important types, such as va_list, directly.
848
  SmallVector<uint64_t, 16> SpecialTypes;
849
850
  /// The IDs of CUDA-specific declarations ASTContext stores directly.
851
  ///
852
  /// The AST context tracks a few important decls, currently cudaConfigureCall,
853
  /// directly.
854
  SmallVector<uint64_t, 2> CUDASpecialDeclRefs;
855
856
  /// The floating point pragma option settings.
857
  SmallVector<uint64_t, 1> FPPragmaOptions;
858
859
  /// The pragma clang optimize location (if the pragma state is "off").
860
  SourceLocation OptimizeOffPragmaLocation;
861
862
  /// The PragmaMSStructKind pragma ms_struct state if set, or -1.
863
  int PragmaMSStructState = -1;
864
865
  /// The PragmaMSPointersToMembersKind pragma pointers_to_members state.
866
  int PragmaMSPointersToMembersState = -1;
867
  SourceLocation PointersToMembersPragmaLocation;
868
869
  /// The pragma pack state.
870
  Optional<unsigned> PragmaPackCurrentValue;
871
  SourceLocation PragmaPackCurrentLocation;
872
  struct PragmaPackStackEntry {
873
    unsigned Value;
874
    SourceLocation Location;
875
    SourceLocation PushLocation;
876
    StringRef SlotLabel;
877
  };
878
  llvm::SmallVector<PragmaPackStackEntry, 2> PragmaPackStack;
879
  llvm::SmallVector<std::string, 2> PragmaPackStrings;
880
881
  /// The OpenCL extension settings.
882
  OpenCLOptions OpenCLExtensions;
883
884
  /// Extensions required by an OpenCL type.
885
  llvm::DenseMap<const Type *, std::set<std::string>> OpenCLTypeExtMap;
886
887
  /// Extensions required by an OpenCL declaration.
888
  llvm::DenseMap<const Decl *, std::set<std::string>> OpenCLDeclExtMap;
889
890
  /// A list of the namespaces we've seen.
891
  SmallVector<uint64_t, 4> KnownNamespaces;
892
893
  /// A list of undefined decls with internal linkage followed by the
894
  /// SourceLocation of a matching ODR-use.
895
  SmallVector<uint64_t, 8> UndefinedButUsed;
896
897
  /// Delete expressions to analyze at the end of translation unit.
898
  SmallVector<uint64_t, 8> DelayedDeleteExprs;
899
900
  // A list of late parsed template function data.
901
  SmallVector<uint64_t, 1> LateParsedTemplates;
902
903
public:
904
  struct ImportedSubmodule {
905
    serialization::SubmoduleID ID;
906
    SourceLocation ImportLoc;
907
908
    ImportedSubmodule(serialization::SubmoduleID ID, SourceLocation ImportLoc)
909
62
        : ID(ID), ImportLoc(ImportLoc) {}
910
  };
911
912
private:
913
  /// A list of modules that were imported by precompiled headers or
914
  /// any other non-module AST file.
915
  SmallVector<ImportedSubmodule, 2> ImportedModules;
916
  //@}
917
918
  /// The system include root to be used when loading the
919
  /// precompiled header.
920
  std::string isysroot;
921
922
  /// Whether to disable the normal validation performed on precompiled
923
  /// headers when they are loaded.
924
  bool DisableValidation;
925
926
  /// Whether to accept an AST file with compiler errors.
927
  bool AllowASTWithCompilerErrors;
928
929
  /// Whether to accept an AST file that has a different configuration
930
  /// from the current compiler instance.
931
  bool AllowConfigurationMismatch;
932
933
  /// Whether validate system input files.
934
  bool ValidateSystemInputs;
935
936
  /// Whether we are allowed to use the global module index.
937
  bool UseGlobalIndex;
938
939
  /// Whether we have tried loading the global module index yet.
940
  bool TriedLoadingGlobalIndex = false;
941
942
  ///Whether we are currently processing update records.
943
  bool ProcessingUpdateRecords = false;
944
945
  using SwitchCaseMapTy = llvm::DenseMap<unsigned, SwitchCase *>;
946
947
  /// Mapping from switch-case IDs in the chain to switch-case statements
948
  ///
949
  /// Statements usually don't have IDs, but switch cases need them, so that the
950
  /// switch statement can refer to them.
951
  SwitchCaseMapTy SwitchCaseStmts;
952
953
  SwitchCaseMapTy *CurrSwitchCaseStmts;
954
955
  /// The number of source location entries de-serialized from
956
  /// the PCH file.
957
  unsigned NumSLocEntriesRead = 0;
958
959
  /// The number of source location entries in the chain.
960
  unsigned TotalNumSLocEntries = 0;
961
962
  /// The number of statements (and expressions) de-serialized
963
  /// from the chain.
964
  unsigned NumStatementsRead = 0;
965
966
  /// The total number of statements (and expressions) stored
967
  /// in the chain.
968
  unsigned TotalNumStatements = 0;
969
970
  /// The number of macros de-serialized from the chain.
971
  unsigned NumMacrosRead = 0;
972
973
  /// The total number of macros stored in the chain.
974
  unsigned TotalNumMacros = 0;
975
976
  /// The number of lookups into identifier tables.
977
  unsigned NumIdentifierLookups = 0;
978
979
  /// The number of lookups into identifier tables that succeed.
980
  unsigned NumIdentifierLookupHits = 0;
981
982
  /// The number of selectors that have been read.
983
  unsigned NumSelectorsRead = 0;
984
985
  /// The number of method pool entries that have been read.
986
  unsigned NumMethodPoolEntriesRead = 0;
987
988
  /// The number of times we have looked up a selector in the method
989
  /// pool.
990
  unsigned NumMethodPoolLookups = 0;
991
992
  /// The number of times we have looked up a selector in the method
993
  /// pool and found something.
994
  unsigned NumMethodPoolHits = 0;
995
996
  /// The number of times we have looked up a selector in the method
997
  /// pool within a specific module.
998
  unsigned NumMethodPoolTableLookups = 0;
999
1000
  /// The number of times we have looked up a selector in the method
1001
  /// pool within a specific module and found something.
1002
  unsigned NumMethodPoolTableHits = 0;
1003
1004
  /// The total number of method pool entries in the selector table.
1005
  unsigned TotalNumMethodPoolEntries = 0;
1006
1007
  /// Number of lexical decl contexts read/total.
1008
  unsigned NumLexicalDeclContextsRead = 0, TotalLexicalDeclContexts = 0;
1009
1010
  /// Number of visible decl contexts read/total.
1011
  unsigned NumVisibleDeclContextsRead = 0, TotalVisibleDeclContexts = 0;
1012
1013
  /// Total size of modules, in bits, currently loaded
1014
  uint64_t TotalModulesSizeInBits = 0;
1015
1016
  /// Number of Decl/types that are currently deserializing.
1017
  unsigned NumCurrentElementsDeserializing = 0;
1018
1019
  /// Set true while we are in the process of passing deserialized
1020
  /// "interesting" decls to consumer inside FinishedDeserializing().
1021
  /// This is used as a guard to avoid recursively repeating the process of
1022
  /// passing decls to consumer.
1023
  bool PassingDeclsToConsumer = false;
1024
1025
  /// The set of identifiers that were read while the AST reader was
1026
  /// (recursively) loading declarations.
1027
  ///
1028
  /// The declarations on the identifier chain for these identifiers will be
1029
  /// loaded once the recursive loading has completed.
1030
  llvm::MapVector<IdentifierInfo *, SmallVector<uint32_t, 4>>
1031
    PendingIdentifierInfos;
1032
1033
  /// The set of lookup results that we have faked in order to support
1034
  /// merging of partially deserialized decls but that we have not yet removed.
1035
  llvm::SmallMapVector<IdentifierInfo *, SmallVector<NamedDecl*, 2>, 16>
1036
    PendingFakeLookupResults;
1037
1038
  /// The generation number of each identifier, which keeps track of
1039
  /// the last time we loaded information about this identifier.
1040
  llvm::DenseMap<IdentifierInfo *, unsigned> IdentifierGeneration;
1041
1042
  class InterestingDecl {
1043
    Decl *D;
1044
    bool DeclHasPendingBody;
1045
1046
  public:
1047
    InterestingDecl(Decl *D, bool HasBody)
1048
248k
        : D(D), DeclHasPendingBody(HasBody) {}
1049
1050
259k
    Decl *getDecl() { return D; }
1051
1052
    /// Whether the declaration has a pending body.
1053
245k
    bool hasPendingBody() { return DeclHasPendingBody; }
1054
  };
1055
1056
  /// Contains declarations and definitions that could be
1057
  /// "interesting" to the ASTConsumer, when we get that AST consumer.
1058
  ///
1059
  /// "Interesting" declarations are those that have data that may
1060
  /// need to be emitted, such as inline function definitions or
1061
  /// Objective-C protocols.
1062
  std::deque<InterestingDecl> PotentiallyInterestingDecls;
1063
1064
  /// The list of deduced function types that we have not yet read, because
1065
  /// they might contain a deduced return type that refers to a local type
1066
  /// declared within the function.
1067
  SmallVector<std::pair<FunctionDecl *, serialization::TypeID>, 16>
1068
      PendingFunctionTypes;
1069
1070
  /// The list of redeclaration chains that still need to be
1071
  /// reconstructed, and the local offset to the corresponding list
1072
  /// of redeclarations.
1073
  SmallVector<std::pair<Decl *, uint64_t>, 16> PendingDeclChains;
1074
1075
  /// The list of canonical declarations whose redeclaration chains
1076
  /// need to be marked as incomplete once we're done deserializing things.
1077
  SmallVector<Decl *, 16> PendingIncompleteDeclChains;
1078
1079
  /// The Decl IDs for the Sema/Lexical DeclContext of a Decl that has
1080
  /// been loaded but its DeclContext was not set yet.
1081
  struct PendingDeclContextInfo {
1082
    Decl *D;
1083
    serialization::GlobalDeclID SemaDC;
1084
    serialization::GlobalDeclID LexicalDC;
1085
  };
1086
1087
  /// The set of Decls that have been loaded but their DeclContexts are
1088
  /// not set yet.
1089
  ///
1090
  /// The DeclContexts for these Decls will be set once recursive loading has
1091
  /// been completed.
1092
  std::deque<PendingDeclContextInfo> PendingDeclContextInfos;
1093
1094
  /// The set of NamedDecls that have been loaded, but are members of a
1095
  /// context that has been merged into another context where the corresponding
1096
  /// declaration is either missing or has not yet been loaded.
1097
  ///
1098
  /// We will check whether the corresponding declaration is in fact missing
1099
  /// once recursing loading has been completed.
1100
  llvm::SmallVector<NamedDecl *, 16> PendingOdrMergeChecks;
1101
1102
  using DataPointers =
1103
      std::pair<CXXRecordDecl *, struct CXXRecordDecl::DefinitionData *>;
1104
1105
  /// Record definitions in which we found an ODR violation.
1106
  llvm::SmallDenseMap<CXXRecordDecl *, llvm::SmallVector<DataPointers, 2>, 2>
1107
      PendingOdrMergeFailures;
1108
1109
  /// Function definitions in which we found an ODR violation.
1110
  llvm::SmallDenseMap<FunctionDecl *, llvm::SmallVector<FunctionDecl *, 2>, 2>
1111
      PendingFunctionOdrMergeFailures;
1112
1113
  /// Enum definitions in which we found an ODR violation.
1114
  llvm::SmallDenseMap<EnumDecl *, llvm::SmallVector<EnumDecl *, 2>, 2>
1115
      PendingEnumOdrMergeFailures;
1116
1117
  /// DeclContexts in which we have diagnosed an ODR violation.
1118
  llvm::SmallPtrSet<DeclContext*, 2> DiagnosedOdrMergeFailures;
1119
1120
  /// The set of Objective-C categories that have been deserialized
1121
  /// since the last time the declaration chains were linked.
1122
  llvm::SmallPtrSet<ObjCCategoryDecl *, 16> CategoriesDeserialized;
1123
1124
  /// The set of Objective-C class definitions that have already been
1125
  /// loaded, for which we will need to check for categories whenever a new
1126
  /// module is loaded.
1127
  SmallVector<ObjCInterfaceDecl *, 16> ObjCClassesLoaded;
1128
1129
  using KeyDeclsMap =
1130
      llvm::DenseMap<Decl *, SmallVector<serialization::DeclID, 2>>;
1131
1132
  /// A mapping from canonical declarations to the set of global
1133
  /// declaration IDs for key declaration that have been merged with that
1134
  /// canonical declaration. A key declaration is a formerly-canonical
1135
  /// declaration whose module did not import any other key declaration for that
1136
  /// entity. These are the IDs that we use as keys when finding redecl chains.
1137
  KeyDeclsMap KeyDecls;
1138
1139
  /// A mapping from DeclContexts to the semantic DeclContext that we
1140
  /// are treating as the definition of the entity. This is used, for instance,
1141
  /// when merging implicit instantiations of class templates across modules.
1142
  llvm::DenseMap<DeclContext *, DeclContext *> MergedDeclContexts;
1143
1144
  /// A mapping from canonical declarations of enums to their canonical
1145
  /// definitions. Only populated when using modules in C++.
1146
  llvm::DenseMap<EnumDecl *, EnumDecl *> EnumDefinitions;
1147
1148
  /// When reading a Stmt tree, Stmt operands are placed in this stack.
1149
  SmallVector<Stmt *, 16> StmtStack;
1150
1151
  /// What kind of records we are reading.
1152
  enum ReadingKind {
1153
    Read_None, Read_Decl, Read_Type, Read_Stmt
1154
  };
1155
1156
  /// What kind of records we are reading.
1157
  ReadingKind ReadingKind = Read_None;
1158
1159
  /// RAII object to change the reading kind.
1160
  class ReadingKindTracker {
1161
    ASTReader &Reader;
1162
    enum ReadingKind PrevKind;
1163
1164
  public:
1165
    ReadingKindTracker(enum ReadingKind newKind, ASTReader &reader)
1166
729k
        : Reader(reader), PrevKind(Reader.ReadingKind) {
1167
729k
      Reader.ReadingKind = newKind;
1168
729k
    }
1169
1170
    ReadingKindTracker(const ReadingKindTracker &) = delete;
1171
    ReadingKindTracker &operator=(const ReadingKindTracker &) = delete;
1172
729k
    ~ReadingKindTracker() { Reader.ReadingKind = PrevKind; }
1173
  };
1174
1175
  /// RAII object to mark the start of processing updates.
1176
  class ProcessingUpdatesRAIIObj {
1177
    ASTReader &Reader;
1178
    bool PrevState;
1179
1180
  public:
1181
    ProcessingUpdatesRAIIObj(ASTReader &reader)
1182
252k
        : Reader(reader), PrevState(Reader.ProcessingUpdateRecords) {
1183
252k
      Reader.ProcessingUpdateRecords = true;
1184
252k
    }
1185
1186
    ProcessingUpdatesRAIIObj(const ProcessingUpdatesRAIIObj &) = delete;
1187
    ProcessingUpdatesRAIIObj &
1188
    operator=(const ProcessingUpdatesRAIIObj &) = delete;
1189
252k
    ~ProcessingUpdatesRAIIObj() { Reader.ProcessingUpdateRecords = PrevState; }
1190
  };
1191
1192
  /// Suggested contents of the predefines buffer, after this
1193
  /// PCH file has been processed.
1194
  ///
1195
  /// In most cases, this string will be empty, because the predefines
1196
  /// buffer computed to build the PCH file will be identical to the
1197
  /// predefines buffer computed from the command line. However, when
1198
  /// there are differences that the PCH reader can work around, this
1199
  /// predefines buffer may contain additional definitions.
1200
  std::string SuggestedPredefines;
1201
1202
  llvm::DenseMap<const Decl *, bool> DefinitionSource;
1203
1204
  /// Reads a statement from the specified cursor.
1205
  Stmt *ReadStmtFromStream(ModuleFile &F);
1206
1207
  struct InputFileInfo {
1208
    std::string Filename;
1209
    off_t StoredSize;
1210
    time_t StoredTime;
1211
    bool Overridden;
1212
    bool Transient;
1213
    bool TopLevelModuleMap;
1214
  };
1215
1216
  /// Reads the stored information about an input file.
1217
  InputFileInfo readInputFileInfo(ModuleFile &F, unsigned ID);
1218
1219
  /// Retrieve the file entry and 'overridden' bit for an input
1220
  /// file in the given module file.
1221
  serialization::InputFile getInputFile(ModuleFile &F, unsigned ID,
1222
                                        bool Complain = true);
1223
1224
public:
1225
  void ResolveImportedPath(ModuleFile &M, std::string &Filename);
1226
  static void ResolveImportedPath(std::string &Filename, StringRef Prefix);
1227
1228
  /// Returns the first key declaration for the given declaration. This
1229
  /// is one that is formerly-canonical (or still canonical) and whose module
1230
  /// did not import any other key declaration of the entity.
1231
650
  Decl *getKeyDeclaration(Decl *D) {
1232
650
    D = D->getCanonicalDecl();
1233
650
    if (D->isFromASTFile())
1234
126
      return D;
1235
524
1236
524
    auto I = KeyDecls.find(D);
1237
524
    if (I == KeyDecls.end() || 
I->second.empty()40
)
1238
484
      return D;
1239
40
    return GetExistingDecl(I->second[0]);
1240
40
  }
1241
80
  const Decl *getKeyDeclaration(const Decl *D) {
1242
80
    return getKeyDeclaration(const_cast<Decl*>(D));
1243
80
  }
1244
1245
  /// Run a callback on each imported key declaration of \p D.
1246
  template <typename Fn>
1247
367
  void forEachImportedKeyDecl(const Decl *D, Fn Visit) {
1248
367
    D = D->getCanonicalDecl();
1249
367
    if (D->isFromASTFile())
1250
23
      Visit(D);
1251
367
1252
367
    auto It = KeyDecls.find(const_cast<Decl*>(D));
1253
367
    if (It != KeyDecls.end())
1254
5
      for (auto ID : It->second)
1255
11
        Visit(GetExistingDecl(ID));
1256
367
  }
ASTWriter.cpp:void clang::ASTReader::forEachImportedKeyDecl<clang::ASTWriter::ResolvedExceptionSpec(clang::FunctionDecl const*)::$_12>(clang::Decl const*, clang::ASTWriter::ResolvedExceptionSpec(clang::FunctionDecl const*)::$_12)
Line
Count
Source
1247
328
  void forEachImportedKeyDecl(const Decl *D, Fn Visit) {
1248
328
    D = D->getCanonicalDecl();
1249
328
    if (D->isFromASTFile())
1250
19
      Visit(D);
1251
328
1252
328
    auto It = KeyDecls.find(const_cast<Decl*>(D));
1253
328
    if (It != KeyDecls.end())
1254
3
      for (auto ID : It->second)
1255
9
        Visit(GetExistingDecl(ID));
1256
328
  }
ASTWriter.cpp:void clang::ASTReader::forEachImportedKeyDecl<clang::ASTWriter::DeducedReturnType(clang::FunctionDecl const*, clang::QualType)::$_13>(clang::Decl const*, clang::ASTWriter::DeducedReturnType(clang::FunctionDecl const*, clang::QualType)::$_13)
Line
Count
Source
1247
30
  void forEachImportedKeyDecl(const Decl *D, Fn Visit) {
1248
30
    D = D->getCanonicalDecl();
1249
30
    if (D->isFromASTFile())
1250
1
      Visit(D);
1251
30
1252
30
    auto It = KeyDecls.find(const_cast<Decl*>(D));
1253
30
    if (It != KeyDecls.end())
1254
0
      for (auto ID : It->second)
1255
0
        Visit(GetExistingDecl(ID));
1256
30
  }
ASTWriter.cpp:void clang::ASTReader::forEachImportedKeyDecl<clang::ASTWriter::ResolvedOperatorDelete(clang::CXXDestructorDecl const*, clang::FunctionDecl const*, clang::Expr*)::$_14>(clang::Decl const*, clang::ASTWriter::ResolvedOperatorDelete(clang::CXXDestructorDecl const*, clang::FunctionDecl const*, clang::Expr*)::$_14)
Line
Count
Source
1247
9
  void forEachImportedKeyDecl(const Decl *D, Fn Visit) {
1248
9
    D = D->getCanonicalDecl();
1249
9
    if (D->isFromASTFile())
1250
3
      Visit(D);
1251
9
1252
9
    auto It = KeyDecls.find(const_cast<Decl*>(D));
1253
9
    if (It != KeyDecls.end())
1254
2
      for (auto ID : It->second)
1255
2
        Visit(GetExistingDecl(ID));
1256
9
  }
1257
1258
  /// Get the loaded lookup tables for \p Primary, if any.
1259
  const serialization::reader::DeclContextLookupTable *
1260
  getLoadedLookupTables(DeclContext *Primary) const;
1261
1262
private:
1263
  struct ImportedModule {
1264
    ModuleFile *Mod;
1265
    ModuleFile *ImportedBy;
1266
    SourceLocation ImportLoc;
1267
1268
    ImportedModule(ModuleFile *Mod,
1269
                   ModuleFile *ImportedBy,
1270
                   SourceLocation ImportLoc)
1271
6.01k
        : Mod(Mod), ImportedBy(ImportedBy), ImportLoc(ImportLoc) {}
1272
  };
1273
1274
  ASTReadResult ReadASTCore(StringRef FileName, ModuleKind Type,
1275
                            SourceLocation ImportLoc, ModuleFile *ImportedBy,
1276
                            SmallVectorImpl<ImportedModule> &Loaded,
1277
                            off_t ExpectedSize, time_t ExpectedModTime,
1278
                            ASTFileSignature ExpectedSignature,
1279
                            unsigned ClientLoadCapabilities);
1280
  ASTReadResult ReadControlBlock(ModuleFile &F,
1281
                                 SmallVectorImpl<ImportedModule> &Loaded,
1282
                                 const ModuleFile *ImportedBy,
1283
                                 unsigned ClientLoadCapabilities);
1284
  static ASTReadResult ReadOptionsBlock(
1285
      llvm::BitstreamCursor &Stream, unsigned ClientLoadCapabilities,
1286
      bool AllowCompatibleConfigurationMismatch, ASTReaderListener &Listener,
1287
      std::string &SuggestedPredefines);
1288
1289
  /// Read the unhashed control block.
1290
  ///
1291
  /// This has no effect on \c F.Stream, instead creating a fresh cursor from
1292
  /// \c F.Data and reading ahead.
1293
  ASTReadResult readUnhashedControlBlock(ModuleFile &F, bool WasImportedBy,
1294
                                         unsigned ClientLoadCapabilities);
1295
1296
  static ASTReadResult
1297
  readUnhashedControlBlockImpl(ModuleFile *F, llvm::StringRef StreamData,
1298
                               unsigned ClientLoadCapabilities,
1299
                               bool AllowCompatibleConfigurationMismatch,
1300
                               ASTReaderListener *Listener,
1301
                               bool ValidateDiagnosticOptions);
1302
1303
  ASTReadResult ReadASTBlock(ModuleFile &F, unsigned ClientLoadCapabilities);
1304
  ASTReadResult ReadExtensionBlock(ModuleFile &F);
1305
  void ReadModuleOffsetMap(ModuleFile &F) const;
1306
  bool ParseLineTable(ModuleFile &F, const RecordData &Record);
1307
  bool ReadSourceManagerBlock(ModuleFile &F);
1308
  llvm::BitstreamCursor &SLocCursorForID(int ID);
1309
  SourceLocation getImportLocation(ModuleFile *F);
1310
  ASTReadResult ReadModuleMapFileBlock(RecordData &Record, ModuleFile &F,
1311
                                       const ModuleFile *ImportedBy,
1312
                                       unsigned ClientLoadCapabilities);
1313
  ASTReadResult ReadSubmoduleBlock(ModuleFile &F,
1314
                                   unsigned ClientLoadCapabilities);
1315
  static bool ParseLanguageOptions(const RecordData &Record, bool Complain,
1316
                                   ASTReaderListener &Listener,
1317
                                   bool AllowCompatibleDifferences);
1318
  static bool ParseTargetOptions(const RecordData &Record, bool Complain,
1319
                                 ASTReaderListener &Listener,
1320
                                 bool AllowCompatibleDifferences);
1321
  static bool ParseDiagnosticOptions(const RecordData &Record, bool Complain,
1322
                                     ASTReaderListener &Listener);
1323
  static bool ParseFileSystemOptions(const RecordData &Record, bool Complain,
1324
                                     ASTReaderListener &Listener);
1325
  static bool ParseHeaderSearchOptions(const RecordData &Record, bool Complain,
1326
                                       ASTReaderListener &Listener);
1327
  static bool ParsePreprocessorOptions(const RecordData &Record, bool Complain,
1328
                                       ASTReaderListener &Listener,
1329
                                       std::string &SuggestedPredefines);
1330
1331
  struct RecordLocation {
1332
    ModuleFile *F;
1333
    uint64_t Offset;
1334
1335
410k
    RecordLocation(ModuleFile *M, uint64_t O) : F(M), Offset(O) {}
1336
  };
1337
1338
  QualType readTypeRecord(unsigned Index);
1339
  void readExceptionSpec(ModuleFile &ModuleFile,
1340
                         SmallVectorImpl<QualType> &ExceptionStorage,
1341
                         FunctionProtoType::ExceptionSpecInfo &ESI,
1342
                         const RecordData &Record, unsigned &Index);
1343
  RecordLocation TypeCursorForIndex(unsigned Index);
1344
  void LoadedDecl(unsigned Index, Decl *D);
1345
  Decl *ReadDeclRecord(serialization::DeclID ID);
1346
  void markIncompleteDeclChain(Decl *Canon);
1347
1348
  /// Returns the most recent declaration of a declaration (which must be
1349
  /// of a redeclarable kind) that is either local or has already been loaded
1350
  /// merged into its redecl chain.
1351
  Decl *getMostRecentExistingDecl(Decl *D);
1352
1353
  RecordLocation DeclCursorForID(serialization::DeclID ID,
1354
                                 SourceLocation &Location);
1355
  void loadDeclUpdateRecords(PendingUpdateRecord &Record);
1356
  void loadPendingDeclChain(Decl *D, uint64_t LocalOffset);
1357
  void loadObjCCategories(serialization::GlobalDeclID ID, ObjCInterfaceDecl *D,
1358
                          unsigned PreviousGeneration = 0);
1359
1360
  RecordLocation getLocalBitOffset(uint64_t GlobalOffset);
1361
  uint64_t getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset);
1362
1363
  /// Returns the first preprocessed entity ID that begins or ends after
1364
  /// \arg Loc.
1365
  serialization::PreprocessedEntityID
1366
  findPreprocessedEntity(SourceLocation Loc, bool EndsAfter) const;
1367
1368
  /// Find the next module that contains entities and return the ID
1369
  /// of the first entry.
1370
  ///
1371
  /// \param SLocMapI points at a chunk of a module that contains no
1372
  /// preprocessed entities or the entities it contains are not the
1373
  /// ones we are looking for.
1374
  serialization::PreprocessedEntityID
1375
    findNextPreprocessedEntity(
1376
                        GlobalSLocOffsetMapType::const_iterator SLocMapI) const;
1377
1378
  /// Returns (ModuleFile, Local index) pair for \p GlobalIndex of a
1379
  /// preprocessed entity.
1380
  std::pair<ModuleFile *, unsigned>
1381
    getModulePreprocessedEntity(unsigned GlobalIndex);
1382
1383
  /// Returns (begin, end) pair for the preprocessed entities of a
1384
  /// particular module.
1385
  llvm::iterator_range<PreprocessingRecord::iterator>
1386
  getModulePreprocessedEntities(ModuleFile &Mod) const;
1387
1388
public:
1389
  class ModuleDeclIterator
1390
      : public llvm::iterator_adaptor_base<
1391
            ModuleDeclIterator, const serialization::LocalDeclID *,
1392
            std::random_access_iterator_tag, const Decl *, ptrdiff_t,
1393
            const Decl *, const Decl *> {
1394
    ASTReader *Reader = nullptr;
1395
    ModuleFile *Mod = nullptr;
1396
1397
  public:
1398
    ModuleDeclIterator() : iterator_adaptor_base(nullptr) {}
1399
1400
    ModuleDeclIterator(ASTReader *Reader, ModuleFile *Mod,
1401
                       const serialization::LocalDeclID *Pos)
1402
22
        : iterator_adaptor_base(Pos), Reader(Reader), Mod(Mod) {}
1403
1404
67
    value_type operator*() const {
1405
67
      return Reader->GetDecl(Reader->getGlobalDeclID(*Mod, *I));
1406
67
    }
1407
1408
0
    value_type operator->() const { return **this; }
1409
1410
78
    bool operator==(const ModuleDeclIterator &RHS) const {
1411
78
      assert(Reader == RHS.Reader && Mod == RHS.Mod);
1412
78
      return I == RHS.I;
1413
78
    }
1414
  };
1415
1416
  llvm::iterator_range<ModuleDeclIterator>
1417
  getModuleFileLevelDecls(ModuleFile &Mod);
1418
1419
private:
1420
  void PassInterestingDeclsToConsumer();
1421
  void PassInterestingDeclToConsumer(Decl *D);
1422
1423
  void finishPendingActions();
1424
  void diagnoseOdrViolations();
1425
1426
  void pushExternalDeclIntoScope(NamedDecl *D, DeclarationName Name);
1427
1428
  void addPendingDeclContextInfo(Decl *D,
1429
                                 serialization::GlobalDeclID SemaDC,
1430
22.2k
                                 serialization::GlobalDeclID LexicalDC) {
1431
22.2k
    assert(D);
1432
22.2k
    PendingDeclContextInfo Info = { D, SemaDC, LexicalDC };
1433
22.2k
    PendingDeclContextInfos.push_back(Info);
1434
22.2k
  }
1435
1436
  /// Produce an error diagnostic and return true.
1437
  ///
1438
  /// This routine should only be used for fatal errors that have to
1439
  /// do with non-routine failures (e.g., corrupted AST file).
1440
  void Error(StringRef Msg) const;
1441
  void Error(unsigned DiagID, StringRef Arg1 = StringRef(),
1442
             StringRef Arg2 = StringRef()) const;
1443
1444
public:
1445
  /// Load the AST file and validate its contents against the given
1446
  /// Preprocessor.
1447
  ///
1448
  /// \param PP the preprocessor associated with the context in which this
1449
  /// precompiled header will be loaded.
1450
  ///
1451
  /// \param Context the AST context that this precompiled header will be
1452
  /// loaded into, if any.
1453
  ///
1454
  /// \param PCHContainerRdr the PCHContainerOperations to use for loading and
1455
  /// creating modules.
1456
  ///
1457
  /// \param Extensions the list of module file extensions that can be loaded
1458
  /// from the AST files.
1459
  ///
1460
  /// \param isysroot If non-NULL, the system include path specified by the
1461
  /// user. This is only used with relocatable PCH files. If non-NULL,
1462
  /// a relocatable PCH file will use the default path "/".
1463
  ///
1464
  /// \param DisableValidation If true, the AST reader will suppress most
1465
  /// of its regular consistency checking, allowing the use of precompiled
1466
  /// headers that cannot be determined to be compatible.
1467
  ///
1468
  /// \param AllowASTWithCompilerErrors If true, the AST reader will accept an
1469
  /// AST file the was created out of an AST with compiler errors,
1470
  /// otherwise it will reject it.
1471
  ///
1472
  /// \param AllowConfigurationMismatch If true, the AST reader will not check
1473
  /// for configuration differences between the AST file and the invocation.
1474
  ///
1475
  /// \param ValidateSystemInputs If true, the AST reader will validate
1476
  /// system input files in addition to user input files. This is only
1477
  /// meaningful if \p DisableValidation is false.
1478
  ///
1479
  /// \param UseGlobalIndex If true, the AST reader will try to load and use
1480
  /// the global module index.
1481
  ///
1482
  /// \param ReadTimer If non-null, a timer used to track the time spent
1483
  /// deserializing.
1484
  ASTReader(Preprocessor &PP, ASTContext *Context,
1485
            const PCHContainerReader &PCHContainerRdr,
1486
            ArrayRef<std::shared_ptr<ModuleFileExtension>> Extensions,
1487
            StringRef isysroot = "", bool DisableValidation = false,
1488
            bool AllowASTWithCompilerErrors = false,
1489
            bool AllowConfigurationMismatch = false,
1490
            bool ValidateSystemInputs = false, bool UseGlobalIndex = true,
1491
            std::unique_ptr<llvm::Timer> ReadTimer = {});
1492
  ASTReader(const ASTReader &) = delete;
1493
  ASTReader &operator=(const ASTReader &) = delete;
1494
  ~ASTReader() override;
1495
1496
122k
  SourceManager &getSourceManager() const { return SourceMgr; }
1497
14.9k
  FileManager &getFileManager() const { return FileMgr; }
1498
2
  DiagnosticsEngine &getDiags() const { return Diags; }
1499
1500
  /// Flags that indicate what kind of AST loading failures the client
1501
  /// of the AST reader can directly handle.
1502
  ///
1503
  /// When a client states that it can handle a particular kind of failure,
1504
  /// the AST reader will not emit errors when producing that kind of failure.
1505
  enum LoadFailureCapabilities {
1506
    /// The client can't handle any AST loading failures.
1507
    ARR_None = 0,
1508
1509
    /// The client can handle an AST file that cannot load because it
1510
    /// is missing.
1511
    ARR_Missing = 0x1,
1512
1513
    /// The client can handle an AST file that cannot load because it
1514
    /// is out-of-date relative to its input files.
1515
    ARR_OutOfDate = 0x2,
1516
1517
    /// The client can handle an AST file that cannot load because it
1518
    /// was built with a different version of Clang.
1519
    ARR_VersionMismatch = 0x4,
1520
1521
    /// The client can handle an AST file that cannot load because it's
1522
    /// compiled configuration doesn't match that of the context it was
1523
    /// loaded into.
1524
    ARR_ConfigurationMismatch = 0x8
1525
  };
1526
1527
  /// Load the AST file designated by the given file name.
1528
  ///
1529
  /// \param FileName The name of the AST file to load.
1530
  ///
1531
  /// \param Type The kind of AST being loaded, e.g., PCH, module, main file,
1532
  /// or preamble.
1533
  ///
1534
  /// \param ImportLoc the location where the module file will be considered as
1535
  /// imported from. For non-module AST types it should be invalid.
1536
  ///
1537
  /// \param ClientLoadCapabilities The set of client load-failure
1538
  /// capabilities, represented as a bitset of the enumerators of
1539
  /// LoadFailureCapabilities.
1540
  ///
1541
  /// \param Imported optional out-parameter to append the list of modules
1542
  /// that were imported by precompiled headers or any other non-module AST file
1543
  ASTReadResult ReadAST(StringRef FileName, ModuleKind Type,
1544
                        SourceLocation ImportLoc,
1545
                        unsigned ClientLoadCapabilities,
1546
                        SmallVectorImpl<ImportedSubmodule> *Imported = nullptr);
1547
1548
  /// Make the entities in the given module and any of its (non-explicit)
1549
  /// submodules visible to name lookup.
1550
  ///
1551
  /// \param Mod The module whose names should be made visible.
1552
  ///
1553
  /// \param NameVisibility The level of visibility to give the names in the
1554
  /// module.  Visibility can only be increased over time.
1555
  ///
1556
  /// \param ImportLoc The location at which the import occurs.
1557
  void makeModuleVisible(Module *Mod,
1558
                         Module::NameVisibilityKind NameVisibility,
1559
                         SourceLocation ImportLoc);
1560
1561
  /// Make the names within this set of hidden names visible.
1562
  void makeNamesVisible(const HiddenNames &Names, Module *Owner);
1563
1564
  /// Note that MergedDef is a redefinition of the canonical definition
1565
  /// Def, so Def should be visible whenever MergedDef is.
1566
  void mergeDefinitionVisibility(NamedDecl *Def, NamedDecl *MergedDef);
1567
1568
  /// Take the AST callbacks listener.
1569
774
  std::unique_ptr<ASTReaderListener> takeListener() {
1570
774
    return std::move(Listener);
1571
774
  }
1572
1573
  /// Set the AST callbacks listener.
1574
905
  void setListener(std::unique_ptr<ASTReaderListener> Listener) {
1575
905
    this->Listener = std::move(Listener);
1576
905
  }
1577
1578
  /// Add an AST callback listener.
1579
  ///
1580
  /// Takes ownership of \p L.
1581
78
  void addListener(std::unique_ptr<ASTReaderListener> L) {
1582
78
    if (Listener)
1583
78
      L = llvm::make_unique<ChainedASTReaderListener>(std::move(L),
1584
78
                                                      std::move(Listener));
1585
78
    Listener = std::move(L);
1586
78
  }
1587
1588
  /// RAII object to temporarily add an AST callback listener.
1589
  class ListenerScope {
1590
    ASTReader &Reader;
1591
    bool Chained = false;
1592
1593
  public:
1594
    ListenerScope(ASTReader &Reader, std::unique_ptr<ASTReaderListener> L)
1595
387
        : Reader(Reader) {
1596
387
      auto Old = Reader.takeListener();
1597
387
      if (Old) {
1598
387
        Chained = true;
1599
387
        L = llvm::make_unique<ChainedASTReaderListener>(std::move(L),
1600
387
                                                        std::move(Old));
1601
387
      }
1602
387
      Reader.setListener(std::move(L));
1603
387
    }
1604
1605
387
    ~ListenerScope() {
1606
387
      auto New = Reader.takeListener();
1607
387
      if (Chained)
1608
387
        Reader.setListener(static_cast<ChainedASTReaderListener *>(New.get())
1609
387
                               ->takeSecond());
1610
387
    }
1611
  };
1612
1613
  /// Set the AST deserialization listener.
1614
  void setDeserializationListener(ASTDeserializationListener *Listener,
1615
                                  bool TakeOwnership = false);
1616
1617
  /// Get the AST deserialization listener.
1618
0
  ASTDeserializationListener *getDeserializationListener() {
1619
0
    return DeserializationListener;
1620
0
  }
1621
1622
  /// Determine whether this AST reader has a global index.
1623
1.94k
  bool hasGlobalIndex() const { return (bool)GlobalIndex; }
1624
1625
  /// Return global module index.
1626
3
  GlobalModuleIndex *getGlobalIndex() { return GlobalIndex.get(); }
1627
1628
  /// Reset reader for a reload try.
1629
2
  void resetForReload() { TriedLoadingGlobalIndex = false; }
1630
1631
  /// Attempts to load the global index.
1632
  ///
1633
  /// \returns true if loading the global index has failed for any reason.
1634
  bool loadGlobalIndex();
1635
1636
  /// Determine whether we tried to load the global index, but failed,
1637
  /// e.g., because it is out-of-date or does not exist.
1638
  bool isGlobalIndexUnavailable() const;
1639
1640
  /// Initializes the ASTContext
1641
  void InitializeContext();
1642
1643
  /// Update the state of Sema after loading some additional modules.
1644
  void UpdateSema();
1645
1646
  /// Add in-memory (virtual file) buffer.
1647
  void addInMemoryBuffer(StringRef &FileName,
1648
66
                         std::unique_ptr<llvm::MemoryBuffer> Buffer) {
1649
66
    ModuleMgr.addInMemoryBuffer(FileName, std::move(Buffer));
1650
66
  }
1651
1652
  /// Finalizes the AST reader's state before writing an AST file to
1653
  /// disk.
1654
  ///
1655
  /// This operation may undo temporary state in the AST that should not be
1656
  /// emitted.
1657
  void finalizeForWriting();
1658
1659
  /// Retrieve the module manager.
1660
5.20k
  ModuleManager &getModuleManager() { return ModuleMgr; }
1661
1662
  /// Retrieve the preprocessor.
1663
442k
  Preprocessor &getPreprocessor() const { return PP; }
1664
1665
  /// Retrieve the name of the original source file name for the primary
1666
  /// module file.
1667
130
  StringRef getOriginalSourceFile() {
1668
130
    return ModuleMgr.getPrimaryModule().OriginalSourceFileName;
1669
130
  }
1670
1671
  /// Retrieve the name of the original source file name directly from
1672
  /// the AST file, without actually loading the AST file.
1673
  static std::string
1674
  getOriginalSourceFile(const std::string &ASTFileName, FileManager &FileMgr,
1675
                        const PCHContainerReader &PCHContainerRdr,
1676
                        DiagnosticsEngine &Diags);
1677
1678
  /// Read the control block for the named AST file.
1679
  ///
1680
  /// \returns true if an error occurred, false otherwise.
1681
  static bool
1682
  readASTFileControlBlock(StringRef Filename, FileManager &FileMgr,
1683
                          const PCHContainerReader &PCHContainerRdr,
1684
                          bool FindModuleFileExtensions,
1685
                          ASTReaderListener &Listener,
1686
                          bool ValidateDiagnosticOptions);
1687
1688
  /// Determine whether the given AST file is acceptable to load into a
1689
  /// translation unit with the given language and target options.
1690
  static bool isAcceptableASTFile(StringRef Filename, FileManager &FileMgr,
1691
                                  const PCHContainerReader &PCHContainerRdr,
1692
                                  const LangOptions &LangOpts,
1693
                                  const TargetOptions &TargetOpts,
1694
                                  const PreprocessorOptions &PPOpts,
1695
                                  StringRef ExistingModuleCachePath);
1696
1697
  /// Returns the suggested contents of the predefines buffer,
1698
  /// which contains a (typically-empty) subset of the predefines
1699
  /// build prior to including the precompiled header.
1700
2.35k
  const std::string &getSuggestedPredefines() { return SuggestedPredefines; }
1701
1702
  /// Read a preallocated preprocessed entity from the external source.
1703
  ///
1704
  /// \returns null if an error occurred that prevented the preprocessed
1705
  /// entity from being loaded.
1706
  PreprocessedEntity *ReadPreprocessedEntity(unsigned Index) override;
1707
1708
  /// Returns a pair of [Begin, End) indices of preallocated
1709
  /// preprocessed entities that \p Range encompasses.
1710
  std::pair<unsigned, unsigned>
1711
      findPreprocessedEntitiesInRange(SourceRange Range) override;
1712
1713
  /// Optionally returns true or false if the preallocated preprocessed
1714
  /// entity with index \p Index came from file \p FID.
1715
  Optional<bool> isPreprocessedEntityInFileID(unsigned Index,
1716
                                              FileID FID) override;
1717
1718
  /// Read a preallocated skipped range from the external source.
1719
  SourceRange ReadSkippedRange(unsigned Index) override;
1720
1721
  /// Read the header file information for the given file entry.
1722
  HeaderFileInfo GetHeaderFileInfo(const FileEntry *FE) override;
1723
1724
  void ReadPragmaDiagnosticMappings(DiagnosticsEngine &Diag);
1725
1726
  /// Returns the number of source locations found in the chain.
1727
12.0k
  unsigned getTotalNumSLocs() const {
1728
12.0k
    return TotalNumSLocEntries;
1729
12.0k
  }
1730
1731
  /// Returns the number of identifiers found in the chain.
1732
13.3k
  unsigned getTotalNumIdentifiers() const {
1733
13.3k
    return static_cast<unsigned>(IdentifiersLoaded.size());
1734
13.3k
  }
1735
1736
  /// Returns the number of macros found in the chain.
1737
11.9k
  unsigned getTotalNumMacros() const {
1738
11.9k
    return static_cast<unsigned>(MacrosLoaded.size());
1739
11.9k
  }
1740
1741
  /// Returns the number of types found in the chain.
1742
14.1k
  unsigned getTotalNumTypes() const {
1743
14.1k
    return static_cast<unsigned>(TypesLoaded.size());
1744
14.1k
  }
1745
1746
  /// Returns the number of declarations found in the chain.
1747
14.0k
  unsigned getTotalNumDecls() const {
1748
14.0k
    return static_cast<unsigned>(DeclsLoaded.size());
1749
14.0k
  }
1750
1751
  /// Returns the number of submodules known.
1752
9.19k
  unsigned getTotalNumSubmodules() const {
1753
9.19k
    return static_cast<unsigned>(SubmodulesLoaded.size());
1754
9.19k
  }
1755
1756
  /// Returns the number of selectors found in the chain.
1757
2.94k
  unsigned getTotalNumSelectors() const {
1758
2.94k
    return static_cast<unsigned>(SelectorsLoaded.size());
1759
2.94k
  }
1760
1761
  /// Returns the number of preprocessed entities known to the AST
1762
  /// reader.
1763
457
  unsigned getTotalNumPreprocessedEntities() const {
1764
457
    unsigned Result = 0;
1765
457
    for (const auto &M : ModuleMgr)
1766
470
      Result += M.NumPreprocessedEntities;
1767
457
    return Result;
1768
457
  }
1769
1770
  /// Reads a TemplateArgumentLocInfo appropriate for the
1771
  /// given TemplateArgument kind.
1772
  TemplateArgumentLocInfo
1773
  GetTemplateArgumentLocInfo(ModuleFile &F, TemplateArgument::ArgKind Kind,
1774
                             const RecordData &Record, unsigned &Idx);
1775
1776
  /// Reads a TemplateArgumentLoc.
1777
  TemplateArgumentLoc
1778
  ReadTemplateArgumentLoc(ModuleFile &F,
1779
                          const RecordData &Record, unsigned &Idx);
1780
1781
  const ASTTemplateArgumentListInfo*
1782
  ReadASTTemplateArgumentListInfo(ModuleFile &F,
1783
                                  const RecordData &Record, unsigned &Index);
1784
1785
  /// Reads a declarator info from the given record.
1786
  TypeSourceInfo *GetTypeSourceInfo(ModuleFile &F,
1787
                                    const RecordData &Record, unsigned &Idx);
1788
1789
  /// Raad the type locations for the given TInfo.
1790
  void ReadTypeLoc(ModuleFile &F, const RecordData &Record, unsigned &Idx,
1791
                   TypeLoc TL);
1792
1793
  /// Resolve a type ID into a type, potentially building a new
1794
  /// type.
1795
  QualType GetType(serialization::TypeID ID);
1796
1797
  /// Resolve a local type ID within a given AST file into a type.
1798
  QualType getLocalType(ModuleFile &F, unsigned LocalID);
1799
1800
  /// Map a local type ID within a given AST file into a global type ID.
1801
  serialization::TypeID getGlobalTypeID(ModuleFile &F, unsigned LocalID) const;
1802
1803
  /// Read a type from the current position in the given record, which
1804
  /// was read from the given AST file.
1805
991k
  QualType readType(ModuleFile &F, const RecordData &Record, unsigned &Idx) {
1806
991k
    if (Idx >= Record.size())
1807
0
      return {};
1808
991k
1809
991k
    return getLocalType(F, Record[Idx++]);
1810
991k
  }
1811
1812
  /// Map from a local declaration ID within a given module to a
1813
  /// global declaration ID.
1814
  serialization::DeclID getGlobalDeclID(ModuleFile &F,
1815
                                      serialization::LocalDeclID LocalID) const;
1816
1817
  /// Returns true if global DeclID \p ID originated from module \p M.
1818
  bool isDeclIDFromModule(serialization::GlobalDeclID ID, ModuleFile &M) const;
1819
1820
  /// Retrieve the module file that owns the given declaration, or NULL
1821
  /// if the declaration is not from a module file.
1822
  ModuleFile *getOwningModuleFile(const Decl *D);
1823
1824
  /// Get the best name we know for the module that owns the given
1825
  /// declaration, or an empty string if the declaration is not from a module.
1826
  std::string getOwningModuleNameForDiagnostic(const Decl *D);
1827
1828
  /// Returns the source location for the decl \p ID.
1829
  SourceLocation getSourceLocationForDeclID(serialization::GlobalDeclID ID);
1830
1831
  /// Resolve a declaration ID into a declaration, potentially
1832
  /// building a new declaration.
1833
  Decl *GetDecl(serialization::DeclID ID);
1834
  Decl *GetExternalDecl(uint32_t ID) override;
1835
1836
  /// Resolve a declaration ID into a declaration. Return 0 if it's not
1837
  /// been loaded yet.
1838
  Decl *GetExistingDecl(serialization::DeclID ID);
1839
1840
  /// Reads a declaration with the given local ID in the given module.
1841
34.3k
  Decl *GetLocalDecl(ModuleFile &F, uint32_t LocalID) {
1842
34.3k
    return GetDecl(getGlobalDeclID(F, LocalID));
1843
34.3k
  }
1844
1845
  /// Reads a declaration with the given local ID in the given module.
1846
  ///
1847
  /// \returns The requested declaration, casted to the given return type.
1848
  template<typename T>
1849
83
  T *GetLocalDeclAs(ModuleFile &F, uint32_t LocalID) {
1850
83
    return cast_or_null<T>(GetLocalDecl(F, LocalID));
1851
83
  }
1852
1853
  /// Map a global declaration ID into the declaration ID used to
1854
  /// refer to this declaration within the given module fule.
1855
  ///
1856
  /// \returns the global ID of the given declaration as known in the given
1857
  /// module file.
1858
  serialization::DeclID
1859
  mapGlobalIDToModuleFileGlobalID(ModuleFile &M,
1860
                                  serialization::DeclID GlobalID);
1861
1862
  /// Reads a declaration ID from the given position in a record in the
1863
  /// given module.
1864
  ///
1865
  /// \returns The declaration ID read from the record, adjusted to a global ID.
1866
  serialization::DeclID ReadDeclID(ModuleFile &F, const RecordData &Record,
1867
                                   unsigned &Idx);
1868
1869
  /// Reads a declaration from the given position in a record in the
1870
  /// given module.
1871
62.9k
  Decl *ReadDecl(ModuleFile &F, const RecordData &R, unsigned &I) {
1872
62.9k
    return GetDecl(ReadDeclID(F, R, I));
1873
62.9k
  }
1874
1875
  /// Reads a declaration from the given position in a record in the
1876
  /// given module.
1877
  ///
1878
  /// \returns The declaration read from this location, casted to the given
1879
  /// result type.
1880
  template<typename T>
1881
904k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
904k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
904k
  }
clang::UnresolvedUsingTypenameDecl* clang::ASTReader::ReadDeclAs<clang::UnresolvedUsingTypenameDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
3
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
3
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
3
  }
clang::TypedefNameDecl* clang::ASTReader::ReadDeclAs<clang::TypedefNameDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
12.5k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
12.5k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
12.5k
  }
clang::RecordDecl* clang::ASTReader::ReadDeclAs<clang::RecordDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
71.0k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
71.0k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
71.0k
  }
clang::EnumDecl* clang::ASTReader::ReadDeclAs<clang::EnumDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
760
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
760
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
760
  }
clang::TagDecl* clang::ASTReader::ReadDeclAs<clang::TagDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
1.10k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
1.10k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
1.10k
  }
clang::ObjCInterfaceDecl* clang::ASTReader::ReadDeclAs<clang::ObjCInterfaceDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
585
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
585
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
585
  }
clang::ObjCTypeParamDecl* clang::ASTReader::ReadDeclAs<clang::ObjCTypeParamDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
40
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
40
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
40
  }
clang::ObjCProtocolDecl* clang::ASTReader::ReadDeclAs<clang::ObjCProtocolDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
56
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
56
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
56
  }
clang::CXXRecordDecl* clang::ASTReader::ReadDeclAs<clang::CXXRecordDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
2.25k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
2.25k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
2.25k
  }
clang::TemplateTypeParmDecl* clang::ASTReader::ReadDeclAs<clang::TemplateTypeParmDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
6.79k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
6.79k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
6.79k
  }
clang::FunctionDecl* clang::ASTReader::ReadDeclAs<clang::FunctionDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
7.09k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
7.09k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
7.09k
  }
clang::ParmVarDecl* clang::ASTReader::ReadDeclAs<clang::ParmVarDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
28.0k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
28.0k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
28.0k
  }
clang::TemplateDecl* clang::ASTReader::ReadDeclAs<clang::TemplateDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
9.66k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
9.66k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
9.66k
  }
clang::NamedDecl* clang::ASTReader::ReadDeclAs<clang::NamedDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
14.0k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
14.0k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
14.0k
  }
clang::TemplateTemplateParmDecl* clang::ASTReader::ReadDeclAs<clang::TemplateTemplateParmDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
8
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
8
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
8
  }
clang::ValueDecl* clang::ASTReader::ReadDeclAs<clang::ValueDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
150k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
150k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
150k
  }
clang::FieldDecl* clang::ASTReader::ReadDeclAs<clang::FieldDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
9.39k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
9.39k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
9.39k
  }
clang::IndirectFieldDecl* clang::ASTReader::ReadDeclAs<clang::IndirectFieldDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
2
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
2
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
2
  }
clang::NamespaceDecl* clang::ASTReader::ReadDeclAs<clang::NamespaceDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
335
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
335
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
335
  }
clang::NamespaceAliasDecl* clang::ASTReader::ReadDeclAs<clang::NamespaceAliasDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
9
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
9
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
9
  }
clang::CXXDestructorDecl* clang::ASTReader::ReadDeclAs<clang::CXXDestructorDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
1.10k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
1.10k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
1.10k
  }
clang::DeclContext* clang::ASTReader::ReadDeclAs<clang::DeclContext>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
451k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
451k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
451k
  }
clang::TypeAliasTemplateDecl* clang::ASTReader::ReadDeclAs<clang::TypeAliasTemplateDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
202
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
202
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
202
  }
clang::FunctionTemplateDecl* clang::ASTReader::ReadDeclAs<clang::FunctionTemplateDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
3.75k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
3.75k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
3.75k
  }
clang::ImplicitParamDecl* clang::ASTReader::ReadDeclAs<clang::ImplicitParamDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
65.0k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
65.0k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
65.0k
  }
clang::ObjCMethodDecl* clang::ASTReader::ReadDeclAs<clang::ObjCMethodDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
158
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
158
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
158
  }
clang::ObjCIvarDecl* clang::ASTReader::ReadDeclAs<clang::ObjCIvarDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
59
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
59
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
59
  }
clang::ObjCPropertyDecl* clang::ASTReader::ReadDeclAs<clang::ObjCPropertyDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
10
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
10
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
10
  }
clang::VarTemplateDecl* clang::ASTReader::ReadDeclAs<clang::VarTemplateDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
253
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
253
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
253
  }
clang::VarDecl* clang::ASTReader::ReadDeclAs<clang::VarDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
31.4k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
31.4k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
31.4k
  }
clang::BindingDecl* clang::ASTReader::ReadDeclAs<clang::BindingDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
4
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
4
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
4
  }
clang::UsingShadowDecl* clang::ASTReader::ReadDeclAs<clang::UsingShadowDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
643
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
643
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
643
  }
clang::ConstructorUsingShadowDecl* clang::ASTReader::ReadDeclAs<clang::ConstructorUsingShadowDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
124
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
124
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
124
  }
clang::ClassTemplateDecl* clang::ASTReader::ReadDeclAs<clang::ClassTemplateDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
7.57k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
7.57k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
7.57k
  }
clang::CXXMethodDecl* clang::ASTReader::ReadDeclAs<clang::CXXMethodDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
20
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
20
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
20
  }
clang::CXXConstructorDecl* clang::ASTReader::ReadDeclAs<clang::CXXConstructorDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
4.98k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
4.98k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
4.98k
  }
clang::RedeclarableTemplateDecl* clang::ASTReader::ReadDeclAs<clang::RedeclarableTemplateDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
3.75k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
3.75k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
3.75k
  }
clang::ClassTemplatePartialSpecializationDecl* clang::ASTReader::ReadDeclAs<clang::ClassTemplatePartialSpecializationDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
160
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
160
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
160
  }
clang::VarTemplatePartialSpecializationDecl* clang::ASTReader::ReadDeclAs<clang::VarTemplatePartialSpecializationDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
10
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
10
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
10
  }
clang::LabelDecl* clang::ASTReader::ReadDeclAs<clang::LabelDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
8
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
8
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
8
  }
clang::CapturedDecl* clang::ASTReader::ReadDeclAs<clang::CapturedDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
19.0k
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
19.0k
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
19.0k
  }
clang::BlockDecl* clang::ASTReader::ReadDeclAs<clang::BlockDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
14
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
14
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
14
  }
clang::NonTypeTemplateParmDecl* clang::ASTReader::ReadDeclAs<clang::NonTypeTemplateParmDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
346
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
346
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
346
  }
clang::MSPropertyDecl* clang::ASTReader::ReadDeclAs<clang::MSPropertyDecl>(clang::serialization::ModuleFile&, llvm::SmallVector<unsigned long long, 64u> const&, unsigned int&)
Line
Count
Source
1881
22
  T *ReadDeclAs(ModuleFile &F, const RecordData &R, unsigned &I) {
1882
22
    return cast_or_null<T>(GetDecl(ReadDeclID(F, R, I)));
1883
22
  }
1884
1885
  /// If any redeclarations of \p D have been imported since it was
1886
  /// last checked, this digs out those redeclarations and adds them to the
1887
  /// redeclaration chain for \p D.
1888
  void CompleteRedeclChain(const Decl *D) override;
1889
1890
  CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset) override;
1891
1892
  /// Resolve the offset of a statement into a statement.
1893
  ///
1894
  /// This operation will read a new statement from the external
1895
  /// source each time it is called, and is meant to be used via a
1896
  /// LazyOffsetPtr (which is used by Decls for the body of functions, etc).
1897
  Stmt *GetExternalDeclStmt(uint64_t Offset) override;
1898
1899
  /// ReadBlockAbbrevs - Enter a subblock of the specified BlockID with the
1900
  /// specified cursor.  Read the abbreviations that are at the top of the block
1901
  /// and then leave the cursor pointing into the block.
1902
  static bool ReadBlockAbbrevs(llvm::BitstreamCursor &Cursor, unsigned BlockID);
1903
1904
  /// Finds all the visible declarations with a given name.
1905
  /// The current implementation of this method just loads the entire
1906
  /// lookup table as unmaterialized references.
1907
  bool FindExternalVisibleDeclsByName(const DeclContext *DC,
1908
                                      DeclarationName Name) override;
1909
1910
  /// Read all of the declarations lexically stored in a
1911
  /// declaration context.
1912
  ///
1913
  /// \param DC The declaration context whose declarations will be
1914
  /// read.
1915
  ///
1916
  /// \param IsKindWeWant A predicate indicating which declaration kinds
1917
  /// we are interested in.
1918
  ///
1919
  /// \param Decls Vector that will contain the declarations loaded
1920
  /// from the external source. The caller is responsible for merging
1921
  /// these declarations with any declarations already stored in the
1922
  /// declaration context.
1923
  void
1924
  FindExternalLexicalDecls(const DeclContext *DC,
1925
                           llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
1926
                           SmallVectorImpl<Decl *> &Decls) override;
1927
1928
  /// Get the decls that are contained in a file in the Offset/Length
1929
  /// range. \p Length can be 0 to indicate a point at \p Offset instead of
1930
  /// a range.
1931
  void FindFileRegionDecls(FileID File, unsigned Offset, unsigned Length,
1932
                           SmallVectorImpl<Decl *> &Decls) override;
1933
1934
  /// Notify ASTReader that we started deserialization of
1935
  /// a decl or type so until FinishedDeserializing is called there may be
1936
  /// decls that are initializing. Must be paired with FinishedDeserializing.
1937
  void StartedDeserializing() override;
1938
1939
  /// Notify ASTReader that we finished the deserialization of
1940
  /// a decl or type. Must be paired with StartedDeserializing.
1941
  void FinishedDeserializing() override;
1942
1943
  /// Function that will be invoked when we begin parsing a new
1944
  /// translation unit involving this external AST source.
1945
  ///
1946
  /// This function will provide all of the external definitions to
1947
  /// the ASTConsumer.
1948
  void StartTranslationUnit(ASTConsumer *Consumer) override;
1949
1950
  /// Print some statistics about AST usage.
1951
  void PrintStats() override;
1952
1953
  /// Dump information about the AST reader to standard error.
1954
  void dump();
1955
1956
  /// Return the amount of memory used by memory buffers, breaking down
1957
  /// by heap-backed versus mmap'ed memory.
1958
  void getMemoryBufferSizes(MemoryBufferSizes &sizes) const override;
1959
1960
  /// Initialize the semantic source with the Sema instance
1961
  /// being used to perform semantic analysis on the abstract syntax
1962
  /// tree.
1963
  void InitializeSema(Sema &S) override;
1964
1965
  /// Inform the semantic consumer that Sema is no longer available.
1966
4.88k
  void ForgetSema() override { SemaObj = nullptr; }
1967
1968
  /// Retrieve the IdentifierInfo for the named identifier.
1969
  ///
1970
  /// This routine builds a new IdentifierInfo for the given identifier. If any
1971
  /// declarations with this name are visible from translation unit scope, their
1972
  /// declarations will be deserialized and introduced into the declaration
1973
  /// chain of the identifier.
1974
  IdentifierInfo *get(StringRef Name) override;
1975
1976
  /// Retrieve an iterator into the set of all identifiers
1977
  /// in all loaded AST files.
1978
  IdentifierIterator *getIdentifiers() override;
1979
1980
  /// Load the contents of the global method pool for a given
1981
  /// selector.
1982
  void ReadMethodPool(Selector Sel) override;
1983
1984
  /// Load the contents of the global method pool for a given
1985
  /// selector if necessary.
1986
  void updateOutOfDateSelector(Selector Sel) override;
1987
1988
  /// Load the set of namespaces that are known to the external source,
1989
  /// which will be used during typo correction.
1990
  void ReadKnownNamespaces(
1991
                         SmallVectorImpl<NamespaceDecl *> &Namespaces) override;
1992
1993
  void ReadUndefinedButUsed(
1994
      llvm::MapVector<NamedDecl *, SourceLocation> &Undefined) override;
1995
1996
  void ReadMismatchingDeleteExpressions(llvm::MapVector<
1997
      FieldDecl *, llvm::SmallVector<std::pair<SourceLocation, bool>, 4>> &
1998
                                            Exprs) override;
1999
2000
  void ReadTentativeDefinitions(
2001
                            SmallVectorImpl<VarDecl *> &TentativeDefs) override;
2002
2003
  void ReadUnusedFileScopedDecls(
2004
                       SmallVectorImpl<const DeclaratorDecl *> &Decls) override;
2005
2006
  void ReadDelegatingConstructors(
2007
                         SmallVectorImpl<CXXConstructorDecl *> &Decls) override;
2008
2009
  void ReadExtVectorDecls(SmallVectorImpl<TypedefNameDecl *> &Decls) override;
2010
2011
  void ReadUnusedLocalTypedefNameCandidates(
2012
      llvm::SmallSetVector<const TypedefNameDecl *, 4> &Decls) override;
2013
2014
  void ReadReferencedSelectors(
2015
           SmallVectorImpl<std::pair<Selector, SourceLocation>> &Sels) override;
2016
2017
  void ReadWeakUndeclaredIdentifiers(
2018
           SmallVectorImpl<std::pair<IdentifierInfo *, WeakInfo>> &WI) override;
2019
2020
  void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) override;
2021
2022
  void ReadPendingInstantiations(
2023
                  SmallVectorImpl<std::pair<ValueDecl *,
2024
                                            SourceLocation>> &Pending) override;
2025
2026
  void ReadLateParsedTemplates(
2027
      llvm::MapVector<const FunctionDecl *, std::unique_ptr<LateParsedTemplate>>
2028
          &LPTMap) override;
2029
2030
  /// Load a selector from disk, registering its ID if it exists.
2031
  void LoadSelector(Selector Sel);
2032
2033
  void SetIdentifierInfo(unsigned ID, IdentifierInfo *II);
2034
  void SetGloballyVisibleDecls(IdentifierInfo *II,
2035
                               const SmallVectorImpl<uint32_t> &DeclIDs,
2036
                               SmallVectorImpl<Decl *> *Decls = nullptr);
2037
2038
  /// Report a diagnostic.
2039
  DiagnosticBuilder Diag(unsigned DiagID) const;
2040
2041
  /// Report a diagnostic.
2042
  DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const;
2043
2044
  IdentifierInfo *DecodeIdentifierInfo(serialization::IdentifierID ID);
2045
2046
  IdentifierInfo *GetIdentifierInfo(ModuleFile &M, const RecordData &Record,
2047
220k
                                    unsigned &Idx) {
2048
220k
    return DecodeIdentifierInfo(getGlobalIdentifierID(M, Record[Idx++]));
2049
220k
  }
2050
2051
65
  IdentifierInfo *GetIdentifier(serialization::IdentifierID ID) override {
2052
65
    // Note that we are loading an identifier.
2053
65
    Deserializing AnIdentifier(this);
2054
65
2055
65
    return DecodeIdentifierInfo(ID);
2056
65
  }
2057
2058
  IdentifierInfo *getLocalIdentifier(ModuleFile &M, unsigned LocalID);
2059
2060
  serialization::IdentifierID getGlobalIdentifierID(ModuleFile &M,
2061
                                                    unsigned LocalID);
2062
2063
  void resolvePendingMacro(IdentifierInfo *II, const PendingMacroInfo &PMInfo);
2064
2065
  /// Retrieve the macro with the given ID.
2066
  MacroInfo *getMacro(serialization::MacroID ID);
2067
2068
  /// Retrieve the global macro ID corresponding to the given local
2069
  /// ID within the given module file.
2070
  serialization::MacroID getGlobalMacroID(ModuleFile &M, unsigned LocalID);
2071
2072
  /// Read the source location entry with index ID.
2073
  bool ReadSLocEntry(int ID) override;
2074
2075
  /// Retrieve the module import location and module name for the
2076
  /// given source manager entry ID.
2077
  std::pair<SourceLocation, StringRef> getModuleImportLoc(int ID) override;
2078
2079
  /// Retrieve the global submodule ID given a module and its local ID
2080
  /// number.
2081
  serialization::SubmoduleID
2082
  getGlobalSubmoduleID(ModuleFile &M, unsigned LocalID);
2083
2084
  /// Retrieve the submodule that corresponds to a global submodule ID.
2085
  ///
2086
  Module *getSubmodule(serialization::SubmoduleID GlobalID);
2087
2088
  /// Retrieve the module that corresponds to the given module ID.
2089
  ///
2090
  /// Note: overrides method in ExternalASTSource
2091
  Module *getModule(unsigned ID) override;
2092
2093
  bool DeclIsFromPCHWithObjectFile(const Decl *D) override;
2094
2095
  /// Retrieve the module file with a given local ID within the specified
2096
  /// ModuleFile.
2097
  ModuleFile *getLocalModuleFile(ModuleFile &M, unsigned ID);
2098
2099
  /// Get an ID for the given module file.
2100
  unsigned getModuleFileID(ModuleFile *M);
2101
2102
  /// Return a descriptor for the corresponding module.
2103
  llvm::Optional<ASTSourceDescriptor> getSourceDescriptor(unsigned ID) override;
2104
2105
  ExtKind hasExternalDefinitions(const Decl *D) override;
2106
2107
  /// Retrieve a selector from the given module with its local ID
2108
  /// number.
2109
  Selector getLocalSelector(ModuleFile &M, unsigned LocalID);
2110
2111
  Selector DecodeSelector(serialization::SelectorID Idx);
2112
2113
  Selector GetExternalSelector(serialization::SelectorID ID) override;
2114
  uint32_t GetNumExternalSelectors() override;
2115
2116
446
  Selector ReadSelector(ModuleFile &M, const RecordData &Record, unsigned &Idx) {
2117
446
    return getLocalSelector(M, Record[Idx++]);
2118
446
  }
2119
2120
  /// Retrieve the global selector ID that corresponds to this
2121
  /// the local selector ID in a given module.
2122
  serialization::SelectorID getGlobalSelectorID(ModuleFile &F,
2123
                                                unsigned LocalID) const;
2124
2125
  /// Read a declaration name.
2126
  DeclarationName ReadDeclarationName(ModuleFile &F,
2127
                                      const RecordData &Record, unsigned &Idx);
2128
  void ReadDeclarationNameLoc(ModuleFile &F,
2129
                              DeclarationNameLoc &DNLoc, DeclarationName Name,
2130
                              const RecordData &Record, unsigned &Idx);
2131
  void ReadDeclarationNameInfo(ModuleFile &F, DeclarationNameInfo &NameInfo,
2132
                               const RecordData &Record, unsigned &Idx);
2133
2134
  void ReadQualifierInfo(ModuleFile &F, QualifierInfo &Info,
2135
                         const RecordData &Record, unsigned &Idx);
2136
2137
  NestedNameSpecifier *ReadNestedNameSpecifier(ModuleFile &F,
2138
                                               const RecordData &Record,
2139
                                               unsigned &Idx);
2140
2141
  NestedNameSpecifierLoc ReadNestedNameSpecifierLoc(ModuleFile &F,
2142
                                                    const RecordData &Record,
2143
                                                    unsigned &Idx);
2144
2145
  /// Read a template name.
2146
  TemplateName ReadTemplateName(ModuleFile &F, const RecordData &Record,
2147
                                unsigned &Idx);
2148
2149
  /// Read a template argument.
2150
  TemplateArgument ReadTemplateArgument(ModuleFile &F, const RecordData &Record,
2151
                                        unsigned &Idx,
2152
                                        bool Canonicalize = false);
2153
2154
  /// Read a template parameter list.
2155
  TemplateParameterList *ReadTemplateParameterList(ModuleFile &F,
2156
                                                   const RecordData &Record,
2157
                                                   unsigned &Idx);
2158
2159
  /// Read a template argument array.
2160
  void ReadTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs,
2161
                                ModuleFile &F, const RecordData &Record,
2162
                                unsigned &Idx, bool Canonicalize = false);
2163
2164
  /// Read a UnresolvedSet structure.
2165
  void ReadUnresolvedSet(ModuleFile &F, LazyASTUnresolvedSet &Set,
2166
                         const RecordData &Record, unsigned &Idx);
2167
2168
  /// Read a C++ base specifier.
2169
  CXXBaseSpecifier ReadCXXBaseSpecifier(ModuleFile &F,
2170
                                        const RecordData &Record,unsigned &Idx);
2171
2172
  /// Read a CXXCtorInitializer array.
2173
  CXXCtorInitializer **
2174
  ReadCXXCtorInitializers(ModuleFile &F, const RecordData &Record,
2175
                          unsigned &Idx);
2176
2177
  /// Read the contents of a CXXCtorInitializer array.
2178
  CXXCtorInitializer **GetExternalCXXCtorInitializers(uint64_t Offset) override;
2179
2180
  /// Read a source location from raw form and return it in its
2181
  /// originating module file's source location space.
2182
1.50M
  SourceLocation ReadUntranslatedSourceLocation(uint32_t Raw) const {
2183
1.50M
    return SourceLocation::getFromRawEncoding((Raw >> 1) | (Raw << 31));
2184
1.50M
  }
2185
2186
  /// Read a source location from raw form.
2187
1.50M
  SourceLocation ReadSourceLocation(ModuleFile &ModuleFile, uint32_t Raw) const {
2188
1.50M
    SourceLocation Loc = ReadUntranslatedSourceLocation(Raw);
2189
1.50M
    return TranslateSourceLocation(ModuleFile, Loc);
2190
1.50M
  }
2191
2192
  /// Translate a source location from another module file's source
2193
  /// location space into ours.
2194
  SourceLocation TranslateSourceLocation(ModuleFile &ModuleFile,
2195
1.85M
                                         SourceLocation Loc) const {
2196
1.85M
    if (!ModuleFile.ModuleOffsetMap.empty())
2197
0
      ReadModuleOffsetMap(ModuleFile);
2198
1.85M
    assert(ModuleFile.SLocRemap.find(Loc.getOffset()) !=
2199
1.85M
               ModuleFile.SLocRemap.end() &&
2200
1.85M
           "Cannot find offset to remap.");
2201
1.85M
    int Remap = ModuleFile.SLocRemap.find(Loc.getOffset())->second;
2202
1.85M
    return Loc.getLocWithOffset(Remap);
2203
1.85M
  }
2204
2205
  /// Read a source location.
2206
  SourceLocation ReadSourceLocation(ModuleFile &ModuleFile,
2207
                                    const RecordDataImpl &Record,
2208
1.47M
                                    unsigned &Idx) {
2209
1.47M
    return ReadSourceLocation(ModuleFile, Record[Idx++]);
2210
1.47M
  }
2211
2212
  /// Read a source range.
2213
  SourceRange ReadSourceRange(ModuleFile &F,
2214
                              const RecordData &Record, unsigned &Idx);
2215
2216
  /// Read an integral value
2217
  llvm::APInt ReadAPInt(const RecordData &Record, unsigned &Idx);
2218
2219
  /// Read a signed integral value
2220
  llvm::APSInt ReadAPSInt(const RecordData &Record, unsigned &Idx);
2221
2222
  /// Read a floating-point value
2223
  llvm::APFloat ReadAPFloat(const RecordData &Record,
2224
                            const llvm::fltSemantics &Sem, unsigned &Idx);
2225
2226
  // Read a string
2227
  static std::string ReadString(const RecordData &Record, unsigned &Idx);
2228
2229
  // Skip a string
2230
5
  static void SkipString(const RecordData &Record, unsigned &Idx) {
2231
5
    Idx += Record[Idx] + 1;
2232
5
  }
2233
2234
  // Read a path
2235
  std::string ReadPath(ModuleFile &F, const RecordData &Record, unsigned &Idx);
2236
2237
  // Skip a path
2238
5
  static void SkipPath(const RecordData &Record, unsigned &Idx) {
2239
5
    SkipString(Record, Idx);
2240
5
  }
2241
2242
  /// Read a version tuple.
2243
  static VersionTuple ReadVersionTuple(const RecordData &Record, unsigned &Idx);
2244
2245
  CXXTemporary *ReadCXXTemporary(ModuleFile &F, const RecordData &Record,
2246
                                 unsigned &Idx);
2247
2248
  /// Reads one attribute from the current stream position.
2249
  Attr *ReadAttr(ModuleFile &M, const RecordData &Record, unsigned &Idx);
2250
2251
  /// Reads attributes from the current stream position.
2252
  void ReadAttributes(ASTRecordReader &Record, AttrVec &Attrs);
2253
2254
  /// Reads a statement.
2255
  Stmt *ReadStmt(ModuleFile &F);
2256
2257
  /// Reads an expression.
2258
  Expr *ReadExpr(ModuleFile &F);
2259
2260
  /// Reads a sub-statement operand during statement reading.
2261
675k
  Stmt *ReadSubStmt() {
2262
675k
    assert(ReadingKind == Read_Stmt &&
2263
675k
           "Should be called only during statement reading!");
2264
675k
    // Subexpressions are stored from last to first, so the next Stmt we need
2265
675k
    // is at the back of the stack.
2266
675k
    assert(!StmtStack.empty() && "Read too many sub-statements!");
2267
675k
    return StmtStack.pop_back_val();
2268
675k
  }
2269
2270
  /// Reads a sub-expression operand during statement reading.
2271
  Expr *ReadSubExpr();
2272
2273
  /// Reads a token out of a record.
2274
  Token ReadToken(ModuleFile &M, const RecordDataImpl &Record, unsigned &Idx);
2275
2276
  /// Reads the macro record located at the given offset.
2277
  MacroInfo *ReadMacroRecord(ModuleFile &F, uint64_t Offset);
2278
2279
  /// Determine the global preprocessed entity ID that corresponds to
2280
  /// the given local ID within the given module.
2281
  serialization::PreprocessedEntityID
2282
  getGlobalPreprocessedEntityID(ModuleFile &M, unsigned LocalID) const;
2283
2284
  /// Add a macro to deserialize its macro directive history.
2285
  ///
2286
  /// \param II The name of the macro.
2287
  /// \param M The module file.
2288
  /// \param MacroDirectivesOffset Offset of the serialized macro directive
2289
  /// history.
2290
  void addPendingMacro(IdentifierInfo *II, ModuleFile *M,
2291
                       uint64_t MacroDirectivesOffset);
2292
2293
  /// Read the set of macros defined by this external macro source.
2294
  void ReadDefinedMacros() override;
2295
2296
  /// Update an out-of-date identifier.
2297
  void updateOutOfDateIdentifier(IdentifierInfo &II) override;
2298
2299
  /// Note that this identifier is up-to-date.
2300
  void markIdentifierUpToDate(IdentifierInfo *II);
2301
2302
  /// Load all external visible decls in the given DeclContext.
2303
  void completeVisibleDeclsMap(const DeclContext *DC) override;
2304
2305
  /// Retrieve the AST context that this AST reader supplements.
2306
4.79M
  ASTContext &getContext() {
2307
4.79M
    assert(ContextObj && "requested AST context when not loading AST");
2308
4.79M
    return *ContextObj;
2309
4.79M
  }
2310
2311
  // Contains the IDs for declarations that were requested before we have
2312
  // access to a Sema object.
2313
  SmallVector<uint64_t, 16> PreloadedDeclIDs;
2314
2315
  /// Retrieve the semantic analysis object used to analyze the
2316
  /// translation unit in which the precompiled header is being
2317
  /// imported.
2318
140
  Sema *getSema() { return SemaObj; }
2319
2320
  /// Get the identifier resolver used for name lookup / updates
2321
  /// in the translation unit scope. We have one of these even if we don't
2322
  /// have a Sema object.
2323
  IdentifierResolver &getIdResolver();
2324
2325
  /// Retrieve the identifier table associated with the
2326
  /// preprocessor.
2327
  IdentifierTable &getIdentifierTable();
2328
2329
  /// Record that the given ID maps to the given switch-case
2330
  /// statement.
2331
  void RecordSwitchCaseID(SwitchCase *SC, unsigned ID);
2332
2333
  /// Retrieve the switch-case statement with the given ID.
2334
  SwitchCase *getSwitchCaseWithID(unsigned ID);
2335
2336
  void ClearSwitchCaseIDs();
2337
2338
  /// Cursors for comments blocks.
2339
  SmallVector<std::pair<llvm::BitstreamCursor,
2340
                        serialization::ModuleFile *>, 8> CommentsCursors;
2341
2342
  /// Loads comments ranges.
2343
  void ReadComments() override;
2344
2345
  /// Visit all the input files of the given module file.
2346
  void visitInputFiles(serialization::ModuleFile &MF,
2347
                       bool IncludeSystem, bool Complain,
2348
          llvm::function_ref<void(const serialization::InputFile &IF,
2349
                                  bool isSystem)> Visitor);
2350
2351
  /// Visit all the top-level module maps loaded when building the given module
2352
  /// file.
2353
  void visitTopLevelModuleMaps(serialization::ModuleFile &MF,
2354
                               llvm::function_ref<
2355
                                   void(const FileEntry *)> Visitor);
2356
2357
173k
  bool isProcessingUpdateRecords() { return ProcessingUpdateRecords; }
2358
};
2359
2360
/// An object for streaming information from a record.
2361
class ASTRecordReader {
2362
  using ModuleFile = serialization::ModuleFile;
2363
2364
  ASTReader *Reader;
2365
  ModuleFile *F;
2366
  unsigned Idx = 0;
2367
  ASTReader::RecordData Record;
2368
2369
  using RecordData = ASTReader::RecordData;
2370
  using RecordDataImpl = ASTReader::RecordDataImpl;
2371
2372
public:
2373
  /// Construct an ASTRecordReader that uses the default encoding scheme.
2374
331k
  ASTRecordReader(ASTReader &Reader, ModuleFile &F) : Reader(&Reader), F(&F) {}
2375
2376
  /// Reads a record with id AbbrevID from Cursor, resetting the
2377
  /// internal state.
2378
  unsigned readRecord(llvm::BitstreamCursor &Cursor, unsigned AbbrevID);
2379
2380
  /// Is this a module file for a module (rather than a PCH or similar).
2381
28
  bool isModule() const { return F->isModule(); }
2382
2383
  /// Retrieve the AST context that this AST reader supplements.
2384
91.6k
  ASTContext &getContext() { return Reader->getContext(); }
2385
2386
  /// The current position in this record.
2387
273k
  unsigned getIdx() const { return Idx; }
2388
2389
  /// The length of this record.
2390
273k
  size_t size() const { return Record.size(); }
2391
2392
  /// An arbitrary index in this record.
2393
727k
  const uint64_t &operator[](size_t N) { return Record[N]; }
2394
2395
  /// The last element in this record.
2396
304
  const uint64_t &back() const { return Record.back(); }
2397
2398
  /// Returns the current value in this record, and advances to the
2399
  /// next value.
2400
12.6M
  const uint64_t &readInt() { return Record[Idx++]; }
2401
2402
  /// Returns the current value in this record, without advancing.
2403
32
  const uint64_t &peekInt() { return Record[Idx]; }
2404
2405
  /// Skips the specified number of values.
2406
30.9k
  void skipInts(unsigned N) { Idx += N; }
2407
2408
  /// Retrieve the global submodule ID its local ID number.
2409
  serialization::SubmoduleID
2410
250k
  getGlobalSubmoduleID(unsigned LocalID) {
2411
250k
    return Reader->getGlobalSubmoduleID(*F, LocalID);
2412
250k
  }
2413
2414
  /// Retrieve the submodule that corresponds to a global submodule ID.
2415
152
  Module *getSubmodule(serialization::SubmoduleID GlobalID) {
2416
152
    return Reader->getSubmodule(GlobalID);
2417
152
  }
2418
2419
  /// Read the record that describes the lexical contents of a DC.
2420
31
  bool readLexicalDeclContextStorage(uint64_t Offset, DeclContext *DC) {
2421
31
    return Reader->ReadLexicalDeclContextStorage(*F, F->DeclsCursor, Offset,
2422
31
                                                 DC);
2423
31
  }
2424
2425
  /// Read the record that describes the visible contents of a DC.
2426
  bool readVisibleDeclContextStorage(uint64_t Offset,
2427
                                     serialization::DeclID ID) {
2428
    return Reader->ReadVisibleDeclContextStorage(*F, F->DeclsCursor, Offset,
2429
                                                 ID);
2430
  }
2431
2432
  void readExceptionSpec(SmallVectorImpl<QualType> &ExceptionStorage,
2433
28
                         FunctionProtoType::ExceptionSpecInfo &ESI) {
2434
28
    return Reader->readExceptionSpec(*F, ExceptionStorage, ESI, Record, Idx);
2435
28
  }
2436
2437
  /// Get the global offset corresponding to a local offset.
2438
2.48k
  uint64_t getGlobalBitOffset(uint32_t LocalOffset) {
2439
2.48k
    return Reader->getGlobalBitOffset(*F, LocalOffset);
2440
2.48k
  }
2441
2442
  /// Reads a statement.
2443
11
  Stmt *readStmt() { return Reader->ReadStmt(*F); }
2444
2445
  /// Reads an expression.
2446
55.7k
  Expr *readExpr() { return Reader->ReadExpr(*F); }
2447
2448
  /// Reads a sub-statement operand during statement reading.
2449
83.9k
  Stmt *readSubStmt() { return Reader->ReadSubStmt(); }
2450
2451
  /// Reads a sub-expression operand during statement reading.
2452
578k
  Expr *readSubExpr() { return Reader->ReadSubExpr(); }
2453
2454
  /// Reads a declaration with the given local ID in the given module.
2455
  ///
2456
  /// \returns The requested declaration, casted to the given return type.
2457
  template<typename T>
2458
  T *GetLocalDeclAs(uint32_t LocalID) {
2459
    return cast_or_null<T>(Reader->GetLocalDecl(*F, LocalID));
2460
  }
2461
2462
  /// Reads a TemplateArgumentLocInfo appropriate for the
2463
  /// given TemplateArgument kind, advancing Idx.
2464
  TemplateArgumentLocInfo
2465
  getTemplateArgumentLocInfo(TemplateArgument::ArgKind Kind) {
2466
    return Reader->GetTemplateArgumentLocInfo(*F, Kind, Record, Idx);
2467
  }
2468
2469
  /// Reads a TemplateArgumentLoc, advancing Idx.
2470
  TemplateArgumentLoc
2471
1.25k
  readTemplateArgumentLoc() {
2472
1.25k
    return Reader->ReadTemplateArgumentLoc(*F, Record, Idx);
2473
1.25k
  }
2474
2475
  const ASTTemplateArgumentListInfo*
2476
162
  readASTTemplateArgumentListInfo() {
2477
162
    return Reader->ReadASTTemplateArgumentListInfo(*F, Record, Idx);
2478
162
  }
2479
2480
  /// Reads a declarator info from the given record, advancing Idx.
2481
15.9k
  TypeSourceInfo *getTypeSourceInfo() {
2482
15.9k
    return Reader->GetTypeSourceInfo(*F, Record, Idx);
2483
15.9k
  }
2484
2485
  /// Reads the location information for a type.
2486
99.2k
  void readTypeLoc(TypeLoc TL) {
2487
99.2k
    return Reader->ReadTypeLoc(*F, Record, Idx, TL);
2488
99.2k
  }
2489
2490
  /// Map a local type ID within a given AST file to a global type ID.
2491
69.4k
  serialization::TypeID getGlobalTypeID(unsigned LocalID) const {
2492
69.4k
    return Reader->getGlobalTypeID(*F, LocalID);
2493
69.4k
  }
2494
2495
  /// Read a type from the current position in the record.
2496
828k
  QualType readType() {
2497
828k
    return Reader->readType(*F, Record, Idx);
2498
828k
  }
2499
2500
  /// Reads a declaration ID from the given position in this record.
2501
  ///
2502
  /// \returns The declaration ID read from the record, adjusted to a global ID.
2503
314k
  serialization::DeclID readDeclID() {
2504
314k
    return Reader->ReadDeclID(*F, Record, Idx);
2505
314k
  }
2506
2507
  /// Reads a declaration from the given position in a record in the
2508
  /// given module, advancing Idx.
2509
62.9k
  Decl *readDecl() {
2510
62.9k
    return Reader->ReadDecl(*F, Record, Idx);
2511
62.9k
  }
2512
2513
  /// Reads a declaration from the given position in the record,
2514
  /// advancing Idx.
2515
  ///
2516
  /// \returns The declaration read from this location, casted to the given
2517
  /// result type.
2518
  template<typename T>
2519
796k
  T *readDeclAs() {
2520
796k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
796k
  }
clang::ValueDecl* clang::ASTRecordReader::readDeclAs<clang::ValueDecl>()
Line
Count
Source
2519
150k
  T *readDeclAs() {
2520
150k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
150k
  }
clang::DeclContext* clang::ASTRecordReader::readDeclAs<clang::DeclContext>()
Line
Count
Source
2519
451k
  T *readDeclAs() {
2520
451k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
451k
  }
clang::TypeAliasTemplateDecl* clang::ASTRecordReader::readDeclAs<clang::TypeAliasTemplateDecl>()
Line
Count
Source
2519
202
  T *readDeclAs() {
2520
202
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
202
  }
clang::EnumDecl* clang::ASTRecordReader::readDeclAs<clang::EnumDecl>()
Line
Count
Source
2519
350
  T *readDeclAs() {
2520
350
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
350
  }
clang::FunctionTemplateDecl* clang::ASTRecordReader::readDeclAs<clang::FunctionTemplateDecl>()
Line
Count
Source
2519
3.75k
  T *readDeclAs() {
2520
3.75k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
3.75k
  }
clang::FunctionDecl* clang::ASTRecordReader::readDeclAs<clang::FunctionDecl>()
Line
Count
Source
2519
4.08k
  T *readDeclAs() {
2520
4.08k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
4.08k
  }
clang::NamedDecl* clang::ASTRecordReader::readDeclAs<clang::NamedDecl>()
Line
Count
Source
2519
7.56k
  T *readDeclAs() {
2520
7.56k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
7.56k
  }
clang::ParmVarDecl* clang::ASTRecordReader::readDeclAs<clang::ParmVarDecl>()
Line
Count
Source
2519
16.0k
  T *readDeclAs() {
2520
16.0k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
16.0k
  }
clang::ImplicitParamDecl* clang::ASTRecordReader::readDeclAs<clang::ImplicitParamDecl>()
Line
Count
Source
2519
65.0k
  T *readDeclAs() {
2520
65.0k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
65.0k
  }
clang::ObjCMethodDecl* clang::ASTRecordReader::readDeclAs<clang::ObjCMethodDecl>()
Line
Count
Source
2519
158
  T *readDeclAs() {
2520
158
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
158
  }
clang::ObjCTypeParamDecl* clang::ASTRecordReader::readDeclAs<clang::ObjCTypeParamDecl>()
Line
Count
Source
2519
17
  T *readDeclAs() {
2520
17
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
17
  }
clang::ObjCProtocolDecl* clang::ASTRecordReader::readDeclAs<clang::ObjCProtocolDecl>()
Line
Count
Source
2519
33
  T *readDeclAs() {
2520
33
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
33
  }
clang::ObjCInterfaceDecl* clang::ASTRecordReader::readDeclAs<clang::ObjCInterfaceDecl>()
Line
Count
Source
2519
183
  T *readDeclAs() {
2520
183
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
183
  }
clang::ObjCIvarDecl* clang::ASTRecordReader::readDeclAs<clang::ObjCIvarDecl>()
Line
Count
Source
2519
59
  T *readDeclAs() {
2520
59
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
59
  }
clang::ObjCPropertyDecl* clang::ASTRecordReader::readDeclAs<clang::ObjCPropertyDecl>()
Line
Count
Source
2519
10
  T *readDeclAs() {
2520
10
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
10
  }
clang::FieldDecl* clang::ASTRecordReader::readDeclAs<clang::FieldDecl>()
Line
Count
Source
2519
8.05k
  T *readDeclAs() {
2520
8.05k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
8.05k
  }
clang::VarTemplateDecl* clang::ASTRecordReader::readDeclAs<clang::VarTemplateDecl>()
Line
Count
Source
2519
253
  T *readDeclAs() {
2520
253
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
253
  }
clang::VarDecl* clang::ASTRecordReader::readDeclAs<clang::VarDecl>()
Line
Count
Source
2519
31.4k
  T *readDeclAs() {
2520
31.4k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
31.4k
  }
clang::BindingDecl* clang::ASTRecordReader::readDeclAs<clang::BindingDecl>()
Line
Count
Source
2519
4
  T *readDeclAs() {
2520
4
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
4
  }
clang::UsingShadowDecl* clang::ASTRecordReader::readDeclAs<clang::UsingShadowDecl>()
Line
Count
Source
2519
643
  T *readDeclAs() {
2520
643
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
643
  }
clang::ConstructorUsingShadowDecl* clang::ASTRecordReader::readDeclAs<clang::ConstructorUsingShadowDecl>()
Line
Count
Source
2519
124
  T *readDeclAs() {
2520
124
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
124
  }
clang::ClassTemplateDecl* clang::ASTRecordReader::readDeclAs<clang::ClassTemplateDecl>()
Line
Count
Source
2519
7.57k
  T *readDeclAs() {
2520
7.57k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
7.57k
  }
clang::CXXRecordDecl* clang::ASTRecordReader::readDeclAs<clang::CXXRecordDecl>()
Line
Count
Source
2519
960
  T *readDeclAs() {
2520
960
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
960
  }
clang::CXXMethodDecl* clang::ASTRecordReader::readDeclAs<clang::CXXMethodDecl>()
Line
Count
Source
2519
20
  T *readDeclAs() {
2520
20
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
20
  }
clang::CXXConstructorDecl* clang::ASTRecordReader::readDeclAs<clang::CXXConstructorDecl>()
Line
Count
Source
2519
4.98k
  T *readDeclAs() {
2520
4.98k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
4.98k
  }
clang::RedeclarableTemplateDecl* clang::ASTRecordReader::readDeclAs<clang::RedeclarableTemplateDecl>()
Line
Count
Source
2519
3.75k
  T *readDeclAs() {
2520
3.75k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
3.75k
  }
clang::ClassTemplatePartialSpecializationDecl* clang::ASTRecordReader::readDeclAs<clang::ClassTemplatePartialSpecializationDecl>()
Line
Count
Source
2519
160
  T *readDeclAs() {
2520
160
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
160
  }
clang::VarTemplatePartialSpecializationDecl* clang::ASTRecordReader::readDeclAs<clang::VarTemplatePartialSpecializationDecl>()
Line
Count
Source
2519
10
  T *readDeclAs() {
2520
10
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
10
  }
clang::NamespaceDecl* clang::ASTRecordReader::readDeclAs<clang::NamespaceDecl>()
Line
Count
Source
2519
18
  T *readDeclAs() {
2520
18
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
18
  }
clang::LabelDecl* clang::ASTRecordReader::readDeclAs<clang::LabelDecl>()
Line
Count
Source
2519
8
  T *readDeclAs() {
2520
8
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
8
  }
clang::CapturedDecl* clang::ASTRecordReader::readDeclAs<clang::CapturedDecl>()
Line
Count
Source
2519
19.0k
  T *readDeclAs() {
2520
19.0k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
19.0k
  }
clang::RecordDecl* clang::ASTRecordReader::readDeclAs<clang::RecordDecl>()
Line
Count
Source
2519
19.0k
  T *readDeclAs() {
2520
19.0k
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
19.0k
  }
clang::BlockDecl* clang::ASTRecordReader::readDeclAs<clang::BlockDecl>()
Line
Count
Source
2519
14
  T *readDeclAs() {
2520
14
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
14
  }
clang::NonTypeTemplateParmDecl* clang::ASTRecordReader::readDeclAs<clang::NonTypeTemplateParmDecl>()
Line
Count
Source
2519
346
  T *readDeclAs() {
2520
346
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
346
  }
clang::MSPropertyDecl* clang::ASTRecordReader::readDeclAs<clang::MSPropertyDecl>()
Line
Count
Source
2519
22
  T *readDeclAs() {
2520
22
    return Reader->ReadDeclAs<T>(*F, Record, Idx);
2521
22
  }
2522
2523
210
  IdentifierInfo *getIdentifierInfo() {
2524
210
    return Reader->GetIdentifierInfo(*F, Record, Idx);
2525
210
  }
2526
2527
  /// Read a selector from the Record, advancing Idx.
2528
3
  Selector readSelector() {
2529
3
    return Reader->ReadSelector(*F, Record, Idx);
2530
3
  }
2531
2532
  /// Read a declaration name, advancing Idx.
2533
227k
  DeclarationName readDeclarationName() {
2534
227k
    return Reader->ReadDeclarationName(*F, Record, Idx);
2535
227k
  }
2536
166k
  void readDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name) {
2537
166k
    return Reader->ReadDeclarationNameLoc(*F, DNLoc, Name, Record, Idx);
2538
166k
  }
2539
4.33k
  void readDeclarationNameInfo(DeclarationNameInfo &NameInfo) {
2540
4.33k
    return Reader->ReadDeclarationNameInfo(*F, NameInfo, Record, Idx);
2541
4.33k
  }
2542
2543
630
  void readQualifierInfo(QualifierInfo &Info) {
2544
630
    return Reader->ReadQualifierInfo(*F, Info, Record, Idx);
2545
630
  }
2546
2547
  NestedNameSpecifier *readNestedNameSpecifier() {
2548
    return Reader->ReadNestedNameSpecifier(*F, Record, Idx);
2549
  }
2550
2551
5.03k
  NestedNameSpecifierLoc readNestedNameSpecifierLoc() {
2552
5.03k
    return Reader->ReadNestedNameSpecifierLoc(*F, Record, Idx);
2553
5.03k
  }
2554
2555
  /// Read a template name, advancing Idx.
2556
  TemplateName readTemplateName() {
2557
    return Reader->ReadTemplateName(*F, Record, Idx);
2558
  }
2559
2560
  /// Read a template argument, advancing Idx.
2561
0
  TemplateArgument readTemplateArgument(bool Canonicalize = false) {
2562
0
    return Reader->ReadTemplateArgument(*F, Record, Idx, Canonicalize);
2563
0
  }
2564
2565
  /// Read a template parameter list, advancing Idx.
2566
5.16k
  TemplateParameterList *readTemplateParameterList() {
2567
5.16k
    return Reader->ReadTemplateParameterList(*F, Record, Idx);
2568
5.16k
  }
2569
2570
  /// Read a template argument array, advancing Idx.
2571
  void readTemplateArgumentList(SmallVectorImpl<TemplateArgument> &TemplArgs,
2572
5.26k
                                bool Canonicalize = false) {
2573
5.26k
    return Reader->ReadTemplateArgumentList(TemplArgs, *F, Record, Idx,
2574
5.26k
                                            Canonicalize);
2575
5.26k
  }
2576
2577
  /// Read a UnresolvedSet structure, advancing Idx.
2578
51.1k
  void readUnresolvedSet(LazyASTUnresolvedSet &Set) {
2579
51.1k
    return Reader->ReadUnresolvedSet(*F, Set, Record, Idx);
2580
51.1k
  }
2581
2582
  /// Read a C++ base specifier, advancing Idx.
2583
586
  CXXBaseSpecifier readCXXBaseSpecifier() {
2584
586
    return Reader->ReadCXXBaseSpecifier(*F, Record, Idx);
2585
586
  }
2586
2587
  /// Read a CXXCtorInitializer array, advancing Idx.
2588
  CXXCtorInitializer **readCXXCtorInitializers() {
2589
    return Reader->ReadCXXCtorInitializers(*F, Record, Idx);
2590
  }
2591
2592
1.10k
  CXXTemporary *readCXXTemporary() {
2593
1.10k
    return Reader->ReadCXXTemporary(*F, Record, Idx);
2594
1.10k
  }
2595
2596
  /// Read a source location, advancing Idx.
2597
841k
  SourceLocation readSourceLocation() {
2598
841k
    return Reader->ReadSourceLocation(*F, Record, Idx);
2599
841k
  }
2600
2601
  /// Read a source range, advancing Idx.
2602
41.6k
  SourceRange readSourceRange() {
2603
41.6k
    return Reader->ReadSourceRange(*F, Record, Idx);
2604
41.6k
  }
2605
2606
  /// Read an integral value, advancing Idx.
2607
69.3k
  llvm::APInt readAPInt() {
2608
69.3k
    return Reader->ReadAPInt(Record, Idx);
2609
69.3k
  }
2610
2611
  /// Read a signed integral value, advancing Idx.
2612
387
  llvm::APSInt readAPSInt() {
2613
387
    return Reader->ReadAPSInt(Record, Idx);
2614
387
  }
2615
2616
  /// Read a floating-point value, advancing Idx.
2617
933
  llvm::APFloat readAPFloat(const llvm::fltSemantics &Sem) {
2618
933
    return Reader->ReadAPFloat(Record, Sem,Idx);
2619
933
  }
2620
2621
  /// Read a string, advancing Idx.
2622
7
  std::string readString() {
2623
7
    return Reader->ReadString(Record, Idx);
2624
7
  }
2625
2626
  /// Read a path, advancing Idx.
2627
  std::string readPath() {
2628
    return Reader->ReadPath(*F, Record, Idx);
2629
  }
2630
2631
  /// Read a version tuple, advancing Idx.
2632
0
  VersionTuple readVersionTuple() {
2633
0
    return ASTReader::ReadVersionTuple(Record, Idx);
2634
0
  }
2635
2636
  /// Reads one attribute from the current stream position, advancing Idx.
2637
41.9k
  Attr *readAttr() {
2638
41.9k
    return Reader->ReadAttr(*F, Record, Idx);
2639
41.9k
  }
2640
2641
  /// Reads attributes from the current stream position, advancing Idx.
2642
41.7k
  void readAttributes(AttrVec &Attrs) {
2643
41.7k
    return Reader->ReadAttributes(*this, Attrs);
2644
41.7k
  }
2645
2646
  /// Reads a token out of a record, advancing Idx.
2647
0
  Token readToken() {
2648
0
    return Reader->ReadToken(*F, Record, Idx);
2649
0
  }
2650
2651
27
  void recordSwitchCaseID(SwitchCase *SC, unsigned ID) {
2652
27
    Reader->RecordSwitchCaseID(SC, ID);
2653
27
  }
2654
2655
  /// Retrieve the switch-case statement with the given ID.
2656
27
  SwitchCase *getSwitchCaseWithID(unsigned ID) {
2657
27
    return Reader->getSwitchCaseWithID(ID);
2658
27
  }
2659
};
2660
2661
/// Helper class that saves the current stream position and
2662
/// then restores it when destroyed.
2663
struct SavedStreamPosition {
2664
  explicit SavedStreamPosition(llvm::BitstreamCursor &Cursor)
2665
583k
      : Cursor(Cursor), Offset(Cursor.GetCurrentBitNo()) {}
2666
2667
583k
  ~SavedStreamPosition() {
2668
583k
    Cursor.JumpToBit(Offset);
2669
583k
  }
2670
2671
private:
2672
  llvm::BitstreamCursor &Cursor;
2673
  uint64_t Offset;
2674
};
2675
2676
0
inline void PCHValidator::Error(const char *Msg) {
2677
0
  Reader.Error(Msg);
2678
0
}
2679
2680
class OMPClauseReader : public OMPClauseVisitor<OMPClauseReader> {
2681
  ASTRecordReader &Record;
2682
  ASTContext &Context;
2683
2684
public:
2685
  OMPClauseReader(ASTRecordReader &Record)
2686
9.99k
      : Record(Record), Context(Record.getContext()) {}
2687
2688
#define OPENMP_CLAUSE(Name, Class) void Visit##Class(Class *C);
2689
  OPENMP_CLAUSE(flush, OMPFlushClause)
2690
#include "clang/Basic/OpenMPKinds.def"
2691
  OMPClause *readClause();
2692
  void VisitOMPClauseWithPreInit(OMPClauseWithPreInit *C);
2693
  void VisitOMPClauseWithPostUpdate(OMPClauseWithPostUpdate *C);
2694
};
2695
2696
} // namespace clang
2697
2698
#endif // LLVM_CLANG_SERIALIZATION_ASTREADER_H