Coverage Report

Created: 2018-07-21 08:31

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/clang/include/clang/AST/ExternalASTSource.h
Line
Count
Source (jump to first uncovered line)
1
//===- ExternalASTSource.h - Abstract External AST Interface ----*- C++ -*-===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
//  This file defines the ExternalASTSource interface, which enables
11
//  construction of AST nodes from some external source.
12
//
13
//===----------------------------------------------------------------------===//
14
15
#ifndef LLVM_CLANG_AST_EXTERNALASTSOURCE_H
16
#define LLVM_CLANG_AST_EXTERNALASTSOURCE_H
17
18
#include "clang/AST/CharUnits.h"
19
#include "clang/AST/DeclBase.h"
20
#include "clang/Basic/LLVM.h"
21
#include "clang/Basic/Module.h"
22
#include "llvm/ADT/ArrayRef.h"
23
#include "llvm/ADT/DenseMap.h"
24
#include "llvm/ADT/IntrusiveRefCntPtr.h"
25
#include "llvm/ADT/Optional.h"
26
#include "llvm/ADT/PointerUnion.h"
27
#include "llvm/ADT/STLExtras.h"
28
#include "llvm/ADT/SmallVector.h"
29
#include "llvm/ADT/StringRef.h"
30
#include "llvm/ADT/iterator.h"
31
#include "llvm/Support/PointerLikeTypeTraits.h"
32
#include <cassert>
33
#include <cstddef>
34
#include <cstdint>
35
#include <iterator>
36
#include <string>
37
#include <utility>
38
39
namespace clang {
40
41
class ASTConsumer;
42
class ASTContext;
43
class CXXBaseSpecifier;
44
class CXXCtorInitializer;
45
class CXXRecordDecl;
46
class DeclarationName;
47
class FieldDecl;
48
class IdentifierInfo;
49
class NamedDecl;
50
class ObjCInterfaceDecl;
51
class RecordDecl;
52
class Selector;
53
class Stmt;
54
class TagDecl;
55
56
/// Abstract interface for external sources of AST nodes.
57
///
58
/// External AST sources provide AST nodes constructed from some
59
/// external source, such as a precompiled header. External AST
60
/// sources can resolve types and declarations from abstract IDs into
61
/// actual type and declaration nodes, and read parts of declaration
62
/// contexts.
63
class ExternalASTSource : public RefCountedBase<ExternalASTSource> {
64
  friend class ExternalSemaSource;
65
66
  /// Generation number for this external AST source. Must be increased
67
  /// whenever we might have added new redeclarations for existing decls.
68
  uint32_t CurrentGeneration = 0;
69
70
  /// Whether this AST source also provides information for
71
  /// semantic analysis.
72
  bool SemaSource = false;
73
74
public:
75
6.99k
  ExternalASTSource() = default;
76
  virtual ~ExternalASTSource();
77
78
  /// RAII class for safely pairing a StartedDeserializing call
79
  /// with FinishedDeserializing.
80
  class Deserializing {
81
    ExternalASTSource *Source;
82
83
  public:
84
1.69M
    explicit Deserializing(ExternalASTSource *source) : Source(source) {
85
1.69M
      assert(Source);
86
1.69M
      Source->StartedDeserializing();
87
1.69M
    }
88
89
1.69M
    ~Deserializing() {
90
1.69M
      Source->FinishedDeserializing();
91
1.69M
    }
92
  };
93
94
  /// Get the current generation of this AST source. This number
95
  /// is incremented each time the AST source lazily extends an existing
96
  /// entity.
97
5.38M
  uint32_t getGeneration() const { return CurrentGeneration; }
98
99
  /// Resolve a declaration ID into a declaration, potentially
100
  /// building a new declaration.
101
  ///
102
  /// This method only needs to be implemented if the AST source ever
103
  /// passes back decl sets as VisibleDeclaration objects.
104
  ///
105
  /// The default implementation of this method is a no-op.
106
  virtual Decl *GetExternalDecl(uint32_t ID);
107
108
  /// Resolve a selector ID into a selector.
109
  ///
110
  /// This operation only needs to be implemented if the AST source
111
  /// returns non-zero for GetNumKnownSelectors().
112
  ///
113
  /// The default implementation of this method is a no-op.
114
  virtual Selector GetExternalSelector(uint32_t ID);
115
116
  /// Returns the number of selectors known to the external AST
117
  /// source.
118
  ///
119
  /// The default implementation of this method is a no-op.
120
  virtual uint32_t GetNumExternalSelectors();
121
122
  /// Resolve the offset of a statement in the decl stream into
123
  /// a statement.
124
  ///
125
  /// This operation is meant to be used via a LazyOffsetPtr.  It only
126
  /// needs to be implemented if the AST source uses methods like
127
  /// FunctionDecl::setLazyBody when building decls.
128
  ///
129
  /// The default implementation of this method is a no-op.
130
  virtual Stmt *GetExternalDeclStmt(uint64_t Offset);
131
132
  /// Resolve the offset of a set of C++ constructor initializers in
133
  /// the decl stream into an array of initializers.
134
  ///
135
  /// The default implementation of this method is a no-op.
136
  virtual CXXCtorInitializer **GetExternalCXXCtorInitializers(uint64_t Offset);
137
138
  /// Resolve the offset of a set of C++ base specifiers in the decl
139
  /// stream into an array of specifiers.
140
  ///
141
  /// The default implementation of this method is a no-op.
142
  virtual CXXBaseSpecifier *GetExternalCXXBaseSpecifiers(uint64_t Offset);
143
144
  /// Update an out-of-date identifier.
145
0
  virtual void updateOutOfDateIdentifier(IdentifierInfo &II) {}
146
147
  /// Find all declarations with the given name in the given context,
148
  /// and add them to the context by calling SetExternalVisibleDeclsForName
149
  /// or SetNoExternalVisibleDeclsForName.
150
  /// \return \c true if any declarations might have been found, \c false if
151
  /// we definitely have no declarations with tbis name.
152
  ///
153
  /// The default implementation of this method is a no-op returning \c false.
154
  virtual bool
155
  FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name);
156
157
  /// Ensures that the table of all visible declarations inside this
158
  /// context is up to date.
159
  ///
160
  /// The default implementation of this function is a no-op.
161
  virtual void completeVisibleDeclsMap(const DeclContext *DC);
162
163
  /// Retrieve the module that corresponds to the given module ID.
164
0
  virtual Module *getModule(unsigned ID) { return nullptr; }
165
166
  /// Determine whether D comes from a PCH which was built with a corresponding
167
  /// object file.
168
21
  virtual bool DeclIsFromPCHWithObjectFile(const Decl *D) { return false; }
169
170
  /// Abstracts clang modules and precompiled header files and holds
171
  /// everything needed to generate debug info for an imported module
172
  /// or PCH.
173
  class ASTSourceDescriptor {
174
    StringRef PCHModuleName;
175
    StringRef Path;
176
    StringRef ASTFile;
177
    ASTFileSignature Signature;
178
    const Module *ClangModule = nullptr;
179
180
  public:
181
2.89k
    ASTSourceDescriptor() = default;
182
    ASTSourceDescriptor(StringRef Name, StringRef Path, StringRef ASTFile,
183
                        ASTFileSignature Signature)
184
        : PCHModuleName(std::move(Name)), Path(std::move(Path)),
185
117
          ASTFile(std::move(ASTFile)), Signature(Signature) {}
186
    ASTSourceDescriptor(const Module &M);
187
188
    std::string getModuleName() const;
189
73
    StringRef getPath() const { return Path; }
190
19
    StringRef getASTFile() const { return ASTFile; }
191
39
    ASTFileSignature getSignature() const { return Signature; }
192
416
    const Module *getModuleOrNull() const { return ClangModule; }
193
  };
194
195
  /// Return a descriptor for the corresponding module, if one exists.
196
  virtual llvm::Optional<ASTSourceDescriptor> getSourceDescriptor(unsigned ID);
197
198
  enum ExtKind { EK_Always, EK_Never, EK_ReplyHazy };
199
200
  virtual ExtKind hasExternalDefinitions(const Decl *D);
201
202
  /// Finds all declarations lexically contained within the given
203
  /// DeclContext, after applying an optional filter predicate.
204
  ///
205
  /// \param IsKindWeWant a predicate function that returns true if the passed
206
  /// declaration kind is one we are looking for.
207
  ///
208
  /// The default implementation of this method is a no-op.
209
  virtual void
210
  FindExternalLexicalDecls(const DeclContext *DC,
211
                           llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,
212
                           SmallVectorImpl<Decl *> &Result);
213
214
  /// Finds all declarations lexically contained within the given
215
  /// DeclContext.
216
  void FindExternalLexicalDecls(const DeclContext *DC,
217
3.35k
                                SmallVectorImpl<Decl *> &Result) {
218
17.6k
    FindExternalLexicalDecls(DC, [](Decl::Kind) { return true; }, Result);
219
3.35k
  }
220
221
  /// Get the decls that are contained in a file in the Offset/Length
222
  /// range. \p Length can be 0 to indicate a point at \p Offset instead of
223
  /// a range.
224
  virtual void FindFileRegionDecls(FileID File, unsigned Offset,
225
                                   unsigned Length,
226
                                   SmallVectorImpl<Decl *> &Decls);
227
228
  /// Gives the external AST source an opportunity to complete
229
  /// the redeclaration chain for a declaration. Called each time we
230
  /// need the most recent declaration of a declaration after the
231
  /// generation count is incremented.
232
  virtual void CompleteRedeclChain(const Decl *D);
233
234
  /// Gives the external AST source an opportunity to complete
235
  /// an incomplete type.
236
  virtual void CompleteType(TagDecl *Tag);
237
238
  /// Gives the external AST source an opportunity to complete an
239
  /// incomplete Objective-C class.
240
  ///
241
  /// This routine will only be invoked if the "externally completed" bit is
242
  /// set on the ObjCInterfaceDecl via the function
243
  /// \c ObjCInterfaceDecl::setExternallyCompleted().
244
  virtual void CompleteType(ObjCInterfaceDecl *Class);
245
246
  /// Loads comment ranges.
247
  virtual void ReadComments();
248
249
  /// Notify ExternalASTSource that we started deserialization of
250
  /// a decl or type so until FinishedDeserializing is called there may be
251
  /// decls that are initializing. Must be paired with FinishedDeserializing.
252
  ///
253
  /// The default implementation of this method is a no-op.
254
  virtual void StartedDeserializing();
255
256
  /// Notify ExternalASTSource that we finished the deserialization of
257
  /// a decl or type. Must be paired with StartedDeserializing.
258
  ///
259
  /// The default implementation of this method is a no-op.
260
  virtual void FinishedDeserializing();
261
262
  /// Function that will be invoked when we begin parsing a new
263
  /// translation unit involving this external AST source.
264
  ///
265
  /// The default implementation of this method is a no-op.
266
  virtual void StartTranslationUnit(ASTConsumer *Consumer);
267
268
  /// Print any statistics that have been gathered regarding
269
  /// the external AST source.
270
  ///
271
  /// The default implementation of this method is a no-op.
272
  virtual void PrintStats();
273
  
274
  /// Perform layout on the given record.
275
  ///
276
  /// This routine allows the external AST source to provide an specific 
277
  /// layout for a record, overriding the layout that would normally be
278
  /// constructed. It is intended for clients who receive specific layout
279
  /// details rather than source code (such as LLDB). The client is expected
280
  /// to fill in the field offsets, base offsets, virtual base offsets, and
281
  /// complete object size.
282
  ///
283
  /// \param Record The record whose layout is being requested.
284
  ///
285
  /// \param Size The final size of the record, in bits.
286
  ///
287
  /// \param Alignment The final alignment of the record, in bits.
288
  ///
289
  /// \param FieldOffsets The offset of each of the fields within the record,
290
  /// expressed in bits. All of the fields must be provided with offsets.
291
  ///
292
  /// \param BaseOffsets The offset of each of the direct, non-virtual base
293
  /// classes. If any bases are not given offsets, the bases will be laid 
294
  /// out according to the ABI.
295
  ///
296
  /// \param VirtualBaseOffsets The offset of each of the virtual base classes
297
  /// (either direct or not). If any bases are not given offsets, the bases will be laid 
298
  /// out according to the ABI.
299
  /// 
300
  /// \returns true if the record layout was provided, false otherwise.
301
  virtual bool layoutRecordType(
302
      const RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,
303
      llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,
304
      llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,
305
      llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets);
306
307
  //===--------------------------------------------------------------------===//
308
  // Queries for performance analysis.
309
  //===--------------------------------------------------------------------===//
310
  
311
  struct MemoryBufferSizes {
312
    size_t malloc_bytes;
313
    size_t mmap_bytes;
314
    
315
    MemoryBufferSizes(size_t malloc_bytes, size_t mmap_bytes)
316
        : malloc_bytes(malloc_bytes), mmap_bytes(mmap_bytes) {}
317
  };
318
  
319
  /// Return the amount of memory used by memory buffers, breaking down
320
  /// by heap-backed versus mmap'ed memory.
321
0
  MemoryBufferSizes getMemoryBufferSizes() const {
322
0
    MemoryBufferSizes sizes(0, 0);
323
0
    getMemoryBufferSizes(sizes);
324
0
    return sizes;
325
0
  }
326
327
  virtual void getMemoryBufferSizes(MemoryBufferSizes &sizes) const;
328
329
protected:
330
  static DeclContextLookupResult
331
  SetExternalVisibleDeclsForName(const DeclContext *DC,
332
                                 DeclarationName Name,
333
                                 ArrayRef<NamedDecl*> Decls);
334
335
  static DeclContextLookupResult
336
  SetNoExternalVisibleDeclsForName(const DeclContext *DC,
337
                                   DeclarationName Name);
338
339
  /// Increment the current generation.
340
  uint32_t incrementGeneration(ASTContext &C);
341
};
342
343
/// A lazy pointer to an AST node (of base type T) that resides
344
/// within an external AST source.
345
///
346
/// The AST node is identified within the external AST source by a
347
/// 63-bit offset, and can be retrieved via an operation on the
348
/// external AST source itself.
349
template<typename T, typename OffsT, T* (ExternalASTSource::*Get)(OffsT Offset)>
350
0
struct LazyOffsetPtr {
351
  /// Either a pointer to an AST node or the offset within the
352
  /// external AST source where the AST node can be found.
353
  ///
354
  /// If the low bit is clear, a pointer to the AST node. If the low
355
  /// bit is set, the upper 63 bits are the offset.
356
  mutable uint64_t Ptr = 0;
357
358
public:
359
14.7M
  LazyOffsetPtr() = default;
clang::LazyOffsetPtr<clang::Decl, unsigned int, &(clang::ExternalASTSource::GetExternalDecl(unsigned int))>::LazyOffsetPtr()
Line
Count
Source
359
2.18M
  LazyOffsetPtr() = default;
clang::LazyOffsetPtr<clang::Stmt, unsigned long long, &(clang::ExternalASTSource::GetExternalDeclStmt(unsigned long long))>::LazyOffsetPtr()
Line
Count
Source
359
7.85M
  LazyOffsetPtr() = default;
clang::LazyOffsetPtr<clang::CXXBaseSpecifier, unsigned long long, &(clang::ExternalASTSource::GetExternalCXXBaseSpecifiers(unsigned long long))>::LazyOffsetPtr()
Line
Count
Source
359
3.88M
  LazyOffsetPtr() = default;
clang::LazyOffsetPtr<clang::CXXCtorInitializer*, unsigned long long, &(clang::ExternalASTSource::GetExternalCXXCtorInitializers(unsigned long long))>::LazyOffsetPtr()
Line
Count
Source
359
802k
  LazyOffsetPtr() = default;
360
728
  explicit LazyOffsetPtr(T *Ptr) : Ptr(reinterpret_cast<uint64_t>(Ptr)) {}
361
362
  explicit LazyOffsetPtr(uint64_t Offset) : Ptr((Offset << 1) | 0x01) {
363
    assert((Offset << 1 >> 1) == Offset && "Offsets must require < 63 bits");
364
    if (Offset == 0)
365
      Ptr = 0;
366
  }
367
368
3.94M
  LazyOffsetPtr &operator=(T *Ptr) {
369
3.94M
    this->Ptr = reinterpret_cast<uint64_t>(Ptr);
370
3.94M
    return *this;
371
3.94M
  }
clang::LazyOffsetPtr<clang::Stmt, unsigned long long, &(clang::ExternalASTSource::GetExternalDeclStmt(unsigned long long))>::operator=(clang::Stmt*)
Line
Count
Source
368
2.97M
  LazyOffsetPtr &operator=(T *Ptr) {
369
2.97M
    this->Ptr = reinterpret_cast<uint64_t>(Ptr);
370
2.97M
    return *this;
371
2.97M
  }
clang::LazyOffsetPtr<clang::Decl, unsigned int, &(clang::ExternalASTSource::GetExternalDecl(unsigned int))>::operator=(clang::Decl*)
Line
Count
Source
368
101k
  LazyOffsetPtr &operator=(T *Ptr) {
369
101k
    this->Ptr = reinterpret_cast<uint64_t>(Ptr);
370
101k
    return *this;
371
101k
  }
clang::LazyOffsetPtr<clang::CXXCtorInitializer*, unsigned long long, &(clang::ExternalASTSource::GetExternalCXXCtorInitializers(unsigned long long))>::operator=(clang::CXXCtorInitializer**)
Line
Count
Source
368
212k
  LazyOffsetPtr &operator=(T *Ptr) {
369
212k
    this->Ptr = reinterpret_cast<uint64_t>(Ptr);
370
212k
    return *this;
371
212k
  }
clang::LazyOffsetPtr<clang::CXXBaseSpecifier, unsigned long long, &(clang::ExternalASTSource::GetExternalCXXBaseSpecifiers(unsigned long long))>::operator=(clang::CXXBaseSpecifier*)
Line
Count
Source
368
652k
  LazyOffsetPtr &operator=(T *Ptr) {
369
652k
    this->Ptr = reinterpret_cast<uint64_t>(Ptr);
370
652k
    return *this;
371
652k
  }
372
373
38.7k
  LazyOffsetPtr &operator=(uint64_t Offset) {
374
38.7k
    assert((Offset << 1 >> 1) == Offset && "Offsets must require < 63 bits");
375
38.7k
    if (Offset == 0)
376
25.6k
      Ptr = 0;
377
13.1k
    else
378
13.1k
      Ptr = (Offset << 1) | 0x01;
379
38.7k
380
38.7k
    return *this;
381
38.7k
  }
clang::LazyOffsetPtr<clang::Stmt, unsigned long long, &(clang::ExternalASTSource::GetExternalDeclStmt(unsigned long long))>::operator=(unsigned long long)
Line
Count
Source
373
10.2k
  LazyOffsetPtr &operator=(uint64_t Offset) {
374
10.2k
    assert((Offset << 1 >> 1) == Offset && "Offsets must require < 63 bits");
375
10.2k
    if (Offset == 0)
376
0
      Ptr = 0;
377
10.2k
    else
378
10.2k
      Ptr = (Offset << 1) | 0x01;
379
10.2k
380
10.2k
    return *this;
381
10.2k
  }
clang::LazyOffsetPtr<clang::Decl, unsigned int, &(clang::ExternalASTSource::GetExternalDecl(unsigned int))>::operator=(unsigned long long)
Line
Count
Source
373
26.0k
  LazyOffsetPtr &operator=(uint64_t Offset) {
374
26.0k
    assert((Offset << 1 >> 1) == Offset && "Offsets must require < 63 bits");
375
26.0k
    if (Offset == 0)
376
25.6k
      Ptr = 0;
377
433
    else
378
433
      Ptr = (Offset << 1) | 0x01;
379
26.0k
380
26.0k
    return *this;
381
26.0k
  }
clang::LazyOffsetPtr<clang::CXXCtorInitializer*, unsigned long long, &(clang::ExternalASTSource::GetExternalCXXCtorInitializers(unsigned long long))>::operator=(unsigned long long)
Line
Count
Source
373
1.96k
  LazyOffsetPtr &operator=(uint64_t Offset) {
374
1.96k
    assert((Offset << 1 >> 1) == Offset && "Offsets must require < 63 bits");
375
1.96k
    if (Offset == 0)
376
0
      Ptr = 0;
377
1.96k
    else
378
1.96k
      Ptr = (Offset << 1) | 0x01;
379
1.96k
380
1.96k
    return *this;
381
1.96k
  }
clang::LazyOffsetPtr<clang::CXXBaseSpecifier, unsigned long long, &(clang::ExternalASTSource::GetExternalCXXBaseSpecifiers(unsigned long long))>::operator=(unsigned long long)
Line
Count
Source
373
496
  LazyOffsetPtr &operator=(uint64_t Offset) {
374
496
    assert((Offset << 1 >> 1) == Offset && "Offsets must require < 63 bits");
375
496
    if (Offset == 0)
376
0
      Ptr = 0;
377
496
    else
378
496
      Ptr = (Offset << 1) | 0x01;
379
496
380
496
    return *this;
381
496
  }
382
383
  /// Whether this pointer is non-NULL.
384
  ///
385
  /// This operation does not require the AST node to be deserialized.
386
37.5M
  explicit operator bool() const { return Ptr != 0; }
clang::LazyOffsetPtr<clang::Stmt, unsigned long long, &(clang::ExternalASTSource::GetExternalDeclStmt(unsigned long long))>::operator bool() const
Line
Count
Source
386
36.8M
  explicit operator bool() const { return Ptr != 0; }
clang::LazyOffsetPtr<clang::Decl, unsigned int, &(clang::ExternalASTSource::GetExternalDecl(unsigned int))>::operator bool() const
Line
Count
Source
386
692k
  explicit operator bool() const { return Ptr != 0; }
387
388
  /// Whether this pointer is non-NULL.
389
  ///
390
  /// This operation does not require the AST node to be deserialized.
391
309k
  bool isValid() const { return Ptr != 0; }
clang::LazyOffsetPtr<clang::Stmt, unsigned long long, &(clang::ExternalASTSource::GetExternalDeclStmt(unsigned long long))>::isValid() const
Line
Count
Source
391
227k
  bool isValid() const { return Ptr != 0; }
clang::LazyOffsetPtr<clang::Decl, unsigned int, &(clang::ExternalASTSource::GetExternalDecl(unsigned int))>::isValid() const
Line
Count
Source
391
82.6k
  bool isValid() const { return Ptr != 0; }
392
393
  /// Whether this pointer is currently stored as an offset.
394
103M
  bool isOffset() const { return Ptr & 0x01; }
clang::LazyOffsetPtr<clang::CXXBaseSpecifier, unsigned long long, &(clang::ExternalASTSource::GetExternalCXXBaseSpecifiers(unsigned long long))>::isOffset() const
Line
Count
Source
394
97.3M
  bool isOffset() const { return Ptr & 0x01; }
clang::LazyOffsetPtr<clang::Decl, unsigned int, &(clang::ExternalASTSource::GetExternalDecl(unsigned int))>::isOffset() const
Line
Count
Source
394
689k
  bool isOffset() const { return Ptr & 0x01; }
clang::LazyOffsetPtr<clang::Stmt, unsigned long long, &(clang::ExternalASTSource::GetExternalDeclStmt(unsigned long long))>::isOffset() const
Line
Count
Source
394
4.64M
  bool isOffset() const { return Ptr & 0x01; }
clang::LazyOffsetPtr<clang::CXXCtorInitializer*, unsigned long long, &(clang::ExternalASTSource::GetExternalCXXCtorInitializers(unsigned long long))>::isOffset() const
Line
Count
Source
394
381k
  bool isOffset() const { return Ptr & 0x01; }
395
396
  /// Retrieve the pointer to the AST node that this lazy pointer points to.
397
  ///
398
  /// \param Source the external AST source.
399
  ///
400
  /// \returns a pointer to the AST node.
401
53.9M
  T* get(ExternalASTSource *Source) const {
402
53.9M
    if (isOffset()) {
403
9.90k
      assert(Source &&
404
9.90k
             "Cannot deserialize a lazy pointer without an AST source");
405
9.90k
      Ptr = reinterpret_cast<uint64_t>((Source->*Get)(Ptr >> 1));
406
9.90k
    }
407
53.9M
    return reinterpret_cast<T*>(Ptr);
408
53.9M
  }
clang::LazyOffsetPtr<clang::CXXBaseSpecifier, unsigned long long, &(clang::ExternalASTSource::GetExternalCXXBaseSpecifiers(unsigned long long))>::get(clang::ExternalASTSource*) const
Line
Count
Source
401
48.3M
  T* get(ExternalASTSource *Source) const {
402
48.3M
    if (isOffset()) {
403
333
      assert(Source &&
404
333
             "Cannot deserialize a lazy pointer without an AST source");
405
333
      Ptr = reinterpret_cast<uint64_t>((Source->*Get)(Ptr >> 1));
406
333
    }
407
48.3M
    return reinterpret_cast<T*>(Ptr);
408
48.3M
  }
clang::LazyOffsetPtr<clang::Decl, unsigned int, &(clang::ExternalASTSource::GetExternalDecl(unsigned int))>::get(clang::ExternalASTSource*) const
Line
Count
Source
401
567k
  T* get(ExternalASTSource *Source) const {
402
567k
    if (isOffset()) {
403
66
      assert(Source &&
404
66
             "Cannot deserialize a lazy pointer without an AST source");
405
66
      Ptr = reinterpret_cast<uint64_t>((Source->*Get)(Ptr >> 1));
406
66
    }
407
567k
    return reinterpret_cast<T*>(Ptr);
408
567k
  }
clang::LazyOffsetPtr<clang::Stmt, unsigned long long, &(clang::ExternalASTSource::GetExternalDeclStmt(unsigned long long))>::get(clang::ExternalASTSource*) const
Line
Count
Source
401
4.64M
  T* get(ExternalASTSource *Source) const {
402
4.64M
    if (isOffset()) {
403
8.21k
      assert(Source &&
404
8.21k
             "Cannot deserialize a lazy pointer without an AST source");
405
8.21k
      Ptr = reinterpret_cast<uint64_t>((Source->*Get)(Ptr >> 1));
406
8.21k
    }
407
4.64M
    return reinterpret_cast<T*>(Ptr);
408
4.64M
  }
clang::LazyOffsetPtr<clang::CXXCtorInitializer*, unsigned long long, &(clang::ExternalASTSource::GetExternalCXXCtorInitializers(unsigned long long))>::get(clang::ExternalASTSource*) const
Line
Count
Source
401
381k
  T* get(ExternalASTSource *Source) const {
402
381k
    if (isOffset()) {
403
1.29k
      assert(Source &&
404
1.29k
             "Cannot deserialize a lazy pointer without an AST source");
405
1.29k
      Ptr = reinterpret_cast<uint64_t>((Source->*Get)(Ptr >> 1));
406
1.29k
    }
407
381k
    return reinterpret_cast<T*>(Ptr);
408
381k
  }
409
};
410
411
/// A lazy value (of type T) that is within an AST node of type Owner,
412
/// where the value might change in later generations of the external AST
413
/// source.
414
template<typename Owner, typename T, void (ExternalASTSource::*Update)(Owner)>
415
struct LazyGenerationalUpdatePtr {
416
  /// A cache of the value of this pointer, in the most recent generation in
417
  /// which we queried it.
418
  struct LazyData {
419
    ExternalASTSource *ExternalSource;
420
    uint32_t LastGeneration = 0;
421
    T LastValue;
422
423
    LazyData(ExternalASTSource *Source, T Value)
424
481k
        : ExternalSource(Source), LastValue(Value) {}
425
  };
426
427
  // Our value is represented as simply T if there is no external AST source.
428
  using ValueType = llvm::PointerUnion<T, LazyData*>;
429
  ValueType Value;
430
431
416M
  LazyGenerationalUpdatePtr(ValueType V) : Value(V) {}
432
433
  // Defined in ASTContext.h
434
  static ValueType makeValue(const ASTContext &Ctx, T Value);
435
436
public:
437
  explicit LazyGenerationalUpdatePtr(const ASTContext &Ctx, T Value = T())
438
20.5M
      : Value(makeValue(Ctx, Value)) {}
439
440
  /// Create a pointer that is not potentially updated by later generations of
441
  /// the external AST source.
442
  enum NotUpdatedTag { NotUpdated };
443
  LazyGenerationalUpdatePtr(NotUpdatedTag, T Value = T())
444
      : Value(Value) {}
445
446
  /// Forcibly set this pointer (which must be lazy) as needing updates.
447
5.35k
  void markIncomplete() {
448
5.35k
    Value.template get<LazyData *>()->LastGeneration = 0;
449
5.35k
  }
450
451
  /// Set the value of this pointer, in the current generation.
452
1.64M
  void set(T NewValue) {
453
1.64M
    if (auto *LazyVal = Value.template dyn_cast<LazyData *>()) {
454
42.2k
      LazyVal->LastValue = NewValue;
455
42.2k
      return;
456
42.2k
    }
457
1.60M
    Value = NewValue;
458
1.60M
  }
459
460
  /// Set the value of this pointer, for this and all future generations.
461
  void setNotUpdated(T NewValue) { Value = NewValue; }
462
463
  /// Get the value of this pointer, updating its owner if necessary.
464
414M
  T get(Owner O) {
465
414M
    if (auto *LazyVal = Value.template dyn_cast<LazyData *>()) {
466
4.24M
      if (LazyVal->LastGeneration != LazyVal->ExternalSource->getGeneration()) {
467
95.6k
        LazyVal->LastGeneration = LazyVal->ExternalSource->getGeneration();
468
95.6k
        (LazyVal->ExternalSource->*Update)(O);
469
95.6k
      }
470
4.24M
      return LazyVal->LastValue;
471
4.24M
    }
472
410M
    return Value.template get<T>();
473
410M
  }
474
475
  /// Get the most recently computed value of this pointer without updating it.
476
8.30k
  T getNotUpdated() const {
477
8.30k
    if (auto *LazyVal = Value.template dyn_cast<LazyData *>())
478
8.30k
      return LazyVal->LastValue;
479
0
    return Value.template get<T>();
480
0
  }
481
482
22.2M
  void *getOpaqueValue() { return Value.getOpaqueValue(); }
483
416M
  static LazyGenerationalUpdatePtr getFromOpaqueValue(void *Ptr) {
484
416M
    return LazyGenerationalUpdatePtr(ValueType::getFromOpaqueValue(Ptr));
485
416M
  }
486
};
487
488
} // namespace clang
489
490
/// Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be
491
/// placed into a PointerUnion.
492
namespace llvm {
493
494
template<typename Owner, typename T,
495
         void (clang::ExternalASTSource::*Update)(Owner)>
496
struct PointerLikeTypeTraits<
497
    clang::LazyGenerationalUpdatePtr<Owner, T, Update>> {
498
  using Ptr = clang::LazyGenerationalUpdatePtr<Owner, T, Update>;
499
500
22.2M
  static void *getAsVoidPointer(Ptr P) { return P.getOpaqueValue(); }
501
416M
  static Ptr getFromVoidPointer(void *P) { return Ptr::getFromOpaqueValue(P); }
502
503
  enum {
504
    NumLowBitsAvailable = PointerLikeTypeTraits<T>::NumLowBitsAvailable - 1
505
  };
506
};
507
508
} // namespace llvm
509
510
namespace clang {
511
512
/// Represents a lazily-loaded vector of data.
513
///
514
/// The lazily-loaded vector of data contains data that is partially loaded
515
/// from an external source and partially added by local translation. The 
516
/// items loaded from the external source are loaded lazily, when needed for
517
/// iteration over the complete vector.
518
template<typename T, typename Source, 
519
         void (Source::*Loader)(SmallVectorImpl<T>&),
520
         unsigned LoadedStorage = 2, unsigned LocalStorage = 4>
521
class LazyVector {
522
  SmallVector<T, LoadedStorage> Loaded;
523
  SmallVector<T, LocalStorage> Local;
524
525
public:
526
  /// Iteration over the elements in the vector.
527
  ///
528
  /// In a complete iteration, the iterator walks the range [-M, N),
529
  /// where negative values are used to indicate elements
530
  /// loaded from the external source while non-negative values are used to
531
  /// indicate elements added via \c push_back().
532
  /// However, to provide iteration in source order (for, e.g., chained
533
  /// precompiled headers), dereferencing the iterator flips the negative
534
  /// values (corresponding to loaded entities), so that position -M
535
  /// corresponds to element 0 in the loaded entities vector, position -M+1
536
  /// corresponds to element 1 in the loaded entities vector, etc. This
537
  /// gives us a reasonably efficient, source-order walk.
538
  ///
539
  /// We define this as a wrapping iterator around an int. The
540
  /// iterator_adaptor_base class forwards the iterator methods to basic integer
541
  /// arithmetic.
542
  class iterator
543
      : public llvm::iterator_adaptor_base<
544
            iterator, int, std::random_access_iterator_tag, T, int, T *, T &> {
545
    friend class LazyVector;
546
547
    LazyVector *Self;
548
549
    iterator(LazyVector *Self, int Position)
550
283k
        : iterator::iterator_adaptor_base(Position), Self(Self) {}
clang::LazyVector<clang::VarDecl*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadTentativeDefinitions(llvm::SmallVectorImpl<clang::VarDecl*>&)), 2u, 2u>::iterator::iterator(clang::LazyVector<clang::VarDecl*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadTentativeDefinitions(llvm::SmallVectorImpl<clang::VarDecl*>&)), 2u, 2u>*, int)
Line
Count
Source
550
73.7k
        : iterator::iterator_adaptor_base(Position), Self(Self) {}
clang::LazyVector<clang::DeclaratorDecl const*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadUnusedFileScopedDecls(llvm::SmallVectorImpl<clang::DeclaratorDecl const*>&)), 2u, 2u>::iterator::iterator(clang::LazyVector<clang::DeclaratorDecl const*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadUnusedFileScopedDecls(llvm::SmallVectorImpl<clang::DeclaratorDecl const*>&)), 2u, 2u>*, int)
Line
Count
Source
550
163k
        : iterator::iterator_adaptor_base(Position), Self(Self) {}
