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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
94
95public:
98
99private:
101
102 enum : UIntTy { MacroIDBit = 1ULL << (8 * sizeof(UIntTy) - 1) };
103
104public:
105 bool isFileID() const { return (ID & MacroIDBit) == 0; }
106 bool isMacroID() const { return (ID & MacroIDBit) != 0; }
107
108
109
110
111
112
115
116private:
117
118 UIntTy getOffset() const { return ID & ~MacroIDBit; }
119
120 static SourceLocation getFileLoc(UIntTy ID) {
121 assert((ID & MacroIDBit) == 0 && "Ran out of source locations!");
122 SourceLocation L;
123 L.ID = ID;
124 return L;
125 }
126
127 static SourceLocation getMacroLoc(UIntTy ID) {
128 assert((ID & MacroIDBit) == 0 && "Ran out of source locations!");
129 SourceLocation L;
130 L.ID = MacroIDBit | ID;
131 return L;
132 }
133
134public:
135
136
138 assert(((getOffset()+Offset) & MacroIDBit) == 0 && "offset overflow");
140 L.ID = ID+Offset;
141 return L;
142 }
143
144
145
146
147
148
150
151
152
153
154
157 X.ID = Encoding;
158 return X;
159 }
160
161
162
163
164
165
167
168
170 }
171
172
173
176 }
177
179 return Start.isValid() && Start.isFileID() && End.isValid() &&
180 End.isFileID();
181 }
182
187};
188
191}
192
194 return !(LHS == RHS);
195}
196
197
198
201}
204}
207}
210}
211
212
216
217public:
221
224
227
230
232 return B == X.B && E == X.E;
233 }
234
236 return B != X.B || E != X.E;
237 }
238
239
241 return B <= other.B && E >= other.E;
242 }
243
247};
248
249
250
251
252
253
254
255
258 bool IsTokenRange = false;
259
260public:
263
266 }
267
270 }
271
274 }
275
278 }
279
280
281
282
285
289
293
296};
297
298
299
300
301
302
303
304
306 const char *Filename = nullptr;
308 unsigned Line, Col;
310
311public:
315 : Filename(FN), ID(FID), Line(Ln), Col(Co), IncludeLoc(IL) {}
316
317
318
319
320
323
324
325
326
330 }
331
334 return ID;
335 }
336
337
338
339
342 return Line;
343 }
344
345
346
347
350 return Col;
351 }
352
353
354
355
358 return IncludeLoc;
359 }
360};
361
362
363
364
365
366
367
368
371
372public:
373
375
378
379
380 bool hasManager() const { return SrcMgr != nullptr; }
381
382
384 assert(SrcMgr && "SourceManager is NULL.");
385 return *SrcMgr;
386 }
387
389
398
401
402
403
404
405
407
410
412
415
418
419
420
422
423
424
425
426
428
430
431
432
433
435
436
437
438
440 assert(Loc.isValid());
441 assert(SrcMgr == Loc.SrcMgr && "Loc comes from another SourceManager!");
443 }
444
445
449 }
450 };
451
452
453
454
455 void dump() const;
456
457 friend bool
460 LHS.SrcMgr == RHS.SrcMgr;
461 }
462
463 friend bool
465 return !(LHS == RHS);
466 }
467};
468
469}
470
471namespace llvm {
472
473
474
475 template <>
476 struct DenseMapInfo<clang::FileID, void> {
478 return {};
479 }
480
483 }
484
486 return S.getHashValue();
487 }
488
490 return LHS == RHS;
491 }
492 };
493
494
495
496
497 template <> struct DenseMapInfo<clang::SourceLocation, void> {
501 }
502
506 }
507
509 return Loc.getHashValue();
510 }
511
513 return LHS == RHS;
514 }
515 };
516
517
520 };
521
522}
523
524#endif
Defines interfaces for clang::FileEntry and clang::FileEntryRef.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Reads an AST files chain containing the contents of a translation unit.
Writes an AST file containing the contents of a translation unit.
Represents a character-granular source range.
void setEnd(SourceLocation e)
bool isTokenRange() const
Return true if the end of this range specifies the start of the last token.
static CharSourceRange getCharRange(SourceLocation B, SourceLocation E)
static CharSourceRange getCharRange(SourceRange R)
void setBegin(SourceLocation b)
static CharSourceRange getTokenRange(SourceRange R)
static CharSourceRange getTokenRange(SourceLocation B, SourceLocation E)
SourceLocation getEnd() const
SourceLocation getBegin() const
void setTokenRange(bool TR)
CharSourceRange()=default
CharSourceRange(SourceRange R, bool ITR)
SourceRange getAsRange() const
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...
bool operator<(const FileID &RHS) const
unsigned getHashValue() const
bool operator>(const FileID &RHS) const
bool operator==(const FileID &RHS) const
bool operator>=(const FileID &RHS) const
bool operator!=(const FileID &RHS) const
bool operator<=(const FileID &RHS) const
friend class SourceManagerTestHelper
static FileID getSentinel()
A SourceLocation and its associated SourceManager.
FullSourceLoc getFileLoc() const
unsigned getColumnNumber(bool *Invalid=nullptr) const
FullSourceLoc(SourceLocation Loc, const SourceManager &SM)
std::pair< FileID, unsigned > getDecomposedExpansionLoc() const
Decompose the underlying SourceLocation into a raw (FileID + Offset) pair, after walking through all ...
bool isBeforeInTranslationUnitThan(FullSourceLoc Loc) const
Determines the order of 2 source locations in the translation unit.
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)
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)
bool isInSystemHeader() const
const FileEntry * getFileEntry() const
unsigned getFileOffset() const
std::pair< FileID, unsigned > getDecomposedLoc() const
Decompose the specified location into a raw FileID + Offset pair.
FullSourceLoc()=default
Creates a FullSourceLoc where isValid() returns false.
PresumedLoc getPresumedLoc(bool UseLineDirectives=true) const
bool hasManager() const
Checks whether the SourceManager is present.
bool isMacroArgExpansion(FullSourceLoc *StartLoc=nullptr) const
const SourceManager & getManager() const
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.
unsigned getColumn() const
Return the presumed column number of this location.
PresumedLoc(const char *FN, FileID FID, unsigned Ln, unsigned Co, SourceLocation IL)
const char * getFilename() const
Return the presumed filename of this location.
unsigned getLine() const
Return the presumed line number of this location.
bool isInvalid() const
Return true if this object is invalid or uninitialized.
SourceLocation getIncludeLoc() const
Return the presumed include location of this location.
Serialized encoding of SourceLocations without context.
Encodes a location in the source.
void * getPtrEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) pointer encoding for it.
static SourceLocation getFromRawEncoding(UIntTy Encoding)
Turn a raw encoding of a SourceLocation object into a real SourceLocation.
std::string printToString(const SourceManager &SM) const
void dump(const SourceManager &SM) const
static bool isPairOfFileLocations(SourceLocation Start, SourceLocation End)
bool isValid() const
Return true if this is a valid SourceLocation object.
void print(raw_ostream &OS, const SourceManager &SM) const
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
UIntTy getRawEncoding() const
When a SourceLocation itself cannot be used, this returns an (opaque) 32-bit integer encoding for it.
unsigned getHashValue() const
static SourceLocation getFromPtrEncoding(const void *Encoding)
Turn a pointer encoding of a SourceLocation object back into a real SourceLocation.
This class handles loading and caching of source files into memory.
A trivial tuple used to represent a source range.
SourceRange(SourceLocation loc)
bool operator==(const SourceRange &X) const
void setBegin(SourceLocation b)
bool fullyContains(const SourceRange &other) const
SourceLocation getEnd() const
SourceLocation getBegin() const
std::string printToString(const SourceManager &SM) const
bool operator!=(const SourceRange &X) const
void dump(const SourceManager &SM) const
void setEnd(SourceLocation e)
SourceRange(SourceLocation begin, SourceLocation end)
void print(raw_ostream &OS, const SourceManager &SM) const
The JSON file list parser is used to communicate input to InstallAPI.
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.
bool operator()(const FullSourceLoc &lhs, const FullSourceLoc &rhs) const
static unsigned getHashValue(clang::FileID S)
static bool isEqual(clang::FileID LHS, clang::FileID RHS)
static clang::FileID getTombstoneKey()
static clang::FileID getEmptyKey()
static clang::SourceLocation getTombstoneKey()
static bool isEqual(clang::SourceLocation LHS, clang::SourceLocation RHS)
static clang::SourceLocation getEmptyKey()
static unsigned getHashValue(clang::SourceLocation Loc)
static void Profile(const clang::SourceLocation &X, FoldingSetNodeID &ID)