Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- SourceLocation.h - Compact identifier for Source Files -*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 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 | |
Chris Lattner | 9dc1f53 | 2007-07-20 16:37:10 +0000 | [diff] [blame] | 17 | #include <cassert> |
Ted Kremenek | 0a449ee | 2007-10-25 18:27:10 +0000 | [diff] [blame] | 18 | #include "llvm/Bitcode/SerializationFwd.h" |
Chris Lattner | 9dc1f53 | 2007-07-20 16:37:10 +0000 | [diff] [blame] | 19 | |
Ted Kremenek | 9c728dc | 2007-12-12 22:39:36 +0000 | [diff] [blame] | 20 | namespace llvm { |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 21 | class MemoryBuffer; |
| 22 | template <typename T> struct DenseMapInfo; |
Ted Kremenek | 9c728dc | 2007-12-12 22:39:36 +0000 | [diff] [blame] | 23 | } |
| 24 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 25 | namespace clang { |
Ted Kremenek | a9793ed | 2007-12-12 18:16:46 +0000 | [diff] [blame] | 26 | |
| 27 | class SourceManager; |
Ted Kremenek | 9c728dc | 2007-12-12 22:39:36 +0000 | [diff] [blame] | 28 | class FileEntry; |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 29 | |
| 30 | /// FileID - This is an opaque identifier used by SourceManager which refers to |
| 31 | /// a source file (MemoryBuffer) along with its #include path and #line data. |
| 32 | /// |
| 33 | class FileID { |
| 34 | /// ID - Opaque identifier, 0 is "invalid". |
| 35 | unsigned ID; |
| 36 | public: |
| 37 | FileID() : ID(0) {} |
| 38 | |
| 39 | bool isInvalid() const { return ID == 0; } |
| 40 | |
| 41 | bool operator==(const FileID &RHS) const { return ID == RHS.ID; } |
| 42 | bool operator<(const FileID &RHS) const { return ID < RHS.ID; } |
| 43 | bool operator<=(const FileID &RHS) const { return ID <= RHS.ID; } |
| 44 | bool operator!=(const FileID &RHS) const { return !(*this == RHS); } |
| 45 | bool operator>(const FileID &RHS) const { return RHS < *this; } |
| 46 | bool operator>=(const FileID &RHS) const { return RHS <= *this; } |
| 47 | |
| 48 | static FileID getSentinel() { return Create(~0U); } |
| 49 | unsigned getHashValue() const { return ID; } |
| 50 | |
| 51 | private: |
| 52 | friend class SourceManager; |
| 53 | static FileID Create(unsigned V) { |
| 54 | FileID F; |
| 55 | F.ID = V; |
| 56 | return F; |
| 57 | } |
| 58 | unsigned getOpaqueValue() const { return ID; } |
| 59 | }; |
| 60 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 61 | |
| 62 | /// SourceLocation - This is a carefully crafted 32-bit identifier that encodes |
| 63 | /// a full include stack, line and column number information for a position in |
| 64 | /// an input translation unit. |
| 65 | class SourceLocation { |
| 66 | unsigned ID; |
Chris Lattner | bcc2a67 | 2009-01-19 06:46:35 +0000 | [diff] [blame] | 67 | friend class SourceManager; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 68 | public: |
| 69 | enum { |
Chris Lattner | b7489d8 | 2007-11-09 23:52:16 +0000 | [diff] [blame] | 70 | // FileID Layout: |
| 71 | // bit 31: 0 -> FileID, 1 -> MacroID (invalid for FileID) |
Chris Lattner | 3b4d5e9 | 2009-01-17 08:45:21 +0000 | [diff] [blame] | 72 | // 30...17 -> ChunkID of location, index into SourceManager table. |
| 73 | ChunkIDBits = 14, |
| 74 | // 0...16 -> Index into the chunk of the specified ChunkID. |
| 75 | FilePosBits = 32-1-ChunkIDBits, |
Chris Lattner | 9dc1f53 | 2007-07-20 16:37:10 +0000 | [diff] [blame] | 76 | |
Chris Lattner | b7489d8 | 2007-11-09 23:52:16 +0000 | [diff] [blame] | 77 | // MacroID Layout: |
| 78 | // bit 31: 1 -> MacroID, 0 -> FileID (invalid for MacroID) |
| 79 | |
Chris Lattner | f848454 | 2008-02-03 08:24:13 +0000 | [diff] [blame] | 80 | // bit 29,30: unused. |
| 81 | |
Chris Lattner | b7489d8 | 2007-11-09 23:52:16 +0000 | [diff] [blame] | 82 | // bits 28...9 -> MacroID number. |
Chris Lattner | d1623a8 | 2007-07-21 06:41:57 +0000 | [diff] [blame] | 83 | MacroIDBits = 20, |
Chris Lattner | df7c17a | 2009-01-16 07:00:02 +0000 | [diff] [blame] | 84 | // bits 8...0 -> Macro spelling offset |
| 85 | MacroSpellingOffsBits = 9, |
Chris Lattner | 2c64b7b | 2007-10-16 21:07:07 +0000 | [diff] [blame] | 86 | |
Chris Lattner | b7489d8 | 2007-11-09 23:52:16 +0000 | [diff] [blame] | 87 | |
| 88 | // Useful constants. |
Chris Lattner | 2c64b7b | 2007-10-16 21:07:07 +0000 | [diff] [blame] | 89 | ChunkSize = (1 << FilePosBits) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | SourceLocation() : ID(0) {} // 0 is an invalid FileID. |
| 93 | |
Chris Lattner | 9dc1f53 | 2007-07-20 16:37:10 +0000 | [diff] [blame] | 94 | bool isFileID() const { return (ID >> 31) == 0; } |
| 95 | bool isMacroID() const { return (ID >> 31) != 0; } |
| 96 | |
Chris Lattner | b7489d8 | 2007-11-09 23:52:16 +0000 | [diff] [blame] | 97 | /// isValid - Return true if this is a valid SourceLocation object. Invalid |
| 98 | /// SourceLocations are often used when events have no corresponding location |
| 99 | /// in the source (e.g. a diagnostic is required for a command line option). |
| 100 | /// |
| 101 | bool isValid() const { return ID != 0; } |
| 102 | bool isInvalid() const { return ID == 0; } |
| 103 | |
Chris Lattner | 4d10ef1 | 2009-01-19 06:55:08 +0000 | [diff] [blame^] | 104 | /// getChunkID - Return the chunk identifier for this SourceLocation. This |
| 105 | /// ChunkID can be used with the SourceManager object to obtain an entire |
| 106 | /// include stack for a file position reference. |
| 107 | unsigned getChunkID() const { |
| 108 | assert(isFileID() && "can't get the file id of a non-file sloc!"); |
| 109 | return ID >> FilePosBits; |
| 110 | } |
| 111 | |
| 112 | unsigned getMacroID() const { |
| 113 | assert(isMacroID() && "Is not a macro id!"); |
| 114 | return (ID >> MacroSpellingOffsBits) & ((1 << MacroIDBits)-1); |
| 115 | } |
| 116 | |
Chris Lattner | bcc2a67 | 2009-01-19 06:46:35 +0000 | [diff] [blame] | 117 | private: |
Chris Lattner | 3b4d5e9 | 2009-01-17 08:45:21 +0000 | [diff] [blame] | 118 | static SourceLocation getFileLoc(unsigned ChunkID, unsigned FilePos) { |
Chris Lattner | 9dc1f53 | 2007-07-20 16:37:10 +0000 | [diff] [blame] | 119 | SourceLocation L; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 120 | // If a FilePos is larger than (1<<FilePosBits), the SourceManager makes |
Chris Lattner | 3b4d5e9 | 2009-01-17 08:45:21 +0000 | [diff] [blame] | 121 | // enough consequtive ChunkIDs that we have one for each chunk. |
Chris Lattner | 2c64b7b | 2007-10-16 21:07:07 +0000 | [diff] [blame] | 122 | if (FilePos >= ChunkSize) { |
Chris Lattner | 3b4d5e9 | 2009-01-17 08:45:21 +0000 | [diff] [blame] | 123 | ChunkID += FilePos >> FilePosBits; |
Chris Lattner | 2c64b7b | 2007-10-16 21:07:07 +0000 | [diff] [blame] | 124 | FilePos &= ChunkSize-1; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 125 | } |
| 126 | |
Chris Lattner | 3b4d5e9 | 2009-01-17 08:45:21 +0000 | [diff] [blame] | 127 | // FIXME: Find a way to handle out of ChunkID bits! Maybe MaxFileID is an |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 128 | // escape of some sort? |
Chris Lattner | 3b4d5e9 | 2009-01-17 08:45:21 +0000 | [diff] [blame] | 129 | assert(ChunkID < (1 << ChunkIDBits) && "Out of ChunkID's"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 130 | |
Chris Lattner | 3b4d5e9 | 2009-01-17 08:45:21 +0000 | [diff] [blame] | 131 | L.ID = (ChunkID << FilePosBits) | FilePos; |
Chris Lattner | 9dc1f53 | 2007-07-20 16:37:10 +0000 | [diff] [blame] | 132 | return L; |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Chris Lattner | df7c17a | 2009-01-16 07:00:02 +0000 | [diff] [blame] | 135 | static bool isValidMacroSpellingOffs(int Val) { |
Chris Lattner | d1623a8 | 2007-07-21 06:41:57 +0000 | [diff] [blame] | 136 | if (Val >= 0) |
Chris Lattner | df7c17a | 2009-01-16 07:00:02 +0000 | [diff] [blame] | 137 | return Val < (1 << (MacroSpellingOffsBits-1)); |
| 138 | return -Val <= (1 << (MacroSpellingOffsBits-1)); |
Chris Lattner | d1623a8 | 2007-07-21 06:41:57 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Chris Lattner | df7c17a | 2009-01-16 07:00:02 +0000 | [diff] [blame] | 141 | static SourceLocation getMacroLoc(unsigned MacroID, int SpellingOffs) { |
Chris Lattner | 9dc1f53 | 2007-07-20 16:37:10 +0000 | [diff] [blame] | 142 | assert(MacroID < (1 << MacroIDBits) && "Too many macros!"); |
Chris Lattner | df7c17a | 2009-01-16 07:00:02 +0000 | [diff] [blame] | 143 | assert(isValidMacroSpellingOffs(SpellingOffs) &&"spelling offs too large!"); |
Chris Lattner | 9dc1f53 | 2007-07-20 16:37:10 +0000 | [diff] [blame] | 144 | |
Chris Lattner | b7489d8 | 2007-11-09 23:52:16 +0000 | [diff] [blame] | 145 | // Mask off sign bits. |
Chris Lattner | df7c17a | 2009-01-16 07:00:02 +0000 | [diff] [blame] | 146 | SpellingOffs &= (1 << MacroSpellingOffsBits)-1; |
Chris Lattner | d1623a8 | 2007-07-21 06:41:57 +0000 | [diff] [blame] | 147 | |
| 148 | SourceLocation L; |
Chris Lattner | b7489d8 | 2007-11-09 23:52:16 +0000 | [diff] [blame] | 149 | L.ID = (1 << 31) | |
Chris Lattner | df7c17a | 2009-01-16 07:00:02 +0000 | [diff] [blame] | 150 | (MacroID << MacroSpellingOffsBits) | |
| 151 | SpellingOffs; |
Chris Lattner | 9dc1f53 | 2007-07-20 16:37:10 +0000 | [diff] [blame] | 152 | return L; |
| 153 | } |
Chris Lattner | 4d10ef1 | 2009-01-19 06:55:08 +0000 | [diff] [blame^] | 154 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 155 | /// getRawFilePos - Return the byte offset from the start of the file-chunk |
Chris Lattner | 3b4d5e9 | 2009-01-17 08:45:21 +0000 | [diff] [blame] | 156 | /// referred to by ChunkID. This method should not be used to get the offset |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 157 | /// from the start of the file, instead you should use |
Ted Kremenek | 9f68fa5 | 2008-03-18 20:13:06 +0000 | [diff] [blame] | 158 | /// SourceManager::getDecomposedFileLoc. This method will be |
| 159 | // incorrect for large files. |
Chris Lattner | 9dc1f53 | 2007-07-20 16:37:10 +0000 | [diff] [blame] | 160 | unsigned getRawFilePos() const { |
| 161 | assert(isFileID() && "can't get the file id of a non-file sloc!"); |
Chris Lattner | 2c64b7b | 2007-10-16 21:07:07 +0000 | [diff] [blame] | 162 | return ID & (ChunkSize-1); |
Chris Lattner | 9dc1f53 | 2007-07-20 16:37:10 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Chris Lattner | df7c17a | 2009-01-16 07:00:02 +0000 | [diff] [blame] | 165 | int getMacroSpellingOffs() const { |
Chris Lattner | 9dc1f53 | 2007-07-20 16:37:10 +0000 | [diff] [blame] | 166 | assert(isMacroID() && "Is not a macro id!"); |
Chris Lattner | df7c17a | 2009-01-16 07:00:02 +0000 | [diff] [blame] | 167 | int Val = ID & ((1 << MacroSpellingOffsBits)-1); |
Chris Lattner | d1623a8 | 2007-07-21 06:41:57 +0000 | [diff] [blame] | 168 | // Sign extend it properly. |
Chris Lattner | df7c17a | 2009-01-16 07:00:02 +0000 | [diff] [blame] | 169 | unsigned ShAmt = sizeof(int)*8 - MacroSpellingOffsBits; |
Chris Lattner | d1623a8 | 2007-07-21 06:41:57 +0000 | [diff] [blame] | 170 | return (Val << ShAmt) >> ShAmt; |
Chris Lattner | 9dc1f53 | 2007-07-20 16:37:10 +0000 | [diff] [blame] | 171 | } |
Chris Lattner | 4d10ef1 | 2009-01-19 06:55:08 +0000 | [diff] [blame^] | 172 | public: |
Chris Lattner | 9dc1f53 | 2007-07-20 16:37:10 +0000 | [diff] [blame] | 173 | |
Chris Lattner | 9dc1f53 | 2007-07-20 16:37:10 +0000 | [diff] [blame] | 174 | /// getFileLocWithOffset - Return a source location with the specified offset |
| 175 | /// from this file SourceLocation. |
Chris Lattner | d1623a8 | 2007-07-21 06:41:57 +0000 | [diff] [blame] | 176 | SourceLocation getFileLocWithOffset(int Offset) const { |
Chris Lattner | 3b4d5e9 | 2009-01-17 08:45:21 +0000 | [diff] [blame] | 177 | unsigned ChunkID = getChunkID(); |
Chris Lattner | 2c64b7b | 2007-10-16 21:07:07 +0000 | [diff] [blame] | 178 | Offset += getRawFilePos(); |
| 179 | // Handle negative offsets correctly. |
| 180 | while (Offset < 0) { |
Chris Lattner | 3b4d5e9 | 2009-01-17 08:45:21 +0000 | [diff] [blame] | 181 | --ChunkID; |
Chris Lattner | 2c64b7b | 2007-10-16 21:07:07 +0000 | [diff] [blame] | 182 | Offset += ChunkSize; |
| 183 | } |
Chris Lattner | 3b4d5e9 | 2009-01-17 08:45:21 +0000 | [diff] [blame] | 184 | return getFileLoc(ChunkID, Offset); |
Chris Lattner | 9dc1f53 | 2007-07-20 16:37:10 +0000 | [diff] [blame] | 185 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 186 | |
| 187 | /// getRawEncoding - When a SourceLocation itself cannot be used, this returns |
| 188 | /// an (opaque) 32-bit integer encoding for it. This should only be passed |
| 189 | /// to SourceLocation::getFromRawEncoding, it should not be inspected |
| 190 | /// directly. |
| 191 | unsigned getRawEncoding() const { return ID; } |
| 192 | |
Chris Lattner | cff9cc9 | 2008-10-12 05:44:03 +0000 | [diff] [blame] | 193 | |
| 194 | bool operator<(const SourceLocation &RHS) const { |
| 195 | return ID < RHS.ID; |
| 196 | } |
| 197 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 198 | /// getFromRawEncoding - Turn a raw encoding of a SourceLocation object into |
| 199 | /// a real SourceLocation. |
| 200 | static SourceLocation getFromRawEncoding(unsigned Encoding) { |
| 201 | SourceLocation X; |
| 202 | X.ID = Encoding; |
| 203 | return X; |
| 204 | } |
Ted Kremenek | beb7713 | 2007-11-01 22:25:41 +0000 | [diff] [blame] | 205 | |
| 206 | /// Emit - Emit this SourceLocation object to Bitcode. |
| 207 | void Emit(llvm::Serializer& S) const; |
| 208 | |
| 209 | /// ReadVal - Read a SourceLocation object from Bitcode. |
| 210 | static SourceLocation ReadVal(llvm::Deserializer& D); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 211 | }; |
| 212 | |
| 213 | inline bool operator==(const SourceLocation &LHS, const SourceLocation &RHS) { |
| 214 | return LHS.getRawEncoding() == RHS.getRawEncoding(); |
| 215 | } |
| 216 | |
| 217 | inline bool operator!=(const SourceLocation &LHS, const SourceLocation &RHS) { |
| 218 | return !(LHS == RHS); |
| 219 | } |
| 220 | |
| 221 | /// SourceRange - a trival tuple used to represent a source range. |
| 222 | class SourceRange { |
| 223 | SourceLocation B; |
| 224 | SourceLocation E; |
| 225 | public: |
| 226 | SourceRange(): B(SourceLocation()), E(SourceLocation()) {} |
| 227 | SourceRange(SourceLocation loc) : B(loc), E(loc) {} |
| 228 | SourceRange(SourceLocation begin, SourceLocation end) : B(begin), E(end) {} |
| 229 | |
Chris Lattner | 311ff02 | 2007-10-16 22:36:42 +0000 | [diff] [blame] | 230 | SourceLocation getBegin() const { return B; } |
| 231 | SourceLocation getEnd() const { return E; } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 232 | |
Chris Lattner | e80a59c | 2007-07-25 00:24:17 +0000 | [diff] [blame] | 233 | void setBegin(SourceLocation b) { B = b; } |
| 234 | void setEnd(SourceLocation e) { E = e; } |
| 235 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 236 | bool isValid() const { return B.isValid() && E.isValid(); } |
Ted Kremenek | beb7713 | 2007-11-01 22:25:41 +0000 | [diff] [blame] | 237 | |
| 238 | /// Emit - Emit this SourceRange object to Bitcode. |
| 239 | void Emit(llvm::Serializer& S) const; |
| 240 | |
| 241 | /// ReadVal - Read a SourceRange object from Bitcode. |
| 242 | static SourceRange ReadVal(llvm::Deserializer& D); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 243 | }; |
| 244 | |
Chris Lattner | a50bd54 | 2009-01-16 23:03:56 +0000 | [diff] [blame] | 245 | /// FullSourceLoc - A SourceLocation and its associated SourceManager. Useful |
| 246 | /// for argument passing to functions that expect both objects. |
| 247 | class FullSourceLoc : public SourceLocation { |
Ted Kremenek | 9c728dc | 2007-12-12 22:39:36 +0000 | [diff] [blame] | 248 | SourceManager* SrcMgr; |
Ted Kremenek | a9793ed | 2007-12-12 18:16:46 +0000 | [diff] [blame] | 249 | public: |
Ted Kremenek | 1b924fd | 2007-12-12 18:54:21 +0000 | [diff] [blame] | 250 | // Creates a FullSourceLoc where isValid() returns false. |
Chris Lattner | a50bd54 | 2009-01-16 23:03:56 +0000 | [diff] [blame] | 251 | explicit FullSourceLoc() : SrcMgr((SourceManager*) 0) {} |
Ted Kremenek | a9793ed | 2007-12-12 18:16:46 +0000 | [diff] [blame] | 252 | |
Chris Lattner | a50bd54 | 2009-01-16 23:03:56 +0000 | [diff] [blame] | 253 | explicit FullSourceLoc(SourceLocation Loc, SourceManager &SM) |
| 254 | : SourceLocation(Loc), SrcMgr(&SM) {} |
Ted Kremenek | 1b924fd | 2007-12-12 18:54:21 +0000 | [diff] [blame] | 255 | |
Ted Kremenek | 9c728dc | 2007-12-12 22:39:36 +0000 | [diff] [blame] | 256 | SourceManager& getManager() { |
| 257 | assert (SrcMgr && "SourceManager is NULL."); |
| 258 | return *SrcMgr; |
| 259 | } |
Ted Kremenek | a9793ed | 2007-12-12 18:16:46 +0000 | [diff] [blame] | 260 | |
Ted Kremenek | 1b924fd | 2007-12-12 18:54:21 +0000 | [diff] [blame] | 261 | const SourceManager& getManager() const { |
Ted Kremenek | a9793ed | 2007-12-12 18:16:46 +0000 | [diff] [blame] | 262 | assert (SrcMgr && "SourceManager is NULL."); |
| 263 | return *SrcMgr; |
| 264 | } |
Ted Kremenek | 9c728dc | 2007-12-12 22:39:36 +0000 | [diff] [blame] | 265 | |
Chris Lattner | 3b4d5e9 | 2009-01-17 08:45:21 +0000 | [diff] [blame] | 266 | FileID getFileID() const; |
| 267 | |
Chris Lattner | f7cf85b | 2009-01-16 07:36:28 +0000 | [diff] [blame] | 268 | FullSourceLoc getInstantiationLoc() const; |
Chris Lattner | df7c17a | 2009-01-16 07:00:02 +0000 | [diff] [blame] | 269 | FullSourceLoc getSpellingLoc() const; |
Chris Lattner | 5c38b63 | 2008-09-29 21:46:13 +0000 | [diff] [blame] | 270 | FullSourceLoc getIncludeLoc() const; |
Ted Kremenek | 9c728dc | 2007-12-12 22:39:36 +0000 | [diff] [blame] | 271 | |
Ted Kremenek | 1758b07 | 2008-04-03 17:55:15 +0000 | [diff] [blame] | 272 | unsigned getLineNumber() const; |
| 273 | unsigned getColumnNumber() const; |
| 274 | |
Chris Lattner | f7cf85b | 2009-01-16 07:36:28 +0000 | [diff] [blame] | 275 | unsigned getInstantiationLineNumber() const; |
| 276 | unsigned getInstantiationColumnNumber() const; |
Ted Kremenek | 9c728dc | 2007-12-12 22:39:36 +0000 | [diff] [blame] | 277 | |
Chris Lattner | df7c17a | 2009-01-16 07:00:02 +0000 | [diff] [blame] | 278 | unsigned getSpellingLineNumber() const; |
| 279 | unsigned getSpellingColumnNumber() const; |
Chris Lattner | 5c38b63 | 2008-09-29 21:46:13 +0000 | [diff] [blame] | 280 | |
Ted Kremenek | 9c728dc | 2007-12-12 22:39:36 +0000 | [diff] [blame] | 281 | const char *getCharacterData() const; |
| 282 | |
| 283 | const llvm::MemoryBuffer* getBuffer() const; |
| 284 | |
| 285 | const char* getSourceName() const; |
| 286 | const FileEntry* getFileEntryForLoc() const; |
Nico Weber | 7bfaaae | 2008-08-10 19:59:06 +0000 | [diff] [blame] | 287 | |
| 288 | bool isInSystemHeader() const; |
Ted Kremenek | 9c728dc | 2007-12-12 22:39:36 +0000 | [diff] [blame] | 289 | |
Chris Lattner | 5c38b63 | 2008-09-29 21:46:13 +0000 | [diff] [blame] | 290 | /// Prints information about this FullSourceLoc to stderr. Useful for |
| 291 | /// debugging. |
| 292 | void dump() const; |
Douglas Gregor | 0b7a158 | 2009-01-17 00:42:38 +0000 | [diff] [blame] | 293 | |
| 294 | friend inline bool |
| 295 | operator==(const FullSourceLoc &LHS, const FullSourceLoc &RHS) { |
| 296 | return LHS.getRawEncoding() == RHS.getRawEncoding() && |
| 297 | LHS.SrcMgr == RHS.SrcMgr; |
| 298 | } |
| 299 | |
| 300 | friend inline bool |
| 301 | operator!=(const FullSourceLoc &LHS, const FullSourceLoc &RHS) { |
| 302 | return !(LHS == RHS); |
| 303 | } |
| 304 | |
Ted Kremenek | a9793ed | 2007-12-12 18:16:46 +0000 | [diff] [blame] | 305 | }; |
Douglas Gregor | 0b7a158 | 2009-01-17 00:42:38 +0000 | [diff] [blame] | 306 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 307 | } // end namespace clang |
| 308 | |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 309 | namespace llvm { |
| 310 | /// Define DenseMapInfo so that FileID's can be used as keys in DenseMap and |
| 311 | /// DenseSets. |
| 312 | template <> |
| 313 | struct DenseMapInfo<clang::FileID> { |
| 314 | static inline clang::FileID getEmptyKey() { |
| 315 | return clang::FileID(); |
| 316 | } |
| 317 | static inline clang::FileID getTombstoneKey() { |
| 318 | return clang::FileID::getSentinel(); |
| 319 | } |
| 320 | |
| 321 | static unsigned getHashValue(clang::FileID S) { |
| 322 | return S.getHashValue(); |
| 323 | } |
| 324 | |
| 325 | static bool isEqual(clang::FileID LHS, clang::FileID RHS) { |
| 326 | return LHS == RHS; |
| 327 | } |
| 328 | |
| 329 | static bool isPod() { return true; } |
| 330 | }; |
| 331 | |
| 332 | } // end namespace llvm |
| 333 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 334 | #endif |