clang::LazyVector<clang::CXXConstructorDecl*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadDelegatingConstructors(llvm::SmallVectorImpl<clang::CXXConstructorDecl*>&)), 2u, 2u>::iterator::iterator(clang::LazyVector<clang::CXXConstructorDecl*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadDelegatingConstructors(llvm::SmallVectorImpl<clang::CXXConstructorDecl*>&)), 2u, 2u>*, int)
Line
Count
Source
550
39.5k
        : iterator::iterator_adaptor_base(Position), Self(Self) {}
clang::LazyVector<clang::TypedefNameDecl*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadExtVectorDecls(llvm::SmallVectorImpl<clang::TypedefNameDecl*>&)), 2u, 2u>::iterator::iterator(clang::LazyVector<clang::TypedefNameDecl*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadExtVectorDecls(llvm::SmallVectorImpl<clang::TypedefNameDecl*>&)), 2u, 2u>*, int)
Line
Count
Source
550
7.17k
        : iterator::iterator_adaptor_base(Position), Self(Self) {}
551
552
196k
    bool isLoaded() const { return this->I < 0; }
clang::LazyVector<clang::VarDecl*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadTentativeDefinitions(llvm::SmallVectorImpl<clang::VarDecl*>&)), 2u, 2u>::iterator::isLoaded() const
Line
Count
Source
552
19.1k
    bool isLoaded() const { return this->I < 0; }
