clang: include/clang/AST/ExternalASTSource.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_CLANG_AST_EXTERNALASTSOURCE_H

15#define LLVM_CLANG_AST_EXTERNALASTSOURCE_H

16

20#include "llvm/ADT/ArrayRef.h"

21#include "llvm/ADT/DenseMap.h"

22#include "llvm/ADT/IntrusiveRefCntPtr.h"

23#include "llvm/ADT/PointerUnion.h"

24#include "llvm/ADT/STLExtras.h"

25#include "llvm/ADT/SmallVector.h"

26#include "llvm/ADT/iterator.h"

27#include "llvm/Support/PointerLikeTypeTraits.h"

28#include

29#include

30#include

31#include

32#include

33#include

34#include

35#include

36

38

55

56

57

58

59

60

61

62

65

66

67

68 uint32_t CurrentGeneration = 0;

69

70

71 static char ID;

72

73public:

76

77

78

81

82 public:

84 assert(Source);

85 Source->StartedDeserializing();

86 }

87

89 Source->FinishedDeserializing();

90 }

91 };

92

93

94

95

96 uint32_t getGeneration() const { return CurrentGeneration; }

97

98

99

100

101

102

103

104

106

107

108

109

110

111

112

114

115

116

117

118

120

121

122

123

124

125

126

127

128

130

131

132

133

134

136

137

138

139

140

142

143

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

163

164

165

166

167

168

170

171

172

173

174

175 virtual bool

178

179

180

181

182

184

185

187

188

189 virtual std::optional getSourceDescriptor(unsigned ID);

190

192

194

195

196

198

199

200

201

202

203

204

205

206 virtual void

208 llvm::function_ref<bool(Decl::Kind)> IsKindWeWant,

210

211

212

217

218

219

220

222 unsigned Length,

224

225

226

227

228

230

231

232

234

235

236

237

238

239

240

242

243

245

246

247

248

249

250

252

253

254

255

256

258

259

260

261

262

264

265

266

267

268

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

299 const RecordDecl *Record, uint64_t &Size, uint64_t &Alignment,

300 llvm::DenseMap<const FieldDecl *, uint64_t> &FieldOffsets,

301 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &BaseOffsets,

302 llvm::DenseMap<const CXXRecordDecl *, CharUnits> &VirtualBaseOffsets);

303

304

305

306

307

315

316

317

323

325

326

327

328 virtual bool isA(const void *ClassID) const { return ClassID == &ID; }

330

331

332protected:

337

341

342

344};

345

346

347

348

349

350

351

352template<typename T, typename OffsT, T* (ExternalASTSource::*Get)(OffsT Offset)>

354

355

356

357

358

359 static constexpr size_t DataSize = std::max(sizeof(uint64_t), sizeof(T *));

360 alignas(uint64_t) alignas(T *) mutable unsigned char Data[DataSize] = {};

361

363 return Data[llvm::sys::IsBigEndianHost ? DataSize - 1 : 0];

364 }

365

366 template U &As(bool New) const {

367 unsigned char *Obj =

368 Data + (llvm::sys::IsBigEndianHost ? DataSize - sizeof(U) : 0);

370 return *new (Obj) U;

371 return *std::launder(reinterpret_cast<U *>(Obj));

372 }

373

378

379public:

382

384 assert((Offset << 1 >> 1) == Offset && "Offsets must require < 63 bits");

385 if (Offset == 0)

387 else

388 SetU64((Offset << 1) | 0x01);

389 }

390

395

397 assert((Offset << 1 >> 1) == Offset && "Offsets must require < 63 bits");

398 if (Offset == 0)

400 else

401 SetU64((Offset << 1) | 0x01);

402

403 return *this;

404 }

405

406

407

408

410

411

412

413

415

416

418

419

420

421

422

423

426 assert(Source &&

427 "Cannot deserialize a lazy pointer without an AST source");

428 SetPtr((Source->*Get)(OffsT(GetU64() >> 1)));

429 }

431 }

432

433

434

436

437 (void)get(Source);

439 }

440};

441

442

443

444

445template<typename Owner, typename T, void (ExternalASTSource::*Update)(Owner)>

447

448

457

458

459 using ValueType = llvm::PointerUnion<T, LazyData*>;

461

463

464

466

467public:

470

471

472

476

477

479

480

482 if (auto *LazyVal = Value.template dyn_cast<LazyData *>()) {

483 LazyVal->LastValue = NewValue;

484 return;

485 }

486 Value = NewValue;

487 }

488

489

491

492

494 if (auto *LazyVal = Value.template dyn_cast<LazyData *>()) {

495 if (LazyVal->LastGeneration != LazyVal->ExternalSource->getGeneration()) {

496 LazyVal->LastGeneration = LazyVal->ExternalSource->getGeneration();

497 (LazyVal->ExternalSource->*Update)(O);

498 }

499 return LazyVal->LastValue;

500 }

