15 #ifndef LLVM_CLANG_LEX_PREPROCESSINGRECORD_H 16 #define LLVM_CLANG_LEX_PREPROCESSINGRECORD_H 22 #include "llvm/ADT/DenseMap.h" 23 #include "llvm/ADT/None.h" 24 #include "llvm/ADT/Optional.h" 25 #include "llvm/ADT/PointerUnion.h" 26 #include "llvm/ADT/StringRef.h" 27 #include "llvm/ADT/iterator.h" 28 #include "llvm/ADT/iterator_range.h" 29 #include "llvm/Support/Allocator.h" 30 #include "llvm/Support/Compiler.h" 39 class PreprocessingRecord;
45 unsigned alignment = 8) noexcept;
98 : Kind(Kind), Range(Range) {}
115 unsigned alignment = 8) noexcept {
116 return ::operator
new(
bytes, PR, alignment);
119 void *
operator new(
size_t bytes,
void *mem) noexcept {
return mem; }
122 unsigned alignment) noexcept {
123 return ::operator
delete(ptr, PR, alignment);
127 void operator delete(
void *,
void *) noexcept {}
131 void *
operator new(
size_t bytes) noexcept;
132 void operator delete(
void *data) noexcept;
174 llvm::PointerUnion<IdentifierInfo *, MacroDefinitionRecord *> NameOrDef;
179 NameOrDef(BuiltinName) {}
234 unsigned InQuotes : 1;
243 unsigned ImportedModule : 1;
251 bool InQuotes,
bool ImportedModule,
292 virtual std::pair<unsigned, unsigned>
293 findPreprocessedEntitiesInRange(
SourceRange Range) = 0;
303 virtual SourceRange ReadSkippedRange(
unsigned Index) = 0;
313 llvm::BumpPtrAllocator BumpAlloc;
317 std::vector<PreprocessedEntity *> PreprocessedEntities;
324 std::vector<PreprocessedEntity *> LoadedPreprocessedEntities;
327 std::vector<SourceRange> SkippedRanges;
329 bool SkippedRangesAllLoaded =
true;
345 explicit PPEntityID(
int ID) :
ID(ID) {}
348 PPEntityID() =
default;
351 static PPEntityID getPPEntityID(
unsigned Index,
bool isLoaded) {
352 return isLoaded ? PPEntityID(-
int(Index)-1) : PPEntityID(Index+1);
356 llvm::DenseMap<const MacroInfo *, MacroDefinitionRecord *> MacroDefinitions;
369 unsigned getNumLoadedPreprocessedEntities()
const {
370 return LoadedPreprocessedEntities.size();
375 std::pair<unsigned, unsigned>
376 findLocalPreprocessedEntitiesInRange(
SourceRange Range)
const;
377 unsigned findBeginLocalPreprocessedEntity(
SourceLocation Loc)
const;
378 unsigned findEndLocalPreprocessedEntity(
SourceLocation Loc)
const;
384 unsigned allocateLoadedEntities(
unsigned NumEntities);
391 unsigned allocateSkippedRanges(
unsigned NumRanges);
394 void ensureSkippedRangesLoaded();
404 void *
Allocate(
unsigned Size,
unsigned Align = 8) {
405 return BumpAlloc.Allocate(Size, Align);
411 size_t getTotalMemory()
const;
431 class iterator :
public llvm::iterator_adaptor_base<
432 iterator, int, std::random_access_iterator_tag,
433 PreprocessedEntity *, int, PreprocessedEntity *,
434 PreprocessedEntity *> {
440 :
iterator::iterator_adaptor_base(Position), Self(Self) {}
446 bool isLoaded = this->I < 0;
447 unsigned Index = isLoaded ?
448 Self->LoadedPreprocessedEntities.size() + this->I : this->I;
449 PPEntityID
ID = Self->getPPEntityID(Index, isLoaded);
450 return Self->getPreprocessedEntity(ID);
457 return iterator(
this, -(
int)LoadedPreprocessedEntities.size());
462 return iterator(
this, PreprocessedEntities.size());
472 return iterator(
this, PreprocessedEntities.size());
479 unsigned end = start + count;
480 assert(end <= LoadedPreprocessedEntities.size());
481 return llvm::make_range(
482 iterator(
this,
int(start) - LoadedPreprocessedEntities.size()),
483 iterator(
this,
int(end) - LoadedPreprocessedEntities.size()));
490 llvm::iterator_range<iterator>
510 return ExternalSource;
519 ensureSkippedRangesLoaded();
520 return SkippedRanges;
533 StringRef FileName,
bool IsAngled,
535 const FileEntry *File, StringRef SearchPath,
536 StringRef RelativePath,
const Module *Imported,
560 std::pair<int, int> getPreprocessedEntitiesInRangeSlow(
SourceRange R);
566 unsigned alignment) noexcept {
567 return PR.Allocate(
bytes, alignment);
575 #endif // LLVM_CLANG_LEX_PREPROCESSINGRECORD_H const FileEntry * getFile() const
Retrieve the file entry for the actual file that was included by this directive.
static bool classof(const PreprocessedEntity *PE)
const std::vector< SourceRange > & getSkippedRanges()
Retrieve all ranges that got skipped while preprocessing.
static ClassTemplateDecl * getDefinition(ClassTemplateDecl *D)
__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...
SourceRange getSourceRange() const LLVM_READONLY
Retrieve the source range that covers this entire preprocessed entity.
CharacteristicKind
Indicates whether a file or directory holds normal user code, system code, or system code which is im...
iterator local_end()
End iterator for local, non-loaded, preprocessed entities.
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.
Record the location of a macro definition.
Token - This structure provides full information about a lexed token.
friend class PreprocessingRecord
Describes a module or submodule.
A record of the steps taken while preprocessing a source file, including the various preprocessing di...
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
SourceManager & getSourceManager() const
MacroExpansion(IdentifierInfo *BuiltinName, SourceRange Range)
StringRef getFileName() const
Retrieve the included file name as it was written in the source.
Records the location of a macro expansion.
InclusionKind getKind() const
Determine what kind of inclusion directive this is.
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)
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 ...
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
Record the location of an inclusion directive, such as an #include or #import statement.
bool isBuiltinMacro() const
True if it is a builtin macro.
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.
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.
bool isInvalid() const
Returns true if there was a problem loading the preprocessed entity.
void Deallocate(void *Ptr)
Deallocate memory in the preprocessing record.
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)
const IdentifierInfo * getName() const
Retrieve the name of the macro being defined.
An inclusion directive, such as #include, #import, or #include_next.
StringRef getName() const
Return the actual identifier string.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
iterator end()
End iterator for all preprocessed entities.
Dataflow Directional Tag Classes.
static bool classof(const PreprocessedEntity *PE)
Reads an AST files chain containing the contents of a translation unit.
const IdentifierInfo * getName() const
The name of the macro being expanded.
bool wasInQuotes() const
Determine whether the included file name was written in quotes; otherwise, it was written in angle br...
Encapsulates the data about a macro definition (e.g.
PreprocessedEntity * operator*() const
SourceLocation getLocation() const
Retrieve the location of the macro name in the definition.
An Objective-C #import directive.
Defines the PPCallbacks interface.
ExternalPreprocessingRecordSource * getExternalSource() const
Retrieve the external source for preprocessed entities.
Defines the clang::SourceLocation class and associated facilities.
iterator begin()
Begin iterator for all preprocessed entities.
PreprocessingDirective(EntityKind Kind, SourceRange Range)
EntityKind getKind() const
Retrieve the kind of preprocessed entity stored in this object.
bool importedModule() const
Determine whether the inclusion directive was automatically turned into a module import.
Writes an AST file containing the contents of a translation unit.
PreprocessedEntity * operator->() const
A trivial tuple used to represent a source range.
SourceLocation getBegin() const
This class handles loading and caching of source files into memory.
MacroDefinitionRecord * getDefinition() const
The definition of the macro being expanded.
iterator local_begin()
Begin iterator for local, non-loaded, preprocessed entities.