clang::LazyVector<clang::DeclaratorDecl const*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadUnusedFileScopedDecls(llvm::SmallVectorImpl<clang::DeclaratorDecl const*>&)), 2u, 2u>::iterator::isLoaded() const
Line
Count
Source
552
176k
    bool isLoaded() const { return this->I < 0; }
clang::LazyVector<clang::CXXConstructorDecl*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadDelegatingConstructors(llvm::SmallVectorImpl<clang::CXXConstructorDecl*>&)), 2u, 2u>::iterator::isLoaded() const
Line
Count
Source
552
131
    bool isLoaded() const { return this->I < 0; }
clang::LazyVector<clang::TypedefNameDecl*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadExtVectorDecls(llvm::SmallVectorImpl<clang::TypedefNameDecl*>&)), 2u, 2u>::iterator::isLoaded() const
Line
Count
Source
552
566
    bool isLoaded() const { return this->I < 0; }
553
554
  public:
555
    iterator() : iterator(nullptr, 0) {}
556
557
125k
    typename iterator::reference operator*() const {
558
125k
      if (isLoaded())
559
1.01k
        return Self->Loaded.end()[this->I];
560
124k
      return Self->Local.begin()[this->I];
561
124k
    }
clang::LazyVector<clang::VarDecl*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadTentativeDefinitions(llvm::SmallVectorImpl<clang::VarDecl*>&)), 2u, 2u>::iterator::operator*() const
Line
Count
Source
557
19.1k
    typename iterator::reference operator*() const {
558
19.1k
      if (isLoaded())
559
988
        return Self->Loaded.end()[this->I];
560
18.2k
      return Self->Local.begin()[this->I];
561
18.2k
    }
