clang: include/clang/Lex/PreprocessingRecord.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_CLANG_LEX_PREPROCESSINGRECORD_H

15#define LLVM_CLANG_LEX_PREPROCESSINGRECORD_H

16

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

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

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

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

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

26#include "llvm/Support/Allocator.h"

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

28#include

29#include

30#include

31#include

32#include

33#include

34

36

38

39}

40

41

43 unsigned alignment = 8) noexcept;

44

45

48

50

55

56

57

59 public:

60

62

64

65

67

68

69

70

71

73

74

75

77

78

79

82 };

83

84 private:

85

86 EntityKind Kind;

87

88

90

91 protected:

93

95 : Kind(Kind), Range(Range) {}

96

97 public:

98

100

101

102

104

105

106

108

109

110

112 unsigned alignment = 8) noexcept {

113 return ::operator new(bytes, PR, alignment);

114 }

115

116 void *operator new(size_t bytes, void *mem) noexcept { return mem; }

117

119 unsigned alignment) noexcept {

120 return ::operator delete(ptr, PR, alignment);

121 }

122

123 void operator delete(void *, std::size_t) noexcept {}

124 void operator delete(void *, void *) noexcept {}

125

126 private:

127

128 void *operator new(size_t bytes) noexcept;

129 void operator delete(void *data) noexcept;

130 };

131

132

134 public:

137

138

143 };

144

145

147

149

150 public:

154

155

157

158

160

161

165 };

166

167

169

170

171 llvm::PointerUnion<IdentifierInfo *, MacroDefinitionRecord *> NameOrDef;

172

173 public:

176 NameOrDef(BuiltinName) {}

177

181

182

184

185

191

192

193

197

198

202 };

203

204

205

207 public:

208

209

211

213

214

216

217

219

220

222 };

223

224 private:

225

226

228

229

230

231 LLVM_PREFERRED_TYPE(bool)

232 unsigned InQuotes : 1;

233

234

235

236

238 unsigned Kind : 2;

239

240

241

242 LLVM_PREFERRED_TYPE(bool)

243 unsigned ImportedModule : 1;

244

245

247

248 public:

250 StringRef FileName, bool InQuotes, bool ImportedModule,

252

253

255

256

258

259

260

262

263

264

266

267

268

270

271

275 };

276

277

278

280 public:

282

283

284

285

286

288

289

290

291 virtual std::pair<unsigned, unsigned>

293

294

295

298 return std::nullopt;

299 }

300

301

303 };

304

305

306

307

310

311

312 llvm::BumpPtrAllocator BumpAlloc;

313

314

315

316 std::vector<PreprocessedEntity *> PreprocessedEntities;

317

318

319

320

321

322

323 std::vector<PreprocessedEntity *> LoadedPreprocessedEntities;

324

325

326 std::vector SkippedRanges;

327

328 bool SkippedRangesAllLoaded = true;

329

330

331

332

333

334

335

336

337

338

339 class PPEntityID {

341

342 int ID = 0;

343

344 explicit PPEntityID(int ID) : ID(ID) {}

345

346 public:

347 PPEntityID() = default;

348 };

349

350 static PPEntityID getPPEntityID(unsigned Index, bool isLoaded) {

351 return isLoaded ? PPEntityID(-int(Index)-1) : PPEntityID(Index+1);

352 }

353

354

355 llvm::DenseMap<const MacroInfo *, MacroDefinitionRecord *> MacroDefinitions;

356

357

359

360

362

363

365

366

367

368 unsigned getNumLoadedPreprocessedEntities() const {

369 return LoadedPreprocessedEntities.size();

370 }

371

372

373

374 std::pair<unsigned, unsigned>

375 findLocalPreprocessedEntitiesInRange(SourceRange Range) const;

376 unsigned findBeginLocalPreprocessedEntity(SourceLocation Loc) const;

377 unsigned findEndLocalPreprocessedEntity(SourceLocation Loc) const;

