clang  16.0.0git
PreprocessingRecord.cpp
Go to the documentation of this file.
1 //===- PreprocessingRecord.cpp - Record of Preprocessing ------------------===//
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 implements the PreprocessingRecord class, which maintains a record
10 // of what occurred during preprocessing, and its helpers.
11 //
12 //===----------------------------------------------------------------------===//
13 
16 #include "clang/Basic/LLVM.h"
19 #include "clang/Basic/TokenKinds.h"
20 #include "clang/Lex/MacroInfo.h"
21 #include "clang/Lex/Token.h"
22 #include "llvm/ADT/DenseMap.h"
23 #include "llvm/ADT/Optional.h"
24 #include "llvm/ADT/StringRef.h"
25 #include "llvm/ADT/iterator_range.h"
26 #include "llvm/Support/Capacity.h"
27 #include "llvm/Support/Casting.h"
28 #include "llvm/Support/ErrorHandling.h"
29 #include <algorithm>
30 #include <cassert>
31 #include <cstddef>
32 #include <cstring>
33 #include <iterator>
34 #include <utility>
35 #include <vector>
36 
37 using namespace clang;
38 
40  default;
41 
43  InclusionKind Kind, StringRef FileName,
44  bool InQuotes, bool ImportedModule,
46  SourceRange Range)
47  : PreprocessingDirective(InclusionDirectiveKind, Range), InQuotes(InQuotes),
48  Kind(Kind), ImportedModule(ImportedModule), File(File) {
49  char *Memory = (char *)PPRec.Allocate(FileName.size() + 1, alignof(char));
50  memcpy(Memory, FileName.data(), FileName.size());
51  Memory[FileName.size()] = 0;
52  this->FileName = StringRef(Memory, FileName.size());
53 }
54 
56 
57 /// Returns a pair of [Begin, End) iterators of preprocessed entities
58 /// that source range \p Range encompasses.
59 llvm::iterator_range<PreprocessingRecord::iterator>
61  if (Range.isInvalid())
62  return llvm::make_range(iterator(), iterator());
63 
64  if (CachedRangeQuery.Range == Range) {
65  return llvm::make_range(iterator(this, CachedRangeQuery.Result.first),
66  iterator(this, CachedRangeQuery.Result.second));
67  }
68 
69  std::pair<int, int> Res = getPreprocessedEntitiesInRangeSlow(Range);
70 
71  CachedRangeQuery.Range = Range;
72  CachedRangeQuery.Result = Res;
73 
74  return llvm::make_range(iterator(this, Res.first),
75  iterator(this, Res.second));
76 }
77 
79  SourceManager &SM) {
80  assert(FID.isValid());
81  if (!PPE)
82  return false;
83 
84  SourceLocation Loc = PPE->getSourceRange().getBegin();
85  if (Loc.isInvalid())
86  return false;
87 
88  return SM.isInFileID(SM.getFileLoc(Loc), FID);
89 }
90 
91 /// Returns true if the preprocessed entity that \arg PPEI iterator
92 /// points to is coming from the file \arg FID.
93 ///
94 /// Can be used to avoid implicit deserializations of preallocated
95 /// preprocessed entities if we only care about entities of a specific file
96 /// and not from files \#included in the range given at
97 /// \see getPreprocessedEntitiesInRange.
99  if (FID.isInvalid())
100  return false;
101 
102  int Pos = std::distance(iterator(this, 0), PPEI);
103  if (Pos < 0) {
104  if (unsigned(-Pos-1) >= LoadedPreprocessedEntities.size()) {
105  assert(0 && "Out-of bounds loaded preprocessed entity");
106  return false;
107  }
108  assert(ExternalSource && "No external source to load from");
109  unsigned LoadedIndex = LoadedPreprocessedEntities.size()+Pos;
110  if (PreprocessedEntity *PPE = LoadedPreprocessedEntities[LoadedIndex])
111  return isPreprocessedEntityIfInFileID(PPE, FID, SourceMgr);
112 
113  // See if the external source can see if the entity is in the file without
114  // deserializing it.
115  Optional<bool> IsInFile =
116  ExternalSource->isPreprocessedEntityInFileID(LoadedIndex, FID);
117  if (IsInFile)
118  return IsInFile.value();
119 
120  // The external source did not provide a definite answer, go and deserialize
121  // the entity to check it.
123  getLoadedPreprocessedEntity(LoadedIndex),
124  FID, SourceMgr);
125  }
126 
127  if (unsigned(Pos) >= PreprocessedEntities.size()) {
128  assert(0 && "Out-of bounds local preprocessed entity");
129  return false;
130  }
131  return isPreprocessedEntityIfInFileID(PreprocessedEntities[Pos],
132  FID, SourceMgr);
133 }
134 
135 /// Returns a pair of [Begin, End) iterators of preprocessed entities
136 /// that source range \arg R encompasses.
137 std::pair<int, int>
138 PreprocessingRecord::getPreprocessedEntitiesInRangeSlow(SourceRange Range) {
139  assert(Range.isValid());
140  assert(!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(),Range.getBegin()));
141 
142  std::pair<unsigned, unsigned>
143  Local = findLocalPreprocessedEntitiesInRange(Range);
144 
145  // Check if range spans local entities.
146  if (!ExternalSource || SourceMgr.isLocalSourceLocation(Range.getBegin()))
147  return std::make_pair(Local.first, Local.second);
148 
149  std::pair<unsigned, unsigned>
150  Loaded = ExternalSource->findPreprocessedEntitiesInRange(Range);
151 
152  // Check if range spans local entities.
153  if (Loaded.first == Loaded.second)
154  return std::make_pair(Local.first, Local.second);
155 
156  unsigned TotalLoaded = LoadedPreprocessedEntities.size();
157 
158  // Check if range spans loaded entities.
159  if (Local.first == Local.second)
160  return std::make_pair(int(Loaded.first)-TotalLoaded,
161  int(Loaded.second)-TotalLoaded);
162 
163  // Range spands loaded and local entities.
164  return std::make_pair(int(Loaded.first)-TotalLoaded, Local.second);
165 }
166 
167 std::pair<unsigned, unsigned>
168 PreprocessingRecord::findLocalPreprocessedEntitiesInRange(
169  SourceRange Range) const {
170  if (Range.isInvalid())
171  return std::make_pair(0,0);
172  assert(!SourceMgr.isBeforeInTranslationUnit(Range.getEnd(),Range.getBegin()));
173 
174  unsigned Begin = findBeginLocalPreprocessedEntity(Range.getBegin());
175  unsigned End = findEndLocalPreprocessedEntity(Range.getEnd());
176  return std::make_pair(Begin, End);
177 }
178 
179 namespace {
180 
181 template <SourceLocation (SourceRange::*getRangeLoc)() const>
182 struct PPEntityComp {
183  const SourceManager &SM;
184 
185  explicit PPEntityComp(const SourceManager &SM) : SM(SM) {}
186 
187  bool operator()(PreprocessedEntity *L, PreprocessedEntity *R) const {
188  SourceLocation LHS = getLoc(L);
189  SourceLocation RHS = getLoc(R);
190  return SM.isBeforeInTranslationUnit(LHS, RHS);
191  }
192 
193  bool operator()(PreprocessedEntity *L, SourceLocation RHS) const {
194  SourceLocation LHS = getLoc(L);
195  return SM.isBeforeInTranslationUnit(LHS, RHS);
196  }
197 
198  bool operator()(SourceLocation LHS, PreprocessedEntity *R) const {
199  SourceLocation RHS = getLoc(R);
200  return SM.isBeforeInTranslationUnit(LHS, RHS);
201  }
202 
203  SourceLocation getLoc(PreprocessedEntity *PPE) const {
205  return (Range.*getRangeLoc)();
206  }
207 };
208 
209 } // namespace
210 
211 unsigned PreprocessingRecord::findBeginLocalPreprocessedEntity(
212  SourceLocation Loc) const {
213  if (SourceMgr.isLoadedSourceLocation(Loc))
214  return 0;
215 
216  size_t Count = PreprocessedEntities.size();
217  size_t Half;
218  std::vector<PreprocessedEntity *>::const_iterator
219  First = PreprocessedEntities.begin();
220  std::vector<PreprocessedEntity *>::const_iterator I;
221 
222  // Do a binary search manually instead of using std::lower_bound because
223  // The end locations of entities may be unordered (when a macro expansion
224  // is inside another macro argument), but for this case it is not important
225  // whether we get the first macro expansion or its containing macro.
226  while (Count > 0) {
227  Half = Count/2;
228  I = First;
229  std::advance(I, Half);
230  if (SourceMgr.isBeforeInTranslationUnit((*I)->getSourceRange().getEnd(),
231  Loc)){
232  First = I;
233  ++First;
234  Count = Count - Half - 1;
235  } else
236  Count = Half;
237  }
238 
239  return First - PreprocessedEntities.begin();
240 }
241 
242 unsigned
243 PreprocessingRecord::findEndLocalPreprocessedEntity(SourceLocation Loc) const {
244  if (SourceMgr.isLoadedSourceLocation(Loc))
245  return 0;
246 
247  auto I = llvm::upper_bound(PreprocessedEntities, Loc,
248  PPEntityComp<&SourceRange::getBegin>(SourceMgr));
249  return I - PreprocessedEntities.begin();
250 }
251 
252 PreprocessingRecord::PPEntityID
254  assert(Entity);
255  SourceLocation BeginLoc = Entity->getSourceRange().getBegin();
256 
257  if (isa<MacroDefinitionRecord>(Entity)) {
258  assert((PreprocessedEntities.empty() ||
259  !SourceMgr.isBeforeInTranslationUnit(
260  BeginLoc,
261  PreprocessedEntities.back()->getSourceRange().getBegin())) &&
262  "a macro definition was encountered out-of-order");
263  PreprocessedEntities.push_back(Entity);
264  return getPPEntityID(PreprocessedEntities.size()-1, /*isLoaded=*/false);
265  }
266 
267  // Check normal case, this entity begin location is after the previous one.
268  if (PreprocessedEntities.empty() ||
269  !SourceMgr.isBeforeInTranslationUnit(BeginLoc,
270  PreprocessedEntities.back()->getSourceRange().getBegin())) {
271  PreprocessedEntities.push_back(Entity);
272  return getPPEntityID(PreprocessedEntities.size()-1, /*isLoaded=*/false);
273  }
274 
275  // The entity's location is not after the previous one; this can happen with
276  // include directives that form the filename using macros, e.g:
277  // "#include MACRO(STUFF)"
278  // or with macro expansions inside macro arguments where the arguments are
279  // not expanded in the same order as listed, e.g:
280  // \code
281  // #define M1 1
282  // #define M2 2
283  // #define FM(x,y) y x
284  // FM(M1, M2)
285  // \endcode
286 
287  using pp_iter = std::vector<PreprocessedEntity *>::iterator;
288 
289  // Usually there are few macro expansions when defining the filename, do a
290  // linear search for a few entities.
291  unsigned count = 0;
292  for (pp_iter RI = PreprocessedEntities.end(),
293  Begin = PreprocessedEntities.begin();
294  RI != Begin && count < 4; --RI, ++count) {
295  pp_iter I = RI;
296  --I;
297  if (!SourceMgr.isBeforeInTranslationUnit(BeginLoc,
298  (*I)->getSourceRange().getBegin())) {
299  pp_iter insertI = PreprocessedEntities.insert(RI, Entity);
300  return getPPEntityID(insertI - PreprocessedEntities.begin(),
301  /*isLoaded=*/false);
302  }
303  }
304 
305  // Linear search unsuccessful. Do a binary search.
306  pp_iter I =
307  llvm::upper_bound(PreprocessedEntities, BeginLoc,
308  PPEntityComp<&SourceRange::getBegin>(SourceMgr));
309  pp_iter insertI = PreprocessedEntities.insert(I, Entity);
310  return getPPEntityID(insertI - PreprocessedEntities.begin(),
311  /*isLoaded=*/false);
312 }
313 
316  assert(!ExternalSource &&
317  "Preprocessing record already has an external source");
318  ExternalSource = &Source;
319 }
320 
321 unsigned PreprocessingRecord::allocateLoadedEntities(unsigned NumEntities) {
322  unsigned Result = LoadedPreprocessedEntities.size();
323  LoadedPreprocessedEntities.resize(LoadedPreprocessedEntities.size()
324  + NumEntities);
325  return Result;
326 }
327 
328 unsigned PreprocessingRecord::allocateSkippedRanges(unsigned NumRanges) {
329  unsigned Result = SkippedRanges.size();
330  SkippedRanges.resize(SkippedRanges.size() + NumRanges);
331  SkippedRangesAllLoaded = false;
332  return Result;
333 }
334 
335 void PreprocessingRecord::ensureSkippedRangesLoaded() {
336  if (SkippedRangesAllLoaded || !ExternalSource)
337  return;
338  for (unsigned Index = 0; Index != SkippedRanges.size(); ++Index) {
339  if (SkippedRanges[Index].isInvalid())
340  SkippedRanges[Index] = ExternalSource->ReadSkippedRange(Index);
341  }
342  SkippedRangesAllLoaded = true;
343 }
344 
345 void PreprocessingRecord::RegisterMacroDefinition(MacroInfo *Macro,
346  MacroDefinitionRecord *Def) {
347  MacroDefinitions[Macro] = Def;
348 }
349 
350 /// Retrieve the preprocessed entity at the given ID.
351 PreprocessedEntity *PreprocessingRecord::getPreprocessedEntity(PPEntityID PPID){
352  if (PPID.ID < 0) {
353  unsigned Index = -PPID.ID - 1;
354  assert(Index < LoadedPreprocessedEntities.size() &&
355  "Out-of bounds loaded preprocessed entity");
356  return getLoadedPreprocessedEntity(Index);
357  }
358 
359  if (PPID.ID == 0)
360  return nullptr;
361  unsigned Index = PPID.ID - 1;
362  assert(Index < PreprocessedEntities.size() &&
363  "Out-of bounds local preprocessed entity");
364  return PreprocessedEntities[Index];
365 }
366 
367 /// Retrieve the loaded preprocessed entity at the given index.
369 PreprocessingRecord::getLoadedPreprocessedEntity(unsigned Index) {
370  assert(Index < LoadedPreprocessedEntities.size() &&
371  "Out-of bounds loaded preprocessed entity");
372  assert(ExternalSource && "No external source to load from");
373  PreprocessedEntity *&Entity = LoadedPreprocessedEntities[Index];
374  if (!Entity) {
375  Entity = ExternalSource->ReadPreprocessedEntity(Index);
376  if (!Entity) // Failed to load.
377  Entity = new (*this)
379  }
380  return Entity;
381 }
382 
385  llvm::DenseMap<const MacroInfo *, MacroDefinitionRecord *>::iterator Pos =
386  MacroDefinitions.find(MI);
387  if (Pos == MacroDefinitions.end())
388  return nullptr;
389 
390  return Pos->second;
391 }
392 
393 void PreprocessingRecord::addMacroExpansion(const Token &Id,
394  const MacroInfo *MI,
395  SourceRange Range) {
396  // We don't record nested macro expansions.
397  if (Id.getLocation().isMacroID())
398  return;
399 
400  if (MI->isBuiltinMacro())
401  addPreprocessedEntity(new (*this)
402  MacroExpansion(Id.getIdentifierInfo(), Range));
403  else if (MacroDefinitionRecord *Def = findMacroDefinition(MI))
404  addPreprocessedEntity(new (*this) MacroExpansion(Def, Range));
405 }
406 
407 void PreprocessingRecord::Ifdef(SourceLocation Loc, const Token &MacroNameTok,
408  const MacroDefinition &MD) {
409  // This is not actually a macro expansion but record it as a macro reference.
410  if (MD)
411  addMacroExpansion(MacroNameTok, MD.getMacroInfo(),
412  MacroNameTok.getLocation());
413 }
414 
415 void PreprocessingRecord::Elifdef(SourceLocation Loc, const Token &MacroNameTok,
416  const MacroDefinition &MD) {
417  // This is not actually a macro expansion but record it as a macro reference.
418  if (MD)
419  addMacroExpansion(MacroNameTok, MD.getMacroInfo(),
420  MacroNameTok.getLocation());
421 }
422 
423 void PreprocessingRecord::Ifndef(SourceLocation Loc, const Token &MacroNameTok,
424  const MacroDefinition &MD) {
425  // This is not actually a macro expansion but record it as a macro reference.
426  if (MD)
427  addMacroExpansion(MacroNameTok, MD.getMacroInfo(),
428  MacroNameTok.getLocation());
429 }
430 
431 void PreprocessingRecord::Elifndef(SourceLocation Loc,
432  const Token &MacroNameTok,
433  const MacroDefinition &MD) {
434  // This is not actually a macro expansion but record it as a macro reference.
435  if (MD)
436  addMacroExpansion(MacroNameTok, MD.getMacroInfo(),
437  MacroNameTok.getLocation());
438 }
439 
440 void PreprocessingRecord::Defined(const Token &MacroNameTok,
441  const MacroDefinition &MD,
442  SourceRange Range) {
443  // This is not actually a macro expansion but record it as a macro reference.
444  if (MD)
445  addMacroExpansion(MacroNameTok, MD.getMacroInfo(),
446  MacroNameTok.getLocation());
447 }
448 
449 void PreprocessingRecord::SourceRangeSkipped(SourceRange Range,
450  SourceLocation EndifLoc) {
451  assert(Range.isValid());
452  SkippedRanges.emplace_back(Range.getBegin(), EndifLoc);
453 }
454 
455 void PreprocessingRecord::MacroExpands(const Token &Id,
456  const MacroDefinition &MD,
457  SourceRange Range,
458  const MacroArgs *Args) {
459  addMacroExpansion(Id, MD.getMacroInfo(), Range);
460 }
461 
462 void PreprocessingRecord::MacroDefined(const Token &Id,
463  const MacroDirective *MD) {
464  const MacroInfo *MI = MD->getMacroInfo();
466  MacroDefinitionRecord *Def =
467  new (*this) MacroDefinitionRecord(Id.getIdentifierInfo(), R);
469  MacroDefinitions[MI] = Def;
470 }
471 
472 void PreprocessingRecord::MacroUndefined(const Token &Id,
473  const MacroDefinition &MD,
474  const MacroDirective *Undef) {
475  MD.forAllDefinitions([&](MacroInfo *MI) { MacroDefinitions.erase(MI); });
476 }
477 
478 void PreprocessingRecord::InclusionDirective(
479  SourceLocation HashLoc,
480  const Token &IncludeTok,
481  StringRef FileName,
482  bool IsAngled,
483  CharSourceRange FilenameRange,
485  StringRef SearchPath,
486  StringRef RelativePath,
487  const Module *Imported,
488  SrcMgr::CharacteristicKind FileType) {
490 
491  switch (IncludeTok.getIdentifierInfo()->getPPKeywordID()) {
492  case tok::pp_include:
494  break;
495 
496  case tok::pp_import:
498  break;
499 
502  break;
503 
506  break;
507 
508  default:
509  llvm_unreachable("Unknown include directive kind");
510  }
511 
512  SourceLocation EndLoc;
513  if (!IsAngled) {
514  EndLoc = FilenameRange.getBegin();
515  } else {
516  EndLoc = FilenameRange.getEnd();
517  if (FilenameRange.isCharRange())
518  EndLoc = EndLoc.getLocWithOffset(-1); // the InclusionDirective expects
519  // a token range.
520  }
522  new (*this) clang::InclusionDirective(*this, Kind, FileName, !IsAngled,
523  (bool)Imported, File,
524  SourceRange(HashLoc, EndLoc));
526 }
527 
529  return BumpAlloc.getTotalMemory()
530  + llvm::capacity_in_bytes(MacroDefinitions)
531  + llvm::capacity_in_bytes(PreprocessedEntities)
532  + llvm::capacity_in_bytes(LoadedPreprocessedEntities)
533  + llvm::capacity_in_bytes(SkippedRanges);
534 }
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::CharSourceRange::isCharRange
bool isCharRange() const
Definition: SourceLocation.h:281
clang::SourceRange::isInvalid
bool isInvalid() const
Definition: SourceLocation.h:226
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::CharSourceRange::getBegin
SourceLocation getBegin() const
Definition: SourceLocation.h:283
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.
advance
static ParseState advance(ParseState S, size_t N)
Definition: Parsing.cpp:144
clang::MacroDefinition
A description of the current definition of a macro.
Definition: MacroInfo.h:587
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::SourceLocation::getLocWithOffset
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
Definition: SourceLocation.h:134
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::Token::getIdentifierInfo
IdentifierInfo * getIdentifierInfo() const
Definition: Token.h:181
clang::MacroArgs
MacroArgs - An instance of this class captures information about the formal arguments specified to a ...
Definition: MacroArgs.h:29
memcpy
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
Definition: __clang_cuda_device_functions.h:1549
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
clang::SourceRange::isValid
bool isValid() const
Definition: SourceLocation.h:225
llvm::Optional< FileEntryRef >
clang::ComparisonCategoryType::First
@ First
clang::MacroInfo
Encapsulates the data about a macro definition (e.g.
Definition: MacroInfo.h:39
SourceManager.h
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::index::SymbolKind::Macro
@ Macro
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:35
End
SourceLocation End
Definition: USRLocFinder.cpp:167
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:637
TokenKinds.h
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
isPreprocessedEntityIfInFileID
static bool isPreprocessedEntityIfInFileID(PreprocessedEntity *PPE, FileID FID, SourceManager &SM)
Definition: PreprocessingRecord.cpp:78
clang::MacroDefinition::getMacroInfo
MacroInfo * getMacroInfo() const
Get the MacroInfo that should be used for this definition.
Definition: MacroInfo.h:603
clang::SourceRange::getEnd
SourceLocation getEnd() const
Definition: SourceLocation.h:220
clang::PreprocessingRecord::Allocate
void * Allocate(unsigned Size, unsigned Align=8)
Allocate memory in the preprocessing record.
Definition: PreprocessingRecord.h:401
clang::FileID::isValid
bool isValid() const
Definition: SourceLocation.h:44
clang::SourceManager::isLoadedSourceLocation
bool isLoadedSourceLocation(SourceLocation Loc) const
Returns true if Loc came from a PCH/Module.
Definition: SourceManager.h:1749
IdentifierTable.h
clang::MacroDefinitionRecord
Record the location of a macro definition.
Definition: PreprocessingRecord.h:147
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::MacroInfo::getDefinitionEndLoc
SourceLocation getDefinitionEndLoc() const
Return the location of the last token in the macro.
Definition: MacroInfo.h:131
isInvalid
static bool isInvalid(LocType Loc, bool *Invalid)
Definition: SourceManager.cpp:1233
clang::dependency_directives_scan::pp___include_macros
@ pp___include_macros
Definition: DependencyDirectivesScanner.h:62
clang::InclusionDirective::Import
@ Import
An Objective-C #import directive.
Definition: PreprocessingRecord.h:216
clang::SourceManager::isBeforeInTranslationUnit
bool isBeforeInTranslationUnit(SourceLocation LHS, SourceLocation RHS) const
Determines the order of 2 source locations in the translation unit.
Definition: SourceManager.cpp:2026
clang::transformer::EditKind::Range
@ Range
clang::PreprocessingRecord::Result
std::pair< int, int > Result
Definition: PreprocessingRecord.h:561
SourceLocation.h
clang::InclusionDirective
Record the location of an inclusion directive, such as an #include or #import statement.
Definition: PreprocessingRecord.h:207
clang::MacroDefinition::forAllDefinitions
void forAllDefinitions(Fn F) const
Definition: MacroInfo.h:623
clang::SourceManager::isLocalSourceLocation
bool isLocalSourceLocation(SourceLocation Loc) const
Returns true if Loc did not come from a PCH/Module.
Definition: SourceManager.h:1754
PreprocessingRecord.h
Begin
SourceLocation Begin
Definition: USRLocFinder.cpp:165
clang::dependency_directives_scan::pp_import
@ pp_import
Definition: DependencyDirectivesScanner.h:65
clang::CharSourceRange
Represents a character-granular source range.
Definition: SourceLocation.h:253
LLVM.h
clang::InclusionDirective::IncludeMacros
@ IncludeMacros
A Clang #__include_macros directive.
Definition: PreprocessingRecord.h:222
clang::IdentifierInfo::getPPKeywordID
tok::PPKeywordKind getPPKeywordID() const
Return the preprocessor keyword ID for this identifier.
Definition: IdentifierTable.cpp:395
clang::dependency_directives_scan::pp_include
@ pp_include
Definition: DependencyDirectivesScanner.h:61
clang::CharSourceRange::getEnd
SourceLocation getEnd() const
Definition: SourceLocation.h:284
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::Token::getLocation
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
Definition: Token.h:126
clang::ExternalPreprocessingRecordSource::ReadSkippedRange
virtual SourceRange ReadSkippedRange(unsigned Index)=0
Read a preallocated skipped range from the external source.
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::PreprocessingRecord::findMacroDefinition
MacroDefinitionRecord * findMacroDefinition(const MacroInfo *MI)
Retrieve the macro definition that corresponds to the given MacroInfo.
Definition: PreprocessingRecord.cpp:384
clang::dependency_directives_scan::pp_include_next
@ pp_include_next
Definition: DependencyDirectivesScanner.h:71
clang::Builtin::ID
ID
Definition: Builtins.h:52
clang::SourceLocation::isInvalid
bool isInvalid() const
Definition: SourceLocation.h:111
clang::MacroInfo::isBuiltinMacro
bool isBuiltinMacro() const
Return true if this macro requires processing before expansion.
Definition: MacroInfo.h:217
clang::FloatModeKind::Half
@ Half
clang
Definition: CalledOnceCheck.h:17
distance
float __ovld __cnfn distance(float, float)
Returns the distance between p0 and p1.
MacroInfo.h
clang::MacroDirective
Encapsulates changes to the "macros namespace" (the location where the macro name became active,...
Definition: MacroInfo.h:313
clang::MacroDirective::getMacroInfo
const MacroInfo * getMacroInfo() const
Definition: MacroInfo.h:413
clang::FileID
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Definition: SourceLocation.h:38
clang::FileID::isInvalid
bool isInvalid() const
Definition: SourceLocation.h:45
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::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
SM
#define SM(sm)
Definition: Cuda.cpp:79
clang::ExternalPreprocessingRecordSource::~ExternalPreprocessingRecordSource
virtual ~ExternalPreprocessingRecordSource()
Token.h
clang::PreprocessedEntity
Base class that describes a preprocessed entity, which may be a preprocessor directive or macro expan...
Definition: PreprocessingRecord.h:59
clang::MacroInfo::getDefinitionLoc
SourceLocation getDefinitionLoc() const
Return the location that the macro was defined at.
Definition: MacroInfo.h:125