clang::LazyVector<clang::DeclaratorDecl const*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadUnusedFileScopedDecls(llvm::SmallVectorImpl<clang::DeclaratorDecl const*>&)), 2u, 2u>::iterator::operator*() const
Line
Count
Source
557
105k
    typename iterator::reference operator*() const {
558
105k
      if (isLoaded())
559
17
        return Self->Loaded.end()[this->I];
560
105k
      return Self->Local.begin()[this->I];
561
105k
    }
clang::LazyVector<clang::CXXConstructorDecl*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadDelegatingConstructors(llvm::SmallVectorImpl<clang::CXXConstructorDecl*>&)), 2u, 2u>::iterator::operator*() const
Line
Count
Source
557
131
    typename iterator::reference operator*() const {
558
131
      if (isLoaded())
559
3
        return Self->Loaded.end()[this->I];
560
128
      return Self->Local.begin()[this->I];
561
128
    }
clang::LazyVector<clang::TypedefNameDecl*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadExtVectorDecls(llvm::SmallVectorImpl<clang::TypedefNameDecl*>&)), 2u, 2u>::iterator::operator*() const
Line
Count
Source
557
566
    typename iterator::reference operator*() const {
558
566
      if (isLoaded())
559
4
        return Self->Loaded.end()[this->I];
560
562
      return Self->Local.begin()[this->I];
561
562
    }
