Coverage Report

Created: 2020-03-31 06:27

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