378

379

380

381

382

383 unsigned allocateLoadedEntities(unsigned NumEntities);

384

385

386

387

388

389

390 unsigned allocateSkippedRanges(unsigned NumRanges);

391

392

393 void ensureSkippedRangesLoaded();

394

395

397

398 public:

399

401

402

403 void *Allocate(unsigned Size, unsigned Align = 8) {

404 return BumpAlloc.Allocate(Size, Align);

405 }

406

407

409

411

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430 class iterator : public llvm::iterator_adaptor_base<

431 iterator, int, std::random_access_iterator_tag,

432 PreprocessedEntity *, int, PreprocessedEntity *,

433 PreprocessedEntity *> {

435

437

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

440

441 public:

443

445 bool isLoaded = this->I < 0;

446 unsigned Index = isLoaded ?

447 Self->LoadedPreprocessedEntities.size() + this->I : this->I;

448 PPEntityID ID = Self->getPPEntityID(Index, isLoaded);

449 return Self->getPreprocessedEntity(ID);

450 }

452 };

453

454

456 return iterator(this, -(int)LoadedPreprocessedEntities.size());

457 }

458

459

461 return iterator(this, PreprocessedEntities.size());

462 }

463

464

468

469

471 return iterator(this, PreprocessedEntities.size());

472 }

473

474

475

477 unsigned count) {

478 unsigned end = start + count;

479 assert(end <= LoadedPreprocessedEntities.size());

480 return llvm::make_range(

481 iterator(this, int(start) - LoadedPreprocessedEntities.size()),

482 iterator(this, int(end) - LoadedPreprocessedEntities.size()));

483 }

484

485

486

487

488

489 llvm::iterator_range

491

492

493

494

495

496

497

498

500

501

503

504

506

507

509 return ExternalSource;

510 }

511

512

513

515

516

518 ensureSkippedRangesLoaded();

519 return SkippedRanges;

520 }

521

522 private:

525

532 StringRef FileName, bool IsAngled,

535 StringRef RelativePath,

536 const Module *SuggestedModule, bool ModuleImported,

542

549

550

553

556

557 void addMacroExpansion(const Token &Id, const MacroInfo *MI,

559

560

561

562 struct {

565 } CachedRangeQuery;

566

567 std::pair<int, int> getPreprocessedEntitiesInRangeSlow(SourceRange R);

568 };

569

570}

571

573 unsigned alignment) noexcept {

574 return PR.Allocate(bytes, alignment);

575}

576

579 PR.Deallocate(ptr);

580}

581

582#endif

static StringRef bytes(const std::vector< T, Allocator > &v)

Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.

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

llvm::MachO::FileType FileType

Defines the PPCallbacks interface.

Defines the clang::SourceLocation class and associated facilities.

Represents a character-granular source range.

An abstract class that should be subclassed by any external source of preprocessing record entries.

Definition PreprocessingRecord.h:279

virtual SourceRange ReadSkippedRange(unsigned Index)=0

Read a preallocated skipped range from the external source.

virtual ~ExternalPreprocessingRecordSource()

virtual std::optional< bool > isPreprocessedEntityInFileID(unsigned Index, FileID FID)

Optionally returns true or false if the preallocated preprocessed entity with index Index came from f...

Definition PreprocessingRecord.h:296

virtual PreprocessedEntity * ReadPreprocessedEntity(unsigned Index)=0

Read a preallocated preprocessed entity from the external source.

virtual std::pair< unsigned, unsigned > findPreprocessedEntitiesInRange(SourceRange Range)=0

Returns a pair of [Begin, End) indices of preallocated preprocessed entities that Range encompasses.

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

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

StringRef getName() const

Return the actual identifier string.

StringRef getFileName() const

Retrieve the included file name as it was written in the source.

Definition PreprocessingRecord.h:257

InclusionKind getKind() const

Determine what kind of inclusion directive this is.

Definition PreprocessingRecord.h:254