562
  };
563
564
124k
  iterator begin(Source *source, bool LocalOnly = false) {
565
124k
    if (LocalOnly)
566
46.5k
      return iterator(this, 0);
567
77.4k
    
568
77.4k
    if (source)
569
10.2k
      (source->*Loader)(Loaded);
570
77.4k
    return iterator(this, -(int)Loaded.size());
571
77.4k
  }
clang::LazyVector<clang::VarDecl*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadTentativeDefinitions(llvm::SmallVectorImpl<clang::VarDecl*>&)), 2u, 2u>::begin(clang::ExternalSemaSource*, bool)
Line
Count
Source
564
36.8k
  iterator begin(Source *source, bool LocalOnly = false) {
565
36.8k
    if (LocalOnly)
566
3.45k
      return iterator(this, 0);
567
33.4k
    
568
33.4k
    if (source)
569
4.48k
      (source->*Loader)(Loaded);
570
33.4k
    return iterator(this, -(int)Loaded.size());
571
33.4k
  }
clang::LazyVector<clang::DeclaratorDecl const*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadUnusedFileScopedDecls(llvm::SmallVectorImpl<clang::DeclaratorDecl const*>&)), 2u, 2u>::begin(clang::ExternalSemaSource*, bool)
Line
Count
Source
564
63.7k
  iterator begin(Source *source, bool LocalOnly = false) {
565
63.7k
    if (LocalOnly)
566
37.6k
      return iterator(this, 0);
567
26.1k
    
568
26.1k
    if (source)
569
2.67k
      (source->*Loader)(Loaded);
570
26.1k
    return iterator(this, -(int)Loaded.size());
571
26.1k
  }