502 }

503

504

506 if (auto *LazyVal = Value.template dyn_cast<LazyData *>())

507 return LazyVal->LastValue;

509 }

510

515};

516

517}

518

519namespace llvm {

520

521

522

523template<typename Owner, typename T,

524 void (clang::ExternalASTSource::*Update)(Owner)>

535

536}

537

539

540

541

542

543

544

545

546template<typename T, typename Source,

547 void (Source::*Loader)(SmallVectorImpl&),

548 unsigned LoadedStorage = 2, unsigned LocalStorage = 4>

552

553public:

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570 class iterator

571 : public llvm::iterator_adaptor_base<

572 iterator, int, std::random_access_iterator_tag, T, int, T *, T &> {

574

576

577 iterator(LazyVector *Self, int Position)

578 : iterator::iterator_adaptor_base(Position), Self(Self) {}

579

580 bool isLoaded() const { return this->I < 0; }

581

582 public:

584

585 typename iterator::reference operator*() const {

586 if (isLoaded())

587 return Self->Loaded.end()[this->I];

588 return Self->Local.begin()[this->I];

589 }

590 };

591

592 iterator begin(Source *source, bool LocalOnly = false) {

593 if (LocalOnly)

594 return iterator(this, 0);

595

596 if (source)

597 (source->*Loader)(Loaded);

598 return iterator(this, -(int)Loaded.size());

599 }

600

602 return iterator(this, Local.size());

603 }

604

606 Local.push_back(LocalValue);

607 }

608

609 void erase(iterator From, iterator To) {

610 if (From.isLoaded() && To.isLoaded()) {

611 Loaded.erase(&*From, &*To);

612 return;

613 }

614

615 if (From.isLoaded()) {

616 Loaded.erase(&*From, Loaded.end());

617 From = begin(nullptr, true);

618 }

619

620 Local.erase(&*From, &*To);

621 }

622};

623

624

627

628

631

632

636

637

641

642}

643

644#endif

Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.

llvm::MachO::Record Record

ASTConsumer - This is an abstract interface that should be implemented by clients that read ASTs.

Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...

Abstracts clang modules and precompiled header files and holds everything needed to generate debug in...

Represents a base class of a C++ class.

Represents a C++ base or member initializer.

Represents a C++ struct/union/class.

The results of name lookup within a DeclContext.

DeclContext - This is used only as base class of specific decl types that can act as declaration cont...

Decl - This represents one declaration (or definition), e.g.

Kind

Lists the kind of concrete classes of Decl.

The name of a declaration.

Deserializing(ExternalASTSource *source)

Definition ExternalASTSource.h:83

~Deserializing()

Definition ExternalASTSource.h:88

Abstract interface for external sources of AST nodes.

Definition ExternalASTSource.h:63

static bool classof(const ExternalASTSource *S)

Definition ExternalASTSource.h:329

virtual ExtKind hasExternalDefinitions(const Decl *D)

virtual void StartTranslationUnit(ASTConsumer *Consumer)

Function that will be invoked when we begin parsing a new translation unit involving this external AS...

virtual std::optional< ASTSourceDescriptor > getSourceDescriptor(unsigned ID)

Return a descriptor for the corresponding module, if one exists.

static DeclContextLookupResult SetExternalVisibleDeclsForName(const DeclContext *DC, DeclarationName Name, ArrayRef< NamedDecl * > Decls)

virtual bool isA(const void *ClassID) const

LLVM-style RTTI.

Definition ExternalASTSource.h:328

MemoryBufferSizes getMemoryBufferSizes() const

Return the amount of memory used by memory buffers, breaking down by heap-backed versus mmap'ed memor...

Definition ExternalASTSource.h:318

uint32_t incrementGeneration(ASTContext &C)

Increment the current generation.

static DeclContextLookupResult SetNoExternalVisibleDeclsForName(const DeclContext *DC, DeclarationName Name)

virtual Module * getModule(unsigned ID)

Retrieve the module that corresponds to the given module ID.

Definition ExternalASTSource.h:186

virtual CXXCtorInitializer ** GetExternalCXXCtorInitializers(uint64_t Offset)

Resolve the offset of a set of C++ constructor initializers in the decl stream into an array of initi...

virtual void FinishedDeserializing()

Notify ExternalASTSource that we finished the deserialization of a decl or type.

virtual Selector GetExternalSelector(uint32_t ID)

Resolve a selector ID into a selector.

virtual uint32_t GetNumExternalSelectors()

Returns the number of selectors known to the external AST source.

ExtKind

Definition ExternalASTSource.h:191

@ EK_ReplyHazy

Definition ExternalASTSource.h:191

@ EK_Never

Definition ExternalASTSource.h:191

