PreprocessingRecord.h revision 92ddef1bf843e1e18c040d69f48a6bf0bc7c776a
133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org//===--- PreprocessingRecord.h - Record of Preprocessing --------*- C++ -*-===// 233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org// 333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org// The LLVM Compiler Infrastructure 433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org// 533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org// This file is distributed under the University of Illinois Open Source 633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org// License. See LICENSE.TXT for details. 733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org// 833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org//===----------------------------------------------------------------------===// 933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org// 1033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org// This file defines the PreprocessingRecord class, which maintains a record 1133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org// of what occurred during preprocessing. 1233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org// 1333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org//===----------------------------------------------------------------------===// 1433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org#ifndef LLVM_CLANG_LEX_PREPROCESSINGRECORD_H 1533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org#define LLVM_CLANG_LEX_PREPROCESSINGRECORD_H 1633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 1733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org#include "clang/Lex/PPCallbacks.h" 1833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org#include "clang/Basic/SourceLocation.h" 1933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org#include "clang/Basic/IdentifierTable.h" 2033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org#include "llvm/ADT/DenseMap.h" 2133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org#include "llvm/Support/Allocator.h" 2233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org#include <vector> 2333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 2433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.orgnamespace clang { 2533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org class IdentifierInfo; 2633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org class PreprocessingRecord; 2733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org} 2833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 2933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org/// \brief Allocates memory within a Clang preprocessing record. 3033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.orgvoid* operator new(size_t bytes, clang::PreprocessingRecord& PR, 3133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org unsigned alignment = 8) throw(); 3233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 3333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org/// \brief Frees memory allocated in a Clang preprocessing record. 3433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.orgvoid operator delete(void* ptr, clang::PreprocessingRecord& PR, 3533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org unsigned) throw(); 3633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 3733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.orgnamespace clang { 3833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org class MacroDefinition; 3933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org class FileEntry; 4033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 4133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org /// \brief Base class that describes a preprocessed entity, which may be a 4233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org /// preprocessor directive or macro expansion. 4333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org class PreprocessedEntity { 4433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org public: 4533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org /// \brief The kind of preprocessed entity an object describes. 4633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org enum EntityKind { 4733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org /// \brief Indicates a problem trying to load the preprocessed entity. 4833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org InvalidKind, 4933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 5033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org /// \brief A macro expansion. 5133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org MacroExpansionKind, 5233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 5333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org /// \brief A preprocessing directive whose kind is not specified. 5433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org /// 5533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org /// This kind will be used for any preprocessing directive that does not 5633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org /// have a more specific kind within the \c DirectiveKind enumeration. 5733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org PreprocessingDirectiveKind, 5833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 5933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org /// \brief A macro definition. 6033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org MacroDefinitionKind, 6133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 6233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org /// \brief An inclusion directive, such as \c #include, \c 6333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org /// #import, or \c #include_next. 6433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org InclusionDirectiveKind, 6533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 6633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org FirstPreprocessingDirective = PreprocessingDirectiveKind, 6733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org LastPreprocessingDirective = InclusionDirectiveKind 6833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org }; 6933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 7033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org private: 7133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org /// \brief The kind of preprocessed entity that this object describes. 7233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org EntityKind Kind; 7333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 7433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org /// \brief The source range that covers this preprocessed entity. 7533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org SourceRange Range; 7633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 7733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org protected: 7833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org PreprocessedEntity(EntityKind Kind, SourceRange Range) 7933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org : Kind(Kind), Range(Range) { } 8033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 8133e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org friend class PreprocessingRecord; 8233e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 8333e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org public: 8433e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org /// \brief Retrieve the kind of preprocessed entity stored in this object. 8533e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org EntityKind getKind() const { return Kind; } 8633e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 8733e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org /// \brief Retrieve the source range that covers this entire preprocessed 8833e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org /// entity. 8933e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org SourceRange getSourceRange() const { return Range; } 9033e09c8efd078308de3c77a88301566f65c07befverwaest@chromium.org 91 /// \brief Returns true if there was a problem loading the preprocessed 92 /// entity. 93 bool isInvalid() const { return Kind == InvalidKind; } 94 95 // Implement isa/cast/dyncast/etc. 96 static bool classof(const PreprocessedEntity *) { return true; } 97 98 // Only allow allocation of preprocessed entities using the allocator 99 // in PreprocessingRecord or by doing a placement new. 100 void* operator new(size_t bytes, PreprocessingRecord& PR, 101 unsigned alignment = 8) throw() { 102 return ::operator new(bytes, PR, alignment); 103 } 104 105 void* operator new(size_t bytes, void* mem) throw() { 106 return mem; 107 } 108 109 void operator delete(void* ptr, PreprocessingRecord& PR, 110 unsigned alignment) throw() { 111 return ::operator delete(ptr, PR, alignment); 112 } 113 114 void operator delete(void*, std::size_t) throw() { } 115 void operator delete(void*, void*) throw() { } 116 117 private: 118 // Make vanilla 'new' and 'delete' illegal for preprocessed entities. 119 void* operator new(size_t bytes) throw(); 120 void operator delete(void* data) throw(); 121 }; 122 123 /// \brief Records the presence of a preprocessor directive. 124 class PreprocessingDirective : public PreprocessedEntity { 125 public: 126 PreprocessingDirective(EntityKind Kind, SourceRange Range) 127 : PreprocessedEntity(Kind, Range) { } 128 129 // Implement isa/cast/dyncast/etc. 130 static bool classof(const PreprocessedEntity *PD) { 131 return PD->getKind() >= FirstPreprocessingDirective && 132 PD->getKind() <= LastPreprocessingDirective; 133 } 134 static bool classof(const PreprocessingDirective *) { return true; } 135 }; 136 137 /// \brief Record the location of a macro definition. 138 class MacroDefinition : public PreprocessingDirective { 139 /// \brief The name of the macro being defined. 140 const IdentifierInfo *Name; 141 142 /// \brief The location of the macro name in the macro definition. 143 SourceLocation Location; 144 145 public: 146 explicit MacroDefinition(const IdentifierInfo *Name, SourceLocation Location, 147 SourceRange Range) 148 : PreprocessingDirective(MacroDefinitionKind, Range), Name(Name), 149 Location(Location) { } 150 151 /// \brief Retrieve the name of the macro being defined. 152 const IdentifierInfo *getName() const { return Name; } 153 154 /// \brief Retrieve the location of the macro name in the definition. 155 SourceLocation getLocation() const { return Location; } 156 157 // Implement isa/cast/dyncast/etc. 158 static bool classof(const PreprocessedEntity *PE) { 159 return PE->getKind() == MacroDefinitionKind; 160 } 161 static bool classof(const MacroDefinition *) { return true; } 162 }; 163 164 /// \brief Records the location of a macro expansion. 165 class MacroExpansion : public PreprocessedEntity { 166 /// \brief The definition of this macro or the name of the macro if it is 167 /// a builtin macro. 168 llvm::PointerUnion<IdentifierInfo *, MacroDefinition *> NameOrDef; 169 170 public: 171 MacroExpansion(IdentifierInfo *BuiltinName, SourceRange Range) 172 : PreprocessedEntity(MacroExpansionKind, Range), 173 NameOrDef(BuiltinName) { } 174 175 MacroExpansion(MacroDefinition *Definition, SourceRange Range) 176 : PreprocessedEntity(MacroExpansionKind, Range), 177 NameOrDef(Definition) { } 178 179 /// \brief True if it is a builtin macro. 180 bool isBuiltinMacro() const { return NameOrDef.is<IdentifierInfo *>(); } 181 182 /// \brief The name of the macro being expanded. 183 const IdentifierInfo *getName() const { 184 if (MacroDefinition *Def = getDefinition()) 185 return Def->getName(); 186 return NameOrDef.get<IdentifierInfo*>(); 187 } 188 189 /// \brief The definition of the macro being expanded. May return null if 190 /// this is a builtin macro. 191 MacroDefinition *getDefinition() const { 192 return NameOrDef.dyn_cast<MacroDefinition *>(); 193 } 194 195 // Implement isa/cast/dyncast/etc. 196 static bool classof(const PreprocessedEntity *PE) { 197 return PE->getKind() == MacroExpansionKind; 198 } 199 static bool classof(const MacroExpansion *) { return true; } 200 }; 201 202 /// \brief Record the location of an inclusion directive, such as an 203 /// \c #include or \c #import statement. 204 class InclusionDirective : public PreprocessingDirective { 205 public: 206 /// \brief The kind of inclusion directives known to the 207 /// preprocessor. 208 enum InclusionKind { 209 /// \brief An \c #include directive. 210 Include, 211 /// \brief An Objective-C \c #import directive. 212 Import, 213 /// \brief A GNU \c #include_next directive. 214 IncludeNext, 215 /// \brief A Clang \c #__include_macros directive. 216 IncludeMacros 217 }; 218 219 private: 220 /// \brief The name of the file that was included, as written in 221 /// the source. 222 StringRef FileName; 223 224 /// \brief Whether the file name was in quotation marks; otherwise, it was 225 /// in angle brackets. 226 unsigned InQuotes : 1; 227 228 /// \brief The kind of inclusion directive we have. 229 /// 230 /// This is a value of type InclusionKind. 231 unsigned Kind : 2; 232 233 /// \brief The file that was included. 234 const FileEntry *File; 235 236 public: 237 InclusionDirective(PreprocessingRecord &PPRec, 238 InclusionKind Kind, StringRef FileName, 239 bool InQuotes, const FileEntry *File, SourceRange Range); 240 241 /// \brief Determine what kind of inclusion directive this is. 242 InclusionKind getKind() const { return static_cast<InclusionKind>(Kind); } 243 244 /// \brief Retrieve the included file name as it was written in the source. 245 StringRef getFileName() const { return FileName; } 246 247 /// \brief Determine whether the included file name was written in quotes; 248 /// otherwise, it was written in angle brackets. 249 bool wasInQuotes() const { return InQuotes; } 250 251 /// \brief Retrieve the file entry for the actual file that was included 252 /// by this directive. 253 const FileEntry *getFile() const { return File; } 254 255 // Implement isa/cast/dyncast/etc. 256 static bool classof(const PreprocessedEntity *PE) { 257 return PE->getKind() == InclusionDirectiveKind; 258 } 259 static bool classof(const InclusionDirective *) { return true; } 260 }; 261 262 /// \brief An abstract class that should be subclassed by any external source 263 /// of preprocessing record entries. 264 class ExternalPreprocessingRecordSource { 265 public: 266 virtual ~ExternalPreprocessingRecordSource(); 267 268 /// \brief Read a preallocated preprocessed entity from the external source. 269 /// 270 /// \returns null if an error occurred that prevented the preprocessed 271 /// entity from being loaded. 272 virtual PreprocessedEntity *ReadPreprocessedEntity(unsigned Index) = 0; 273 274 /// \brief Returns a pair of [Begin, End) indices of preallocated 275 /// preprocessed entities that \arg Range encompasses. 276 virtual std::pair<unsigned, unsigned> 277 findPreprocessedEntitiesInRange(SourceRange Range) = 0; 278 }; 279 280 /// \brief A record of the steps taken while preprocessing a source file, 281 /// including the various preprocessing directives processed, macros 282 /// expanded, etc. 283 class PreprocessingRecord : public PPCallbacks { 284 SourceManager &SourceMgr; 285 286 /// \brief Whether we should include nested macro expansions in 287 /// the preprocessing record. 288 bool IncludeNestedMacroExpansions; 289 290 /// \brief Allocator used to store preprocessing objects. 291 llvm::BumpPtrAllocator BumpAlloc; 292 293 /// \brief The set of preprocessed entities in this record, in order they 294 /// were seen. 295 std::vector<PreprocessedEntity *> PreprocessedEntities; 296 297 /// \brief The set of preprocessed entities in this record that have been 298 /// loaded from external sources. 299 /// 300 /// The entries in this vector are loaded lazily from the external source, 301 /// and are referenced by the iterator using negative indices. 302 std::vector<PreprocessedEntity *> LoadedPreprocessedEntities; 303 304 /// \brief Global (loaded or local) ID for a preprocessed entity. 305 /// Negative values are used to indicate preprocessed entities 306 /// loaded from the external source while non-negative values are used to 307 /// indicate preprocessed entities introduced by the current preprocessor. 308 /// If M is the number of loaded preprocessed entities, value -M 309 /// corresponds to element 0 in the loaded entities vector, position -M+1 310 /// corresponds to element 1 in the loaded entities vector, etc. 311 typedef int PPEntityID; 312 313 PPEntityID getPPEntityID(unsigned Index, bool isLoaded) const { 314 return isLoaded ? PPEntityID(Index) - LoadedPreprocessedEntities.size() 315 : Index; 316 } 317 318 /// \brief Mapping from MacroInfo structures to their definitions. 319 llvm::DenseMap<const MacroInfo *, PPEntityID> MacroDefinitions; 320 321 /// \brief External source of preprocessed entities. 322 ExternalPreprocessingRecordSource *ExternalSource; 323 324 /// \brief Retrieve the preprocessed entity at the given ID. 325 PreprocessedEntity *getPreprocessedEntity(PPEntityID PPID); 326 327 /// \brief Retrieve the loaded preprocessed entity at the given index. 328 PreprocessedEntity *getLoadedPreprocessedEntity(unsigned Index); 329 330 /// \brief Determine the number of preprocessed entities that were 331 /// loaded (or can be loaded) from an external source. 332 unsigned getNumLoadedPreprocessedEntities() const { 333 return LoadedPreprocessedEntities.size(); 334 } 335 336 /// \brief Returns a pair of [Begin, End) indices of local preprocessed 337 /// entities that \arg Range encompasses. 338 std::pair<unsigned, unsigned> 339 findLocalPreprocessedEntitiesInRange(SourceRange Range) const; 340 unsigned findBeginLocalPreprocessedEntity(SourceLocation Loc) const; 341 unsigned findEndLocalPreprocessedEntity(SourceLocation Loc) const; 342 343 /// \brief Allocate space for a new set of loaded preprocessed entities. 344 /// 345 /// \returns The index into the set of loaded preprocessed entities, which 346 /// corresponds to the first newly-allocated entity. 347 unsigned allocateLoadedEntities(unsigned NumEntities); 348 349 /// \brief Register a new macro definition. 350 void RegisterMacroDefinition(MacroInfo *Macro, PPEntityID PPID); 351 352 public: 353 /// \brief Construct a new preprocessing record. 354 PreprocessingRecord(SourceManager &SM, bool IncludeNestedMacroExpansions); 355 356 /// \brief Allocate memory in the preprocessing record. 357 void *Allocate(unsigned Size, unsigned Align = 8) { 358 return BumpAlloc.Allocate(Size, Align); 359 } 360 361 /// \brief Deallocate memory in the preprocessing record. 362 void Deallocate(void *Ptr) { } 363 364 size_t getTotalMemory() const; 365 366 SourceManager &getSourceManager() const { return SourceMgr; } 367 368 // Iteration over the preprocessed entities. 369 class iterator { 370 PreprocessingRecord *Self; 371 372 /// \brief Position within the preprocessed entity sequence. 373 /// 374 /// In a complete iteration, the Position field walks the range [-M, N), 375 /// where negative values are used to indicate preprocessed entities 376 /// loaded from the external source while non-negative values are used to 377 /// indicate preprocessed entities introduced by the current preprocessor. 378 /// However, to provide iteration in source order (for, e.g., chained 379 /// precompiled headers), dereferencing the iterator flips the negative 380 /// values (corresponding to loaded entities), so that position -M 381 /// corresponds to element 0 in the loaded entities vector, position -M+1 382 /// corresponds to element 1 in the loaded entities vector, etc. This 383 /// gives us a reasonably efficient, source-order walk. 384 PPEntityID Position; 385 386 public: 387 typedef PreprocessedEntity *value_type; 388 typedef value_type& reference; 389 typedef value_type* pointer; 390 typedef std::random_access_iterator_tag iterator_category; 391 typedef int difference_type; 392 393 iterator() : Self(0), Position(0) { } 394 395 iterator(PreprocessingRecord *Self, int Position) 396 : Self(Self), Position(Position) { } 397 398 value_type operator*() const { 399 return Self->getPreprocessedEntity(Position); 400 } 401 402 value_type operator[](difference_type D) { 403 return *(*this + D); 404 } 405 406 iterator &operator++() { 407 ++Position; 408 return *this; 409 } 410 411 iterator operator++(int) { 412 iterator Prev(*this); 413 ++Position; 414 return Prev; 415 } 416 417 iterator &operator--() { 418 --Position; 419 return *this; 420 } 421 422 iterator operator--(int) { 423 iterator Prev(*this); 424 --Position; 425 return Prev; 426 } 427 428 friend bool operator==(const iterator &X, const iterator &Y) { 429 return X.Position == Y.Position; 430 } 431 432 friend bool operator!=(const iterator &X, const iterator &Y) { 433 return X.Position != Y.Position; 434 } 435 436 friend bool operator<(const iterator &X, const iterator &Y) { 437 return X.Position < Y.Position; 438 } 439 440 friend bool operator>(const iterator &X, const iterator &Y) { 441 return X.Position > Y.Position; 442 } 443 444 friend bool operator<=(const iterator &X, const iterator &Y) { 445 return X.Position < Y.Position; 446 } 447 448 friend bool operator>=(const iterator &X, const iterator &Y) { 449 return X.Position > Y.Position; 450 } 451 452 friend iterator& operator+=(iterator &X, difference_type D) { 453 X.Position += D; 454 return X; 455 } 456 457 friend iterator& operator-=(iterator &X, difference_type D) { 458 X.Position -= D; 459 return X; 460 } 461 462 friend iterator operator+(iterator X, difference_type D) { 463 X.Position += D; 464 return X; 465 } 466 467 friend iterator operator+(difference_type D, iterator X) { 468 X.Position += D; 469 return X; 470 } 471 472 friend difference_type operator-(const iterator &X, const iterator &Y) { 473 return X.Position - Y.Position; 474 } 475 476 friend iterator operator-(iterator X, difference_type D) { 477 X.Position -= D; 478 return X; 479 } 480 }; 481 friend class iterator; 482 483 /// \brief Begin iterator for all preprocessed entities. 484 iterator begin() { 485 return iterator(this, -(int)LoadedPreprocessedEntities.size()); 486 } 487 488 /// \brief End iterator for all preprocessed entities. 489 iterator end() { 490 return iterator(this, PreprocessedEntities.size()); 491 } 492 493 /// \brief Begin iterator for local, non-loaded, preprocessed entities. 494 iterator local_begin() { 495 return iterator(this, 0); 496 } 497 498 /// \brief End iterator for local, non-loaded, preprocessed entities. 499 iterator local_end() { 500 return iterator(this, PreprocessedEntities.size()); 501 } 502 503 /// \brief Returns a pair of [Begin, End) iterators of preprocessed entities 504 /// that source range \arg R encompasses. 505 std::pair<iterator, iterator> getPreprocessedEntitiesInRange(SourceRange R); 506 507 /// \brief Add a new preprocessed entity to this record. 508 void addPreprocessedEntity(PreprocessedEntity *Entity); 509 510 /// \brief Set the external source for preprocessed entities. 511 void SetExternalSource(ExternalPreprocessingRecordSource &Source); 512 513 /// \brief Retrieve the external source for preprocessed entities. 514 ExternalPreprocessingRecordSource *getExternalSource() const { 515 return ExternalSource; 516 } 517 518 /// \brief Retrieve the macro definition that corresponds to the given 519 /// \c MacroInfo. 520 MacroDefinition *findMacroDefinition(const MacroInfo *MI); 521 522 virtual void MacroExpands(const Token &Id, const MacroInfo* MI, 523 SourceRange Range); 524 virtual void MacroDefined(const Token &Id, const MacroInfo *MI); 525 virtual void MacroUndefined(const Token &Id, const MacroInfo *MI); 526 virtual void InclusionDirective(SourceLocation HashLoc, 527 const Token &IncludeTok, 528 StringRef FileName, 529 bool IsAngled, 530 const FileEntry *File, 531 SourceLocation EndLoc, 532 StringRef SearchPath, 533 StringRef RelativePath); 534 535 friend class ASTReader; 536 friend class ASTWriter; 537 }; 538} // end namespace clang 539 540inline void* operator new(size_t bytes, clang::PreprocessingRecord& PR, 541 unsigned alignment) throw() { 542 return PR.Allocate(bytes, alignment); 543} 544 545inline void operator delete(void* ptr, clang::PreprocessingRecord& PR, 546 unsigned) throw() { 547 PR.Deallocate(ptr); 548} 549 550#endif // LLVM_CLANG_LEX_PREPROCESSINGRECORD_H 551