clang::LazyVector<clang::CXXConstructorDecl*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadDelegatingConstructors(llvm::SmallVectorImpl<clang::CXXConstructorDecl*>&)), 2u, 2u>::begin(clang::ExternalSemaSource*, bool)
Line
Count
Source
564
19.7k
  iterator begin(Source *source, bool LocalOnly = false) {
565
19.7k
    if (LocalOnly)
566
2.06k
      return iterator(this, 0);
567
17.7k
    
568
17.7k
    if (source)
569
3.11k
      (source->*Loader)(Loaded);
570
17.7k
    return iterator(this, -(int)Loaded.size());
571
17.7k
  }
clang::LazyVector<clang::TypedefNameDecl*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadExtVectorDecls(llvm::SmallVectorImpl<clang::TypedefNameDecl*>&)), 2u, 2u>::begin(clang::ExternalSemaSource*, bool)
Line
Count
Source
564
3.58k
  iterator begin(Source *source, bool LocalOnly = false) {
565
3.58k
    if (LocalOnly)
566
3.45k
      return iterator(this, 0);
567
132
    
568
132
    if (source)
569
2
      (source->*Loader)(Loaded);
570
132
    return iterator(this, -(int)Loaded.size());
571
132
  }
572
  
573
159k
  iterator end() {
574
159k
    return iterator(this, Local.size());
575
159k
  }