@ EK_Always

Definition ExternalASTSource.h:191

void FindExternalLexicalDecls(const DeclContext *DC, SmallVectorImpl< Decl * > &Result)

Finds all declarations lexically contained within the given DeclContext.

Definition ExternalASTSource.h:213

virtual ~ExternalASTSource()

virtual void ReadComments()

Loads comment ranges.

virtual bool wasThisDeclarationADefinition(const FunctionDecl *FD)

True if this function declaration was a definition before in its own module.

virtual void CompleteRedeclChain(const Decl *D)

Gives the external AST source an opportunity to complete the redeclaration chain for a declaration.

virtual void FindFileRegionDecls(FileID File, unsigned Offset, unsigned Length, SmallVectorImpl< Decl * > &Decls)

Get the decls that are contained in a file in the Offset/Length range.

virtual bool LoadExternalSpecializations(const Decl *D, bool OnlyPartial)

Load all the external specializations for the Decl.

virtual Decl * GetExternalDecl(GlobalDeclID ID)

Resolve a declaration ID into a declaration, potentially building a new declaration.

virtual void PrintStats()

Print any statistics that have been gathered regarding the external AST source.

virtual Stmt * GetExternalDeclStmt(uint64_t Offset)

Resolve the offset of a statement in the decl stream into a statement.

virtual void StartedDeserializing()

Notify ExternalASTSource that we started deserialization of a decl or type so until FinishedDeseriali...

virtual CXXBaseSpecifier * GetExternalCXXBaseSpecifiers(uint64_t Offset)

Resolve the offset of a set of C++ base specifiers in the decl stream into an array of specifiers.

uint32_t getGeneration() const

Get the current generation of this AST source.

Definition ExternalASTSource.h:96

virtual bool layoutRecordType(const RecordDecl *Record, uint64_t &Size, uint64_t &Alignment, llvm::DenseMap< const FieldDecl *, uint64_t > &FieldOffsets, llvm::DenseMap< const CXXRecordDecl *, CharUnits > &BaseOffsets, llvm::DenseMap< const CXXRecordDecl *, CharUnits > &VirtualBaseOffsets)

Perform layout on the given record.

virtual bool FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name, const DeclContext *OriginalDC)

Find all declarations with the given name in the given context, and add them to the context by callin...

virtual void CompleteType(TagDecl *Tag)

Gives the external AST source an opportunity to complete an incomplete type.

virtual void completeVisibleDeclsMap(const DeclContext *DC)

Ensures that the table of all visible declarations inside this context is up to date.

friend class ExternalSemaSource

Definition ExternalASTSource.h:64

virtual void updateOutOfDateIdentifier(const IdentifierInfo &II)

Update an out-of-date identifier.

Definition ExternalASTSource.h:144

ExternalASTSource()=default

virtual void FindExternalLexicalDecls(const DeclContext *DC, llvm::function_ref< bool(Decl::Kind)> IsKindWeWant, SmallVectorImpl< Decl * > &Result)

Finds all declarations lexically contained within the given DeclContext, after applying an optional f...

Represents a member of a struct/union/class.

An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...

Represents a function declaration or definition.

One of these records is kept for each identifier that is lexed.

friend class LazyVector

Definition ExternalASTSource.h:573

iterator::reference operator*() const

Definition ExternalASTSource.h:585

iterator()

Definition ExternalASTSource.h:583

Represents a lazily-loaded vector of data.

Definition ExternalASTSource.h:549

void push_back(const T &LocalValue)

Definition ExternalASTSource.h:605

iterator end()

Definition ExternalASTSource.h:601

void erase(iterator From, iterator To)

Definition ExternalASTSource.h:609

iterator begin(Source *source, bool LocalOnly=false)

Definition ExternalASTSource.h:592

Describes a module or submodule.

This represents a decl that may have a name.

Represents an ObjC class declaration.

Represents a struct/union/class.

Smart pointer class that efficiently represents Objective-C method names.

Stmt - This represents one statement.

Represents the declaration of a struct/union/class/enum.

Represents a variable declaration or definition.

The JSON file list parser is used to communicate input to InstallAPI.

LazyOffsetPtr< Stmt, uint64_t, &ExternalASTSource::GetExternalDeclStmt > LazyDeclStmtPtr

A lazy pointer to a statement.

Definition ExternalASTSource.h:625

LazyOffsetPtr< CXXCtorInitializer *, uint64_t, &ExternalASTSource::GetExternalCXXCtorInitializers > LazyCXXCtorInitializersPtr

A lazy pointer to a set of CXXCtorInitializers.

Definition ExternalASTSource.h:633

LazyOffsetPtr< CXXBaseSpecifier, uint64_t, &ExternalASTSource::GetExternalCXXBaseSpecifiers > LazyCXXBaseSpecifiersPtr

