clang  16.0.0git
PreprocessingRecord.h
Go to the documentation of this file.
1 //===- PreprocessingRecord.h - Record of Preprocessing ----------*- 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 PreprocessingRecord class, which maintains a record
10 // of what occurred during preprocessing.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_LEX_PREPROCESSINGRECORD_H
15 #define LLVM_CLANG_LEX_PREPROCESSINGRECORD_H
16 
18 #include "clang/Basic/LLVM.h"
20 #include "clang/Lex/PPCallbacks.h"
21 #include "llvm/ADT/DenseMap.h"
22 #include "llvm/ADT/None.h"
23 #include "llvm/ADT/Optional.h"
24 #include "llvm/ADT/PointerUnion.h"
25 #include "llvm/ADT/StringRef.h"
26 #include "llvm/ADT/iterator.h"
27 #include "llvm/ADT/iterator_range.h"
28 #include "llvm/Support/Allocator.h"
29 #include "llvm/Support/Compiler.h"
30 #include <cassert>
31 #include <cstddef>
32 #include <iterator>
33 #include <utility>
34 #include <vector>
35 
36 namespace clang {
37 
38 class PreprocessingRecord;
39 
40 } // namespace clang
41 
42 /// Allocates memory within a Clang preprocessing record.
43 void *operator new(size_t bytes, clang::PreprocessingRecord &PR,
44  unsigned alignment = 8) noexcept;
45 
46 /// Frees memory allocated in a Clang preprocessing record.
47 void operator delete(void *ptr, clang::PreprocessingRecord &PR,
48  unsigned) noexcept;
49 
50 namespace clang {
51 
52 class IdentifierInfo;
53 class MacroInfo;
54 class SourceManager;
55 class Token;
56 
57  /// Base class that describes a preprocessed entity, which may be a
58  /// preprocessor directive or macro expansion.
60  public:
61  /// The kind of preprocessed entity an object describes.
62  enum EntityKind {
63  /// Indicates a problem trying to load the preprocessed entity.
65 
66  /// A macro expansion.
68 
69  /// \defgroup Preprocessing directives
70  /// @{
71 
72  /// A macro definition.
74 
75  /// An inclusion directive, such as \c \#include, \c
76  /// \#import, or \c \#include_next.
78 
79  /// @}
80 
83  };
84 
85  private:
86  /// The kind of preprocessed entity that this object describes.
87  EntityKind Kind;
88 
89  /// The source range that covers this preprocessed entity.
90  SourceRange Range;
91 
92  protected:
93  friend class PreprocessingRecord;
94 
96  : Kind(Kind), Range(Range) {}
97 
98  public:
99  /// Retrieve the kind of preprocessed entity stored in this object.
100  EntityKind getKind() const { return Kind; }
101 
102  /// Retrieve the source range that covers this entire preprocessed
103  /// entity.
104  SourceRange getSourceRange() const LLVM_READONLY { return Range; }
105 
106  /// Returns true if there was a problem loading the preprocessed
107  /// entity.
108  bool isInvalid() const { return Kind == InvalidKind; }
109 
110  // Only allow allocation of preprocessed entities using the allocator
111  // in PreprocessingRecord or by doing a placement new.
112  void *operator new(size_t bytes, PreprocessingRecord &PR,
113  unsigned alignment = 8) noexcept {
114  return ::operator new(bytes, PR, alignment);
115  }
116 
117  void *operator new(size_t bytes, void *mem) noexcept { return mem; }
118 
119  void operator delete(void *ptr, PreprocessingRecord &PR,
120  unsigned alignment) noexcept {
121  return ::operator delete(ptr, PR, alignment);
122  }
123 
124  void operator delete(void *, std::size_t) noexcept {}
125  void operator delete(void *, void *) noexcept {}
126 
127  private:
128  // Make vanilla 'new' and 'delete' illegal for preprocessed entities.
129  void *operator new(size_t bytes) noexcept;
130  void operator delete(void *data) noexcept;
131  };
132 
133  /// Records the presence of a preprocessor directive.
135  public:
137  : PreprocessedEntity(Kind, Range) {}
138 
139  // Implement isa/cast/dyncast/etc.
140  static bool classof(const PreprocessedEntity *PD) {
141  return PD->getKind() >= FirstPreprocessingDirective &&
143  }
144  };
145 
146  /// Record the location of a macro definition.
148  /// The name of the macro being defined.
149  const IdentifierInfo *Name;
150 
151  public:
152  explicit MacroDefinitionRecord(const IdentifierInfo *Name,
153  SourceRange Range)
154  : PreprocessingDirective(MacroDefinitionKind, Range), Name(Name) {}
155 
156  /// Retrieve the name of the macro being defined.
157  const IdentifierInfo *getName() const { return Name; }
158 
159  /// Retrieve the location of the macro name in the definition.
161 
162  // Implement isa/cast/dyncast/etc.
163  static bool classof(const PreprocessedEntity *PE) {
164  return PE->getKind() == MacroDefinitionKind;
165  }
166  };
167 
168  /// Records the location of a macro expansion.
170  /// The definition of this macro or the name of the macro if it is
171  /// a builtin macro.
172  llvm::PointerUnion<IdentifierInfo *, MacroDefinitionRecord *> NameOrDef;
173 
174  public:
177  NameOrDef(BuiltinName) {}
178 
180  : PreprocessedEntity(MacroExpansionKind, Range), NameOrDef(Definition) {
181  }
182 
183  /// True if it is a builtin macro.
184  bool isBuiltinMacro() const { return NameOrDef.is<IdentifierInfo *>(); }
185 
186  /// The name of the macro being expanded.
187  const IdentifierInfo *getName() const {
189  return Def->getName();
190  return NameOrDef.get<IdentifierInfo *>();
191  }
192 
193  /// The definition of the macro being expanded. May return null if
194  /// this is a builtin macro.
196  return NameOrDef.dyn_cast<MacroDefinitionRecord *>();
197  }
198 
199  // Implement isa/cast/dyncast/etc.
200  static bool classof(const PreprocessedEntity *PE) {
201  return PE->getKind() == MacroExpansionKind;
202  }
203  };
204 
205  /// Record the location of an inclusion directive, such as an
206  /// \c \#include or \c \#import statement.
208  public:
209  /// The kind of inclusion directives known to the
210  /// preprocessor.
212  /// An \c \#include directive.
214 
215  /// An Objective-C \c \#import directive.
217 
218  /// A GNU \c \#include_next directive.
220 
221  /// A Clang \c \#__include_macros directive.
223  };
224 
225  private:
226  /// The name of the file that was included, as written in
227  /// the source.
228  StringRef FileName;
229 
230  /// Whether the file name was in quotation marks; otherwise, it was
231  /// in angle brackets.
232  unsigned InQuotes : 1;
233 
234  /// The kind of inclusion directive we have.
235  ///
236  /// This is a value of type InclusionKind.
237  unsigned Kind : 2;
238 
239  /// Whether the inclusion directive was automatically turned into
240  /// a module import.
241  unsigned ImportedModule : 1;
242 
243  /// The file that was included.
245 
246  public:
248  StringRef FileName, bool InQuotes, bool ImportedModule,
249  Optional<FileEntryRef> File, SourceRange Range);
250 
251  /// Determine what kind of inclusion directive this is.
252  InclusionKind getKind() const { return static_cast<InclusionKind>(Kind); }
253 
254  /// Retrieve the included file name as it was written in the source.
255  StringRef getFileName() const { return FileName; }
256 
257  /// Determine whether the included file name was written in quotes;
258  /// otherwise, it was written in angle brackets.
259  bool wasInQuotes() const { return InQuotes; }
260 
261  /// Determine whether the inclusion directive was automatically
262  /// turned into a module import.
263  bool importedModule() const { return ImportedModule; }
264 
265  /// Retrieve the file entry for the actual file that was included
266  /// by this directive.
267  Optional<FileEntryRef> getFile() const { return File; }
268 
269  // Implement isa/cast/dyncast/etc.
270  static bool classof(const PreprocessedEntity *PE) {
271  return PE->getKind() == InclusionDirectiveKind;
272  }
273  };
274 
275  /// An abstract class that should be subclassed by any external source
276  /// of preprocessing record entries.
278  public:
280 
281  /// Read a preallocated preprocessed entity from the external source.
282  ///
283  /// \returns null if an error occurred that prevented the preprocessed
284  /// entity from being loaded.
285  virtual PreprocessedEntity *ReadPreprocessedEntity(unsigned Index) = 0;
286 
287  /// Returns a pair of [Begin, End) indices of preallocated
288  /// preprocessed entities that \p Range encompasses.
289  virtual std::pair<unsigned, unsigned>
291 
292  /// Optionally returns true or false if the preallocated preprocessed
293  /// entity with index \p Index came from file \p FID.
295  FileID FID) {
296  return None;
297  }
298 
299  /// Read a preallocated skipped range from the external source.
300  virtual SourceRange ReadSkippedRange(unsigned Index) = 0;
301  };
302 
303  /// A record of the steps taken while preprocessing a source file,
304  /// including the various preprocessing directives processed, macros
305  /// expanded, etc.
307  SourceManager &SourceMgr;
308 
309  /// Allocator used to store preprocessing objects.
310  llvm::BumpPtrAllocator BumpAlloc;
311 
312  /// The set of preprocessed entities in this record, in order they
313  /// were seen.
314  std::vector<PreprocessedEntity *> PreprocessedEntities;
315 
316  /// The set of preprocessed entities in this record that have been
317  /// loaded from external sources.
318  ///
319  /// The entries in this vector are loaded lazily from the external source,
320  /// and are referenced by the iterator using negative indices.
321  std::vector<PreprocessedEntity *> LoadedPreprocessedEntities;
322 
323  /// The set of ranges that were skipped by the preprocessor,
324  std::vector<SourceRange> SkippedRanges;
325 
326  bool SkippedRangesAllLoaded = true;
327 
328  /// Global (loaded or local) ID for a preprocessed entity.
329  /// Negative values are used to indicate preprocessed entities
330  /// loaded from the external source while non-negative values are used to
331  /// indicate preprocessed entities introduced by the current preprocessor.
332  /// Value -1 corresponds to element 0 in the loaded entities vector,
333  /// value -2 corresponds to element 1 in the loaded entities vector, etc.
334  /// Value 0 is an invalid value, the index to local entities is 1-based,
335  /// value 1 corresponds to element 0 in the local entities vector,
336  /// value 2 corresponds to element 1 in the local entities vector, etc.
337  class PPEntityID {
338  friend class PreprocessingRecord;
339 
340  int ID = 0;
341 
342  explicit PPEntityID(int ID) : ID(ID) {}
343 
344  public:
345  PPEntityID() = default;
346  };
347 
348  static PPEntityID getPPEntityID(unsigned Index, bool isLoaded) {
349  return isLoaded ? PPEntityID(-int(Index)-1) : PPEntityID(Index+1);
350  }
351 
352  /// Mapping from MacroInfo structures to their definitions.
353  llvm::DenseMap<const MacroInfo *, MacroDefinitionRecord *> MacroDefinitions;
354 
355  /// External source of preprocessed entities.
356  ExternalPreprocessingRecordSource *ExternalSource = nullptr;
357 
358  /// Retrieve the preprocessed entity at the given ID.
359  PreprocessedEntity *getPreprocessedEntity(PPEntityID PPID);
360 
361  /// Retrieve the loaded preprocessed entity at the given index.
362  PreprocessedEntity *getLoadedPreprocessedEntity(unsigned Index);
363 
364  /// Determine the number of preprocessed entities that were
365  /// loaded (or can be loaded) from an external source.
366  unsigned getNumLoadedPreprocessedEntities() const {
367  return LoadedPreprocessedEntities.size();
368  }
369 
370  /// Returns a pair of [Begin, End) indices of local preprocessed
371  /// entities that \p Range encompasses.
372  std::pair<unsigned, unsigned>
373  findLocalPreprocessedEntitiesInRange(SourceRange Range) const;
374  unsigned findBeginLocalPreprocessedEntity(SourceLocation Loc) const;
375  unsigned findEndLocalPreprocessedEntity(SourceLocation Loc) const;
376 
377  /// Allocate space for a new set of loaded preprocessed entities.
378  ///
379  /// \returns The index into the set of loaded preprocessed entities, which
380  /// corresponds to the first newly-allocated entity.
381  unsigned allocateLoadedEntities(unsigned NumEntities);
382 
383  /// Allocate space for a new set of loaded preprocessed skipped
384  /// ranges.
385  ///
386  /// \returns The index into the set of loaded preprocessed ranges, which
387  /// corresponds to the first newly-allocated range.
388  unsigned allocateSkippedRanges(unsigned NumRanges);
389 
390  /// Ensures that all external skipped ranges have been loaded.
391  void ensureSkippedRangesLoaded();
392 
393  /// Register a new macro definition.
394  void RegisterMacroDefinition(MacroInfo *Macro, MacroDefinitionRecord *Def);
395 
396  public:
397  /// Construct a new preprocessing record.
399 
400  /// Allocate memory in the preprocessing record.
401  void *Allocate(unsigned Size, unsigned Align = 8) {
402  return BumpAlloc.Allocate(Size, Align);
403  }
404 
405  /// Deallocate memory in the preprocessing record.
406  void Deallocate(void *Ptr) {}
407 
408  size_t getTotalMemory() const;
409 
410  SourceManager &getSourceManager() const { return SourceMgr; }
411 
412  /// Iteration over the preprocessed entities.
413  ///
414  /// In a complete iteration, the iterator walks the range [-M, N),
415  /// where negative values are used to indicate preprocessed entities
416  /// loaded from the external source while non-negative values are used to
417  /// indicate preprocessed entities introduced by the current preprocessor.
418  /// However, to provide iteration in source order (for, e.g., chained
419  /// precompiled headers), dereferencing the iterator flips the negative
420  /// values (corresponding to loaded entities), so that position -M
421  /// corresponds to element 0 in the loaded entities vector, position -M+1
422  /// corresponds to element 1 in the loaded entities vector, etc. This
423  /// gives us a reasonably efficient, source-order walk.
424  ///
425  /// We define this as a wrapping iterator around an int. The
426  /// iterator_adaptor_base class forwards the iterator methods to basic
427  /// integer arithmetic.
428  class iterator : public llvm::iterator_adaptor_base<
429  iterator, int, std::random_access_iterator_tag,
430  PreprocessedEntity *, int, PreprocessedEntity *,
431  PreprocessedEntity *> {
432  friend class PreprocessingRecord;
433 
434  PreprocessingRecord *Self;
435 
436  iterator(PreprocessingRecord *Self, int Position)
437  : iterator::iterator_adaptor_base(Position), Self(Self) {}
438 
439  public:
440  iterator() : iterator(nullptr, 0) {}
441 
443  bool isLoaded = this->I < 0;
444  unsigned Index = isLoaded ?
445  Self->LoadedPreprocessedEntities.size() + this->I : this->I;
446  PPEntityID ID = Self->getPPEntityID(Index, isLoaded);
447  return Self->getPreprocessedEntity(ID);
448  }
449  PreprocessedEntity *operator->() const { return **this; }
450  };
451 
452  /// Begin iterator for all preprocessed entities.
454  return iterator(this, -(int)LoadedPreprocessedEntities.size());
455  }
456 
457  /// End iterator for all preprocessed entities.
459  return iterator(this, PreprocessedEntities.size());
460  }
461 
462  /// Begin iterator for local, non-loaded, preprocessed entities.
464  return iterator(this, 0);
465  }
466 
467  /// End iterator for local, non-loaded, preprocessed entities.
469  return iterator(this, PreprocessedEntities.size());
470  }
471 
472  /// iterator range for the given range of loaded
473  /// preprocessed entities.
474  llvm::iterator_range<iterator> getIteratorsForLoadedRange(unsigned start,
475  unsigned count) {
476  unsigned end = start + count;
477  assert(end <= LoadedPreprocessedEntities.size());
478  return llvm::make_range(
479  iterator(this, int(start) - LoadedPreprocessedEntities.size()),
480  iterator(this, int(end) - LoadedPreprocessedEntities.size()));
481  }
482 
483  /// Returns a range of preprocessed entities that source range \p R
484  /// encompasses.
485  ///
486  /// \param R the range to look for preprocessed entities.
487  llvm::iterator_range<iterator>
489 
490  /// Returns true if the preprocessed entity that \p PPEI iterator
491  /// points to is coming from the file \p FID.
492  ///
493  /// Can be used to avoid implicit deserializations of preallocated
494  /// preprocessed entities if we only care about entities of a specific file
495  /// and not from files \#included in the range given at
496  /// \see getPreprocessedEntitiesInRange.
497  bool isEntityInFileID(iterator PPEI, FileID FID);
498 
499  /// Add a new preprocessed entity to this record.
500  PPEntityID addPreprocessedEntity(PreprocessedEntity *Entity);
501 
502  /// Set the external source for preprocessed entities.
504 
505  /// Retrieve the external source for preprocessed entities.
507  return ExternalSource;
508  }
509 
510  /// Retrieve the macro definition that corresponds to the given
511  /// \c MacroInfo.
513 
514  /// Retrieve all ranges that got skipped while preprocessing.
515  const std::vector<SourceRange> &getSkippedRanges() {
516  ensureSkippedRangesLoaded();
517  return SkippedRanges;
518  }
519 
520  private:
521  friend class ASTReader;
522  friend class ASTWriter;
523 
524  void MacroExpands(const Token &Id, const MacroDefinition &MD,
525  SourceRange Range, const MacroArgs *Args) override;
526  void MacroDefined(const Token &Id, const MacroDirective *MD) override;
527  void MacroUndefined(const Token &Id, const MacroDefinition &MD,
528  const MacroDirective *Undef) override;
529  void InclusionDirective(SourceLocation HashLoc, const Token &IncludeTok,
530  StringRef FileName, bool IsAngled,
531  CharSourceRange FilenameRange,
532  Optional<FileEntryRef> File, StringRef SearchPath,
533  StringRef RelativePath, const Module *Imported,
534  SrcMgr::CharacteristicKind FileType) override;
535  void Ifdef(SourceLocation Loc, const Token &MacroNameTok,
536  const MacroDefinition &MD) override;
537  void Ifndef(SourceLocation Loc, const Token &MacroNameTok,
538  const MacroDefinition &MD) override;
539 
540  using PPCallbacks::Elifdef;
541  using PPCallbacks::Elifndef;
542  void Elifdef(SourceLocation Loc, const Token &MacroNameTok,
543  const MacroDefinition &MD) override;
544  void Elifndef(SourceLocation Loc, const Token &MacroNameTok,
545  const MacroDefinition &MD) override;
546 
547  /// Hook called whenever the 'defined' operator is seen.
548  void Defined(const Token &MacroNameTok, const MacroDefinition &MD,
549  SourceRange Range) override;
550 
551  void SourceRangeSkipped(SourceRange Range,
552  SourceLocation EndifLoc) override;
553 
554  void addMacroExpansion(const Token &Id, const MacroInfo *MI,
556 
557  /// Cached result of the last \see getPreprocessedEntitiesInRange
558  /// query.
559  struct {
561  std::pair<int, int> Result;
562  } CachedRangeQuery;
563 
564  std::pair<int, int> getPreprocessedEntitiesInRangeSlow(SourceRange R);
565  };
566 
567 } // namespace clang
568 
569 inline void *operator new(size_t bytes, clang::PreprocessingRecord &PR,
570  unsigned alignment) noexcept {
571  return PR.Allocate(bytes, alignment);
572 }
573 
574 inline void operator delete(void *ptr, clang::PreprocessingRecord &PR,
575  unsigned) noexcept {
576  PR.Deallocate(ptr);
577 }
578 
579 #endif // LLVM_CLANG_LEX_PREPROCESSINGRECORD_H
clang::PreprocessingDirective
Records the presence of a preprocessor directive.
Definition: PreprocessingRecord.h:134
clang::PreprocessingRecord::SetExternalSource
void SetExternalSource(ExternalPreprocessingRecordSource &Source)
Set the external source for preprocessed entities.
Definition: PreprocessingRecord.cpp:314
clang::PreprocessedEntity::isInvalid
bool isInvalid() const
Returns true if there was a problem loading the preprocessed entity.
Definition: PreprocessingRecord.h:108
clang::PreprocessingDirective::PreprocessingDirective
PreprocessingDirective(EntityKind Kind, SourceRange Range)
Definition: PreprocessingRecord.h:136
clang::PreprocessedEntity::LastPreprocessingDirective
@ LastPreprocessingDirective
Definition: PreprocessingRecord.h:82
clang::ExternalPreprocessingRecordSource
An abstract class that should be subclassed by any external source of preprocessing record entries.
Definition: PreprocessingRecord.h:277
clang::PreprocessingRecord::getTotalMemory
size_t getTotalMemory() const
Definition: PreprocessingRecord.cpp:528
clang::DeclaratorContext::File
@ File
clang::ExternalPreprocessingRecordSource::ReadPreprocessedEntity
virtual PreprocessedEntity * ReadPreprocessedEntity(unsigned Index)=0
Read a preallocated preprocessed entity from the external source.
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:210
clang::ExternalPreprocessingRecordSource::findPreprocessedEntitiesInRange
virtual std::pair< unsigned, unsigned > findPreprocessedEntitiesInRange(SourceRange Range)=0
Returns a pair of [Begin, End) indices of preallocated preprocessed entities that Range encompasses.
clang::MacroExpansion::getDefinition
MacroDefinitionRecord * getDefinition() const
The definition of the macro being expanded.
Definition: PreprocessingRecord.h:195
clang::MacroDefinition
A description of the current definition of a macro.
Definition: MacroInfo.h:587
clang::PreprocessingRecord::local_end
iterator local_end()
End iterator for local, non-loaded, preprocessed entities.
Definition: PreprocessingRecord.h:468
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::PPCallbacks
This interface provides a way to observe the actions of the preprocessor as it does its thing.
Definition: PPCallbacks.h:35
clang::SourceRange::getBegin
SourceLocation getBegin() const
Definition: SourceLocation.h:219
clang::PreprocessingRecord::getPreprocessedEntitiesInRange
llvm::iterator_range< iterator > getPreprocessedEntitiesInRange(SourceRange R)
Returns a range of preprocessed entities that source range R encompasses.
Definition: PreprocessingRecord.cpp:60
clang::MacroArgs
MacroArgs - An instance of this class captures information about the formal arguments specified to a ...
Definition: MacroArgs.h:29
clang::MacroExpansion::MacroExpansion
MacroExpansion(MacroDefinitionRecord *Definition, SourceRange Range)
Definition: PreprocessingRecord.h:179
clang::MacroExpansion
Records the location of a macro expansion.
Definition: PreprocessingRecord.h:169
clang::PreprocessingRecord
A record of the steps taken while preprocessing a source file, including the various preprocessing di...
Definition: PreprocessingRecord.h:306
llvm::Optional< FileEntryRef >
clang::MacroInfo
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:39
clang::SrcMgr::CharacteristicKind
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
Definition: SourceManager.h:79
clang::PreprocessingRecord::Range
SourceRange Range
Definition: PreprocessingRecord.h:560
clang::PreprocessedEntity::MacroExpansionKind
@ MacroExpansionKind
A macro expansion.
Definition: PreprocessingRecord.h:67
clang::PreprocessingRecord::PreprocessingRecord
PreprocessingRecord(SourceManager &SM)
Construct a new preprocessing record.
Definition: PreprocessingRecord.cpp:55
clang::Token
Token - This structure provides full information about a lexed token.
Definition: Token.h:34
clang::MacroExpansion::MacroExpansion
MacroExpansion(IdentifierInfo *BuiltinName, SourceRange Range)
Definition: PreprocessingRecord.h:175
clang::PreprocessedEntity::MacroDefinitionKind
@ MacroDefinitionKind
A macro definition.
Definition: PreprocessingRecord.h:73
clang::PreprocessedEntity::InclusionDirectiveKind
@ InclusionDirectiveKind
An inclusion directive, such as #include, #import, or #include_next.
Definition: PreprocessingRecord.h:77
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:636
clang::PreprocessingRecord::getSourceManager
SourceManager & getSourceManager() const
Definition: PreprocessingRecord.h:410
clang::InclusionDirective::getFile
Optional< FileEntryRef > getFile() const
Retrieve the file entry for the actual file that was included by this directive.
Definition: PreprocessingRecord.h:267
clang::MacroDefinitionRecord::MacroDefinitionRecord
MacroDefinitionRecord(const IdentifierInfo *Name, SourceRange Range)
Definition: PreprocessingRecord.h:152
size_t
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
Definition: opencl-c-base.h:118
clang::PreprocessingRecord::iterator
Iteration over the preprocessed entities.
Definition: PreprocessingRecord.h:428
clang::PreprocessedEntity::getSourceRange
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range that covers this entire preprocessed entity.
Definition: PreprocessingRecord.h:104
clang::InclusionDirective::InclusionKind
InclusionKind
The kind of inclusion directives known to the preprocessor.
Definition: PreprocessingRecord.h:211
clang::Module
Describes a module or submodule.
Definition: Module.h:98
Id
int Id
Definition: ASTDiff.cpp:189
clang::PreprocessingRecord::Allocate
void * Allocate(unsigned Size, unsigned Align=8)
Allocate memory in the preprocessing record.
Definition: PreprocessingRecord.h:401
clang::PPCallbacks::Elifdef
virtual void Elifdef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD)
Hook called whenever an #elifdef branch is taken.
Definition: PPCallbacks.h:378
clang::PreprocessedEntity::EntityKind
EntityKind
The kind of preprocessed entity an object describes.
Definition: PreprocessingRecord.h:62
clang::PPCallbacks::Elifndef
virtual void Elifndef(SourceLocation Loc, const Token &MacroNameTok, const MacroDefinition &MD)
Hook called whenever an #elifndef branch is taken.
Definition: PPCallbacks.h:402
IdentifierTable.h
clang::MacroDefinitionRecord
Record the location of a macro definition.
Definition: PreprocessingRecord.h:147
clang::PreprocessingRecord::iterator::iterator
iterator()
Definition: PreprocessingRecord.h:440
clang::InclusionDirective::Include
@ Include
An #include directive.
Definition: PreprocessingRecord.h:213
clang::InclusionDirective::IncludeNext
@ IncludeNext
A GNU #include_next directive.
Definition: PreprocessingRecord.h:219
clang::PreprocessingRecord::getIteratorsForLoadedRange
llvm::iterator_range< iterator > getIteratorsForLoadedRange(unsigned start, unsigned count)
iterator range for the given range of loaded preprocessed entities.
Definition: PreprocessingRecord.h:474
clang::ASTWriter
Writes an AST file containing the contents of a translation unit.
Definition: ASTWriter.h:85
clang::InclusionDirective::Import
@ Import
An Objective-C #import directive.
Definition: PreprocessingRecord.h:216
clang::MacroDefinitionRecord::getLocation
SourceLocation getLocation() const
Retrieve the location of the macro name in the definition.
Definition: PreprocessingRecord.h:160
clang::PreprocessingRecord::Result
std::pair< int, int > Result
Definition: PreprocessingRecord.h:561
SourceLocation.h
clang::InclusionDirective::wasInQuotes
bool wasInQuotes() const
Determine whether the included file name was written in quotes; otherwise, it was written in angle br...
Definition: PreprocessingRecord.h:259
clang::InclusionDirective
Record the location of an inclusion directive, such as an #include or #import statement.
Definition: PreprocessingRecord.h:207
clang::PreprocessingDirective::classof
static bool classof(const PreprocessedEntity *PD)
Definition: PreprocessingRecord.h:140
clang::PreprocessedEntity::getKind
EntityKind getKind() const
Retrieve the kind of preprocessed entity stored in this object.
Definition: PreprocessingRecord.h:100
clang::MacroExpansion::isBuiltinMacro
bool isBuiltinMacro() const
True if it is a builtin macro.
Definition: PreprocessingRecord.h:184
clang::MacroDefinitionRecord::classof
static bool classof(const PreprocessedEntity *PE)
Definition: PreprocessingRecord.h:163
clang::PreprocessingRecord::Deallocate
void Deallocate(void *Ptr)
Deallocate memory in the preprocessing record.
Definition: PreprocessingRecord.h:406
clang::CharSourceRange
Represents a character-granular source range.
Definition: SourceLocation.h:253
LLVM.h
clang::PreprocessingRecord::iterator::operator->
PreprocessedEntity * operator->() const
Definition: PreprocessingRecord.h:449
clang::InclusionDirective::getKind
InclusionKind getKind() const
Determine what kind of inclusion directive this is.
Definition: PreprocessingRecord.h:252
clang::InclusionDirective::IncludeMacros
@ IncludeMacros
A Clang #__include_macros directive.
Definition: PreprocessingRecord.h:222
clang::PreprocessingRecord::begin
iterator begin()
Begin iterator for all preprocessed entities.
Definition: PreprocessingRecord.h:453
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:85
clang::ExternalPreprocessingRecordSource::isPreprocessedEntityInFileID
virtual 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:294
clang::ExternalPreprocessingRecordSource::ReadSkippedRange
virtual SourceRange ReadSkippedRange(unsigned Index)=0
Read a preallocated skipped range from the external source.
bytes
static StringRef bytes(const std::vector< T, Allocator > &v)
Definition: ASTWriter.cpp:123
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::ASTReader
Reads an AST files chain containing the contents of a translation unit.
Definition: ASTReader.h:341
clang::PreprocessingRecord::findMacroDefinition
MacroDefinitionRecord * findMacroDefinition(const MacroInfo *MI)
Retrieve the macro definition that corresponds to the given MacroInfo.
Definition: PreprocessingRecord.cpp:384
clang::PreprocessingRecord::getExternalSource
ExternalPreprocessingRecordSource * getExternalSource() const
Retrieve the external source for preprocessed entities.
Definition: PreprocessingRecord.h:506
clang::IdentifierInfo::getName
StringRef getName() const
Return the actual identifier string.
Definition: IdentifierTable.h:196
clang::Builtin::ID
ID
Definition: Builtins.h:52
clang::PreprocessingRecord::end
iterator end()
End iterator for all preprocessed entities.
Definition: PreprocessingRecord.h:458
clang
Definition: CalledOnceCheck.h:17
PPCallbacks.h
clang::MacroDirective
Encapsulates changes to the "macros namespace" (the location where the macro name became active,...
Definition: MacroInfo.h:313
clang::FileID
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Definition: SourceLocation.h:38
clang::MacroExpansion::classof
static bool classof(const PreprocessedEntity *PE)
Definition: PreprocessingRecord.h:200
clang::PreprocessingRecord::iterator::operator*
PreprocessedEntity * operator*() const
Definition: PreprocessingRecord.h:442
unsigned
clang::PreprocessedEntity::InvalidKind
@ InvalidKind
Indicates a problem trying to load the preprocessed entity.
Definition: PreprocessingRecord.h:64
clang::PreprocessingRecord::isEntityInFileID
bool isEntityInFileID(iterator PPEI, FileID FID)
Returns true if the preprocessed entity that PPEI iterator points to is coming from the file FID.
Definition: PreprocessingRecord.cpp:98
clang::InclusionDirective::getFileName
StringRef getFileName() const
Retrieve the included file name as it was written in the source.
Definition: PreprocessingRecord.h:255
clang::MacroExpansion::getName
const IdentifierInfo * getName() const
The name of the macro being expanded.
Definition: PreprocessingRecord.h:187
clang::InclusionDirective::InclusionDirective
InclusionDirective(PreprocessingRecord &PPRec, InclusionKind Kind, StringRef FileName, bool InQuotes, bool ImportedModule, Optional< FileEntryRef > File, SourceRange Range)
Definition: PreprocessingRecord.cpp:42
clang::PreprocessingRecord::addPreprocessedEntity
PPEntityID addPreprocessedEntity(PreprocessedEntity *Entity)
Add a new preprocessed entity to this record.
Definition: PreprocessingRecord.cpp:253
clang::MacroDefinitionRecord::getName
const IdentifierInfo * getName() const
Retrieve the name of the macro being defined.
Definition: PreprocessingRecord.h:157
clang::PreprocessingRecord::getSkippedRanges
const std::vector< SourceRange > & getSkippedRanges()
Retrieve all ranges that got skipped while preprocessing.
Definition: PreprocessingRecord.h:515
clang::InclusionDirective::importedModule
bool importedModule() const
Determine whether the inclusion directive was automatically turned into a module import.
Definition: PreprocessingRecord.h:263
clang::InclusionDirective::classof
static bool classof(const PreprocessedEntity *PE)
Definition: PreprocessingRecord.h:270
clang::PreprocessedEntity::FirstPreprocessingDirective
@ FirstPreprocessingDirective
Definition: PreprocessingRecord.h:81
clang::PreprocessedEntity::PreprocessedEntity
PreprocessedEntity(EntityKind Kind, SourceRange Range)
Definition: PreprocessingRecord.h:95
SM
#define SM(sm)
Definition: Cuda.cpp:79
clang::ExternalPreprocessingRecordSource::~ExternalPreprocessingRecordSource
virtual ~ExternalPreprocessingRecordSource()
clang::PreprocessingRecord::local_begin
iterator local_begin()
Begin iterator for local, non-loaded, preprocessed entities.
Definition: PreprocessingRecord.h:463
clang::PreprocessedEntity
Base class that describes a preprocessed entity, which may be a preprocessor directive or macro expan...
Definition: PreprocessingRecord.h:59