clang::LazyVector<clang::VarDecl*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadTentativeDefinitions(llvm::SmallVectorImpl<clang::VarDecl*>&)), 2u, 2u>::end()
Line
Count
Source
573
36.8k
  iterator end() {
574
36.8k
    return iterator(this, Local.size());
575
36.8k
  }
clang::LazyVector<clang::DeclaratorDecl const*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadUnusedFileScopedDecls(llvm::SmallVectorImpl<clang::DeclaratorDecl const*>&)), 2u, 2u>::end()
Line
Count
Source
573
99.3k
  iterator end() {
574
99.3k
    return iterator(this, Local.size());
575
99.3k
  }
clang::LazyVector<clang::CXXConstructorDecl*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadDelegatingConstructors(llvm::SmallVectorImpl<clang::CXXConstructorDecl*>&)), 2u, 2u>::end()
Line
Count
Source
573
19.7k
  iterator end() {
574
19.7k
    return iterator(this, Local.size());
575
19.7k
  }
clang::LazyVector<clang::TypedefNameDecl*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadExtVectorDecls(llvm::SmallVectorImpl<clang::TypedefNameDecl*>&)), 2u, 2u>::end()
Line
Count
Source
573
3.58k
  iterator end() {
574
3.58k
    return iterator(this, Local.size());
575
3.58k
  }