A lazy pointer to a set of CXXBaseSpecifiers.

Definition ExternalASTSource.h:638

LazyOffsetPtr< Decl, GlobalDeclID, &ExternalASTSource::GetExternalDecl > LazyDeclPtr

A lazy pointer to a declaration.

Definition ExternalASTSource.h:629

nullptr

This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...

@ Result

The result type of a method or function.

const FunctionProtoType * T

U cast(CodeGen::Address addr)

@ Class

The "class" keyword introduces the elaborated-type-specifier.

Diagnostic wrappers for TextAPI types for error reporting.

MemoryBufferSizes(size_t malloc_bytes, size_t mmap_bytes)

Definition ExternalASTSource.h:312

size_t mmap_bytes

Definition ExternalASTSource.h:310

size_t malloc_bytes

Definition ExternalASTSource.h:309

T LastValue

Definition ExternalASTSource.h:452

LazyData(ExternalASTSource *Source, T Value)

Definition ExternalASTSource.h:454

uint32_t LastGeneration

Definition ExternalASTSource.h:451

ExternalASTSource * ExternalSource

Definition ExternalASTSource.h:450

A lazy value (of type T) that is within an AST node of type Owner, where the value might change in la...

Definition ExternalASTSource.h:446

static ValueType makeValue(const ASTContext &Ctx, T Value)

Create the representation of a LazyGenerationalUpdatePtr.

T getNotUpdated() const

Get the most recently computed value of this pointer without updating it.

Definition ExternalASTSource.h:505

void set(T NewValue)

Set the value of this pointer, in the current generation.

Definition ExternalASTSource.h:481

LazyGenerationalUpdatePtr(ValueType V)

Definition ExternalASTSource.h:462

LazyGenerationalUpdatePtr(const ASTContext &Ctx, T Value=T())

Definition ExternalASTSource.h:468

NotUpdatedTag

Definition ExternalASTSource.h:473

@ NotUpdated

Definition ExternalASTSource.h:473

void setNotUpdated(T NewValue)

Set the value of this pointer, for this and all future generations.

Definition ExternalASTSource.h:490

T get(Owner O)

Get the value of this pointer, updating its owner if necessary.

Definition ExternalASTSource.h:493

void markIncomplete()

Forcibly set this pointer (which must be lazy) as needing updates.

Definition ExternalASTSource.h:478

static LazyGenerationalUpdatePtr getFromOpaqueValue(void *Ptr)

Definition ExternalASTSource.h:512

llvm::PointerUnion< T, LazyData * > ValueType

Definition ExternalASTSource.h:459

void * getOpaqueValue()

Definition ExternalASTSource.h:511

LazyGenerationalUpdatePtr(NotUpdatedTag, T Value=T())

Definition ExternalASTSource.h:474

ValueType Value

Definition ExternalASTSource.h:460

A lazy pointer to an AST node (of base type T) that resides within an external AST source.

Definition ExternalASTSource.h:353

bool isValid() const

Whether this pointer is non-NULL.

Definition ExternalASTSource.h:414

LazyOffsetPtr(uint64_t Offset)

Definition ExternalASTSource.h:383

bool isOffset() const

Whether this pointer is currently stored as an offset.

Definition ExternalASTSource.h:417

LazyOffsetPtr & operator=(T *Ptr)

Definition ExternalASTSource.h:391

T ** getAddressOfPointer(ExternalASTSource *Source) const

Retrieve the address of the AST node pointer.

Definition ExternalASTSource.h:435

void SetU64(uint64_t U64) const

Definition ExternalASTSource.h:377

uint64_t & GetU64() const

Definition ExternalASTSource.h:375

LazyOffsetPtr(T *Ptr)

Definition ExternalASTSource.h:381

LazyOffsetPtr & operator=(uint64_t Offset)

Definition ExternalASTSource.h:396

T * get(ExternalASTSource *Source) const

Retrieve the pointer to the AST node that this lazy pointer points to.

Definition ExternalASTSource.h:424

unsigned char Data[DataSize]

Definition ExternalASTSource.h:360

static constexpr size_t DataSize

Definition ExternalASTSource.h:359

void SetPtr(T *Ptr) const

Definition ExternalASTSource.h:376

unsigned char GetLSB() const

Definition ExternalASTSource.h:362

T *& GetPtr() const

Definition ExternalASTSource.h:374

U & As(bool New) const

Definition ExternalASTSource.h:366

static Ptr getFromVoidPointer(void *P)

Definition ExternalASTSource.h:530

static constexpr int NumLowBitsAvailable

Definition ExternalASTSource.h:532

static void * getAsVoidPointer(Ptr P)

Definition ExternalASTSource.h:529

clang::LazyGenerationalUpdatePtr< Owner, T, Update > Ptr

Definition ExternalASTSource.h:527