14 #ifndef LLVM_CLANG_LEX_PREPROCESSINGRECORD_H
15 #define LLVM_CLANG_LEX_PREPROCESSINGRECORD_H
20 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/ADT/Optional.h"
22 #include "llvm/ADT/SmallVector.h"
23 #include "llvm/ADT/iterator.h"
24 #include "llvm/Support/Allocator.h"
25 #include "llvm/Support/Compiler.h"
31 class PreprocessingRecord;
36 unsigned alignment = 8) LLVM_NOEXCEPT;
43 class MacroDefinitionRecord;
83 : Kind(Kind), Range(Range) { }
102 unsigned alignment = 8) LLVM_NOEXCEPT {
103 return ::operator
new(
bytes, PR, alignment);
106 void *
operator new(
size_t bytes,
void *mem) LLVM_NOEXCEPT {
return mem; }
109 unsigned alignment) LLVM_NOEXCEPT {
110 return ::operator
delete(ptr, PR, alignment);
114 void operator delete(
void *,
void *) LLVM_NOEXCEPT {}
118 void *
operator new(
size_t bytes) LLVM_NOEXCEPT;
119 void operator delete(
void *data) LLVM_NOEXCEPT;
161 llvm::PointerUnion<IdentifierInfo *, MacroDefinitionRecord *> NameOrDef;
166 NameOrDef(BuiltinName) {}
218 unsigned InQuotes : 1;
227 unsigned ImportedModule : 1;
235 bool InQuotes,
bool ImportedModule,
276 virtual std::pair<unsigned, unsigned>
294 llvm::BumpPtrAllocator BumpAlloc;
298 std::vector<PreprocessedEntity *> PreprocessedEntities;
305 std::vector<PreprocessedEntity *> LoadedPreprocessedEntities;
308 std::vector<SourceRange> SkippedRanges;
321 explicit PPEntityID(
int ID) :
ID(ID) {}
324 PPEntityID() :
ID(0) {}
327 static PPEntityID getPPEntityID(
unsigned Index,
bool isLoaded) {
328 return isLoaded ? PPEntityID(-
int(Index)-1) : PPEntityID(Index+1);
332 llvm::DenseMap<const MacroInfo *, MacroDefinitionRecord *> MacroDefinitions;
345 unsigned getNumLoadedPreprocessedEntities()
const {
346 return LoadedPreprocessedEntities.size();
351 std::pair<unsigned, unsigned>
353 unsigned findBeginLocalPreprocessedEntity(
SourceLocation Loc)
const;
354 unsigned findEndLocalPreprocessedEntity(
SourceLocation Loc)
const;
360 unsigned allocateLoadedEntities(
unsigned NumEntities);
370 void *
Allocate(
unsigned Size,
unsigned Align = 8) {
371 return BumpAlloc.Allocate(Size, Align);
397 class iterator :
public llvm::iterator_adaptor_base<
398 iterator, int, std::random_access_iterator_tag,
399 PreprocessedEntity *, int, PreprocessedEntity *,
400 PreprocessedEntity *> {
404 : iterator::iterator_adaptor_base(Position), Self(Self) {}
411 bool isLoaded = this->
I < 0;
412 unsigned Index = isLoaded ?
413 Self->LoadedPreprocessedEntities.size() + this->
I : this->
I;
414 PPEntityID
ID = Self->getPPEntityID(Index, isLoaded);
415 return Self->getPreprocessedEntity(ID);
422 return iterator(
this, -(
int)LoadedPreprocessedEntities.size());
427 return iterator(
this, PreprocessedEntities.size());
437 return iterator(
this, PreprocessedEntities.size());
444 unsigned end = start + count;
445 assert(end <= LoadedPreprocessedEntities.size());
446 return llvm::make_range(
447 iterator(
this,
int(start) - LoadedPreprocessedEntities.size()),
448 iterator(
this,
int(end) - LoadedPreprocessedEntities.size()));
456 llvm::iterator_range<iterator>
476 return ExternalSource;
485 return SkippedRanges;
496 const FileEntry *File, StringRef SearchPath,
497 StringRef RelativePath,
498 const Module *Imported)
override;
507 void SourceRangeSkipped(
SourceRange Range)
override;
519 std::pair<int, int> getPreprocessedEntitiesInRangeSlow(
SourceRange R);
527 unsigned alignment) LLVM_NOEXCEPT {
528 return PR.Allocate(
bytes, alignment);
536 #endif // LLVM_CLANG_LEX_PREPROCESSINGRECORD_H
static bool classof(const PreprocessedEntity *PE)
__SIZE_TYPE__ size_t
The unsigned integer type of the result of the sizeof operator.
MacroExpansion(MacroDefinitionRecord *Definition, SourceRange Range)
A description of the current definition of a macro.
Indicates a problem trying to load the preprocessed entity.
Base class that describes a preprocessed entity, which may be a preprocessor directive or macro expan...
virtual PreprocessedEntity * ReadPreprocessedEntity(unsigned Index)=0
Read a preallocated preprocessed entity from the external source.
const std::vector< SourceRange > & getSkippedRanges() const
Retrieve all ranges that got skipped while preprocessing.
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range that covers this entire preprocessed entity.
iterator local_end()
End iterator for local, non-loaded, preprocessed entities.
StringRef getFileName() const
Retrieve the included file name as it was written in the source.
bool isBuiltinMacro() const
True if it is a builtin macro.
static StringRef bytes(const std::vector< T, Allocator > &v)
This interface provides a way to observe the actions of the preprocessor as it does its thing...
Records the presence of a preprocessor directive.
One of these records is kept for each identifier that is lexed.
Iteration over the preprocessed entities.
InclusionKind getKind() const
Determine what kind of inclusion directive this is.
Record the location of a macro definition.
Token - This structure provides full information about a lexed token.
bool wasInQuotes() const
Determine whether the included file name was written in quotes; otherwise, it was written in angle br...
Describes a module or submodule.
llvm::iterator_range< iterator > getPreprocessedEntitiesInRange(SourceRange R)
Returns a range of preprocessed entities that source range R encompasses.
EntityKind getKind() const
Retrieve the kind of preprocessed entity stored in this object.
A record of the steps taken while preprocessing a source file, including the various preprocessing di...
virtual std::pair< unsigned, unsigned > findPreprocessedEntitiesInRange(SourceRange Range)=0
Returns a pair of [Begin, End) indices of preallocated preprocessed entities that Range encompasses...
MacroDefinitionRecord * getDefinition() const
The definition of the macro being expanded.
MacroExpansion(IdentifierInfo *BuiltinName, SourceRange Range)
SourceManager & getSourceManager() const
detail::InMemoryDirectory::const_iterator I
virtual ~ExternalPreprocessingRecordSource()
const FileEntry * getFile() const
Retrieve the file entry for the actual file that was included by this directive.
Records the location of a macro expansion.
PreprocessingRecord(SourceManager &SM)
Construct a new preprocessing record.
A GNU #include_next directive.
static bool classof(const PreprocessedEntity *PE)
std::pair< int, int > Result
virtual Optional< bool > isPreprocessedEntityInFileID(unsigned Index, FileID FID)
Optionally returns true or false if the preallocated preprocessed entity with index Index came from f...
static bool classof(const PreprocessedEntity *PD)
StringRef getName() const
Return the actual identifier string.
void * Allocate(unsigned Size, unsigned Align=8)
Allocate memory in the preprocessing record.
Represents a character-granular source range.
MacroArgs - An instance of this class captures information about the formal arguments specified to a ...
PreprocessedEntity * operator->() const
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
bool importedModule() const
Determine whether the inclusion directive was automatically turned into a module import.
const IdentifierInfo * getName() const
The name of the macro being expanded.
Record the location of an inclusion directive, such as an #include or #import statement.
InclusionKind
The kind of inclusion directives known to the preprocessor.
llvm::iterator_range< iterator > getIteratorsForLoadedRange(unsigned start, unsigned count)
iterator range for the given range of loaded preprocessed entities.
ExternalPreprocessingRecordSource * getExternalSource() const
Retrieve the external source for preprocessed entities.
InclusionDirective(PreprocessingRecord &PPRec, InclusionKind Kind, StringRef FileName, bool InQuotes, bool ImportedModule, const FileEntry *File, SourceRange Range)
EntityKind
The kind of preprocessed entity an object describes.
Encapsulates changes to the "macros namespace" (the location where the macro name became active...
Encodes a location in the source.
void Deallocate(void *Ptr)
Deallocate memory in the preprocessing record.
const TemplateArgument * iterator
PreprocessedEntity(EntityKind Kind, SourceRange Range)
Cached information about one file (either on disk or in the virtual file system). ...
An abstract class that should be subclassed by any external source of preprocessing record entries...
MacroDefinitionRecord(const IdentifierInfo *Name, SourceRange Range)
SourceLocation getBegin() const
An inclusion directive, such as #include, #import, or #include_next.
bool isEntityInFileID(iterator PPEI, FileID FID)
Returns true if the preprocessed entity that PPEI iterator points to is coming from the file FID...
const IdentifierInfo * getName() const
Retrieve the name of the macro being defined.
A Clang #__include_macros directive.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Represents a template argument.
iterator end()
End iterator for all preprocessed entities.
static bool classof(const PreprocessedEntity *PE)
Reads an AST files chain containing the contents of a translation unit.
Encapsulates the data about a macro definition (e.g.
PPEntityID addPreprocessedEntity(PreprocessedEntity *Entity)
Add a new preprocessed entity to this record.
An Objective-C #import directive.
size_t getTotalMemory() const
Defines the PPCallbacks interface.
Defines the clang::SourceLocation class and associated facilities.
PreprocessedEntity * operator*() const
iterator begin()
Begin iterator for all preprocessed entities.
PreprocessingDirective(EntityKind Kind, SourceRange Range)
Writes an AST file containing the contents of a translation unit.
SourceLocation getLocation() const
Retrieve the location of the macro name in the definition.
MacroDefinitionRecord * findMacroDefinition(const MacroInfo *MI)
Retrieve the macro definition that corresponds to the given MacroInfo.
void SetExternalSource(ExternalPreprocessingRecordSource &Source)
Set the external source for preprocessed entities.
A trivial tuple used to represent a source range.
This class handles loading and caching of source files into memory.
bool isInvalid() const
Returns true if there was a problem loading the preprocessed entity.
iterator local_begin()
Begin iterator for local, non-loaded, preprocessed entities.