576
  
577
46.3k
  void push_back(const T& LocalValue) {
578
46.3k
    Local.push_back(LocalValue);
579
46.3k
  }
clang::LazyVector<clang::DeclaratorDecl const*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadUnusedFileScopedDecls(llvm::SmallVectorImpl<clang::DeclaratorDecl const*>&)), 2u, 2u>::push_back(clang::DeclaratorDecl const* const&)
Line
Count
Source
577
26.7k
  void push_back(const T& LocalValue) {
578
26.7k
    Local.push_back(LocalValue);
579
26.7k
  }
clang::LazyVector<clang::VarDecl*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadTentativeDefinitions(llvm::SmallVectorImpl<clang::VarDecl*>&)), 2u, 2u>::push_back(clang::VarDecl* const&)
Line
Count
Source
577
17.8k
  void push_back(const T& LocalValue) {
578
17.8k
    Local.push_back(LocalValue);
579
17.8k
  }
clang::LazyVector<clang::TypedefNameDecl*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadExtVectorDecls(llvm::SmallVectorImpl<clang::TypedefNameDecl*>&)), 2u, 2u>::push_back(clang::TypedefNameDecl* const&)
Line
Count
Source
577
1.67k
  void push_back(const T& LocalValue) {
578
1.67k
    Local.push_back(LocalValue);
579
1.67k
  }
clang::LazyVector<clang::CXXConstructorDecl*, clang::ExternalSemaSource, &(clang::ExternalSemaSource::ReadDelegatingConstructors(llvm::SmallVectorImpl<clang::CXXConstructorDecl*>&)), 2u, 2u>::push_back(clang::CXXConstructorDecl* const&)
Line
Count
Source
577
128
  void push_back(const T& LocalValue) {
578
128
    Local.push_back(LocalValue);
579
128
  }
580
  
581
35.5k
  void erase(iterator From, iterator To) {
582
35.5k
    if (From.isLoaded() && 
To.isLoaded()0
) {
583
0
      Loaded.erase(&*From, &*To);
584
0
      return;
585
0
    }
586
35.5k
587
35.5k
    if (From.isLoaded()) {
588
0
      Loaded.erase(&*From, Loaded.end());
589
0
      From = begin(nullptr, true);
590
0
    }
591
35.5k
592
35.5k
    Local.erase(&*From, &*To);
593
35.5k
  }
594
};
595
596
/// A lazy pointer to a statement.
597
using LazyDeclStmtPtr =
598
    LazyOffsetPtr<Stmt, uint64_t, &ExternalASTSource::GetExternalDeclStmt>;
599
600
/// A lazy pointer to a declaration.
601
using LazyDeclPtr =
602
    LazyOffsetPtr<Decl, uint32_t, &ExternalASTSource::GetExternalDecl>;
603
604
/// A lazy pointer to a set of CXXCtorInitializers.
605
using LazyCXXCtorInitializersPtr =
606
    LazyOffsetPtr<CXXCtorInitializer *, uint64_t,
607
                  &ExternalASTSource::GetExternalCXXCtorInitializers>;
608
609
/// A lazy pointer to a set of CXXBaseSpecifiers.
610
using LazyCXXBaseSpecifiersPtr =
611
    LazyOffsetPtr<CXXBaseSpecifier, uint64_t,
612
                  &ExternalASTSource::GetExternalCXXBaseSpecifiers>;
613
614
} // namespace clang
615
616
#endif // LLVM_CLANG_AST_EXTERNALASTSOURCE_H