bool wasInQuotes() const

Determine whether the included file name was written in quotes; otherwise, it was written in angle br...

Definition PreprocessingRecord.h:261

bool importedModule() const

Determine whether the inclusion directive was automatically turned into a module import.

Definition PreprocessingRecord.h:265

InclusionKind

The kind of inclusion directives known to the preprocessor.

Definition PreprocessingRecord.h:210

@ IncludeMacros

A Clang #__include_macros directive.

Definition PreprocessingRecord.h:221

@ Import

An Objective-C #import directive.

Definition PreprocessingRecord.h:215

@ IncludeNext

A GNU #include_next directive.

Definition PreprocessingRecord.h:218

@ Include

An #include directive.

Definition PreprocessingRecord.h:212

static bool classof(const PreprocessedEntity *PE)

Definition PreprocessingRecord.h:272

InclusionDirective(PreprocessingRecord &PPRec, InclusionKind Kind, StringRef FileName, bool InQuotes, bool ImportedModule, OptionalFileEntryRef File, SourceRange Range)

OptionalFileEntryRef getFile() const

Retrieve the file entry for the actual file that was included by this directive.

Definition PreprocessingRecord.h:269

MacroArgs - An instance of this class captures information about the formal arguments specified to a ...

Record the location of a macro definition.

Definition PreprocessingRecord.h:146

static bool classof(const PreprocessedEntity *PE)

Definition PreprocessingRecord.h:162

SourceLocation getLocation() const

Retrieve the location of the macro name in the definition.

Definition PreprocessingRecord.h:159

MacroDefinitionRecord(const IdentifierInfo *Name, SourceRange Range)

Definition PreprocessingRecord.h:151

const IdentifierInfo * getName() const

Retrieve the name of the macro being defined.

Definition PreprocessingRecord.h:156

A description of the current definition of a macro.

Encapsulates changes to the "macros namespace" (the location where the macro name became active,...

MacroDefinitionRecord * getDefinition() const

The definition of the macro being expanded.

Definition PreprocessingRecord.h:194

bool isBuiltinMacro() const

True if it is a builtin macro.

Definition PreprocessingRecord.h:183

const IdentifierInfo * getName() const

The name of the macro being expanded.

Definition PreprocessingRecord.h:186

static bool classof(const PreprocessedEntity *PE)

Definition PreprocessingRecord.h:199

MacroExpansion(MacroDefinitionRecord *Definition, SourceRange Range)

Definition PreprocessingRecord.h:178

MacroExpansion(IdentifierInfo *BuiltinName, SourceRange Range)

Definition PreprocessingRecord.h:174

Encapsulates the data about a macro definition (e.g.

Describes a module or submodule.

This interface provides a way to observe the actions of the preprocessor as it does its thing.

virtual void Elifndef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD)

Hook called whenever an #elifndef branch is taken.

virtual void Elifdef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD)

Hook called whenever an #elifdef branch is taken.

Base class that describes a preprocessed entity, which may be a preprocessor directive or macro expan...

Definition PreprocessingRecord.h:58

EntityKind

The kind of preprocessed entity an object describes.

Definition PreprocessingRecord.h:61

@ InvalidKind

Indicates a problem trying to load the preprocessed entity.

Definition PreprocessingRecord.h:63

@ MacroExpansionKind

A macro expansion.

Definition PreprocessingRecord.h:66

@ LastPreprocessingDirective

Definition PreprocessingRecord.h:81

bool isInvalid() const

Returns true if there was a problem loading the preprocessed entity.

Definition PreprocessingRecord.h:107

PreprocessedEntity(EntityKind Kind, SourceRange Range)

Definition PreprocessingRecord.h:94

EntityKind getKind() const

Retrieve the kind of preprocessed entity stored in this object.

Definition PreprocessingRecord.h:99

SourceRange getSourceRange() const LLVM_READONLY

Retrieve the source range that covers this entire preprocessed entity.

Definition PreprocessingRecord.h:103

