blob: ee5f96fe937a4381e9a0d30fe19dda8a55507b98 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- SourceLocation.h - Compact identifier for Source Files -*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the SourceLocation class.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_SOURCELOCATION_H
15#define LLVM_CLANG_SOURCELOCATION_H
16
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +000017#include "llvm/Support/PointerLikeTypeTraits.h"
Ted Kremenek3632a352009-01-28 20:46:26 +000018#include <utility>
Argyrios Kyrtzidis8f896522011-04-07 18:10:07 +000019#include <functional>
Chris Lattnerae50fa02009-03-05 00:00:31 +000020#include <cassert>
Chris Lattner9dc1f532007-07-20 16:37:10 +000021
Ted Kremenek9c728dc2007-12-12 22:39:36 +000022namespace llvm {
Chris Lattner2b2453a2009-01-17 06:22:33 +000023 class MemoryBuffer;
Chris Lattnerae50fa02009-03-05 00:00:31 +000024 class raw_ostream;
Benjamin Kramerceafc4b2010-03-16 14:48:07 +000025 class StringRef;
Chris Lattner2b2453a2009-01-17 06:22:33 +000026 template <typename T> struct DenseMapInfo;
Chris Lattner06159e82009-12-15 07:26:51 +000027 template <typename T> struct isPodLike;
Ted Kremenek9c728dc2007-12-12 22:39:36 +000028}
29
Reid Spencer5f016e22007-07-11 17:01:13 +000030namespace clang {
Mike Stump1eb44332009-09-09 15:08:12 +000031
Ted Kremeneka9793ed2007-12-12 18:16:46 +000032class SourceManager;
Mike Stump1eb44332009-09-09 15:08:12 +000033
Chris Lattner2b2453a2009-01-17 06:22:33 +000034/// FileID - This is an opaque identifier used by SourceManager which refers to
35/// a source file (MemoryBuffer) along with its #include path and #line data.
36///
37class FileID {
38 /// ID - Opaque identifier, 0 is "invalid".
39 unsigned ID;
40public:
41 FileID() : ID(0) {}
Mike Stump1eb44332009-09-09 15:08:12 +000042
Chris Lattner2b2453a2009-01-17 06:22:33 +000043 bool isInvalid() const { return ID == 0; }
Mike Stump1eb44332009-09-09 15:08:12 +000044
Chris Lattner2b2453a2009-01-17 06:22:33 +000045 bool operator==(const FileID &RHS) const { return ID == RHS.ID; }
46 bool operator<(const FileID &RHS) const { return ID < RHS.ID; }
47 bool operator<=(const FileID &RHS) const { return ID <= RHS.ID; }
48 bool operator!=(const FileID &RHS) const { return !(*this == RHS); }
49 bool operator>(const FileID &RHS) const { return RHS < *this; }
50 bool operator>=(const FileID &RHS) const { return RHS <= *this; }
Mike Stump1eb44332009-09-09 15:08:12 +000051
Chris Lattnerde7aeef2009-01-26 00:43:02 +000052 static FileID getSentinel() { return get(~0U); }
Chris Lattner2b2453a2009-01-17 06:22:33 +000053 unsigned getHashValue() const { return ID; }
Mike Stump1eb44332009-09-09 15:08:12 +000054
Chris Lattner2b2453a2009-01-17 06:22:33 +000055private:
56 friend class SourceManager;
Douglas Gregor31d375f2011-05-06 21:43:30 +000057 friend class ASTWriter;
58 friend class ASTReader;
59
Chris Lattnerde7aeef2009-01-26 00:43:02 +000060 static FileID get(unsigned V) {
Chris Lattner2b2453a2009-01-17 06:22:33 +000061 FileID F;
62 F.ID = V;
63 return F;
64 }
65 unsigned getOpaqueValue() const { return ID; }
66};
Mike Stump1eb44332009-09-09 15:08:12 +000067
68
Reid Spencer5f016e22007-07-11 17:01:13 +000069/// SourceLocation - This is a carefully crafted 32-bit identifier that encodes
70/// a full include stack, line and column number information for a position in
71/// an input translation unit.
72class SourceLocation {
73 unsigned ID;
Chris Lattnerbcc2a672009-01-19 06:46:35 +000074 friend class SourceManager;
Reid Spencer5f016e22007-07-11 17:01:13 +000075 enum {
Chris Lattnerde7aeef2009-01-26 00:43:02 +000076 MacroIDBit = 1U << 31
Reid Spencer5f016e22007-07-11 17:01:13 +000077 };
Chris Lattner9ebac5e2009-01-19 06:57:37 +000078public:
Reid Spencer5f016e22007-07-11 17:01:13 +000079
80 SourceLocation() : ID(0) {} // 0 is an invalid FileID.
Mike Stump1eb44332009-09-09 15:08:12 +000081
Chris Lattnerde7aeef2009-01-26 00:43:02 +000082 bool isFileID() const { return (ID & MacroIDBit) == 0; }
83 bool isMacroID() const { return (ID & MacroIDBit) != 0; }
Mike Stump1eb44332009-09-09 15:08:12 +000084
Chris Lattnerb7489d82007-11-09 23:52:16 +000085 /// isValid - Return true if this is a valid SourceLocation object. Invalid
86 /// SourceLocations are often used when events have no corresponding location
87 /// in the source (e.g. a diagnostic is required for a command line option).
88 ///
89 bool isValid() const { return ID != 0; }
90 bool isInvalid() const { return ID == 0; }
Mike Stump1eb44332009-09-09 15:08:12 +000091
Chris Lattner6fda54c2009-01-19 07:00:35 +000092private:
Chris Lattnerde7aeef2009-01-26 00:43:02 +000093 /// getOffset - Return the index for SourceManager's SLocEntryTable table,
94 /// note that this is not an index *into* it though.
95 unsigned getOffset() const {
96 return ID & ~MacroIDBit;
Chris Lattner4d10ef12009-01-19 06:55:08 +000097 }
Chris Lattner6fda54c2009-01-19 07:00:35 +000098
Chris Lattnerde7aeef2009-01-26 00:43:02 +000099 static SourceLocation getFileLoc(unsigned ID) {
100 assert((ID & MacroIDBit) == 0 && "Ran out of source locations!");
Chris Lattner9dc1f532007-07-20 16:37:10 +0000101 SourceLocation L;
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000102 L.ID = ID;
Chris Lattner9dc1f532007-07-20 16:37:10 +0000103 return L;
Reid Spencer5f016e22007-07-11 17:01:13 +0000104 }
Mike Stump1eb44332009-09-09 15:08:12 +0000105
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000106 static SourceLocation getMacroLoc(unsigned ID) {
107 assert((ID & MacroIDBit) == 0 && "Ran out of source locations!");
Chris Lattnerd1623a82007-07-21 06:41:57 +0000108 SourceLocation L;
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000109 L.ID = MacroIDBit | ID;
Chris Lattner9dc1f532007-07-20 16:37:10 +0000110 return L;
111 }
Chris Lattner4d10ef12009-01-19 06:55:08 +0000112public:
Mike Stump1eb44332009-09-09 15:08:12 +0000113
Chris Lattner9dc1f532007-07-20 16:37:10 +0000114 /// getFileLocWithOffset - Return a source location with the specified offset
115 /// from this file SourceLocation.
Chris Lattnerd1623a82007-07-21 06:41:57 +0000116 SourceLocation getFileLocWithOffset(int Offset) const {
Chris Lattnerde7aeef2009-01-26 00:43:02 +0000117 assert(((getOffset()+Offset) & MacroIDBit) == 0 && "invalid location");
118 SourceLocation L;
119 L.ID = ID+Offset;
120 return L;
Chris Lattner9dc1f532007-07-20 16:37:10 +0000121 }
Mike Stump1eb44332009-09-09 15:08:12 +0000122
Reid Spencer5f016e22007-07-11 17:01:13 +0000123 /// getRawEncoding - When a SourceLocation itself cannot be used, this returns
124 /// an (opaque) 32-bit integer encoding for it. This should only be passed
125 /// to SourceLocation::getFromRawEncoding, it should not be inspected
126 /// directly.
127 unsigned getRawEncoding() const { return ID; }
Mike Stump1eb44332009-09-09 15:08:12 +0000128
Reid Spencer5f016e22007-07-11 17:01:13 +0000129 /// getFromRawEncoding - Turn a raw encoding of a SourceLocation object into
130 /// a real SourceLocation.
131 static SourceLocation getFromRawEncoding(unsigned Encoding) {
132 SourceLocation X;
133 X.ID = Encoding;
134 return X;
135 }
Mike Stump1eb44332009-09-09 15:08:12 +0000136
Jeffrey Yasskindec09842011-01-18 02:00:16 +0000137 /// getPtrEncoding - When a SourceLocation itself cannot be used, this returns
138 /// an (opaque) pointer encoding for it. This should only be passed
139 /// to SourceLocation::getFromPtrEncoding, it should not be inspected
140 /// directly.
141 void* getPtrEncoding() const {
142 // Double cast to avoid a warning "cast to pointer from integer of different
143 // size".
144 return (void*)(uintptr_t)getRawEncoding();
145 }
146
147 /// getFromPtrEncoding - Turn a pointer encoding of a SourceLocation object
148 /// into a real SourceLocation.
149 static SourceLocation getFromPtrEncoding(void *Encoding) {
150 return getFromRawEncoding((unsigned)(uintptr_t)Encoding);
151 }
152
Chris Lattnerae50fa02009-03-05 00:00:31 +0000153 void print(llvm::raw_ostream &OS, const SourceManager &SM) const;
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000154 void dump(const SourceManager &SM) const;
Reid Spencer5f016e22007-07-11 17:01:13 +0000155};
156
157inline bool operator==(const SourceLocation &LHS, const SourceLocation &RHS) {
158 return LHS.getRawEncoding() == RHS.getRawEncoding();
159}
160
161inline bool operator!=(const SourceLocation &LHS, const SourceLocation &RHS) {
162 return !(LHS == RHS);
163}
Mike Stump1eb44332009-09-09 15:08:12 +0000164
Chris Lattner6fda54c2009-01-19 07:00:35 +0000165inline bool operator<(const SourceLocation &LHS, const SourceLocation &RHS) {
166 return LHS.getRawEncoding() < RHS.getRawEncoding();
167}
Reid Spencer5f016e22007-07-11 17:01:13 +0000168
169/// SourceRange - a trival tuple used to represent a source range.
170class SourceRange {
171 SourceLocation B;
172 SourceLocation E;
173public:
174 SourceRange(): B(SourceLocation()), E(SourceLocation()) {}
175 SourceRange(SourceLocation loc) : B(loc), E(loc) {}
176 SourceRange(SourceLocation begin, SourceLocation end) : B(begin), E(end) {}
Mike Stump1eb44332009-09-09 15:08:12 +0000177
Chris Lattner311ff022007-10-16 22:36:42 +0000178 SourceLocation getBegin() const { return B; }
179 SourceLocation getEnd() const { return E; }
Mike Stump1eb44332009-09-09 15:08:12 +0000180
Chris Lattnere80a59c2007-07-25 00:24:17 +0000181 void setBegin(SourceLocation b) { B = b; }
182 void setEnd(SourceLocation e) { E = e; }
Mike Stump1eb44332009-09-09 15:08:12 +0000183
Reid Spencer5f016e22007-07-11 17:01:13 +0000184 bool isValid() const { return B.isValid() && E.isValid(); }
Ted Kremenek782f2f52010-01-07 01:20:12 +0000185 bool isInvalid() const { return !isValid(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000186
Ted Kremeneka8982832009-03-28 17:32:39 +0000187 bool operator==(const SourceRange &X) const {
188 return B == X.B && E == X.E;
189 }
Mike Stump1eb44332009-09-09 15:08:12 +0000190
Ted Kremeneka8982832009-03-28 17:32:39 +0000191 bool operator!=(const SourceRange &X) const {
192 return B != X.B || E != X.E;
193 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000194};
Chris Lattner0a76aae2010-06-18 22:45:06 +0000195
196/// CharSourceRange - This class represents a character granular source range.
197/// The underlying SourceRange can either specify the starting/ending character
198/// of the range, or it can specify the start or the range and the start of the
199/// last token of the range (a "token range"). In the token range case, the
200/// size of the last token must be measured to determine the actual end of the
201/// range.
202class CharSourceRange {
203 SourceRange Range;
204 bool IsTokenRange;
205public:
206 CharSourceRange() : IsTokenRange(false) {}
207 CharSourceRange(SourceRange R, bool ITR) : Range(R),IsTokenRange(ITR){}
208
209 static CharSourceRange getTokenRange(SourceRange R) {
210 CharSourceRange Result;
211 Result.Range = R;
212 Result.IsTokenRange = true;
213 return Result;
214 }
215
216 static CharSourceRange getCharRange(SourceRange R) {
217 CharSourceRange Result;
218 Result.Range = R;
219 Result.IsTokenRange = false;
220 return Result;
221 }
222
223 static CharSourceRange getTokenRange(SourceLocation B, SourceLocation E) {
224 return getTokenRange(SourceRange(B, E));
225 }
226 static CharSourceRange getCharRange(SourceLocation B, SourceLocation E) {
227 return getCharRange(SourceRange(B, E));
228 }
229
230 /// isTokenRange - Return true if the end of this range specifies the start of
231 /// the last token. Return false if the end of this range specifies the last
232 /// character in the range.
233 bool isTokenRange() const { return IsTokenRange; }
234
235 SourceLocation getBegin() const { return Range.getBegin(); }
236 SourceLocation getEnd() const { return Range.getEnd(); }
237 const SourceRange &getAsRange() const { return Range; }
238
239 void setBegin(SourceLocation b) { Range.setBegin(b); }
240 void setEnd(SourceLocation e) { Range.setEnd(e); }
241
242 bool isValid() const { return Range.isValid(); }
243 bool isInvalid() const { return !isValid(); }
244};
Mike Stump1eb44332009-09-09 15:08:12 +0000245
Chris Lattnera50bd542009-01-16 23:03:56 +0000246/// FullSourceLoc - A SourceLocation and its associated SourceManager. Useful
247/// for argument passing to functions that expect both objects.
248class FullSourceLoc : public SourceLocation {
Chris Lattner5c5db4e2010-04-20 20:49:23 +0000249 const SourceManager *SrcMgr;
Ted Kremeneka9793ed2007-12-12 18:16:46 +0000250public:
Ted Kremenek3632a352009-01-28 20:46:26 +0000251 /// Creates a FullSourceLoc where isValid() returns false.
Chris Lattner5c5db4e2010-04-20 20:49:23 +0000252 explicit FullSourceLoc() : SrcMgr(0) {}
Ted Kremeneka9793ed2007-12-12 18:16:46 +0000253
Chris Lattner5c5db4e2010-04-20 20:49:23 +0000254 explicit FullSourceLoc(SourceLocation Loc, const SourceManager &SM)
Chris Lattnera50bd542009-01-16 23:03:56 +0000255 : SourceLocation(Loc), SrcMgr(&SM) {}
Mike Stump1eb44332009-09-09 15:08:12 +0000256
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000257 const SourceManager &getManager() const {
258 assert(SrcMgr && "SourceManager is NULL.");
Ted Kremeneka9793ed2007-12-12 18:16:46 +0000259 return *SrcMgr;
260 }
Mike Stump1eb44332009-09-09 15:08:12 +0000261
Chris Lattner3b4d5e92009-01-17 08:45:21 +0000262 FileID getFileID() const;
Mike Stump1eb44332009-09-09 15:08:12 +0000263
Chris Lattnerf7cf85b2009-01-16 07:36:28 +0000264 FullSourceLoc getInstantiationLoc() const;
Chris Lattnerdf7c17a2009-01-16 07:00:02 +0000265 FullSourceLoc getSpellingLoc() const;
Ted Kremenek9c728dc2007-12-12 22:39:36 +0000266
Douglas Gregor64e462d2010-03-16 20:53:17 +0000267 unsigned getInstantiationLineNumber(bool *Invalid = 0) const;
268 unsigned getInstantiationColumnNumber(bool *Invalid = 0) const;
Ted Kremenek9c728dc2007-12-12 22:39:36 +0000269
Douglas Gregor64e462d2010-03-16 20:53:17 +0000270 unsigned getSpellingLineNumber(bool *Invalid = 0) const;
271 unsigned getSpellingColumnNumber(bool *Invalid = 0) const;
Chris Lattner5c38b632008-09-29 21:46:13 +0000272
Douglas Gregora5430162010-03-16 20:46:42 +0000273 const char *getCharacterData(bool *Invalid = 0) const;
Mike Stump1eb44332009-09-09 15:08:12 +0000274
Douglas Gregoraae58b02010-03-16 20:01:30 +0000275 const llvm::MemoryBuffer* getBuffer(bool *Invalid = 0) const;
Mike Stump1eb44332009-09-09 15:08:12 +0000276
Benjamin Kramerceafc4b2010-03-16 14:48:07 +0000277 /// getBufferData - Return a StringRef to the source buffer data for the
278 /// specified FileID.
Douglas Gregoraae58b02010-03-16 20:01:30 +0000279 llvm::StringRef getBufferData(bool *Invalid = 0) const;
Mike Stump1eb44332009-09-09 15:08:12 +0000280
Ted Kremenek321abd42009-03-10 05:13:43 +0000281 /// getDecomposedLoc - Decompose the specified location into a raw FileID +
282 /// Offset pair. The first element is the FileID, the second is the
283 /// offset from the start of the buffer of the location.
284 std::pair<FileID, unsigned> getDecomposedLoc() const;
285
Nico Weber7bfaaae2008-08-10 19:59:06 +0000286 bool isInSystemHeader() const;
Mike Stump1eb44332009-09-09 15:08:12 +0000287
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000288 /// \brief Determines the order of 2 source locations in the translation unit.
289 ///
290 /// \returns true if this source location comes before 'Loc', false otherwise.
291 bool isBeforeInTranslationUnitThan(SourceLocation Loc) const;
292
293 /// \brief Determines the order of 2 source locations in the translation unit.
294 ///
295 /// \returns true if this source location comes before 'Loc', false otherwise.
296 bool isBeforeInTranslationUnitThan(FullSourceLoc Loc) const {
297 assert(Loc.isValid());
298 assert(SrcMgr == Loc.SrcMgr && "Loc comes from another SourceManager!");
299 return isBeforeInTranslationUnitThan((SourceLocation)Loc);
300 }
301
Argyrios Kyrtzidis8f896522011-04-07 18:10:07 +0000302 /// \brief Comparison function class, useful for sorting FullSourceLocs.
303 struct BeforeThanCompare : public std::binary_function<FullSourceLoc,
304 FullSourceLoc, bool> {
305 bool operator()(const FullSourceLoc& lhs, const FullSourceLoc& rhs) const {
306 return lhs.isBeforeInTranslationUnitThan(rhs);
307 }
308 };
309
Chris Lattner5c38b632008-09-29 21:46:13 +0000310 /// Prints information about this FullSourceLoc to stderr. Useful for
311 /// debugging.
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000312 void dump() const { SourceLocation::dump(*SrcMgr); }
Douglas Gregor0b7a1582009-01-17 00:42:38 +0000313
Mike Stump1eb44332009-09-09 15:08:12 +0000314 friend inline bool
Douglas Gregor0b7a1582009-01-17 00:42:38 +0000315 operator==(const FullSourceLoc &LHS, const FullSourceLoc &RHS) {
316 return LHS.getRawEncoding() == RHS.getRawEncoding() &&
317 LHS.SrcMgr == RHS.SrcMgr;
318 }
319
Mike Stump1eb44332009-09-09 15:08:12 +0000320 friend inline bool
Douglas Gregor0b7a1582009-01-17 00:42:38 +0000321 operator!=(const FullSourceLoc &LHS, const FullSourceLoc &RHS) {
322 return !(LHS == RHS);
323 }
324
Ted Kremeneka9793ed2007-12-12 18:16:46 +0000325};
Mike Stump1eb44332009-09-09 15:08:12 +0000326
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000327/// PresumedLoc - This class represents an unpacked "presumed" location which
328/// can be presented to the user. A 'presumed' location can be modified by
329/// #line and GNU line marker directives and is always the instantiation point
330/// of a normal location.
331///
332/// You can get a PresumedLoc from a SourceLocation with SourceManager.
333class PresumedLoc {
334 const char *Filename;
335 unsigned Line, Col;
336 SourceLocation IncludeLoc;
337public:
338 PresumedLoc() : Filename(0) {}
339 PresumedLoc(const char *FN, unsigned Ln, unsigned Co, SourceLocation IL)
340 : Filename(FN), Line(Ln), Col(Co), IncludeLoc(IL) {
341 }
Mike Stump1eb44332009-09-09 15:08:12 +0000342
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000343 /// isInvalid - Return true if this object is invalid or uninitialized. This
344 /// occurs when created with invalid source locations or when walking off
345 /// the top of a #include stack.
346 bool isInvalid() const { return Filename == 0; }
347 bool isValid() const { return Filename != 0; }
Mike Stump1eb44332009-09-09 15:08:12 +0000348
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000349 /// getFilename - Return the presumed filename of this location. This can be
350 /// affected by #line etc.
351 const char *getFilename() const { return Filename; }
352
353 /// getLine - Return the presumed line number of this location. This can be
354 /// affected by #line etc.
355 unsigned getLine() const { return Line; }
Mike Stump1eb44332009-09-09 15:08:12 +0000356
Chris Lattnerb9c3f962009-01-27 07:57:44 +0000357 /// getColumn - Return the presumed column number of this location. This can
358 /// not be affected by #line, but is packaged here for convenience.
359 unsigned getColumn() const { return Col; }
360
361 /// getIncludeLoc - Return the presumed include location of this location.
362 /// This can be affected by GNU linemarker directives.
363 SourceLocation getIncludeLoc() const { return IncludeLoc; }
364};
365
Mike Stump1eb44332009-09-09 15:08:12 +0000366
Reid Spencer5f016e22007-07-11 17:01:13 +0000367} // end namespace clang
368
Chris Lattner2b2453a2009-01-17 06:22:33 +0000369namespace llvm {
370 /// Define DenseMapInfo so that FileID's can be used as keys in DenseMap and
371 /// DenseSets.
372 template <>
373 struct DenseMapInfo<clang::FileID> {
374 static inline clang::FileID getEmptyKey() {
375 return clang::FileID();
376 }
377 static inline clang::FileID getTombstoneKey() {
Mike Stump1eb44332009-09-09 15:08:12 +0000378 return clang::FileID::getSentinel();
Chris Lattner2b2453a2009-01-17 06:22:33 +0000379 }
Mike Stump1eb44332009-09-09 15:08:12 +0000380
Chris Lattner2b2453a2009-01-17 06:22:33 +0000381 static unsigned getHashValue(clang::FileID S) {
382 return S.getHashValue();
383 }
Mike Stump1eb44332009-09-09 15:08:12 +0000384
Chris Lattner2b2453a2009-01-17 06:22:33 +0000385 static bool isEqual(clang::FileID LHS, clang::FileID RHS) {
386 return LHS == RHS;
387 }
Chris Lattner2b2453a2009-01-17 06:22:33 +0000388 };
Chris Lattner06159e82009-12-15 07:26:51 +0000389
390 template <>
391 struct isPodLike<clang::SourceLocation> { static const bool value = true; };
392 template <>
393 struct isPodLike<clang::FileID> { static const bool value = true; };
Mike Stump1eb44332009-09-09 15:08:12 +0000394
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000395 // Teach SmallPtrSet how to handle SourceLocation.
396 template<>
397 class PointerLikeTypeTraits<clang::SourceLocation> {
398 public:
399 static inline void *getAsVoidPointer(clang::SourceLocation L) {
Jeffrey Yasskindec09842011-01-18 02:00:16 +0000400 return L.getPtrEncoding();
Argyrios Kyrtzidis08274082010-12-15 18:44:22 +0000401 }
402 static inline clang::SourceLocation getFromVoidPointer(void *P) {
403 return clang::SourceLocation::getFromRawEncoding((unsigned)(uintptr_t)P);
404 }
405 enum { NumLowBitsAvailable = 0 };
406 };
407
Chris Lattner2b2453a2009-01-17 06:22:33 +0000408} // end namespace llvm
409
Reid Spencer5f016e22007-07-11 17:01:13 +0000410#endif