clang: include/clang/Basic/SourceLocation.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef LLVM_CLANG_BASIC_SOURCELOCATION_H
15#define LLVM_CLANG_BASIC_SOURCELOCATION_H
16
19#include "llvm/ADT/StringRef.h"
20#include
21#include
22#include
23#include
24
25namespace llvm {
26
27class FoldingSetNodeID;
29
30}
31
33
34class SourceManager;
35
36
37
38
40
41
42 int ID = 0;
43
44public:
45 bool isValid() const { return ID != 0; }
46 bool isInvalid() const { return ID == 0; }
47
54
56 unsigned getHashValue() const { return static_cast<unsigned>(ID); }
57
58private:
63
66 F.ID = V;
67 return F;
68 }
69
70 int getOpaqueValue() const { return ID; }
71};
72
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
96
97public:
100
101private:
103
104 enum : UIntTy { MacroIDBit = 1ULL << (8 * sizeof(UIntTy) - 1) };
105
106public:
107 bool isFileID() const { return (ID & MacroIDBit) == 0; }
108 bool isMacroID() const { return (ID & MacroIDBit) != 0; }
109
110
111
112
113
114
115 bool isValid() const { return ID != 0; }
117
118private:
119
120 UIntTy getOffset() const { return ID & ~MacroIDBit; }
121
122 static SourceLocation getFileLoc(UIntTy ID) {
123 assert((ID & MacroIDBit) == 0 && "Ran out of source locations!");
124 SourceLocation L;
125 L.ID = ID;
126 return L;
127 }
128
129 static SourceLocation getMacroLoc(UIntTy ID) {
130 assert((ID & MacroIDBit) == 0 && "Ran out of source locations!");
131 SourceLocation L;
132 L.ID = MacroIDBit | ID;
133 return L;
134 }
135
136public:
137
138
140 assert(((getOffset()+Offset) & MacroIDBit) == 0 && "offset overflow");
142 L.ID = ID+Offset;
143 return L;
144 }
145
146
147
148
149
150
152
153
154
155
156
159 X.ID = Encoding;
160 return X;
161 }
162
163
164
165
166
167
173
174
175
179
184
189};
190
194
196 return !(LHS == RHS);
197}
198
199
200
213
214
218
219public:
223
226
229
230 bool isValid() const { return B.isValid() && E.isValid(); }
232
234 return B == X.B && E == X.E;
235 }
236
238 return B != X.B || E != X.E;
239 }
240
241
243 return B <= other.B && E >= other.E;
244 }
245
249};
250
251
252
253
254
255
256
257
260 bool IsTokenRange = false;
261
262public:
265
269
273
277
281
282
283
284
287
291
295
296 bool isValid() const { return Range.isValid(); }
298};
299
300
301
302
303
304
305
306
308 const char *Filename = nullptr;
310 unsigned Line, Col;
312
313public:
317 : Filename(FN), ID(FID), Line(Ln), Col(Co), IncludeLoc(IL) {}
318
319
320
321
322
323 bool isInvalid() const { return Filename == nullptr; }
324 bool isValid() const { return Filename != nullptr; }
325
326
327
328
331 return Filename;
332 }
333
338
339
340
341
346
347
348
349
354
355
356
357
360 return IncludeLoc;
361 }
362};
363
364
365
366
367
368
369
370
373
374public:
375
377
380
381
382 bool hasManager() const { return SrcMgr != nullptr; }
383
384
386 assert(SrcMgr && "SourceManager is NULL.");
387 return *SrcMgr;
388 }
389
391
400
403
404
405
406
407
409
412
414
417
420
421
422
424
425
426
427
428
430
432
433
434
435
437
438
439
440
443 assert(SrcMgr == Loc.SrcMgr && "Loc comes from another SourceManager!");
445 }
446
447
453
454
455
456
457 void dump() const;
458
459 friend bool
462 LHS.SrcMgr == RHS.SrcMgr;
463 }
464
465 friend bool
467 return !(LHS == RHS);
468 }
469};
470
471}
472
473namespace llvm {
474
475
476
477 template <>
478 struct DenseMapInfo<clang::FileID, void> {
482
486
490
492 return LHS == RHS;
493 }
494 };
495
496
497
498
499 template <> struct DenseMapInfo<clang::SourceLocation, void> {
504
509
513
515 return LHS == RHS;
516 }
517 };
518
519
523
524}
525
526#endif
Defines interfaces for clang::FileEntry and clang::FileEntryRef.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
void setEnd(SourceLocation e)
Definition SourceLocation.h:293
bool isTokenRange() const
Return true if the end of this range specifies the start of the last token.
Definition SourceLocation.h:285
bool isInvalid() const
Definition SourceLocation.h:297
static CharSourceRange getCharRange(SourceLocation B, SourceLocation E)
Definition SourceLocation.h:278
static CharSourceRange getCharRange(SourceRange R)
Definition SourceLocation.h:270
void setBegin(SourceLocation b)
Definition SourceLocation.h:292
static CharSourceRange getTokenRange(SourceRange R)
Definition SourceLocation.h:266
static CharSourceRange getTokenRange(SourceLocation B, SourceLocation E)
Definition SourceLocation.h:274
SourceLocation getEnd() const
Definition SourceLocation.h:289
SourceLocation getBegin() const
Definition SourceLocation.h:288
void setTokenRange(bool TR)
Definition SourceLocation.h:294
bool isCharRange() const
Definition SourceLocation.h:286
CharSourceRange()=default
CharSourceRange(SourceRange R, bool ITR)
Definition SourceLocation.h:264
bool isValid() const
Definition SourceLocation.h:296
SourceRange getAsRange() const
Definition SourceLocation.h:290
Cached information about one file (either on disk or in the virtual file system).
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Definition SourceLocation.h:39
friend class ASTWriter
Definition SourceLocation.h:59
bool operator<(const FileID &RHS) const
Definition SourceLocation.h:49
unsigned getHashValue() const
Definition SourceLocation.h:56
bool operator>(const FileID &RHS) const
Definition SourceLocation.h:52
bool isValid() const
Definition SourceLocation.h:45
friend class ASTReader
Definition SourceLocation.h:60
bool operator==(const FileID &RHS) const
Definition SourceLocation.h:48
bool isInvalid() const
Definition SourceLocation.h:46
bool operator>=(const FileID &RHS) const
Definition SourceLocation.h:53
friend class SourceManager
Definition SourceLocation.h:61
bool operator!=(const FileID &RHS) const
Definition SourceLocation.h:51
bool operator<=(const FileID &RHS) const
Definition SourceLocation.h:50
friend class SourceManagerTestHelper
Definition SourceLocation.h:62
static FileID getSentinel()
Definition SourceLocation.h:55
A SourceLocation and its associated SourceManager.
Definition SourceLocation.h:371
FullSourceLoc getFileLoc() const
unsigned getColumnNumber(bool *Invalid=nullptr) const
FileIDAndOffset getDecomposedExpansionLoc() const
Decompose the underlying SourceLocation into a raw (FileID + Offset) pair, after walking through all ...
FullSourceLoc(SourceLocation Loc, const SourceManager &SM)
Definition SourceLocation.h:378
bool isBeforeInTranslationUnitThan(FullSourceLoc Loc) const
Determines the order of 2 source locations in the translation unit.
Definition SourceLocation.h:441
FullSourceLoc getExpansionLoc() const
unsigned getLineNumber(bool *Invalid=nullptr) const
FullSourceLoc getSpellingLoc() const
std::pair< FullSourceLoc, StringRef > getModuleImportLoc() const
OptionalFileEntryRef getFileEntryRef() const
unsigned getSpellingLineNumber(bool *Invalid=nullptr) const
FullSourceLoc getImmediateMacroCallerLoc() const
friend bool operator!=(const FullSourceLoc &LHS, const FullSourceLoc &RHS)
Definition SourceLocation.h:466
const char * getCharacterData(bool *Invalid=nullptr) const
unsigned getExpansionColumnNumber(bool *Invalid=nullptr) const
StringRef getBufferData(bool *Invalid=nullptr) const
Return a StringRef to the source buffer data for the specified FileID.
void dump() const
Prints information about this FullSourceLoc to stderr.
friend bool operator==(const FullSourceLoc &LHS, const FullSourceLoc &RHS)
Definition SourceLocation.h:460
bool isInSystemHeader() const
const FileEntry * getFileEntry() const
unsigned getFileOffset() const
FullSourceLoc()=default
Creates a FullSourceLoc where isValid() returns false.
PresumedLoc getPresumedLoc(bool UseLineDirectives=true) const
bool hasManager() const
Checks whether the SourceManager is present.
Definition SourceLocation.h:382
FileIDAndOffset getDecomposedLoc() const
Decompose the specified location into a raw FileID + Offset pair.
bool isMacroArgExpansion(FullSourceLoc *StartLoc=nullptr) const
const SourceManager & getManager() const
Definition SourceLocation.h:385
unsigned getExpansionLineNumber(bool *Invalid=nullptr) const
bool isBeforeInTranslationUnitThan(SourceLocation Loc) const
Determines the order of 2 source locations in the translation unit.
unsigned getSpellingColumnNumber(bool *Invalid=nullptr) const
Represents an unpacked "presumed" location which can be presented to the user.
Definition SourceLocation.h:307
unsigned getColumn() const
Return the presumed column number of this location.
Definition SourceLocation.h:350
PresumedLoc(const char *FN, FileID FID, unsigned Ln, unsigned Co, SourceLocation IL)
Definition SourceLocation.h:315
const char * getFilename() const
Return the presumed filename of this location.
Definition SourceLocation.h:329
bool isValid() const
Definition SourceLocation.h:324
unsigned getLine() const
Return the presumed line number of this location.
Definition SourceLocation.h:342
bool isInvalid() const
Return true if this object is invalid or uninitialized.
Definition SourceLocation.h:323
FileID getFileID() const
Definition SourceLocation.h:334
SourceLocation getIncludeLoc() const
Return the presumed include location of this location.
Definition SourceLocation.h:358
Encodes a location in the source.
Definition SourceLocation.h:90
void * getPtrEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) pointer encoding for it.
Definition SourceLocation.h:168
static SourceLocation getFromRawEncoding(UIntTy Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
Definition SourceLocation.h:157
friend class ASTWriter
Definition SourceLocation.h:92
int32_t IntTy
Definition SourceLocation.h:99
bool isFileID() const
Definition SourceLocation.h:107
friend class SourceLocationEncoding
Definition SourceLocation.h:95
std::string printToString(const SourceManager &SM) const
void dump(const SourceManager &SM) const
friend class ASTReader
Definition SourceLocation.h:91
bool isMacroID() const
Definition SourceLocation.h:108
static bool isPairOfFileLocations(SourceLocation Start, SourceLocation End)
Definition SourceLocation.h:180
bool isValid() const
Return true if this is a valid SourceLocation object.
Definition SourceLocation.h:115
void print(raw_ostream &OS, const SourceManager &SM) const
friend class SourceManager
Definition SourceLocation.h:93
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
Definition SourceLocation.h:139
UIntTy getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it.
Definition SourceLocation.h:151
unsigned getHashValue() const
uint32_t UIntTy
Definition SourceLocation.h:98
bool isInvalid() const
Definition SourceLocation.h:116
static SourceLocation getFromPtrEncoding(const void *Encoding)
Turn a pointer encoding of a SourceLocation object back into a real SourceLocation.
Definition SourceLocation.h:176
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
Definition SourceLocation.h:215
SourceRange(SourceLocation loc)
Definition SourceLocation.h:221
bool operator==(const SourceRange &X) const
Definition SourceLocation.h:233
void setBegin(SourceLocation b)
Definition SourceLocation.h:227
bool isInvalid() const
Definition SourceLocation.h:231
bool fullyContains(const SourceRange &other) const
Definition SourceLocation.h:242
SourceLocation getEnd() const
Definition SourceLocation.h:225
SourceLocation getBegin() const
Definition SourceLocation.h:224
bool isValid() const
Definition SourceLocation.h:230
std::string printToString(const SourceManager &SM) const
bool operator!=(const SourceRange &X) const
Definition SourceLocation.h:237
void dump(const SourceManager &SM) const
void setEnd(SourceLocation e)
Definition SourceLocation.h:228
SourceRange(SourceLocation begin, SourceLocation end)
Definition SourceLocation.h:222
void print(raw_ostream &OS, const SourceManager &SM) const
The JSON file list parser is used to communicate input to InstallAPI.
CustomizableOptional< FileEntryRef > OptionalFileEntryRef
std::pair< FileID, unsigned > FileIDAndOffset
Definition SourceLocation.h:73
bool operator==(const CallGraphNode::CallRecord &LHS, const CallGraphNode::CallRecord &RHS)
bool operator<(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
bool operator!=(CanQual< T > x, CanQual< U > y)
bool operator<=(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
bool operator>(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
bool operator>=(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
Diagnostic wrappers for TextAPI types for error reporting.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
Comparison function class, useful for sorting FullSourceLocs.
Definition SourceLocation.h:448
bool operator()(const FullSourceLoc &lhs, const FullSourceLoc &rhs) const
Definition SourceLocation.h:449
static unsigned getHashValue(clang::FileID S)
Definition SourceLocation.h:487
static bool isEqual(clang::FileID LHS, clang::FileID RHS)
Definition SourceLocation.h:491
static clang::FileID getTombstoneKey()
Definition SourceLocation.h:483
static clang::FileID getEmptyKey()
Definition SourceLocation.h:479
static clang::SourceLocation getTombstoneKey()
Definition SourceLocation.h:505
static bool isEqual(clang::SourceLocation LHS, clang::SourceLocation RHS)
Definition SourceLocation.h:514
static clang::SourceLocation getEmptyKey()
Definition SourceLocation.h:500
static unsigned getHashValue(clang::SourceLocation Loc)
Definition SourceLocation.h:510
static void Profile(const clang::SourceLocation &X, FoldingSetNodeID &ID)
Definition SourceLocation.h:28