friend class PreprocessingRecord

Definition PreprocessingRecord.h:92

PreprocessingDirective(EntityKind Kind, SourceRange Range)

Definition PreprocessingRecord.h:135

static bool classof(const PreprocessedEntity *PD)

Definition PreprocessingRecord.h:139

Iteration over the preprocessed entities.

Definition PreprocessingRecord.h:433

iterator()

Definition PreprocessingRecord.h:442

PreprocessedEntity * operator->() const

Definition PreprocessingRecord.h:451

PreprocessedEntity * operator*() const

Definition PreprocessingRecord.h:444

friend class PreprocessingRecord

Definition PreprocessingRecord.h:434

A record of the steps taken while preprocessing a source file, including the various preprocessing di...

Definition PreprocessingRecord.h:308

SourceManager & getSourceManager() const

Definition PreprocessingRecord.h:412

friend class ASTWriter

Definition PreprocessingRecord.h:524

void Deallocate(void *Ptr)

Deallocate memory in the preprocessing record.

Definition PreprocessingRecord.h:408

PreprocessingRecord(SourceManager &SM)

Construct a new preprocessing record.

void * Allocate(unsigned Size, unsigned Align=8)

Allocate memory in the preprocessing record.

Definition PreprocessingRecord.h:403

llvm::iterator_range< iterator > getPreprocessedEntitiesInRange(SourceRange R)

Returns a range of preprocessed entities that source range R encompasses.

iterator end()

End iterator for all preprocessed entities.

Definition PreprocessingRecord.h:460

ExternalPreprocessingRecordSource * getExternalSource() const

Retrieve the external source for preprocessed entities.

Definition PreprocessingRecord.h:508

MacroDefinitionRecord * findMacroDefinition(const MacroInfo *MI)

Retrieve the macro definition that corresponds to the given MacroInfo.

PPEntityID addPreprocessedEntity(PreprocessedEntity *Entity)

Add a new preprocessed entity to this record.

llvm::iterator_range< iterator > getIteratorsForLoadedRange(unsigned start, unsigned count)

iterator range for the given range of loaded preprocessed entities.

Definition PreprocessingRecord.h:476

friend class ASTReader

Definition PreprocessingRecord.h:523

const std::vector< SourceRange > & getSkippedRanges()

Retrieve all ranges that got skipped while preprocessing.

Definition PreprocessingRecord.h:517

SourceRange Range

Definition PreprocessingRecord.h:563

bool isEntityInFileID(iterator PPEI, FileID FID)

Returns true if the preprocessed entity that PPEI iterator points to is coming from the file FID.

size_t getTotalMemory() const

iterator begin()

Begin iterator for all preprocessed entities.

Definition PreprocessingRecord.h:455

iterator local_begin()

Begin iterator for local, non-loaded, preprocessed entities.

Definition PreprocessingRecord.h:465

std::pair< int, int > Result

Definition PreprocessingRecord.h:564

iterator local_end()

End iterator for local, non-loaded, preprocessed entities.

Definition PreprocessingRecord.h:470

void SetExternalSource(ExternalPreprocessingRecordSource &Source)

Set the external source for preprocessed entities.

Encodes a location in the source.

This class handles loading and caching of source files into memory.

A trivial tuple used to represent a source range.

SourceLocation getBegin() const

Token - This structure provides full information about a lexed token.

@ MacroDefinitionKind

A macro definition.

Definition PreprocessingRecord.h:72

@ FirstPreprocessingDirective

Definition PreprocessingRecord.h:80

@ InclusionDirectiveKind

An inclusion directive, such as #include, #import, or #include_next.

Definition PreprocessingRecord.h:76

CharacteristicKind

Indicates whether a file or directory holds normal user code, system code, or system code which is im...

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

bool isa(CodeGen::Address addr)

CustomizableOptional< FileEntryRef > OptionalFileEntryRef

nullptr

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

U cast(CodeGen::Address addr)